mirror of
https://github.com/GTAmodding/re3.git
synced 2021-02-19 17:49:54 +01:00
GenericSave complete, still needs some testing
This commit is contained in:
parent
5bc51f8462
commit
c7f16879df
@ -3,6 +3,8 @@
|
|||||||
#include "AudioScriptObject.h"
|
#include "AudioScriptObject.h"
|
||||||
#include "Pools.h"
|
#include "Pools.h"
|
||||||
|
|
||||||
|
WRAPPER void cAudioScriptObject::SaveAllAudioScriptObjects(uint8 *buf, uint32 *size) { EAXJMP(0x57c460); }
|
||||||
|
|
||||||
void
|
void
|
||||||
cAudioScriptObject::Reset()
|
cAudioScriptObject::Reset()
|
||||||
{
|
{
|
||||||
|
@ -141,6 +141,8 @@ public:
|
|||||||
static void* operator new(size_t, int);
|
static void* operator new(size_t, int);
|
||||||
static void operator delete(void*, size_t);
|
static void operator delete(void*, size_t);
|
||||||
static void operator delete(void*, int);
|
static void operator delete(void*, int);
|
||||||
|
|
||||||
|
static void SaveAllAudioScriptObjects(uint8 *buf, uint32 *size);
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(sizeof(cAudioScriptObject) == 20, "cAudioScriptObject: error");
|
static_assert(sizeof(cAudioScriptObject) == 20, "cAudioScriptObject: error");
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "patcher.h"
|
||||||
#include "Stats.h"
|
#include "Stats.h"
|
||||||
|
|
||||||
|
WRAPPER void CStats::SaveStats(uint8 *buf, uint32 *size) { EAXJMP(0x4ab3e0); }
|
||||||
|
|
||||||
int32 &CStats::DaysPassed = *(int32*)0x8F2BB8;
|
int32 &CStats::DaysPassed = *(int32*)0x8F2BB8;
|
||||||
int32 &CStats::HeadsPopped = *(int32*)0x8F647C;
|
int32 &CStats::HeadsPopped = *(int32*)0x8F647C;
|
||||||
bool& CStats::CommercialPassed = *(bool*)0x8F4334;
|
bool& CStats::CommercialPassed = *(bool*)0x8F4334;
|
||||||
|
@ -73,4 +73,5 @@ public:
|
|||||||
static void CheckPointReachedUnsuccessfully() { KillsSinceLastCheckpoint = 0; };
|
static void CheckPointReachedUnsuccessfully() { KillsSinceLastCheckpoint = 0; };
|
||||||
static void CheckPointReachedSuccessfully() { TotalLegitimateKills += KillsSinceLastCheckpoint; KillsSinceLastCheckpoint = 0; };
|
static void CheckPointReachedSuccessfully() { TotalLegitimateKills += KillsSinceLastCheckpoint; KillsSinceLastCheckpoint = 0; };
|
||||||
static void RegisterElBurroTime(int32);
|
static void RegisterElBurroTime(int32);
|
||||||
|
static void SaveStats(uint8 *buf, uint32 *size);
|
||||||
};
|
};
|
@ -321,9 +321,9 @@ _TWEEKCLASS(CTweakFloat, float);
|
|||||||
#undef _TWEEKCLASS
|
#undef _TWEEKCLASS
|
||||||
|
|
||||||
#ifdef VALIDATE_SAVE_SIZE
|
#ifdef VALIDATE_SAVE_SIZE
|
||||||
extern int32 _bufBytesRead;
|
extern int32 _saveBufCount;
|
||||||
#define INITSAVEBUF _bufBytesRead = 0;
|
#define INITSAVEBUF _saveBufCount = 0;
|
||||||
#define VALIDATESAVEBUF(b) assert(_bufBytesRead == b);
|
#define VALIDATESAVEBUF(b) assert(_saveBufCount == b);
|
||||||
#else
|
#else
|
||||||
#define INITSAVEBUF
|
#define INITSAVEBUF
|
||||||
#define VALIDATESAVEBUF(b)
|
#define VALIDATESAVEBUF(b)
|
||||||
@ -333,7 +333,7 @@ inline void SkipSaveBuf(uint8 *&buf, int32 skip)
|
|||||||
{
|
{
|
||||||
buf += skip;
|
buf += skip;
|
||||||
#ifdef VALIDATE_SAVE_SIZE
|
#ifdef VALIDATE_SAVE_SIZE
|
||||||
_bufBytesRead += skip;
|
_saveBufCount += skip;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,7 +449,7 @@ void re3_trace(const char *filename, unsigned int lineno, const char *func, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VALIDATE_SAVE_SIZE
|
#ifdef VALIDATE_SAVE_SIZE
|
||||||
int32 _bufBytesRead;
|
int32 _saveBufCount;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "patcher.h"
|
#include "patcher.h"
|
||||||
|
#include "AudioScriptObject.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "CarGen.h"
|
#include "CarGen.h"
|
||||||
#include "Cranes.h"
|
#include "Cranes.h"
|
||||||
@ -12,6 +13,7 @@
|
|||||||
#include "Garages.h"
|
#include "Garages.h"
|
||||||
#include "GenericGameStorage.h"
|
#include "GenericGameStorage.h"
|
||||||
#include "Pad.h"
|
#include "Pad.h"
|
||||||
|
#include "ParticleObject.h"
|
||||||
#include "PathFind.h"
|
#include "PathFind.h"
|
||||||
#include "PCSave.h"
|
#include "PCSave.h"
|
||||||
#include "Phones.h"
|
#include "Phones.h"
|
||||||
@ -27,6 +29,7 @@
|
|||||||
#include "World.h"
|
#include "World.h"
|
||||||
#include "Zones.h"
|
#include "Zones.h"
|
||||||
|
|
||||||
|
#define BLOCK_COUNT 20
|
||||||
const uint32 SIZE_OF_ONE_GAME_IN_BYTES = 201729;
|
const uint32 SIZE_OF_ONE_GAME_IN_BYTES = 201729;
|
||||||
|
|
||||||
char (&DefaultPCSaveFileName)[260] = *(char(*)[260])*(uintptr*)0x8E28C0;
|
char (&DefaultPCSaveFileName)[260] = *(char(*)[260])*(uintptr*)0x8E28C0;
|
||||||
@ -46,41 +49,60 @@ CDate &CompileDateAndTime = *(CDate*)0x72BCB8;
|
|||||||
//WRAPPER bool GenericSave(int file) { EAXJMP(0x58F8D0); }
|
//WRAPPER bool GenericSave(int file) { EAXJMP(0x58F8D0); }
|
||||||
WRAPPER bool GenericLoad() { EAXJMP(0x590A00); }
|
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
|
bool
|
||||||
GenericSave(int file)
|
GenericSave(int file)
|
||||||
{
|
{
|
||||||
static const int NameBufferSize = 0x30;
|
uint8 *buf, *presize, *postsize;
|
||||||
static const int MaxNameLength = 22;
|
|
||||||
static const char *NameSuffix = "'...\0";
|
|
||||||
|
|
||||||
uint8 *buf;
|
|
||||||
uint8 *tmpbuf;
|
|
||||||
uint8 *postsize;
|
|
||||||
uint32 size;
|
uint32 size;
|
||||||
uint32 reserved;
|
uint32 reserved;
|
||||||
wchar *saveName;
|
|
||||||
|
uint32 totalSize;
|
||||||
|
uint32 blockSizes[BLOCK_COUNT];
|
||||||
|
uint32 blockIndex;
|
||||||
|
uint32 i;
|
||||||
|
|
||||||
|
wchar *lastMissionPassed;
|
||||||
wchar suffix[6];
|
wchar suffix[6];
|
||||||
wchar nameBuf[MaxNameLength] = { 0 };
|
wchar saveName[24];
|
||||||
int nameLen;
|
SYSTEMTIME saveTime;
|
||||||
CPad *currPad;
|
CPad *currPad;
|
||||||
|
|
||||||
CheckSum = 0;
|
CheckSum = 0;
|
||||||
buf = work_buff;
|
buf = work_buff;
|
||||||
|
reserved = 0;
|
||||||
|
blockIndex = 0;
|
||||||
|
|
||||||
saveName = TheText.Get(CStats::LastMissionPassedName);
|
// Save simple vars
|
||||||
if (saveName[0] != '\0') {
|
INITSAVEBUF
|
||||||
AsciiToUnicode(NameSuffix, suffix);
|
lastMissionPassed = TheText.Get(CStats::LastMissionPassedName);
|
||||||
TextCopy(nameBuf, saveName);
|
if (*lastMissionPassed) {
|
||||||
nameLen = UnicodeStrlen(nameBuf);
|
AsciiToUnicode("'...", suffix);
|
||||||
nameBuf[nameLen] = '\0';
|
TextCopy(saveName, lastMissionPassed);
|
||||||
if (nameLen > MaxNameLength)
|
int len = UnicodeStrlen(saveName);
|
||||||
TextCopy(nameBuf + MaxNameLength, suffix);
|
saveName[len] = '\0';
|
||||||
|
if (22 < len)
|
||||||
|
TextCopy(saveName + 18, suffix);
|
||||||
|
saveName[23] = '\0';
|
||||||
}
|
}
|
||||||
|
WriteDataToBufferPointer(buf, saveName);
|
||||||
memcpy(buf, saveName, NameBufferSize);
|
#ifdef VALIDATE_SAVE_SIZE
|
||||||
buf += NameBufferSize;
|
_saveBufCount += sizeof(saveName);
|
||||||
GetLocalTime((LPSYSTEMTIME) buf);
|
#endif
|
||||||
buf += sizeof(SYSTEMTIME);
|
GetLocalTime(&saveTime);
|
||||||
|
WriteSaveBuf(buf, saveTime);
|
||||||
WriteSaveBuf(buf, SIZE_OF_ONE_GAME_IN_BYTES);
|
WriteSaveBuf(buf, SIZE_OF_ONE_GAME_IN_BYTES);
|
||||||
WriteSaveBuf(buf, CGame::currLevel);
|
WriteSaveBuf(buf, CGame::currLevel);
|
||||||
WriteSaveBuf(buf, TheCamera.m_matrix.m_matrix.pos.x);
|
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, TheCamera.m_matrix.m_matrix.pos.z);
|
||||||
WriteSaveBuf(buf, CClock::ms_nMillisecondsPerGameMinute);
|
WriteSaveBuf(buf, CClock::ms_nMillisecondsPerGameMinute);
|
||||||
WriteSaveBuf(buf, CClock::ms_nLastClockTick);
|
WriteSaveBuf(buf, CClock::ms_nLastClockTick);
|
||||||
WriteSaveBuf(buf, CClock::ms_nGameClockHours);
|
WriteSaveBuf(buf, (uint32) CClock::ms_nGameClockHours);
|
||||||
buf += 3;
|
WriteSaveBuf(buf, (uint32) CClock::ms_nGameClockMinutes);
|
||||||
WriteSaveBuf(buf, CClock::ms_nGameClockMinutes); // TOOD: aligned WriteSaveBuf?
|
|
||||||
buf += 3;
|
|
||||||
currPad = CPad::GetPad(0);
|
currPad = CPad::GetPad(0);
|
||||||
WriteSaveBuf(buf, currPad->Mode);
|
WriteSaveBuf(buf, (uint32) currPad->Mode);
|
||||||
buf += 2;
|
|
||||||
WriteSaveBuf(buf, CTimer::m_snTimeInMilliseconds);
|
WriteSaveBuf(buf, CTimer::m_snTimeInMilliseconds);
|
||||||
WriteSaveBuf(buf, CTimer::ms_fTimeScale);
|
WriteSaveBuf(buf, CTimer::ms_fTimeScale);
|
||||||
WriteSaveBuf(buf, CTimer::ms_fTimeStep);
|
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_fTimeStep;
|
||||||
WriteSaveBuf(buf, 1.0f); // CTimeStep::ms_fFramesPerUpdate;
|
WriteSaveBuf(buf, 1.0f); // CTimeStep::ms_fFramesPerUpdate;
|
||||||
WriteSaveBuf(buf, 1.0f); // CTimeStep::ms_fTimeScale;
|
WriteSaveBuf(buf, 1.0f); // CTimeStep::ms_fTimeScale;
|
||||||
WriteSaveBuf(buf, CWeather::OldWeatherType);
|
WriteSaveBuf(buf, (int32) CWeather::OldWeatherType);
|
||||||
buf += 2;
|
WriteSaveBuf(buf, (int32) CWeather::NewWeatherType);
|
||||||
WriteSaveBuf(buf, CWeather::NewWeatherType);
|
WriteSaveBuf(buf, (int32) CWeather::ForcedWeatherType);
|
||||||
buf += 2;
|
|
||||||
WriteSaveBuf(buf, CWeather::ForcedWeatherType);
|
|
||||||
buf += 2;
|
|
||||||
WriteSaveBuf(buf, CWeather::InterpolationValue);
|
WriteSaveBuf(buf, CWeather::InterpolationValue);
|
||||||
WriteSaveBuf(buf, CompileDateAndTime.m_nSecond);
|
WriteSaveBuf(buf, CompileDateAndTime.m_nSecond);
|
||||||
WriteSaveBuf(buf, CompileDateAndTime.m_nMinute);
|
WriteSaveBuf(buf, CompileDateAndTime.m_nMinute);
|
||||||
@ -117,53 +133,68 @@ GenericSave(int file)
|
|||||||
WriteSaveBuf(buf, CompileDateAndTime.m_nMonth);
|
WriteSaveBuf(buf, CompileDateAndTime.m_nMonth);
|
||||||
WriteSaveBuf(buf, CompileDateAndTime.m_nYear);
|
WriteSaveBuf(buf, CompileDateAndTime.m_nYear);
|
||||||
WriteSaveBuf(buf, CWeather::WeatherTypeInList);
|
WriteSaveBuf(buf, CWeather::WeatherTypeInList);
|
||||||
WriteSaveBuf(buf, TheCamera.m_fCarZoomValueScript); // TODO: unconfirmed
|
WriteSaveBuf(buf, TheCamera.CarZoomIndicator);
|
||||||
WriteSaveBuf(buf, TheCamera.m_fPedZoomValueScript); // TODO: unconfirmed
|
WriteSaveBuf(buf, TheCamera.PedZoomIndicator);
|
||||||
|
VALIDATESAVEBUF(0xBC);
|
||||||
|
|
||||||
size = 0;
|
// Save scripts, block is nested within the same block as simple vars for some reason
|
||||||
reserved = 0;
|
presize = buf;
|
||||||
|
buf += 4;
|
||||||
MakeSpaceForSizeInBufferPointer(tmpbuf, buf, postsize);
|
postsize = buf;
|
||||||
CTheScripts::SaveAllScripts(buf, &size);
|
CTheScripts::SaveAllScripts(buf, &size);
|
||||||
CopySizeAndPreparePointer(tmpbuf, buf, postsize, reserved, size);
|
CopySizeAndPreparePointer(presize, buf, postsize, reserved, size);
|
||||||
if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, size))
|
if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, size))
|
||||||
return false;
|
return false;
|
||||||
|
blockSizes[0] = size + 0xBC;
|
||||||
|
blockIndex++;
|
||||||
|
|
||||||
for (int i = 1; i < 19; i++) {
|
// Save the rest
|
||||||
buf = work_buff;
|
WRITE_BLOCK(CPools::SavePedPool);
|
||||||
size = 0;
|
WRITE_BLOCK(CGarages::Save);
|
||||||
reserved = 0;
|
WRITE_BLOCK(CPools::SaveVehiclePool);
|
||||||
MakeSpaceForSizeInBufferPointer(tmpbuf, buf, postsize);
|
WRITE_BLOCK(CPools::SaveObjectPool);
|
||||||
switch (i) {
|
WRITE_BLOCK(ThePaths.Save);
|
||||||
case 1: CPools::SavePedPool(buf, &size); break;
|
WRITE_BLOCK(CCranes::Save);
|
||||||
case 2: CGarages::Save(buf, &size); break;
|
WRITE_BLOCK(CPickups::Save);
|
||||||
case 3: CPools::SaveVehiclePool(buf, &size); break;
|
WRITE_BLOCK(gPhoneInfo.Save);
|
||||||
case 4: CPools::SaveObjectPool(buf, &size); break;
|
WRITE_BLOCK(CRestart::SaveAllRestartPoints);
|
||||||
case 5: ThePaths.Save(buf, &size); break;
|
WRITE_BLOCK(CRadar::SaveAllRadarBlips);
|
||||||
case 6: CCranes::Save(buf, &size); break;
|
WRITE_BLOCK(CTheZones::SaveAllZones);
|
||||||
case 7: CPickups::Save(buf, &size); break;
|
WRITE_BLOCK(CGangs::SaveAllGangData);
|
||||||
case 8: gPhoneInfo.Save(buf, &size); break;
|
WRITE_BLOCK(CTheCarGenerators::SaveAllCarGenerators);
|
||||||
case 9: CRestart::SaveAllRestartPoints(buf, &size); break;
|
WRITE_BLOCK(CParticleObject::SaveParticle);
|
||||||
case 10: CRadar::SaveAllRadarBlips(buf, &size); break;
|
WRITE_BLOCK(cAudioScriptObject::SaveAllAudioScriptObjects);
|
||||||
case 11: CTheZones::SaveAllZones(buf, &size); break;
|
WRITE_BLOCK(CWorld::Players[CWorld::PlayerInFocus].SavePlayerInfo);
|
||||||
case 12: CGangs::SaveAllGangData(buf, &size); break;
|
WRITE_BLOCK(CStats::SaveStats);
|
||||||
case 13: CTheCarGenerators::SaveAllCarGenerators(buf, &size); break;
|
WRITE_BLOCK(CStreaming::MemoryCardSave);
|
||||||
case 14: break;
|
WRITE_BLOCK(CPedType::Save);
|
||||||
case 15: break;
|
|
||||||
case 16: break;
|
|
||||||
case 17: break;
|
|
||||||
case 18: break;
|
|
||||||
case 19: break;
|
|
||||||
}
|
|
||||||
|
|
||||||
CopySizeAndPreparePointer(tmpbuf, buf, postsize, reserved, size);
|
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))
|
if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, size))
|
||||||
return false;
|
return false;
|
||||||
|
totalSize += size;
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
|
} while (i < 4);
|
||||||
|
|
||||||
|
// Write checksum and close
|
||||||
|
CFileMgr::Write(file, (const char *) &CheckSum, 4);
|
||||||
// TODO: padding
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -380,7 +411,7 @@ align4bytes(int32 size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
STARTPATCHES
|
STARTPATCHES
|
||||||
//InjectHook(0x58F8D0, GenericSave, PATCH_JUMP);
|
InjectHook(0x58F8D0, GenericSave, PATCH_JUMP);
|
||||||
//InjectHook(0x590A00, GenericLoad, PATCH_JUMP);
|
//InjectHook(0x590A00, GenericLoad, PATCH_JUMP);
|
||||||
InjectHook(0x591910, ReadInSizeofSaveFileBuffer, PATCH_JUMP);
|
InjectHook(0x591910, ReadInSizeofSaveFileBuffer, PATCH_JUMP);
|
||||||
InjectHook(0x591990, ReadDataFromFile, PATCH_JUMP);
|
InjectHook(0x591990, ReadDataFromFile, PATCH_JUMP);
|
||||||
|
Loading…
Reference in New Issue
Block a user