From 2e2e887428087e5ec985394a28ea087fe7ad5a72 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Tue, 27 Feb 2024 14:02:16 -0500 Subject: [PATCH] WIP --- .../legoomni/src/common/legogamestate.cpp | 49 ++++++++++++++----- LEGO1/lego/sources/misc/legostorage.h | 6 +++ 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/LEGO1/lego/legoomni/src/common/legogamestate.cpp b/LEGO1/lego/legoomni/src/common/legogamestate.cpp index 6cfc80d8..6c2bc8f7 100644 --- a/LEGO1/lego/legoomni/src/common/legogamestate.cpp +++ b/LEGO1/lego/legoomni/src/common/legogamestate.cpp @@ -163,8 +163,10 @@ void LegoGameState::ResetROI() { if (m_actorId) { IslePathActor* actor = CurrentActor(); + if (actor) { LegoROI* roi = actor->GetROI(); + if (roi) { VideoManager()->Get3DManager()->GetLego3DView()->Remove(*roi); VideoManager()->Get3DManager()->GetLego3DView()->Add(*roi); @@ -180,24 +182,40 @@ MxResult LegoGameState::Save(MxULong p_slot) InfocenterState* infocenterState = (InfocenterState*) GameState()->GetState("InfocenterState"); if (!infocenterState || !infocenterState->HasRegistered()) { - result = SUCCESS; + return SUCCESS; } else { result = FAILURE; + LegoFile fileStream; MxVariableTable* variableTable = VariableTable(); - MxU16 count = 0; + MxS16 count = 0; + MxString savePath; GetFileSavePath(&savePath, p_slot); - if (fileStream.Open(savePath.GetData(), LegoFile::c_write) != FAILURE) { - MxU32 version = 0x1000C; - Write(&fileStream, &version); - Write(&fileStream, &m_unk0x24); - MxU16 act = m_currentAct; - Write(&fileStream, &act); - Write(&fileStream, &m_actorId); - for (MxS32 i = 0; i < sizeof(g_colorSaveData) / sizeof(g_colorSaveData[0]); ++i) { + if (fileStream.Open(savePath.GetData(), LegoFile::c_write) != FAILURE) { + { + MxU32 version = 0x1000C; + ((LegoStorage*) &fileStream)->Write(&version, sizeof(version)); + } + + { + MxU16 unk0x24 = m_unk0x24; + ((LegoStorage*) &fileStream)->Write(&unk0x24, sizeof(unk0x24)); + } + + { + MxU16 act = m_currentAct; + ((LegoStorage*) &fileStream)->Write(&act, sizeof(act)); + } + + { + MxU8 actorId = m_actorId; + ((LegoStorage*) &fileStream)->Write(&actorId, sizeof(actorId)); + } + + for (MxU32 i = 0; i < _countof(g_colorSaveData); i++) { if (WriteVariable(&fileStream, variableTable, g_colorSaveData[i].m_targetName) == FAILURE) { return result; } @@ -209,26 +227,33 @@ MxResult LegoGameState::Save(MxULong p_slot) UnkSaveDataWriter()->WriteSaveData3(&fileStream); PlantManager()->Save(&fileStream); result = BuildingManager()->Save(&fileStream); + for (MxS32 i = 0; i < m_stateCount; i++) { if (m_stateArray[i]->VTable0x14()) { count++; } } - Write(&fileStream, &count); + + { + MxU16 c = count; + ((LegoStorage*) &fileStream)->Write(&c, sizeof(c)); + } + for (MxS32 j = 0; j < m_stateCount; j++) { if (m_stateArray[j]->VTable0x14()) { m_stateArray[j]->VTable0x1c(&fileStream); } } + MxU16 area = m_unk0x42c; Write(&fileStream, &area); SerializeScoreHistory(2); m_isDirty = FALSE; } } - return result; } } + return result; } diff --git a/LEGO1/lego/sources/misc/legostorage.h b/LEGO1/lego/sources/misc/legostorage.h index df8dd072..4df5486f 100644 --- a/LEGO1/lego/sources/misc/legostorage.h +++ b/LEGO1/lego/sources/misc/legostorage.h @@ -53,6 +53,12 @@ inline void Write(LegoStorage* p_storage, T* p_variable) p_storage->Write(&variable, sizeof(variable)); } +template +inline void WriteScalar(LegoStorage* p_storage, T p_variable) +{ + p_storage->Write(&p_variable, sizeof(p_variable)); +} + // VTABLE: LEGO1 0x100db710 // SIZE 0x10 class LegoMemory : public LegoStorage {