|
@@ -18,6 +18,8 @@
|
|
|
#include <string>
|
|
|
#include <vector>
|
|
|
|
|
|
#include "extended_ver_sl.h"
|
|
|
|
|
|
/** SaveLoad versions
|
|
|
* Previous savegame versions, the trunk revision where they were
|
|
|
* introduced and the released version that had that particular
|
|
@@ -323,6 +325,30 @@ enum SaveLoadVersion : uint16 {
|
|
|
* its own chunk with feature toggles.
|
|
|
*/
|
|
|
SLV_START_PATCHPACKS, ///< 220 First known patchpack to use a version just above ours.
|
|
|
|
|
|
// legacy patchpack version codes
|
|
|
SLV_PP1X = 100, ///< 1.x
|
|
|
SLV_PP2X = 126, ///< 2.x
|
|
|
SLV_PP3X = 186, ///< 3.x
|
|
|
SLV_PP4X = 189, ///< 4.20033.004 (conflicting with 5.x, because FGS)
|
|
|
SLV_PP5X_DAYLENGTH = 160, ///< 5.22434.001
|
|
|
SLV_PP5X_HOTFIX_174 = 174, ///< 5.23975.005b
|
|
|
SLV_PP5X_HOTFIX_175 = 175, ///< 5.24187.007
|
|
|
SLV_PP5X_HOTFIX_177 = 177, ///< 5.24771.008b
|
|
|
SLV_PP5X_HOTFIX_187 = 187, ///< 5.25942.009
|
|
|
SLV_PP5X_STATION_NEWGRF = 188, ///< 5.26167.011
|
|
|
SLV_PP5X_INFRASTRUCTURE = 189, ///< 5.26167.012
|
|
|
SLV_PP5X_RUNNING_COST_MULT = 194, ///< 5.27099.013
|
|
|
SLV_PP5X_PLANE_RANGE_MULT = 195, ///< 5.27500.016
|
|
|
SLV_PP5X_HOTFIX_196 = 196, ///< 5.27930.017
|
|
|
SLV_PP5X_EXTRA_EXPENSES = 197, ///< 5.27930.018
|
|
|
SLV_PP5X_HOTFIX_198 = 198, ///< 5.020
|
|
|
SLV_PP5X_IMPROVED_BREAKDOWNS = 217, ///< 5.022 dev
|
|
|
SLV_PP5X_BREAKDOWN_SCALER = 218, ///< 5.022 dev
|
|
|
SLV_PP5X_TOWN_IMPROVEMENTS = 219, ///< 5.022 dev
|
|
|
SLV_PP5X_DILAPIDATION = 220, ///< 5.022 final
|
|
|
SLV_PP5X_HOTFIX_222 = 222, ///< 5.024
|
|
|
|
|
|
SLV_END_PATCHPACKS = 286, ///< 286 Last known patchpack to use a version just above ours.
|
|
|
|
|
|
SLV_GS_INDUSTRY_CONTROL, ///< 287 PR#7912 and PR#8115 GS industry control.
|
|
@@ -663,6 +689,7 @@ struct SaveLoad {
|
|
|
SaveLoadAddrProc *address_proc; ///< Callback proc the get the actual variable address in memory.
|
|
|
size_t extra_data; ///< Extra data for the callback proc.
|
|
|
std::shared_ptr<SaveLoadHandler> handler; ///< Custom handler for Save/Load procs.
|
|
|
SlXvFeatureTest ext_feature_test; ///< extended feature test
|
|
|
};
|
|
|
|
|
|
/**
|
|
@@ -678,6 +705,7 @@ struct SaveLoadCompat {
|
|
|
uint16 length; ///< Length of the NULL field.
|
|
|
SaveLoadVersion version_from; ///< Save/load the variable starting from this savegame version.
|
|
|
SaveLoadVersion version_to; ///< Save/load the variable before this savegame version.
|
|
|
SlXvFeatureTest ext_feature_test; ///< extended feature test
|
|
|
};
|
|
|
|
|
|
/**
|
|
@@ -689,9 +717,11 @@ struct SaveLoadCompat {
|
|
|
* @param from First savegame version that has the field.
|
|
|
* @param to Last savegame version that has the field.
|
|
|
* @param extra Extra data to pass to the address callback function.
|
|
|
* @param extver Extended feature test
|
|
|
* @note In general, it is better to use one of the SLE_* macros below.
|
|
|
*/
|
|
|
#define SLE_GENERAL(cmd, base, variable, type, length, from, to, extra) SaveLoad {#variable, 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, nullptr}
|
|
|
#define SLE_GENERAL_X(cmd, base, variable, type, length, from, to, extra, extver) SaveLoad {#variable, 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, nullptr, extver}
|
|
|
#define SLE_GENERAL(cmd, base, variable, type, length, from, to, extra) SLE_GENERAL_X(cmd, base, variable, type, length, from, to, extra, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a variable in some savegame versions.
|
|
@@ -700,8 +730,10 @@ struct SaveLoadCompat {
|
|
|
* @param type Storage of the data in memory and in the savegame.
|
|
|
* @param from First savegame version that has the field.
|
|
|
* @param to Last savegame version that has the field.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLE_CONDVAR(base, variable, type, from, to) SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to, 0)
|
|
|
#define SLE_CONDVAR_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_VAR, base, variable, type, 0, from, to, 0, extver)
|
|
|
#define SLE_CONDVAR(base, variable, type, from, to) SLE_CONDVAR_X(base, variable, type, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a reference in some savegame versions.
|
|
@@ -710,8 +742,10 @@ struct SaveLoadCompat {
|
|
|
* @param type Type of the reference, a value from #SLRefType.
|
|
|
* @param from First savegame version that has the field.
|
|
|
* @param to Last savegame version that has the field.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLE_CONDREF(base, variable, type, from, to) SLE_GENERAL(SL_REF, base, variable, type, 0, from, to, 0)
|
|
|
#define SLE_CONDREF_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_REF, base, variable, type, 0, from, to, 0, extver)
|
|
|
#define SLE_CONDREF(base, variable, type, from, to) SLE_CONDREF_X(base, variable, type, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a fixed-size array of #SL_VAR elements in some savegame versions.
|
|
@@ -721,8 +755,10 @@ struct SaveLoadCompat {
|
|
|
* @param length Number of elements in the array.
|
|
|
* @param from First savegame version that has the array.
|
|
|
* @param to Last savegame version that has the array.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLE_CONDARR(base, variable, type, length, from, to) SLE_GENERAL(SL_ARR, base, variable, type, length, from, to, 0)
|
|
|
#define SLE_CONDARR_X(base, variable, type, length, from, to, extver) SLE_GENERAL_X(SL_ARR, base, variable, type, length, from, to, 0, extver)
|
|
|
#define SLE_CONDARR(base, variable, type, length, from, to) SLE_CONDARR_X(base, variable, type, length, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a string in some savegame versions.
|
|
@@ -732,8 +768,10 @@ struct SaveLoadCompat {
|
|
|
* @param length Number of elements in the string (only used for fixed size buffers).
|
|
|
* @param from First savegame version that has the string.
|
|
|
* @param to Last savegame version that has the string.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLE_CONDSTR(base, variable, type, length, from, to) SLE_GENERAL(SL_STR, base, variable, type, length, from, to, 0)
|
|
|
#define SLE_CONDSTR_X(base, variable, type, length, from, to, extver) SLE_GENERAL_X(SL_STR, base, variable, type, length, from, to, 0, extver)
|
|
|
#define SLE_CONDSTR(base, variable, type, length, from, to) SLE_CONDSTR_X(base, variable, type, length, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a \c std::string in some savegame versions.
|
|
@@ -742,8 +780,10 @@ struct SaveLoadCompat {
|
|
|
* @param type Storage of the data in memory and in the savegame.
|
|
|
* @param from First savegame version that has the string.
|
|
|
* @param to Last savegame version that has the string.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLE_CONDSSTR(base, variable, type, from, to) SLE_GENERAL(SL_STDSTR, base, variable, type, 0, from, to, 0)
|
|
|
#define SLE_CONDSSTR_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_STDSTR, base, variable, type, 0, from, to, 0, extver)
|
|
|
#define SLE_CONDSSTR(base, variable, type, from, to) SLE_CONDSSTR_X(base, variable, type, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a list of #SL_REF elements in some savegame versions.
|
|
@@ -752,8 +792,10 @@ struct SaveLoadCompat {
|
|
|
* @param type Storage of the data in memory and in the savegame.
|
|
|
* @param from First savegame version that has the list.
|
|
|
* @param to Last savegame version that has the list.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLE_CONDREFLIST(base, variable, type, from, to) SLE_GENERAL(SL_REFLIST, base, variable, type, 0, from, to, 0)
|
|
|
#define SLE_CONDREFLIST_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_REFLIST, base, variable, type, 0, from, to, 0, extver)
|
|
|
#define SLE_CONDREFLIST(base, variable, type, from, to) SLE_CONDREFLIST_X(base, variable, type, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a deque of #SL_VAR elements in some savegame versions.
|
|
@@ -762,8 +804,10 @@ struct SaveLoadCompat {
|
|
|
* @param type Storage of the data in memory and in the savegame.
|
|
|
* @param from First savegame version that has the list.
|
|
|
* @param to Last savegame version that has the list.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLE_CONDDEQUE(base, variable, type, from, to) SLE_GENERAL(SL_DEQUE, base, variable, type, 0, from, to, 0)
|
|
|
#define SLE_CONDDEQUE_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_DEQUE, base, variable, type, 0, from, to, 0, extver)
|
|
|
#define SLE_CONDDEQUE(base, variable, type, from, to) SLE_CONDDEQUE_X(base, variable, type, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a variable in every version of a savegame.
|
|
@@ -837,8 +881,10 @@ struct SaveLoadCompat {
|
|
|
* @param to Last savegame version that has the field.
|
|
|
* @param extra Extra data to pass to the address callback function.
|
|
|
* @note In general, it is better to use one of the SLEG_* macros below.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLEG_GENERAL(name, cmd, variable, type, length, from, to, extra) SaveLoad {name, cmd, type, length, from, to, sizeof(variable), [] (void *, size_t) -> void * { return static_cast<void *>(std::addressof(variable)); }, extra, nullptr}
|
|
|
#define SLEG_GENERAL_X(name, cmd, variable, type, length, from, to, extra, extver) SaveLoad {name, cmd, type, length, from, to, sizeof(variable), [] (void *, size_t) -> void * { return static_cast<void *>(std::addressof(variable)); }, extra, nullptr, extver}
|
|
|
#define SLEG_GENERAL(name, cmd, variable, type, length, from, to, extra) SLEG_GENERAL_X(name, cmd, variable, type, length, from, to, extra, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a global variable in some savegame versions.
|
|
@@ -847,8 +893,10 @@ struct SaveLoadCompat {
|
|
|
* @param type Storage of the data in memory and in the savegame.
|
|
|
* @param from First savegame version that has the field.
|
|
|
* @param to Last savegame version that has the field.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLEG_CONDVAR(name, variable, type, from, to) SLEG_GENERAL(name, SL_VAR, variable, type, 0, from, to, 0)
|
|
|
#define SLEG_CONDVAR_X(name, variable, type, from, to, extver) SLEG_GENERAL_X(name, SL_VAR, variable, type, 0, from, to, 0, extver)
|
|
|
#define SLEG_CONDVAR(name, variable, type, from, to) SLEG_CONDVAR_X(name, variable, type, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a global reference in some savegame versions.
|
|
@@ -857,8 +905,10 @@ struct SaveLoadCompat {
|
|
|
* @param type Storage of the data in memory and in the savegame.
|
|
|
* @param from First savegame version that has the field.
|
|
|
* @param to Last savegame version that has the field.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLEG_CONDREF(name, variable, type, from, to) SLEG_GENERAL(name, SL_REF, variable, type, 0, from, to, 0)
|
|
|
#define SLEG_CONDREF_X(name, variable, type, from, to, extver) SLEG_GENERAL_X(name, SL_REF, variable, type, 0, from, to, 0, extver)
|
|
|
#define SLEG_CONDREF(name, variable, type, from, to) SLEG_CONDREF_X(name, variable, type, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a global fixed-size array of #SL_VAR elements in some savegame versions.
|
|
@@ -868,8 +918,10 @@ struct SaveLoadCompat {
|
|
|
* @param length Number of elements in the array.
|
|
|
* @param from First savegame version that has the array.
|
|
|
* @param to Last savegame version that has the array.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLEG_CONDARR(name, variable, type, length, from, to) SLEG_GENERAL(name, SL_ARR, variable, type, length, from, to, 0)
|
|
|
#define SLEG_CONDARR_X(name, variable, type, length, from, to, extver) SLEG_GENERAL_X(name, SL_ARR, variable, type, length, from, to, 0, extver)
|
|
|
#define SLEG_CONDARR(name, variable, type, length, from, to) SLEG_CONDARR_X(name, variable, type, length, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a global string in some savegame versions.
|
|
@@ -879,8 +931,10 @@ struct SaveLoadCompat {
|
|
|
* @param length Number of elements in the string (only used for fixed size buffers).
|
|
|
* @param from First savegame version that has the string.
|
|
|
* @param to Last savegame version that has the string.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLEG_CONDSTR(name, variable, type, length, from, to) SLEG_GENERAL(name, SL_STR, variable, type, length, from, to, 0)
|
|
|
#define SLEG_CONDSTR_X(name, variable, type, length, from, to, extver) SLEG_GENERAL_X(name, SL_STR, variable, type, length, from, to, 0, extver)
|
|
|
#define SLEG_CONDSTR(name, variable, type, length, from, to) SLEG_CONDSTR_X(name, variable, type, length, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a global \c std::string in some savegame versions.
|
|
@@ -889,8 +943,10 @@ struct SaveLoadCompat {
|
|
|
* @param type Storage of the data in memory and in the savegame.
|
|
|
* @param from First savegame version that has the string.
|
|
|
* @param to Last savegame version that has the string.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLEG_CONDSSTR(name, variable, type, from, to) SLEG_GENERAL(name, SL_STDSTR, variable, type, 0, from, to, 0)
|
|
|
#define SLEG_CONDSSTR_X(name, variable, type, from, to, extver) SLEG_GENERAL_X(name, SL_STDSTR, variable, type, 0, from, to, 0, extver)
|
|
|
#define SLEG_CONDSSTR(name, variable, type, from, to) SLEG_CONDSSTR_X(name, variable, type, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a structs in some savegame versions.
|
|
@@ -898,8 +954,10 @@ struct SaveLoadCompat {
|
|
|
* @param handler SaveLoadHandler for the structs.
|
|
|
* @param from First savegame version that has the struct.
|
|
|
* @param to Last savegame version that has the struct.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLEG_CONDSTRUCT(name, handler, from, to) SaveLoad {name, SL_STRUCT, 0, 0, from, to, 0, nullptr, 0, std::make_shared<handler>()}
|
|
|
#define SLEG_CONDSTRUCT_X(name, handler, from, to, extver) SaveLoad {name, SL_STRUCT, 0, 0, from, to, 0, nullptr, 0, std::make_shared<handler>(), extver}
|
|
|
#define SLEG_CONDSTRUCT(name, handler, from, to) SLEG_CONDSTRUCT_X(name, handler, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a global reference list in some savegame versions.
|
|
@@ -908,8 +966,10 @@ struct SaveLoadCompat {
|
|
|
* @param type Storage of the data in memory and in the savegame.
|
|
|
* @param from First savegame version that has the list.
|
|
|
* @param to Last savegame version that has the list.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLEG_CONDREFLIST(name, variable, type, from, to) SLEG_GENERAL(name, SL_REFLIST, variable, type, 0, from, to, 0)
|
|
|
#define SLEG_CONDREFLIST_X(name, variable, type, from, to, extver) SLEG_GENERAL_X(name, SL_REFLIST, variable, type, 0, from, to, 0, extver)
|
|
|
#define SLEG_CONDREFLIST(name, variable, type, from, to) SLEG_CONDREFLIST_X(name, variable, type, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a global vector of #SL_VAR elements in some savegame versions.
|
|
@@ -918,8 +978,10 @@ struct SaveLoadCompat {
|
|
|
* @param type Storage of the data in memory and in the savegame.
|
|
|
* @param from First savegame version that has the list.
|
|
|
* @param to Last savegame version that has the list.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLEG_CONDVECTOR(name, variable, type, from, to) SLEG_GENERAL(name, SL_VECTOR, variable, type, 0, from, to, 0)
|
|
|
#define SLEG_CONDVECTOR_X(name, variable, type, from, to, extver) SLEG_GENERAL_X(name, SL_VECTOR, variable, type, 0, from, to, 0, extver)
|
|
|
#define SLEG_CONDVECTOR(name, variable, type, from, to) SLEG_CONDVECTOR_X(name, variable, type, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a list of structs in some savegame versions.
|
|
@@ -927,8 +989,10 @@ struct SaveLoadCompat {
|
|
|
* @param handler SaveLoadHandler for the list of structs.
|
|
|
* @param from First savegame version that has the list.
|
|
|
* @param to Last savegame version that has the list.
|
|
|
* @param extver Extended feature test
|
|
|
*/
|
|
|
#define SLEG_CONDSTRUCTLIST(name, handler, from, to) SaveLoad {name, SL_STRUCTLIST, 0, 0, from, to, 0, nullptr, 0, std::make_shared<handler>()}
|
|
|
#define SLEG_CONDSTRUCTLIST_X(name, handler, from, to, extver) SaveLoad {name, SL_STRUCTLIST, 0, 0, from, to, 0, nullptr, 0, std::make_shared<handler>(), extver}
|
|
|
#define SLEG_CONDSTRUCTLIST(name, handler, from, to) SLEG_CONDSTRUCTLIST_X(name, handler, from, to, SlXvFeatureTest())
|
|
|
|
|
|
/**
|
|
|
* Storage of a global variable in every savegame version.
|
|
@@ -1004,7 +1068,8 @@ struct SaveLoadCompat {
|
|
|
* Field name where the real SaveLoad can be located.
|
|
|
* @param name The name of the field.
|
|
|
*/
|
|
|
#define SLC_VAR(name) {name, 0, SL_MIN_VERSION, SL_MAX_VERSION}
|
|
|
#define SLC_VAR_X(name, extver) {name, 0, SL_MIN_VERSION, SL_MAX_VERSION, extver}
|
|
|
#define SLC_VAR(name) {name, 0, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest()}
|
|
|
|
|
|
/**
|
|
|
* Empty space in every savegame version.
|
|
@@ -1012,10 +1077,11 @@ struct SaveLoadCompat {
|
|
|
* @param from First savegame version that has the empty space.
|
|
|
* @param to Last savegame version that has the empty space.
|
|
|
*/
|
|
|
#define SLC_NULL(length, from, to) {{}, length, from, to}
|
|
|
#define SLC_NULL_X(length, from, to, extver) {{}, length, from, to, extver}
|
|
|
#define SLC_NULL(length, from, to) {{}, length, from, to, SlXvFeatureTest()}
|
|
|
|
|
|
/** End marker of compat variables save or load. */
|
|
|
#define SLC_END() {{}, 0, SL_MIN_VERSION, SL_MIN_VERSION}
|
|
|
#define SLC_END() {{}, 0, SL_MIN_VERSION, SL_MIN_VERSION, SlXvFeatureTest()}
|
|
|
|
|
|
/**
|
|
|
* Checks whether the savegame is below \a major.\a minor.
|
|
@@ -1124,6 +1190,17 @@ size_t SlCalcObjLength(const void *objec
|
|
|
byte SlReadByte();
|
|
|
void SlWriteByte(byte b);
|
|
|
|
|
|
int SlReadUint16();
|
|
|
uint32 SlReadUint32();
|
|
|
uint64 SlReadUint64();
|
|
|
|
|
|
void SlWriteUint16(uint16 v);
|
|
|
void SlWriteUint32(uint32 v);
|
|
|
void SlWriteUint64(uint64 v);
|
|
|
|
|
|
size_t SlGetBytesRead();
|
|
|
size_t SlGetBytesWritten();
|
|
|
|
|
|
void SlGlobList(const SaveLoadTable &slt);
|
|
|
void SlCopy(void *object, size_t length, VarType conv);
|
|
|
std::vector<SaveLoad> SlTableHeader(const SaveLoadTable &slt);
|