From 1b4142c6a9de2ade6d9abf20140e0811490e5a0f Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Sun, 15 Dec 2024 10:15:10 -0700 Subject: [PATCH] Implement/match `Write` functions in `LegoAnim` class (#1232) * Implement/match `LegoAnim::Write` * Implement remaining Write functions * Bump total function count --- .github/workflows/build.yml | 2 +- LEGO1/lego/sources/anim/legoanim.cpp | 342 ++++++++++++++++++++++++--- LEGO1/lego/sources/anim/legoanim.h | 15 +- 3 files changed, 320 insertions(+), 39 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 217ad762..36a7db9a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -139,7 +139,7 @@ jobs: run: | reccmp-reccmp -S CONFIGPROGRESS.SVG --svg-icon assets/config.png --target CONFIG | tee CONFIGPROGRESS.TXT reccmp-reccmp -S ISLEPROGRESS.SVG --svg-icon assets/isle.png --target ISLE | tee ISLEPROGRESS.TXT - reccmp-reccmp -S LEGO1PROGRESS.SVG -T 4345 --svg-icon assets/lego1.png --target LEGO1 | tee LEGO1PROGRESS.TXT + reccmp-reccmp -S LEGO1PROGRESS.SVG -T 4352 --svg-icon assets/lego1.png --target LEGO1 | tee LEGO1PROGRESS.TXT - name: Compare Accuracy With Current Master shell: bash diff --git a/LEGO1/lego/sources/anim/legoanim.cpp b/LEGO1/lego/sources/anim/legoanim.cpp index 2477a6ef..0328738b 100644 --- a/LEGO1/lego/sources/anim/legoanim.cpp +++ b/LEGO1/lego/sources/anim/legoanim.cpp @@ -30,8 +30,28 @@ LegoResult LegoUnknownKey::Read(LegoStorage* p_storage) return result; } - result = p_storage->Read(&m_z, sizeof(m_z)); - return result == SUCCESS ? SUCCESS : result; + if ((result = p_storage->Read(&m_z, sizeof(m_z))) != SUCCESS) { + return result; + } + + return SUCCESS; +} + +// FUNCTION: LEGO1 0x1009f060 +// FUNCTION: BETA10 0x1018133f +LegoResult LegoUnknownKey::Write(LegoStorage* p_storage) +{ + LegoResult result; + + if ((result = LegoAnimKey::Write(p_storage)) != SUCCESS) { + return result; + } + + if ((result = p_storage->Write(&m_z, sizeof(m_z))) != SUCCESS) { + return result; + } + + return SUCCESS; } // FUNCTION: LEGO1 0x1009f0a0 @@ -67,6 +87,49 @@ LegoAnimScene::~LegoAnimScene() } } +// FUNCTION: LEGO1 0x1009f120 +// FUNCTION: BETA10 0x101814be +LegoResult LegoAnimScene::Write(LegoStorage* p_storage) +{ + LegoResult result; + LegoS32 i; + + if ((result = p_storage->Write(&m_unk0x00, sizeof(m_unk0x00))) != SUCCESS) { + return result; + } + if (m_unk0x00 != 0) { + for (i = 0; i < m_unk0x00; i++) { + if ((result = m_unk0x04[i].Write(p_storage)) != SUCCESS) { + return result; + } + } + } + + if ((result = p_storage->Write(&m_unk0x08, sizeof(m_unk0x08))) != SUCCESS) { + return result; + } + if (m_unk0x08 != 0) { + for (i = 0; i < m_unk0x08; i++) { + if ((result = m_unk0x0c[i].Write(p_storage)) != SUCCESS) { + return result; + } + } + } + + if ((result = p_storage->Write(&m_unk0x10, sizeof(m_unk0x10))) != SUCCESS) { + return result; + } + if (m_unk0x10 != 0) { + for (i = 0; i < m_unk0x10; i++) { + if ((result = m_unk0x14[i].Write(p_storage)) != SUCCESS) { + return result; + } + } + } + + return SUCCESS; +} + // FUNCTION: LEGO1 0x1009f200 LegoResult LegoAnimScene::Read(LegoStorage* p_storage) { @@ -76,8 +139,7 @@ LegoResult LegoAnimScene::Read(LegoStorage* p_storage) if ((result = p_storage->Read(&m_unk0x00, sizeof(m_unk0x00))) != SUCCESS) { return result; } - - if (m_unk0x00) { + if (m_unk0x00 != 0) { m_unk0x04 = new LegoTranslationKey[m_unk0x00]; for (i = 0; i < m_unk0x00; i++) { if ((result = m_unk0x04[i].Read(p_storage)) != SUCCESS) { @@ -89,8 +151,7 @@ LegoResult LegoAnimScene::Read(LegoStorage* p_storage) if ((result = p_storage->Read(&m_unk0x08, sizeof(m_unk0x08))) != SUCCESS) { return result; } - - if (m_unk0x08) { + if (m_unk0x08 != 0) { m_unk0x0c = new LegoTranslationKey[m_unk0x08]; for (i = 0; i < m_unk0x08; i++) { if ((result = m_unk0x0c[i].Read(p_storage)) != SUCCESS) { @@ -102,8 +163,7 @@ LegoResult LegoAnimScene::Read(LegoStorage* p_storage) if ((result = p_storage->Read(&m_unk0x10, sizeof(m_unk0x10))) != SUCCESS) { return result; } - - if (m_unk0x10) { + if (m_unk0x10 != 0) { m_unk0x14 = new LegoUnknownKey[m_unk0x10]; for (i = 0; i < m_unk0x10; i++) { if ((result = m_unk0x14[i].Read(p_storage)) != SUCCESS) { @@ -232,14 +292,28 @@ LegoAnimKey::LegoAnimKey() LegoResult LegoAnimKey::Read(LegoStorage* p_storage) { LegoResult result; - LegoS32 und; + LegoS32 timeAndFlags; - if ((result = p_storage->Read(&und, sizeof(und))) != SUCCESS) { + if ((result = p_storage->Read(&timeAndFlags, sizeof(timeAndFlags))) != SUCCESS) { + return result; + } + + m_flags = (LegoU32) timeAndFlags >> 24; + m_time = timeAndFlags & 0xffffff; + return SUCCESS; +} + +// FUNCTION: LEGO1 0x1009f950 +// FUNCTION: BETA10 0x1017e018 +LegoResult LegoAnimKey::Write(LegoStorage* p_storage) +{ + LegoResult result; + LegoS32 timeAndFlags = (LegoS32) m_time | (m_flags << 24); + + if ((result = p_storage->Write(&timeAndFlags, sizeof(timeAndFlags))) != SUCCESS) { return result; } - m_flags = (LegoU32) und >> 24; - m_time = und & 0xffffff; return SUCCESS; } @@ -279,6 +353,31 @@ LegoResult LegoTranslationKey::Read(LegoStorage* p_storage) return SUCCESS; } +// FUNCTION: LEGO1 0x1009fa40 +// FUNCTION: BETA10 0x1017e1fd +LegoResult LegoTranslationKey::Write(LegoStorage* p_storage) +{ + LegoResult result; + + if ((result = LegoAnimKey::Write(p_storage)) != SUCCESS) { + return result; + } + + if ((result = p_storage->Write(&m_x, sizeof(m_x))) != SUCCESS) { + return result; + } + + if ((result = p_storage->Write(&m_y, sizeof(m_y))) != SUCCESS) { + return result; + } + + if ((result = p_storage->Write(&m_z, sizeof(m_z))) != SUCCESS) { + return result; + } + + return SUCCESS; +} + // FUNCTION: LEGO1 0x1009faa0 // FUNCTION: BETA10 0x1017e2b3 LegoRotationKey::LegoRotationKey() @@ -321,6 +420,35 @@ LegoResult LegoRotationKey::Read(LegoStorage* p_storage) return SUCCESS; } +// FUNCTION: LEGO1 0x1009fb30 +// FUNCTION: BETA10 0x1017e3fc +LegoResult LegoRotationKey::Write(LegoStorage* p_storage) +{ + LegoResult result; + + if ((result = LegoAnimKey::Write(p_storage)) != SUCCESS) { + return result; + } + + if ((result = p_storage->Write(&m_angle, sizeof(m_angle))) != SUCCESS) { + return result; + } + + if ((result = p_storage->Write(&m_x, sizeof(m_x))) != SUCCESS) { + return result; + } + + if ((result = p_storage->Write(&m_y, sizeof(m_y))) != SUCCESS) { + return result; + } + + if ((result = p_storage->Write(&m_z, sizeof(m_z))) != SUCCESS) { + return result; + } + + return SUCCESS; +} + // FUNCTION: LEGO1 0x1009fba0 LegoScaleKey::LegoScaleKey() { @@ -357,6 +485,31 @@ LegoResult LegoScaleKey::Read(LegoStorage* p_storage) return SUCCESS; } +// FUNCTION: LEGO1 0x1009fc90 +// FUNCTION: BETA10 0x1017e664 +LegoResult LegoScaleKey::Write(LegoStorage* p_storage) +{ + LegoResult result; + + if ((result = LegoAnimKey::Write(p_storage)) != SUCCESS) { + return result; + } + + if ((result = p_storage->Write(&m_x, sizeof(m_x))) != SUCCESS) { + return result; + } + + if ((result = p_storage->Write(&m_y, sizeof(m_y))) != SUCCESS) { + return result; + } + + if ((result = p_storage->Write(&m_z, sizeof(m_z))) != SUCCESS) { + return result; + } + + return SUCCESS; +} + // FUNCTION: LEGO1 0x1009fcf0 // FUNCTION: BETA10 0x1017e71a LegoAnimNodeData::LegoAnimNodeData() @@ -400,6 +553,7 @@ LegoAnimNodeData::~LegoAnimNodeData() } // FUNCTION: LEGO1 0x1009fe60 +// FUNCTION: BETA10 0x1017e949 LegoResult LegoAnimNodeData::Read(LegoStorage* p_storage) { LegoResult result; @@ -490,10 +644,70 @@ LegoResult LegoAnimNodeData::Read(LegoStorage* p_storage) return SUCCESS; } -// STUB: LEGO1 0x100a01e0 +// FUNCTION: LEGO1 0x100a01e0 +// FUNCTION: BETA10 0x1017ef0f LegoResult LegoAnimNodeData::Write(LegoStorage* p_storage) { - // TODO + LegoResult result; + LegoU32 length = 0; + LegoU32 i; + + if (m_name != NULL) { + length = strlen(m_name); + } + + if ((result = p_storage->Write(&length, sizeof(length))) != SUCCESS) { + return result; + } + + if (m_name != NULL && (result = p_storage->Write(m_name, length)) != SUCCESS) { + return result; + } + + if ((result = p_storage->Write(&m_numTranslationKeys, sizeof(m_numTranslationKeys))) != SUCCESS) { + return result; + } + if (m_numTranslationKeys != 0) { + for (i = 0; i < m_numTranslationKeys; i++) { + if ((result = m_translationKeys[i].Write(p_storage)) != SUCCESS) { + return result; + } + } + } + + if ((result = p_storage->Write(&m_numRotationKeys, sizeof(m_numRotationKeys))) != SUCCESS) { + return result; + } + if (m_numRotationKeys != 0) { + for (i = 0; i < m_numRotationKeys; i++) { + if ((result = m_rotationKeys[i].Write(p_storage)) != SUCCESS) { + return result; + } + } + } + + if ((result = p_storage->Write(&m_numScaleKeys, sizeof(m_numScaleKeys))) != SUCCESS) { + return result; + } + if (m_numScaleKeys != 0) { + for (i = 0; i < m_numScaleKeys; i++) { + if ((result = m_scaleKeys[i].Write(p_storage)) != SUCCESS) { + return result; + } + } + } + + if ((result = p_storage->Write(&m_numMorphKeys, sizeof(m_numMorphKeys))) != SUCCESS) { + return result; + } + if (m_numMorphKeys != 0) { + for (i = 0; i < m_numMorphKeys; i++) { + if ((result = m_morphKeys[i].Write(p_storage)) != SUCCESS) { + return result; + } + } + } + return SUCCESS; } @@ -798,7 +1012,7 @@ inline LegoAnimKey& LegoAnimNodeData::GetKey(LegoU32 p_i, LegoAnimKey* p_keys, L LegoAnim::LegoAnim() { m_duration = 0; - m_actors = NULL; + m_modelList = NULL; m_numActors = 0; m_camAnim = NULL; } @@ -806,12 +1020,12 @@ LegoAnim::LegoAnim() // FUNCTION: LEGO1 0x100a0bc0 LegoAnim::~LegoAnim() { - if (m_actors != NULL) { + if (m_modelList != NULL) { for (LegoU32 i = 0; i < m_numActors; i++) { - delete[] m_actors[i].m_name; + delete[] m_modelList[i].m_name; } - delete[] m_actors; + delete[] m_modelList; } if (m_camAnim != NULL) { @@ -829,7 +1043,7 @@ LegoResult LegoAnim::Read(LegoStorage* p_storage, LegoS32 p_parseScene) goto done; } - m_actors = new LegoAnimActorEntry[length]; + m_modelList = new LegoAnimActorEntry[length]; m_numActors = 0; for (i = 0; i < length; i++) { @@ -839,15 +1053,15 @@ LegoResult LegoAnim::Read(LegoStorage* p_storage, LegoS32 p_parseScene) } if (length) { - m_actors[i].m_name = new LegoChar[length + 1]; + m_modelList[i].m_name = new LegoChar[length + 1]; - if (p_storage->Read(m_actors[i].m_name, length) != SUCCESS) { + if (p_storage->Read(m_modelList[i].m_name, length) != SUCCESS) { goto done; } - m_actors[i].m_name[length] = '\0'; + m_modelList[i].m_name[length] = '\0'; - if (p_storage->Read(&m_actors[i].m_unk0x04, sizeof(m_actors[i].m_unk0x04)) != SUCCESS) { + if (p_storage->Read(&m_modelList[i].m_unk0x04, sizeof(m_modelList[i].m_unk0x04)) != SUCCESS) { goto done; } } @@ -872,41 +1086,81 @@ LegoResult LegoAnim::Read(LegoStorage* p_storage, LegoS32 p_parseScene) result = LegoTree::Read(p_storage); done: - if (result != SUCCESS && m_actors != NULL) { + if (result != SUCCESS && m_modelList != NULL) { for (i = 0; i < m_numActors; i++) { - delete[] m_actors[i].m_name; + delete[] m_modelList[i].m_name; } m_numActors = 0; - delete[] m_actors; - m_actors = NULL; + delete[] m_modelList; + m_modelList = NULL; } return result; } -// STUB: LEGO1 0x100a0e30 +// FUNCTION: LEGO1 0x100a0e30 +// FUNCTION: BETA10 0x1017fe3a LegoResult LegoAnim::Write(LegoStorage* p_storage) { - // TODO - return SUCCESS; + LegoResult result = FAILURE; + LegoU32 i; + + if (p_storage->Write(&m_numActors, sizeof(m_numActors)) != SUCCESS) { + goto done; + } + + for (i = 0; i < m_numActors; i++) { + LegoU32 length = strlen(m_modelList[i].m_name); + + if (p_storage->Write(&length, sizeof(length)) != SUCCESS) { + goto done; + } + + if (length != 0) { + if (p_storage->Write(m_modelList[i].m_name, length) != SUCCESS) { + goto done; + } + + if (p_storage->Write(&m_modelList[i].m_unk0x04, sizeof(m_modelList[i].m_unk0x04)) != SUCCESS) { + goto done; + } + } + } + + if (p_storage->Write(&m_duration, sizeof(m_duration)) != SUCCESS) { + goto done; + } + + if (m_camAnim != NULL) { + if (m_camAnim->Write(p_storage) != SUCCESS) { + goto done; + } + } + + result = LegoTree::Write(p_storage); + +done: + return result; } // FUNCTION: LEGO1 0x100a0f20 +// FUNCTION: BETA10 0x101801fd const LegoChar* LegoAnim::GetActorName(LegoU32 p_index) { if (p_index < m_numActors) { - return m_actors[p_index].m_name; + return m_modelList[p_index].m_name; } return NULL; } // FUNCTION: LEGO1 0x100a0f40 +// FUNCTION: BETA10 0x1018023c undefined4 LegoAnim::GetActorUnknown0x04(LegoU32 p_index) { if (p_index < m_numActors) { - return m_actors[p_index].m_unk0x04; + return m_modelList[p_index].m_unk0x04; } return NULL; @@ -928,6 +1182,26 @@ LegoResult LegoMorphKey::Read(LegoStorage* p_storage) return result; } - result = p_storage->Read(&m_unk0x08, sizeof(m_unk0x08)); - return result == SUCCESS ? SUCCESS : result; + if ((result = p_storage->Read(&m_unk0x08, sizeof(m_unk0x08))) != SUCCESS) { + return result; + } + + return SUCCESS; +} + +// FUNCTION: LEGO1 0x100a0fb0 +// FUNCTION: BETA10 0x10180308 +LegoResult LegoMorphKey::Write(LegoStorage* p_storage) +{ + LegoResult result; + + if ((result = LegoAnimKey::Write(p_storage)) != SUCCESS) { + return result; + } + + if ((result = p_storage->Write(&m_unk0x08, sizeof(m_unk0x08))) != SUCCESS) { + return result; + } + + return SUCCESS; } diff --git a/LEGO1/lego/sources/anim/legoanim.h b/LEGO1/lego/sources/anim/legoanim.h index f02566b1..00cbafdb 100644 --- a/LEGO1/lego/sources/anim/legoanim.h +++ b/LEGO1/lego/sources/anim/legoanim.h @@ -18,6 +18,7 @@ class LegoAnimKey { LegoAnimKey(); LegoResult Read(LegoStorage* p_storage); + LegoResult Write(LegoStorage* p_storage); LegoFloat GetTime() { return m_time; } // The different types (LegoFloat vs. MxS32) are correct according to BETA10 @@ -49,6 +50,7 @@ class LegoTranslationKey : public LegoAnimKey { public: LegoTranslationKey(); LegoResult Read(LegoStorage* p_storage); + LegoResult Write(LegoStorage* p_storage); LegoFloat GetX() { return m_x; } void SetX(LegoFloat p_x) { m_x = p_x; } LegoFloat GetY() { return m_y; } @@ -67,6 +69,7 @@ class LegoRotationKey : public LegoAnimKey { public: LegoRotationKey(); LegoResult Read(LegoStorage* p_storage); + LegoResult Write(LegoStorage* p_storage); // FUNCTION: BETA10 0x10073a00 LegoFloat GetAngle() { return m_angle; } @@ -104,6 +107,7 @@ class LegoScaleKey : public LegoAnimKey { public: LegoScaleKey(); LegoResult Read(LegoStorage* p_storage); + LegoResult Write(LegoStorage* p_storage); LegoFloat GetX() { return m_x; } void SetX(LegoFloat p_x) { m_x = p_x; } LegoFloat GetY() { return m_y; } @@ -122,6 +126,7 @@ class LegoMorphKey : public LegoAnimKey { public: LegoMorphKey(); LegoResult Read(LegoStorage* p_storage); + LegoResult Write(LegoStorage* p_storage); LegoBool GetUnknown0x08() { return m_unk0x08; } // FUNCTION: BETA10 0x100738d0 @@ -136,6 +141,7 @@ class LegoUnknownKey : public LegoAnimKey { public: LegoUnknownKey(); LegoResult Read(LegoStorage* p_storage); + LegoResult Write(LegoStorage* p_storage); LegoFloat GetZ() { return m_z; } @@ -291,6 +297,7 @@ class LegoAnimScene { LegoAnimScene(); ~LegoAnimScene(); LegoResult Read(LegoStorage* p_storage); + LegoResult Write(LegoStorage* p_storage); LegoResult FUN_1009f490(LegoFloat p_time, Matrix4& p_matrix); LegoU32 GetUnknown0x18() { return m_unk0x18; } @@ -337,10 +344,10 @@ class LegoAnim : public LegoTree { // LegoAnim::`scalar deleting destructor' protected: - LegoTime m_duration; // 0x08 - LegoAnimActorEntry* m_actors; // 0x0c - LegoU32 m_numActors; // 0x10 - LegoAnimScene* m_camAnim; // 0x14 + LegoTime m_duration; // 0x08 + LegoAnimActorEntry* m_modelList; // 0x0c + LegoU32 m_numActors; // 0x10 + LegoAnimScene* m_camAnim; // 0x14 // FUNCTION: LEGO1 0x100a1040 LegoTreeNodeData* CreateData() override { return new LegoAnimNodeData(); } // vtable+0x0c