From 4fee2cbdd9948bd591d6e5bebd4bed827e12498a Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Thu, 5 Mar 2020 01:44:42 -0800 Subject: [PATCH 01/10] Begin work on GenericSave --- src/core/Radar.cpp | 4 +- src/core/Radar.h | 2 +- src/save/GenericGameStorage.cpp | 84 ++++++++++++++++++++++++++++++++- 3 files changed, 86 insertions(+), 4 deletions(-) diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp index 6a1446da..3a706bad 100644 --- a/src/core/Radar.cpp +++ b/src/core/Radar.cpp @@ -946,9 +946,9 @@ void CRadar::RequestMapSection(int32 x, int32 y) #endif #if 1 -WRAPPER void CRadar::SaveAllRadarBlips(int32) { EAXJMP(0x4A6E30); } +WRAPPER void CRadar::SaveAllRadarBlips(uint8 *buf, uint32 *size) { EAXJMP(0x4A6E30); } #else -void CRadar::SaveAllRadarBlips(int32) +void CRadar::SaveAllRadarBlips(uint8 *buf, uint32 *size) { } diff --git a/src/core/Radar.h b/src/core/Radar.h index 650c6fb4..5b2174d7 100644 --- a/src/core/Radar.h +++ b/src/core/Radar.h @@ -130,7 +130,7 @@ public: static void RemoveRadarSections(); static void RemoveMapSection(int32 x, int32 y); static void RequestMapSection(int32 x, int32 y); - static void SaveAllRadarBlips(int32); + static void SaveAllRadarBlips(uint8 *buf, uint32 *size); static void SetBlipSprite(int32 i, int32 icon); static int32 SetCoordBlip(eBlipType type, CVector pos, int32, eBlipDisplay); static int32 SetEntityBlip(eBlipType type, int32, int32, eBlipDisplay); diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index 5a55dbd5..6880915d 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -2,18 +2,27 @@ #include "main.h" #include "patcher.h" #include "Camera.h" +#include "CarGen.h" #include "Clock.h" #include "Date.h" #include "FileMgr.h" #include "GameLogic.h" +#include "Gangs.h" #include "Garages.h" #include "GenericGameStorage.h" +#include "PathFind.h" #include "PCSave.h" +#include "Phones.h" +#include "Pickups.h" #include "PlayerPed.h" #include "Pools.h" +#include "Radar.h" +#include "Restart.h" #include "Script.h" +#include "Stats.h" #include "Streaming.h" #include "World.h" +#include "Zones.h" const int SIZE_OF_ONE_GAME_IN_BYTES = 201729; @@ -31,9 +40,82 @@ CDate &CompileDateAndTime = *(CDate*)0x72BCB8; #define ReadDataFromBufferPointer(buf, to) memcpy(&to, buf, sizeof(to)); buf += align4bytes(sizeof(to)); #define WriteDataToBufferPointer(buf, from) memcpy(buf, &from, sizeof(from)); buf += align4bytes(sizeof(from)); -WRAPPER bool GenericSave(int file) { EAXJMP(0x58F8D0); } +//WRAPPER bool GenericSave(int file) { EAXJMP(0x58F8D0); } WRAPPER bool GenericLoad() { EAXJMP(0x590A00); } +bool +GenericSave(int file) +{ + /*char *tmpSaveName; + wchar saveName[24]; + SYSTEMTIME saveTime;*/ + + // TODO: Use GetLastMissionPassedName() to get this + //tmpSaveName = CStats::LastMissionPassedName; + + //AsciiToUnicode(tmpSaveName, saveName); + + //// TODO: some stuff here + + //memcpy(work_buff, saveName, 0x30); + //GetLocalTime((SYSTEMTIME *)(work_buff + 0x30)); + //*((uint32 *)(work_buff + 0x40)) = SIZE_OF_ONE_GAME_IN_BYTES; + //*((uint32 *)(work_buff + 0x44)) = CGame::currLevel; + // + //PcSaveHelper.PcClassSaveRoutine(file, work_buff, 0xE8); + + + uint8 *buf; + uint8 *tmpbuf; + uint8 *postsize; + uint32 size; + uint32 reserved; + bool result; + + // TODO: simplevars and scripts + + for (int i = 1; i < 19; i++) { + buf = work_buff; + size = 0; + reserved = 0; + MakeSpaceForSizeInBufferPointer(tmpbuf, buf, postsize); + switch (i) { + case 1: break; + case 2: break; + case 3: break; + case 4: break; + case 5: ThePaths.Save(buf, &size); break; + case 6: break; + case 7: CPickups::Save(buf, &size); break; + case 8: gPhoneInfo.Save(buf, &size); break; + case 9: CRestart::SaveAllRestartPoints(buf, &size); break; + case 10: CRadar::SaveAllRadarBlips(buf, &size); break; + case 11: CTheZones::SaveAllZones(buf, &size); break; + case 12: CGangs::SaveAllGangData(buf, &size); break; + case 13: CTheCarGenerators::SaveAllCarGenerators(buf, &size); break; + case 14: break; + case 15: break; + case 16: break; + case 17: break; + case 18: break; + case 19: break; + } + + CopySizeAndPreparePointer(tmpbuf, buf, postsize, reserved, size); + result = PcSaveHelper.PcClassSaveRoutine(file, work_buff, size); + if (!result) + { + return false; + } + } + + + + // TODO: padding + + return true; +} + bool ReadInSizeofSaveFileBuffer(int32 &file, uint32 &size) { From 28342405d37ae28fdf98546753e89d683480914f Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Tue, 10 Mar 2020 20:25:50 -0700 Subject: [PATCH 02/10] Add Load/Save functions --- src/control/Cranes.cpp | 4 +++- src/control/Cranes.h | 3 +++ src/control/Garages.cpp | 2 ++ src/control/Garages.h | 2 ++ src/control/Script.cpp | 4 ++-- src/core/Clock.h | 2 +- src/core/Pools.cpp | 39 +++++++++++++++++++++++---------------- src/core/Pools.h | 6 ++++++ src/core/Timer.h | 3 ++- 9 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/control/Cranes.cpp b/src/control/Cranes.cpp index c8d64077..4c1bf2c8 100644 --- a/src/control/Cranes.cpp +++ b/src/control/Cranes.cpp @@ -9,4 +9,6 @@ WRAPPER bool CCranes::HaveAllCarsBeenCollectedByMilitaryCrane() { EAXJMP(0x544BE WRAPPER void CCranes::ActivateCrane(float, float, float, float, float, float, float, float, bool, bool, float, float) { EAXJMP(0x543650); } WRAPPER void CCranes::DeActivateCrane(float, float) { EAXJMP(0x543890); } WRAPPER void CCranes::InitCranes(void) { EAXJMP(0x543360); } -WRAPPER void CCranes::UpdateCranes(void) { EAXJMP(0x5439E0); } \ No newline at end of file +WRAPPER void CCranes::UpdateCranes(void) { EAXJMP(0x5439E0); } +WRAPPER void CCranes::Save(uint8*, uint32*) { EAXJMP(0x545210); } +WRAPPER void CranesLoad(uint8*, uint32) { EAXJMP(0x5454d0); } diff --git a/src/control/Cranes.h b/src/control/Cranes.h index 4625463e..9f606c9f 100644 --- a/src/control/Cranes.h +++ b/src/control/Cranes.h @@ -14,4 +14,7 @@ public: static void DeActivateCrane(float, float); static void InitCranes(void); static void UpdateCranes(void); + static void Save(uint8*, uint32*); }; + +void CranesLoad(uint8*, uint32); // is this really outside CCranes? diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index 8270780d..9f300257 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -31,6 +31,8 @@ CGarage(&CGarages::Garages)[NUM_GARAGES] = *(CGarage(*)[NUM_GARAGES])(uintptr*)0 WRAPPER void CGarages::Init(void) { EAXJMP(0x421C60); } WRAPPER void CGarages::Update(void) { EAXJMP(0x421E40); } +WRAPPER void CGarages::Load(uint8* buf, uint32 size) { EAXJMP(0x428940); } +WRAPPER void CGarages::Save(uint8* buf, uint32 *size) { EAXJMP(0x4284e0); } bool CGarages::IsModelIndexADoor(uint32 id) diff --git a/src/control/Garages.h b/src/control/Garages.h index fe0d1a20..5e106ade 100644 --- a/src/control/Garages.h +++ b/src/control/Garages.h @@ -147,6 +147,8 @@ public: static void PlayerArrestedOrDied(); static void Init(void); static void Update(void); + static void Load(uint8 *buf, uint32 size); + static void Save(uint8 *buf, uint32 *size); static int16 AddOne(float, float, float, float, float, float, uint8, uint32); static void SetTargetCarForMissonGarage(int16, CVehicle*); static bool HasCarBeenDroppedOffYet(int16); diff --git a/src/control/Script.cpp b/src/control/Script.cpp index b8add76a..96835aef 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -11212,8 +11212,8 @@ void CTheScripts::RenderTheScriptDebugLines() RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)0); } -WRAPPER void CTheScripts::SaveAllScripts(uint8*, uint32*) { EAXJMP(0x4535E0); } -WRAPPER void CTheScripts::LoadAllScripts(uint8*, uint32) { EAXJMP(0x453B30); } +WRAPPER void CTheScripts::SaveAllScripts(uint8 *buf, uint32 *size) { EAXJMP(0x4535E0); } +WRAPPER void CTheScripts::LoadAllScripts(uint8 *buf, uint32 size) { EAXJMP(0x453B30); } WRAPPER void CTheScripts::ClearSpaceForMissionEntity(const CVector&, CEntity*) { EAXJMP(0x454060); } WRAPPER void CTheScripts::HighlightImportantArea(uint32, float, float, float, float, float) { EAXJMP(0x454320); } WRAPPER void CTheScripts::HighlightImportantAngledArea(uint32, float, float, float, float, float, float, float, float, float) { EAXJMP(0x454430); } diff --git a/src/core/Clock.h b/src/core/Clock.h index ea4263bd..6b9908ba 100644 --- a/src/core/Clock.h +++ b/src/core/Clock.h @@ -2,6 +2,7 @@ class CClock { +public: static uint8 &ms_nGameClockHours; static uint8 &ms_nGameClockMinutes; static uint16 &ms_nGameClockSeconds; @@ -11,7 +12,6 @@ class CClock static uint32 &ms_nMillisecondsPerGameMinute; static uint32 &ms_nLastClockTick; static bool &ms_bClockHasBeenStored; -public: static void Initialise(uint32 scale); static void Update(void); diff --git a/src/core/Pools.cpp b/src/core/Pools.cpp index 8e66b049..75536b88 100644 --- a/src/core/Pools.cpp +++ b/src/core/Pools.cpp @@ -14,6 +14,13 @@ CObjectPool *&CPools::ms_pObjectPool = *(CObjectPool**)0x880E28; CDummyPool *&CPools::ms_pDummyPool = *(CDummyPool**)0x8F2C18; CAudioScriptObjectPool *&CPools::ms_pAudioScriptObjectPool = *(CAudioScriptObjectPool**)0x8F1B6C; +WRAPPER void CPools::LoadObjectPool(uint8* buf, uint32 size) { EAXJMP(0x4a2550); } +WRAPPER void CPools::LoadPedPool(uint8* buf, uint32 size) { EAXJMP(0x4a2b50); } +WRAPPER void CPools::LoadVehiclePool(uint8* buf, uint32 size) { EAXJMP(0x4a1b40); } +WRAPPER void CPools::SaveObjectPool(uint8* buf, uint32 *size) { EAXJMP(0x4a22d0); } +WRAPPER void CPools::SavePedPool(uint8* buf, uint32 *size) { EAXJMP(0x4a29b0); } +WRAPPER void CPools::SaveVehiclePool(uint8* buf, uint32 *size) { EAXJMP(0x4a2080); } + void CPools::Initialise(void) { @@ -30,16 +37,16 @@ CPools::Initialise(void) void CPools::ShutDown(void) -{ - debug("PtrNodes left %d\n", ms_pPtrNodePool->GetNoOfUsedSpaces()); - debug("EntryInfoNodes left %d\n", ms_pEntryInfoNodePool->GetNoOfUsedSpaces()); - debug("Peds left %d\n", ms_pPedPool->GetNoOfUsedSpaces()); - debug("Vehicles left %d\n", ms_pVehiclePool->GetNoOfUsedSpaces()); - debug("Buildings left %d\n", ms_pBuildingPool->GetNoOfUsedSpaces()); - debug("Treadables left %d\n", ms_pTreadablePool->GetNoOfUsedSpaces()); - debug("Objects left %d\n", ms_pObjectPool->GetNoOfUsedSpaces()); - debug("Dummys left %d\n", ms_pDummyPool->GetNoOfUsedSpaces()); - debug("AudioScriptObjects left %d\n", ms_pAudioScriptObjectPool->GetNoOfUsedSpaces()); +{ + debug("PtrNodes left %d\n", ms_pPtrNodePool->GetNoOfUsedSpaces()); + debug("EntryInfoNodes left %d\n", ms_pEntryInfoNodePool->GetNoOfUsedSpaces()); + debug("Peds left %d\n", ms_pPedPool->GetNoOfUsedSpaces()); + debug("Vehicles left %d\n", ms_pVehiclePool->GetNoOfUsedSpaces()); + debug("Buildings left %d\n", ms_pBuildingPool->GetNoOfUsedSpaces()); + debug("Treadables left %d\n", ms_pTreadablePool->GetNoOfUsedSpaces()); + debug("Objects left %d\n", ms_pObjectPool->GetNoOfUsedSpaces()); + debug("Dummys left %d\n", ms_pDummyPool->GetNoOfUsedSpaces()); + debug("AudioScriptObjects left %d\n", ms_pAudioScriptObjectPool->GetNoOfUsedSpaces()); printf("Shutdown pool started\n"); delete ms_pPtrNodePool; @@ -62,12 +69,12 @@ CVehicle *CPools::GetVehicle(int32 handle) { return ms_pVehiclePool->GetAt(handl int32 CPools::GetObjectRef(CObject *object) { return ms_pObjectPool->GetIndex(object); } CObject *CPools::GetObject(int32 handle) { return ms_pObjectPool->GetAt(handle); } -void -CPools::CheckPoolsEmpty() -{ - assert(ms_pPedPool->GetNoOfUsedSpaces() == 0); - assert(ms_pVehiclePool->GetNoOfUsedSpaces() == 0); - printf("pools have beem cleared \n"); +void +CPools::CheckPoolsEmpty() +{ + assert(ms_pPedPool->GetNoOfUsedSpaces() == 0); + assert(ms_pVehiclePool->GetNoOfUsedSpaces() == 0); + printf("pools have been cleared\n"); } diff --git a/src/core/Pools.h b/src/core/Pools.h index 862062ee..74b87585 100644 --- a/src/core/Pools.h +++ b/src/core/Pools.h @@ -52,4 +52,10 @@ public: static CObject *GetObject(int32 handle); static void CheckPoolsEmpty(); static void MakeSureSlotInObjectPoolIsEmpty(int32 slot); + static void LoadObjectPool(uint8 *buf, uint32 size); + static void LoadPedPool(uint8 *buf, uint32 size); + static void LoadVehiclePool(uint8 *buf, uint32 size); + static void SaveObjectPool(uint8 *buf, uint32 *size); + static void SavePedPool(uint8 *buf, uint32 *size); + static void SaveVehiclePool(uint8 *buf, uint32 *size); }; diff --git a/src/core/Timer.h b/src/core/Timer.h index 8f3b77c2..89c4a430 100644 --- a/src/core/Timer.h +++ b/src/core/Timer.h @@ -2,6 +2,7 @@ class CTimer { +public: static uint32 &m_snTimeInMilliseconds; static uint32 &m_snTimeInMillisecondsPauseMode; static uint32 &m_snTimeInMillisecondsNonClipped; @@ -12,7 +13,7 @@ class CTimer static float &ms_fTimeStepNonClipped; static bool &m_UserPause; static bool &m_CodePause; -public: + static float GetTimeStep(void) { return ms_fTimeStep; } static void SetTimeStep(float ts) { ms_fTimeStep = ts; } static float GetTimeStepInSeconds() { return ms_fTimeStep / 50.0f; } From 5bc51f84622af8bf6ec3b2ef8d0faee0eca237c4 Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Tue, 10 Mar 2020 20:27:41 -0700 Subject: [PATCH 03/10] Save SimpleVars, Scripts, and a few others --- src/save/GenericGameStorage.cpp | 114 +++++++++++++++++++++++--------- 1 file changed, 83 insertions(+), 31 deletions(-) diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index 6880915d..3fbc97c0 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -3,6 +3,7 @@ #include "patcher.h" #include "Camera.h" #include "CarGen.h" +#include "Cranes.h" #include "Clock.h" #include "Date.h" #include "FileMgr.h" @@ -10,6 +11,7 @@ #include "Gangs.h" #include "Garages.h" #include "GenericGameStorage.h" +#include "Pad.h" #include "PathFind.h" #include "PCSave.h" #include "Phones.h" @@ -21,10 +23,11 @@ #include "Script.h" #include "Stats.h" #include "Streaming.h" +#include "Weather.h" #include "World.h" #include "Zones.h" -const int SIZE_OF_ONE_GAME_IN_BYTES = 201729; +const uint32 SIZE_OF_ONE_GAME_IN_BYTES = 201729; char (&DefaultPCSaveFileName)[260] = *(char(*)[260])*(uintptr*)0x8E28C0; char (&ValidSaveName)[260] = *(char(*)[260])*(uintptr*)0x8E2CBC; @@ -46,33 +49,85 @@ WRAPPER bool GenericLoad() { EAXJMP(0x590A00); } bool GenericSave(int file) { - /*char *tmpSaveName; - wchar saveName[24]; - SYSTEMTIME saveTime;*/ - - // TODO: Use GetLastMissionPassedName() to get this - //tmpSaveName = CStats::LastMissionPassedName; - - //AsciiToUnicode(tmpSaveName, saveName); - - //// TODO: some stuff here - - //memcpy(work_buff, saveName, 0x30); - //GetLocalTime((SYSTEMTIME *)(work_buff + 0x30)); - //*((uint32 *)(work_buff + 0x40)) = SIZE_OF_ONE_GAME_IN_BYTES; - //*((uint32 *)(work_buff + 0x44)) = CGame::currLevel; - // - //PcSaveHelper.PcClassSaveRoutine(file, work_buff, 0xE8); - + static const int NameBufferSize = 0x30; + static const int MaxNameLength = 22; + static const char *NameSuffix = "'...\0"; uint8 *buf; uint8 *tmpbuf; uint8 *postsize; uint32 size; uint32 reserved; - bool result; + wchar *saveName; + wchar suffix[6]; + wchar nameBuf[MaxNameLength] = { 0 }; + int nameLen; + CPad *currPad; - // TODO: simplevars and scripts + CheckSum = 0; + buf = work_buff; + + saveName = TheText.Get(CStats::LastMissionPassedName); + if (saveName[0] != '\0') { + AsciiToUnicode(NameSuffix, suffix); + TextCopy(nameBuf, saveName); + nameLen = UnicodeStrlen(nameBuf); + nameBuf[nameLen] = '\0'; + if (nameLen > MaxNameLength) + TextCopy(nameBuf + MaxNameLength, suffix); + } + + memcpy(buf, saveName, NameBufferSize); + buf += NameBufferSize; + GetLocalTime((LPSYSTEMTIME) buf); + buf += sizeof(SYSTEMTIME); + WriteSaveBuf(buf, SIZE_OF_ONE_GAME_IN_BYTES); + WriteSaveBuf(buf, CGame::currLevel); + WriteSaveBuf(buf, TheCamera.m_matrix.m_matrix.pos.x); + WriteSaveBuf(buf, TheCamera.m_matrix.m_matrix.pos.y); + WriteSaveBuf(buf, TheCamera.m_matrix.m_matrix.pos.z); + WriteSaveBuf(buf, CClock::ms_nMillisecondsPerGameMinute); + WriteSaveBuf(buf, CClock::ms_nLastClockTick); + WriteSaveBuf(buf, CClock::ms_nGameClockHours); + buf += 3; + WriteSaveBuf(buf, CClock::ms_nGameClockMinutes); // TOOD: aligned WriteSaveBuf? + buf += 3; + currPad = CPad::GetPad(0); + WriteSaveBuf(buf, currPad->Mode); + buf += 2; + WriteSaveBuf(buf, CTimer::m_snTimeInMilliseconds); + WriteSaveBuf(buf, CTimer::ms_fTimeScale); + WriteSaveBuf(buf, CTimer::ms_fTimeStep); + WriteSaveBuf(buf, CTimer::ms_fTimeStepNonClipped); + WriteSaveBuf(buf, CTimer::m_FrameCounter); + WriteSaveBuf(buf, 1.0f); // CTimeStep::ms_fTimeStep; + WriteSaveBuf(buf, 1.0f); // CTimeStep::ms_fFramesPerUpdate; + WriteSaveBuf(buf, 1.0f); // CTimeStep::ms_fTimeScale; + WriteSaveBuf(buf, CWeather::OldWeatherType); + buf += 2; + WriteSaveBuf(buf, CWeather::NewWeatherType); + buf += 2; + WriteSaveBuf(buf, CWeather::ForcedWeatherType); + buf += 2; + WriteSaveBuf(buf, CWeather::InterpolationValue); + WriteSaveBuf(buf, CompileDateAndTime.m_nSecond); + WriteSaveBuf(buf, CompileDateAndTime.m_nMinute); + WriteSaveBuf(buf, CompileDateAndTime.m_nHour); + WriteSaveBuf(buf, CompileDateAndTime.m_nDay); + WriteSaveBuf(buf, CompileDateAndTime.m_nMonth); + WriteSaveBuf(buf, CompileDateAndTime.m_nYear); + WriteSaveBuf(buf, CWeather::WeatherTypeInList); + WriteSaveBuf(buf, TheCamera.m_fCarZoomValueScript); // TODO: unconfirmed + WriteSaveBuf(buf, TheCamera.m_fPedZoomValueScript); // TODO: unconfirmed + + size = 0; + reserved = 0; + + MakeSpaceForSizeInBufferPointer(tmpbuf, buf, postsize); + CTheScripts::SaveAllScripts(buf, &size); + CopySizeAndPreparePointer(tmpbuf, buf, postsize, reserved, size); + if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, size)) + return false; for (int i = 1; i < 19; i++) { buf = work_buff; @@ -80,12 +135,12 @@ GenericSave(int file) reserved = 0; MakeSpaceForSizeInBufferPointer(tmpbuf, buf, postsize); switch (i) { - case 1: break; - case 2: break; - case 3: break; - case 4: break; + case 1: CPools::SavePedPool(buf, &size); break; + case 2: CGarages::Save(buf, &size); break; + case 3: CPools::SaveVehiclePool(buf, &size); break; + case 4: CPools::SaveObjectPool(buf, &size); break; case 5: ThePaths.Save(buf, &size); break; - case 6: break; + case 6: CCranes::Save(buf, &size); break; case 7: CPickups::Save(buf, &size); break; case 8: gPhoneInfo.Save(buf, &size); break; case 9: CRestart::SaveAllRestartPoints(buf, &size); break; @@ -102,11 +157,8 @@ GenericSave(int file) } CopySizeAndPreparePointer(tmpbuf, buf, postsize, reserved, size); - result = PcSaveHelper.PcClassSaveRoutine(file, work_buff, size); - if (!result) - { + if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, size)) return false; - } } @@ -163,7 +215,7 @@ DoGameSpecificStuffAfterSucessLoad() StillToFadeOut = true; JustLoadedDontFadeInYet = true; CTheScripts::Process(); -} + } bool CheckSlotDataValid(int32 slot) From c7f16879df25fc962b67716e1f82881595451a5f Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Wed, 11 Mar 2020 00:12:40 -0700 Subject: [PATCH 04/10] GenericSave complete, still needs some testing --- src/audio/AudioScriptObject.cpp | 2 + src/audio/AudioScriptObject.h | 2 + src/core/Stats.cpp | 3 + src/core/Stats.h | 1 + src/core/common.h | 8 +- src/core/re3.cpp | 2 +- src/save/GenericGameStorage.cpp | 183 +++++++++++++++++++------------- 7 files changed, 120 insertions(+), 81 deletions(-) diff --git a/src/audio/AudioScriptObject.cpp b/src/audio/AudioScriptObject.cpp index c5115ddb..796cd88b 100644 --- a/src/audio/AudioScriptObject.cpp +++ b/src/audio/AudioScriptObject.cpp @@ -3,6 +3,8 @@ #include "AudioScriptObject.h" #include "Pools.h" +WRAPPER void cAudioScriptObject::SaveAllAudioScriptObjects(uint8 *buf, uint32 *size) { EAXJMP(0x57c460); } + void cAudioScriptObject::Reset() { diff --git a/src/audio/AudioScriptObject.h b/src/audio/AudioScriptObject.h index 9aac1c30..1db19865 100644 --- a/src/audio/AudioScriptObject.h +++ b/src/audio/AudioScriptObject.h @@ -141,6 +141,8 @@ public: static void* operator new(size_t, int); static void operator delete(void*, size_t); static void operator delete(void*, int); + + static void SaveAllAudioScriptObjects(uint8 *buf, uint32 *size); }; static_assert(sizeof(cAudioScriptObject) == 20, "cAudioScriptObject: error"); diff --git a/src/core/Stats.cpp b/src/core/Stats.cpp index 2c27ba70..1d088e04 100644 --- a/src/core/Stats.cpp +++ b/src/core/Stats.cpp @@ -1,6 +1,9 @@ #include "common.h" +#include "patcher.h" #include "Stats.h" +WRAPPER void CStats::SaveStats(uint8 *buf, uint32 *size) { EAXJMP(0x4ab3e0); } + int32 &CStats::DaysPassed = *(int32*)0x8F2BB8; int32 &CStats::HeadsPopped = *(int32*)0x8F647C; bool& CStats::CommercialPassed = *(bool*)0x8F4334; diff --git a/src/core/Stats.h b/src/core/Stats.h index 4b558c32..7ee4aed0 100644 --- a/src/core/Stats.h +++ b/src/core/Stats.h @@ -73,4 +73,5 @@ public: static void CheckPointReachedUnsuccessfully() { KillsSinceLastCheckpoint = 0; }; static void CheckPointReachedSuccessfully() { TotalLegitimateKills += KillsSinceLastCheckpoint; KillsSinceLastCheckpoint = 0; }; static void RegisterElBurroTime(int32); + static void SaveStats(uint8 *buf, uint32 *size); }; \ No newline at end of file diff --git a/src/core/common.h b/src/core/common.h index cadcac1d..9a5cdb38 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -321,9 +321,9 @@ _TWEEKCLASS(CTweakFloat, float); #undef _TWEEKCLASS #ifdef VALIDATE_SAVE_SIZE -extern int32 _bufBytesRead; -#define INITSAVEBUF _bufBytesRead = 0; -#define VALIDATESAVEBUF(b) assert(_bufBytesRead == b); +extern int32 _saveBufCount; +#define INITSAVEBUF _saveBufCount = 0; +#define VALIDATESAVEBUF(b) assert(_saveBufCount == b); #else #define INITSAVEBUF #define VALIDATESAVEBUF(b) @@ -333,7 +333,7 @@ inline void SkipSaveBuf(uint8 *&buf, int32 skip) { buf += skip; #ifdef VALIDATE_SAVE_SIZE - _bufBytesRead += skip; + _saveBufCount += skip; #endif } diff --git a/src/core/re3.cpp b/src/core/re3.cpp index 989a05b5..ed32632f 100644 --- a/src/core/re3.cpp +++ b/src/core/re3.cpp @@ -449,7 +449,7 @@ void re3_trace(const char *filename, unsigned int lineno, const char *func, cons } #ifdef VALIDATE_SAVE_SIZE -int32 _bufBytesRead; +int32 _saveBufCount; #endif void diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index 3fbc97c0..7a2da753 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -1,6 +1,7 @@ #include "common.h" #include "main.h" #include "patcher.h" +#include "AudioScriptObject.h" #include "Camera.h" #include "CarGen.h" #include "Cranes.h" @@ -12,6 +13,7 @@ #include "Garages.h" #include "GenericGameStorage.h" #include "Pad.h" +#include "ParticleObject.h" #include "PathFind.h" #include "PCSave.h" #include "Phones.h" @@ -27,6 +29,7 @@ #include "World.h" #include "Zones.h" +#define BLOCK_COUNT 20 const uint32 SIZE_OF_ONE_GAME_IN_BYTES = 201729; char (&DefaultPCSaveFileName)[260] = *(char(*)[260])*(uintptr*)0x8E28C0; @@ -46,41 +49,60 @@ CDate &CompileDateAndTime = *(CDate*)0x72BCB8; //WRAPPER bool GenericSave(int file) { EAXJMP(0x58F8D0); } WRAPPER bool GenericLoad() { EAXJMP(0x590A00); } + +#define WRITE_BLOCK(save_func)\ +do {\ + buf = work_buff;\ + reserved = 0;\ + MakeSpaceForSizeInBufferPointer(presize, buf, postsize);\ + save_func(buf, &size);\ + CopySizeAndPreparePointer(presize, buf, postsize, reserved, size);\ + if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, size))\ + return false;\ + blockSizes[blockIndex++] = size;\ +} while (0) + bool GenericSave(int file) { - static const int NameBufferSize = 0x30; - static const int MaxNameLength = 22; - static const char *NameSuffix = "'...\0"; - - uint8 *buf; - uint8 *tmpbuf; - uint8 *postsize; + uint8 *buf, *presize, *postsize; uint32 size; uint32 reserved; - wchar *saveName; + + uint32 totalSize; + uint32 blockSizes[BLOCK_COUNT]; + uint32 blockIndex; + uint32 i; + + wchar *lastMissionPassed; wchar suffix[6]; - wchar nameBuf[MaxNameLength] = { 0 }; - int nameLen; + wchar saveName[24]; + SYSTEMTIME saveTime; CPad *currPad; CheckSum = 0; buf = work_buff; + reserved = 0; + blockIndex = 0; - saveName = TheText.Get(CStats::LastMissionPassedName); - if (saveName[0] != '\0') { - AsciiToUnicode(NameSuffix, suffix); - TextCopy(nameBuf, saveName); - nameLen = UnicodeStrlen(nameBuf); - nameBuf[nameLen] = '\0'; - if (nameLen > MaxNameLength) - TextCopy(nameBuf + MaxNameLength, suffix); + // Save simple vars +INITSAVEBUF + lastMissionPassed = TheText.Get(CStats::LastMissionPassedName); + if (*lastMissionPassed) { + AsciiToUnicode("'...", suffix); + TextCopy(saveName, lastMissionPassed); + int len = UnicodeStrlen(saveName); + saveName[len] = '\0'; + if (22 < len) + TextCopy(saveName + 18, suffix); + saveName[23] = '\0'; } - - memcpy(buf, saveName, NameBufferSize); - buf += NameBufferSize; - GetLocalTime((LPSYSTEMTIME) buf); - buf += sizeof(SYSTEMTIME); + WriteDataToBufferPointer(buf, saveName); +#ifdef VALIDATE_SAVE_SIZE + _saveBufCount += sizeof(saveName); +#endif + GetLocalTime(&saveTime); + WriteSaveBuf(buf, saveTime); WriteSaveBuf(buf, SIZE_OF_ONE_GAME_IN_BYTES); WriteSaveBuf(buf, CGame::currLevel); WriteSaveBuf(buf, TheCamera.m_matrix.m_matrix.pos.x); @@ -88,13 +110,10 @@ GenericSave(int file) WriteSaveBuf(buf, TheCamera.m_matrix.m_matrix.pos.z); WriteSaveBuf(buf, CClock::ms_nMillisecondsPerGameMinute); WriteSaveBuf(buf, CClock::ms_nLastClockTick); - WriteSaveBuf(buf, CClock::ms_nGameClockHours); - buf += 3; - WriteSaveBuf(buf, CClock::ms_nGameClockMinutes); // TOOD: aligned WriteSaveBuf? - buf += 3; + WriteSaveBuf(buf, (uint32) CClock::ms_nGameClockHours); + WriteSaveBuf(buf, (uint32) CClock::ms_nGameClockMinutes); currPad = CPad::GetPad(0); - WriteSaveBuf(buf, currPad->Mode); - buf += 2; + WriteSaveBuf(buf, (uint32) currPad->Mode); WriteSaveBuf(buf, CTimer::m_snTimeInMilliseconds); WriteSaveBuf(buf, CTimer::ms_fTimeScale); WriteSaveBuf(buf, CTimer::ms_fTimeStep); @@ -103,12 +122,9 @@ GenericSave(int file) WriteSaveBuf(buf, 1.0f); // CTimeStep::ms_fTimeStep; WriteSaveBuf(buf, 1.0f); // CTimeStep::ms_fFramesPerUpdate; WriteSaveBuf(buf, 1.0f); // CTimeStep::ms_fTimeScale; - WriteSaveBuf(buf, CWeather::OldWeatherType); - buf += 2; - WriteSaveBuf(buf, CWeather::NewWeatherType); - buf += 2; - WriteSaveBuf(buf, CWeather::ForcedWeatherType); - buf += 2; + WriteSaveBuf(buf, (int32) CWeather::OldWeatherType); + WriteSaveBuf(buf, (int32) CWeather::NewWeatherType); + WriteSaveBuf(buf, (int32) CWeather::ForcedWeatherType); WriteSaveBuf(buf, CWeather::InterpolationValue); WriteSaveBuf(buf, CompileDateAndTime.m_nSecond); WriteSaveBuf(buf, CompileDateAndTime.m_nMinute); @@ -117,53 +133,68 @@ GenericSave(int file) WriteSaveBuf(buf, CompileDateAndTime.m_nMonth); WriteSaveBuf(buf, CompileDateAndTime.m_nYear); WriteSaveBuf(buf, CWeather::WeatherTypeInList); - WriteSaveBuf(buf, TheCamera.m_fCarZoomValueScript); // TODO: unconfirmed - WriteSaveBuf(buf, TheCamera.m_fPedZoomValueScript); // TODO: unconfirmed + WriteSaveBuf(buf, TheCamera.CarZoomIndicator); + WriteSaveBuf(buf, TheCamera.PedZoomIndicator); +VALIDATESAVEBUF(0xBC); - size = 0; - reserved = 0; - - MakeSpaceForSizeInBufferPointer(tmpbuf, buf, postsize); + // Save scripts, block is nested within the same block as simple vars for some reason + presize = buf; + buf += 4; + postsize = buf; CTheScripts::SaveAllScripts(buf, &size); - CopySizeAndPreparePointer(tmpbuf, buf, postsize, reserved, size); + CopySizeAndPreparePointer(presize, buf, postsize, reserved, size); if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, size)) return false; + blockSizes[0] = size + 0xBC; + blockIndex++; - for (int i = 1; i < 19; i++) { - buf = work_buff; - size = 0; - reserved = 0; - MakeSpaceForSizeInBufferPointer(tmpbuf, buf, postsize); - switch (i) { - case 1: CPools::SavePedPool(buf, &size); break; - case 2: CGarages::Save(buf, &size); break; - case 3: CPools::SaveVehiclePool(buf, &size); break; - case 4: CPools::SaveObjectPool(buf, &size); break; - case 5: ThePaths.Save(buf, &size); break; - case 6: CCranes::Save(buf, &size); break; - case 7: CPickups::Save(buf, &size); break; - case 8: gPhoneInfo.Save(buf, &size); break; - case 9: CRestart::SaveAllRestartPoints(buf, &size); break; - case 10: CRadar::SaveAllRadarBlips(buf, &size); break; - case 11: CTheZones::SaveAllZones(buf, &size); break; - case 12: CGangs::SaveAllGangData(buf, &size); break; - case 13: CTheCarGenerators::SaveAllCarGenerators(buf, &size); break; - case 14: break; - case 15: break; - case 16: break; - case 17: break; - case 18: break; - case 19: break; + // Save the rest + WRITE_BLOCK(CPools::SavePedPool); + WRITE_BLOCK(CGarages::Save); + WRITE_BLOCK(CPools::SaveVehiclePool); + WRITE_BLOCK(CPools::SaveObjectPool); + WRITE_BLOCK(ThePaths.Save); + WRITE_BLOCK(CCranes::Save); + WRITE_BLOCK(CPickups::Save); + WRITE_BLOCK(gPhoneInfo.Save); + WRITE_BLOCK(CRestart::SaveAllRestartPoints); + WRITE_BLOCK(CRadar::SaveAllRadarBlips); + WRITE_BLOCK(CTheZones::SaveAllZones); + WRITE_BLOCK(CGangs::SaveAllGangData); + WRITE_BLOCK(CTheCarGenerators::SaveAllCarGenerators); + WRITE_BLOCK(CParticleObject::SaveParticle); + WRITE_BLOCK(cAudioScriptObject::SaveAllAudioScriptObjects); + WRITE_BLOCK(CWorld::Players[CWorld::PlayerInFocus].SavePlayerInfo); + WRITE_BLOCK(CStats::SaveStats); + WRITE_BLOCK(CStreaming::MemoryCardSave); + WRITE_BLOCK(CPedType::Save); + + totalSize = 0; + for (i = 0; i < BLOCK_COUNT; i++) + totalSize += blockSizes[i]; + + // Write padding + i = 0; + do { + size = align4bytes(SIZE_OF_ONE_GAME_IN_BYTES - totalSize - 4); + if (size > sizeof(work_buff)) + size = sizeof(work_buff); + if (size > 4) { + if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, size)) + return false; + totalSize += size; } - - CopySizeAndPreparePointer(tmpbuf, buf, postsize, reserved, size); - if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, size)) - return false; + i++; + } while (i < 4); + + // Write checksum and close + CFileMgr::Write(file, (const char *) &CheckSum, 4); + if (CFileMgr::GetErrorReadWrite(file)) { + PcSaveHelper.nErrorCode = SAVESTATUS_ERR_SAVE_WRITE; + if (CFileMgr::CloseFile(file) == 0) + PcSaveHelper.nErrorCode = SAVESTATUS_ERR_SAVE_CLOSE; + return false; } - - - - // TODO: padding return true; } @@ -380,7 +411,7 @@ align4bytes(int32 size) } STARTPATCHES - //InjectHook(0x58F8D0, GenericSave, PATCH_JUMP); + InjectHook(0x58F8D0, GenericSave, PATCH_JUMP); //InjectHook(0x590A00, GenericLoad, PATCH_JUMP); InjectHook(0x591910, ReadInSizeofSaveFileBuffer, PATCH_JUMP); InjectHook(0x591990, ReadDataFromFile, PATCH_JUMP); From 81c4f75c63a851a9f63fe31aacde5b58bb3a7f4a Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Wed, 11 Mar 2020 14:08:10 -0700 Subject: [PATCH 05/10] Bugfixes, GenericSave() works now! --- src/save/GenericGameStorage.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index 7a2da753..7cef6c9e 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -30,6 +30,8 @@ #include "Zones.h" #define BLOCK_COUNT 20 +#define SIZE_OF_SIMPLEVARS 0xBC + const uint32 SIZE_OF_ONE_GAME_IN_BYTES = 201729; char (&DefaultPCSaveFileName)[260] = *(char(*)[260])*(uintptr*)0x8E28C0; @@ -57,9 +59,9 @@ do {\ MakeSpaceForSizeInBufferPointer(presize, buf, postsize);\ save_func(buf, &size);\ CopySizeAndPreparePointer(presize, buf, postsize, reserved, size);\ - if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, size))\ + if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, size + 4))\ return false;\ - blockSizes[blockIndex++] = size;\ + totalSize += size;\ } while (0) bool @@ -70,8 +72,6 @@ GenericSave(int file) uint32 reserved; uint32 totalSize; - uint32 blockSizes[BLOCK_COUNT]; - uint32 blockIndex; uint32 i; wchar *lastMissionPassed; @@ -83,7 +83,7 @@ GenericSave(int file) CheckSum = 0; buf = work_buff; reserved = 0; - blockIndex = 0; + totalSize = 0; // Save simple vars INITSAVEBUF @@ -135,7 +135,7 @@ INITSAVEBUF WriteSaveBuf(buf, CWeather::WeatherTypeInList); WriteSaveBuf(buf, TheCamera.CarZoomIndicator); WriteSaveBuf(buf, TheCamera.PedZoomIndicator); -VALIDATESAVEBUF(0xBC); +VALIDATESAVEBUF(SIZE_OF_SIMPLEVARS); // Save scripts, block is nested within the same block as simple vars for some reason presize = buf; @@ -143,10 +143,9 @@ VALIDATESAVEBUF(0xBC); postsize = buf; CTheScripts::SaveAllScripts(buf, &size); CopySizeAndPreparePointer(presize, buf, postsize, reserved, size); - if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, size)) + if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, size + SIZE_OF_SIMPLEVARS + 4)) return false; - blockSizes[0] = size + 0xBC; - blockIndex++; + totalSize += size + SIZE_OF_SIMPLEVARS; // Save the rest WRITE_BLOCK(CPools::SavePedPool); @@ -169,10 +168,6 @@ VALIDATESAVEBUF(0xBC); WRITE_BLOCK(CStreaming::MemoryCardSave); WRITE_BLOCK(CPedType::Save); - totalSize = 0; - for (i = 0; i < BLOCK_COUNT; i++) - totalSize += blockSizes[i]; - // Write padding i = 0; do { @@ -188,10 +183,10 @@ VALIDATESAVEBUF(0xBC); } while (i < 4); // Write checksum and close - CFileMgr::Write(file, (const char *) &CheckSum, 4); + CFileMgr::Write(file, (const char *) &CheckSum, sizeof(CheckSum)); if (CFileMgr::GetErrorReadWrite(file)) { PcSaveHelper.nErrorCode = SAVESTATUS_ERR_SAVE_WRITE; - if (CFileMgr::CloseFile(file) == 0) + if (CloseFile(file)) PcSaveHelper.nErrorCode = SAVESTATUS_ERR_SAVE_CLOSE; return false; } From 018fb3a9298c8c549745ad5af9fb708ef7b8cb41 Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Wed, 11 Mar 2020 14:15:27 -0700 Subject: [PATCH 06/10] Style fixes --- src/core/Stats.h | 2 +- src/save/GenericGameStorage.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/Stats.h b/src/core/Stats.h index 7ee4aed0..4bf99c45 100644 --- a/src/core/Stats.h +++ b/src/core/Stats.h @@ -74,4 +74,4 @@ public: static void CheckPointReachedSuccessfully() { TotalLegitimateKills += KillsSinceLastCheckpoint; KillsSinceLastCheckpoint = 0; }; static void RegisterElBurroTime(int32); static void SaveStats(uint8 *buf, uint32 *size); -}; \ No newline at end of file +}; diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index 7cef6c9e..5a0df1fe 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -241,7 +241,7 @@ DoGameSpecificStuffAfterSucessLoad() StillToFadeOut = true; JustLoadedDontFadeInYet = true; CTheScripts::Process(); - } +} bool CheckSlotDataValid(int32 slot) From 8280dda9cba53608be137a7e6a82ea45aca339c4 Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Fri, 13 Mar 2020 13:46:59 -0700 Subject: [PATCH 07/10] Add CTimeStep --- src/core/TimeStep.cpp | 5 +++++ src/core/TimeStep.h | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/core/TimeStep.cpp create mode 100644 src/core/TimeStep.h diff --git a/src/core/TimeStep.cpp b/src/core/TimeStep.cpp new file mode 100644 index 00000000..9ccf7200 --- /dev/null +++ b/src/core/TimeStep.cpp @@ -0,0 +1,5 @@ +#include "TimeStep.h" + +float &CTimeStep::ms_fTimeScale = *(float*)0x5F76C8; +float &CTimeStep::ms_fFramesPerUpdate = *(float*)0x5F76CC; +float &CTimeStep::ms_fTimeStep = *(float*)0x5F76D0; diff --git a/src/core/TimeStep.h b/src/core/TimeStep.h new file mode 100644 index 00000000..ee595383 --- /dev/null +++ b/src/core/TimeStep.h @@ -0,0 +1,10 @@ +#pragma once + +// Pretty sure this class is not used by the game +class CTimeStep +{ +public: + static float &ms_fTimeScale; + static float &ms_fFramesPerUpdate; + static float &ms_fTimeStep; +}; \ No newline at end of file From 3862cda2318ead796544b70549176588e4917d91 Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Fri, 13 Mar 2020 13:47:53 -0700 Subject: [PATCH 08/10] Style fix, use CTimeStep --- src/save/GenericGameStorage.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index 5a0df1fe..d3d1d989 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -25,6 +25,8 @@ #include "Script.h" #include "Stats.h" #include "Streaming.h" +#include "Timer.h" +#include "TimeStep.h" #include "Weather.h" #include "World.h" #include "Zones.h" @@ -93,7 +95,7 @@ INITSAVEBUF TextCopy(saveName, lastMissionPassed); int len = UnicodeStrlen(saveName); saveName[len] = '\0'; - if (22 < len) + if (len > 22) TextCopy(saveName + 18, suffix); saveName[23] = '\0'; } @@ -119,9 +121,9 @@ INITSAVEBUF WriteSaveBuf(buf, CTimer::ms_fTimeStep); WriteSaveBuf(buf, CTimer::ms_fTimeStepNonClipped); WriteSaveBuf(buf, CTimer::m_FrameCounter); - WriteSaveBuf(buf, 1.0f); // CTimeStep::ms_fTimeStep; - WriteSaveBuf(buf, 1.0f); // CTimeStep::ms_fFramesPerUpdate; - WriteSaveBuf(buf, 1.0f); // CTimeStep::ms_fTimeScale; + WriteSaveBuf(buf, CTimeStep::ms_fTimeStep); + WriteSaveBuf(buf, CTimeStep::ms_fFramesPerUpdate); + WriteSaveBuf(buf, CTimeStep::ms_fTimeScale); WriteSaveBuf(buf, (int32) CWeather::OldWeatherType); WriteSaveBuf(buf, (int32) CWeather::NewWeatherType); WriteSaveBuf(buf, (int32) CWeather::ForcedWeatherType); From afeac5486046a4db987f2572264ed13eac1b2de2 Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Fri, 13 Mar 2020 13:50:23 -0700 Subject: [PATCH 09/10] Spacing fix --- src/core/TimeStep.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/TimeStep.h b/src/core/TimeStep.h index ee595383..c74df02a 100644 --- a/src/core/TimeStep.h +++ b/src/core/TimeStep.h @@ -4,7 +4,7 @@ class CTimeStep { public: - static float &ms_fTimeScale; - static float &ms_fFramesPerUpdate; + static float &ms_fTimeScale; + static float &ms_fFramesPerUpdate; static float &ms_fTimeStep; -}; \ No newline at end of file +}; From f35758a8f18fac2da8624eb273d1791b337f3cb5 Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Fri, 13 Mar 2020 21:23:03 -0700 Subject: [PATCH 10/10] Use WriteDataToBufferPointer --- src/save/GenericGameStorage.cpp | 70 ++++++++++++++++----------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index d3d1d989..8c851686 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -100,43 +100,43 @@ INITSAVEBUF saveName[23] = '\0'; } WriteDataToBufferPointer(buf, saveName); -#ifdef VALIDATE_SAVE_SIZE - _saveBufCount += sizeof(saveName); -#endif GetLocalTime(&saveTime); - WriteSaveBuf(buf, saveTime); - WriteSaveBuf(buf, SIZE_OF_ONE_GAME_IN_BYTES); - WriteSaveBuf(buf, CGame::currLevel); - WriteSaveBuf(buf, TheCamera.m_matrix.m_matrix.pos.x); - WriteSaveBuf(buf, TheCamera.m_matrix.m_matrix.pos.y); - WriteSaveBuf(buf, TheCamera.m_matrix.m_matrix.pos.z); - WriteSaveBuf(buf, CClock::ms_nMillisecondsPerGameMinute); - WriteSaveBuf(buf, CClock::ms_nLastClockTick); - WriteSaveBuf(buf, (uint32) CClock::ms_nGameClockHours); - WriteSaveBuf(buf, (uint32) CClock::ms_nGameClockMinutes); + WriteDataToBufferPointer(buf, saveTime); + WriteDataToBufferPointer(buf, SIZE_OF_ONE_GAME_IN_BYTES); + WriteDataToBufferPointer(buf, CGame::currLevel); + WriteDataToBufferPointer(buf, TheCamera.m_matrix.m_matrix.pos.x); + WriteDataToBufferPointer(buf, TheCamera.m_matrix.m_matrix.pos.y); + WriteDataToBufferPointer(buf, TheCamera.m_matrix.m_matrix.pos.z); + WriteDataToBufferPointer(buf, CClock::ms_nMillisecondsPerGameMinute); + WriteDataToBufferPointer(buf, CClock::ms_nLastClockTick); + WriteDataToBufferPointer(buf, CClock::ms_nGameClockHours); + WriteDataToBufferPointer(buf, CClock::ms_nGameClockMinutes); currPad = CPad::GetPad(0); - WriteSaveBuf(buf, (uint32) currPad->Mode); - WriteSaveBuf(buf, CTimer::m_snTimeInMilliseconds); - WriteSaveBuf(buf, CTimer::ms_fTimeScale); - WriteSaveBuf(buf, CTimer::ms_fTimeStep); - WriteSaveBuf(buf, CTimer::ms_fTimeStepNonClipped); - WriteSaveBuf(buf, CTimer::m_FrameCounter); - WriteSaveBuf(buf, CTimeStep::ms_fTimeStep); - WriteSaveBuf(buf, CTimeStep::ms_fFramesPerUpdate); - WriteSaveBuf(buf, CTimeStep::ms_fTimeScale); - WriteSaveBuf(buf, (int32) CWeather::OldWeatherType); - WriteSaveBuf(buf, (int32) CWeather::NewWeatherType); - WriteSaveBuf(buf, (int32) CWeather::ForcedWeatherType); - WriteSaveBuf(buf, CWeather::InterpolationValue); - WriteSaveBuf(buf, CompileDateAndTime.m_nSecond); - WriteSaveBuf(buf, CompileDateAndTime.m_nMinute); - WriteSaveBuf(buf, CompileDateAndTime.m_nHour); - WriteSaveBuf(buf, CompileDateAndTime.m_nDay); - WriteSaveBuf(buf, CompileDateAndTime.m_nMonth); - WriteSaveBuf(buf, CompileDateAndTime.m_nYear); - WriteSaveBuf(buf, CWeather::WeatherTypeInList); - WriteSaveBuf(buf, TheCamera.CarZoomIndicator); - WriteSaveBuf(buf, TheCamera.PedZoomIndicator); + WriteDataToBufferPointer(buf, currPad->Mode); + WriteDataToBufferPointer(buf, CTimer::m_snTimeInMilliseconds); + WriteDataToBufferPointer(buf, CTimer::ms_fTimeScale); + WriteDataToBufferPointer(buf, CTimer::ms_fTimeStep); + WriteDataToBufferPointer(buf, CTimer::ms_fTimeStepNonClipped); + WriteDataToBufferPointer(buf, CTimer::m_FrameCounter); + WriteDataToBufferPointer(buf, CTimeStep::ms_fTimeStep); + WriteDataToBufferPointer(buf, CTimeStep::ms_fFramesPerUpdate); + WriteDataToBufferPointer(buf, CTimeStep::ms_fTimeScale); + WriteDataToBufferPointer(buf, CWeather::OldWeatherType); + WriteDataToBufferPointer(buf, CWeather::NewWeatherType); + WriteDataToBufferPointer(buf, CWeather::ForcedWeatherType); + WriteDataToBufferPointer(buf, CWeather::InterpolationValue); + WriteDataToBufferPointer(buf, CompileDateAndTime.m_nSecond); + WriteDataToBufferPointer(buf, CompileDateAndTime.m_nMinute); + WriteDataToBufferPointer(buf, CompileDateAndTime.m_nHour); + WriteDataToBufferPointer(buf, CompileDateAndTime.m_nDay); + WriteDataToBufferPointer(buf, CompileDateAndTime.m_nMonth); + WriteDataToBufferPointer(buf, CompileDateAndTime.m_nYear); + WriteDataToBufferPointer(buf, CWeather::WeatherTypeInList); + WriteDataToBufferPointer(buf, TheCamera.CarZoomIndicator); + WriteDataToBufferPointer(buf, TheCamera.PedZoomIndicator); +#ifdef VALIDATE_SAVE_SIZE + _saveBufCount = buf - work_buff; +#endif VALIDATESAVEBUF(SIZE_OF_SIMPLEVARS); // Save scripts, block is nested within the same block as simple vars for some reason