From 761b120aeedefda5de172f6ba0524e4279d63292 Mon Sep 17 00:00:00 2001 From: MS Date: Wed, 21 Feb 2024 15:30:02 -0500 Subject: [PATCH] CustomizeAnimFile MxVariable (#584) * CustomizeAnimFile MxVariable * Fixes * Remove returns * Add size asserts --------- Co-authored-by: Christian Semmler --- .../legoomni/include/legobuildingmanager.h | 3 ++ .../lego/legoomni/include/legoplantmanager.h | 4 ++ .../legoomni/include/legounksavedatawriter.h | 51 ++++++++++++++++++- LEGO1/lego/legoomni/include/legovariables.h | 9 ++++ .../src/build/legobuildingmanager.cpp | 22 ++++++++ .../legoomni/src/common/legoplantmanager.cpp | 22 ++++++++ .../src/common/legounksavedatawriter.cpp | 44 ++++++++++++++-- .../legoomni/src/common/legovariables.cpp | 29 +++++++++++ .../legoomni/src/video/legomodelpresenter.cpp | 2 +- 9 files changed, 180 insertions(+), 6 deletions(-) diff --git a/LEGO1/lego/legoomni/include/legobuildingmanager.h b/LEGO1/lego/legoomni/include/legobuildingmanager.h index f603b5dd..f6b5c0e6 100644 --- a/LEGO1/lego/legoomni/include/legobuildingmanager.h +++ b/LEGO1/lego/legoomni/include/legobuildingmanager.h @@ -21,6 +21,7 @@ public: } static void configureLegoBuildingManager(MxS32); + static void SetCustomizeAnimFile(const char* p_value); void FUN_1002fa00(); void FUN_1002fb30(); @@ -30,6 +31,8 @@ public: // LegoBuildingManager::`scalar deleting destructor' private: + static char* g_customizeAnimFile; + void Init(); undefined m_unk0x08[0x28]; // 0x08 diff --git a/LEGO1/lego/legoomni/include/legoplantmanager.h b/LEGO1/lego/legoomni/include/legoplantmanager.h index 2670d13c..5d64ca27 100644 --- a/LEGO1/lego/legoomni/include/legoplantmanager.h +++ b/LEGO1/lego/legoomni/include/legoplantmanager.h @@ -24,10 +24,14 @@ public: void FUN_100263a0(undefined4 p_und); void FUN_10027120(); + static void SetCustomizeAnimFile(const char* p_value); + // SYNTHETIC: LEGO1 0x100262a0 // LegoPlantManager::`scalar deleting destructor' private: + static char* g_customizeAnimFile; + void Init(); undefined m_unk0x08[0x24]; // 0x08 diff --git a/LEGO1/lego/legoomni/include/legounksavedatawriter.h b/LEGO1/lego/legoomni/include/legounksavedatawriter.h index 43a17dfc..e0aa8cea 100644 --- a/LEGO1/lego/legoomni/include/legounksavedatawriter.h +++ b/LEGO1/lego/legoomni/include/legounksavedatawriter.h @@ -3,10 +3,28 @@ #include "decomp.h" #include "lego/sources/misc/legostorage.h" +#include "legovariables.h" +#include "mxstl/stlcompat.h" #include "mxtypes.h" class LegoROI; +#pragma warning(disable : 4237) + +// TODO: generic string comparator? +struct LegoUnkSaveDataMapComparator { + bool operator()(const char* const& p_a, const char* const& p_b) const { return strcmpi(p_a, p_b) > 0; } +}; + +// TODO: pair instead? +// SIZE 0x08 +struct LegoUnkSaveDataMapValue { + LegoROI* m_roi; // 0x00 + MxU32 m_counter; // 0x04 +}; + +typedef map LegoUnkSaveDataMap; + struct LegoSaveDataEntry3 { char* m_name; void* m_unk0x04; @@ -38,13 +56,42 @@ public: LegoUnkSaveDataWriter(); MxResult WriteSaveData3(LegoStorage* p_stream); - LegoROI* FUN_10083500(char*, undefined4); + LegoROI* FUN_10083500(char*, MxBool); + + static void InitSaveData(); + static void SetCustomizeAnimFile(const char* p_value); + void FUN_100832a0(); void FUN_10083db0(LegoROI* p_roi); void FUN_10083f10(LegoROI* p_roi); private: - undefined m_unk0x00[0x08]; // 0x00 + static char* g_customizeAnimFile; + + LegoUnkSaveDataMap* m_map; // 0x00 + CustomizeAnimFileVariable* m_customizeAnimFile; // 0x04 }; +// clang-format off + +// FUNCTION: LEGO1 0x10082b90 +// _Tree,map >::_Kfn,LegoUnkSaveDataMapComparator,allocator >::~_Tree,map >::_Kfn,LegoUnkSaveDataMapComparator,allocator > + +// FUNCTION: LEGO1 0x10082c60 +// _Tree,map >::_Kfn,LegoUnkSaveDataMapComparator,allocator >::iterator::_Inc + +// FUNCTION: LEGO1 0x10082ca0 +// _Tree,map >::_Kfn,LegoUnkSaveDataMapComparator,allocator >::erase + +// FUNCTION: LEGO1 0x100830f0 +// _Tree,map >::_Kfn,LegoUnkSaveDataMapComparator,allocator >::_Erase + +// FUNCTION: LEGO1 0x10083130 +// map >::~map > + +// GLOBAL: LEGO1 0x100fc508 +// _Tree,map >::_Kfn,LegoUnkSaveDataMapComparator,allocator >::_Nil + +// clang-format on + #endif // LEGOUNKSAVEDATAWRITER_H diff --git a/LEGO1/lego/legoomni/include/legovariables.h b/LEGO1/lego/legoomni/include/legovariables.h index 2116c564..8528d44d 100644 --- a/LEGO1/lego/legoomni/include/legovariables.h +++ b/LEGO1/lego/legoomni/include/legovariables.h @@ -44,4 +44,13 @@ public: void SetValue(const char* p_value) override; // vtable+0x04 }; +// VTABLE: LEGO1 0x100da878 +// SIZE 0x24 +class CustomizeAnimFileVariable : public MxVariable { +public: + CustomizeAnimFileVariable(const char* p_key); + + void SetValue(const char* p_value) override; // vtable+0x04 +}; + #endif // LEGOVARIABLES_H diff --git a/LEGO1/lego/legoomni/src/build/legobuildingmanager.cpp b/LEGO1/lego/legoomni/src/build/legobuildingmanager.cpp index 8ec95f44..ddb2788d 100644 --- a/LEGO1/lego/legoomni/src/build/legobuildingmanager.cpp +++ b/LEGO1/lego/legoomni/src/build/legobuildingmanager.cpp @@ -2,6 +2,9 @@ DECOMP_SIZE_ASSERT(LegoBuildingManager, 0x30) +// GLOBAL: LEGO1 0x100f37c8 +char* LegoBuildingManager::g_customizeAnimFile = NULL; + // GLOBAL: LEGO1 0x100f37cc int g_buildingManagerConfig = 1; @@ -41,6 +44,25 @@ void LegoBuildingManager::FUN_1002fb30() // TODO } +// FUNCTION: LEGO1 0x1002ff90 +void LegoBuildingManager::SetCustomizeAnimFile(const char* p_value) +{ + if (g_customizeAnimFile != NULL) { + delete[] g_customizeAnimFile; + } + + if (p_value != NULL) { + g_customizeAnimFile = new char[strlen(p_value) + 1]; + + if (g_customizeAnimFile != NULL) { + strcpy(g_customizeAnimFile, p_value); + } + } + else { + g_customizeAnimFile = NULL; + } +} + // STUB: LEGO1 0x10030220 MxResult LegoBuildingManager::Tickle() { diff --git a/LEGO1/lego/legoomni/src/common/legoplantmanager.cpp b/LEGO1/lego/legoomni/src/common/legoplantmanager.cpp index b111186a..2b2cc4e9 100644 --- a/LEGO1/lego/legoomni/src/common/legoplantmanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legoplantmanager.cpp @@ -2,6 +2,9 @@ DECOMP_SIZE_ASSERT(LegoPlantManager, 0x2c) +// GLOBAL: LEGO1 0x100f3188 +char* LegoPlantManager::g_customizeAnimFile = NULL; + // FUNCTION: LEGO1 0x10026220 LegoPlantManager::LegoPlantManager() { @@ -32,6 +35,25 @@ void LegoPlantManager::FUN_100263a0(undefined4 p_und) // TODO } +// FUNCTION: LEGO1 0x10026be0 +void LegoPlantManager::SetCustomizeAnimFile(const char* p_value) +{ + if (g_customizeAnimFile != NULL) { + delete[] g_customizeAnimFile; + } + + if (p_value != NULL) { + g_customizeAnimFile = new char[strlen(p_value) + 1]; + + if (g_customizeAnimFile != NULL) { + strcpy(g_customizeAnimFile, p_value); + } + } + else { + g_customizeAnimFile = NULL; + } +} + // STUB: LEGO1 0x10026e00 MxResult LegoPlantManager::Tickle() { diff --git a/LEGO1/lego/legoomni/src/common/legounksavedatawriter.cpp b/LEGO1/lego/legoomni/src/common/legounksavedatawriter.cpp index 9849adb2..336c5838 100644 --- a/LEGO1/lego/legoomni/src/common/legounksavedatawriter.cpp +++ b/LEGO1/lego/legoomni/src/common/legounksavedatawriter.cpp @@ -1,18 +1,37 @@ #include "legounksavedatawriter.h" #include "legogamestate.h" +#include "legoomni.h" #include "roi/legoroi.h" DECOMP_SIZE_ASSERT(LegoUnkSaveDataWriter, 0x08) DECOMP_SIZE_ASSERT(LegoSaveDataEntry3, 0x108) +// GLOBAL: LEGO1 0x100f80c0 +LegoSaveDataEntry3 g_saveDataInit[66]; // TODO: add data + +// GLOBAL: LEGO1 0x100fc4e4 +char* LegoUnkSaveDataWriter::g_customizeAnimFile = NULL; + // GLOBAL: LEGO1 0x10104f20 LegoSaveDataEntry3 g_saveData3[66]; -// STUB: LEGO1 0x10082a20 +// FUNCTION: LEGO1 0x10082a20 LegoUnkSaveDataWriter::LegoUnkSaveDataWriter() { - // TODO + m_map = new LegoUnkSaveDataMap(); + InitSaveData(); + + m_customizeAnimFile = new CustomizeAnimFileVariable("CUSTOMIZE_ANIM_FILE"); + VariableTable()->SetVariable(m_customizeAnimFile); +} + +// FUNCTION: LEGO1 0x10083270 +void LegoUnkSaveDataWriter::InitSaveData() +{ + for (MxS32 i = 0; i < 66; i++) { + g_saveData3[i] = g_saveDataInit[i]; + } } // STUB: LEGO1 0x100832a0 @@ -71,7 +90,7 @@ MxResult LegoUnkSaveDataWriter::WriteSaveData3(LegoStorage* p_stream) } // STUB: LEGO1 0x10083500 -LegoROI* LegoUnkSaveDataWriter::FUN_10083500(char*, undefined4) +LegoROI* LegoUnkSaveDataWriter::FUN_10083500(char* p_key, MxBool p_option) { // TODO // involves an STL map with a _Nil node at 0x100fc508 @@ -89,3 +108,22 @@ void LegoUnkSaveDataWriter::FUN_10083f10(LegoROI* p_roi) { // TODO } + +// FUNCTION: LEGO1 0x100851a0 +void LegoUnkSaveDataWriter::SetCustomizeAnimFile(const char* p_value) +{ + if (g_customizeAnimFile != NULL) { + delete[] g_customizeAnimFile; + } + + if (p_value != NULL) { + g_customizeAnimFile = new char[strlen(p_value) + 1]; + + if (g_customizeAnimFile != NULL) { + strcpy(g_customizeAnimFile, p_value); + } + } + else { + g_customizeAnimFile = NULL; + } +} diff --git a/LEGO1/lego/legoomni/src/common/legovariables.cpp b/LEGO1/lego/legoomni/src/common/legovariables.cpp index f69bfcd3..420aa91e 100644 --- a/LEGO1/lego/legoomni/src/common/legovariables.cpp +++ b/LEGO1/lego/legoomni/src/common/legovariables.cpp @@ -1,5 +1,16 @@ #include "legovariables.h" +#include "legobuildingmanager.h" +#include "legoomni.h" +#include "legoplantmanager.h" +#include "legounksavedatawriter.h" + +DECOMP_SIZE_ASSERT(VisibilityVariable, 0x24) +DECOMP_SIZE_ASSERT(CameraLocationVariable, 0x24) +DECOMP_SIZE_ASSERT(CursorVariable, 0x24) +DECOMP_SIZE_ASSERT(WhoAmIVariable, 0x24) +DECOMP_SIZE_ASSERT(CustomizeAnimFileVariable, 0x24) + // GLOBAL: LEGO1 0x100f3a40 // STRING: LEGO1 0x100f3808 const char* g_varVISIBILITY = "VISIBILITY"; @@ -38,3 +49,21 @@ void WhoAmIVariable::SetValue(const char* p_value) { // TODO } + +// FUNCTION: LEGO1 0x10085aa0 +CustomizeAnimFileVariable::CustomizeAnimFileVariable(const char* p_key) +{ + m_key = p_key; + m_key.ToUpperCase(); +} + +// FUNCTION: LEGO1 0x10085b50 +void CustomizeAnimFileVariable::SetValue(const char* p_value) +{ + // STRING: LEGO1 0x100fc4f4 + if (strcmp(m_key.GetData(), "CUSTOMIZE_ANIM_FILE") == 0) { + UnkSaveDataWriter()->SetCustomizeAnimFile(p_value); + PlantManager()->SetCustomizeAnimFile(p_value); + BuildingManager()->SetCustomizeAnimFile(p_value); + } +} diff --git a/LEGO1/lego/legoomni/src/video/legomodelpresenter.cpp b/LEGO1/lego/legoomni/src/video/legomodelpresenter.cpp index ca2f1ead..abc43b4e 100644 --- a/LEGO1/lego/legoomni/src/video/legomodelpresenter.cpp +++ b/LEGO1/lego/legoomni/src/video/legomodelpresenter.cpp @@ -126,7 +126,7 @@ void LegoModelPresenter::ParseExtra() if (KeyValueStringParse(output, g_autoCreate, buffer) != 0) { char* token = strtok(output, g_parseExtraTokens); if (m_roi == NULL) { - m_roi = UnkSaveDataWriter()->FUN_10083500(token, 0); + m_roi = UnkSaveDataWriter()->FUN_10083500(token, FALSE); m_addedToView = FALSE; } }