summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorSergeanur <s.anureev@yandex.ua>2019-10-11 00:51:25 +0200
committerGitHub <noreply@github.com>2019-10-11 00:51:25 +0200
commit0408b30a9ffba583f0437c294a98a2cecef74e1d (patch)
tree5fc346badb4cac417ea73b457831c3de89bc450f /src/core
parentSingle-wagon train fix (diff)
parentFix CCarGenerator Load/Save (diff)
downloadre3-0408b30a9ffba583f0437c294a98a2cecef74e1d.tar
re3-0408b30a9ffba583f0437c294a98a2cecef74e1d.tar.gz
re3-0408b30a9ffba583f0437c294a98a2cecef74e1d.tar.bz2
re3-0408b30a9ffba583f0437c294a98a2cecef74e1d.tar.lz
re3-0408b30a9ffba583f0437c294a98a2cecef74e1d.tar.xz
re3-0408b30a9ffba583f0437c294a98a2cecef74e1d.tar.zst
re3-0408b30a9ffba583f0437c294a98a2cecef74e1d.zip
Diffstat (limited to 'src/core')
-rw-r--r--src/core/Streaming.cpp18
-rw-r--r--src/core/common.h51
-rw-r--r--src/core/config.h1
3 files changed, 61 insertions, 9 deletions
diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp
index e59b2b39..d9dc8628 100644
--- a/src/core/Streaming.cpp
+++ b/src/core/Streaming.cpp
@@ -2401,28 +2401,28 @@ CStreaming::LoadScene(const CVector &pos)
}
void
-CStreaming::MemoryCardSave(uint8 *buffer, uint32 *length)
+CStreaming::MemoryCardSave(uint8 *buf, uint32 *size)
{
int i;
- *length = NUM_DEFAULT_MODELS;
+ *size = NUM_DEFAULT_MODELS;
for(i = 0; i < NUM_DEFAULT_MODELS; i++)
if(ms_aInfoForModel[i].m_loadState == STREAMSTATE_LOADED)
- buffer[i] = ms_aInfoForModel[i].m_flags;
+ buf[i] = ms_aInfoForModel[i].m_flags;
else
- buffer[i] = 0xFF;
+ buf[i] = 0xFF;
}
void
-CStreaming::MemoryCardLoad(uint8 *buffer, uint32 length)
+CStreaming::MemoryCardLoad(uint8 *buf, uint32 size)
{
uint32 i;
- assert(length == NUM_DEFAULT_MODELS);
- for(i = 0; i < length; i++)
+ assert(size == NUM_DEFAULT_MODELS);
+ for(i = 0; i < size; i++)
if(ms_aInfoForModel[i].m_loadState == STREAMSTATE_LOADED)
- if(buffer[i] != 0xFF)
- ms_aInfoForModel[i].m_flags = buffer[i];
+ if(buf[i] != 0xFF)
+ ms_aInfoForModel[i].m_flags = buf[i];
}
void
diff --git a/src/core/common.h b/src/core/common.h
index caa305d6..3ea37071 100644
--- a/src/core/common.h
+++ b/src/core/common.h
@@ -317,3 +317,54 @@ _TWEEKCLASS(CTweakUInt32, uint32);
_TWEEKCLASS(CTweakFloat, float);
#undef _TWEEKCLASS
+
+#ifdef VALIDATE_SAVE_SIZE
+static int32 _bufBytesRead;
+#define INITSAVEBUF _bufBytesRead = 0;
+#define VALIDATESAVEBUF(b) assert(_bufBytesRead == b);
+#else
+#define INITSAVEBUF
+#define VALIDATESAVEBUF(b)
+#endif
+
+inline void SkipSaveBuf(uint8 *&buf, int32 skip)
+{
+ buf += skip;
+#ifdef VALIDATE_SAVE_SIZE
+ _bufBytesRead += skip;
+#endif
+}
+
+template<typename T>
+inline const T ReadSaveBuf(uint8 *&buf)
+{
+ T &value = *(T*)buf;
+ SkipSaveBuf(buf, sizeof(T));
+ return value;
+}
+
+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, size);
+
+#define CheckSaveHeader(buf,a,b,c,d,size)\
+ assert(ReadSaveBuf<char>(buf) == a);\
+ assert(ReadSaveBuf<char>(buf) == b);\
+ assert(ReadSaveBuf<char>(buf) == c);\
+ assert(ReadSaveBuf<char>(buf) == d);\
+ assert(ReadSaveBuf<uint32>(buf) == size); \ No newline at end of file
diff --git a/src/core/config.h b/src/core/config.h
index a3fbac1b..08ddd007 100644
--- a/src/core/config.h
+++ b/src/core/config.h
@@ -126,6 +126,7 @@ enum Config {
// only in master builds
#else
// not in master builds
+ #define VALIDATE_SAVE_SIZE
#endif
#ifdef FINAL