10 #include "../stdafx.h"
15 #include "../gamelog_internal.h"
17 #include "../string_func.h"
19 #include "../safeguards.h"
24 inline static const SaveLoad description[] = {
42 void LoadCheck(
LoggedChange *lc)
const override { this->Load(lc); }
47 static const size_t GAMELOG_REVISION_LENGTH = 15;
48 static char revision_text[GAMELOG_REVISION_LENGTH];
50 inline static const SaveLoad description[] = {
71 static_cast<LoggedChangeRevision *
>(lc)->text =
StrMakeValid(std::string_view(std::begin(SlGamelogRevision::revision_text), std::end(SlGamelogRevision::revision_text)));
75 void LoadCheck(
LoggedChange *lc)
const override { this->Load(lc); }
78 char SlGamelogRevision::revision_text[GAMELOG_REVISION_LENGTH];
82 inline static const SaveLoad description[] = {
100 void LoadCheck(
LoggedChange *lc)
const override { this->Load(lc); }
105 inline static const SaveLoad description[] = {
124 void LoadCheck(
LoggedChange *lc)
const override { this->Load(lc); }
129 inline static const SaveLoad description[] = {
147 void LoadCheck(
LoggedChange *lc)
const override { this->Load(lc); }
152 inline static const SaveLoad description[] = {
169 void LoadCheck(
LoggedChange *lc)
const override { this->Load(lc); }
174 inline static const SaveLoad description[] = {
192 void LoadCheck(
LoggedChange *lc)
const override { this->Load(lc); }
197 inline static const SaveLoad description[] = {
214 void LoadCheck(
LoggedChange *lc)
const override { this->Load(lc); }
219 inline static const SaveLoad description[] = {
237 void LoadCheck(
LoggedChange *lc)
const override { this->Load(lc); }
242 inline static const SaveLoad description[] = {
261 void LoadCheck(
LoggedChange *lc)
const override { this->Load(lc); }
264 static bool _is_emergency_save =
true;
269 inline static const SaveLoad description[] = {
278 _is_emergency_save =
true;
289 void LoadCheck(
LoggedChange *lc)
const override { this->Load(lc); }
295 case GLCT_MODE:
return std::make_unique<LoggedChangeMode>();
296 case GLCT_REVISION:
return std::make_unique<LoggedChangeRevision>();
297 case GLCT_OLDVER:
return std::make_unique<LoggedChangeOldVersion>();
298 case GLCT_SETTING:
return std::make_unique<LoggedChangeSettingChanged>();
299 case GLCT_GRFADD:
return std::make_unique<LoggedChangeGRFAdd>();
300 case GLCT_GRFREM:
return std::make_unique<LoggedChangeGRFRemoved>();
301 case GLCT_GRFCOMPAT:
return std::make_unique<LoggedChangeGRFChanged>();
302 case GLCT_GRFPARAM:
return std::make_unique<LoggedChangeGRFParameterChanged>();
303 case GLCT_GRFMOVE:
return std::make_unique<LoggedChangeGRFMoved>();
304 case GLCT_GRFBUG:
return std::make_unique<LoggedChangeGRFBug>();
305 case GLCT_EMERGENCY:
return std::make_unique<LoggedChangeEmergencySave>();
315 inline static const SaveLoad description[] = {
335 for (
auto &lc : la->
change) {
337 SlObject(lc.get(), this->GetDescription());
343 std::unique_ptr<LoggedChange> lc = MakeLoggedChange(type);
344 SlObject(lc.get(), this->GetLoadDescription());
345 la->
change.push_back(std::move(lc));
360 la->
change.reserve(length);
362 for (
size_t i = 0; i < length; i++) {
367 void LoadCheck(
LoggedAction *la)
const override { this->Load(la); }
370 static const SaveLoad _gamelog_desc[] = {
380 void LoadCommon(
Gamelog &gamelog)
const
382 assert(gamelog.data->action.empty());
410 SlSetArrayIndex(i++);
Default handler for saving/loading an object to/from disk.
SaveLoadTable GetDescription() const override
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Gamelog _gamelog
Gamelog instance.
GamelogChangeType
Type of logged change.
@ GLCT_MODE
Scenario editor x Game, different landscape.
@ GLCT_OLDVER
Loaded from savegame without logged data.
@ GLCT_SETTING
Non-networksafe setting value changed.
@ GLCT_GRFCOMPAT
Loading compatible GRF.
@ GLCT_GRFADD
Removed GRF.
@ GLCT_END
So we know how many GLCTs are there.
@ GLCT_EMERGENCY
Emergency savegame.
@ GLCT_GRFPARAM
GRF parameter changed.
@ GLCT_GRFMOVE
GRF order changed.
@ GLCT_GRFBUG
GRF bug triggered.
@ GLCT_REVISION
Changed game revision string.
@ GLCT_NONE
In savegames, end of list.
GamelogActionType
The actions we log.
@ GLAT_NONE
No logging active; in savegames, end of list.
@ GLAT_END
So we know how many GLATs are there.
Loading for gamelog chunks before table headers were added.
const SaveLoadCompat _gamelog_emergency_sl_compat[]
Original field order for SlGamelogEmergency.
const SaveLoadCompat _gamelog_mode_sl_compat[]
Original field order for SlGamelogMode.
const SaveLoadCompat _gamelog_grfmove_sl_compat[]
Original field order for SlGamelogGrfmove.
const SaveLoadCompat _gamelog_action_sl_compat[]
Original field order for SlGamelogAction.
const SaveLoadCompat _gamelog_oldver_sl_compat[]
Original field order for SlGamelogOldver.
const SaveLoadCompat _gamelog_revision_sl_compat[]
Original field order for SlGamelogRevision.
const SaveLoadCompat _gamelog_sl_compat[]
Original field order for _gamelog_desc.
const SaveLoadCompat _gamelog_setting_sl_compat[]
Original field order for SlGamelogSetting.
const SaveLoadCompat _gamelog_grfrem_sl_compat[]
Original field order for SlGamelogGrfrem.
const SaveLoadCompat _gamelog_grfbug_sl_compat[]
Original field order for SlGamelogGrfbug.
const SaveLoadCompat _gamelog_grfadd_sl_compat[]
Original field order for SlGamelogGrfadd.
const SaveLoadCompat _gamelog_grfcompat_sl_compat[]
Original field order for SlGamelogGrfcompat.
const SaveLoadCompat _gamelog_grfparam_sl_compat[]
Original field order for SlGamelogGrfparam.
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
uint8_t SlReadByte()
Wrapper for reading a byte from the buffer.
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
void SlSetStructListLength(size_t length)
Set the length of this list.
Functions/types related to saving and loading games.
#define SLEG_CONDARR(name, variable, type, length, from, to)
Storage of a global fixed-size array of SL_VAR elements in some savegame versions.
#define SLEG_STRUCTLIST(name, handler)
Storage of a list of structs in every savegame version.
#define SLE_CONDSSTRNAME(base, variable, name, type, from, to)
Storage of a std::string in some savegame versions.
#define SLE_SSTRNAME(base, variable, name, type)
Storage of a std::string in every savegame version.
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
#define SLE_VARNAME(base, variable, name, type)
Storage of a variable in every version of a savegame.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
#define SLE_ARRNAME(base, variable, name, type, length)
Storage of fixed-size array of SL_VAR elements in every version of a savegame.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
#define SLE_SAVEBYTE(base, variable)
Only write byte during saving; never read it during loading.
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
#define SLEG_STRUCT(name, handler)
Storage of a structs in every savegame version.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
@ SLV_RIFF_TO_ARRAY
294 PR#9375 Changed many CH_RIFF chunks to CH_ARRAY chunks.
@ SL_MAX_VERSION
Highest possible saveload version.
@ SL_MIN_VERSION
First savegame version.
@ SLV_STRING_GAMELOG
314 PR#10801 Use std::string in gamelog.
@ SLV_U64_TICK_COUNTER
300 PR#10035 Make tick counter 64bit to avoid wrapping.
static void StrMakeValid(T &dst, const char *str, const char *last, StringValidationSettings settings)
Copies the valid (UTF-8) characters from str up to last to the dst.
Handlers and description of chunk.
ChunkType type
Type of the chunk.
void LoadCheck(size_t) const override
Load the chunk for game preview.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
Gamelog gamelog
Gamelog actions.
Contains information about one logged action that caused at least one logged change.
std::vector< std::unique_ptr< LoggedChange > > change
Logged changes in this action.
GamelogActionType at
Type of action.