From 1a2b2f1a2075cd236bf388090a6d122082687cb3 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Wed, 15 Jan 2025 15:32:36 -0700 Subject: [PATCH] Add remaining Serialize implementations --- LEGO1/lego/legoomni/include/legogamestate.h | 2 +- LEGO1/lego/legoomni/include/pizza.h | 18 ----- .../legoomni/src/common/legogamestate.cpp | 72 ++++++++++--------- LEGO1/lego/sources/misc/legostorage.h | 12 ---- 4 files changed, 38 insertions(+), 66 deletions(-) diff --git a/LEGO1/lego/legoomni/include/legogamestate.h b/LEGO1/lego/legoomni/include/legogamestate.h index 731a0e4a..858c13e6 100644 --- a/LEGO1/lego/legoomni/include/legogamestate.h +++ b/LEGO1/lego/legoomni/include/legogamestate.h @@ -214,7 +214,7 @@ class LegoGameState { // TODO: Most likely getters/setters are not used according to BETA for the following members: public: - MxU16 m_unk0x24; // 0x24 + MxS16 m_unk0x24; // 0x24 MxS16 m_playerCount; // 0x26 Username m_players[9]; // 0x28 History m_history; // 0xa6 diff --git a/LEGO1/lego/legoomni/include/pizza.h b/LEGO1/lego/legoomni/include/pizza.h index b08e5310..855f2b59 100644 --- a/LEGO1/lego/legoomni/include/pizza.h +++ b/LEGO1/lego/legoomni/include/pizza.h @@ -93,24 +93,6 @@ class PizzaMissionState : public LegoState { // FUNCTION: BETA10 0x100ef7e0 MxLong GetTimeoutTime() { return m_finishTimes[3]; } - MxResult WriteToFile(LegoFile* p_file) - { - Write(p_file, m_unk0x06); - Write(p_file, m_unk0x14); - Write(p_file, m_score); - Write(p_file, m_hiScore); - return SUCCESS; - } - - MxResult ReadFromFile(LegoFile* p_file) - { - Read(p_file, &m_unk0x06); - Read(p_file, &m_unk0x14); - Read(p_file, &m_score); - Read(p_file, &m_hiScore); - return SUCCESS; - } - MxS16 m_numActions; // 0x00 MxU8 m_actorId; // 0x02 undefined2 m_unk0x04; // 0x04 diff --git a/LEGO1/lego/legoomni/src/common/legogamestate.cpp b/LEGO1/lego/legoomni/src/common/legogamestate.cpp index ceb26765..a24b2e19 100644 --- a/LEGO1/lego/legoomni/src/common/legogamestate.cpp +++ b/LEGO1/lego/legoomni/src/common/legogamestate.cpp @@ -171,6 +171,7 @@ LegoGameState::~LegoGameState() } // FUNCTION: LEGO1 0x10039780 +// FUNCTION: BETA10 0x10083d43 void LegoGameState::SetActor(MxU8 p_actorId) { if (p_actorId) { @@ -238,7 +239,7 @@ MxResult LegoGameState::Save(MxULong p_slot) } MxResult result = FAILURE; - LegoFile fileStorage; + LegoFile storage; MxVariableTable* variableTable = VariableTable(); MxS16 count = 0; MxU32 i; @@ -248,32 +249,32 @@ MxResult LegoGameState::Save(MxULong p_slot) MxString savePath; GetFileSavePath(&savePath, p_slot); - if (fileStorage.Open(savePath.GetData(), LegoFile::c_write) == FAILURE) { + if (storage.Open(savePath.GetData(), LegoFile::c_write) == FAILURE) { goto done; } - Write(&fileStorage, 0x1000c); - Write(&fileStorage, m_unk0x24); - Write(&fileStorage, (MxU16) m_currentAct); - Write(&fileStorage, m_actorId); + storage.Write(0x1000c); + storage.Write(m_unk0x24); + storage.Write((MxU16) m_currentAct); + storage.Write(m_actorId); for (i = 0; i < sizeOfArray(g_colorSaveData); i++) { - if (WriteVariable(&fileStorage, variableTable, g_colorSaveData[i].m_targetName) == FAILURE) { + if (WriteVariable(&storage, variableTable, g_colorSaveData[i].m_targetName) == FAILURE) { goto done; } } - if (WriteVariable(&fileStorage, variableTable, "backgroundcolor") == FAILURE) { + if (WriteVariable(&storage, variableTable, "backgroundcolor") == FAILURE) { goto done; } - if (WriteVariable(&fileStorage, variableTable, "lightposition") == FAILURE) { + if (WriteVariable(&storage, variableTable, "lightposition") == FAILURE) { goto done; } - WriteEndOfVariables(&fileStorage); - CharacterManager()->Write(&fileStorage); - PlantManager()->Write(&fileStorage); - result = BuildingManager()->Write(&fileStorage); + WriteEndOfVariables(&storage); + CharacterManager()->Write(&storage); + PlantManager()->Write(&storage); + result = BuildingManager()->Write(&storage); for (j = 0; j < m_stateCount; j++) { if (m_stateArray[j]->IsSerializable()) { @@ -281,16 +282,16 @@ MxResult LegoGameState::Save(MxULong p_slot) } } - Write(&fileStorage, count); + storage.Write(count); for (j = 0; j < m_stateCount; j++) { if (m_stateArray[j]->IsSerializable()) { - m_stateArray[j]->Serialize(&fileStorage); + m_stateArray[j]->Serialize(&storage); } } area = m_unk0x42c; - Write(&fileStorage, (MxU16) area); + storage.Write((MxU16) area); SerializeScoreHistory(2); m_isDirty = FALSE; @@ -322,42 +323,43 @@ MxResult LegoGameState::DeleteState() } // FUNCTION: LEGO1 0x10039c60 +// FUNCTION: BETA10 0x10084329 MxResult LegoGameState::Load(MxULong p_slot) { MxResult result = FAILURE; - LegoFile fileStorage; + LegoFile storage; MxVariableTable* variableTable = VariableTable(); MxString savePath; GetFileSavePath(&savePath, p_slot); - if (fileStorage.Open(savePath.GetData(), LegoFile::c_read) == FAILURE) { + if (storage.Open(savePath.GetData(), LegoFile::c_read) == FAILURE) { goto done; } - MxU32 version, status; + MxS32 version; + MxU32 status; MxS16 count, actArea; const char* lightPosition; - Read(&fileStorage, &version); + storage.Read(version); if (version != 0x1000c) { OmniError("Saved game version mismatch", 0); goto done; } - Read(&fileStorage, &m_unk0x24); + storage.Read(m_unk0x24); + storage.Read(actArea); - Read(&fileStorage, &actArea); SetCurrentAct((Act) actArea); - - Read(&fileStorage, &m_actorId); + storage.Read(m_actorId); if (m_actorId) { SetActor(m_actorId); } do { - status = ReadVariable(&fileStorage, variableTable); + status = ReadVariable(&storage, variableTable); if (status == 1) { goto done; } @@ -370,13 +372,13 @@ MxResult LegoGameState::Load(MxULong p_slot) SetLightPosition(atoi(lightPosition)); } - if (CharacterManager()->Read(&fileStorage) == FAILURE) { + if (CharacterManager()->Read(&storage) == FAILURE) { goto done; } - if (PlantManager()->Read(&fileStorage) == FAILURE) { + if (PlantManager()->Read(&storage) == FAILURE) { goto done; } - if (BuildingManager()->Read(&fileStorage) == FAILURE) { + if (BuildingManager()->Read(&storage) == FAILURE) { goto done; } if (DeleteState() != SUCCESS) { @@ -384,13 +386,13 @@ MxResult LegoGameState::Load(MxULong p_slot) } char stateName[80]; - Read(&fileStorage, &count); + storage.Read(count); if (count) { for (MxS16 i = 0; i < count; i++) { MxS16 stateNameLength; - Read(&fileStorage, &stateNameLength); - Read(&fileStorage, stateName, (MxULong) stateNameLength); + storage.Read(stateNameLength); + storage.Read(stateName, (MxULong) stateNameLength); stateName[stateNameLength] = 0; LegoState* state = GetState(stateName); @@ -402,11 +404,11 @@ MxResult LegoGameState::Load(MxULong p_slot) } } - state->Serialize(&fileStorage); + state->Serialize(&storage); } } - Read(&fileStorage, &actArea); + storage.Read(actArea); if (m_currentAct == e_act1) { m_unk0x42c = e_undefined; @@ -537,10 +539,10 @@ void LegoGameState::SerializePlayersInfo(MxS16 p_flags) if (fileStorage.Open(playersGSI.GetData(), p_flags) == SUCCESS) { if (fileStorage.IsReadMode()) { - Read(&fileStorage, &m_playerCount); + fileStorage.Read(m_playerCount); } else if (fileStorage.IsWriteMode()) { - Write(&fileStorage, m_playerCount); + fileStorage.Write(m_playerCount); } for (MxS16 i = 0; i < m_playerCount; i++) { diff --git a/LEGO1/lego/sources/misc/legostorage.h b/LEGO1/lego/sources/misc/legostorage.h index 9c1e957a..fa7f6ae4 100644 --- a/LEGO1/lego/sources/misc/legostorage.h +++ b/LEGO1/lego/sources/misc/legostorage.h @@ -40,18 +40,6 @@ class LegoStorage { LegoU8 m_mode; // 0x04 }; -template -inline void Read(LegoStorage* p_storage, T* p_variable, LegoU32 p_size = sizeof(T)) -{ - p_storage->Read(p_variable, p_size); -} - -template -inline void Write(LegoStorage* p_storage, T p_variable) -{ - p_storage->Write(&p_variable, sizeof(p_variable)); -} - // VTABLE: LEGO1 0x100db710 // SIZE 0x10 class LegoMemory : public LegoStorage {