diff options
author | erorcun <erayorcunus@gmail.com> | 2020-04-13 20:49:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-13 20:49:57 +0200 |
commit | 0e056a8e01fe82504d65cd73a8c3fec431d08418 (patch) | |
tree | 8ac875cee53bd5957b99c819e93a513afbf3ba20 | |
parent | Merge pull request #413 from erorcun/erorcun (diff) | |
parent | Fixes (diff) | |
download | re3-0e056a8e01fe82504d65cd73a8c3fec431d08418.tar re3-0e056a8e01fe82504d65cd73a8c3fec431d08418.tar.gz re3-0e056a8e01fe82504d65cd73a8c3fec431d08418.tar.bz2 re3-0e056a8e01fe82504d65cd73a8c3fec431d08418.tar.lz re3-0e056a8e01fe82504d65cd73a8c3fec431d08418.tar.xz re3-0e056a8e01fe82504d65cd73a8c3fec431d08418.tar.zst re3-0e056a8e01fe82504d65cd73a8c3fec431d08418.zip |
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | src/core/Timer.h | 3 | ||||
-rw-r--r-- | src/save/GenericGameStorage.cpp | 184 |
3 files changed, 158 insertions, 30 deletions
@@ -38,7 +38,6 @@ CPedPath CRoadBlocks CWeapon CWorld -GenericLoad ``` The following classes have only unused or practically unused code left: diff --git a/src/core/Timer.h b/src/core/Timer.h index b119bfb2..a4d674da 100644 --- a/src/core/Timer.h +++ b/src/core/Timer.h @@ -53,6 +53,9 @@ public: static void Stop(void); static void StartUserPause(void); static void EndUserPause(void); + + friend bool GenericLoad(void); + friend bool GenericSave(int file); }; #ifdef FIX_BUGS diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index 2545b9ab..4cfa75b3 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -9,17 +9,20 @@ #include "Clock.h" #include "Date.h" #include "FileMgr.h" +#include "Frontend.h" #include "GameLogic.h" #include "Gangs.h" #include "Garages.h" #include "GenericGameStorage.h" #include "Pad.h" +#include "Particle.h" #include "ParticleObject.h" #include "PathFind.h" #include "PCSave.h" #include "Phones.h" #include "Pickups.h" #include "PlayerPed.h" +#include "ProjectileInfo.h" #include "Pools.h" #include "Radar.h" #include "Restart.h" @@ -48,7 +51,6 @@ char SaveFileNameJustSaved[260]; int (&Slots)[SLOT_COUNT+1] = *(int(*)[SLOT_COUNT+1])*(uintptr*)0x72803C; CDate &CompileDateAndTime = *(CDate*)0x72BCB8; - bool &b_FoundRecentSavedGameWantToLoad = *(bool*)0x95CDA8; bool &JustLoadedDontFadeInYet = *(bool*)0x95CDB4; bool &StillToFadeOut = *(bool*)0x95CD99; @@ -58,10 +60,26 @@ uint32 &TimeToStayFadedBeforeFadeOut = *(uint32*)0x611564; #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 GenericLoad() { EAXJMP(0x590A00); } +#define LoadSaveDataBlock()\ +do {\ + if (!ReadDataFromFile(file, (uint8 *) &size, 4))\ + return false;\ + size = align4bytes(size);\ + if (!ReadDataFromFile(file, work_buff, size))\ + return false;\ + buf = work_buff;\ +} while (0) +#define ReadDataFromBlock(msg,load_func)\ +do {\ + debug(msg);\ + ReadDataFromBufferPointer(buf, size);\ + load_func(buf, size);\ + size = align4bytes(size);\ + buf += size;\ +} while (0) -#define WRITE_BLOCK(save_func)\ +#define WriteSaveDataBlock(save_func)\ do {\ buf = work_buff;\ reserved = 0;\ @@ -117,11 +135,11 @@ GenericSave(int file) WriteDataToBufferPointer(buf, CClock::ms_nGameClockMinutes); currPad = CPad::GetPad(0); WriteDataToBufferPointer(buf, currPad->Mode); - WriteDataToBufferPointer(buf, CTimer::GetTimeInMilliseconds()); - WriteDataToBufferPointer(buf, CTimer::GetTimeScale()); - WriteDataToBufferPointer(buf, CTimer::GetTimeStep()); - WriteDataToBufferPointer(buf, CTimer::GetTimeStepNonClipped()); - WriteDataToBufferPointer(buf, CTimer::GetFrameCounter()); + 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); @@ -138,7 +156,6 @@ GenericSave(int file) WriteDataToBufferPointer(buf, CWeather::WeatherTypeInList); WriteDataToBufferPointer(buf, TheCamera.CarZoomIndicator); WriteDataToBufferPointer(buf, TheCamera.PedZoomIndicator); - assert(buf - work_buff == SIZE_OF_SIMPLEVARS); // Save scripts, block is nested within the same block as simple vars for some reason @@ -153,25 +170,25 @@ GenericSave(int file) totalSize = buf - work_buff; // 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); + WriteSaveDataBlock(CPools::SavePedPool); + WriteSaveDataBlock(CGarages::Save); + WriteSaveDataBlock(CPools::SaveVehiclePool); + WriteSaveDataBlock(CPools::SaveObjectPool); + WriteSaveDataBlock(ThePaths.Save); + WriteSaveDataBlock(CCranes::Save); + WriteSaveDataBlock(CPickups::Save); + WriteSaveDataBlock(gPhoneInfo.Save); + WriteSaveDataBlock(CRestart::SaveAllRestartPoints); + WriteSaveDataBlock(CRadar::SaveAllRadarBlips); + WriteSaveDataBlock(CTheZones::SaveAllZones); + WriteSaveDataBlock(CGangs::SaveAllGangData); + WriteSaveDataBlock(CTheCarGenerators::SaveAllCarGenerators); + WriteSaveDataBlock(CParticleObject::SaveParticle); + WriteSaveDataBlock(cAudioScriptObject::SaveAllAudioScriptObjects); + WriteSaveDataBlock(CWorld::Players[CWorld::PlayerInFocus].SavePlayerInfo); + WriteSaveDataBlock(CStats::SaveStats); + WriteSaveDataBlock(CStreaming::MemoryCardSave); + WriteSaveDataBlock(CPedType::Save); // Write padding for (int i = 0; i < 4; i++) { @@ -199,6 +216,115 @@ GenericSave(int file) } bool +GenericLoad() +{ + uint8 *buf; + int32 file; + uint32 size; + + int32 saveSize; + CPad *currPad; + + // Load SimpleVars and Scripts + CheckSum = 0; + CDate(CompileDateAndTime); + CPad::ResetCheats(); + if (!ReadInSizeofSaveFileBuffer(file, size)) + return false; + size = align4bytes(size); + ReadDataFromFile(file, work_buff, size); + buf = (work_buff + 0x40); + ReadDataFromBufferPointer(buf, saveSize); + ReadDataFromBufferPointer(buf, CGame::currLevel); + ReadDataFromBufferPointer(buf, TheCamera.GetPosition().x); + ReadDataFromBufferPointer(buf, TheCamera.GetPosition().y); + ReadDataFromBufferPointer(buf, TheCamera.GetPosition().z); + ReadDataFromBufferPointer(buf, CClock::ms_nMillisecondsPerGameMinute); + ReadDataFromBufferPointer(buf, CClock::ms_nLastClockTick); + ReadDataFromBufferPointer(buf, CClock::ms_nGameClockHours); + ReadDataFromBufferPointer(buf, CClock::ms_nGameClockMinutes); + currPad = CPad::GetPad(0); + ReadDataFromBufferPointer(buf, currPad->Mode); + ReadDataFromBufferPointer(buf, CTimer::m_snTimeInMilliseconds); + ReadDataFromBufferPointer(buf, CTimer::ms_fTimeScale); + ReadDataFromBufferPointer(buf, CTimer::ms_fTimeStep); + ReadDataFromBufferPointer(buf, CTimer::ms_fTimeStepNonClipped); + ReadDataFromBufferPointer(buf, CTimer::m_FrameCounter); + ReadDataFromBufferPointer(buf, CTimeStep::ms_fTimeStep); + ReadDataFromBufferPointer(buf, CTimeStep::ms_fFramesPerUpdate); + ReadDataFromBufferPointer(buf, CTimeStep::ms_fTimeScale); + ReadDataFromBufferPointer(buf, CWeather::OldWeatherType); + ReadDataFromBufferPointer(buf, CWeather::NewWeatherType); + ReadDataFromBufferPointer(buf, CWeather::ForcedWeatherType); + ReadDataFromBufferPointer(buf, CWeather::InterpolationValue); + ReadDataFromBufferPointer(buf, CompileDateAndTime.m_nSecond); + ReadDataFromBufferPointer(buf, CompileDateAndTime.m_nMinute); + ReadDataFromBufferPointer(buf, CompileDateAndTime.m_nHour); + ReadDataFromBufferPointer(buf, CompileDateAndTime.m_nDay); + ReadDataFromBufferPointer(buf, CompileDateAndTime.m_nMonth); + ReadDataFromBufferPointer(buf, CompileDateAndTime.m_nYear); + ReadDataFromBufferPointer(buf, CWeather::WeatherTypeInList); + ReadDataFromBufferPointer(buf, TheCamera.CarZoomIndicator); + ReadDataFromBufferPointer(buf, TheCamera.PedZoomIndicator); + assert(buf - work_buff == SIZE_OF_SIMPLEVARS); + ReadDataFromBlock("Loading Scripts \n", CTheScripts::LoadAllScripts); + + // Load the rest + LoadSaveDataBlock(); + ReadDataFromBlock("Loading PedPool \n", CPools::LoadPedPool); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading Garages \n", CGarages::Load); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading Vehicles \n", CPools::LoadVehiclePool); + LoadSaveDataBlock(); + CProjectileInfo::RemoveAllProjectiles(); + CObject::DeleteAllTempObjects(); + ReadDataFromBlock("Loading Objects \n", CPools::LoadObjectPool); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading Paths \n", ThePaths.Load); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading Cranes \n", CranesLoad); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading Pickups \n", CPickups::Load); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading Phoneinfo \n", gPhoneInfo.Load); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading Restart \n", CRestart::LoadAllRestartPoints); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading Radar Blips \n", CRadar::LoadAllRadarBlips); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading Zones \n", CTheZones::LoadAllZones); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading Gang Data \n", CGangs::LoadAllGangData); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading Car Generators \n", CTheCarGenerators::LoadAllCarGenerators); + CParticle::ReloadConfig(); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading Particles \n", CParticleObject::LoadParticle); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading AudioScript Objects \n", cAudioScriptObject::LoadAllAudioScriptObjects); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading Player Info \n", CWorld::Players[CWorld::PlayerInFocus].LoadPlayerInfo); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading Stats \n", CStats::LoadStats); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading Streaming Stuff \n", CStreaming::MemoryCardLoad); + LoadSaveDataBlock(); + ReadDataFromBlock("Loading PedType Stuff \n", CPedType::Load); + + DMAudio.SetMusicMasterVolume(CMenuManager::m_PrefsMusicVolume); + DMAudio.SetEffectsMasterVolume(CMenuManager::m_PrefsSfxVolume); + if (!CloseFile(file)) { + PcSaveHelper.nErrorCode = SAVESTATUS_ERR_LOAD_CLOSE; + return false; + } + + DoGameSpecificStuffAfterSucessLoad(); + debug("Game successfully loaded \n"); + return true; +} + +bool ReadInSizeofSaveFileBuffer(int32 &file, uint32 &size) { file = CFileMgr::OpenFile(LoadFileName, "rb"); @@ -411,7 +537,7 @@ align4bytes(int32 size) STARTPATCHES InjectHook(0x58F8D0, GenericSave, PATCH_JUMP); - //InjectHook(0x590A00, GenericLoad, PATCH_JUMP); + InjectHook(0x590A00, GenericLoad, PATCH_JUMP); InjectHook(0x591910, ReadInSizeofSaveFileBuffer, PATCH_JUMP); InjectHook(0x591990, ReadDataFromFile, PATCH_JUMP); InjectHook(0x591A00, CloseFile, PATCH_JUMP); |