From 708d5831e4c78383f73fba4db14f9cac69b5c116 Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Sat, 16 Jan 2021 13:26:46 +0300 Subject: [PATCH] Script5.cpp --- src/control/Script.h | 4 ++-- src/control/Script3.cpp | 2 ++ src/control/Script4.cpp | 2 ++ src/control/Script5.cpp | 50 ++++++++++++++++++++++++++++++++--------- src/control/Script6.cpp | 1 + src/peds/Ped.h | 2 +- 6 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/control/Script.h b/src/control/Script.h index a1e786c9..709070a5 100644 --- a/src/control/Script.h +++ b/src/control/Script.h @@ -366,7 +366,7 @@ public: */ static void SaveAllScripts(uint8*, uint32*); - static void LoadAllScripts(uint8*, uint32); + static bool LoadAllScripts(uint8*, uint32); static bool IsDebugOn() { return DbgFlag; }; static void InvertDebugFlag() { DbgFlag = !DbgFlag; } @@ -508,7 +508,7 @@ class CRunningScript public: CRunningScript* next; CRunningScript* prev; - int m_nId; + int32 m_nId; char m_abScriptName[8]; uint32 m_nIp; uint32 m_anStack[MAX_STACK_DEPTH]; diff --git a/src/control/Script3.cpp b/src/control/Script3.cpp index 9d8cc352..1bb4f12c 100644 --- a/src/control/Script3.cpp +++ b/src/control/Script3.cpp @@ -36,6 +36,8 @@ #include "GameLogic.h" #include "Bike.h" +// LCS: file done except TODOs + int8 CRunningScript::ProcessCommands500To599(int32 command) { switch (command) { diff --git a/src/control/Script4.cpp b/src/control/Script4.cpp index 12eb179c..ba845ad8 100644 --- a/src/control/Script4.cpp +++ b/src/control/Script4.cpp @@ -40,6 +40,8 @@ #include "Zones.h" #include "Bike.h" +// LCS: file done except TODOs + #ifdef FIX_BUGS static bool IsSlideObjectUsedWrongByScript(const CVector& posTarget, const CVector& slideBy) { diff --git a/src/control/Script5.cpp b/src/control/Script5.cpp index fff8628c..38dcdaf9 100644 --- a/src/control/Script5.cpp +++ b/src/control/Script5.cpp @@ -17,6 +17,8 @@ #include "World.h" #include "main.h" +// LCS: file done except TODOs + uint32 CRunningScript::CollectLocateParameters(uint32* pIp, bool b3D) { CollectParameters(pIp, 1); @@ -2133,6 +2135,9 @@ INITSAVEBUF WriteSaveBuf(buf, script_data_size); WriteSaveBuf(buf, OnAMissionFlag); WriteSaveBuf(buf, LastMissionPassedTime); + for (uint32 i = 0; i < MAX_NUM_COLLECTIVES; i++) + WriteSaveBuf(buf, CollectiveArray[i]); + WriteSaveBuf(buf, NextFreeCollectiveIndex); for (uint32 i = 0; i < MAX_NUM_BUILDING_SWAPS; i++) { CBuilding* pBuilding = BuildingSwapArray[i].m_pBuilding; uint32 type, handle; @@ -2194,14 +2199,26 @@ INITSAVEBUF VALIDATESAVEBUF(*size) } -void CTheScripts::LoadAllScripts(uint8* buf, uint32 size) +// TODO: I don't really understand how script loading works, so I leave it the VC way for now. +bool CTheScripts::LoadAllScripts(uint8* buf, uint32 size) { - Init(); + 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); - for (uint32 i = 0; i < varSpace; i++) - ScriptSpace[i] = ReadSaveBuf(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); + else if (GetSaveVarIndex(i / 4 * 4) != -1) + ScriptSpace[i] = ReadSaveBuf(buf); + else + ReadSaveBuf(buf); + } + // everything else is... gone? TODO script_assert(ReadSaveBuf(buf) == SCRIPT_DATA_SIZE); OnAMissionFlag = ReadSaveBuf(buf); LastMissionPassedTime = ReadSaveBuf(buf); @@ -2270,6 +2287,7 @@ void CRunningScript::Save(uint8*& buf) { #ifdef COMPATIBLE_SAVES SkipSaveBuf(buf, 8); + WriteSaveBuf(buf, m_nId); for (int i = 0; i < 8; i++) WriteSaveBuf(buf, m_abScriptName[i]); WriteSaveBuf(buf, m_nIp); @@ -2281,10 +2299,11 @@ void CRunningScript::Save(uint8*& buf) WriteSaveBuf(buf, m_nStackPointer); SkipSaveBuf(buf, 2); #ifdef CHECK_STRUCT_SIZES - static_assert(NUM_LOCAL_VARS + NUM_TIMERS == 18, "Compatibility loss: NUM_LOCAL_VARS + NUM_TIMERS != 18"); + static_assert(NUM_LOCAL_VARS + 8 + NUM_TIMERS == 106, "Compatibility loss: NUM_LOCAL_VARS + NUM_TIMERS != 106"); #endif - for (int i = 0; i < NUM_LOCAL_VARS + NUM_TIMERS; i++) + for (int i = 0; i < NUM_LOCAL_VARS + 8 + NUM_TIMERS; i++) WriteSaveBuf(buf, m_anLocalVariables[i]); + WriteSaveBuf(buf, m_nLocalsPointer); WriteSaveBuf(buf, m_bIsActive); WriteSaveBuf(buf, m_bCondResult); WriteSaveBuf(buf, m_bIsMissionScript); @@ -2305,6 +2324,7 @@ void CRunningScript::Load(uint8*& buf) { #ifdef COMPATIBLE_SAVES SkipSaveBuf(buf, 8); + m_nId = ReadSaveBuf(buf); for (int i = 0; i < 8; i++) m_abScriptName[i] = ReadSaveBuf(buf); m_nIp = ReadSaveBuf(buf); @@ -2316,10 +2336,11 @@ void CRunningScript::Load(uint8*& buf) m_nStackPointer = ReadSaveBuf(buf); SkipSaveBuf(buf, 2); #ifdef CHECK_STRUCT_SIZES - static_assert(NUM_LOCAL_VARS + NUM_TIMERS == 18, "Compatibility loss: NUM_LOCAL_VARS + NUM_TIMERS != 18"); + 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 + NUM_TIMERS; i++) + 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); @@ -2698,8 +2719,14 @@ void CTheScripts::CleanUpThisPed(CPed* pPed) } else { if (pPed->m_pMyVehicle->m_vehType == VEHICLE_TYPE_CAR) { - pPed->SetObjective(OBJECTIVE_LEAVE_CAR, pPed->m_pMyVehicle); - pPed->bWanderPathAfterExitingCar = true; + if ((pPed->m_fHealth < 1.0f && !pPed->IsPedHeadAbovePos(-0.3f)) || pPed->bBodyPartJustCameOff) { + pPed->SetObjective(OBJECTIVE_LEAVE_CAR_AND_DIE, pPed->m_pMyVehicle); + pPed->bWanderPathAfterExitingCar = false; + } + else { + pPed->SetObjective(OBJECTIVE_LEAVE_CAR, pPed->m_pMyVehicle); + pPed->bWanderPathAfterExitingCar = true; + } } } } @@ -2712,6 +2739,7 @@ void CTheScripts::CleanUpThisPed(CPed* pPed) flees = true; } pPed->ClearObjective(); + pPed->SetWaitState(WAITSTATE_FALSE, nil); // third parameter is 0 TODO? pPed->bRespondsToThreats = true; pPed->bScriptObjectiveCompleted = false; pPed->bKindaStayInSamePlace = false; @@ -2756,7 +2784,7 @@ void CTheScripts::ReadObjectNamesFromScript() int32 varSpace = GetSizeOfVariableSpace(); uint32 ip = varSpace + 8; NumSaveVars = Read4BytesFromScript(&ip); - SavedVarIndices = (short*)&ScriptParams[ip]; + SavedVarIndices = (short*)&ScriptSpace[ip]; ip += 2 * NumSaveVars; NumberOfUsedObjects = Read2BytesFromScript(&ip); ip += 2; diff --git a/src/control/Script6.cpp b/src/control/Script6.cpp index 02427eed..1db9e207 100644 --- a/src/control/Script6.cpp +++ b/src/control/Script6.cpp @@ -77,6 +77,7 @@ bool CRunningScript::ThisIsAValidRandomCop(int32 mi, bool cop, bool swat, bool f default: return miami && (mi >= MI_VICE1 && mi <= MI_VICE8); } + return false; } int8 CRunningScript::ProcessCommands1000To1099(int32 command) diff --git a/src/peds/Ped.h b/src/peds/Ped.h index 242a86f2..5d8383eb 100644 --- a/src/peds/Ped.h +++ b/src/peds/Ped.h @@ -406,7 +406,7 @@ public: float m_fCollisionSpeed; // cf. https://github.com/DK22Pac/plugin-sdk/blob/master/plugin_sa/game_sa/CPed.h from R* - uint32 bIsStanding : 1; + uint32 bIsStanding : 1; // 0x194 on PS2, 0x1A4 on android uint32 bWasStanding : 1; uint32 bIsAttacking : 1; // doesn't reset after fist fight uint32 bIsPointingGunAt : 1;