Bugfixes, GenericSave() works now!

This commit is contained in:
Wes Hampson 2020-03-11 14:08:10 -07:00
parent c7f16879df
commit 81c4f75c63

View File

@ -30,6 +30,8 @@
#include "Zones.h" #include "Zones.h"
#define BLOCK_COUNT 20 #define BLOCK_COUNT 20
#define SIZE_OF_SIMPLEVARS 0xBC
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;
@ -57,9 +59,9 @@ do {\
MakeSpaceForSizeInBufferPointer(presize, buf, postsize);\ MakeSpaceForSizeInBufferPointer(presize, buf, postsize);\
save_func(buf, &size);\ save_func(buf, &size);\
CopySizeAndPreparePointer(presize, buf, postsize, reserved, size);\ CopySizeAndPreparePointer(presize, buf, postsize, reserved, size);\
if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, size))\ if (!PcSaveHelper.PcClassSaveRoutine(file, work_buff, size + 4))\
return false;\ return false;\
blockSizes[blockIndex++] = size;\ totalSize += size;\
} while (0) } while (0)
bool bool
@ -70,8 +72,6 @@ GenericSave(int file)
uint32 reserved; uint32 reserved;
uint32 totalSize; uint32 totalSize;
uint32 blockSizes[BLOCK_COUNT];
uint32 blockIndex;
uint32 i; uint32 i;
wchar *lastMissionPassed; wchar *lastMissionPassed;
@ -83,7 +83,7 @@ GenericSave(int file)
CheckSum = 0; CheckSum = 0;
buf = work_buff; buf = work_buff;
reserved = 0; reserved = 0;
blockIndex = 0; totalSize = 0;
// Save simple vars // Save simple vars
INITSAVEBUF INITSAVEBUF
@ -135,7 +135,7 @@ INITSAVEBUF
WriteSaveBuf(buf, CWeather::WeatherTypeInList); WriteSaveBuf(buf, CWeather::WeatherTypeInList);
WriteSaveBuf(buf, TheCamera.CarZoomIndicator); WriteSaveBuf(buf, TheCamera.CarZoomIndicator);
WriteSaveBuf(buf, TheCamera.PedZoomIndicator); 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 // Save scripts, block is nested within the same block as simple vars for some reason
presize = buf; presize = buf;
@ -143,10 +143,9 @@ VALIDATESAVEBUF(0xBC);
postsize = buf; postsize = buf;
CTheScripts::SaveAllScripts(buf, &size); CTheScripts::SaveAllScripts(buf, &size);
CopySizeAndPreparePointer(presize, buf, postsize, reserved, 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; return false;
blockSizes[0] = size + 0xBC; totalSize += size + SIZE_OF_SIMPLEVARS;
blockIndex++;
// Save the rest // Save the rest
WRITE_BLOCK(CPools::SavePedPool); WRITE_BLOCK(CPools::SavePedPool);
@ -169,10 +168,6 @@ VALIDATESAVEBUF(0xBC);
WRITE_BLOCK(CStreaming::MemoryCardSave); WRITE_BLOCK(CStreaming::MemoryCardSave);
WRITE_BLOCK(CPedType::Save); WRITE_BLOCK(CPedType::Save);
totalSize = 0;
for (i = 0; i < BLOCK_COUNT; i++)
totalSize += blockSizes[i];
// Write padding // Write padding
i = 0; i = 0;
do { do {
@ -188,10 +183,10 @@ VALIDATESAVEBUF(0xBC);
} while (i < 4); } while (i < 4);
// Write checksum and close // Write checksum and close
CFileMgr::Write(file, (const char *) &CheckSum, 4); CFileMgr::Write(file, (const char *) &CheckSum, sizeof(CheckSum));
if (CFileMgr::GetErrorReadWrite(file)) { if (CFileMgr::GetErrorReadWrite(file)) {
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_SAVE_WRITE; PcSaveHelper.nErrorCode = SAVESTATUS_ERR_SAVE_WRITE;
if (CFileMgr::CloseFile(file) == 0) if (CloseFile(file))
PcSaveHelper.nErrorCode = SAVESTATUS_ERR_SAVE_CLOSE; PcSaveHelper.nErrorCode = SAVESTATUS_ERR_SAVE_CLOSE;
return false; return false;
} }