summaryrefslogtreecommitdiffstats
path: root/src/save
diff options
context:
space:
mode:
authorNikolay Korolev <nickvnuk@gmail.com>2021-07-02 10:28:46 +0200
committerNikolay Korolev <nickvnuk@gmail.com>2021-07-02 10:28:46 +0200
commit10cc444482b52d6e82b624bbbb7d87c48dcf48e2 (patch)
tree2c80031552d77909220ed7bd66a7e055aa3e5b45 /src/save
parentMerge remote-tracking branch 'upstream/lcs' into lcs (diff)
parentMerge branch 'miami' into lcs (diff)
downloadre3-10cc444482b52d6e82b624bbbb7d87c48dcf48e2.tar
re3-10cc444482b52d6e82b624bbbb7d87c48dcf48e2.tar.gz
re3-10cc444482b52d6e82b624bbbb7d87c48dcf48e2.tar.bz2
re3-10cc444482b52d6e82b624bbbb7d87c48dcf48e2.tar.lz
re3-10cc444482b52d6e82b624bbbb7d87c48dcf48e2.tar.xz
re3-10cc444482b52d6e82b624bbbb7d87c48dcf48e2.tar.zst
re3-10cc444482b52d6e82b624bbbb7d87c48dcf48e2.zip
Diffstat (limited to 'src/save')
-rw-r--r--src/save/GenericGameStorage.cpp4
-rw-r--r--src/save/PCSave.cpp4
-rw-r--r--src/save/SaveBuf.h115
3 files changed, 123 insertions, 0 deletions
diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp
index 0bab5439..cbd4e2a4 100644
--- a/src/save/GenericGameStorage.cpp
+++ b/src/save/GenericGameStorage.cpp
@@ -540,7 +540,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 70ca31d2..c9045705 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..de27017e
--- /dev/null
+++ b/src/save/SaveBuf.h
@@ -0,0 +1,115 @@
+#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
+}
+
+inline void
+SkipSaveBuf(uint8*& buf, uint32 &length, int32 skip)
+{
+ buf += skip;
+ length += 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 void
+ReadSaveBuf(T *out, uint8 *&buf, uint32 &length)
+{
+ *out = *(T *)buf;
+ SkipSaveBuf(buf, length, 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;
+}
+
+template<typename T>
+inline T *
+WriteSaveBuf(uint8 *&buf, uint32 &length, const T &value)
+{
+ T *p = (T*)buf;
+ *p = value;
+ SkipSaveBuf(buf, length, 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<uint32>(buf, size);
+
+#define WriteSaveHeaderWithLength(buf,len,a,b,c,d,size) \
+ WriteSaveBuf(buf, len, a);\
+ WriteSaveBuf(buf, len, b);\
+ WriteSaveBuf(buf, len, c);\
+ WriteSaveBuf(buf, len, d);\
+ WriteSaveBuf(buf, len, (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)
+
+#define CheckSaveHeaderWithLength(buf,len,a,b,c,d,size) do { \
+ char _C; uint32 _size;\
+ ReadSaveBuf(&_C, buf, len);\
+ assert(_C == a);\
+ ReadSaveBuf(&_C, buf, len);\
+ assert(_C == b);\
+ ReadSaveBuf(&_C, buf, len);\
+ assert(_C == c);\
+ ReadSaveBuf(&_C, buf, len);\
+ assert(_C == d);\
+ ReadSaveBuf(&_size, buf, len);\
+ assert(_size == size);\
+ } while(0)
+#else
+#define CheckSaveHeader(buf, a, b, c, d, size) SkipSaveBuf(buf, 8);
+#define CheckSaveHeaderWithLength(buf, len, a, b, c, d, size) SkipSaveBuf(buf, 8);
+#endif