|
@@ -85,25 +85,26 @@ enum SLRefType {
|
|
|
|
|
|
#define SL_MAX_VERSION 255
|
|
|
|
|
|
enum ChunkType {
|
|
|
CH_RIFF = 0,
|
|
|
CH_ARRAY = 1,
|
|
|
CH_SPARSE_ARRAY = 2,
|
|
|
CH_TYPE_MASK = 3,
|
|
|
CH_LAST = 8,
|
|
|
CH_AUTO_LENGTH = 16,
|
|
|
};
|
|
|
|
|
|
/** VarTypes is the general bitmasked magic type that tells us
|
|
|
/**
|
|
|
* 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 */
|
|
|
enum VarTypes {
|
|
|
/* 4 bits allocated a maximum of 16 types for NumberType */
|
|
|
SLE_FILE_I8 = 0,
|
|
|
SLE_FILE_U8 = 1,
|
|
|
SLE_FILE_I16 = 2,
|
|
|
SLE_FILE_U16 = 3,
|
|
|
SLE_FILE_I32 = 4,
|
|
@@ -242,42 +243,45 @@ typedef SaveLoad SaveLoadGlobVarList;
|
|
|
#define SLEG_CONDLST(variable, type, from, to) SLEG_GENERAL(SL_LST, variable, type, 0, from, to)
|
|
|
|
|
|
#define SLEG_VAR(variable, type) SLEG_CONDVAR(variable, type, 0, SL_MAX_VERSION)
|
|
|
#define SLEG_REF(variable, type) SLEG_CONDREF(variable, type, 0, SL_MAX_VERSION)
|
|
|
#define SLEG_ARR(variable, type) SLEG_CONDARR(variable, type, lengthof(variable), 0, SL_MAX_VERSION)
|
|
|
#define SLEG_STR(variable, type) SLEG_CONDSTR(variable, type, lengthof(variable), 0, SL_MAX_VERSION)
|
|
|
#define SLEG_LST(variable, type) SLEG_CONDLST(variable, type, 0, SL_MAX_VERSION)
|
|
|
|
|
|
#define SLEG_CONDNULL(length, from, to) {true, SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_CONFIG_NO, length, from, to, (void*)NULL}
|
|
|
|
|
|
#define SLEG_END() {true, SL_END, 0, 0, 0, 0, NULL}
|
|
|
|
|
|
/** Checks if the savegame is below major.minor.
|
|
|
/**
|
|
|
* Checks if the savegame is below major.minor.
|
|
|
*/
|
|
|
static inline bool CheckSavegameVersionOldStyle(uint16 major, byte minor)
|
|
|
{
|
|
|
extern uint16 _sl_version;
|
|
|
extern byte _sl_minor_version;
|
|
|
return (_sl_version < major) || (_sl_version == major && _sl_minor_version < minor);
|
|
|
}
|
|
|
|
|
|
/** Checks if the savegame is below version.
|
|
|
/**
|
|
|
* Checks if the savegame is below version.
|
|
|
*/
|
|
|
static inline bool CheckSavegameVersion(uint16 version)
|
|
|
{
|
|
|
extern uint16 _sl_version;
|
|
|
return _sl_version < version;
|
|
|
}
|
|
|
|
|
|
/** Checks if some version from/to combination falls within the range of the
|
|
|
/**
|
|
|
* Checks if some version from/to combination falls within the range of the
|
|
|
* active savegame version */
|
|
|
static inline bool SlIsObjectCurrentlyValid(uint16 version_from, uint16 version_to)
|
|
|
{
|
|
|
extern const uint16 SAVEGAME_VERSION;
|
|
|
if (SAVEGAME_VERSION < version_from || SAVEGAME_VERSION > version_to) return false;
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get the NumberType of a setting. This describes the integer type
|
|
|
* as it is represented in memory
|
|
@@ -301,25 +305,26 @@ static inline VarType GetVarFileType(Var
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Check if the given saveload type is a numeric type.
|
|
|
* @param conv the type to check
|
|
|
* @return True if it's a numeric type.
|
|
|
*/
|
|
|
static inline bool IsNumericType(VarType conv)
|
|
|
{
|
|
|
return GetVarMemType(conv) <= SLE_VAR_U64;
|
|
|
}
|
|
|
|
|
|
/** Get the address of the variable. Which one to pick depends on the object
|
|
|
/**
|
|
|
* Get the address of the variable. Which one to pick depends on the object
|
|
|
* pointer. If it is NULL we are dealing with global variables so the address
|
|
|
* is taken. If non-null only the offset is stored in the union and we need
|
|
|
* to add this to the address of the object */
|
|
|
static inline void *GetVariableAddress(const void *object, const SaveLoad *sld)
|
|
|
{
|
|
|
return (byte*)(sld->global ? NULL : object) + (ptrdiff_t)sld->address;
|
|
|
}
|
|
|
|
|
|
int64 ReadValue(const void *ptr, VarType conv);
|
|
|
void WriteValue(void *ptr, VarType conv, int64 val);
|
|
|
|
|
|
void SlSetArrayIndex(uint index);
|