From 06fadd922efaa232c91b83a5ee2cb6164238d6b6 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Wed, 17 Apr 2024 09:18:34 -0400 Subject: [PATCH] Implement/match LegoROI/LegoLOD::GetTexture (#814) * Implement/match LegoROI/LegoLOD::GetTexture * Remove explicit truth tests * LegoTextureContainer::AddToList fix * Revert "Remove explicit truth tests" This reverts commit d169349bd61294e3cf4d645ac59244b48fb95867. --- LEGO1/lego/legoomni/include/legotextureinfo.h | 4 +++ .../legoomni/src/common/legotextureinfo.cpp | 24 ++++++++++++++++++ LEGO1/lego/sources/misc/legocontainer.cpp | 2 +- LEGO1/lego/sources/roi/legolod.cpp | 14 +++++++++++ LEGO1/lego/sources/roi/legolod.h | 1 + LEGO1/lego/sources/roi/legoroi.cpp | 25 ++++++++++++++++--- LEGO1/lego/sources/roi/legoroi.h | 2 +- 7 files changed, 67 insertions(+), 5 deletions(-) diff --git a/LEGO1/lego/legoomni/include/legotextureinfo.h b/LEGO1/lego/legoomni/include/legotextureinfo.h index 3256ebbf..e7cd894b 100644 --- a/LEGO1/lego/legoomni/include/legotextureinfo.h +++ b/LEGO1/lego/legoomni/include/legotextureinfo.h @@ -17,6 +17,7 @@ class LegoTextureInfo { static LegoTextureInfo* Create(const char* p_name, LegoTexture* p_texture); static BOOL SetGroupTexture(Tgl::Mesh* pMesh, LegoTextureInfo* p_textureInfo); + static BOOL GetGroupTexture(Tgl::Mesh* pMesh, LegoTextureInfo*& p_textureInfo); LegoResult FUN_10066010(LegoU8* p_bits); @@ -27,4 +28,7 @@ class LegoTextureInfo { LPDIRECT3DRMTEXTURE2 m_texture; // 0x0c }; +// GLOBAL: LEGO1 0x100db6f0 +// IID_IDirect3DRMTexture2 + #endif // LEGOTEXTUREINFO_H diff --git a/LEGO1/lego/legoomni/src/common/legotextureinfo.cpp b/LEGO1/lego/legoomni/src/common/legotextureinfo.cpp index 75034536..2a750a48 100644 --- a/LEGO1/lego/legoomni/src/common/legotextureinfo.cpp +++ b/LEGO1/lego/legoomni/src/common/legotextureinfo.cpp @@ -160,6 +160,30 @@ BOOL LegoTextureInfo::SetGroupTexture(Tgl::Mesh* pMesh, LegoTextureInfo* p_textu return TRUE; } +// FUNCTION: LEGO1 0x10065f90 +BOOL LegoTextureInfo::GetGroupTexture(Tgl::Mesh* pMesh, LegoTextureInfo*& p_textureInfo) +{ + TglImpl::MeshImpl::MeshData* data = ((TglImpl::MeshImpl*) pMesh)->ImplementationData(); + + IDirect3DRMMesh* mesh = data->groupMesh; + D3DRMGROUPINDEX id = data->groupIndex; + LPDIRECT3DRMTEXTURE returnPtr = NULL; + LPDIRECT3DRMTEXTURE2 texture = NULL; + + if (mesh->GetGroupTexture(id, &returnPtr) == D3DRM_OK) { + if (returnPtr->QueryInterface(IID_IDirect3DRMTexture2, (LPVOID*) &texture) == D3DRM_OK) { + p_textureInfo = (LegoTextureInfo*) texture->GetAppData(); + + texture->Release(); + returnPtr->Release(); + } + + return TRUE; + } + + return FALSE; +} + // STUB: LEGO1 0x10066010 LegoResult LegoTextureInfo::FUN_10066010(LegoU8* p_bits) { diff --git a/LEGO1/lego/sources/misc/legocontainer.cpp b/LEGO1/lego/sources/misc/legocontainer.cpp index b6a04a98..0238794c 100644 --- a/LEGO1/lego/sources/misc/legocontainer.cpp +++ b/LEGO1/lego/sources/misc/legocontainer.cpp @@ -54,7 +54,7 @@ LegoTextureInfo* LegoTextureContainer::AddToList(LegoTextureInfo* p_textureInfo) LegoTextureInfo* textureInfo = new LegoTextureInfo(); textureInfo->m_palette = p_textureInfo->m_palette; - p_textureInfo->m_palette->Release(); + textureInfo->m_palette->AddRef(); memset(&newDesc, 0, sizeof(newDesc)); newDesc.dwWidth = desc.dwWidth; diff --git a/LEGO1/lego/sources/roi/legolod.cpp b/LEGO1/lego/sources/roi/legolod.cpp index 0aae147d..e9997907 100644 --- a/LEGO1/lego/sources/roi/legolod.cpp +++ b/LEGO1/lego/sources/roi/legolod.cpp @@ -362,6 +362,20 @@ LegoResult LegoLOD::FUN_100aad70(LegoTextureInfo* p_textureInfo) return SUCCESS; } +// FUNCTION: LEGO1 0x100aadc0 +LegoResult LegoLOD::GetTexture(LegoTextureInfo*& p_textureInfo) +{ + for (LegoU32 i = m_unk0x1c; i < m_numMeshes; i++) { + if (m_melems[i].m_unk0x04) { + if (LegoTextureInfo::GetGroupTexture(m_melems[i].m_tglMesh, p_textureInfo) == TRUE) { + return SUCCESS; + } + } + } + + return FAILURE; +} + // FUNCTION: LEGO1 0x100aae20 LegoBool LegoLOD::FUN_100aae20(const LegoChar* p_name) { diff --git a/LEGO1/lego/sources/roi/legolod.h b/LEGO1/lego/sources/roi/legolod.h index 395f416c..a47a3d24 100644 --- a/LEGO1/lego/sources/roi/legolod.h +++ b/LEGO1/lego/sources/roi/legolod.h @@ -32,6 +32,7 @@ class LegoLOD : public ViewLOD { LegoResult FUN_100aacb0(LegoFloat p_red, LegoFloat p_green, LegoFloat p_blue, LegoFloat p_alpha); LegoResult FUN_100aad00(LegoTextureInfo* p_textureInfo); LegoResult FUN_100aad70(LegoTextureInfo* p_textureInfo); + LegoResult GetTexture(LegoTextureInfo*& p_textureInfo); static LegoBool FUN_100aae20(const LegoChar* p_name); diff --git a/LEGO1/lego/sources/roi/legoroi.cpp b/LEGO1/lego/sources/roi/legoroi.cpp index 7885482f..c18b5de6 100644 --- a/LEGO1/lego/sources/roi/legoroi.cpp +++ b/LEGO1/lego/sources/roi/legoroi.cpp @@ -498,10 +498,29 @@ LegoResult LegoROI::FUN_100a9210(LegoTextureInfo* p_textureInfo) return result; } -// STUB: LEGO1 0x100a92a0 -LegoResult LegoROI::GetTexture(LegoTextureInfo*&) +// FUNCTION: LEGO1 0x100a92a0 +// FUNCTION: BETA10 0x1018b12d +LegoResult LegoROI::GetTexture(LegoTextureInfo*& p_textureInfo) { - // TODO + CompoundObject::iterator it; + + int lodCount = GetLODCount(); + for (LegoU32 i = 0; i < lodCount; i++) { + LegoLOD* lod = (LegoLOD*) GetLOD(i); + + if (lod->GetTexture(p_textureInfo) == SUCCESS) { + return SUCCESS; + } + } + + if (comp != NULL) { + for (it = comp->begin(); it != comp->end(); it++) { + if (((LegoROI*) *it)->GetTexture(p_textureInfo) == SUCCESS) { + return SUCCESS; + } + } + } + return FAILURE; } diff --git a/LEGO1/lego/sources/roi/legoroi.h b/LEGO1/lego/sources/roi/legoroi.h index d71d8b47..34b5f809 100644 --- a/LEGO1/lego/sources/roi/legoroi.h +++ b/LEGO1/lego/sources/roi/legoroi.h @@ -36,7 +36,7 @@ class LegoROI : public ViewROI { LegoResult SetFrame(LegoAnim* p_anim, LegoTime p_time); LegoResult FUN_100a9170(LegoFloat p_red, LegoFloat p_green, LegoFloat p_blue, LegoFloat p_alpha); LegoResult FUN_100a9210(LegoTextureInfo* p_textureInfo); - LegoResult GetTexture(LegoTextureInfo*&); + LegoResult GetTexture(LegoTextureInfo*& p_textureInfo); LegoU32 FUN_100a9410(Vector3&, Vector3&, float, float, Vector3&, LegoBool); void SetName(const LegoChar* p_name);