15 #include "../fileio_type.h" 16 #include "../strings_type.h" 62 typedef void ChunkSaveLoadProc();
63 typedef void AutolengthProc(
void *arg);
68 ChunkSaveLoadProc *save_proc;
69 ChunkSaveLoadProc *load_proc;
70 ChunkSaveLoadProc *ptrs_proc;
71 ChunkSaveLoadProc *load_check_proc;
96 #define SL_MAX_VERSION UINT16_MAX 134 SLE_VAR_I16 = 3 << 4,
135 SLE_VAR_U16 = 4 << 4,
136 SLE_VAR_I32 = 5 << 4,
137 SLE_VAR_U32 = 6 << 4,
138 SLE_VAR_I64 = 7 << 4,
139 SLE_VAR_U64 = 8 << 4,
149 SLE_VAR_CHAR = SLE_VAR_I8,
154 SLE_BOOL = SLE_FILE_I8 | SLE_VAR_BL,
155 SLE_INT8 = SLE_FILE_I8 | SLE_VAR_I8,
156 SLE_UINT8 = SLE_FILE_U8 | SLE_VAR_U8,
157 SLE_INT16 = SLE_FILE_I16 | SLE_VAR_I16,
158 SLE_UINT16 = SLE_FILE_U16 | SLE_VAR_U16,
159 SLE_INT32 = SLE_FILE_I32 | SLE_VAR_I32,
160 SLE_UINT32 = SLE_FILE_U32 | SLE_VAR_U32,
161 SLE_INT64 = SLE_FILE_I64 | SLE_VAR_I64,
162 SLE_UINT64 = SLE_FILE_U64 | SLE_VAR_U64,
163 SLE_CHAR = SLE_FILE_I8 | SLE_VAR_CHAR,
172 SLE_UINT = SLE_UINT32,
174 SLE_STRB = SLE_STRINGBUF,
175 SLE_STRBQ = SLE_STRINGBQUOTE,
177 SLE_STRQ = SLE_STRINGQUOTE,
189 typedef uint32 VarType;
236 #define SLE_GENERAL(cmd, base, variable, type, length, from, to) {false, cmd, type, length, from, to, (void*)cpp_offsetof(base, variable), cpp_sizeof(base, variable)} 246 #define SLE_CONDVAR(base, variable, type, from, to) SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to) 256 #define SLE_CONDREF(base, variable, type, from, to) SLE_GENERAL(SL_REF, base, variable, type, 0, from, to) 267 #define SLE_CONDARR(base, variable, type, length, from, to) SLE_GENERAL(SL_ARR, base, variable, type, length, from, to) 278 #define SLE_CONDSTR(base, variable, type, length, from, to) SLE_GENERAL(SL_STR, base, variable, type, length, from, to) 288 #define SLE_CONDLST(base, variable, type, from, to) SLE_GENERAL(SL_LST, base, variable, type, 0, from, to) 296 #define SLE_VAR(base, variable, type) SLE_CONDVAR(base, variable, type, 0, SL_MAX_VERSION) 304 #define SLE_REF(base, variable, type) SLE_CONDREF(base, variable, type, 0, SL_MAX_VERSION) 313 #define SLE_ARR(base, variable, type, length) SLE_CONDARR(base, variable, type, length, 0, SL_MAX_VERSION) 322 #define SLE_STR(base, variable, type, length) SLE_CONDSTR(base, variable, type, length, 0, SL_MAX_VERSION) 330 #define SLE_LST(base, variable, type) SLE_CONDLST(base, variable, type, 0, SL_MAX_VERSION) 336 #define SLE_NULL(length) SLE_CONDNULL(length, 0, SL_MAX_VERSION) 344 #define SLE_CONDNULL(length, from, to) SLE_CONDARR(NullStruct, null, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to) 347 #define SLE_WRITEBYTE(base, variable, value) SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, value, value) 349 #define SLE_VEH_INCLUDE() {false, SL_VEH_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL, 0} 350 #define SLE_ST_INCLUDE() {false, SL_ST_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL, 0} 353 #define SLE_END() {false, SL_END, 0, 0, 0, 0, NULL, 0} 364 #define SLEG_GENERAL(cmd, variable, type, length, from, to) {true, cmd, type, length, from, to, (void*)&variable, sizeof(variable)} 373 #define SLEG_CONDVAR(variable, type, from, to) SLEG_GENERAL(SL_VAR, variable, type, 0, from, to) 382 #define SLEG_CONDREF(variable, type, from, to) SLEG_GENERAL(SL_REF, variable, type, 0, from, to) 392 #define SLEG_CONDARR(variable, type, length, from, to) SLEG_GENERAL(SL_ARR, variable, type, length, from, to) 402 #define SLEG_CONDSTR(variable, type, length, from, to) SLEG_GENERAL(SL_STR, variable, type, length, from, to) 411 #define SLEG_CONDLST(variable, type, from, to) SLEG_GENERAL(SL_LST, variable, type, 0, from, to) 418 #define SLEG_VAR(variable, type) SLEG_CONDVAR(variable, type, 0, SL_MAX_VERSION) 425 #define SLEG_REF(variable, type) SLEG_CONDREF(variable, type, 0, SL_MAX_VERSION) 432 #define SLEG_ARR(variable, type) SLEG_CONDARR(variable, type, lengthof(variable), 0, SL_MAX_VERSION) 439 #define SLEG_STR(variable, type) SLEG_CONDSTR(variable, type, lengthof(variable), 0, SL_MAX_VERSION) 446 #define SLEG_LST(variable, type) SLEG_CONDLST(variable, type, 0, SL_MAX_VERSION) 454 #define SLEG_CONDNULL(length, from, to) {true, SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, (void*)NULL} 457 #define SLEG_END() {true, SL_END, 0, 0, 0, 0, NULL, 0} 469 return _sl_version < major || (minor > 0 && _sl_version == major && _sl_minor_version < minor);
482 if (SAVEGAME_VERSION < version_from || SAVEGAME_VERSION > version_to)
return false;
527 return const_cast<byte *
>((
const byte*)(sld->
global ? NULL :
object) + (ptrdiff_t)sld->
address);
530 int64
ReadValue(
const void *ptr, VarType conv);
531 void WriteValue(
void *ptr, VarType conv, int64 val);
533 void SlSetArrayIndex(uint index);
539 size_t SlCalcObjMemberLength(
const void *
object,
const SaveLoad *sld);
546 void SlArray(
void *array,
size_t length, VarType conv);
548 bool SlObjectMember(
void *
object,
const SaveLoad *sld);
void ProcessAsyncSaveFinish()
Handle async save finishes.
FiosType
Elements of a file system that are recognized.
AbstractFileType
The different abstract types of files that the system knows about.
void SetSaveLoadError(StringID str)
Set the error message from outside of the actual loading/saving of the game (AfterLoadGame and friend...
void SlGlobList(const SaveLoadGlobVarList *sldg)
Save or Load (a list of) global variables.
char _savegame_format[8]
how to compress savegames
size_t SlGetFieldLength()
Get the length of the current object.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
string (with pre-allocated buffer)
uint32 flags
Flags of the chunk.
void SetName(const char *name)
Set the name of the file.
void NORETURN SlErrorCorrupt(const char *msg)
Error handler for corrupt savegames.
uint16 _sl_version
the major savegame version identifier
SaveLoadTypes
Type of data saved.
VarTypes
VarTypes is the general bitmasked magic type that tells us certain characteristics about the variable...
do not synchronize over network (but it is saved if SLF_NOT_IN_SAVE is not set)
uint32 id
Unique ID (4 letters).
SaveOrLoadResult SaveWithFilter(struct SaveFilter *writer, bool threaded)
Save the game using a (writer) filter.
char title[255]
Internal name of the game.
SaveOrLoadResult SaveOrLoad(const char *filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded=true)
Main Save or Load function where the high-level saveload functions are handled.
Load/save a reference to a link graph job.
Load/save an old-style reference to a vehicle (for pre-4.4 savegames).
void * address
address of variable OR offset of variable in the struct (max offset is 65536)
TTD savegame (can be detected incorrectly)
do not save to config file
Load/save a reference to a town.
SavegameType
Types of save games.
void WriteValue(void *ptr, VarType conv, int64 val)
Write the value of a setting.
int64 ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
Deals with the type of the savegame, independent of extension.
size_t size
the sizeof size.
void SlArray(void *array, size_t length, VarType conv)
Save/Load an array.
const uint16 SAVEGAME_VERSION
current savegame version
void SlAutolength(AutolengthProc *proc, void *arg)
Do something of which I have no idea what it is :P.
Interface for filtering a savegame till it is loaded.
uint16 length
(conditional) length of the variable (eg. arrays) (max array size is 65536 elements) ...
Load/save a reference to a bus/truck stop.
ChunkType
Flags of a chunk.
void NORETURN SlError(StringID string, const char *extra_msg=NULL)
Error handler.
bool global
should we load a global variable or a non-global one
Load/save a reference to an engine renewal (autoreplace).
void SetTitle(const char *title)
Set the title of the file.
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
VarType conv
type of the variable to be saved, int
byte SaveLoadType
Save/load type.
SLRefType
Type of reference (SLE_REF, SLE_CONDREF).
void GenerateDefaultSaveName(char *buf, const char *last)
Fill the buffer with the default name for a savegame or screenshot.
allow new lines in the strings
SaveOrLoadResult
Save or load result codes.
do not save with savegame, basically client-based
allow control codes in the strings
StringID offset into strings-array.
byte _sl_minor_version
the minor savegame version, DO NOT USE!
Load/save a reference to a station.
TTDP savegame in new format (data at SE border)
Load/save a reference to an order.
byte SlReadByte()
Wrapper for reading a byte from the buffer.
static VarType GetVarFileType(VarType type)
Get the #FileType of a setting.
uint16 version_to
save/load the variable until this savegame version
static bool IsSavegameVersionBefore(uint16 major, byte minor=0)
Checks whether the savegame is below major.
static bool SlIsObjectCurrentlyValid(uint16 version_from, uint16 version_to)
Checks if some version from/to combination falls within the range of the active savegame version...
const char * GetSaveLoadErrorString()
Get the string representation of the error message.
static VarType GetVarMemType(VarType type)
Get the NumberType of a setting.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static bool IsNumericType(VarType conv)
Check if the given saveload type is a numeric type.
SaveOrLoadResult LoadWithFilter(struct LoadFilter *reader)
Load the game using a (reader) filter.
SaveLoadOperation
Operation performed on the file.
Load/save a reference to a vehicle.
Handlers and description of chunk.
string enclosed in quotes (with pre-allocated buffer)
static void * GetVariableAddress(const void *object, const SaveLoad *sld)
Get the address of the variable.
Load/save a reference to a cargo packet.
TTDP savegame ( -//- ) (data at NW border)
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
useful to write zeros in savegame.
string pointer enclosed in quotes
broken savegame (used internally)
bool SaveloadCrashWithMissingNewGRFs()
Did loading the savegame cause a crash? If so, were NewGRFs missing?
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
SaveLoadType cmd
the action to take with the saved/loaded type, All types need different action
char name[MAX_PATH]
Name of the file.
SaveLoadOperation file_op
File operation to perform.
void SlWriteByte(byte b)
Wrapper for writing a byte to the dumper.
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
void SlSetLength(size_t length)
Sets the length of either a RIFF object or the number of items in an array.
Load/save a reference to an orderlist.
Load/save a reference to a link graph.
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
void SetMode(FiosType ft)
Set the mode and file type of the file to save or load based on the type of file entry at the file sy...
DetailedFileType detail_ftype
Concrete file type (PNG, BMP, old save, etc).
Interface for filtering a savegame till it is written.
uint16 version_from
save/load the variable starting from this savegame version
error that was caught before internal structures were modified
DetailedFileType
Kinds of files in each AbstractFileType.
SaveLoad SaveLoadGlobVarList
Same as SaveLoad but global variables are used (for better readability);.
size_t SlCalcObjLength(const void *object, const SaveLoad *sld)
Calculate the size of an object.
old custom name to be converted to a char pointer
Last chunk in this array.
bool _do_autosave
are we doing an autosave at the moment?
Load/save a reference to a persistent storage.
error that was caught in the middle of updating game state, need to clear it. (can only happen during...