summaryrefslogtreecommitdiffstats
path: root/src/save
diff options
context:
space:
mode:
Diffstat (limited to 'src/save')
-rw-r--r--src/save/GenericGameStorage.cpp9
-rw-r--r--src/save/PCSave.cpp4
-rw-r--r--src/save/SaveBuf.h64
3 files changed, 77 insertions, 0 deletions
diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp
index a7cafec8..23a8fd6a 100644
--- a/src/save/GenericGameStorage.cpp
+++ b/src/save/GenericGameStorage.cpp
@@ -220,6 +220,11 @@ GenericSave(int file)
WriteSaveDataBlock(CStreaming::MemoryCardSave);
WriteSaveDataBlock(CPedType::Save);
+ // sure just write garbage data repeatedly ...
+#ifndef THIS_IS_STUPID
+ memset(work_buff, 0, sizeof(work_buff));
+#endif
+
// Write padding
for (int i = 0; i < 4; i++) {
size = align4bytes(SIZE_OF_ONE_GAME_IN_BYTES - totalSize - 4);
@@ -487,7 +492,11 @@ GetNameOfSavedGame(int32 slot)
bool
CheckDataNotCorrupt(int32 slot, char *name)
{
+#ifdef FIX_BUGS
+ char filename[MAX_PATH];
+#else
char filename[100];
+#endif
int32 blocknum = 0;
eLevelName level = LEVEL_GENERIC;
diff --git a/src/save/PCSave.cpp b/src/save/PCSave.cpp
index d8ede0d3..a9df00af 100644
--- a/src/save/PCSave.cpp
+++ b/src/save/PCSave.cpp
@@ -25,7 +25,11 @@ C_PcSave::SetSaveDirectory(const char *path)
bool
C_PcSave::DeleteSlot(int32 slot)
{
+#ifdef FIX_BUGS
+ char FileName[MAX_PATH];
+#else
char FileName[200];
+#endif
PcSaveHelper.nErrorCode = SAVESTATUS_SUCCESSFUL;
sprintf(FileName, "%s%i.b", DefaultPCSaveFileName, slot + 1);
diff --git a/src/save/SaveBuf.h b/src/save/SaveBuf.h
new file mode 100644
index 00000000..98fe888b
--- /dev/null
+++ b/src/save/SaveBuf.h
@@ -0,0 +1,64 @@
+#pragma once
+
+#ifdef VALIDATE_SAVE_SIZE
+extern int32 _saveBufCount;
+#define INITSAVEBUF _saveBufCount = 0;
+#define VALIDATESAVEBUF(b) assert(_saveBufCount == b);
+#else
+#define INITSAVEBUF
+#define VALIDATESAVEBUF(b)
+#endif
+
+inline void
+SkipSaveBuf(uint8 *&buf, int32 skip)
+{
+ buf += skip;
+#ifdef VALIDATE_SAVE_SIZE
+ _saveBufCount += skip;
+#endif
+}
+
+template <typename T>
+inline void
+ReadSaveBuf(T* out, uint8 *&buf)
+{
+ *out = *(T *)buf;
+ SkipSaveBuf(buf, sizeof(T));
+}
+
+template <typename T>
+inline T *
+WriteSaveBuf(uint8 *&buf, const T &value)
+{
+ T *p = (T *)buf;
+ *p = value;
+ SkipSaveBuf(buf, sizeof(T));
+ return p;
+}
+
+#define SAVE_HEADER_SIZE (4 * sizeof(char) + sizeof(uint32))
+
+#define WriteSaveHeader(buf, a, b, c, d, size) \
+ WriteSaveBuf(buf, a); \
+ WriteSaveBuf(buf, b); \
+ WriteSaveBuf(buf, c); \
+ WriteSaveBuf(buf, d); \
+ WriteSaveBuf(buf, (uint32)(size));
+
+#ifdef VALIDATE_SAVE_SIZE
+#define CheckSaveHeader(buf, a, b, c, d, size) do { \
+ char _c; uint32 _size;\
+ ReadSaveBuf(&_c, buf);\
+ assert(_c == a);\
+ ReadSaveBuf(&_c, buf);\
+ assert(_c == b);\
+ ReadSaveBuf(&_c, buf);\
+ assert(_c == c);\
+ ReadSaveBuf(&_c, buf);\
+ assert(_c == d);\
+ ReadSaveBuf(&_size, buf);\
+ assert(_size == size);\
+ } while(0)
+#else
+#define CheckSaveHeader(buf, a, b, c, d, size) SkipSaveBuf(buf, 8);
+#endif \ No newline at end of file