forked from mirror/OpenTTD
Add: store headers for most savegame chunks
When a header is added, the chunk changes from CH_ARRAY type to CH_TABLE type.
This commit is contained in:
committed by
Patric Stout
parent
7dd5fd6ed4
commit
cdb3dd0493
@@ -8,9 +8,11 @@
|
||||
/** @file cheat_sl.cpp Code handling saving and loading of cheats */
|
||||
|
||||
#include "../stdafx.h"
|
||||
#include "../cheat_type.h"
|
||||
|
||||
#include "saveload.h"
|
||||
#include "compat/cheat_sl_compat.h"
|
||||
|
||||
#include "../cheat_type.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
@@ -23,18 +25,12 @@ static const SaveLoad _cheats_desc[] = {
|
||||
SLE_VAR(Cheats, money.value, SLE_BOOL),
|
||||
SLE_VAR(Cheats, crossing_tunnels.been_used, SLE_BOOL),
|
||||
SLE_VAR(Cheats, crossing_tunnels.value, SLE_BOOL),
|
||||
SLE_NULL(1),
|
||||
SLE_NULL(1), // Needs to be two NULL fields. See Load_CHTS().
|
||||
SLE_VAR(Cheats, no_jetcrash.been_used, SLE_BOOL),
|
||||
SLE_VAR(Cheats, no_jetcrash.value, SLE_BOOL),
|
||||
SLE_NULL(1),
|
||||
SLE_NULL(1), // Needs to be two NULL fields. See Load_CHTS().
|
||||
SLE_VAR(Cheats, change_date.been_used, SLE_BOOL),
|
||||
SLE_VAR(Cheats, change_date.value, SLE_BOOL),
|
||||
SLE_VAR(Cheats, setup_prod.been_used, SLE_BOOL),
|
||||
SLE_VAR(Cheats, setup_prod.value, SLE_BOOL),
|
||||
SLE_NULL(1),
|
||||
SLE_NULL(1), // Needs to be two NULL fields. See Load_CHTS().
|
||||
SLE_VAR(Cheats, edit_max_hl.been_used, SLE_BOOL),
|
||||
SLE_VAR(Cheats, edit_max_hl.value, SLE_BOOL),
|
||||
};
|
||||
@@ -44,9 +40,9 @@ static const SaveLoad _cheats_desc[] = {
|
||||
*/
|
||||
static void Save_CHTS()
|
||||
{
|
||||
SlSetArrayIndex(0);
|
||||
SlTableHeader(_cheats_desc);
|
||||
|
||||
SlSetLength(std::size(_cheats_desc));
|
||||
SlSetArrayIndex(0);
|
||||
SlObject(&_cheats, _cheats_desc);
|
||||
}
|
||||
|
||||
@@ -55,18 +51,23 @@ static void Save_CHTS()
|
||||
*/
|
||||
static void Load_CHTS()
|
||||
{
|
||||
size_t count = SlGetFieldLength();
|
||||
std::vector<SaveLoad> slt;
|
||||
std::vector<SaveLoad> slt = SlCompatTableHeader(_cheats_desc, _cheats_sl_compat);
|
||||
|
||||
/* Cheats were added over the years without a savegame bump. They are
|
||||
* stored as 2 SLE_BOOLs per entry. "count" indicates how many SLE_BOOLs
|
||||
* are stored for this savegame. So read only "count" SLE_BOOLs (and in
|
||||
* result "count / 2" cheats). */
|
||||
for (auto &sld : _cheats_desc) {
|
||||
count--;
|
||||
slt.push_back(sld);
|
||||
if (IsSavegameVersionBefore(SLV_TABLE_CHUNKS)) {
|
||||
size_t count = SlGetFieldLength();
|
||||
std::vector<SaveLoad> oslt;
|
||||
|
||||
if (count == 0) break;
|
||||
/* Cheats were added over the years without a savegame bump. They are
|
||||
* stored as 2 SLE_BOOLs per entry. "count" indicates how many SLE_BOOLs
|
||||
* are stored for this savegame. So read only "count" SLE_BOOLs (and in
|
||||
* result "count / 2" cheats). */
|
||||
for (auto &sld : slt) {
|
||||
count--;
|
||||
oslt.push_back(sld);
|
||||
|
||||
if (count == 0) break;
|
||||
}
|
||||
slt = oslt;
|
||||
}
|
||||
|
||||
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return;
|
||||
@@ -75,7 +76,7 @@ static void Load_CHTS()
|
||||
}
|
||||
|
||||
static const ChunkHandler cheat_chunk_handlers[] = {
|
||||
{ 'CHTS', Save_CHTS, Load_CHTS, nullptr, nullptr, CH_ARRAY },
|
||||
{ 'CHTS', Save_CHTS, Load_CHTS, nullptr, nullptr, CH_TABLE },
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _cheat_chunk_handlers(cheat_chunk_handlers);
|
||||
|
Reference in New Issue
Block a user