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.
This commit is contained in:
Patric Stout
2021-06-06 09:59:33 +02:00
committed by Patric Stout
parent b9ab9e4d05
commit 88edfd4ef1
10 changed files with 97 additions and 32 deletions

View File

@@ -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);