From 4fee2cbdd9948bd591d6e5bebd4bed827e12498a Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Thu, 5 Mar 2020 01:44:42 -0800 Subject: Begin work on GenericSave --- src/save/GenericGameStorage.cpp | 84 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) (limited to 'src/save/GenericGameStorage.cpp') 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) { -- cgit v1.2.3 From 5bc51f84622af8bf6ec3b2ef8d0faee0eca237c4 Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Tue, 10 Mar 2020 20:27:41 -0700 Subject: Save SimpleVars, Scripts, and a few others --- src/save/GenericGameStorage.cpp | 114 +++++++++++++++++++++++++++++----------- 1 file changed, 83 insertions(+), 31 deletions(-) (limited to 'src/save/GenericGameStorage.cpp') 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) -- cgit v1.2.3 From c7f16879df25fc962b67716e1f82881595451a5f Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Wed, 11 Mar 2020 00:12:40 -0700 Subject: GenericSave complete, still needs some testing --- src/save/GenericGameStorage.cpp | 187 +++++++++++++++++++++++----------------- 1 file changed, 109 insertions(+), 78 deletions(-) (limited to 'src/save/GenericGameStorage.cpp') 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; - - 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); + reserved = 0; + blockIndex = 0; + + // 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; - - 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; + blockSizes[0] = size + 0xBC; + blockIndex++; + + // 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); - // TODO: padding + // 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; + } 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); -- cgit v1.2.3 From 81c4f75c63a851a9f63fe31aacde5b58bb3a7f4a Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Wed, 11 Mar 2020 14:08:10 -0700 Subject: Bugfixes, GenericSave() works now! --- src/save/GenericGameStorage.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'src/save/GenericGameStorage.cpp') 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; } -- cgit v1.2.3 From 018fb3a9298c8c549745ad5af9fb708ef7b8cb41 Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Wed, 11 Mar 2020 14:15:27 -0700 Subject: Style fixes --- src/save/GenericGameStorage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/save/GenericGameStorage.cpp') 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) -- cgit v1.2.3 From 3862cda2318ead796544b70549176588e4917d91 Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Fri, 13 Mar 2020 13:47:53 -0700 Subject: Style fix, use CTimeStep --- src/save/GenericGameStorage.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/save/GenericGameStorage.cpp') 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); -- cgit v1.2.3 From f35758a8f18fac2da8624eb273d1791b337f3cb5 Mon Sep 17 00:00:00 2001 From: Wes Hampson Date: Fri, 13 Mar 2020 21:23:03 -0700 Subject: Use WriteDataToBufferPointer --- src/save/GenericGameStorage.cpp | 70 ++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'src/save/GenericGameStorage.cpp') 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 -- cgit v1.2.3