2020-03-27 19:53:47 +00:00
|
|
|
#define WITHWINDOWS
|
2020-01-13 23:13:42 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "main.h"
|
2020-04-17 13:31:11 +00:00
|
|
|
|
2020-03-11 07:12:40 +00:00
|
|
|
#include "AudioScriptObject.h"
|
2020-01-13 23:13:42 +00:00
|
|
|
#include "Camera.h"
|
2020-03-05 09:44:42 +00:00
|
|
|
#include "CarGen.h"
|
2020-03-11 03:27:41 +00:00
|
|
|
#include "Cranes.h"
|
2020-01-13 23:13:42 +00:00
|
|
|
#include "Clock.h"
|
2020-01-27 22:16:38 +00:00
|
|
|
#include "Date.h"
|
2020-01-13 23:13:42 +00:00
|
|
|
#include "FileMgr.h"
|
2020-04-12 22:47:12 +00:00
|
|
|
#include "Frontend.h"
|
2020-01-13 23:13:42 +00:00
|
|
|
#include "GameLogic.h"
|
2020-03-05 09:44:42 +00:00
|
|
|
#include "Gangs.h"
|
2020-01-13 23:13:42 +00:00
|
|
|
#include "Garages.h"
|
|
|
|
#include "GenericGameStorage.h"
|
2020-03-11 03:27:41 +00:00
|
|
|
#include "Pad.h"
|
2020-04-12 22:47:12 +00:00
|
|
|
#include "Particle.h"
|
2020-03-11 07:12:40 +00:00
|
|
|
#include "ParticleObject.h"
|
2020-03-05 09:44:42 +00:00
|
|
|
#include "PathFind.h"
|
2020-01-13 23:13:42 +00:00
|
|
|
#include "PCSave.h"
|
2020-03-05 09:44:42 +00:00
|
|
|
#include "Phones.h"
|
|
|
|
#include "Pickups.h"
|
2020-01-13 23:13:42 +00:00
|
|
|
#include "PlayerPed.h"
|
2020-04-13 18:20:57 +00:00
|
|
|
#include "ProjectileInfo.h"
|
2020-01-13 23:13:42 +00:00
|
|
|
#include "Pools.h"
|
2020-03-05 09:44:42 +00:00
|
|
|
#include "Radar.h"
|
|
|
|
#include "Restart.h"
|
2020-01-13 23:13:42 +00:00
|
|
|
#include "Script.h"
|
2020-03-05 09:44:42 +00:00
|
|
|
#include "Stats.h"
|
2020-01-13 23:13:42 +00:00
|
|
|
#include "Streaming.h"
|
2020-03-13 20:47:53 +00:00
|
|
|
#include "Timer.h"
|
|
|
|
#include "TimeStep.h"
|
2020-03-11 03:27:41 +00:00
|
|
|
#include "Weather.h"
|
2020-01-13 23:13:42 +00:00
|
|
|
#include "World.h"
|
2020-03-05 09:44:42 +00:00
|
|
|
#include "Zones.h"
|
2020-01-13 23:13:42 +00:00
|
|
|
|
2020-03-11 07:12:40 +00:00
|
|
|
#define BLOCK_COUNT 20
|
2020-03-11 21:08:10 +00:00
|
|
|
#define SIZE_OF_SIMPLEVARS 0xBC
|
|
|
|
|
2020-03-11 03:27:41 +00:00
|
|
|
const uint32 SIZE_OF_ONE_GAME_IN_BYTES = 201729;
|
2020-01-13 23:13:42 +00:00
|
|
|
|
2020-04-17 05:54:14 +00:00
|
|
|
char DefaultPCSaveFileName[260];
|
|
|
|
char ValidSaveName[260];
|
|
|
|
char LoadFileName[256];
|
|
|
|
wchar SlotFileName[SLOT_COUNT][260];
|
|
|
|
wchar SlotSaveDate[SLOT_COUNT][70];
|
|
|
|
int CheckSum;
|
|
|
|
eLevelName m_LevelToLoad;
|
2020-01-13 23:13:42 +00:00
|
|
|
char SaveFileNameJustSaved[260];
|
2020-04-17 05:54:14 +00:00
|
|
|
int Slots[SLOT_COUNT+1];
|
|
|
|
CDate CompileDateAndTime;
|
2020-01-13 23:13:42 +00:00
|
|
|
|
2020-04-17 05:54:14 +00:00
|
|
|
bool b_FoundRecentSavedGameWantToLoad;
|
|
|
|
bool JustLoadedDontFadeInYet;
|
|
|
|
bool StillToFadeOut;
|
|
|
|
uint32 TimeStartedCountingForFade;
|
|
|
|
uint32 TimeToStayFadedBeforeFadeOut = 1750;
|
2020-04-08 23:52:38 +00:00
|
|
|
|
2020-01-31 08:12:36 +00:00
|
|
|
#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));
|
|
|
|
|
2020-04-13 18:20:57 +00:00
|
|
|
#define LoadSaveDataBlock()\
|
2020-04-12 22:47:12 +00:00
|
|
|
do {\
|
|
|
|
if (!ReadDataFromFile(file, (uint8 *) &size, 4))\
|
|
|
|
return false;\
|
|
|
|
size = align4bytes(size);\
|
|
|
|
if (!ReadDataFromFile(file, work_buff, size))\
|
|
|
|
return false;\
|
|
|
|
buf = work_buff;\
|
2020-04-13 18:20:57 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ReadDataFromBlock(msg,load_func)\
|
|
|
|
do {\
|
|
|
|
debug(msg);\
|
2020-04-12 22:47:12 +00:00
|
|
|
ReadDataFromBufferPointer(buf, size);\
|
|
|
|
load_func(buf, size);\
|
|
|
|
size = align4bytes(size);\
|
|
|
|
buf += size;\
|
|
|
|
} while (0)
|
2020-03-11 07:12:40 +00:00
|
|
|
|
2020-04-12 22:47:12 +00:00
|
|
|
#define WriteSaveDataBlock(save_func)\
|
2020-03-11 07:12:40 +00:00
|
|
|
do {\
|
|
|
|
buf = work_buff;\
|
|
|
|
reserved = 0;\
|
|
|
|
MakeSpaceForSizeInBufferPointer(presize, buf, postsize);\
|
|
|
|
save_func(buf, &size);\
|
|
|
|
CopySizeAndPreparePointer(presize, buf, postsize, reserved, size);\
|
2020-03-25 14:13:06 +00:00
|
|
|
if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, buf - work_buff))\
|
2020-03-11 07:12:40 +00:00
|
|
|
return false;\
|
2020-03-25 14:13:06 +00:00
|
|
|
totalSize += buf - work_buff;\
|
2020-03-11 07:12:40 +00:00
|
|
|
} while (0)
|
|
|
|
|
2020-03-05 09:44:42 +00:00
|
|
|
bool
|
|
|
|
GenericSave(int file)
|
|
|
|
{
|
2020-03-11 07:12:40 +00:00
|
|
|
uint8 *buf, *presize, *postsize;
|
2020-03-05 09:44:42 +00:00
|
|
|
uint32 size;
|
|
|
|
uint32 reserved;
|
2020-03-11 07:12:40 +00:00
|
|
|
|
|
|
|
uint32 totalSize;
|
|
|
|
|
|
|
|
wchar *lastMissionPassed;
|
2020-03-11 03:27:41 +00:00
|
|
|
wchar suffix[6];
|
2020-03-11 07:12:40 +00:00
|
|
|
wchar saveName[24];
|
|
|
|
SYSTEMTIME saveTime;
|
2020-03-11 03:27:41 +00:00
|
|
|
CPad *currPad;
|
|
|
|
|
|
|
|
CheckSum = 0;
|
|
|
|
buf = work_buff;
|
2020-03-11 07:12:40 +00:00
|
|
|
reserved = 0;
|
|
|
|
|
|
|
|
// Save simple vars
|
|
|
|
lastMissionPassed = TheText.Get(CStats::LastMissionPassedName);
|
2020-04-18 20:58:43 +00:00
|
|
|
if (lastMissionPassed[0] != '\0') {
|
2020-03-25 14:13:06 +00:00
|
|
|
AsciiToUnicode("...'", suffix);
|
2020-04-18 20:58:43 +00:00
|
|
|
#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
|
2020-03-11 07:12:40 +00:00
|
|
|
TextCopy(saveName, lastMissionPassed);
|
|
|
|
int len = UnicodeStrlen(saveName);
|
2020-04-18 20:58:43 +00:00
|
|
|
#endif
|
2020-03-11 07:12:40 +00:00
|
|
|
saveName[len] = '\0';
|
2020-04-18 20:58:43 +00:00
|
|
|
if (len > ARRAY_SIZE(saveName)-2)
|
|
|
|
TextCopy(&saveName[ARRAY_SIZE(saveName)-ARRAY_SIZE(suffix)], suffix);
|
|
|
|
saveName[ARRAY_SIZE(saveName)-1] = '\0';
|
2020-03-11 03:27:41 +00:00
|
|
|
}
|
2020-03-11 07:12:40 +00:00
|
|
|
WriteDataToBufferPointer(buf, saveName);
|
|
|
|
GetLocalTime(&saveTime);
|
2020-03-14 04:23:03 +00:00
|
|
|
WriteDataToBufferPointer(buf, saveTime);
|
|
|
|
WriteDataToBufferPointer(buf, SIZE_OF_ONE_GAME_IN_BYTES);
|
|
|
|
WriteDataToBufferPointer(buf, CGame::currLevel);
|
2020-03-25 14:13:06 +00:00
|
|
|
WriteDataToBufferPointer(buf, TheCamera.GetPosition().x);
|
|
|
|
WriteDataToBufferPointer(buf, TheCamera.GetPosition().y);
|
|
|
|
WriteDataToBufferPointer(buf, TheCamera.GetPosition().z);
|
2020-03-14 04:23:03 +00:00
|
|
|
WriteDataToBufferPointer(buf, CClock::ms_nMillisecondsPerGameMinute);
|
|
|
|
WriteDataToBufferPointer(buf, CClock::ms_nLastClockTick);
|
|
|
|
WriteDataToBufferPointer(buf, CClock::ms_nGameClockHours);
|
|
|
|
WriteDataToBufferPointer(buf, CClock::ms_nGameClockMinutes);
|
2020-03-11 03:27:41 +00:00
|
|
|
currPad = CPad::GetPad(0);
|
2020-03-14 04:23:03 +00:00
|
|
|
WriteDataToBufferPointer(buf, currPad->Mode);
|
2020-04-13 18:20:57 +00:00
|
|
|
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);
|
2020-03-14 04:23:03 +00:00
|
|
|
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);
|
2020-04-15 21:44:25 +00:00
|
|
|
#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
|
2020-03-14 04:23:03 +00:00
|
|
|
WriteDataToBufferPointer(buf, TheCamera.CarZoomIndicator);
|
|
|
|
WriteDataToBufferPointer(buf, TheCamera.PedZoomIndicator);
|
2020-04-15 21:44:25 +00:00
|
|
|
#endif
|
2020-03-25 14:13:06 +00:00
|
|
|
assert(buf - work_buff == SIZE_OF_SIMPLEVARS);
|
2020-03-11 03:27:41 +00:00
|
|
|
|
2020-03-11 07:12:40 +00:00
|
|
|
// Save scripts, block is nested within the same block as simple vars for some reason
|
|
|
|
presize = buf;
|
|
|
|
buf += 4;
|
|
|
|
postsize = buf;
|
2020-03-11 03:27:41 +00:00
|
|
|
CTheScripts::SaveAllScripts(buf, &size);
|
2020-03-11 07:12:40 +00:00
|
|
|
CopySizeAndPreparePointer(presize, buf, postsize, reserved, size);
|
2020-03-25 14:13:06 +00:00
|
|
|
if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, buf - work_buff))
|
2020-03-11 03:27:41 +00:00
|
|
|
return false;
|
2020-03-25 14:13:06 +00:00
|
|
|
|
|
|
|
totalSize = buf - work_buff;
|
2020-03-11 07:12:40 +00:00
|
|
|
|
|
|
|
// Save the rest
|
2020-04-12 22:47:12 +00:00
|
|
|
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);
|
2020-03-11 07:12:40 +00:00
|
|
|
|
|
|
|
// Write padding
|
2020-03-25 14:13:06 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2020-03-11 07:12:40 +00:00
|
|
|
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;
|
2020-03-05 09:44:42 +00:00
|
|
|
}
|
2020-03-25 14:13:06 +00:00
|
|
|
}
|
2020-03-05 09:44:42 +00:00
|
|
|
|
2020-03-11 07:12:40 +00:00
|
|
|
// Write checksum and close
|
2020-03-11 21:08:10 +00:00
|
|
|
CFileMgr::Write(file, (const char *) &CheckSum, sizeof(CheckSum));
|
2020-03-11 07:12:40 +00:00
|
|
|
if (CFileMgr::GetErrorReadWrite(file)) {
|
|
|
|
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_SAVE_WRITE;
|
2020-03-25 14:13:06 +00:00
|
|
|
if (!CloseFile(file))
|
2020-03-11 07:12:40 +00:00
|
|
|
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_SAVE_CLOSE;
|
2020-03-25 14:13:06 +00:00
|
|
|
|
2020-03-11 07:12:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-03-05 09:44:42 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-12 22:47:12 +00:00
|
|
|
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);
|
2020-04-13 18:20:57 +00:00
|
|
|
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);
|
2020-04-12 22:47:12 +00:00
|
|
|
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);
|
2020-04-15 21:44:25 +00:00
|
|
|
#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
|
2020-04-12 22:47:12 +00:00
|
|
|
ReadDataFromBufferPointer(buf, TheCamera.CarZoomIndicator);
|
|
|
|
ReadDataFromBufferPointer(buf, TheCamera.PedZoomIndicator);
|
2020-04-15 21:44:25 +00:00
|
|
|
#endif
|
2020-04-12 22:47:12 +00:00
|
|
|
assert(buf - work_buff == SIZE_OF_SIMPLEVARS);
|
2020-04-13 18:20:57 +00:00
|
|
|
ReadDataFromBlock("Loading Scripts \n", CTheScripts::LoadAllScripts);
|
2020-04-12 22:47:12 +00:00
|
|
|
|
|
|
|
// Load the rest
|
2020-04-13 18:20:57 +00:00
|
|
|
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();
|
2020-04-14 10:08:03 +00:00
|
|
|
ReadDataFromBlock("Loading Cranes \n", CCranes::Load);
|
2020-04-13 18:20:57 +00:00
|
|
|
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);
|
2020-04-12 22:47:12 +00:00
|
|
|
CParticle::ReloadConfig();
|
2020-04-13 18:20:57 +00:00
|
|
|
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);
|
2020-04-12 22:47:12 +00:00
|
|
|
|
|
|
|
DMAudio.SetMusicMasterVolume(CMenuManager::m_PrefsMusicVolume);
|
|
|
|
DMAudio.SetEffectsMasterVolume(CMenuManager::m_PrefsSfxVolume);
|
|
|
|
if (!CloseFile(file)) {
|
|
|
|
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_LOAD_CLOSE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-13 18:20:57 +00:00
|
|
|
DoGameSpecificStuffAfterSucessLoad();
|
|
|
|
debug("Game successfully loaded \n");
|
2020-04-12 22:47:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-13 23:13:42 +00:00
|
|
|
bool
|
|
|
|
ReadInSizeofSaveFileBuffer(int32 &file, uint32 &size)
|
|
|
|
{
|
|
|
|
file = CFileMgr::OpenFile(LoadFileName, "rb");
|
|
|
|
if (file == 0) {
|
|
|
|
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_LOAD_OPEN;
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-31 08:12:36 +00:00
|
|
|
CFileMgr::Read(file, (const char*)&size, sizeof(size));
|
2020-01-13 23:13:42 +00:00
|
|
|
if (CFileMgr::GetErrorReadWrite(file)) {
|
|
|
|
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_LOAD_READ;
|
|
|
|
if (!CloseFile(file))
|
|
|
|
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_LOAD_CLOSE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ReadDataFromFile(int32 file, uint8 *buf, uint32 size)
|
|
|
|
{
|
|
|
|
if (file == 0) {
|
|
|
|
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_LOAD_OPEN;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
size_t read_size = CFileMgr::Read(file, (const char*)buf, size);
|
|
|
|
if (CFileMgr::GetErrorReadWrite(file) || read_size != size) {
|
|
|
|
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_LOAD_READ;
|
|
|
|
if (!CloseFile(file))
|
|
|
|
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_LOAD_CLOSE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CloseFile(int32 file)
|
|
|
|
{
|
|
|
|
return CFileMgr::CloseFile(file) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DoGameSpecificStuffAfterSucessLoad()
|
|
|
|
{
|
|
|
|
StillToFadeOut = true;
|
|
|
|
JustLoadedDontFadeInYet = true;
|
|
|
|
CTheScripts::Process();
|
2020-03-11 21:15:27 +00:00
|
|
|
}
|
2020-01-13 23:13:42 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
CheckSlotDataValid(int32 slot)
|
|
|
|
{
|
|
|
|
PcSaveHelper.nErrorCode = SAVESTATUS_SUCCESSFUL;
|
|
|
|
if (CheckDataNotCorrupt(slot, LoadFileName)) {
|
|
|
|
CStreaming::DeleteAllRwObjects();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_DATA_INVALID;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MakeSpaceForSizeInBufferPointer(uint8 *&presize, uint8 *&buf, uint8 *&postsize)
|
|
|
|
{
|
|
|
|
presize = buf;
|
2020-01-31 08:12:36 +00:00
|
|
|
buf += sizeof(uint32);
|
2020-01-13 23:13:42 +00:00
|
|
|
postsize = buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CopySizeAndPreparePointer(uint8 *&buf, uint8 *&postbuf, uint8 *&postbuf2, uint32 &unused, uint32 &size)
|
|
|
|
{
|
2020-01-31 08:12:36 +00:00
|
|
|
memcpy(buf, &size, sizeof(size));
|
2020-01-13 23:13:42 +00:00
|
|
|
size = align4bytes(size);
|
|
|
|
postbuf2 += size;
|
|
|
|
postbuf = postbuf2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DoGameSpecificStuffBeforeSave()
|
|
|
|
{
|
|
|
|
CGameLogic::PassTime(360);
|
|
|
|
CPlayerPed *ped = FindPlayerPed();
|
|
|
|
ped->m_fCurrentStamina = ped->m_fMaxStamina;
|
|
|
|
CGame::TidyUpMemory(true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
MakeValidSaveName(int32 slot)
|
|
|
|
{
|
|
|
|
ValidSaveName[0] = '\0';
|
|
|
|
sprintf(ValidSaveName, "%s%i", DefaultPCSaveFileName, slot + 1);
|
|
|
|
strncat(ValidSaveName, ".b", 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
wchar *
|
|
|
|
GetSavedGameDateAndTime(int32 slot)
|
|
|
|
{
|
|
|
|
return SlotSaveDate[slot];
|
|
|
|
}
|
|
|
|
|
|
|
|
wchar *
|
|
|
|
GetNameOfSavedGame(int32 slot)
|
|
|
|
{
|
|
|
|
return SlotFileName[slot];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CheckDataNotCorrupt(int32 slot, char *name)
|
|
|
|
{
|
|
|
|
char filename[100];
|
|
|
|
|
|
|
|
int32 blocknum = 0;
|
|
|
|
eLevelName level = LEVEL_NONE;
|
|
|
|
CheckSum = 0;
|
2020-01-31 12:33:46 +00:00
|
|
|
uint32 bytes_processed = 0;
|
2020-01-13 23:13:42 +00:00
|
|
|
sprintf(filename, "%s%i%s", DefaultPCSaveFileName, slot + 1, ".b");
|
|
|
|
int file = CFileMgr::OpenFile(filename, "rb");
|
|
|
|
if (file == 0)
|
|
|
|
return false;
|
|
|
|
strcpy(name, filename);
|
2020-01-31 12:33:46 +00:00
|
|
|
while (SIZE_OF_ONE_GAME_IN_BYTES - sizeof(uint32) > bytes_processed && blocknum < 40) {
|
2020-01-13 23:13:42 +00:00
|
|
|
int32 blocksize;
|
2020-01-31 08:12:36 +00:00
|
|
|
if (!ReadDataFromFile(file, (uint8*)&blocksize, sizeof(blocksize))) {
|
2020-01-13 23:13:42 +00:00
|
|
|
CloseFile(file);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (blocksize > align4bytes(sizeof(work_buff)))
|
2020-01-31 08:12:36 +00:00
|
|
|
blocksize = sizeof(work_buff) - sizeof(uint32);
|
2020-01-13 23:13:42 +00:00
|
|
|
if (!ReadDataFromFile(file, work_buff, align4bytes(blocksize))) {
|
|
|
|
CloseFile(file);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckSum += ((uint8*)&blocksize)[0];
|
|
|
|
CheckSum += ((uint8*)&blocksize)[1];
|
|
|
|
CheckSum += ((uint8*)&blocksize)[2];
|
|
|
|
CheckSum += ((uint8*)&blocksize)[3];
|
|
|
|
uint8 *_work_buf = work_buff;
|
|
|
|
for (int i = 0; i < align4bytes(blocksize); i++) {
|
|
|
|
CheckSum += *_work_buf++;
|
2020-01-31 12:33:46 +00:00
|
|
|
bytes_processed++;
|
2020-01-13 23:13:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (blocknum == 0)
|
2020-01-31 08:12:36 +00:00
|
|
|
memcpy(&level, work_buff+4, sizeof(level));
|
2020-01-13 23:13:42 +00:00
|
|
|
blocknum++;
|
|
|
|
}
|
|
|
|
int32 _checkSum;
|
2020-01-31 08:12:36 +00:00
|
|
|
if (ReadDataFromFile(file, (uint8*)&_checkSum, sizeof(_checkSum))) {
|
2020-01-13 23:13:42 +00:00
|
|
|
if (CloseFile(file)) {
|
|
|
|
if (CheckSum == _checkSum) {
|
|
|
|
m_LevelToLoad = level;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseFile(file);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
RestoreForStartLoad()
|
|
|
|
{
|
|
|
|
uint8 buf[999];
|
|
|
|
|
|
|
|
int file = CFileMgr::OpenFile(LoadFileName, "rb");
|
|
|
|
if (file == 0) {
|
|
|
|
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_LOAD_OPEN;
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-31 08:12:36 +00:00
|
|
|
ReadDataFromFile(file, buf, sizeof(buf));
|
2020-01-13 23:13:42 +00:00
|
|
|
if (CFileMgr::GetErrorReadWrite(file)) {
|
|
|
|
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_LOAD_READ;
|
|
|
|
if (!CloseFile(file))
|
|
|
|
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_LOAD_CLOSE;
|
|
|
|
return false;
|
|
|
|
} else {
|
2020-01-31 08:12:36 +00:00
|
|
|
uint8 *_buf = buf + sizeof(int32) + sizeof(wchar[24]) + sizeof(SYSTEMTIME) + sizeof(SIZE_OF_ONE_GAME_IN_BYTES);
|
|
|
|
ReadDataFromBufferPointer(_buf, CGame::currLevel);
|
|
|
|
ReadDataFromBufferPointer(_buf, TheCamera.GetPosition().x);
|
|
|
|
ReadDataFromBufferPointer(_buf, TheCamera.GetPosition().y);
|
|
|
|
ReadDataFromBufferPointer(_buf, TheCamera.GetPosition().z);
|
|
|
|
CStreaming::RemoveUnusedBigBuildings(CGame::currLevel);
|
2020-01-13 23:13:42 +00:00
|
|
|
CStreaming::RemoveUnusedBuildings(CGame::currLevel);
|
|
|
|
CCollision::SortOutCollisionAfterLoad();
|
|
|
|
CStreaming::RequestBigBuildings(CGame::currLevel);
|
|
|
|
CStreaming::LoadAllRequestedModels(false);
|
|
|
|
CStreaming::HaveAllBigBuildingsLoaded(CGame::currLevel);
|
|
|
|
CGame::TidyUpMemory(true, false);
|
|
|
|
|
|
|
|
if (CloseFile(file)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_LOAD_CLOSE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
align4bytes(int32 size)
|
|
|
|
{
|
|
|
|
return (size + 3) & 0xFFFFFFFC;
|
|
|
|
}
|