From 3a3b7d52595b5c1c76f9a0c80346a6ddc3e20e15 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Mon, 3 Nov 2025 16:37:18 -0600 Subject: [PATCH] feat(component): implement CCharacterComponent::AddHandItem --- src/component/CCharacterComponent.cpp | 46 +++++++++++++++++++++++++-- src/component/CCharacterComponent.hpp | 4 ++- src/component/Types.hpp | 2 +- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/component/CCharacterComponent.cpp b/src/component/CCharacterComponent.cpp index 2c35369..019be87 100644 --- a/src/component/CCharacterComponent.cpp +++ b/src/component/CCharacterComponent.cpp @@ -90,6 +90,7 @@ int32_t s_itemPriority[NUM_ITEM_SLOT][NUM_COMPONENT_SECTIONS] = { #define SECTION_HL_ITEM_PRIORITIES 0 int32_t s_bInRenderPrep = 0; +char s_buffer[STORM_MAX_PATH]; uint32_t* s_componentHeap; char* s_pathEnd; char s_path[STORM_MAX_PATH]; @@ -99,8 +100,13 @@ CStatus s_status; #define TEXTURE_INDEX(section, texture) (3 * section + texture) -int32_t CCharacterComponent::AddHandItem(CM2Model* model, const ItemDisplayInfoRec* displayRec, INVENTORY_SLOTS invSlot, SHEATHE_TYPE sheatheType, bool a5, bool a6, bool a7, int32_t a8) { - // TODO +int32_t CCharacterComponent::AddHandItem(CM2Model* model, const ItemDisplayInfoRec* displayRec, INVENTORY_SLOTS invSlot, SHEATHE_TYPE sheatheType, bool sheathed, bool shield, bool a7, int32_t visualID) { + if (!model || !displayRec || invSlot > INVSLOT_TABARD) { + return -1; + } + + auto modelPath = "Item\\ObjectComponents\\Weapon\\"; + auto texturePath = "Item\\ObjectComponents\\Weapon\\"; GEOCOMPONENTLINKS itemLink; GEOCOMPONENTLINKS sheatheLink; @@ -123,6 +129,38 @@ int32_t CCharacterComponent::AddHandItem(CM2Model* model, const ItemDisplayInfoR return -1; } + if (shield) { + modelPath = "Item\\ObjectComponents\\Shield\\"; + texturePath = "Item\\ObjectComponents\\Shield\\"; + + itemLink = ATTACH_SHIELD; + } + + CCharacterComponent::RemoveLinkpt(model, itemLink); + CCharacterComponent::RemoveLinkpt(model, sheatheLink); + + auto link = sheathed ? sheatheLink : itemLink; + + if (model->IsLoaded(0, 0) && !model->HasAttachment(link)) { + return -1; + } + + SStrPrintf(s_buffer, sizeof(s_buffer), "%s%s", modelPath, displayRec->m_modelName[0]); + SStrCopy(s_pathEnd, s_buffer); + + SStrPrintf(s_buffer, sizeof(s_buffer), "%s%s.blp", texturePath, displayRec->m_modelTexture[0]); + SStrCopy(s_pathEnd2, s_buffer); + + if (visualID == 0) { + visualID = displayRec->m_itemVisual; + } + + CCharacterComponent::AddLink(model, link, s_path, s_path2, visualID, displayRec); + + return link; +} + +void CCharacterComponent::AddLink(CM2Model* model, GEOCOMPONENTLINKS link, char const* modelPath, char const* texturePath, int32_t a5, const ItemDisplayInfoRec* displayRec) { // TODO } @@ -596,6 +634,10 @@ void CCharacterComponent::PasteTransparent8Bit(void* srcTexture, const BlpPalPix } } +void CCharacterComponent::RemoveLinkpt(CM2Model* model, GEOCOMPONENTLINKS link) { + // TODO +} + void CCharacterComponent::UpdateBaseTexture(EGxTexCommand cmd, uint32_t width, uint32_t height, uint32_t depth, uint32_t mipLevel, void* userArg, uint32_t& texelStrideInBytes, const void*& texels) { auto component = static_cast(userArg); diff --git a/src/component/CCharacterComponent.hpp b/src/component/CCharacterComponent.hpp index 2415401..3be3eac 100644 --- a/src/component/CCharacterComponent.hpp +++ b/src/component/CCharacterComponent.hpp @@ -47,7 +47,8 @@ class CCharacterComponent { static uint32_t s_textureSize; // Static functions - static int32_t AddHandItem(CM2Model* model, const ItemDisplayInfoRec* displayRec, INVENTORY_SLOTS invSlot, SHEATHE_TYPE sheatheType, bool a5, bool a6, bool a7, int32_t a8); + static int32_t AddHandItem(CM2Model* model, const ItemDisplayInfoRec* displayRec, INVENTORY_SLOTS invSlot, SHEATHE_TYPE sheatheType, bool sheathed, bool shield, bool a7, int32_t a8); + static void AddLink(CM2Model* model, GEOCOMPONENTLINKS link, char const* modelPath, char const* texturePath, int32_t a5, const ItemDisplayInfoRec* displayRec); static CCharacterComponent* AllocComponent(); static HTEXTURE CreateTexture(const char* fileName, CStatus* status); static GEOCOMPONENTLINKS GetSheatheLink(SHEATHE_TYPE sheatheType, bool a2); @@ -62,6 +63,7 @@ class CCharacterComponent { static void PasteTransparent1Bit(void* srcTexture, const BlpPalPixel* srcPal, MipBits* dstMips, const C2iVector& dstPos, uint32_t dstWidth, const C2iVector& srcPos, const C2iVector& srcSize, TCTEXTUREINFO& srcInfo, int32_t srcMipLevel, int32_t dstMipLevelOfs); static void PasteTransparent4Bit(void* srcTexture, const BlpPalPixel* srcPal, MipBits* dstMips, const C2iVector& dstPos, uint32_t dstWidth, const C2iVector& srcPos, const C2iVector& srcSize, TCTEXTUREINFO& srcInfo, int32_t srcMipLevel, int32_t dstMipLevelOfs); static void PasteTransparent8Bit(void* srcTexture, const BlpPalPixel* srcPal, MipBits* dstMips, const C2iVector& dstPos, uint32_t dstWidth, const C2iVector& srcPos, const C2iVector& srcSize, TCTEXTUREINFO& srcInfo, int32_t srcMipLevel, int32_t dstMipLevelOfs); + static void RemoveLinkpt(CM2Model* model, GEOCOMPONENTLINKS link); static void UpdateBaseTexture(EGxTexCommand cmd, uint32_t width, uint32_t height, uint32_t depth, uint32_t mipLevel, void* userArg, uint32_t& texelStrideInBytes, const void*& texels); // Member variables diff --git a/src/component/Types.hpp b/src/component/Types.hpp index eb58240..ca2f575 100644 --- a/src/component/Types.hpp +++ b/src/component/Types.hpp @@ -53,7 +53,7 @@ enum COMPONENT_VARIATIONS { }; enum GEOCOMPONENTLINKS { - // TODO + ATTACH_SHIELD = 0, ATTACH_HANDR = 1, ATTACH_HANDL = 2, // TODO