diff options
Diffstat (limited to 'src/save')
-rw-r--r-- | src/save/GenericGameStorage.cpp | 87 | ||||
-rw-r--r-- | src/save/GenericGameStorage.h | 32 | ||||
-rw-r--r-- | src/save/PCSave.cpp | 25 | ||||
-rw-r--r-- | src/save/PCSave.h | 2 |
4 files changed, 76 insertions, 70 deletions
diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index 0ec0b117..29f666df 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -1,7 +1,8 @@ -#define WITHWINDOWS #include "common.h" +#define USEALTERNATIVEWINFUNCS +#include "crossplatform.h" #include "main.h" -#include "patcher.h" + #include "AudioScriptObject.h" #include "Camera.h" #include "CarGen.h" @@ -40,22 +41,22 @@ const uint32 SIZE_OF_ONE_GAME_IN_BYTES = 201729; -char (&DefaultPCSaveFileName)[260] = *(char(*)[260])*(uintptr*)0x8E28C0; -char (&ValidSaveName)[260] = *(char(*)[260])*(uintptr*)0x8E2CBC; -char (&LoadFileName)[256] = *(char(*)[256])*(uintptr*)0x9403C4; -wchar (&SlotFileName)[SLOT_COUNT][260] = *(wchar(*)[SLOT_COUNT][260])*(uintptr*)0x6F07C8; -wchar (&SlotSaveDate)[SLOT_COUNT][70] = *(wchar(*)[SLOT_COUNT][70])*(uintptr*)0x72B858; -int &CheckSum = *(int*)0x8E2BE0; -eLevelName &m_LevelToLoad = *(eLevelName*)0x8E29CC; +char DefaultPCSaveFileName[260]; +char ValidSaveName[260]; +char LoadFileName[256]; +wchar SlotFileName[SLOT_COUNT][260]; +wchar SlotSaveDate[SLOT_COUNT][70]; +int CheckSum; +eLevelName m_LevelToLoad; char SaveFileNameJustSaved[260]; -int (&Slots)[SLOT_COUNT+1] = *(int(*)[SLOT_COUNT+1])*(uintptr*)0x72803C; -CDate &CompileDateAndTime = *(CDate*)0x72BCB8; +int Slots[SLOT_COUNT+1]; +CDate CompileDateAndTime; -bool &b_FoundRecentSavedGameWantToLoad = *(bool*)0x95CDA8; -bool &JustLoadedDontFadeInYet = *(bool*)0x95CDB4; -bool &StillToFadeOut = *(bool*)0x95CD99; -uint32 &TimeStartedCountingForFade = *(uint32*)0x9430EC; -uint32 &TimeToStayFadedBeforeFadeOut = *(uint32*)0x611564; +bool b_FoundRecentSavedGameWantToLoad; +bool JustLoadedDontFadeInYet; +bool StillToFadeOut; +uint32 TimeStartedCountingForFade; +uint32 TimeToStayFadedBeforeFadeOut = 1750; #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)); @@ -112,14 +113,22 @@ GenericSave(int file) // Save simple vars lastMissionPassed = TheText.Get(CStats::LastMissionPassedName); - if (*lastMissionPassed) { + if (lastMissionPassed[0] != '\0') { AsciiToUnicode("...'", suffix); +#ifdef FIX_BUGS + // fix buffer overflow + int len = UnicodeStrlen(lastMissionPassed); + if (len > ARRAY_SIZE(saveName)-1) + len = ARRAY_SIZE(saveName)-1; + memcpy(saveName, lastMissionPassed, sizeof(wchar) * len); +#else TextCopy(saveName, lastMissionPassed); int len = UnicodeStrlen(saveName); +#endif saveName[len] = '\0'; - if (len > 22) - TextCopy(saveName + 18, suffix); - saveName[23] = '\0'; + if (len > ARRAY_SIZE(saveName)-2) + TextCopy(&saveName[ARRAY_SIZE(saveName)-ARRAY_SIZE(suffix)], suffix); + saveName[ARRAY_SIZE(saveName)-1] = '\0'; } WriteDataToBufferPointer(buf, saveName); GetLocalTime(&saveTime); @@ -154,8 +163,17 @@ GenericSave(int file) WriteDataToBufferPointer(buf, CompileDateAndTime.m_nMonth); WriteDataToBufferPointer(buf, CompileDateAndTime.m_nYear); WriteDataToBufferPointer(buf, CWeather::WeatherTypeInList); +#ifdef FIX_BUGS + // converted to float for compatibility with original format + // TODO: maybe remove this? not really gonna break anything vital + float f = TheCamera.CarZoomIndicator; + WriteDataToBufferPointer(buf, f); + f = TheCamera.PedZoomIndicator; + WriteDataToBufferPointer(buf, f); +#else WriteDataToBufferPointer(buf, TheCamera.CarZoomIndicator); WriteDataToBufferPointer(buf, TheCamera.PedZoomIndicator); +#endif assert(buf - work_buff == SIZE_OF_SIMPLEVARS); // Save scripts, block is nested within the same block as simple vars for some reason @@ -264,8 +282,18 @@ GenericLoad() ReadDataFromBufferPointer(buf, CompileDateAndTime.m_nMonth); ReadDataFromBufferPointer(buf, CompileDateAndTime.m_nYear); ReadDataFromBufferPointer(buf, CWeather::WeatherTypeInList); +#ifdef FIX_BUGS + // converted to float for compatibility with original format + // TODO: maybe remove this? not really gonna break anything vital + float f; + ReadDataFromBufferPointer(buf, f); + TheCamera.CarZoomIndicator = f; + ReadDataFromBufferPointer(buf, f); + TheCamera.PedZoomIndicator = f; +#else ReadDataFromBufferPointer(buf, TheCamera.CarZoomIndicator); ReadDataFromBufferPointer(buf, TheCamera.PedZoomIndicator); +#endif assert(buf - work_buff == SIZE_OF_SIMPLEVARS); ReadDataFromBlock("Loading Scripts \n", CTheScripts::LoadAllScripts); @@ -534,22 +562,3 @@ align4bytes(int32 size) { return (size + 3) & 0xFFFFFFFC; } - -STARTPATCHES - InjectHook(0x58F8D0, GenericSave, PATCH_JUMP); - InjectHook(0x590A00, GenericLoad, PATCH_JUMP); - InjectHook(0x591910, ReadInSizeofSaveFileBuffer, PATCH_JUMP); - InjectHook(0x591990, ReadDataFromFile, PATCH_JUMP); - InjectHook(0x591A00, CloseFile, PATCH_JUMP); - InjectHook(0x591A20, DoGameSpecificStuffAfterSucessLoad, PATCH_JUMP); - InjectHook(0x591A40, CheckSlotDataValid, PATCH_JUMP); - InjectHook(0x591A80, MakeSpaceForSizeInBufferPointer, PATCH_JUMP); - InjectHook(0x591AA0, CopySizeAndPreparePointer, PATCH_JUMP); - InjectHook(0x591AE0, DoGameSpecificStuffBeforeSave, PATCH_JUMP); - InjectHook(0x591B10, MakeValidSaveName, PATCH_JUMP); - InjectHook(0x591B50, GetSavedGameDateAndTime, PATCH_JUMP); - InjectHook(0x591B60, GetNameOfSavedGame, PATCH_JUMP); - InjectHook(0x591B70, CheckDataNotCorrupt, PATCH_JUMP); - InjectHook(0x591D60, RestoreForStartLoad, PATCH_JUMP); - InjectHook(0x591E80, align4bytes, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/save/GenericGameStorage.h b/src/save/GenericGameStorage.h index e6fd2e2d..b913c305 100644 --- a/src/save/GenericGameStorage.h +++ b/src/save/GenericGameStorage.h @@ -21,22 +21,22 @@ bool CheckDataNotCorrupt(int32 slot, char *name); bool RestoreForStartLoad(); int align4bytes(int32 size); -extern class CDate& CompileDateAndTime; - -extern char (&DefaultPCSaveFileName)[260]; -extern char (&ValidSaveName)[260]; -extern char (&LoadFileName)[256]; -extern wchar (&SlotFileName)[SLOT_COUNT][260]; -extern wchar (&SlotSaveDate)[SLOT_COUNT][70]; -extern int &CheckSum; -extern enum eLevelName &m_LevelToLoad; -extern int (&Slots)[SLOT_COUNT+1]; - -extern bool &b_FoundRecentSavedGameWantToLoad; -extern bool &JustLoadedDontFadeInYet; -extern bool &StillToFadeOut; -extern uint32 &TimeStartedCountingForFade; -extern uint32 &TimeToStayFadedBeforeFadeOut; +extern class CDate CompileDateAndTime; + +extern char DefaultPCSaveFileName[260]; +extern char ValidSaveName[260]; +extern char LoadFileName[256]; +extern wchar SlotFileName[SLOT_COUNT][260]; +extern wchar SlotSaveDate[SLOT_COUNT][70]; +extern int CheckSum; +extern enum eLevelName m_LevelToLoad; +extern int Slots[SLOT_COUNT+1]; + +extern bool b_FoundRecentSavedGameWantToLoad; +extern bool JustLoadedDontFadeInYet; +extern bool StillToFadeOut; +extern uint32 TimeStartedCountingForFade; +extern uint32 TimeToStayFadedBeforeFadeOut; extern char SaveFileNameJustSaved[260]; // 8F2570 diff --git a/src/save/PCSave.cpp b/src/save/PCSave.cpp index 744f5e0d..6f1b1b45 100644 --- a/src/save/PCSave.cpp +++ b/src/save/PCSave.cpp @@ -1,6 +1,7 @@ -#define WITHWINDOWS #include "common.h" -#include "patcher.h" +#define USEALTERNATIVEWINFUNCS +#include "crossplatform.h" + #include "FileMgr.h" #include "GenericGameStorage.h" #include "Messages.h" @@ -9,7 +10,7 @@ const char* _psGetUserFilesFolder(); -C_PcSave &PcSaveHelper = *(C_PcSave*)0x8E2C60; +C_PcSave PcSaveHelper; void C_PcSave::SetSaveDirectory(const char *path) @@ -86,11 +87,15 @@ C_PcSave::PopulateSlotInfo() SlotSaveDate[i][0] = '\0'; } for (int i = 0; i < SLOT_COUNT; i++) { +#ifdef FIX_BUGS + char savename[MAX_PATH]; +#else char savename[52]; +#endif struct { int size; wchar FileName[24]; - _SYSTEMTIME SaveDateTime; + SYSTEMTIME SaveDateTime; } header; sprintf(savename, "%s%i%s", DefaultPCSaveFileName, i + 1, ".b"); int file = CFileMgr::OpenFile(savename, "rb"); @@ -106,8 +111,8 @@ C_PcSave::PopulateSlotInfo() } if (Slots[i + 1] == SLOT_OK) { if (CheckDataNotCorrupt(i, savename)) { - _SYSTEMTIME st; - memcpy(&st, &header.SaveDateTime, sizeof(_SYSTEMTIME)); + SYSTEMTIME st; + memcpy(&st, &header.SaveDateTime, sizeof(SYSTEMTIME)); const char *month; switch (st.wMonth) { @@ -136,11 +141,3 @@ C_PcSave::PopulateSlotInfo() } } } - -STARTPATCHES - InjectHook(0x591EA0, C_PcSave::SetSaveDirectory, PATCH_JUMP); - InjectHook(0x5922F0, &C_PcSave::DeleteSlot, PATCH_JUMP); - InjectHook(0x591EC0, &C_PcSave::SaveSlot, PATCH_JUMP); - InjectHook(0x591F80, &C_PcSave::PcClassSaveRoutine, PATCH_JUMP); - InjectHook(0x592090, &C_PcSave::PopulateSlotInfo, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/save/PCSave.h b/src/save/PCSave.h index c58a5c9e..4a2d9a66 100644 --- a/src/save/PCSave.h +++ b/src/save/PCSave.h @@ -37,4 +37,4 @@ public: static void SetSaveDirectory(const char *path); }; -extern C_PcSave &PcSaveHelper; +extern C_PcSave PcSaveHelper; |