summaryrefslogtreecommitdiff
path: root/src/saveload/cheat_sl.cpp
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-06-06 09:59:33 +0200
committerPatric Stout <github@truebrain.nl>2021-06-15 19:36:15 +0200
commit88edfd4ef16bedd98a07a2142e693ab50fbdcef2 (patch)
treef39b00764786763b3350dd06c2c4014605678ca1 /src/saveload/cheat_sl.cpp
parentb9ab9e4d051eea7d6aedfb60930b039b778568af (diff)
downloadopenttd-88edfd4ef16bedd98a07a2142e693ab50fbdcef2.tar.xz
Change: rework several CH_RIFF chunks to use CH_ARRAY instead
This adds two byte extra to those chunks, and might feel a bit silly at first. But in later changes we will prefix CH_ARRAY with a table header, and then this change shines. Without this, we could still add headers to these chunks, but any external reader wouldn't know if the CH_RIFF has them or not. This way is much more practical, as they are now more like any other chunk.
Diffstat (limited to 'src/saveload/cheat_sl.cpp')
-rw-r--r--src/saveload/cheat_sl.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/saveload/cheat_sl.cpp b/src/saveload/cheat_sl.cpp
index fde1fc176..51df50314 100644
--- a/src/saveload/cheat_sl.cpp
+++ b/src/saveload/cheat_sl.cpp
@@ -44,6 +44,8 @@ static const SaveLoad _cheats_desc[] = {
*/
static void Save_CHTS()
{
+ SlSetArrayIndex(0);
+
SlSetLength(std::size(_cheats_desc));
SlObject(&_cheats, _cheats_desc);
}
@@ -67,12 +69,14 @@ static void Load_CHTS()
if (count == 0) break;
}
+ if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return;
SlObject(&_cheats, slt);
+ if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many CHTS entries");
}
/** Chunk handlers related to cheats. */
static const ChunkHandler cheat_chunk_handlers[] = {
- { 'CHTS', Save_CHTS, Load_CHTS, nullptr, nullptr, CH_RIFF },
+ { 'CHTS', Save_CHTS, Load_CHTS, nullptr, nullptr, CH_ARRAY },
};
extern const ChunkHandlerTable _cheat_chunk_handlers(cheat_chunk_handlers);