From dd318480f19589a579c613281645209561f35e0f Mon Sep 17 00:00:00 2001 From: fallenoak Date: Mon, 27 Oct 2025 21:15:46 -0500 Subject: [PATCH] feat(component): implement CCharacterComponent::ReplaceHairTexture --- src/component/CCharacterComponent.cpp | 31 ++++++++++++++++++++++++++- src/component/CCharacterComponent.hpp | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/component/CCharacterComponent.cpp b/src/component/CCharacterComponent.cpp index 93fc605..f53cb90 100644 --- a/src/component/CCharacterComponent.cpp +++ b/src/component/CCharacterComponent.cpp @@ -7,6 +7,7 @@ #include "gx/Texture.hpp" #include "model/CM2Model.hpp" #include "object/Types.hpp" +#include "util/CStatus.hpp" #include #include @@ -70,6 +71,7 @@ int32_t s_itemPriority[NUM_ITEM_SLOT][NUM_COMPONENT_SECTIONS] = { int32_t s_bInRenderPrep = 0; char* s_pathEnd; char s_path[STORM_MAX_PATH]; +CStatus s_status; #define TEXTURE_INDEX(section, texture) (3 * section + texture) @@ -78,6 +80,11 @@ CCharacterComponent* CCharacterComponent::AllocComponent() { return STORM_NEW(CCharacterComponent); } +HTEXTURE CCharacterComponent::CreateTexture(const char* fileName, CStatus* status) { + auto texFlags = CGxTexFlags(GxTex_LinearMipNearest, 0, 0, 0, 0, 0, 1); + return TextureCreate(fileName, texFlags, status, 0); +} + void CCharacterComponent::Initialize() { // TODO @@ -841,7 +848,29 @@ void CCharacterComponent::ReplaceExtraSkinTexture(const char* a2) { } void CCharacterComponent::ReplaceHairTexture(int32_t hairStyleID, const char* a3) { - // TODO + if (!ComponentValidateBase( + CCharacterComponent::s_chrVarArray, + this->m_data.raceID, + this->m_data.sexID, + VARIATION_HAIR, + hairStyleID, + this->m_data.hairColorID + )) { + return; + } + + auto sectionsRec = this->GetSectionsRecord(VARIATION_HAIR, hairStyleID, this->m_data.hairColorID, nullptr); + if (!*sectionsRec->m_textureName[0]) { + return; + } + + SStrCopy(s_pathEnd, sectionsRec->m_textureName[0]); + + auto hairTexture = CCharacterComponent::CreateTexture(s_path, &s_status); + if (hairTexture) { + this->m_data.model->ReplaceTexture(6, hairTexture); + HandleClose(hairTexture); + } } void CCharacterComponent::SetFace(int32_t faceID, bool a3, const char* a4) { diff --git a/src/component/CCharacterComponent.hpp b/src/component/CCharacterComponent.hpp index e57d107..c9cdefe 100644 --- a/src/component/CCharacterComponent.hpp +++ b/src/component/CCharacterComponent.hpp @@ -43,6 +43,7 @@ class CCharacterComponent { // Static functions static CCharacterComponent* AllocComponent(); + static HTEXTURE CreateTexture(const char* fileName, CStatus* status); static void Initialize(); static void Initialize(EGxTexFormat textureFormat, uint32_t textureLevel, int32_t thread, int32_t compress); static void InitDbData();