From d74d42ddfd5fd395504acb20aaabe4403eee022c Mon Sep 17 00:00:00 2001 From: Misha <106913236+MishaProductions@users.noreply.github.com> Date: Fri, 15 Dec 2023 15:56:19 -0500 Subject: [PATCH] some gamestate functions --- LEGO1/legogamestate.cpp | 49 ++++++++++++++++++++++++++++++++++++++--- LEGO1/legogamestate.h | 12 ++++++---- LEGO1/legoomni.cpp | 6 +++++ LEGO1/legoomni.h | 1 + 4 files changed, 61 insertions(+), 7 deletions(-) diff --git a/LEGO1/legogamestate.cpp b/LEGO1/legogamestate.cpp index 599b4c79..378241b3 100644 --- a/LEGO1/legogamestate.cpp +++ b/LEGO1/legogamestate.cpp @@ -13,6 +13,12 @@ // There may be other members that come after. DECOMP_SIZE_ASSERT(LegoGameState, 0x430) +// GLOBAL: LEGO1 0x100f3e24 +const char* g_historyGSI = "History.gsi"; + +// GLOBAL: LEGO1 0x100f3e30 +const char* g_playersGSI = "Players.gsi"; + // GLOBAL: LEGO1 0x100f3e40 const char* g_fileExtensionGS = ".GS"; @@ -255,10 +261,30 @@ void LegoGameState::RegisterState(LegoState* p_state) m_stateArray[targetIndex] = p_state; } -// STUB: LEGO1 0x1003cdd0 -void LegoGameState::SerializeScoreHistory(MxS16) +void LegoGameState::WriteScoreHistory(MxU16*) { - // TODO +} + +// STUB: LEGO1 0x1003ccf0 +void FUN_1003ccf0(MxU16*, LegoFileStream&) +{ +} + +// FUNCTION: LEGO1 0x1003cdd0 +void LegoGameState::SerializeScoreHistory(MxS16 m_flags) +{ + LegoFileStream stream; + MxString savePath(m_savePath); + savePath += "\\"; + savePath += g_historyGSI; + + if (m_flags == LegoStream::WriteBit) { + WriteScoreHistory(&m_unk0xa6); + } + + if (stream.Open(savePath.GetData(), (LegoStream::OpenFlags) m_flags) == SUCCESS) { + FUN_1003ccf0(&m_unk0xa6, stream); + } } // FUNCTION: LEGO1 0x1003cea0 @@ -266,3 +292,20 @@ void LegoGameState::SetSomeEnumState(undefined4 p_state) { m_unk0x10 = p_state; } + +// FUNCTION: LEGO1 0x1003ceb0 +void LegoGameState::FUN_1003ceb0() +{ + if (FindEntityByAtomIdOrEntityId(*g_isleScript, 0)) { + m_currentAct = 0; + } + else if (FindEntityByAtomIdOrEntityId(*g_act2mainScript, 0)) { + m_currentAct = 1; + } + else if (FindEntityByAtomIdOrEntityId(*g_act3Script, 0)) { + m_currentAct = 2; + } + else { + m_currentAct = -1; + } +} diff --git a/LEGO1/legogamestate.h b/LEGO1/legogamestate.h index 4951df0f..5465ec52 100644 --- a/LEGO1/legogamestate.h +++ b/LEGO1/legogamestate.h @@ -4,10 +4,10 @@ #include "decomp.h" #include "legobackgroundcolor.h" #include "legofullscreenmovie.h" +#include "legostream.h" #include "mxtypes.h" class LegoState; -class LegoStream; class MxVariable; class MxString; @@ -24,7 +24,7 @@ class LegoGameState { __declspec(dllexport) MxResult Load(MxULong); __declspec(dllexport) MxResult Save(MxULong); __declspec(dllexport) void SerializePlayersInfo(MxS16); - __declspec(dllexport) void SerializeScoreHistory(MxS16); + __declspec(dllexport) void SerializeScoreHistory(MxS16 m_flags); __declspec(dllexport) void SetSavePath(char*); LegoState* GetState(COMPAT_CONST char* p_stateName); @@ -33,12 +33,14 @@ class LegoGameState { void GetFileSavePath(MxString* p_outPath, MxULong p_slotn); void FUN_1003a720(MxU32); void HandleAction(MxU32); + void WriteScoreHistory(MxU16*); inline MxU8 GetUnknownC() { return m_unk0xc; } inline MxU32 GetUnknown10() { return m_unk0x10; } inline void SetUnknown424(undefined4 p_unk0x424) { m_unk0x424 = p_unk0x424; } void SetSomeEnumState(undefined4 p_state); + void FUN_1003ceb0(); private: void RegisterState(LegoState* p_state); @@ -51,12 +53,14 @@ class LegoGameState { LegoState** m_stateArray; // 0x8 MxU8 m_unk0xc; // 0xc MxU32 m_unk0x10; // 0x10 - undefined4 m_unk0x14; // 0x14 + undefined4 m_currentAct; // 0x14 LegoBackgroundColor* m_backgroundColor; // 0x18 LegoBackgroundColor* m_tempBackgroundColor; // 0x1c LegoFullScreenMovie* m_fullScreenMovie; // 0x20 MxU16 m_unk0x24; // 0x24 - undefined m_unk0x28[1020]; // 0x28 + undefined m_unk0x28[128]; // 0x28 + MxU16 m_unk0xa6; // 0xa6 + undefined m_unk0xa9[890]; // 0xa9 undefined4 m_unk0x424; // 0x424 undefined4 m_unk0x428; // 0x428 undefined4 m_unk0x42c; // 0x42c diff --git a/LEGO1/legoomni.cpp b/LEGO1/legoomni.cpp index 88f6bb26..f7a95487 100644 --- a/LEGO1/legoomni.cpp +++ b/LEGO1/legoomni.cpp @@ -188,6 +188,12 @@ LegoBuildingManager* BuildingManager() return LegoOmni::GetInstance()->GetLegoBuildingManager(); } +// FUNCTION: LEGO1 0x100158c0 +LegoEntity* FindEntityByAtomIdOrEntityId(const MxAtomId& p_atom, MxS32 p_entityid) +{ + return LegoOmni::GetInstance()->FindByEntityIdOrAtomId(p_atom, p_entityid); +} + // FUNCTION: LEGO1 0x10015800 GifManager* GetGifManager() { diff --git a/LEGO1/legoomni.h b/LEGO1/legoomni.h index ba6e6051..38a1b7f3 100644 --- a/LEGO1/legoomni.h +++ b/LEGO1/legoomni.h @@ -157,6 +157,7 @@ IslePathActor* GetCurrentVehicle(); LegoPlantManager* PlantManager(); MxBool KeyValueStringParse(char*, const char*, const char*); LegoWorld* GetCurrentWorld(); +LegoEntity* FindEntityByAtomIdOrEntityId(const MxAtomId& p_atom, MxS32 p_entityid); GifManager* GetGifManager(); MxDSAction& GetCurrentAction();