OpenTTD Source  1.11.0-beta2
saveload.h File Reference
#include "../fileio_type.h"
#include "../strings_type.h"
#include <string>

Go to the source code of this file.

Data Structures

struct  FileToSaveLoad
 Deals with the type of the savegame, independent of extension. More...
 
struct  ChunkHandler
 Handlers and description of chunk. More...
 
struct  SaveLoad
 SaveLoad type struct. More...
 

Macros

#define SLE_GENERAL(cmd, base, variable, type, length, from, to, extra)   {cmd, type, length, from, to, cpp_sizeof(base, variable), [] (void *b, size_t) -> void * { assert(b != nullptr); return const_cast<void *>(static_cast<const void *>(std::addressof(static_cast<base *>(b)->variable))); }, extra}
 Storage of simple variables, references (pointers), and arrays. More...
 
#define SLE_CONDVAR(base, variable, type, from, to)   SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to, 0)
 Storage of a variable in some savegame versions. More...
 
#define SLE_CONDREF(base, variable, type, from, to)   SLE_GENERAL(SL_REF, base, variable, type, 0, from, to, 0)
 Storage of a reference in some savegame versions. More...
 
#define SLE_CONDARR(base, variable, type, length, from, to)   SLE_GENERAL(SL_ARR, base, variable, type, length, from, to, 0)
 Storage of an array in some savegame versions. More...
 
#define SLE_CONDSTR(base, variable, type, length, from, to)   SLE_GENERAL(SL_STR, base, variable, type, length, from, to, 0)
 Storage of a string in some savegame versions. More...
 
#define SLE_CONDSSTR(base, variable, type, from, to)   SLE_GENERAL(SL_STDSTR, base, variable, type, 0, from, to, 0)
 Storage of a std::string in some savegame versions. More...
 
#define SLE_CONDLST(base, variable, type, from, to)   SLE_GENERAL(SL_LST, base, variable, type, 0, from, to, 0)
 Storage of a list in some savegame versions. More...
 
#define SLE_CONDDEQUE(base, variable, type, from, to)   SLE_GENERAL(SL_DEQUE, base, variable, type, 0, from, to, 0)
 Storage of a deque in some savegame versions. More...
 
#define SLE_VAR(base, variable, type)   SLE_CONDVAR(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
 Storage of a variable in every version of a savegame. More...
 
#define SLE_REF(base, variable, type)   SLE_CONDREF(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
 Storage of a reference in every version of a savegame. More...
 
#define SLE_ARR(base, variable, type, length)   SLE_CONDARR(base, variable, type, length, SL_MIN_VERSION, SL_MAX_VERSION)
 Storage of an array in every version of a savegame. More...
 
#define SLE_STR(base, variable, type, length)   SLE_CONDSTR(base, variable, type, length, SL_MIN_VERSION, SL_MAX_VERSION)
 Storage of a string in every savegame version. More...
 
#define SLE_SSTR(base, variable, type)   SLE_CONDSSTR(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
 Storage of a std::string in every savegame version. More...
 
#define SLE_LST(base, variable, type)   SLE_CONDLST(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
 Storage of a list in every savegame version. More...
 
#define SLE_NULL(length)   SLE_CONDNULL(length, SL_MIN_VERSION, SL_MAX_VERSION)
 Empty space in every savegame version. More...
 
#define SLE_CONDNULL(length, from, to)   {SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, 0, nullptr, 0}
 Empty space in some savegame versions. More...
 
#define SLE_WRITEBYTE(base, variable)   SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, 0)
 Translate values ingame to different values in the savegame and vv.
 
#define SLE_VEH_INCLUDE()   {SL_VEH_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, 0, [] (void *b, size_t) { return b; }, 0}
 
#define SLE_ST_INCLUDE()   {SL_ST_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, 0, [] (void *b, size_t) { return b; }, 0}
 
#define SLE_END()   {SL_END, 0, 0, SL_MIN_VERSION, SL_MIN_VERSION, 0, nullptr, 0}
 End marker of a struct/class save or load.
 
#define SLEG_GENERAL(cmd, variable, type, length, from, to, extra)   {cmd, type, length, from, to, sizeof(variable), [] (void *, size_t) -> void * { return static_cast<void *>(std::addressof(variable)); }, extra}
 Storage of global simple variables, references (pointers), and arrays. More...
 
#define SLEG_CONDVAR(variable, type, from, to)   SLEG_GENERAL(SL_VAR, variable, type, 0, from, to, 0)
 Storage of a global variable in some savegame versions. More...
 
#define SLEG_CONDREF(variable, type, from, to)   SLEG_GENERAL(SL_REF, variable, type, 0, from, to, 0)
 Storage of a global reference in some savegame versions. More...
 
#define SLEG_CONDARR(variable, type, length, from, to)   SLEG_GENERAL(SL_ARR, variable, type, length, from, to, 0)
 Storage of a global array in some savegame versions. More...
 
#define SLEG_CONDSTR(variable, type, length, from, to)   SLEG_GENERAL(SL_STR, variable, type, length, from, to, 0)
 Storage of a global string in some savegame versions. More...
 
#define SLEG_CONDSSTR(variable, type, from, to)   SLEG_GENERAL(SL_STDSTR, variable, type, 0, from, to, 0)
 Storage of a global std::string in some savegame versions. More...
 
#define SLEG_CONDLST(variable, type, from, to)   SLEG_GENERAL(SL_LST, variable, type, 0, from, to, 0)
 Storage of a global list in some savegame versions. More...
 
#define SLEG_VAR(variable, type)   SLEG_CONDVAR(variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
 Storage of a global variable in every savegame version. More...
 
#define SLEG_REF(variable, type)   SLEG_CONDREF(variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
 Storage of a global reference in every savegame version. More...
 
#define SLEG_ARR(variable, type)   SLEG_CONDARR(variable, type, lengthof(variable), SL_MIN_VERSION, SL_MAX_VERSION)
 Storage of a global array in every savegame version. More...
 
#define SLEG_STR(variable, type)   SLEG_CONDSTR(variable, type, sizeof(variable), SL_MIN_VERSION, SL_MAX_VERSION)
 Storage of a global string in every savegame version. More...
 
#define SLEG_SSTR(variable, type)   SLEG_CONDSSTR(variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
 Storage of a global std::string in every savegame version. More...
 
#define SLEG_LST(variable, type)   SLEG_CONDLST(variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
 Storage of a global list in every savegame version. More...
 
#define SLEG_CONDNULL(length, from, to)   {SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, 0, nullptr, 0}
 Empty global space in some savegame versions. More...
 
#define SLEG_END()   {SL_END, 0, 0, SL_MIN_VERSION, SL_MIN_VERSION, 0, nullptr, 0}
 End marker of global variables save or load.
 

Typedefs

typedef void ChunkSaveLoadProc()
 
typedef void AutolengthProc(void *arg)
 
typedef uint32 VarType
 
typedef void * SaveLoadAddrProc(void *base, size_t extra)
 
typedef SaveLoad SaveLoadGlobVarList
 Same as SaveLoad but global variables are used (for better readability);.
 

Enumerations

enum  SaveLoadVersion : uint16 {
  SL_MIN_VERSION, SLV_1, SLV_2, SLV_3,
  SLV_4, SLV_5, SLV_6, SLV_7,
  SLV_8, SLV_9, SLV_10, SLV_11,
  SLV_12, SLV_13, SLV_14, SLV_15,
  SLV_16, SLV_17, SLV_18, SLV_19,
  SLV_20, SLV_21, SLV_22, SLV_23,
  SLV_24, SLV_25, SLV_26, SLV_27,
  SLV_28, SLV_29, SLV_30, SLV_31,
  SLV_32, SLV_33, SLV_34, SLV_35,
  SLV_36, SLV_37, SLV_38, SLV_39,
  SLV_40, SLV_41, SLV_42, SLV_43,
  SLV_44, SLV_45, SLV_46, SLV_47,
  SLV_48, SLV_49, SLV_50, SLV_51,
  SLV_52, SLV_53, SLV_54, SLV_55,
  SLV_56, SLV_57, SLV_58, SLV_59,
  SLV_60, SLV_61, SLV_62, SLV_63,
  SLV_64, SLV_65, SLV_66, SLV_67,
  SLV_68, SLV_69, SLV_70, SLV_71,
  SLV_72, SLV_73, SLV_74, SLV_75,
  SLV_76, SLV_77, SLV_78, SLV_79,
  SLV_80, SLV_81, SLV_82, SLV_83,
  SLV_84, SLV_85, SLV_86, SLV_87,
  SLV_88, SLV_89, SLV_90, SLV_91,
  SLV_92, SLV_93, SLV_94, SLV_95,
  SLV_96, SLV_97, SLV_98, SLV_99,
  SLV_100, SLV_101, SLV_102, SLV_103,
  SLV_104, SLV_105, SLV_106, SLV_107,
  SLV_108, SLV_109, SLV_110, SLV_111,
  SLV_112, SLV_113, SLV_114, SLV_115,
  SLV_116, SLV_117, SLV_118, SLV_119,
  SLV_120, SLV_121, SLV_122, SLV_123,
  SLV_124, SLV_125, SLV_126, SLV_127,
  SLV_128, SLV_129, SLV_130, SLV_131,
  SLV_132, SLV_133, SLV_134, SLV_135,
  SLV_136, SLV_137, SLV_138, SLV_139,
  SLV_140, SLV_141, SLV_142, SLV_143,
  SLV_144, SLV_145, SLV_146, SLV_147,
  SLV_148, SLV_149, SLV_150, SLV_151,
  SLV_152, SLV_153, SLV_154, SLV_155,
  SLV_156, SLV_157, SLV_158, SLV_159,
  SLV_160, SLV_161, SLV_162, SLV_163,
  SLV_164, SLV_165, SLV_166, SLV_167,
  SLV_168, SLV_169, SLV_170, SLV_171,
  SLV_172, SLV_173, SLV_174, SLV_175,
  SLV_176, SLV_177, SLV_178, SLV_179,
  SLV_180, SLV_181, SLV_182, SLV_183,
  SLV_184, SLV_185, SLV_186, SLV_187,
  SLV_188, SLV_189, SLV_190, SLV_191,
  SLV_192, SLV_193, SLV_194, SLV_195,
  SLV_196, SLV_197, SLV_198, SLV_EXTEND_CARGOTYPES,
  SLV_EXTEND_RAILTYPES, SLV_EXTEND_PERSISTENT_STORAGE, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_SHIP_PATH_CACHE,
  SLV_SHIP_ROTATION, SLV_GROUP_LIVERIES, SLV_SHIPS_STOP_IN_LOCKS, SLV_FIX_CARGO_MONITOR,
  SLV_TOWN_CARGOGEN, SLV_SHIP_CURVE_PENALTY, SLV_SERVE_NEUTRAL_INDUSTRIES, SLV_ROADVEH_PATH_CACHE,
  SLV_REMOVE_OPF, SLV_TREES_WATER_CLASS, SLV_ROAD_TYPES, SLV_SCRIPT_MEMLIMIT,
  SLV_MULTITILE_DOCKS, SLV_TRADING_AGE, SLV_ENDING_YEAR, SLV_REMOVE_TOWN_CARGO_CACHE,
  SLV_START_PATCHPACKS, SLV_END_PATCHPACKS = 286, SLV_GS_INDUSTRY_CONTROL, SLV_VEH_MOTION_COUNTER,
  SLV_INDUSTRY_TEXT, SL_MAX_VERSION
}
 SaveLoad versions Previous savegame versions, the trunk revision where they were introduced and the released version that had that particular savegame version. More...
 
enum  SaveOrLoadResult { SL_OK = 0, SL_ERROR = 1, SL_REINIT = 2 }
 Save or load result codes. More...
 
enum  SavegameType {
  SGT_TTD, SGT_TTDP1, SGT_TTDP2, SGT_OTTD,
  SGT_TTO, SGT_INVALID = 0xFF
}
 Types of save games. More...
 
enum  SLRefType {
  REF_ORDER = 0, REF_VEHICLE = 1, REF_STATION = 2, REF_TOWN = 3,
  REF_VEHICLE_OLD = 4, REF_ROADSTOPS = 5, REF_ENGINE_RENEWS = 6, REF_CARGO_PACKET = 7,
  REF_ORDERLIST = 8, REF_STORAGE = 9, REF_LINK_GRAPH = 10, REF_LINK_GRAPH_JOB = 11
}
 Type of reference (SLE_REF, SLE_CONDREF). More...
 
enum  ChunkType {
  CH_RIFF = 0, CH_ARRAY = 1, CH_SPARSE_ARRAY = 2, CH_TYPE_MASK = 3,
  CH_LAST = 8
}
 Flags of a chunk. More...
 
enum  VarTypes {
  SLE_FILE_I8 = 0, SLE_FILE_U8 = 1, SLE_FILE_I16 = 2, SLE_FILE_U16 = 3,
  SLE_FILE_I32 = 4, SLE_FILE_U32 = 5, SLE_FILE_I64 = 6, SLE_FILE_U64 = 7,
  SLE_FILE_STRINGID = 8, SLE_FILE_STRING = 9, SLE_VAR_BL = 0 << 4, SLE_VAR_I8 = 1 << 4,
  SLE_VAR_U8 = 2 << 4, SLE_VAR_I16 = 3 << 4, SLE_VAR_U16 = 4 << 4, SLE_VAR_I32 = 5 << 4,
  SLE_VAR_U32 = 6 << 4, SLE_VAR_I64 = 7 << 4, SLE_VAR_U64 = 8 << 4, SLE_VAR_NULL = 9 << 4,
  SLE_VAR_STRB = 10 << 4, SLE_VAR_STRBQ = 11 << 4, SLE_VAR_STR = 12 << 4, SLE_VAR_STRQ = 13 << 4,
  SLE_VAR_NAME = 14 << 4, SLE_VAR_CHAR = SLE_VAR_I8, SLE_BOOL = SLE_FILE_I8 | SLE_VAR_BL, SLE_INT8 = SLE_FILE_I8 | SLE_VAR_I8,
  SLE_UINT8 = SLE_FILE_U8 | SLE_VAR_U8, SLE_INT16 = SLE_FILE_I16 | SLE_VAR_I16, SLE_UINT16 = SLE_FILE_U16 | SLE_VAR_U16, SLE_INT32 = SLE_FILE_I32 | SLE_VAR_I32,
  SLE_UINT32 = SLE_FILE_U32 | SLE_VAR_U32, SLE_INT64 = SLE_FILE_I64 | SLE_VAR_I64, SLE_UINT64 = SLE_FILE_U64 | SLE_VAR_U64, SLE_CHAR = SLE_FILE_I8 | SLE_VAR_CHAR,
  SLE_STRINGID = SLE_FILE_STRINGID | SLE_VAR_U32, SLE_STRINGBUF = SLE_FILE_STRING | SLE_VAR_STRB, SLE_STRINGBQUOTE = SLE_FILE_STRING | SLE_VAR_STRBQ, SLE_STRING = SLE_FILE_STRING | SLE_VAR_STR,
  SLE_STRINGQUOTE = SLE_FILE_STRING | SLE_VAR_STRQ, SLE_NAME = SLE_FILE_STRINGID | SLE_VAR_NAME, SLE_UINT = SLE_UINT32, SLE_INT = SLE_INT32,
  SLE_STRB = SLE_STRINGBUF, SLE_STRBQ = SLE_STRINGBQUOTE, SLE_STR = SLE_STRING, SLE_STRQ = SLE_STRINGQUOTE,
  SLF_NOT_IN_SAVE = 1 << 8, SLF_NOT_IN_CONFIG = 1 << 9, SLF_NO_NETWORK_SYNC = 1 << 10, SLF_ALLOW_CONTROL = 1 << 11,
  SLF_ALLOW_NEWLINE = 1 << 12, SLF_HEX = 1 << 13
}
 VarTypes is the general bitmasked magic type that tells us certain characteristics about the variable it refers to. More...
 
enum  SaveLoadType : byte {
  SL_VAR = 0, SL_REF = 1, SL_ARR = 2, SL_STR = 3,
  SL_LST = 4, SL_DEQUE = 5, SL_STDSTR = 6, SL_WRITEBYTE = 8,
  SL_VEH_INCLUDE = 9, SL_ST_INCLUDE = 10, SL_END = 15
}
 Type of data saved. More...
 

Functions

void GenerateDefaultSaveName (char *buf, const char *last)
 Fill the buffer with the default name for a savegame or screenshot. More...
 
void SetSaveLoadError (StringID str)
 Set the error message from outside of the actual loading/saving of the game (AfterLoadGame and friends)
 
const char * GetSaveLoadErrorString ()
 Get the string representation of the error message.
 
SaveOrLoadResult SaveOrLoad (const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded=true)
 Main Save or Load function where the high-level saveload functions are handled. More...
 
void WaitTillSaved ()
 
void ProcessAsyncSaveFinish ()
 Handle async save finishes.
 
void DoExitSave ()
 Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
 
SaveOrLoadResult SaveWithFilter (struct SaveFilter *writer, bool threaded)
 Save the game using a (writer) filter. More...
 
SaveOrLoadResult LoadWithFilter (struct LoadFilter *reader)
 Load the game using a (reader) filter. More...
 
static bool IsSavegameVersionBefore (SaveLoadVersion major, byte minor=0)
 Checks whether the savegame is below major. More...
 
static bool IsSavegameVersionUntil (SaveLoadVersion major)
 Checks whether the savegame is below or at major. More...
 
static bool SlIsObjectCurrentlyValid (SaveLoadVersion version_from, SaveLoadVersion version_to)
 Checks if some version from/to combination falls within the range of the active savegame version. More...
 
static VarType GetVarMemType (VarType type)
 Get the NumberType of a setting. More...
 
static VarType GetVarFileType (VarType type)
 Get the FileType of a setting. More...
 
static bool IsNumericType (VarType conv)
 Check if the given saveload type is a numeric type. More...
 
static void * GetVariableAddress (const void *object, const SaveLoad *sld)
 Get the address of the variable. More...
 
int64 ReadValue (const void *ptr, VarType conv)
 Return a signed-long version of the value of a setting. More...
 
void WriteValue (void *ptr, VarType conv, int64 val)
 Write the value of a setting. More...
 
void SlSetArrayIndex (uint index)
 
int SlIterateArray ()
 Iterate through the elements of an array and read the whole thing. More...
 
void SlAutolength (AutolengthProc *proc, void *arg)
 Do something of which I have no idea what it is :P. More...
 
size_t SlGetFieldLength ()
 Get the length of the current object.
 
void SlSetLength (size_t length)
 Sets the length of either a RIFF object or the number of items in an array. More...
 
size_t SlCalcObjMemberLength (const void *object, const SaveLoad *sld)
 
size_t SlCalcObjLength (const void *object, const SaveLoad *sld)
 Calculate the size of an object. More...
 
byte SlReadByte ()
 Wrapper for reading a byte from the buffer. More...
 
void SlWriteByte (byte b)
 Wrapper for writing a byte to the dumper. More...
 
void SlGlobList (const SaveLoadGlobVarList *sldg)
 Save or Load (a list of) global variables. More...
 
void SlArray (void *array, size_t length, VarType conv)
 Save/Load an array. More...
 
void SlObject (void *object, const SaveLoad *sld)
 Main SaveLoad function. More...
 
bool SlObjectMember (void *object, const SaveLoad *sld)
 
void NORETURN SlError (StringID string, const char *extra_msg=nullptr)
 Error handler. More...
 
void NORETURN SlErrorCorrupt (const char *msg)
 Error handler for corrupt savegames. More...
 
void NORETURN SlErrorCorruptFmt (const char *format,...) WARN_FORMAT(1
 
void NORETURN bool SaveloadCrashWithMissingNewGRFs ()
 Did loading the savegame cause a crash? If so, were NewGRFs missing? More...
 
static void SlSkipBytes (size_t length)
 Read in bytes from the file/data structure but don't do anything with them, discarding them in effect. More...
 

Variables

FileToSaveLoad _file_to_saveload
 File to save or load in the openttd loop.
 
char _savegame_format [8]
 how to compress savegames
 
bool _do_autosave
 are we doing an autosave at the moment?
 

Detailed Description

Functions/types related to saving and loading games.

Definition in file saveload.h.

Macro Definition Documentation

◆ SLE_ARR

#define SLE_ARR (   base,
  variable,
  type,
  length 
)    SLE_CONDARR(base, variable, type, length, SL_MIN_VERSION, SL_MAX_VERSION)

Storage of an array in every version of a savegame.

Parameters
baseName of the class or struct containing the array.
variableName of the variable in the class or struct referenced by base.
typeStorage of the data in memory and in the savegame.
lengthNumber of elements in the array.

Definition at line 638 of file saveload.h.

◆ SLE_CONDARR

#define SLE_CONDARR (   base,
  variable,
  type,
  length,
  from,
  to 
)    SLE_GENERAL(SL_ARR, base, variable, type, length, from, to, 0)

Storage of an array in some savegame versions.

Parameters
baseName of the class or struct containing the array.
variableName of the variable in the class or struct referenced by base.
typeStorage of the data in memory and in the savegame.
lengthNumber of elements in the array.
fromFirst savegame version that has the array.
toLast savegame version that has the array.

Definition at line 572 of file saveload.h.

◆ SLE_CONDDEQUE

#define SLE_CONDDEQUE (   base,
  variable,
  type,
  from,
  to 
)    SLE_GENERAL(SL_DEQUE, base, variable, type, 0, from, to, 0)

Storage of a deque in some savegame versions.

Parameters
baseName of the class or struct containing the list.
variableName of the variable in the class or struct referenced by base.
typeStorage of the data in memory and in the savegame.
fromFirst savegame version that has the list.
toLast savegame version that has the list.

Definition at line 613 of file saveload.h.

◆ SLE_CONDLST

#define SLE_CONDLST (   base,
  variable,
  type,
  from,
  to 
)    SLE_GENERAL(SL_LST, base, variable, type, 0, from, to, 0)

Storage of a list in some savegame versions.

Parameters
baseName of the class or struct containing the list.
variableName of the variable in the class or struct referenced by base.
typeStorage of the data in memory and in the savegame.
fromFirst savegame version that has the list.
toLast savegame version that has the list.

Definition at line 603 of file saveload.h.

◆ SLE_CONDNULL

#define SLE_CONDNULL (   length,
  from,
  to 
)    {SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, 0, nullptr, 0}

Empty space in some savegame versions.

Parameters
lengthLength of the empty space.
fromFirst savegame version that has the empty space.
toLast savegame version that has the empty space.

Definition at line 677 of file saveload.h.

◆ SLE_CONDREF

#define SLE_CONDREF (   base,
  variable,
  type,
  from,
  to 
)    SLE_GENERAL(SL_REF, base, variable, type, 0, from, to, 0)

Storage of a reference in some savegame versions.

Parameters
baseName of the class or struct containing the variable.
variableName of the variable in the class or struct referenced by base.
typeType of the reference, a value from SLRefType.
fromFirst savegame version that has the field.
toLast savegame version that has the field.

Definition at line 561 of file saveload.h.

◆ SLE_CONDSSTR

#define SLE_CONDSSTR (   base,
  variable,
  type,
  from,
  to 
)    SLE_GENERAL(SL_STDSTR, base, variable, type, 0, from, to, 0)

Storage of a std::string in some savegame versions.

Parameters
baseName of the class or struct containing the string.
variableName of the variable in the class or struct referenced by base.
typeStorage of the data in memory and in the savegame.
fromFirst savegame version that has the string.
toLast savegame version that has the string.

Definition at line 593 of file saveload.h.

◆ SLE_CONDSTR

#define SLE_CONDSTR (   base,
  variable,
  type,
  length,
  from,
  to 
)    SLE_GENERAL(SL_STR, base, variable, type, length, from, to, 0)

Storage of a string in some savegame versions.

Parameters
baseName of the class or struct containing the string.
variableName of the variable in the class or struct referenced by base.
typeStorage of the data in memory and in the savegame.
lengthNumber of elements in the string (only used for fixed size buffers).
fromFirst savegame version that has the string.
toLast savegame version that has the string.

Definition at line 583 of file saveload.h.

◆ SLE_CONDVAR

#define SLE_CONDVAR (   base,
  variable,
  type,
  from,
  to 
)    SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to, 0)

Storage of a variable in some savegame versions.

Parameters
baseName of the class or struct containing the variable.
variableName of the variable in the class or struct referenced by base.
typeStorage of the data in memory and in the savegame.
fromFirst savegame version that has the field.
toLast savegame version that has the field.

Definition at line 551 of file saveload.h.

◆ SLE_GENERAL

#define SLE_GENERAL (   cmd,
  base,
  variable,
  type,
  length,
  from,
  to,
  extra 
)    {cmd, type, length, from, to, cpp_sizeof(base, variable), [] (void *b, size_t) -> void * { assert(b != nullptr); return const_cast<void *>(static_cast<const void *>(std::addressof(static_cast<base *>(b)->variable))); }, extra}

Storage of simple variables, references (pointers), and arrays.

Parameters
cmdLoad/save type.
See also
SaveLoadType
Parameters
baseName of the class or struct containing the variable.
variableName of the variable in the class or struct referenced by base.
typeStorage of the data in memory and in the savegame.
fromFirst savegame version that has the field.
toLast savegame version that has the field.
extraExtra data to pass to the address callback function.
Note
In general, it is better to use one of the SLE_* macros below.

Definition at line 541 of file saveload.h.

◆ SLE_LST

#define SLE_LST (   base,
  variable,
  type 
)    SLE_CONDLST(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)

Storage of a list in every savegame version.

Parameters
baseName of the class or struct containing the list.
variableName of the variable in the class or struct referenced by base.
typeStorage of the data in memory and in the savegame.

Definition at line 663 of file saveload.h.

◆ SLE_NULL

#define SLE_NULL (   length)    SLE_CONDNULL(length, SL_MIN_VERSION, SL_MAX_VERSION)

Empty space in every savegame version.

Parameters
lengthLength of the empty space.

Definition at line 669 of file saveload.h.

◆ SLE_REF

#define SLE_REF (   base,
  variable,
  type 
)    SLE_CONDREF(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)

Storage of a reference in every version of a savegame.

Parameters
baseName of the class or struct containing the variable.
variableName of the variable in the class or struct referenced by base.
typeType of the reference, a value from SLRefType.

Definition at line 629 of file saveload.h.

◆ SLE_SSTR

#define SLE_SSTR (   base,
  variable,
  type 
)    SLE_CONDSSTR(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)

Storage of a std::string in every savegame version.

Parameters
baseName of the class or struct containing the string.
variableName of the variable in the class or struct referenced by base.
typeStorage of the data in memory and in the savegame.

Definition at line 655 of file saveload.h.

◆ SLE_STR

#define SLE_STR (   base,
  variable,
  type,
  length 
)    SLE_CONDSTR(base, variable, type, length, SL_MIN_VERSION, SL_MAX_VERSION)

Storage of a string in every savegame version.

Parameters
baseName of the class or struct containing the string.
variableName of the variable in the class or struct referenced by base.
typeStorage of the data in memory and in the savegame.
lengthNumber of elements in the string (only used for fixed size buffers).

Definition at line 647 of file saveload.h.

◆ SLE_VAR

#define SLE_VAR (   base,
  variable,
  type 
)    SLE_CONDVAR(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)

Storage of a variable in every version of a savegame.

Parameters
baseName of the class or struct containing the variable.
variableName of the variable in the class or struct referenced by base.
typeStorage of the data in memory and in the savegame.

Definition at line 621 of file saveload.h.

◆ SLEG_ARR

#define SLEG_ARR (   variable,
  type 
)    SLEG_CONDARR(variable, type, lengthof(variable), SL_MIN_VERSION, SL_MAX_VERSION)

Storage of a global array in every savegame version.

Parameters
variableName of the global variable.
typeStorage of the data in memory and in the savegame.

Definition at line 775 of file saveload.h.

◆ SLEG_CONDARR

#define SLEG_CONDARR (   variable,
  type,
  length,
  from,
  to 
)    SLEG_GENERAL(SL_ARR, variable, type, length, from, to, 0)

Storage of a global array in some savegame versions.

Parameters
variableName of the global variable.
typeStorage of the data in memory and in the savegame.
lengthNumber of elements in the array.
fromFirst savegame version that has the array.
toLast savegame version that has the array.

Definition at line 726 of file saveload.h.

◆ SLEG_CONDLST

#define SLEG_CONDLST (   variable,
  type,
  from,
  to 
)    SLEG_GENERAL(SL_LST, variable, type, 0, from, to, 0)

Storage of a global list in some savegame versions.

Parameters
variableName of the global variable.
typeStorage of the data in memory and in the savegame.
fromFirst savegame version that has the list.
toLast savegame version that has the list.

Definition at line 754 of file saveload.h.

◆ SLEG_CONDNULL

#define SLEG_CONDNULL (   length,
  from,
  to 
)    {SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, 0, nullptr, 0}

Empty global space in some savegame versions.

Parameters
lengthLength of the empty space.
fromFirst savegame version that has the empty space.
toLast savegame version that has the empty space.

Definition at line 804 of file saveload.h.

◆ SLEG_CONDREF

#define SLEG_CONDREF (   variable,
  type,
  from,
  to 
)    SLEG_GENERAL(SL_REF, variable, type, 0, from, to, 0)

Storage of a global reference in some savegame versions.

Parameters
variableName of the global variable.
typeStorage of the data in memory and in the savegame.
fromFirst savegame version that has the field.
toLast savegame version that has the field.

Definition at line 716 of file saveload.h.

◆ SLEG_CONDSSTR

#define SLEG_CONDSSTR (   variable,
  type,
  from,
  to 
)    SLEG_GENERAL(SL_STDSTR, variable, type, 0, from, to, 0)

Storage of a global std::string in some savegame versions.

Parameters
variableName of the global variable.
typeStorage of the data in memory and in the savegame.
fromFirst savegame version that has the string.
toLast savegame version that has the string.

Definition at line 745 of file saveload.h.

◆ SLEG_CONDSTR

#define SLEG_CONDSTR (   variable,
  type,
  length,
  from,
  to 
)    SLEG_GENERAL(SL_STR, variable, type, length, from, to, 0)

Storage of a global string in some savegame versions.

Parameters
variableName of the global variable.
typeStorage of the data in memory and in the savegame.
lengthNumber of elements in the string (only used for fixed size buffers).
fromFirst savegame version that has the string.
toLast savegame version that has the string.

Definition at line 736 of file saveload.h.

◆ SLEG_CONDVAR

#define SLEG_CONDVAR (   variable,
  type,
  from,
  to 
)    SLEG_GENERAL(SL_VAR, variable, type, 0, from, to, 0)

Storage of a global variable in some savegame versions.

Parameters
variableName of the global variable.
typeStorage of the data in memory and in the savegame.
fromFirst savegame version that has the field.
toLast savegame version that has the field.

Definition at line 707 of file saveload.h.

◆ SLEG_GENERAL

#define SLEG_GENERAL (   cmd,
  variable,
  type,
  length,
  from,
  to,
  extra 
)    {cmd, type, length, from, to, sizeof(variable), [] (void *, size_t) -> void * { return static_cast<void *>(std::addressof(variable)); }, extra}

Storage of global simple variables, references (pointers), and arrays.

Parameters
cmdLoad/save type.
See also
SaveLoadType
Parameters
variableName of the global variable.
typeStorage of the data in memory and in the savegame.
fromFirst savegame version that has the field.
toLast savegame version that has the field.
extraExtra data to pass to the address callback function.
Note
In general, it is better to use one of the SLEG_* macros below.

Definition at line 698 of file saveload.h.

◆ SLEG_LST

#define SLEG_LST (   variable,
  type 
)    SLEG_CONDLST(variable, type, SL_MIN_VERSION, SL_MAX_VERSION)

Storage of a global list in every savegame version.

Parameters
variableName of the global variable.
typeStorage of the data in memory and in the savegame.

Definition at line 796 of file saveload.h.

◆ SLEG_REF

#define SLEG_REF (   variable,
  type 
)    SLEG_CONDREF(variable, type, SL_MIN_VERSION, SL_MAX_VERSION)

Storage of a global reference in every savegame version.

Parameters
variableName of the global variable.
typeStorage of the data in memory and in the savegame.

Definition at line 768 of file saveload.h.

◆ SLEG_SSTR

#define SLEG_SSTR (   variable,
  type 
)    SLEG_CONDSSTR(variable, type, SL_MIN_VERSION, SL_MAX_VERSION)

Storage of a global std::string in every savegame version.

Parameters
variableName of the global variable.
typeStorage of the data in memory and in the savegame.

Definition at line 789 of file saveload.h.

◆ SLEG_STR

#define SLEG_STR (   variable,
  type 
)    SLEG_CONDSTR(variable, type, sizeof(variable), SL_MIN_VERSION, SL_MAX_VERSION)

Storage of a global string in every savegame version.

Parameters
variableName of the global variable.
typeStorage of the data in memory and in the savegame.

Definition at line 782 of file saveload.h.

◆ SLEG_VAR

#define SLEG_VAR (   variable,
  type 
)    SLEG_CONDVAR(variable, type, SL_MIN_VERSION, SL_MAX_VERSION)

Storage of a global variable in every savegame version.

Parameters
variableName of the global variable.
typeStorage of the data in memory and in the savegame.

Definition at line 761 of file saveload.h.

Enumeration Type Documentation

◆ ChunkType

enum ChunkType

Flags of a chunk.

Enumerator
CH_LAST 

Last chunk in this array.

Definition at line 405 of file saveload.h.

◆ SavegameType

Types of save games.

Enumerator
SGT_TTD 

TTD savegame (can be detected incorrectly)

SGT_TTDP1 

TTDP savegame ( -//- ) (data at NW border)

SGT_TTDP2 

TTDP savegame in new format (data at SE border)

SGT_OTTD 

OTTD savegame.

SGT_TTO 

TTO savegame.

SGT_INVALID 

broken savegame (used internally)

Definition at line 353 of file saveload.h.

◆ SaveLoadType

enum SaveLoadType : byte

Type of data saved.

Enumerator
SL_VAR 

Save/load a variable.

SL_REF 

Save/load a reference.

SL_ARR 

Save/load an array.

SL_STR 

Save/load a string.

SL_LST 

Save/load a list.

SL_DEQUE 

Save/load a deque.

SL_STDSTR 

Save/load a std::string.

Definition at line 498 of file saveload.h.

◆ SaveLoadVersion

enum SaveLoadVersion : uint16

SaveLoad versions Previous savegame versions, the trunk revision where they were introduced and the released version that had that particular savegame version.

Up to savegame version 18 there is a minor version as well.

Older entries keep their original numbering.

Newer entries should use a descriptive labels, numeric version and PR can be added to comment.

Note that this list must not be reordered.

Enumerator
SL_MIN_VERSION 

First savegame version.

SLV_1 

1.0 0.1.x, 0.2.x

SLV_2 

2.0 0.3.0 2.1 0.3.1, 0.3.2

SLV_3 

3.x lost

SLV_4 

4.0 1 4.1 122 0.3.3, 0.3.4 4.2 1222 0.3.5 4.3 1417 4.4 1426

SLV_5 

5.0 1429 5.1 1440 5.2 1525 0.3.6

SLV_6 

6.0 1721 6.1 1768

SLV_7 

7.0 1770

SLV_8 

8.0 1786

SLV_9 

9.0 1909

SLV_10 

10.0 2030

SLV_11 

11.0 2033 11.1 2041

SLV_12 

12.1 2046

SLV_13 

13.1 2080 0.4.0, 0.4.0.1

SLV_14 

14.0 2441

SLV_15 

15.0 2499

SLV_16 

16.0 2817 16.1 3155

SLV_17 

17.0 3212 17.1 3218

SLV_18 

18 3227

SLV_19 

19 3396

SLV_20 

20 3403

SLV_21 

21 3472 0.4.x

SLV_22 

22 3726

SLV_23 

23 3915

SLV_24 

24 4150

SLV_25 

25 4259

SLV_26 

26 4466

SLV_27 

27 4757

SLV_28 

28 4987

SLV_29 

29 5070

SLV_30 

30 5946

SLV_31 

31 5999

SLV_32 

32 6001

SLV_33 

33 6440

SLV_34 

34 6455

SLV_35 

35 6602

SLV_36 

36 6624

SLV_37 

37 7182

SLV_38 

38 7195

SLV_39 

39 7269

SLV_40 

40 7326

SLV_41 

41 7348 0.5.x

SLV_42 

42 7573

SLV_43 

43 7642

SLV_44 

44 8144

SLV_45 

45 8501

SLV_46 

46 8705

SLV_47 

47 8735

SLV_48 

48 8935

SLV_49 

49 8969

SLV_50 

50 8973

SLV_51 

51 8978

SLV_52 

52 9066

SLV_53 

53 9316

SLV_54 

54 9613

SLV_55 

55 9638

SLV_56 

56 9667

SLV_57 

57 9691

SLV_58 

58 9762

SLV_59 

59 9779

SLV_60 

60 9874

SLV_61 

61 9892

SLV_62 

62 9905

SLV_63 

63 9956

SLV_64 

64 10006

SLV_65 

65 10210

SLV_66 

66 10211

SLV_67 

67 10236

SLV_68 

68 10266

SLV_69 

69 10319

SLV_70 

70 10541

SLV_71 

71 10567

SLV_72 

72 10601

SLV_73 

73 10903

SLV_74 

74 11030

SLV_75 

75 11107

SLV_76 

76 11139

SLV_77 

77 11172

SLV_78 

78 11176

SLV_79 

79 11188

SLV_80 

80 11228

SLV_81 

81 11244

SLV_82 

82 11410

SLV_83 

83 11589

SLV_84 

84 11822

SLV_85 

85 11874

SLV_86 

86 12042

SLV_87 

87 12129

SLV_88 

88 12134

SLV_89 

89 12160

SLV_90 

90 12293

SLV_91 

91 12347

SLV_92 

92 12381 0.6.x

SLV_93 

93 12648

SLV_94 

94 12816

SLV_95 

95 12924

SLV_96 

96 13226

SLV_97 

97 13256

SLV_98 

98 13375

SLV_99 

99 13838

SLV_100 

100 13952

SLV_101 

101 14233

SLV_102 

102 14332

SLV_103 

103 14598

SLV_104 

104 14735

SLV_105 

105 14803

SLV_106 

106 14919

SLV_107 

107 15027

SLV_108 

108 15045

SLV_109 

109 15075

SLV_110 

110 15148

SLV_111 

111 15190

SLV_112 

112 15290

SLV_113 

113 15340

SLV_114 

114 15601

SLV_115 

115 15695

SLV_116 

116 15893 0.7.x

SLV_117 

117 16037

SLV_118 

118 16129

SLV_119 

119 16242

SLV_120 

120 16439

SLV_121 

121 16694

SLV_122 

122 16855

SLV_123 

123 16909

SLV_124 

124 16993

SLV_125 

125 17113

SLV_126 

126 17433

SLV_127 

127 17439

SLV_128 

128 18281

SLV_129 

129 18292

SLV_130 

130 18404

SLV_131 

131 18481

SLV_132 

132 18522

SLV_133 

133 18674

SLV_134 

134 18703

SLV_135 

135 18719

SLV_136 

136 18764

SLV_137 

137 18912

SLV_138 

138 18942 1.0.x

SLV_139 

139 19346

SLV_140 

140 19382

SLV_141 

141 19799

SLV_142 

142 20003

SLV_143 

143 20048

SLV_144 

144 20334

SLV_145 

145 20376

SLV_146 

146 20446

SLV_147 

147 20621

SLV_148 

148 20659

SLV_149 

149 20832

SLV_150 

150 20857

SLV_151 

151 20918

SLV_152 

152 21171

SLV_153 

153 21263

SLV_154 

154 21426

SLV_155 

155 21453

SLV_156 

156 21728

SLV_157 

157 21862

SLV_158 

158 21933

SLV_159 

159 21962

SLV_160 

160 21974 1.1.x

SLV_161 

161 22567

SLV_162 

162 22713

SLV_163 

163 22767

SLV_164 

164 23290

SLV_165 

165 23304

SLV_166 

166 23415

SLV_167 

167 23504

SLV_168 

168 23637

SLV_169 

169 23816

SLV_170 

170 23826

SLV_171 

171 23835

SLV_172 

172 23947

SLV_173 

173 23967 1.2.0-RC1

SLV_174 

174 23973 1.2.x

SLV_175 

175 24136

SLV_176 

176 24446

SLV_177 

177 24619

SLV_178 

178 24789

SLV_179 

179 24810

SLV_180 

180 24998 1.3.x

SLV_181 

181 25012

SLV_182 

182 25115 FS#5492, r25259, r25296 Goal status

SLV_183 

183 25363 Cargodist

SLV_184 

184 25508 Unit localisation split

SLV_185 

185 25620 Storybooks

SLV_186 

186 25833 Objects storage

SLV_187 

187 25899 Linkgraph - restricted flows

SLV_188 

188 26169 v1.4 FS#5831 Unify RV travel time

SLV_189 

189 26450 Hierarchical vehicle subgroups

SLV_190 

190 26547 Separate order travel and wait times

SLV_191 

191 26636 FS#6026 Fix disaster vehicle storage (No bump) 191 26646 FS#6041 Linkgraph - store locations

SLV_192 

192 26700 FS#6066 Fix saving of order backups

SLV_193 

193 26802

SLV_194 

194 26881 v1.5

SLV_195 

195 27572 v1.6.1

SLV_196 

196 27778 v1.7

SLV_197 

197 27978 v1.8

SLV_198 

198 PR#6763 Switch town growth rate and counter to actual game ticks

SLV_EXTEND_CARGOTYPES 

199 PR#6802 Extend cargotypes to 64

SLV_EXTEND_RAILTYPES 

200 PR#6805 Extend railtypes to 64, adding uint16 to map array.

SLV_EXTEND_PERSISTENT_STORAGE 

201 PR#6885 Extend NewGRF persistent storages.

SLV_EXTEND_INDUSTRY_CARGO_SLOTS 

202 PR#6867 Increase industry cargo slots to 16 in, 16 out

SLV_SHIP_PATH_CACHE 

203 PR#7072 Add path cache for ships

SLV_SHIP_ROTATION 

204 PR#7065 Add extra rotation stages for ships.

SLV_GROUP_LIVERIES 

205 PR#7108 Livery storage change and group liveries.

SLV_SHIPS_STOP_IN_LOCKS 

206 PR#7150 Ship/lock movement changes.

SLV_FIX_CARGO_MONITOR 

207 PR#7175 v1.9 Cargo monitor data packing fix to support 64 cargotypes.

SLV_TOWN_CARGOGEN 

208 PR#6965 New algorithms for town building cargo generation.

SLV_SHIP_CURVE_PENALTY 

209 PR#7289 Configurable ship curve penalties.

SLV_SERVE_NEUTRAL_INDUSTRIES 

210 PR#7234 Company stations can serve industries with attached neutral stations.

SLV_ROADVEH_PATH_CACHE 

211 PR#7261 Add path cache for road vehicles.

SLV_REMOVE_OPF 

212 PR#7245 Remove OPF.

SLV_TREES_WATER_CLASS 

213 PR#7405 WaterClass update for tree tiles.

SLV_ROAD_TYPES 

214 PR#6811 NewGRF road types.

SLV_SCRIPT_MEMLIMIT 

215 PR#7516 Limit on AI/GS memory consumption.

SLV_MULTITILE_DOCKS 

216 PR#7380 Multiple docks per station.

SLV_TRADING_AGE 

217 PR#7780 Configurable company trading age.

SLV_ENDING_YEAR 

218 PR#7747 v1.10 Configurable ending year.

SLV_REMOVE_TOWN_CARGO_CACHE 

219 PR#8258 Remove town cargo acceptance and production caches.

SLV_START_PATCHPACKS 

220 First known patchpack to use a version just above ours.

SLV_END_PATCHPACKS 

286 Last known patchpack to use a version just above ours.

SLV_GS_INDUSTRY_CONTROL 

287 PR#7912 and PR#8115 GS industry control.

SLV_VEH_MOTION_COUNTER 

288 PR#8591 Desync safe motion counter

SLV_INDUSTRY_TEXT 

289 PR#8576 Additional GS text for industries.

SL_MAX_VERSION 

Highest possible saveload version.

Definition at line 30 of file saveload.h.

◆ SaveOrLoadResult

Save or load result codes.

Enumerator
SL_OK 

completed successfully

SL_ERROR 

error that was caught before internal structures were modified

SL_REINIT 

error that was caught in the middle of updating game state, need to clear it. (can only happen during load)

Definition at line 332 of file saveload.h.

◆ SLRefType

enum SLRefType

Type of reference (SLE_REF, SLE_CONDREF).

Enumerator
REF_ORDER 

Load/save a reference to an order.

REF_VEHICLE 

Load/save a reference to a vehicle.

REF_STATION 

Load/save a reference to a station.

REF_TOWN 

Load/save a reference to a town.

REF_VEHICLE_OLD 

Load/save an old-style reference to a vehicle (for pre-4.4 savegames).

REF_ROADSTOPS 

Load/save a reference to a bus/truck stop.

REF_ENGINE_RENEWS 

Load/save a reference to an engine renewal (autoreplace).

REF_CARGO_PACKET 

Load/save a reference to a cargo packet.

REF_ORDERLIST 

Load/save a reference to an orderlist.

REF_STORAGE 

Load/save a reference to a persistent storage.

REF_LINK_GRAPH 

Load/save a reference to a link graph.

REF_LINK_GRAPH_JOB 

Load/save a reference to a link graph job.

Definition at line 389 of file saveload.h.

◆ VarTypes

enum VarTypes

VarTypes is the general bitmasked magic type that tells us certain characteristics about the variable it refers to.

For example SLE_FILE_* gives the size(type) as it would be in the savegame and SLE_VAR_* the size(type) as it is in memory during runtime. These are the first 8 bits (0-3 SLE_FILE, 4-7 SLE_VAR). Bits 8-15 are reserved for various flags as explained below

Enumerator
SLE_FILE_STRINGID 

StringID offset into strings-array.

SLE_VAR_NULL 

useful to write zeros in savegame.

SLE_VAR_STRB 

string (with pre-allocated buffer)

SLE_VAR_STRBQ 

string enclosed in quotes (with pre-allocated buffer)

SLE_VAR_STR 

string pointer

SLE_VAR_STRQ 

string pointer enclosed in quotes

SLE_VAR_NAME 

old custom name to be converted to a char pointer

SLF_NOT_IN_SAVE 

do not save with savegame, basically client-based

SLF_NOT_IN_CONFIG 

do not save to config file

SLF_NO_NETWORK_SYNC 

do not synchronize over network (but it is saved if SLF_NOT_IN_SAVE is not set)

SLF_ALLOW_CONTROL 

allow control codes in the strings

SLF_ALLOW_NEWLINE 

allow new lines in the strings

SLF_HEX 

print numbers as hex in the config file (only useful for unsigned)

Definition at line 421 of file saveload.h.

Function Documentation

◆ GenerateDefaultSaveName()

void GenerateDefaultSaveName ( char *  buf,
const char *  last 
)

◆ GetVarFileType()

static VarType GetVarFileType ( VarType  type)
inlinestatic

Get the FileType of a setting.

This describes the integer type as it is represented in a savegame/file

Parameters
typeVarType holding information about the file-type
Returns
the SLE_FILE_* part of a variable-type description

Definition at line 867 of file saveload.h.

◆ GetVariableAddress()

static void* GetVariableAddress ( const void *  object,
const SaveLoad sld 
)
inlinestatic

Get the address of the variable.

Null-variables don't have an address, everything else has a callback function that returns the address based on the saveload data and the current object for non-globals.

Definition at line 887 of file saveload.h.

References SaveLoad::address_proc, SaveLoad::conv, SaveLoad::extra_data, GetVarMemType(), and SLE_VAR_NULL.

Referenced by CmdChangeCompanySetting(), NewsTypeData::GetDisplay(), HandleOldDiffCustom(), IConsoleGetSetting(), and SetSettingValue().

◆ GetVarMemType()

static VarType GetVarMemType ( VarType  type)
inlinestatic

Get the NumberType of a setting.

This describes the integer type as it is represented in memory

Parameters
typeVarType holding information about the variable-type
Returns
the SLE_VAR_* part of a variable-type description

Definition at line 856 of file saveload.h.

Referenced by GetVariableAddress(), IsNumericType(), IsVariableSizeRight(), MakeIntList(), ReadValue(), SetSettingValue(), SlCalcDequeLen(), SlCalcStringLen(), SlDeque(), SlString(), Write_ValidateSetting(), and WriteValue().

◆ IsNumericType()

static bool IsNumericType ( VarType  conv)
inlinestatic

Check if the given saveload type is a numeric type.

Parameters
convthe type to check
Returns
True if it's a numeric type.

Definition at line 877 of file saveload.h.

References GetVarMemType().

◆ IsSavegameVersionBefore()

static bool IsSavegameVersionBefore ( SaveLoadVersion  major,
byte  minor = 0 
)
inlinestatic

Checks whether the savegame is below major.

minor.

Parameters
majorMajor number of the version to check against.
minorMinor number of the version to check against. If minor is 0 or not specified, only the major number is checked.
Returns
Savegame version is earlier than the specified version.

Definition at line 815 of file saveload.h.

References _sl_minor_version, and _sl_version.

Referenced by CargoPacket::AfterLoad(), AfterLoadLinkGraphs(), AfterLoadStoryBook(), Order::ConvertFromOldSavegame(), HandleOldDiffCustom(), IntToReference(), Load_ANIT(), Load_CAPR(), Load_PRIC(), Load_SIGN(), LoadDelivery(), LoadPickup(), MoveWaypointsToBaseStations(), Ptrs_TOWN(), SaveLoad_LinkGraph(), SlCalcListLen(), and SlCalcRefLen().

◆ IsSavegameVersionUntil()

static bool IsSavegameVersionUntil ( SaveLoadVersion  major)
inlinestatic

Checks whether the savegame is below or at major.

This should be used to repair data from existing savegames which is no longer corrupted in new savegames, but for which otherwise no savegame bump is required.

Parameters
majorMajor number of the version to check against.
Returns
Savegame version is at most the specified version.

Definition at line 829 of file saveload.h.

References _sl_version.

◆ LoadWithFilter()

SaveOrLoadResult LoadWithFilter ( LoadFilter reader)

Load the game using a (reader) filter.

Parameters
readerThe filter to read the savegame from.
Returns
Return the result of the action. SL_OK or SL_REINIT ("unload" the game)

Definition at line 2744 of file saveload.cpp.

References _sl, SaveLoadParams::action, ClearSaveLoadState(), DoLoad(), SL_REINIT, and SLA_LOAD.

◆ ReadValue()

int64 ReadValue ( const void *  ptr,
VarType  conv 
)

Return a signed-long version of the value of a setting.

Parameters
ptrpointer to the variable
convtype of variable, can be a non-clean type, eg one with other flags because it is parsed
Returns
returns the value of the pointer-setting

Definition at line 749 of file saveload.cpp.

References GetVarMemType().

Referenced by NewsTypeData::GetDisplay().

◆ SaveloadCrashWithMissingNewGRFs()

void NORETURN bool SaveloadCrashWithMissingNewGRFs ( )

Did loading the savegame cause a crash? If so, were NewGRFs missing?

Returns
when the saveload crashed due to missing NewGRFs.

Definition at line 364 of file afterload.cpp.

References _saveload_crash_with_missing_newgrfs.

Referenced by HandleCrash().

◆ SaveOrLoad()

SaveOrLoadResult SaveOrLoad ( const std::string &  filename,
SaveLoadOperation  fop,
DetailedFileType  dft,
Subdirectory  sb,
bool  threaded 
)

Main Save or Load function where the high-level saveload functions are handled.

It opens the savegame, selects format and checks versions

Parameters
filenameThe name of the savegame being created/loaded
fopSave or load mode. Load can also be a TTD(Patch) game.
sbThe sub directory to save the savegame in
threadedTrue when threaded saving is allowed
Returns
Return the result of the action. SL_OK, SL_ERROR, or SL_REINIT ("unload" the game)

Definition at line 2764 of file saveload.cpp.

References _do_autosave, _sl, DFT_GAME_FILE, INVALID_STRING_ID, SaveLoadParams::saveinprogress, ShowErrorMessage(), SL_OK, SLO_SAVE, and WL_ERROR.

Referenced by ClientNetworkEmergencySave(), DEF_CONSOLE_CMD(), DoExitSave(), and CrashLog::WriteSavegame().

◆ SaveWithFilter()

SaveOrLoadResult SaveWithFilter ( SaveFilter writer,
bool  threaded 
)

Save the game using a (writer) filter.

Parameters
writerThe filter to write the savegame to.
threadedWhether to try to perform the saving asynchronously.
Returns
Return the result of the action. SL_OK or SL_ERROR

Definition at line 2586 of file saveload.cpp.

References _sl, SaveLoadParams::action, ClearSaveLoadState(), DoSave(), SL_ERROR, and SLA_SAVE.

◆ SlArray()

void SlArray ( void *  array,
size_t  length,
VarType  conv 
)

Save/Load an array.

Parameters
arrayThe array being manipulated
lengthThe length of the array in elements
convVarType type of the atomic array (int, byte, uint64, etc.)

Definition at line 1051 of file saveload.cpp.

References _sl, _sl_version, SaveLoadParams::action, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SLA_NULL, SLA_PTRS, SLA_SAVE, SlCalcArrayLen(), and SlSetLength().

Referenced by Load_ANIT(), Load_NAME(), ScriptInstance::LoadObjects(), Save_ANIT(), and ScriptInstance::SaveObject().

◆ SlAutolength()

void SlAutolength ( AutolengthProc *  proc,
void *  arg 
)

Do something of which I have no idea what it is :P.

Parameters
procThe callback procedure that is called
argThe variable that will be used for the callback procedure

Definition at line 1640 of file saveload.cpp.

◆ SlCalcObjLength()

size_t SlCalcObjLength ( const void *  object,
const SaveLoad sld 
)

Calculate the size of an object.

Parameters
objectto be measured
sldThe SaveLoad description of the object so we know how to manipulate it
Returns
size of given object

Definition at line 1436 of file saveload.cpp.

References SaveLoad::cmd.

Referenced by SlObject().

◆ SlError()

void NORETURN SlError ( StringID  string,
const char *  extra_msg 
)

Error handler.

Sets everything up to show an error message and to clean up the mess of a partial savegame load.

Parameters
stringThe translatable error message to show.
extra_msgAn extra error message coming from one of the APIs.
Note
This function does never return as it throws an exception to break out of all the saveload code.

Definition at line 326 of file saveload.cpp.

References _load_check_data, _sl, SaveLoadParams::action, LoadCheckData::error, LoadCheckData::error_data, SaveLoadParams::error_str, SaveLoadParams::extra_msg, free(), SLA_LOAD, SLA_LOAD_CHECK, SLA_PTRS, SlNullPointers(), and stredup().

Referenced by DoLoad(), PacketWriter::Finish(), LZMALoadFilter::LZMALoadFilter(), LZMASaveFilter::LZMASaveFilter(), LZOLoadFilter::LZOLoadFilter(), LZOSaveFilter::LZOSaveFilter(), LZMALoadFilter::Read(), SlErrorCorrupt(), PacketWriter::Write(), FileWriter::Write(), ZlibSaveFilter::WriteLoop(), LZMASaveFilter::WriteLoop(), and ZlibSaveFilter::ZlibSaveFilter().

◆ SlErrorCorrupt()

void NORETURN SlErrorCorrupt ( const char *  msg)

Error handler for corrupt savegames.

Sets everything up to show the error message and to clean up the mess of a partial savegame load.

Parameters
msgLocation the corruption has been spotted.
Note
This function does never return as it throws an exception to break out of all the saveload code.

Definition at line 358 of file saveload.cpp.

References SlError().

Referenced by IntToReference(), Load_CHTS(), Load_ITBL(), Load_NAME(), Load_NewGRFMapping(), SetWaterClassDependingOnSurroundings(), SlErrorCorruptFmt(), and SlReadSimpleGamma().

◆ SlGlobList()

void SlGlobList ( const SaveLoadGlobVarList sldg)

Save or Load (a list of) global variables.

Parameters
sldgThe global variable that is being loaded or saved

Definition at line 1630 of file saveload.cpp.

References SlObject().

Referenced by LoadSave_IBLD().

◆ SlIsObjectCurrentlyValid()

static bool SlIsObjectCurrentlyValid ( SaveLoadVersion  version_from,
SaveLoadVersion  version_to 
)
inlinestatic

Checks if some version from/to combination falls within the range of the active savegame version.

Parameters
version_fromInclusive savegame version lower bound.
version_toExclusive savegame version upper bound. SL_MAX_VERSION if no upper bound.
Returns
Active savegame version falls within the given range.

Definition at line 842 of file saveload.h.

References SAVEGAME_VERSION.

Referenced by HandleOldDiffCustom().

◆ SlIterateArray()

int SlIterateArray ( )

Iterate through the elements of an array and read the whole thing.

Returns
The index of the object, or -1 if we have reached the end of current block

Definition at line 631 of file saveload.cpp.

Referenced by Load_CAPA(), Load_ITBL(), Load_LGRJ(), Load_LGRP(), Load_NAME(), Load_NewGRFMapping(), Load_PSAC(), Load_SIGN(), LoadDelivery(), LoadPickup(), and SlSkipArray().

◆ SlObject()

◆ SlReadByte()

byte SlReadByte ( )

Wrapper for reading a byte from the buffer.

Returns
The read byte.

Definition at line 418 of file saveload.cpp.

References _sl, and SaveLoadParams::reader.

Referenced by Load_CHTS(), SlCopyBytes(), SlLoadCheckChunk(), SlLoadChunk(), SlReadSimpleGamma(), and SlSkipBytes().

◆ SlSetLength()

void SlSetLength ( size_t  length)

Sets the length of either a RIFF object or the number of items in an array.

This lets us load an object or an array of arbitrary size

Parameters
lengthThe length of the sought object/array

Definition at line 676 of file saveload.cpp.

References _sl, SaveLoadParams::action, SaveLoadParams::block_mode, SaveLoadParams::need_length, NL_NONE, NL_WANTLENGTH, and SLA_SAVE.

Referenced by Save_ANIT(), Save_CHTS(), SlArray(), SlList(), and SlObject().

◆ SlSkipBytes()

static void SlSkipBytes ( size_t  length)
inlinestatic

Read in bytes from the file/data structure but don't do anything with them, discarding them in effect.

Parameters
lengthThe amount of bytes that is being treated this way

Definition at line 930 of file saveload.h.

References SlReadByte().

Referenced by SlSkipArray(), and SlSkipVariableOnLoad().

◆ SlWriteByte()

void SlWriteByte ( byte  b)

Wrapper for writing a byte to the dumper.

Parameters
bThe byte to write.

Definition at line 427 of file saveload.cpp.

References _sl, SaveLoadParams::dumper, and MemoryDumper::WriteByte().

Referenced by Save_CHTS(), and SlCopyBytes().

◆ WriteValue()

void WriteValue ( void *  ptr,
VarType  conv,
int64  val 
)

Write the value of a setting.

Parameters
ptrpointer to the variable
convtype of variable, can be a non-clean type, eg with other flags. It is parsed upon read
valthe new value being given to the variable

Definition at line 773 of file saveload.cpp.

References GetVarMemType().