diff --git a/src/model/CM2Model.cpp b/src/model/CM2Model.cpp index 4228c3a..f9aa868 100644 --- a/src/model/CM2Model.cpp +++ b/src/model/CM2Model.cpp @@ -1343,6 +1343,56 @@ void CM2Model::Release() { // TODO } +void CM2Model::ReplaceTexture(uint32_t textureId, HTEXTURE texture) { + // Waiting for load + + if (!this->m_loaded) { + auto modelCall = STORM_NEW(CM2ModelCall); + + modelCall->type = 0; + modelCall->modelCallNext = nullptr; + modelCall->time = this->m_scene->m_time; + modelCall->args[0] = textureId; + *reinterpret_cast(&modelCall->args[1]) = texture ? HandleDuplicate(texture) : nullptr; + + *this->m_modelCallTail = modelCall; + this->m_modelCallTail = &modelCall->modelCallNext; + + return; + } + + // Replace textures + + for (int32_t i = 0; i < this->m_shared->m_data->textures.Count(); i++) { + // Only replace if texture IDs match + if (this->m_shared->m_data->textures[i].textureId != textureId) { + continue; + }; + + auto currentTexture = this->m_textures[i]; + + if (currentTexture) { + HandleClose(currentTexture); + } + + if (texture) { + this->m_textures[i] = HandleDuplicate(texture); + + auto gxTexture = TextureGetGxTex(this->m_textures[i], 0, nullptr); + + if (!gxTexture) { + this->m_flag2 = 0; + } + } else { + this->m_textures[i] = nullptr; + } + } + + // TODO replace ribbon textures + + // TODO replace particle textures +} + void CM2Model::SetAnimating(int32_t animating) { if (!animating) { if (this->m_animatePrev) { diff --git a/src/model/CM2Model.hpp b/src/model/CM2Model.hpp index 2eda9ca..e3896b8 100644 --- a/src/model/CM2Model.hpp +++ b/src/model/CM2Model.hpp @@ -169,6 +169,7 @@ class CM2Model { int32_t ProcessCallbacks(); void ProcessCallbacksRecursive(); void Release(); + void ReplaceTexture(uint32_t textureId, HTEXTURE texture); void SetAnimating(int32_t animating); void SetBoneSequence(uint32_t boneId, uint32_t sequenceId, uint32_t a4, uint32_t time, float a6, int32_t a7, int32_t a8); void SetBoneSequenceDeferred(uint16_t a2, M2Data* data, uint16_t boneIndex, uint32_t time, float a6, M2SequenceFallback fallback, int32_t a8, int32_t a9, int32_t a10);