From a6644801f1c24dbd90483ab91572f83be33d8500 Mon Sep 17 00:00:00 2001 From: jonschz <17198703+jonschz@users.noreply.github.com> Date: Fri, 14 Jun 2024 23:24:34 +0200 Subject: [PATCH] feat: Implement several ::Serialize functions (#1017) * feat: Implement many ::Serialize functions * address review comments, part 1 [skip ci] * address review comments, part 2 [skip ci] * review comments (final part) * refactor: Remove Read/Write duplication * fix merge conflict * Match PizzeriaState::Serialize again * Remove unused variable, add LegoVehicleBuildState::Serialize * Implement AnimState::Serialize * fix: Conform with naming scheme * refactor: change names back * refactor: int to MxS32 --------- Co-authored-by: jonschz --- LEGO1/lego/legoomni/include/ambulance.h | 2 +- LEGO1/lego/legoomni/include/gasstation.h | 2 +- LEGO1/lego/legoomni/include/hospital.h | 2 +- LEGO1/lego/legoomni/include/isle.h | 4 +- .../legoomni/include/legoanimationmanager.h | 12 ++- LEGO1/lego/legoomni/include/legocarbuild.h | 2 +- LEGO1/lego/legoomni/include/legorace.h | 18 +++- LEGO1/lego/legoomni/include/legostate.h | 18 +++- LEGO1/lego/legoomni/include/pizza.h | 36 ++++++-- LEGO1/lego/legoomni/include/pizzeria.h | 2 +- LEGO1/lego/legoomni/include/police.h | 2 +- LEGO1/lego/legoomni/include/towtrack.h | 2 +- LEGO1/lego/legoomni/src/actors/ambulance.cpp | 34 +++++++- LEGO1/lego/legoomni/src/actors/pizza.cpp | 20 ++++- LEGO1/lego/legoomni/src/actors/pizzeria.cpp | 21 ++++- LEGO1/lego/legoomni/src/actors/towtrack.cpp | 67 ++++++--------- .../lego/legoomni/src/build/legocarbuild.cpp | 22 ++++- .../src/common/legoanimationmanager.cpp | 63 +++++++++++++- LEGO1/lego/legoomni/src/race/legorace.cpp | 13 ++- LEGO1/lego/legoomni/src/worlds/gasstation.cpp | 24 +++++- LEGO1/lego/legoomni/src/worlds/hospital.cpp | 42 ++++------ LEGO1/lego/legoomni/src/worlds/isle.cpp | 84 +++++++++---------- LEGO1/lego/legoomni/src/worlds/police.cpp | 11 ++- 23 files changed, 335 insertions(+), 168 deletions(-) diff --git a/LEGO1/lego/legoomni/include/ambulance.h b/LEGO1/lego/legoomni/include/ambulance.h index 3c6d8f0b..79091329 100644 --- a/LEGO1/lego/legoomni/include/ambulance.h +++ b/LEGO1/lego/legoomni/include/ambulance.h @@ -25,7 +25,7 @@ class AmbulanceMissionState : public LegoState { return !strcmp(p_name, AmbulanceMissionState::ClassName()) || LegoState::IsA(p_name); } - MxResult Serialize(LegoFile* p_legoFile) override; // vtable+0x1c + MxResult Serialize(LegoFile* p_file) override; // vtable+0x1c inline MxS16 GetHighScore(MxU8 p_actorId) { diff --git a/LEGO1/lego/legoomni/include/gasstation.h b/LEGO1/lego/legoomni/include/gasstation.h index 6a37db84..75234a25 100644 --- a/LEGO1/lego/legoomni/include/gasstation.h +++ b/LEGO1/lego/legoomni/include/gasstation.h @@ -33,7 +33,7 @@ class GasStationState : public LegoState { return !strcmp(p_name, GasStationState::ClassName()) || LegoState::IsA(p_name); } - MxResult Serialize(LegoFile* p_legoFile) override; // vtable+0x1c + MxResult Serialize(LegoFile* p_file) override; // vtable+0x1c // SYNTHETIC: LEGO1 0x10006290 // GasStationState::`scalar deleting destructor' diff --git a/LEGO1/lego/legoomni/include/hospital.h b/LEGO1/lego/legoomni/include/hospital.h index 32377fe3..4c453240 100644 --- a/LEGO1/lego/legoomni/include/hospital.h +++ b/LEGO1/lego/legoomni/include/hospital.h @@ -36,7 +36,7 @@ class HospitalState : public LegoState { return !strcmp(p_name, HospitalState::ClassName()) || LegoState::IsA(p_name); } - MxResult Serialize(LegoFile* p_legoFile) override; // vtable+0x1c + MxResult Serialize(LegoFile* p_file) override; // vtable+0x1c // SYNTHETIC: LEGO1 0x100764c0 // HospitalState::`scalar deleting destructor' diff --git a/LEGO1/lego/legoomni/include/isle.h b/LEGO1/lego/legoomni/include/isle.h index ee7a6363..d1faaa16 100644 --- a/LEGO1/lego/legoomni/include/isle.h +++ b/LEGO1/lego/legoomni/include/isle.h @@ -88,8 +88,8 @@ class Act1State : public LegoState { return !strcmp(p_name, Act1State::ClassName()) || LegoState::IsA(p_name); } - MxBool SetFlag() override; // vtable+0x18 - MxResult Serialize(LegoFile* p_legoFile) override; // vtable+0x1c + MxBool SetFlag() override; // vtable+0x18 + MxResult Serialize(LegoFile* p_file) override; // vtable+0x1c void FUN_10034660(); void FUN_100346a0(); diff --git a/LEGO1/lego/legoomni/include/legoanimationmanager.h b/LEGO1/lego/legoomni/include/legoanimationmanager.h index 8e473077..018a0059 100644 --- a/LEGO1/lego/legoomni/include/legoanimationmanager.h +++ b/LEGO1/lego/legoomni/include/legoanimationmanager.h @@ -68,8 +68,8 @@ class AnimState : public LegoState { return !strcmp(p_name, AnimState::ClassName()) || LegoState::IsA(p_name); } - MxBool SetFlag() override; // vtable+0x18 - MxResult Serialize(LegoFile* p_legoFile) override; // vtable+0x1c + MxBool SetFlag() override; // vtable+0x18 + MxResult Serialize(LegoFile* p_file) override; // vtable+0x1c void FUN_100651d0(MxU32, AnimInfo*, MxU32&); void FUN_10065240(MxU32, AnimInfo*, MxU32); @@ -79,10 +79,14 @@ class AnimState : public LegoState { private: undefined4 m_unk0x08; // 0x08 + // appears to store the length of m_unk0x10 undefined4 m_unk0x0c; // 0x0c - void* m_unk0x10; // 0x10 + // dynamically sized array of two-byte elements + undefined2* m_unk0x10; // 0x10 + // appears to store the length of m_unk0x18 undefined4 m_unk0x14; // 0x14 - void* m_unk0x18; // 0x18 + // dynamically sized array of one-byte elements + undefined* m_unk0x18; // 0x18 }; // VTABLE: LEGO1 0x100d8c18 diff --git a/LEGO1/lego/legoomni/include/legocarbuild.h b/LEGO1/lego/legoomni/include/legocarbuild.h index 30c064af..d11056c1 100644 --- a/LEGO1/lego/legoomni/include/legocarbuild.h +++ b/LEGO1/lego/legoomni/include/legocarbuild.h @@ -22,7 +22,7 @@ class LegoVehicleBuildState : public LegoState { return !strcmp(p_name, this->m_className.GetData()) || LegoState::IsA(p_name); } - MxResult Serialize(LegoFile* p_legoFile) override; // vtable+0x1c + MxResult Serialize(LegoFile* p_file) override; // vtable+0x1c // SYNTHETIC: LEGO1 0x100260a0 // LegoVehicleBuildState::`scalar deleting destructor' diff --git a/LEGO1/lego/legoomni/include/legorace.h b/LEGO1/lego/legoomni/include/legorace.h index 101c3ec3..84d3689a 100644 --- a/LEGO1/lego/legoomni/include/legorace.h +++ b/LEGO1/lego/legoomni/include/legorace.h @@ -25,6 +25,22 @@ class RaceState : public LegoState { inline MxS16 GetUnknown0x02() { return m_unk0x02; } inline MxS16 GetHighScore() { return m_score; } + inline MxResult Serialize(LegoFile* p_file) + { + if (p_file->IsReadMode()) { + Read(p_file, &m_id); + Read(p_file, &m_unk0x02); + Read(p_file, &m_score); + } + else if (p_file->IsWriteMode()) { + Write(p_file, m_id); + Write(p_file, m_unk0x02); + Write(p_file, m_score); + } + + return SUCCESS; + } + // TODO: Possibly private MxU8 m_id; // 0x00 MxS16 m_unk0x02; // 0x02 @@ -46,7 +62,7 @@ class RaceState : public LegoState { return !strcmp(p_name, RaceState::ClassName()) || LegoState::IsA(p_name); } - MxResult Serialize(LegoFile* p_legoFile) override; // vtable+0x1c + MxResult Serialize(LegoFile* p_file) override; // vtable+0x1c Entry* GetState(MxU8 p_id); diff --git a/LEGO1/lego/legoomni/include/legostate.h b/LEGO1/lego/legoomni/include/legostate.h index 1e149681..766da110 100644 --- a/LEGO1/lego/legoomni/include/legostate.h +++ b/LEGO1/lego/legoomni/include/legostate.h @@ -58,6 +58,18 @@ class LegoState : public MxCore { inline void SetUnknown0x08(MxS16 p_unk0x08) { m_nextIndex = p_unk0x08; } + inline MxResult ReadFromFile(LegoFile* p_file) + { + Read(p_file, &m_nextIndex); + return SUCCESS; + } + + inline MxResult WriteToFile(LegoFile* p_file) + { + Write(p_file, m_nextIndex); + return SUCCESS; + } + private: MxU32* m_objectIds; // 0x00 MxS16 m_length; // 0x04 @@ -88,10 +100,10 @@ class LegoState : public MxCore { virtual MxBool SetFlag() { return FALSE; } // vtable+0x18 // FUNCTION: LEGO1 0x10005fb0 - virtual MxResult Serialize(LegoFile* p_legoFile) + virtual MxResult Serialize(LegoFile* p_file) { - if (p_legoFile->IsWriteMode()) { - p_legoFile->WriteString(ClassName()); + if (p_file->IsWriteMode()) { + p_file->WriteString(ClassName()); } return SUCCESS; } // vtable+0x1c diff --git a/LEGO1/lego/legoomni/include/pizza.h b/LEGO1/lego/legoomni/include/pizza.h index ac6ad7bb..433b6f0f 100644 --- a/LEGO1/lego/legoomni/include/pizza.h +++ b/LEGO1/lego/legoomni/include/pizza.h @@ -15,11 +15,35 @@ class PizzaMissionState : public LegoState { // SIZE 0x20 struct Entry { public: - undefined2 m_unk0x00; // 0x00 - MxU8 m_id; // 0x02 - undefined m_unk0x03[0x15]; // 0x03 - MxS16 m_score; // 0x18 - undefined m_unk0x18[6]; // 0x1a + inline MxResult WriteToFile(LegoFile* p_file) + { + Write(p_file, m_unk0x06); + Write(p_file, m_unk0x14); + Write(p_file, m_unk0x16); + Write(p_file, m_score); + return SUCCESS; + } + + inline MxResult ReadFromFile(LegoFile* p_file) + { + Read(p_file, &m_unk0x06); + Read(p_file, &m_unk0x14); + Read(p_file, &m_unk0x16); + Read(p_file, &m_score); + return SUCCESS; + } + + undefined2 m_unk0x00; // 0x00 + MxU8 m_id; // 0x02 + undefined m_unk0x03[3]; // 0x03 + MxS16 m_unk0x06; // 0x06 + undefined m_unk0x08[8]; // 0x08 + MxS16 m_unk0x10; // 0x10 + MxS16 m_unk0x12; // 0x12 + MxS16 m_unk0x14; // 0x14 + MxS16 m_unk0x16; // 0x16 + MxS16 m_score; // 0x18 + undefined m_unk0x1a[6]; // 0x1a }; PizzaMissionState(); @@ -37,7 +61,7 @@ class PizzaMissionState : public LegoState { return !strcmp(p_name, PizzaMissionState::ClassName()) || LegoState::IsA(p_name); } - MxResult Serialize(LegoFile* p_legoFile) override; // vtable+0x1c + MxResult Serialize(LegoFile* p_file) override; // vtable+0x1c inline MxS16 GetHighScore(MxU8 p_id) { return GetState(p_id)->m_score; } diff --git a/LEGO1/lego/legoomni/include/pizzeria.h b/LEGO1/lego/legoomni/include/pizzeria.h index 46150249..2008f629 100644 --- a/LEGO1/lego/legoomni/include/pizzeria.h +++ b/LEGO1/lego/legoomni/include/pizzeria.h @@ -35,7 +35,7 @@ class PizzeriaState : public LegoState { return !strcmp(p_name, PizzeriaState::ClassName()) || LegoState::IsA(p_name); } - MxResult Serialize(LegoFile* p_legoFile) override; // vtable+0x1c + MxResult Serialize(LegoFile* p_file) override; // vtable+0x1c // SYNTHETIC: LEGO1 0x10017ce0 // PizzeriaState::`scalar deleting destructor' diff --git a/LEGO1/lego/legoomni/include/police.h b/LEGO1/lego/legoomni/include/police.h index 4c8c34eb..83394b1a 100644 --- a/LEGO1/lego/legoomni/include/police.h +++ b/LEGO1/lego/legoomni/include/police.h @@ -31,7 +31,7 @@ class PoliceState : public LegoState { return !strcmp(p_name, PoliceState::ClassName()) || LegoState::IsA(p_name); } - MxResult Serialize(LegoFile* p_legoFile) override; // vtable+0x1c + MxResult Serialize(LegoFile* p_file) override; // vtable+0x1c // SYNTHETIC: LEGO1 0x1005e920 // PoliceState::`scalar deleting destructor' diff --git a/LEGO1/lego/legoomni/include/towtrack.h b/LEGO1/lego/legoomni/include/towtrack.h index 31c1dc4b..3b3faafe 100644 --- a/LEGO1/lego/legoomni/include/towtrack.h +++ b/LEGO1/lego/legoomni/include/towtrack.h @@ -24,7 +24,7 @@ class TowTrackMissionState : public LegoState { return !strcmp(p_name, TowTrackMissionState::ClassName()) || LegoState::IsA(p_name); } - MxResult Serialize(LegoFile* p_legoFile) override; // vtable+0x1c + MxResult Serialize(LegoFile* p_file) override; // vtable+0x1c inline MxS16 GetHighScore(MxU8 p_id) { diff --git a/LEGO1/lego/legoomni/src/actors/ambulance.cpp b/LEGO1/lego/legoomni/src/actors/ambulance.cpp index 4b9f86a6..e4ea9b3b 100644 --- a/LEGO1/lego/legoomni/src/actors/ambulance.cpp +++ b/LEGO1/lego/legoomni/src/actors/ambulance.cpp @@ -642,9 +642,35 @@ AmbulanceMissionState::AmbulanceMissionState() m_laHighScore = 0; } -// STUB: LEGO1 0x10037440 -MxResult AmbulanceMissionState::Serialize(LegoFile* p_legoFile) +// FUNCTION: LEGO1 0x10037440 +MxResult AmbulanceMissionState::Serialize(LegoFile* p_file) { - // TODO - return LegoState::Serialize(p_legoFile); + LegoState::Serialize(p_file); + + if (p_file->IsReadMode()) { + Read(p_file, &m_peScore); + Read(p_file, &m_maScore); + Read(p_file, &m_paScore); + Read(p_file, &m_niScore); + Read(p_file, &m_laScore); + Read(p_file, &m_peHighScore); + Read(p_file, &m_maHighScore); + Read(p_file, &m_paHighScore); + Read(p_file, &m_niHighScore); + Read(p_file, &m_laHighScore); + } + else if (p_file->IsWriteMode()) { + Write(p_file, m_peScore); + Write(p_file, m_maScore); + Write(p_file, m_paScore); + Write(p_file, m_niScore); + Write(p_file, m_laScore); + Write(p_file, m_peHighScore); + Write(p_file, m_maHighScore); + Write(p_file, m_paHighScore); + Write(p_file, m_niHighScore); + Write(p_file, m_laHighScore); + } + + return SUCCESS; } diff --git a/LEGO1/lego/legoomni/src/actors/pizza.cpp b/LEGO1/lego/legoomni/src/actors/pizza.cpp index 0b783995..76588406 100644 --- a/LEGO1/lego/legoomni/src/actors/pizza.cpp +++ b/LEGO1/lego/legoomni/src/actors/pizza.cpp @@ -105,11 +105,23 @@ PizzaMissionState::PizzaMissionState() // TODO } -// STUB: LEGO1 0x100393c0 -MxResult PizzaMissionState::Serialize(LegoFile* p_legoFile) +// FUNCTION: LEGO1 0x100393c0 +MxResult PizzaMissionState::Serialize(LegoFile* p_file) { - // TODO - return LegoState::Serialize(p_legoFile); + LegoState::Serialize(p_file); + + if (p_file->IsReadMode()) { + for (MxS16 i = 0; i < 5; i++) { + m_state[i].ReadFromFile(p_file); + } + } + else if (p_file->IsWriteMode()) { + for (MxS16 i = 0; i < 5; i++) { + m_state[i].WriteToFile(p_file); + } + } + + return SUCCESS; } // FUNCTION: LEGO1 0x10039510 diff --git a/LEGO1/lego/legoomni/src/actors/pizzeria.cpp b/LEGO1/lego/legoomni/src/actors/pizzeria.cpp index a0cabb73..68484768 100644 --- a/LEGO1/lego/legoomni/src/actors/pizzeria.cpp +++ b/LEGO1/lego/legoomni/src/actors/pizzeria.cpp @@ -76,9 +76,22 @@ MxU32 PizzeriaState::FUN_10017d70() return 0; } -// STUB: LEGO1 0x10017da0 -MxResult PizzeriaState::Serialize(LegoFile* p_legoFile) +// FUNCTION: LEGO1 0x10017da0 +// FUNCTION: BETA10 0x100efe33 +MxResult PizzeriaState::Serialize(LegoFile* p_file) { - // TODO - return LegoState::Serialize(p_legoFile); + MxResult res = LegoState::Serialize(p_file); + + if (p_file->IsReadMode()) { + for (MxS16 i = 0; i < 5; i++) { + m_unk0x08[i].ReadFromFile(p_file); + } + } + else { + for (MxS16 i = 0; i < 5; i++) { + m_unk0x08[i].WriteToFile(p_file); + } + } + + return res; } diff --git a/LEGO1/lego/legoomni/src/actors/towtrack.cpp b/LEGO1/lego/legoomni/src/actors/towtrack.cpp index 1643230a..ba51a309 100644 --- a/LEGO1/lego/legoomni/src/actors/towtrack.cpp +++ b/LEGO1/lego/legoomni/src/actors/towtrack.cpp @@ -158,52 +158,33 @@ TowTrackMissionState::TowTrackMissionState() } // FUNCTION: LEGO1 0x1004dde0 -MxResult TowTrackMissionState::Serialize(LegoFile* p_legoFile) +MxResult TowTrackMissionState::Serialize(LegoFile* p_file) { - LegoState::Serialize(p_legoFile); + LegoState::Serialize(p_file); - if (p_legoFile->IsReadMode()) { - p_legoFile->Read(&m_unk0x12, sizeof(m_unk0x12)); - p_legoFile->Read(&m_unk0x14, sizeof(m_unk0x14)); - p_legoFile->Read(&m_unk0x16, sizeof(m_unk0x16)); - p_legoFile->Read(&m_unk0x18, sizeof(m_unk0x18)); - p_legoFile->Read(&m_unk0x1a, sizeof(m_unk0x1a)); - p_legoFile->Read(&m_score1, sizeof(m_score1)); - p_legoFile->Read(&m_score2, sizeof(m_score2)); - p_legoFile->Read(&m_score3, sizeof(m_score3)); - p_legoFile->Read(&m_score4, sizeof(m_score4)); - p_legoFile->Read(&m_score5, sizeof(m_score5)); + if (p_file->IsReadMode()) { + Read(p_file, &m_unk0x12); + Read(p_file, &m_unk0x14); + Read(p_file, &m_unk0x16); + Read(p_file, &m_unk0x18); + Read(p_file, &m_unk0x1a); + Read(p_file, &m_score1); + Read(p_file, &m_score2); + Read(p_file, &m_score3); + Read(p_file, &m_score4); + Read(p_file, &m_score5); } - else if (p_legoFile->IsWriteMode()) { - MxU16 write = m_unk0x12; - p_legoFile->Write(&write, sizeof(m_unk0x12)); - - write = m_unk0x14; - p_legoFile->Write(&write, sizeof(m_unk0x12)); - - write = m_unk0x16; - p_legoFile->Write(&write, sizeof(m_unk0x12)); - - write = m_unk0x18; - p_legoFile->Write(&write, sizeof(m_unk0x12)); - - write = m_unk0x1a; - p_legoFile->Write(&write, sizeof(m_unk0x12)); - - write = m_score1; - p_legoFile->Write(&write, sizeof(m_unk0x12)); - - write = m_score2; - p_legoFile->Write(&write, sizeof(m_unk0x12)); - - write = m_score3; - p_legoFile->Write(&write, sizeof(m_unk0x12)); - - write = m_score4; - p_legoFile->Write(&write, sizeof(m_unk0x12)); - - write = m_score5; - p_legoFile->Write(&write, sizeof(m_unk0x12)); + else if (p_file->IsWriteMode()) { + Write(p_file, m_unk0x12); + Write(p_file, m_unk0x14); + Write(p_file, m_unk0x16); + Write(p_file, m_unk0x18); + Write(p_file, m_unk0x1a); + Write(p_file, m_score1); + Write(p_file, m_score2); + Write(p_file, m_score3); + Write(p_file, m_score4); + Write(p_file, m_score5); } return SUCCESS; diff --git a/LEGO1/lego/legoomni/src/build/legocarbuild.cpp b/LEGO1/lego/legoomni/src/build/legocarbuild.cpp index 68bdc755..3eae3094 100644 --- a/LEGO1/lego/legoomni/src/build/legocarbuild.cpp +++ b/LEGO1/lego/legoomni/src/build/legocarbuild.cpp @@ -73,9 +73,23 @@ LegoVehicleBuildState::LegoVehicleBuildState(const char* p_classType) m_placedPartCount = 0; } -// STUB: LEGO1 0x10026120 -MxResult LegoVehicleBuildState::Serialize(LegoFile* p_legoFile) +// FUNCTION: LEGO1 0x10026120 +MxResult LegoVehicleBuildState::Serialize(LegoFile* p_file) { - // TODO - return LegoState::Serialize(p_legoFile); + LegoState::Serialize(p_file); + + if (p_file->IsReadMode()) { + Read(p_file, &m_unk0x4c); + Read(p_file, &m_unk0x4d); + Read(p_file, &m_unk0x4e); + Read(p_file, &m_placedPartCount); + } + else { + Write(p_file, m_unk0x4c); + Write(p_file, m_unk0x4d); + Write(p_file, m_unk0x4e); + Write(p_file, m_placedPartCount); + } + + return SUCCESS; } diff --git a/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp b/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp index dce362c3..3c4545b5 100644 --- a/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp @@ -2850,11 +2850,66 @@ void AnimState::FUN_10065240(MxU32, AnimInfo*, MxU32) // TODO } -// STUB: LEGO1 0x100652d0 -MxResult AnimState::Serialize(LegoFile* p_legoFile) +// FUNCTION: LEGO1 0x100652d0 +// FUNCTION: BETA10 0x10046621 +MxResult AnimState::Serialize(LegoFile* p_file) { - // TODO - return LegoState::Serialize(p_legoFile); + // These two are equivalent up to the order of some deallocation. + // Choose as needed to get 100 %. + // Option 1: + // LegoState::Serialize(p_file); + // Option 2: + if (p_file->IsWriteMode()) { + p_file->WriteString(ClassName()); + } + + if (p_file->IsReadMode()) { + Read(p_file, &m_unk0x08); + + // m_unk0x10_len and m_unk0x10 + if (m_unk0x10) { + delete[] m_unk0x10; + } + Read(p_file, &m_unk0x0c); + if (m_unk0x0c != 0) { + m_unk0x10 = new undefined2[m_unk0x0c]; + } + else { + m_unk0x10 = NULL; + } + for (MxS32 i = 0; i < m_unk0x0c; i++) { + Read(p_file, &m_unk0x10[i]); + } + + // m_unk0x18_len and m_unk0x18 + // Note that here we read first and then free memory in contrast to above + Read(p_file, &m_unk0x14); + if (m_unk0x18) { + delete[] m_unk0x18; + } + if (m_unk0x14 != 0) { + m_unk0x18 = new undefined[m_unk0x14]; + } + else { + m_unk0x18 = NULL; + } + for (MxS32 j = 0; j < m_unk0x14; j++) { + Read(p_file, &m_unk0x18[j]); + } + } + else if (p_file->IsWriteMode()) { + Write(p_file, m_unk0x08); + Write(p_file, m_unk0x0c); + for (MxS32 i = 0; i < m_unk0x0c; i++) { + Write(p_file, m_unk0x10[i]); + } + Write(p_file, m_unk0x14); + for (MxS32 j = 0; j < m_unk0x14; j++) { + Write(p_file, m_unk0x18[j]); + } + } + + return SUCCESS; } // STUB: LEGO1 0x100654f0 diff --git a/LEGO1/lego/legoomni/src/race/legorace.cpp b/LEGO1/lego/legoomni/src/race/legorace.cpp index e1e39afc..ccb6ceda 100644 --- a/LEGO1/lego/legoomni/src/race/legorace.cpp +++ b/LEGO1/lego/legoomni/src/race/legorace.cpp @@ -134,11 +134,16 @@ RaceState::RaceState() // TODO } -// STUB: LEGO1 0x10016140 -MxResult RaceState::Serialize(LegoFile* p_legoFile) +// FUNCTION: LEGO1 0x10016140 +MxResult RaceState::Serialize(LegoFile* p_file) { - // TODO - return LegoState::Serialize(p_legoFile); + LegoState::Serialize(p_file); + + for (MxS16 i = 0; i < 5; i++) { + m_state[i].Serialize(p_file); + } + + return SUCCESS; } // FUNCTION: LEGO1 0x10016280 diff --git a/LEGO1/lego/legoomni/src/worlds/gasstation.cpp b/LEGO1/lego/legoomni/src/worlds/gasstation.cpp index f5383ee9..aadf6b1c 100644 --- a/LEGO1/lego/legoomni/src/worlds/gasstation.cpp +++ b/LEGO1/lego/legoomni/src/worlds/gasstation.cpp @@ -435,11 +435,27 @@ GasStationState::GasStationState() unk0x08[2] = -1; } -// STUB: LEGO1 0x10006300 -MxResult GasStationState::Serialize(LegoFile* p_legoFile) +// FUNCTION: LEGO1 0x10006300 +MxResult GasStationState::Serialize(LegoFile* p_file) { - // TODO - return LegoState::Serialize(p_legoFile); + LegoState::Serialize(p_file); + + if (p_file->IsWriteMode()) { + Write(p_file, m_unk0x18); + Write(p_file, m_unk0x1a); + Write(p_file, m_unk0x1c); + Write(p_file, m_unk0x1e); + Write(p_file, m_unk0x20); + } + else if (p_file->IsReadMode()) { + Read(p_file, &m_unk0x18); + Read(p_file, &m_unk0x1a); + Read(p_file, &m_unk0x1c); + Read(p_file, &m_unk0x1e); + Read(p_file, &m_unk0x20); + } + + return SUCCESS; } // STUB: LEGO1 0x10006430 diff --git a/LEGO1/lego/legoomni/src/worlds/hospital.cpp b/LEGO1/lego/legoomni/src/worlds/hospital.cpp index e08a39c6..f29fe3df 100644 --- a/LEGO1/lego/legoomni/src/worlds/hospital.cpp +++ b/LEGO1/lego/legoomni/src/worlds/hospital.cpp @@ -684,35 +684,25 @@ HospitalState::HospitalState() } // FUNCTION: LEGO1 0x10076530 -MxResult HospitalState::Serialize(LegoFile* p_legoFile) +MxResult HospitalState::Serialize(LegoFile* p_file) { - LegoState::Serialize(p_legoFile); + LegoState::Serialize(p_file); - if (p_legoFile->IsWriteMode()) { - // A write variable needs to be used here, otherwise - // the compiler aggresively optimizes the function - MxS16 write; - - write = m_unk0x0c; - p_legoFile->Write(&write, sizeof(m_unk0x0c)); - write = m_unk0x0e; - p_legoFile->Write(&write, sizeof(m_unk0x0e)); - write = m_unk0x10; - p_legoFile->Write(&write, sizeof(m_unk0x10)); - write = m_unk0x12; - p_legoFile->Write(&write, sizeof(m_unk0x12)); - write = m_unk0x14; - p_legoFile->Write(&write, sizeof(m_unk0x14)); - write = m_unk0x16; - p_legoFile->Write(&write, sizeof(m_unk0x16)); + if (p_file->IsWriteMode()) { + Write(p_file, m_unk0x0c); + Write(p_file, m_unk0x0e); + Write(p_file, m_unk0x10); + Write(p_file, m_unk0x12); + Write(p_file, m_unk0x14); + Write(p_file, m_unk0x16); } - else if (p_legoFile->IsReadMode()) { - p_legoFile->Read(&m_unk0x0c, sizeof(m_unk0x0c)); - p_legoFile->Read(&m_unk0x0e, sizeof(m_unk0x0e)); - p_legoFile->Read(&m_unk0x10, sizeof(m_unk0x10)); - p_legoFile->Read(&m_unk0x12, sizeof(m_unk0x12)); - p_legoFile->Read(&m_unk0x14, sizeof(m_unk0x14)); - p_legoFile->Read(&m_unk0x16, sizeof(m_unk0x16)); + else if (p_file->IsReadMode()) { + Read(p_file, &m_unk0x0c); + Read(p_file, &m_unk0x0e); + Read(p_file, &m_unk0x10); + Read(p_file, &m_unk0x12); + Read(p_file, &m_unk0x14); + Read(p_file, &m_unk0x16); } return SUCCESS; diff --git a/LEGO1/lego/legoomni/src/worlds/isle.cpp b/LEGO1/lego/legoomni/src/worlds/isle.cpp index d6a066fc..b542afac 100644 --- a/LEGO1/lego/legoomni/src/worlds/isle.cpp +++ b/LEGO1/lego/legoomni/src/worlds/isle.cpp @@ -1314,138 +1314,138 @@ Act1State::Act1State() : m_unk0x00c(0), m_unk0x00e(0), m_unk0x008(NULL), m_unk0x } // FUNCTION: LEGO1 0x10033ac0 -MxResult Act1State::Serialize(LegoFile* p_legoFile) +MxResult Act1State::Serialize(LegoFile* p_file) { - LegoState::Serialize(p_legoFile); + LegoState::Serialize(p_file); - m_unk0x024.Serialize(p_legoFile); - m_unk0x070.Serialize(p_legoFile); - m_unk0x0bc.Serialize(p_legoFile); - m_unk0x108.Serialize(p_legoFile); - m_unk0x164.Serialize(p_legoFile); - m_unk0x1bc.Serialize(p_legoFile); - m_unk0x210.Serialize(p_legoFile); + m_unk0x024.Serialize(p_file); + m_unk0x070.Serialize(p_file); + m_unk0x0bc.Serialize(p_file); + m_unk0x108.Serialize(p_file); + m_unk0x164.Serialize(p_file); + m_unk0x1bc.Serialize(p_file); + m_unk0x210.Serialize(p_file); - if (p_legoFile->IsWriteMode()) { + if (p_file->IsWriteMode()) { if (m_unk0x108.GetName()->Compare("") != 0) { if (m_unk0x154) { - WriteNamedTexture(p_legoFile, m_unk0x154); + WriteNamedTexture(p_file, m_unk0x154); } else { - FUN_1003f540(p_legoFile, "chwind.gif"); + FUN_1003f540(p_file, "chwind.gif"); } if (m_unk0x158) { - WriteNamedTexture(p_legoFile, m_unk0x158); + WriteNamedTexture(p_file, m_unk0x158); } else { - FUN_1003f540(p_legoFile, "chjetl.gif"); + FUN_1003f540(p_file, "chjetl.gif"); } if (m_unk0x15c) { - WriteNamedTexture(p_legoFile, m_unk0x15c); + WriteNamedTexture(p_file, m_unk0x15c); } else { - FUN_1003f540(p_legoFile, "chjetr.gif"); + FUN_1003f540(p_file, "chjetr.gif"); } } if (m_unk0x164.GetName()->Compare("") != 0) { if (m_unk0x1b0) { - WriteNamedTexture(p_legoFile, m_unk0x1b0); + WriteNamedTexture(p_file, m_unk0x1b0); } else { - FUN_1003f540(p_legoFile, "jsfrnt.gif"); + FUN_1003f540(p_file, "jsfrnt.gif"); } if (m_unk0x1b4) { - WriteNamedTexture(p_legoFile, m_unk0x1b4); + WriteNamedTexture(p_file, m_unk0x1b4); } else { - FUN_1003f540(p_legoFile, "jswnsh.gif"); + FUN_1003f540(p_file, "jswnsh.gif"); } } if (m_unk0x1bc.GetName()->Compare("") != 0) { if (m_unk0x208) { - WriteNamedTexture(p_legoFile, m_unk0x208); + WriteNamedTexture(p_file, m_unk0x208); } else { - FUN_1003f540(p_legoFile, "dbfrfn.gif"); + FUN_1003f540(p_file, "dbfrfn.gif"); } } if (m_unk0x210.GetName()->Compare("") != 0) { if (m_unk0x25c) { - WriteNamedTexture(p_legoFile, m_unk0x25c); + WriteNamedTexture(p_file, m_unk0x25c); } else { - FUN_1003f540(p_legoFile, "rcfrnt.gif"); + FUN_1003f540(p_file, "rcfrnt.gif"); } if (m_unk0x260) { - WriteNamedTexture(p_legoFile, m_unk0x260); + WriteNamedTexture(p_file, m_unk0x260); } else { - FUN_1003f540(p_legoFile, "rcback.gif"); + FUN_1003f540(p_file, "rcback.gif"); } if (m_unk0x264) { - WriteNamedTexture(p_legoFile, m_unk0x264); + WriteNamedTexture(p_file, m_unk0x264); } else { - FUN_1003f540(p_legoFile, "rctail.gif"); + FUN_1003f540(p_file, "rctail.gif"); } } - p_legoFile->Write(&m_unk0x010, sizeof(m_unk0x010)); - p_legoFile->Write(&m_unk0x022, sizeof(m_unk0x022)); + Write(p_file, m_unk0x010); + Write(p_file, m_unk0x022); } - else if (p_legoFile->IsReadMode()) { + else if (p_file->IsReadMode()) { if (m_unk0x108.GetName()->Compare("") != 0) { - m_unk0x154 = ReadNamedTexture(p_legoFile); + m_unk0x154 = ReadNamedTexture(p_file); if (m_unk0x154 == NULL) { return FAILURE; } - m_unk0x158 = ReadNamedTexture(p_legoFile); + m_unk0x158 = ReadNamedTexture(p_file); if (m_unk0x158 == NULL) { return FAILURE; } - m_unk0x15c = ReadNamedTexture(p_legoFile); + m_unk0x15c = ReadNamedTexture(p_file); if (m_unk0x15c == NULL) { return FAILURE; } } if (m_unk0x164.GetName()->Compare("") != 0) { - m_unk0x1b0 = ReadNamedTexture(p_legoFile); + m_unk0x1b0 = ReadNamedTexture(p_file); if (m_unk0x1b0 == NULL) { return FAILURE; } - m_unk0x1b4 = ReadNamedTexture(p_legoFile); + m_unk0x1b4 = ReadNamedTexture(p_file); if (m_unk0x1b4 == NULL) { return FAILURE; } } if (m_unk0x1bc.GetName()->Compare("") != 0) { - m_unk0x208 = ReadNamedTexture(p_legoFile); + m_unk0x208 = ReadNamedTexture(p_file); if (m_unk0x208 == NULL) { return FAILURE; } } if (m_unk0x210.GetName()->Compare("") != 0) { - m_unk0x25c = ReadNamedTexture(p_legoFile); + m_unk0x25c = ReadNamedTexture(p_file); if (m_unk0x25c == NULL) { return FAILURE; } - m_unk0x260 = ReadNamedTexture(p_legoFile); + m_unk0x260 = ReadNamedTexture(p_file); if (m_unk0x260 == NULL) { return FAILURE; } - m_unk0x264 = ReadNamedTexture(p_legoFile); + m_unk0x264 = ReadNamedTexture(p_file); if (m_unk0x264 == NULL) { return FAILURE; } } - p_legoFile->Read(&m_unk0x010, sizeof(m_unk0x010)); - p_legoFile->Read(&m_unk0x022, sizeof(m_unk0x022)); + Read(p_file, &m_unk0x010); + Read(p_file, &m_unk0x022); } // TODO diff --git a/LEGO1/lego/legoomni/src/worlds/police.cpp b/LEGO1/lego/legoomni/src/worlds/police.cpp index 66422959..1af480a8 100644 --- a/LEGO1/lego/legoomni/src/worlds/police.cpp +++ b/LEGO1/lego/legoomni/src/worlds/police.cpp @@ -206,16 +206,15 @@ PoliceState::PoliceState() } // FUNCTION: LEGO1 0x1005e990 -MxResult PoliceState::Serialize(LegoFile* p_legoFile) +MxResult PoliceState::Serialize(LegoFile* p_file) { - LegoState::Serialize(p_legoFile); + LegoState::Serialize(p_file); - if (p_legoFile->IsReadMode()) { - p_legoFile->Read(&m_policeScript, sizeof(m_policeScript)); + if (p_file->IsReadMode()) { + Read(p_file, &m_policeScript); } else { - PoliceScript::Script policeScript = m_policeScript; - p_legoFile->Write(&policeScript, sizeof(m_policeScript)); + Write(p_file, m_policeScript); } return SUCCESS;