From 1c5a86459863fbaae6e231af19dba2407d947310 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Mon, 28 Jun 2021 05:23:58 +0300 Subject: Fix script load --- src/control/Script5.cpp | 98 ++++++++++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 41 deletions(-) diff --git a/src/control/Script5.cpp b/src/control/Script5.cpp index 6208b79f..88054f3f 100644 --- a/src/control/Script5.cpp +++ b/src/control/Script5.cpp @@ -2206,29 +2206,33 @@ bool CTheScripts::LoadAllScripts(uint8* buf, uint32 size) Init(); // TODO: in LCS CTheScripts::Init call GenericLoad, which then calls LoadAllScripts INITSAVEBUF CheckSaveHeader(buf, 'S', 'C', 'R', '\0', size - SAVE_HEADER_SIZE); - uint32 varSpace = ReadSaveBuf(buf); + uint32 varSpace, type, handle; + uint32 tmp; + + ReadSaveBuf(&varSpace, buf); if (*(int32*)&ScriptSpace[0] != *(int32*)&buf[0] || *(int32*)&ScriptSpace[4] != *(int32*)&buf[4]) { printf("\n===================================================\nSave Game Mismatch!!!\n"); return false; } for (uint32 i = 0; i < varSpace; i++) { // this is not exactly what function does if (i < 8) - ScriptSpace[i] = ReadSaveBuf(buf); + ReadSaveBuf(&ScriptSpace[i], buf); else if (GetSaveVarIndex(i / 4 * 4) != -1) - ScriptSpace[i] = ReadSaveBuf(buf); + ReadSaveBuf(&ScriptSpace[i], buf); else - ReadSaveBuf(buf); + SkipSaveBuf(buf, 1); } // everything else is... gone? TODO - script_assert(ReadSaveBuf(buf) == SCRIPT_DATA_SIZE); - OnAMissionFlag = ReadSaveBuf(buf); - LastMissionPassedTime = ReadSaveBuf(buf); + ReadSaveBuf(&tmp, buf); + script_assert(tmp == SCRIPT_DATA_SIZE); + ReadSaveBuf(&OnAMissionFlag, buf); + ReadSaveBuf(&LastMissionPassedTime, buf); for (uint32 i = 0; i < MAX_NUM_COLLECTIVES; i++) - CollectiveArray[i] = ReadSaveBuf(buf); - NextFreeCollectiveIndex = ReadSaveBuf(buf); + ReadSaveBuf(&CollectiveArray[i], buf); + ReadSaveBuf(&NextFreeCollectiveIndex, buf); for (uint32 i = 0; i < MAX_NUM_BUILDING_SWAPS; i++) { - uint32 type = ReadSaveBuf(buf); - uint32 handle = ReadSaveBuf(buf); + ReadSaveBuf(&type, buf); + ReadSaveBuf(&handle, buf); /* switch (type) { case 0: @@ -2244,16 +2248,17 @@ INITSAVEBUF script_assert(false); } */ - /*BuildingSwapArray[i].m_nNewModel = */ReadSaveBuf(buf); - /*BuildingSwapArray[i].m_nOldModel = */ReadSaveBuf(buf); + /*BuildingSwapArray[i].m_nNewModel = ReadSaveBuf(buf);*/ + /*BuildingSwapArray[i].m_nOldModel = ReadSaveBuf(buf);*/ + SkipSaveBuf(buf, 8); /* if (BuildingSwapArray[i].m_pBuilding) BuildingSwapArray[i].m_pBuilding->ReplaceWithNewModel(BuildingSwapArray[i].m_nNewModel); */ } for (uint32 i = 0; i < MAX_NUM_INVISIBILITY_SETTINGS; i++) { - uint32 type = ReadSaveBuf(buf); - uint32 handle = ReadSaveBuf(buf); + ReadSaveBuf(&type, buf); + ReadSaveBuf(&handle, buf); /* switch (type) { case 0: @@ -2278,14 +2283,25 @@ INITSAVEBUF InvisibilitySettingArray[i]->bIsVisible = false; */ } - script_assert(ReadSaveBuf(buf) == bUsingAMultiScriptFile); - /*bPlayerHasMetDebbieHarry = */ReadSaveBuf(buf); - ReadSaveBuf(buf); - script_assert(ReadSaveBuf(buf) == MainScriptSize); - script_assert(ReadSaveBuf(buf) == LargestMissionScriptSize); - script_assert(ReadSaveBuf(buf) == NumberOfMissionScripts); - script_assert(ReadSaveBuf(buf) == NumberOfExclusiveMissionScripts); - uint32 runningScripts = ReadSaveBuf(buf); + bool tmpBool; + ReadSaveBuf(&tmpBool, buf); + script_assert(tmpBool == bUsingAMultiScriptFile); + ///*bPlayerHasMetDebbieHarry = */ReadSaveBuf(buf); + //ReadSaveBuf(buf); + + SkipSaveBuf(buf, 3); + + ReadSaveBuf(&tmp, buf); + script_assert(tmp == MainScriptSize); + ReadSaveBuf(&tmp, buf); + script_assert(tmp == LargestMissionScriptSize); + uint16 tmp16; + ReadSaveBuf(&tmp16, buf); + script_assert(tmp16 == NumberOfMissionScripts); + ReadSaveBuf(&tmp16, buf); + script_assert(tmp16 == NumberOfExclusiveMissionScripts); + uint32 runningScripts; + ReadSaveBuf(&runningScripts, buf); for (uint32 i = 0; i < runningScripts; i++) CRunningScript().Load(buf); StartTestScript(); // <- tmp hack @@ -2336,38 +2352,38 @@ void CRunningScript::Load(uint8*& buf) { #ifdef COMPATIBLE_SAVES SkipSaveBuf(buf, 8); - m_nId = ReadSaveBuf(buf); + ReadSaveBuf(&m_nId, buf); for (int i = 0; i < 8; i++) - m_abScriptName[i] = ReadSaveBuf(buf); - m_nIp = ReadSaveBuf(buf); + ReadSaveBuf(&m_abScriptName[i], buf); + ReadSaveBuf(&m_nIp, buf); #ifdef CHECK_STRUCT_SIZES static_assert(MAX_STACK_DEPTH == 6, "Compatibility loss: MAX_STACK_DEPTH != 6"); #endif for (int i = 0; i < MAX_STACK_DEPTH; i++) - m_anStack[i] = ReadSaveBuf(buf); - m_nStackPointer = ReadSaveBuf(buf); + ReadSaveBuf(&m_anStack[i], buf); + ReadSaveBuf(&m_nStackPointer, buf); SkipSaveBuf(buf, 2); #ifdef CHECK_STRUCT_SIZES static_assert(NUM_LOCAL_VARS + 8 + NUM_TIMERS == 106, "Compatibility loss: NUM_LOCAL_VARS + 8 + NUM_TIMERS != 106"); #endif for (int i = 0; i < NUM_LOCAL_VARS + 8 + NUM_TIMERS; i++) - m_anLocalVariables[i] = ReadSaveBuf(buf); - m_nLocalsPointer = ReadSaveBuf(buf); - m_bIsActive = ReadSaveBuf(buf); - m_bCondResult = ReadSaveBuf(buf); - m_bIsMissionScript = ReadSaveBuf(buf); - m_bSkipWakeTime = ReadSaveBuf(buf); - m_nWakeTime = ReadSaveBuf(buf); - m_nAndOrState = ReadSaveBuf(buf); - m_bNotFlag = ReadSaveBuf(buf); - m_bDeatharrestEnabled = ReadSaveBuf(buf); - m_bDeatharrestExecuted = ReadSaveBuf(buf); - m_bMissionFlag = ReadSaveBuf(buf); + ReadSaveBuf(&m_anLocalVariables[i], buf); + ReadSaveBuf(&m_nLocalsPointer, buf); + ReadSaveBuf(&m_bIsActive, buf); + ReadSaveBuf(&m_bCondResult, buf); + ReadSaveBuf(&m_bIsMissionScript, buf); + ReadSaveBuf(&m_bSkipWakeTime, buf); + ReadSaveBuf(&m_nWakeTime, buf); + ReadSaveBuf(&m_nAndOrState, buf); + ReadSaveBuf(&m_bNotFlag, buf); + ReadSaveBuf(&m_bDeatharrestEnabled, buf); + ReadSaveBuf(&m_bDeatharrestExecuted, buf); + ReadSaveBuf(&m_bMissionFlag, buf); SkipSaveBuf(buf, 2); #else CRunningScript* n = next; CRunningScript* p = prev; - *this = ReadSaveBuf(buf); + ReadSaveBuf(this, buf); next = n; prev = p; #endif -- cgit v1.2.3