Add remaining Serialize implementations

This commit is contained in:
Christian Semmler 2025-01-15 15:32:36 -07:00
parent 78ee2de392
commit 1a2b2f1a20
4 changed files with 38 additions and 66 deletions

View File

@ -214,7 +214,7 @@ class LegoGameState {
// TODO: Most likely getters/setters are not used according to BETA for the following members: // TODO: Most likely getters/setters are not used according to BETA for the following members:
public: public:
MxU16 m_unk0x24; // 0x24 MxS16 m_unk0x24; // 0x24
MxS16 m_playerCount; // 0x26 MxS16 m_playerCount; // 0x26
Username m_players[9]; // 0x28 Username m_players[9]; // 0x28
History m_history; // 0xa6 History m_history; // 0xa6

View File

@ -93,24 +93,6 @@ class PizzaMissionState : public LegoState {
// FUNCTION: BETA10 0x100ef7e0 // FUNCTION: BETA10 0x100ef7e0
MxLong GetTimeoutTime() { return m_finishTimes[3]; } 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 MxS16 m_numActions; // 0x00
MxU8 m_actorId; // 0x02 MxU8 m_actorId; // 0x02
undefined2 m_unk0x04; // 0x04 undefined2 m_unk0x04; // 0x04

View File

@ -171,6 +171,7 @@ LegoGameState::~LegoGameState()
} }
// FUNCTION: LEGO1 0x10039780 // FUNCTION: LEGO1 0x10039780
// FUNCTION: BETA10 0x10083d43
void LegoGameState::SetActor(MxU8 p_actorId) void LegoGameState::SetActor(MxU8 p_actorId)
{ {
if (p_actorId) { if (p_actorId) {
@ -238,7 +239,7 @@ MxResult LegoGameState::Save(MxULong p_slot)
} }
MxResult result = FAILURE; MxResult result = FAILURE;
LegoFile fileStorage; LegoFile storage;
MxVariableTable* variableTable = VariableTable(); MxVariableTable* variableTable = VariableTable();
MxS16 count = 0; MxS16 count = 0;
MxU32 i; MxU32 i;
@ -248,32 +249,32 @@ MxResult LegoGameState::Save(MxULong p_slot)
MxString savePath; MxString savePath;
GetFileSavePath(&savePath, p_slot); GetFileSavePath(&savePath, p_slot);
if (fileStorage.Open(savePath.GetData(), LegoFile::c_write) == FAILURE) { if (storage.Open(savePath.GetData(), LegoFile::c_write) == FAILURE) {
goto done; goto done;
} }
Write(&fileStorage, 0x1000c); storage.Write(0x1000c);
Write(&fileStorage, m_unk0x24); storage.Write(m_unk0x24);
Write(&fileStorage, (MxU16) m_currentAct); storage.Write((MxU16) m_currentAct);
Write(&fileStorage, m_actorId); storage.Write(m_actorId);
for (i = 0; i < sizeOfArray(g_colorSaveData); i++) { 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; goto done;
} }
} }
if (WriteVariable(&fileStorage, variableTable, "backgroundcolor") == FAILURE) { if (WriteVariable(&storage, variableTable, "backgroundcolor") == FAILURE) {
goto done; goto done;
} }
if (WriteVariable(&fileStorage, variableTable, "lightposition") == FAILURE) { if (WriteVariable(&storage, variableTable, "lightposition") == FAILURE) {
goto done; goto done;
} }
WriteEndOfVariables(&fileStorage); WriteEndOfVariables(&storage);
CharacterManager()->Write(&fileStorage); CharacterManager()->Write(&storage);
PlantManager()->Write(&fileStorage); PlantManager()->Write(&storage);
result = BuildingManager()->Write(&fileStorage); result = BuildingManager()->Write(&storage);
for (j = 0; j < m_stateCount; j++) { for (j = 0; j < m_stateCount; j++) {
if (m_stateArray[j]->IsSerializable()) { 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++) { for (j = 0; j < m_stateCount; j++) {
if (m_stateArray[j]->IsSerializable()) { if (m_stateArray[j]->IsSerializable()) {
m_stateArray[j]->Serialize(&fileStorage); m_stateArray[j]->Serialize(&storage);
} }
} }
area = m_unk0x42c; area = m_unk0x42c;
Write(&fileStorage, (MxU16) area); storage.Write((MxU16) area);
SerializeScoreHistory(2); SerializeScoreHistory(2);
m_isDirty = FALSE; m_isDirty = FALSE;
@ -322,42 +323,43 @@ MxResult LegoGameState::DeleteState()
} }
// FUNCTION: LEGO1 0x10039c60 // FUNCTION: LEGO1 0x10039c60
// FUNCTION: BETA10 0x10084329
MxResult LegoGameState::Load(MxULong p_slot) MxResult LegoGameState::Load(MxULong p_slot)
{ {
MxResult result = FAILURE; MxResult result = FAILURE;
LegoFile fileStorage; LegoFile storage;
MxVariableTable* variableTable = VariableTable(); MxVariableTable* variableTable = VariableTable();
MxString savePath; MxString savePath;
GetFileSavePath(&savePath, p_slot); GetFileSavePath(&savePath, p_slot);
if (fileStorage.Open(savePath.GetData(), LegoFile::c_read) == FAILURE) { if (storage.Open(savePath.GetData(), LegoFile::c_read) == FAILURE) {
goto done; goto done;
} }
MxU32 version, status; MxS32 version;
MxU32 status;
MxS16 count, actArea; MxS16 count, actArea;
const char* lightPosition; const char* lightPosition;
Read(&fileStorage, &version); storage.Read(version);
if (version != 0x1000c) { if (version != 0x1000c) {
OmniError("Saved game version mismatch", 0); OmniError("Saved game version mismatch", 0);
goto done; goto done;
} }
Read(&fileStorage, &m_unk0x24); storage.Read(m_unk0x24);
storage.Read(actArea);
Read(&fileStorage, &actArea);
SetCurrentAct((Act) actArea); SetCurrentAct((Act) actArea);
storage.Read(m_actorId);
Read(&fileStorage, &m_actorId);
if (m_actorId) { if (m_actorId) {
SetActor(m_actorId); SetActor(m_actorId);
} }
do { do {
status = ReadVariable(&fileStorage, variableTable); status = ReadVariable(&storage, variableTable);
if (status == 1) { if (status == 1) {
goto done; goto done;
} }
@ -370,13 +372,13 @@ MxResult LegoGameState::Load(MxULong p_slot)
SetLightPosition(atoi(lightPosition)); SetLightPosition(atoi(lightPosition));
} }
if (CharacterManager()->Read(&fileStorage) == FAILURE) { if (CharacterManager()->Read(&storage) == FAILURE) {
goto done; goto done;
} }
if (PlantManager()->Read(&fileStorage) == FAILURE) { if (PlantManager()->Read(&storage) == FAILURE) {
goto done; goto done;
} }
if (BuildingManager()->Read(&fileStorage) == FAILURE) { if (BuildingManager()->Read(&storage) == FAILURE) {
goto done; goto done;
} }
if (DeleteState() != SUCCESS) { if (DeleteState() != SUCCESS) {
@ -384,13 +386,13 @@ MxResult LegoGameState::Load(MxULong p_slot)
} }
char stateName[80]; char stateName[80];
Read(&fileStorage, &count); storage.Read(count);
if (count) { if (count) {
for (MxS16 i = 0; i < count; i++) { for (MxS16 i = 0; i < count; i++) {
MxS16 stateNameLength; MxS16 stateNameLength;
Read(&fileStorage, &stateNameLength); storage.Read(stateNameLength);
Read(&fileStorage, stateName, (MxULong) stateNameLength); storage.Read(stateName, (MxULong) stateNameLength);
stateName[stateNameLength] = 0; stateName[stateNameLength] = 0;
LegoState* state = GetState(stateName); 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) { if (m_currentAct == e_act1) {
m_unk0x42c = e_undefined; m_unk0x42c = e_undefined;
@ -537,10 +539,10 @@ void LegoGameState::SerializePlayersInfo(MxS16 p_flags)
if (fileStorage.Open(playersGSI.GetData(), p_flags) == SUCCESS) { if (fileStorage.Open(playersGSI.GetData(), p_flags) == SUCCESS) {
if (fileStorage.IsReadMode()) { if (fileStorage.IsReadMode()) {
Read(&fileStorage, &m_playerCount); fileStorage.Read(m_playerCount);
} }
else if (fileStorage.IsWriteMode()) { else if (fileStorage.IsWriteMode()) {
Write(&fileStorage, m_playerCount); fileStorage.Write(m_playerCount);
} }
for (MxS16 i = 0; i < m_playerCount; i++) { for (MxS16 i = 0; i < m_playerCount; i++) {

View File

@ -40,18 +40,6 @@ class LegoStorage {
LegoU8 m_mode; // 0x04 LegoU8 m_mode; // 0x04
}; };
template <class T>
inline void Read(LegoStorage* p_storage, T* p_variable, LegoU32 p_size = sizeof(T))
{
p_storage->Read(p_variable, p_size);
}
template <class T>
inline void Write(LegoStorage* p_storage, T p_variable)
{
p_storage->Write(&p_variable, sizeof(p_variable));
}
// VTABLE: LEGO1 0x100db710 // VTABLE: LEGO1 0x100db710
// SIZE 0x10 // SIZE 0x10
class LegoMemory : public LegoStorage { class LegoMemory : public LegoStorage {