Merge branch 'save_ext' into adjacent_crossings-sx

pull/3/head
Jonathan G Rennison 9 years ago
commit b8ef887cc1

@ -869,6 +869,8 @@
<ClCompile Include="..\src\saveload\town_sl.cpp" />
<ClCompile Include="..\src\saveload\vehicle_sl.cpp" />
<ClCompile Include="..\src\saveload\waypoint_sl.cpp" />
<ClInclude Include="..\src\saveload\extended_ver_sl.h" />
<ClCompile Include="..\src\saveload\extended_ver_sl.cpp" />
<ClInclude Include="..\src\table\airport_defaults.h" />
<ClInclude Include="..\src\table\airport_movement.h" />
<ClInclude Include="..\src\table\airporttile_ids.h" />

@ -1836,6 +1836,12 @@
<ClCompile Include="..\src\saveload\waypoint_sl.cpp">
<Filter>Save/Load handlers</Filter>
</ClCompile>
<ClInclude Include="..\src\saveload\extended_ver_sl.h">
<Filter>Save/Load handlers</Filter>
</ClInclude>
<ClCompile Include="..\src\saveload\extended_ver_sl.cpp">
<Filter>Save/Load handlers</Filter>
</ClCompile>
<ClInclude Include="..\src\table\airport_defaults.h">
<Filter>Tables</Filter>
</ClInclude>

@ -2770,6 +2770,14 @@
RelativePath=".\..\src\saveload\waypoint_sl.cpp"
>
</File>
<File
RelativePath=".\..\src\saveload\extended_ver_sl.h"
>
</File>
<File
RelativePath=".\..\src\saveload\extended_ver_sl.cpp"
>
</File>
</Filter>
<Filter
Name="Tables"

@ -2767,6 +2767,14 @@
RelativePath=".\..\src\saveload\waypoint_sl.cpp"
>
</File>
<File
RelativePath=".\..\src\saveload\extended_ver_sl.h"
>
</File>
<File
RelativePath=".\..\src\saveload\extended_ver_sl.cpp"
>
</File>
</Filter>
<Filter
Name="Tables"

@ -633,6 +633,8 @@ saveload/subsidy_sl.cpp
saveload/town_sl.cpp
saveload/vehicle_sl.cpp
saveload/waypoint_sl.cpp
saveload/extended_ver_sl.h
saveload/extended_ver_sl.cpp
# Tables
table/airport_defaults.h

@ -0,0 +1,343 @@
/* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file extended_ver_sl.cpp Functions related to handling save/load extended version info.
*
* Known extended features are stored in _sl_xv_feature_versions, features which are currently enabled/in use and their versions are stored in the savegame.
* On load, the list of features and their versions are loaded from the savegame. If the savegame contains a feature which is either unknown, or has too high a version,
* loading can be either aborted, or the feature can be ignored if the the feature flags in the savegame indicate that it can be ignored. The savegame may also list any additional
* chunk IDs which are associated with an extended feature, these can be discarded if the feature is discarded.
* This information is stored in the SLXI chunk, the contents of which has the following format:
*
* uint32 chunk version
* uint32 chunk flags
* uint32 number of sub chunks/features
* For each of N sub chunk/feature:
* uint32 feature flags (SlxiSubChunkFlags)
* uint16 feature version
* SLE_STR feature name
* uint32* extra data length [only present iff feature flags & XSCF_EXTRA_DATA_PRESENT]
* N bytes extra data
* uint32* chunk ID list count [only present iff feature flags & XSCF_CHUNK_ID_LIST_PRESENT]
* N x uint32 chunk ID list
*/
#include "../stdafx.h"
#include "../debug.h"
#include "saveload.h"
#include "extended_ver_sl.h"
#include <vector>
#include "../safeguards.h"
uint16 _sl_xv_feature_versions[XSLFI_SIZE]; ///< array of all known feature types and their current versions
bool _sl_is_ext_version; ///< is this an extended savegame version, with more info in the SLXI chunk?
bool _sl_is_faked_ext; ///< is this a faked extended savegame version, with no SLXI chunk?
std::vector<uint32> _sl_xv_discardable_chunk_ids; ///< list of chunks IDs which we can discard if no chunk loader exists
static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version os SLXI chunk
const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker
};
/**
* Extended save/load feature test
*
* First performs a tradional check on the provided @p savegame_version against @p savegame_version_from and @p savegame_version_to.
* Then, if the feature set in the constructor is not XSLFI_NULL, also check than the feature version is inclusively bounded by @p min_version and @p max_version,
* and return the combination of the two tests using the operator defined in the constructor.
* Otherwise just returns the result of the savegame version test
*/
bool SlXvFeatureTest::IsFeaturePresent(uint16 savegame_version, uint16 savegame_version_from, uint16 savegame_version_to) const
{
bool savegame_version_ok = savegame_version >= savegame_version_from && savegame_version <= savegame_version_to;
SlXvFeatureIndex feature = static_cast<SlXvFeatureIndex>(GB(this->value, 0, 16));
if (feature == XSLFI_NULL) return savegame_version_ok;
uint16 min_version = GB(this->value, 16, 16);
uint16 max_version = GB(this->value, 32, 16);
SlXvFeatureTestOperator op = static_cast<SlXvFeatureTestOperator>(GB(this->value, 48, 16));
bool feature_ok = SlXvIsFeaturePresent(feature, min_version, max_version);
switch (op) {
case XSLFTO_OR:
return savegame_version_ok || feature_ok;
case XSLFTO_AND:
return savegame_version_ok && feature_ok;
default:
NOT_REACHED();
return false;
}
}
/**
* Returns true if @p feature is present and has a version inclusively bounded by @p min_version and @p max_version
*/
bool SlXvIsFeaturePresent(SlXvFeatureIndex feature, uint16 min_version, uint16 max_version)
{
assert(feature < XSLFI_SIZE);
return _sl_xv_feature_versions[feature] >= min_version && _sl_xv_feature_versions[feature] <= max_version;
}
/**
* Resets all extended feature versions to 0
*/
void SlXvResetState()
{
_sl_is_ext_version = false;
_sl_is_faked_ext = false;
memset(_sl_xv_feature_versions, 0, sizeof(_sl_xv_feature_versions));
}
/**
* Resets all extended feature versions to their currently enabled versions, i.e. versions suitable for saving
*/
void SlXvSetCurrentState()
{
SlXvResetState();
_sl_is_ext_version = true;
const SlxiSubChunkInfo *info = _sl_xv_sub_chunk_infos;
for (; info->index != XSLFI_NULL; ++info) {
_sl_xv_feature_versions[info->index] = info->save_version;
}
}
/**
* Check for "special" savegame versions (i.e. known patchpacks) and set correct savegame version, settings, etc.
*/
void SlXvCheckSpecialSavegameVersions()
{
extern uint16 _sl_version;
// TODO: check for savegame versions
}
/**
* Return true if this chunk has been marked as discardable
*/
bool SlXvIsChunkDiscardable(uint32 id)
{
for(size_t i = 0; i < _sl_xv_discardable_chunk_ids.size(); i++) {
if (_sl_xv_discardable_chunk_ids[i] == id) {
return true;
}
}
return false;
}
/**
* Writes a chunk ID list string to the savegame, returns the number of chunks written
* In dry run mode, only returns the number of chunk which would have been written
*/
static uint32 WriteChunkIdList(const char *chunk_list, bool dry_run)
{
unsigned int chunk_count = 0; // number of chunks output
unsigned int id_offset = 0; // how far are we into the ID
for (; *chunk_list != 0; chunk_list++) {
if (id_offset == 4) {
assert(*chunk_list == ',');
id_offset = 0;
} else {
if (!dry_run) {
SlWriteByte(*chunk_list);
}
if (id_offset == 3) {
chunk_count++;
}
id_offset++;
}
}
assert(id_offset == 4);
return chunk_count;
}
static void Save_SLXI()
{
SlXvSetCurrentState();
static const SaveLoad _xlsi_sub_chunk_desc[] = {
SLE_VAR(SlxiSubChunkInfo, save_version, SLE_UINT16),
SLE_STR(SlxiSubChunkInfo, name, SLE_STR, 0),
SLE_END()
};
// calculate lengths
uint32 item_count = 0;
uint32 length = 12;
std::vector<uint32> extra_data_lengths;
std::vector<uint32> chunk_counts;
extra_data_lengths.resize(XSLFI_SIZE);
chunk_counts.resize(XSLFI_SIZE);
const SlxiSubChunkInfo *info = _sl_xv_sub_chunk_infos;
for (; info->index != XSLFI_NULL; ++info) {
if (info->save_version > 0) {
item_count++;
length += 4;
length += SlCalcObjLength(info, _xlsi_sub_chunk_desc);
if (info->save_proc) {
uint32 extra_data_length = info->save_proc(info, true);
if (extra_data_length) {
extra_data_lengths[info->index] = extra_data_length;
length += 4 + extra_data_length;
}
}
if (info->chunk_list) {
uint32 chunk_count = WriteChunkIdList(info->chunk_list, true);
if (chunk_count) {
chunk_counts[info->index] = chunk_count;
length += 4 * (1 + chunk_count);
}
}
}
}
// write header
SlSetLength(length);
SlWriteUint32(_sl_xv_slxi_chunk_version); // chunk version
SlWriteUint32(0); // flags
SlWriteUint32(item_count); // item count
// write data
info = _sl_xv_sub_chunk_infos;
for (; info->index != XSLFI_NULL; ++info) {
if (info->save_version > 0) {
SlxiSubChunkFlags flags = info->flags;
assert(!(flags & (XSCF_EXTRA_DATA_PRESENT | XSCF_CHUNK_ID_LIST_PRESENT)));
uint32 extra_data_length = extra_data_lengths[info->index];
uint32 chunk_count = chunk_counts[info->index];
if (extra_data_length > 0) flags |= XSCF_EXTRA_DATA_PRESENT;
if (chunk_count > 0) flags |= XSCF_CHUNK_ID_LIST_PRESENT;
SlWriteUint32(flags);
SlObject(const_cast<SlxiSubChunkInfo *>(info), _xlsi_sub_chunk_desc);
if (extra_data_length > 0) {
SlWriteUint32(extra_data_length);
size_t written = SlGetBytesWritten();
info->save_proc(info, false);
assert(SlGetBytesWritten() == written + extra_data_length);
}
if (chunk_count > 0) {
SlWriteUint32(chunk_count);
size_t written = SlGetBytesWritten();
WriteChunkIdList(info->chunk_list, false);
assert(SlGetBytesWritten() == written + (chunk_count * 4));
}
}
}
}
static void Load_SLXI()
{
if (_sl_is_faked_ext || !_sl_is_ext_version) {
SlErrorCorrupt("SXLI chunk is unexpectedly present");
}
SlXvResetState();
_sl_is_ext_version = true;
uint32 version = SlReadUint32();
if (version > _sl_xv_slxi_chunk_version) SlErrorCorruptFmt("SLXI chunk: version: %u is too new (expected max: %u)", version, _sl_xv_slxi_chunk_version);
uint32 chunk_flags = SlReadUint32();
// flags are not in use yet, reserve for future expansion
if (chunk_flags != 0) SlErrorCorruptFmt("SLXI chunk: unknown chunk header flags: 0x%X", chunk_flags);
char name_buffer[256];
const SaveLoadGlobVarList xlsi_sub_chunk_name_desc[] = {
SLEG_STR(name_buffer, SLE_STRB),
SLEG_END()
};
uint32 item_count = SlReadUint32();
for (uint32 i = 0; i < item_count; i++) {
SlxiSubChunkFlags flags = static_cast<SlxiSubChunkFlags>(SlReadUint32());
uint16 version = SlReadUint16();
SlGlobList(xlsi_sub_chunk_name_desc);
// linearly scan through feature list until found name match
bool found = false;
const SlxiSubChunkInfo *info = _sl_xv_sub_chunk_infos;
for (; info->index != XSLFI_NULL; ++info) {
if (strcmp(name_buffer, info->name) == 0) {
found = true;
break;
}
}
bool discard_chunks = false;
if (found) {
if (version > info->max_version) {
if (flags & XSCF_IGNORABLE_VERSION) {
// version too large but carry on regardless
discard_chunks = true;
if (flags & XSCF_EXTRA_DATA_PRESENT) {
SlSkipBytes(SlReadUint32()); // skip extra data field
}
DEBUG(sl, 1, "SLXI chunk: too large version for feature: '%s', version: %d, max version: %d, ignoring", name_buffer, version, info->max_version);
} else {
SlErrorCorruptFmt("SLXI chunk: too large version for feature: '%s', version: %d, max version: %d", name_buffer, version, info->max_version);
}
} else {
// success path :)
_sl_xv_feature_versions[info->index] = version;
if (flags & XSCF_EXTRA_DATA_PRESENT) {
uint32 extra_data_size = SlReadUint32();
if (extra_data_size) {
if (info->load_proc) {
size_t read = SlGetBytesRead();
info->load_proc(info, extra_data_size);
if (SlGetBytesRead() != read + extra_data_size) {
SlErrorCorruptFmt("SLXI chunk: feature: %s, version: %d, extra data length mismatch", name_buffer, version);
}
} else {
SlErrorCorruptFmt("SLXI chunk: feature: %s, version: %d, unexpectedly includes extra data", name_buffer, version);
}
}
}
DEBUG(sl, 1, "SLXI chunk: found known feature: '%s', version: %d, max version: %d", name_buffer, version, info->max_version);
}
} else {
if (flags & XSCF_IGNORABLE_UNKNOWN) {
// not found but carry on regardless
discard_chunks = true;
if (flags & XSCF_EXTRA_DATA_PRESENT) {
SlSkipBytes(SlReadUint32()); // skip extra data field
}
DEBUG(sl, 1, "SLXI chunk: unknown feature: '%s', version: %d, ignoring", name_buffer, version);
} else {
SlErrorCorruptFmt("SLXI chunk: unknown feature: %s, version: %d", name_buffer, version);
}
}
// at this point the extra data field should have been consumed
// handle chunk ID list field
if (flags & XSCF_CHUNK_ID_LIST_PRESENT) {
uint32 chunk_count = SlReadUint32();
for (uint32 j = 0; j < chunk_count; j++) {
uint32 chunk_id = SlReadUint32();
if (discard_chunks) {
_sl_xv_discardable_chunk_ids.push_back(chunk_id);
DEBUG(sl, 2, "SLXI chunk: unknown feature: '%s', discarding chunk: %c%c%c%c", name_buffer, chunk_id >> 24, chunk_id >> 16, chunk_id >> 8, chunk_id);
}
}
}
}
}
extern const ChunkHandler _version_ext_chunk_handlers[] = {
{ 'SLXI', Save_SLXI, Load_SLXI, NULL, Load_SLXI, CH_RIFF | CH_LAST},
};

@ -0,0 +1,109 @@
/* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file extended_ver_sl.h Functions/types related to handling save/load extended version info. */
#ifndef EXTENDED_VER_SL_H
#define EXTENDED_VER_SL_H
#include "../core/bitmath_func.hpp"
#include <vector>
/**
* List of extended features, each feature has its own (16 bit) version
*/
enum SlXvFeatureIndex {
XSLFI_NULL = 0, ///< Unused value, to indicate that no extended feature test is in use
XSLFI_SIZE, ///< Total count of features, including null feature
};
extern uint16 _sl_xv_feature_versions[XSLFI_SIZE];
/**
* Operator to use when combining traditional savegame number test with an extended feature version test
*/
enum SlXvFeatureTestOperator {
XSLFTO_OR = 0, ///< Test if traditional savegame version is in bounds OR extended feature is in version bounds
XSLFTO_AND ///< Test if traditional savegame version is in bounds AND extended feature is in version bounds
};
/**
* Structure to describe an extended feature version test, and how it combines with a traditional savegame version test
*/
struct SlXvFeatureTest {
private:
uint64 value;
public:
SlXvFeatureTest()
: value(0) { }
SlXvFeatureTest(SlXvFeatureTestOperator op, SlXvFeatureIndex feature, uint16 min_version = 1, uint16 max_version = 0xFFFF)
{
this->value = 0;
SB(this->value, 0, 16, feature);
SB(this->value, 16, 16, min_version);
SB(this->value, 32, 16, max_version);
SB(this->value, 48, 16, op);
}
bool IsFeaturePresent(uint16 savegame_version, uint16 savegame_version_from, uint16 savegame_version_to) const;
};
bool SlXvIsFeaturePresent(SlXvFeatureIndex feature, uint16 min_version = 1, uint16 max_version = 0xFFFF);
/**
* Returns true if @p feature is missing (i.e. has a version of 0)
*/
inline bool SlXvIsFeatureMissing(SlXvFeatureIndex feature)
{
return !SlXvIsFeaturePresent(feature);
}
/**
* sub chunk flags, this is saved as-is
* (XSCF_EXTRA_DATA_PRESENT and XSCF_CHUNK_ID_LIST_PRESENT must only be set by the save code, and read by the load code)
*/
enum SlxiSubChunkFlags {
XSCF_NULL = 0, ///< zero value
XSCF_IGNORABLE_UNKNOWN = 1 << 0, ///< the loader is free to ignore this without aborting the load if it doesn't know what it is at all
XSCF_IGNORABLE_VERSION = 1 << 1, ///< the loader is free to ignore this without aborting the load if the version is greater than the maximum that can be loaded
XSCF_EXTRA_DATA_PRESENT = 1 << 2, ///< extra data field is present, extra data in some sub-chunk/feature specific format, not used for anything yet
XSCF_CHUNK_ID_LIST_PRESENT = 1 << 3, ///< chunk ID list field is present, list of chunks which this sub-chunk/feature adds to the save game, this can be used to discard the chunks if the feature is unknown
};
DECLARE_ENUM_AS_BIT_SET(SlxiSubChunkFlags)
struct SlxiSubChunkInfo;
typedef uint32 SlxiSubChunkSaveProc(const SlxiSubChunkInfo *info, bool dry_run); ///< sub chunk save procedure type, must return length and write no data when dry_run is true
typedef void SlxiSubChunkLoadProc(const SlxiSubChunkInfo *info, uint32 length); ///< sub chunk load procedure, must consume length bytes
/** Handlers and description of chunk. */
struct SlxiSubChunkInfo {
SlXvFeatureIndex index; ///< feature index, this is saved
SlxiSubChunkFlags flags; ///< flags, this is saved
uint16 save_version; ///< version to save
uint16 max_version; ///< maximum version to accept on load
const char *name; ///< feature name, this *IS* saved, so must be globally unique
SlxiSubChunkSaveProc *save_proc; ///< save procedure of the sub chunk, this may be NULL in which case no extra chunk data is saved
SlxiSubChunkLoadProc *load_proc; ///< load procedure of the sub chunk, this may be NULL in which case the extra chunk data must be missing or of 0 length
const char *chunk_list; ///< this is a list of chunks that this feature uses, which should be written to the savegame, this must be a comma-seperated list of 4-character IDs, with no spaces, or NULL
};
void SlXvResetState();
void SlXvSetCurrentState();
void SlXvCheckSpecialSavegameVersions();
bool SlXvIsChunkDiscardable(uint32 id);
#endif /* EXTENDED_VER_SL_H */

@ -48,9 +48,12 @@
#include "saveload_internal.h"
#include "saveload_filter.h"
#include "extended_ver_sl.h"
#include "../safeguards.h"
#include <vector>
/*
* Previous savegame versions, the trunk revision where they were
* introduced and the released version that had that particular
@ -264,6 +267,7 @@
* 194 26881 1.5.x
*/
extern const uint16 SAVEGAME_VERSION = 194; ///< Current savegame version of OpenTTD.
const uint16 SAVEGAME_VERSION_EXT = 0x8000; ///< Savegame extension indicator mask
SavegameType _savegame_type; ///< type of savegame we are loading
@ -273,6 +277,8 @@ byte _sl_minor_version; ///< the minor savegame version, DO NOT USE!
char _savegame_format[8]; ///< how to compress savegames
bool _do_autosave; ///< are we doing an autosave at the moment?
extern bool _sl_is_ext_version;
/** What are we currently doing? */
enum SaveLoadAction {
SLA_LOAD, ///< loading
@ -414,6 +420,7 @@ struct SaveLoadParams {
static SaveLoadParams _sl; ///< Parameters used for/at saveload.
/* these define the chunks */
extern const ChunkHandler _version_ext_chunk_handlers[];
extern const ChunkHandler _gamelog_chunk_handlers[];
extern const ChunkHandler _map_chunk_handlers[];
extern const ChunkHandler _misc_chunk_handlers[];
@ -450,6 +457,7 @@ extern const ChunkHandler _persistent_storage_chunk_handlers[];
/** Array of all chunks in a savegame, \c NULL terminated. */
static const ChunkHandler * const _chunk_handlers[] = {
_version_ext_chunk_handlers, // this should be first, such that it is saved first, as when loading it affects the loading of subsequent chunks
_gamelog_chunk_handlers,
_map_chunk_handlers,
_misc_chunk_handlers,
@ -503,6 +511,7 @@ static void SlNullPointers()
* during NULLing; especially those that try to get
* pointers from other pools. */
_sl_version = SAVEGAME_VERSION;
SlXvSetCurrentState();
DEBUG(sl, 1, "Nulling pointers");
@ -526,17 +535,22 @@ static void SlNullPointers()
* @note This function does never return as it throws an exception to
* break out of all the saveload code.
*/
void NORETURN SlError(StringID string, const char *extra_msg)
void NORETURN SlError(StringID string, const char *extra_msg, bool already_malloced)
{
char *str = NULL;
if (extra_msg != NULL) {
str = already_malloced ? const_cast<char *>(extra_msg) : stredup(extra_msg);
}
/* Distinguish between loading into _load_check_data vs. normal save/load. */
if (_sl.action == SLA_LOAD_CHECK) {
_load_check_data.error = string;
free(_load_check_data.error_data);
_load_check_data.error_data = (extra_msg == NULL) ? NULL : stredup(extra_msg);
_load_check_data.error_data = str;
} else {
_sl.error_str = string;
free(_sl.extra_msg);
_sl.extra_msg = (extra_msg == NULL) ? NULL : stredup(extra_msg);
_sl.extra_msg = str;
}
/* We have to NULL all pointers here; we might be in a state where
@ -547,6 +561,18 @@ void NORETURN SlError(StringID string, const char *extra_msg)
throw std::exception();
}
/**
* As SlError, except that it takes a format string and additional parameters
*/
void CDECL NORETURN SlErrorFmt(StringID string, const char *msg, ...)
{
va_list va;
va_start(va, msg);
char *str = str_vfmt(msg, va);
va_end(va);
SlError(string, str, true);
}
/**
* Error handler for corrupt savegames. Sets everything up to show the
* error message and to clean up the mess of a partial savegame load.
@ -554,9 +580,21 @@ void NORETURN SlError(StringID string, const char *extra_msg)
* @note This function does never return as it throws an exception to
* break out of all the saveload code.
*/
void NORETURN SlErrorCorrupt(const char *msg)
void NORETURN SlErrorCorrupt(const char *msg, bool already_malloced)
{
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, msg);
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, msg, already_malloced);
}
/**
* As SlErrorCorruptFmt, except that it takes a format string and additional parameters
*/
void CDECL NORETURN SlErrorCorruptFmt(const char *msg, ...)
{
va_list va;
va_start(va, msg);
char *str = str_vfmt(msg, va);
va_end(va);
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, str, true);
}
@ -612,51 +650,24 @@ void SlWriteByte(byte b)
_sl.dumper->WriteByte(b);
}
static inline int SlReadUint16()
{
int x = SlReadByte() << 8;
return x | SlReadByte();
}
static inline uint32 SlReadUint32()
{
uint32 x = SlReadUint16() << 16;
return x | SlReadUint16();
}
static inline uint64 SlReadUint64()
{
uint32 x = SlReadUint32();
uint32 y = SlReadUint32();
return (uint64)x << 32 | y;
}
static inline void SlWriteUint16(uint16 v)
{
SlWriteByte(GB(v, 8, 8));
SlWriteByte(GB(v, 0, 8));
}
static inline void SlWriteUint32(uint32 v)
{
SlWriteUint16(GB(v, 16, 16));
SlWriteUint16(GB(v, 0, 16));
}
static inline void SlWriteUint64(uint64 x)
/**
* Returns number of bytes read so far
* May only be called during a load/load check action
*/
size_t SlGetBytesRead()
{
SlWriteUint32((uint32)(x >> 32));
SlWriteUint32((uint32)x);
assert(_sl.action == SLA_LOAD || _sl.action == SLA_LOAD_CHECK);
return _sl.reader->GetSize();
}
/**
* Read in bytes from the file/data structure but don't do
* anything with them, discarding them in effect
* @param length The amount of bytes that is being treated this way
* Returns number of bytes written so far
* May only be called during a save action
*/
static inline void SlSkipBytes(size_t length)
size_t SlGetBytesWritten()
{
for (; length != 0; length--) SlReadByte();
assert(_sl.action == SLA_SAVE);
return _sl.dumper->GetSize();
}
/**
@ -1414,7 +1425,7 @@ static void SlList(void *list, SLRefType conv)
/** Are we going to save this object or not? */
static inline bool SlIsObjectValidInSavegame(const SaveLoad *sld)
{
if (_sl_version < sld->version_from || _sl_version > sld->version_to) return false;
if (!sld->ext_feature_test.IsFeaturePresent(_sl_version, sld->version_from, sld->version_to)) return false;
if (sld->conv & SLF_NOT_IN_SAVE) return false;
return true;
@ -1692,7 +1703,7 @@ static void SlLoadChunk(const ChunkHandler *ch)
/**
* Load a chunk of data for checking savegames.
* If the chunkhandler is NULL, the chunk is skipped.
* @param ch The chunkhandler that will be used for the operation
* @param ch The chunkhandler that will be used for the operation, this may be NULL
*/
static void SlLoadCheckChunk(const ChunkHandler *ch)
{
@ -1706,14 +1717,14 @@ static void SlLoadCheckChunk(const ChunkHandler *ch)
switch (m) {
case CH_ARRAY:
_sl.array_index = 0;
if (ch->load_check_proc) {
if (ch && ch->load_check_proc) {
ch->load_check_proc();
} else {
SlSkipArray();
}
break;
case CH_SPARSE_ARRAY:
if (ch->load_check_proc) {
if (ch && ch->load_check_proc) {
ch->load_check_proc();
} else {
SlSkipArray();
@ -1726,7 +1737,7 @@ static void SlLoadCheckChunk(const ChunkHandler *ch)
len += SlReadUint16();
_sl.obj_len = len;
endoffs = _sl.reader->GetSize() + len;
if (ch->load_check_proc) {
if (ch && ch->load_check_proc) {
ch->load_check_proc();
} else {
SlSkipBytes(len);
@ -1840,8 +1851,16 @@ static void SlLoadChunks()
DEBUG(sl, 2, "Loading chunk %c%c%c%c", id >> 24, id >> 16, id >> 8, id);
ch = SlFindChunkHandler(id);
if (ch == NULL) SlErrorCorrupt("Unknown chunk type");
SlLoadChunk(ch);
if (ch == NULL) {
if (SlXvIsChunkDiscardable(id)) {
DEBUG(sl, 1, "Discarding chunk %c%c%c%c", id >> 24, id >> 16, id >> 8, id);
SlLoadCheckChunk(NULL);
} else {
SlErrorCorrupt("Unknown chunk type");
}
} else {
SlLoadChunk(ch);
}
}
}
@ -1855,7 +1874,7 @@ static void SlLoadCheckChunks()
DEBUG(sl, 2, "Loading chunk %c%c%c%c", id >> 24, id >> 16, id >> 8, id);
ch = SlFindChunkHandler(id);
if (ch == NULL) SlErrorCorrupt("Unknown chunk type");
if (ch == NULL && !SlXvIsChunkDiscardable(id)) SlErrorCorrupt("Unknown chunk type");
SlLoadCheckChunk(ch);
}
}
@ -2448,6 +2467,8 @@ static inline void ClearSaveLoadState()
delete _sl.lf;
_sl.lf = NULL;
SlXvSetCurrentState();
}
/**
@ -2511,7 +2532,7 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded)
const SaveLoadFormat *fmt = GetSavegameFormat(_savegame_format, &compression);
/* We have written our stuff to memory, now write it to file! */
uint32 hdr[2] = { fmt->tag, TO_BE32(SAVEGAME_VERSION << 16) };
uint32 hdr[2] = { fmt->tag, TO_BE32((SAVEGAME_VERSION | SAVEGAME_VERSION_EXT) << 16) };
_sl.sf->Write((byte*)hdr, sizeof(hdr));
_sl.sf = fmt->init_write(_sl.sf, compression);
@ -2578,6 +2599,7 @@ static SaveOrLoadResult DoSave(SaveFilter *writer, bool threaded)
_sl.sf = writer;
_sl_version = SAVEGAME_VERSION;
SlXvSetCurrentState();
SaveViewportBeforeSaveGame();
SlSaveChunks();
@ -2629,6 +2651,8 @@ static SaveOrLoadResult DoLoad(LoadFilter *reader, bool load_check)
_load_check_data.checkable = true;
}
SlXvResetState();
uint32 hdr[2];
if (_sl.lf->Read((byte*)hdr, sizeof(hdr)) != sizeof(hdr)) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
@ -2641,6 +2665,7 @@ static SaveOrLoadResult DoLoad(LoadFilter *reader, bool load_check)
_sl.lf->Reset();
_sl_version = 0;
_sl_minor_version = 0;
SlXvResetState();
/* Try to find the LZO savegame format; it uses 'OTTD' as tag. */
fmt = _saveload_formats;
@ -2663,7 +2688,14 @@ static SaveOrLoadResult DoLoad(LoadFilter *reader, bool load_check)
* Therefore it is loaded, but never saved (or, it saves a 0 in any scenario). */
_sl_minor_version = (TO_BE32(hdr[1]) >> 8) & 0xFF;
DEBUG(sl, 1, "Loading savegame version %d", _sl_version);
if (_sl_version & SAVEGAME_VERSION_EXT) {
_sl_version &= ~SAVEGAME_VERSION_EXT;
_sl_is_ext_version = true;
} else {
SlXvCheckSpecialSavegameVersions();
}
DEBUG(sl, 1, "Loading savegame version %d%s", _sl_version, _sl_is_ext_version ? " (extended)" : "");
/* Is the version higher than the current? */
if (_sl_version > SAVEGAME_VERSION) SlError(STR_GAME_SAVELOAD_ERROR_TOO_NEW_SAVEGAME);
@ -2800,6 +2832,7 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo
if (!LoadOldSaveGame(filename)) return SL_REINIT;
_sl_version = 0;
_sl_minor_version = 0;
SlXvResetState();
GamelogStartAction(GLAT_LOAD);
if (!AfterLoadGame()) {
GamelogStopAction();

@ -14,6 +14,9 @@
#include "../fileio_type.h"
#include "../strings_type.h"
#include "extended_ver_sl.h"
#include <stdarg.h>
/** Save or load result codes. */
enum SaveOrLoadResult {
@ -213,6 +216,7 @@ struct SaveLoad {
* that is called to save it. address: global=true, offset: global=false */
void *address; ///< address of variable OR offset of variable in the struct (max offset is 65536)
size_t size; ///< the sizeof size.
SlXvFeatureTest ext_feature_test; ///< extended feature test
};
/** Same as #SaveLoad but global variables are used (for better readability); */
@ -226,9 +230,11 @@ typedef SaveLoad SaveLoadGlobVarList;
* @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 SlXvFeatureTest to test (along with from and to) which savegames have the field
* @note In general, it is better to use one of the SLE_* macros below.
*/
#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)}
#define SLE_GENERAL_X(cmd, base, variable, type, length, from, to, extver) {false, cmd, type, length, from, to, (void*)cpp_offsetof(base, variable), cpp_sizeof(base, variable), extver}
#define SLE_GENERAL(cmd, base, variable, type, length, from, to) SLE_GENERAL_X(cmd, base, variable, type, length, from, to, {})
/**
* Storage of a variable in some savegame versions.
@ -237,8 +243,10 @@ typedef SaveLoad SaveLoadGlobVarList;
* @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 SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLE_CONDVAR(base, variable, type, from, to) SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to)
#define SLE_CONDVAR_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_VAR, base, variable, type, 0, from, to, extver)
#define SLE_CONDVAR(base, variable, type, from, to) SLE_CONDVAR_X(base, variable, type, from, to, {})
/**
* Storage of a reference in some savegame versions.
@ -247,8 +255,10 @@ typedef SaveLoad SaveLoadGlobVarList;
* @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 SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLE_CONDREF(base, variable, type, from, to) SLE_GENERAL(SL_REF, base, variable, type, 0, from, to)
#define SLE_CONDREF_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_REF, base, variable, type, 0, from, to, extver)
#define SLE_CONDREF(base, variable, type, from, to) SLE_CONDREF_X(base, variable, type, from, to, {})
/**
* Storage of an array in some savegame versions.
@ -258,8 +268,10 @@ typedef SaveLoad SaveLoadGlobVarList;
* @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 SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLE_CONDARR(base, variable, type, length, from, to) SLE_GENERAL(SL_ARR, base, variable, type, length, from, to)
#define SLE_CONDARR_X(base, variable, type, length, from, to, extver) SLE_GENERAL_X(SL_ARR, base, variable, type, length, from, to, extver)
#define SLE_CONDARR(base, variable, type, length, from, to) SLE_CONDARR_X(base, variable, type, length, from, to, {})
/**
* Storage of a string in some savegame versions.
@ -269,8 +281,10 @@ typedef SaveLoad SaveLoadGlobVarList;
* @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 SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLE_CONDSTR(base, variable, type, length, from, to) SLE_GENERAL(SL_STR, base, variable, type, length, from, to)
#define SLE_CONDSTR_X(base, variable, type, length, from, to, extver) SLE_GENERAL_X(SL_STR, base, variable, type, length, from, to, extver)
#define SLE_CONDSTR(base, variable, type, length, from, to) SLE_CONDSTR_X(base, variable, type, length, from, to, {})
/**
* Storage of a list in some savegame versions.
@ -279,8 +293,10 @@ typedef SaveLoad SaveLoadGlobVarList;
* @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 SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLE_CONDLST(base, variable, type, from, to) SLE_GENERAL(SL_LST, base, variable, type, 0, from, to)
#define SLE_CONDLST_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_LST, base, variable, type, 0, from, to, extver)
#define SLE_CONDLST(base, variable, type, from, to) SLE_CONDLST_X(base, variable, type, from, to, {})
/**
* Storage of a variable in every version of a savegame.
@ -335,17 +351,19 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param length Length of the empty space.
* @param from First savegame version that has the empty space.
* @param to Last savegame version that has the empty space.
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have empty space
*/
#define SLE_CONDNULL(length, from, to) SLE_CONDARR(NullStruct, null, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to)
#define SLE_CONDNULL_X(length, from, to, extver) SLE_CONDARR_X(NullStruct, null, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, extver)
#define SLE_CONDNULL(length, from, to) SLE_CONDNULL_X(length, from, to, {})
/** Translate values ingame to different values in the savegame and vv. */
#define SLE_WRITEBYTE(base, variable, value) SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, value, value)
#define SLE_VEH_INCLUDE() {false, SL_VEH_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL, 0}
#define SLE_ST_INCLUDE() {false, SL_ST_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL, 0}
#define SLE_VEH_INCLUDE() {false, SL_VEH_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL, 0, {}}
#define SLE_ST_INCLUDE() {false, SL_ST_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL, 0, {}}
/** End marker of a struct/class save or load. */
#define SLE_END() {false, SL_END, 0, 0, 0, 0, NULL, 0}
#define SLE_END() {false, SL_END, 0, 0, 0, 0, NULL, 0, {}}
/**
* Storage of global simple variables, references (pointers), and arrays.
@ -354,9 +372,11 @@ typedef SaveLoad SaveLoadGlobVarList;
* @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 SlXvFeatureTest to test (along with from and to) which savegames have the field
* @note In general, it is better to use one of the SLEG_* macros below.
*/
#define SLEG_GENERAL(cmd, variable, type, length, from, to) {true, cmd, type, length, from, to, (void*)&variable, sizeof(variable)}
#define SLEG_GENERAL_X(cmd, variable, type, length, from, to, extver) {true, cmd, type, length, from, to, (void*)&variable, sizeof(variable), extver}
#define SLEG_GENERAL(cmd, variable, type, length, from, to) SLEG_GENERAL_X(cmd, variable, type, length, from, to, {})
/**
* Storage of a global variable in some savegame versions.
@ -364,8 +384,10 @@ typedef SaveLoad SaveLoadGlobVarList;
* @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 SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLEG_CONDVAR(variable, type, from, to) SLEG_GENERAL(SL_VAR, variable, type, 0, from, to)
#define SLEG_CONDVAR_X(variable, type, from, to, extver) SLEG_GENERAL_X(SL_VAR, variable, type, 0, from, to, extver)
#define SLEG_CONDVAR(variable, type, from, to) SLEG_CONDVAR_X(variable, type, from, to, {})
/**
* Storage of a global reference in some savegame versions.
@ -373,8 +395,10 @@ typedef SaveLoad SaveLoadGlobVarList;
* @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 SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLEG_CONDREF(variable, type, from, to) SLEG_GENERAL(SL_REF, variable, type, 0, from, to)
#define SLEG_CONDREF_X(variable, type, from, to, extver) SLEG_GENERAL_X(SL_REF, variable, type, 0, from, to, extver)
#define SLEG_CONDREF(variable, type, from, to) SLEG_CONDREF_X(variable, type, from, to, {})
/**
* Storage of a global array in some savegame versions.
@ -383,8 +407,10 @@ typedef SaveLoad SaveLoadGlobVarList;
* @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 SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLEG_CONDARR(variable, type, length, from, to) SLEG_GENERAL(SL_ARR, variable, type, length, from, to)
#define SLEG_CONDARR_X(variable, type, length, from, to, extver) SLEG_GENERAL_X(SL_ARR, variable, type, length, from, to, extver)
#define SLEG_CONDARR(variable, type, length, from, to) SLEG_CONDARR_X(variable, type, length, from, to, {})
/**
* Storage of a global string in some savegame versions.
@ -393,8 +419,10 @@ typedef SaveLoad SaveLoadGlobVarList;
* @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 SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLEG_CONDSTR(variable, type, length, from, to) SLEG_GENERAL(SL_STR, variable, type, length, from, to)
#define SLEG_CONDSTR_X(variable, type, length, from, to, extver) SLEG_GENERAL_X(SL_STR, variable, type, length, from, to, extver)
#define SLEG_CONDSTR(variable, type, length, from, to) SLEG_CONDSTR_X(variable, type, length, from, to, {})
/**
* Storage of a global list in some savegame versions.
@ -402,8 +430,10 @@ typedef SaveLoad SaveLoadGlobVarList;
* @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 SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLEG_CONDLST(variable, type, from, to) SLEG_GENERAL(SL_LST, variable, type, 0, from, to)
#define SLEG_CONDLST_X(variable, type, from, to, extver) SLEG_GENERAL_X(SL_LST, variable, type, 0, from, to, extver)
#define SLEG_CONDLST(variable, type, from, to) SLEG_CONDLST_X(variable, type, from, to, {})
/**
* Storage of a global variable in every savegame version.
@ -445,11 +475,12 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param length Length of the empty space.
* @param from First savegame version that has the empty space.
* @param to Last savegame version that has the empty space.
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have empty space
*/
#define SLEG_CONDNULL(length, from, to) {true, SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, (void*)NULL}
#define SLEG_CONDNULL(length, from, to) {true, SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, (void*)NULL, {}}
/** End marker of global variables save or load. */
#define SLEG_END() {true, SL_END, 0, 0, 0, 0, NULL, 0}
#define SLEG_END() {true, SL_END, 0, 0, 0, 0, NULL, 0, {}}
/**
* Checks whether the savegame is below \a major.\a minor.
@ -471,10 +502,10 @@ static inline bool IsSavegameVersionBefore(uint16 major, byte minor = 0)
* @param version_to Highest version number that falls within the range.
* @return Active savegame version falls within the given range.
*/
static inline bool SlIsObjectCurrentlyValid(uint16 version_from, uint16 version_to)
static inline bool SlIsObjectCurrentlyValid(uint16 version_from, uint16 version_to, SlXvFeatureTest ext_feature_test)
{
extern const uint16 SAVEGAME_VERSION;
if (SAVEGAME_VERSION < version_from || SAVEGAME_VERSION > version_to) return false;
if (!ext_feature_test.IsFeaturePresent(SAVEGAME_VERSION, version_from, version_to)) return false;
return true;
}
@ -537,12 +568,64 @@ size_t SlCalcObjLength(const void *object, const SaveLoad *sld);
byte SlReadByte();
void SlWriteByte(byte b);
static inline int SlReadUint16()
{
int x = SlReadByte() << 8;
return x | SlReadByte();
}
static inline uint32 SlReadUint32()
{
uint32 x = SlReadUint16() << 16;
return x | SlReadUint16();
}
static inline uint64 SlReadUint64()
{
uint32 x = SlReadUint32();
uint32 y = SlReadUint32();
return (uint64)x << 32 | y;
}
static inline void SlWriteUint16(uint16 v)
{
SlWriteByte(GB(v, 8, 8));
SlWriteByte(GB(v, 0, 8));
}
static inline void SlWriteUint32(uint32 v)
{
SlWriteUint16(GB(v, 16, 16));
SlWriteUint16(GB(v, 0, 16));
}
static inline void SlWriteUint64(uint64 x)
{
SlWriteUint32((uint32)(x >> 32));
SlWriteUint32((uint32)x);
}
/**
* Read in bytes from the file/data structure but don't do
* anything with them, discarding them in effect
* @param length The amount of bytes that is being treated this way
*/
static inline void SlSkipBytes(size_t length)
{
for (; length != 0; length--) SlReadByte();
}
size_t SlGetBytesRead();
size_t SlGetBytesWritten();
void SlGlobList(const SaveLoadGlobVarList *sldg);
void SlArray(void *array, size_t length, VarType conv);
void SlObject(void *object, const SaveLoad *sld);
bool SlObjectMember(void *object, const SaveLoad *sld);
void NORETURN SlError(StringID string, const char *extra_msg = NULL);
void NORETURN SlErrorCorrupt(const char *msg);
void NORETURN SlError(StringID string, const char *extra_msg = NULL, bool already_malloced = false);
void NORETURN SlErrorCorrupt(const char *msg, bool already_malloced = false);
void CDECL NORETURN SlErrorFmt(StringID string, const char *msg, ...) WARN_FORMAT(2, 3);
void CDECL NORETURN SlErrorCorruptFmt(const char *msg, ...) WARN_FORMAT(1, 2);
bool SaveloadCrashWithMissingNewGRFs();

@ -64,6 +64,8 @@
#include "roadveh.h"
#include "fios.h"
#include "strings_func.h"
#include "string_func.h"
#include "debug.h"
#include "void_map.h"
#include "station_base.h"
@ -71,6 +73,9 @@
#include "table/strings.h"
#include "table/settings.h"
#include <algorithm>
#include <vector>
#include "safeguards.h"
ClientSettings _settings_client;
@ -486,7 +491,7 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
const SettingDescBase *sdb = &sd->desc;
const SaveLoad *sld = &sd->save;
if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to, sld->ext_feature_test)) continue;
/* For settings.xx.yy load the settings from [xx] yy = ? */
s = strchr(sdb->name, '.');
@ -585,7 +590,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
/* If the setting is not saved to the configuration
* file, just continue with the next setting */
if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to, sld->ext_feature_test)) continue;
if (sld->conv & SLF_NOT_IN_CONFIG) continue;
/* XXX - wtf is this?? (group override?) */
@ -1381,7 +1386,7 @@ static void HandleOldDiffCustom(bool savegame)
for (uint i = 0; i < options_to_load; i++) {
const SettingDesc *sd = &_settings[i];
/* Skip deprecated options */
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to, sd->save.ext_feature_test)) continue;
void *var = GetVariableAddress(savegame ? &_settings_game : &_settings_newgame, &sd->save);
Write_ValidateSetting(var, sd, (int32)((i == 4 ? 1000 : 1) * _old_diff_custom[i]));
}
@ -1839,7 +1844,7 @@ CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
const SettingDesc *sd = GetSettingDescription(p1);
if (sd == NULL) return CMD_ERROR;
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) return CMD_ERROR;
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to, sd->save.ext_feature_test)) return CMD_ERROR;
if (!sd->IsEditable(true)) return CMD_ERROR;
@ -2050,13 +2055,13 @@ const SettingDesc *GetSettingFromName(const char *name, uint *i)
/* First check all full names */
for (*i = 0, sd = _settings; sd->save.cmd != SL_END; sd++, (*i)++) {
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to, sd->save.ext_feature_test)) continue;
if (strcmp(sd->desc.name, name) == 0) return sd;
}
/* Then check the shortcut variant of the name. */
for (*i = 0, sd = _settings; sd->save.cmd != SL_END; sd++, (*i)++) {
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to, sd->save.ext_feature_test)) continue;
const char *short_name = strchr(sd->desc.name, '.');
if (short_name != NULL) {
short_name++;
@ -2067,7 +2072,7 @@ const SettingDesc *GetSettingFromName(const char *name, uint *i)
if (strncmp(name, "company.", 8) == 0) name += 8;
/* And finally the company-based settings */
for (*i = 0, sd = _company_settings; sd->save.cmd != SL_END; sd++, (*i)++) {
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to, sd->save.ext_feature_test)) continue;
if (strcmp(sd->desc.name, name) == 0) return sd;
}
@ -2161,7 +2166,7 @@ void IConsoleListSettings(const char *prefilter)
IConsolePrintF(CC_WARNING, "All settings with their current value:");
for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to, sd->save.ext_feature_test)) continue;
if (prefilter != NULL && strstr(sd->desc.name, prefilter) == NULL) continue;
char value[80];
const void *ptr = GetVariableAddress(&GetGameSettings(), &sd->save);
@ -2180,7 +2185,7 @@ void IConsoleListSettings(const char *prefilter)
}
/**
* Save and load handler for settings
* Save and load handler for settings, except for those which go in the PATX chunk
* @param osd SettingDesc struct containing all information
* @param object can be either NULL in which case we load global variables or
* a pointer to a struct which is getting saved
@ -2188,6 +2193,7 @@ void IConsoleListSettings(const char *prefilter)
static void LoadSettings(const SettingDesc *osd, void *object)
{
for (; osd->save.cmd != SL_END; osd++) {
if (osd->patx_name != NULL) continue;
const SaveLoad *sld = &osd->save;
void *ptr = GetVariableAddress(object, sld);
@ -2197,7 +2203,7 @@ static void LoadSettings(const SettingDesc *osd, void *object)
}
/**
* Save and load handler for settings
* Save and load handler for settings, except for those which go in the PATX chunk
* @param sd SettingDesc struct containing all information
* @param object can be either NULL in which case we load global variables or
* a pointer to a struct which is getting saved
@ -2209,16 +2215,195 @@ static void SaveSettings(const SettingDesc *sd, void *object)
const SettingDesc *i;
size_t length = 0;
for (i = sd; i->save.cmd != SL_END; i++) {
if (i->patx_name != NULL) continue;
length += SlCalcObjMemberLength(object, &i->save);
}
SlSetLength(length);
for (i = sd; i->save.cmd != SL_END; i++) {
if (i->patx_name != NULL) continue;
void *ptr = GetVariableAddress(object, &i->save);
SlObjectMember(ptr, &i->save);
}
}
/** @file
*
* The PATX chunk stores additional settings in an unordered format
* which is tolerant of extra, missing or reordered settings.
* Additional settings generally means those that aren't in trunk.
*
* The PATX chunk contents has the following format:
*
* uint32 chunk flags
* uint32 number of settings
* For each of N settings:
* uint32 setting flags
* SLE_STR setting name
* uint32 length of setting field
* N bytes setting field
*/
/** Sorted list of PATX settings, generated by MakeSettingsPatxList */
static std::vector<const SettingDesc *> _sorted_patx_settings;
/**
* Prepare a sorted list of settings to be potentially be loaded out of the PATX chunk
* This is to enable efficient lookup of settings by name
* This is stored in _sorted_patx_settings
*/
static void MakeSettingsPatxList(const SettingDesc *sd)
{
static const SettingDesc *previous = NULL;
if (sd == previous) return;
_sorted_patx_settings.clear();
for (const SettingDesc *desc = sd; desc->save.cmd != SL_END; desc++) {
if (desc->patx_name == NULL) continue;
_sorted_patx_settings.push_back(desc);
}
// this makes me miss lambdas :/
struct StringSorter {
bool operator()(const SettingDesc *a, const SettingDesc *b)
{
return strcmp(a->patx_name, b->patx_name) < 0;
}
};
std::sort(_sorted_patx_settings.begin(), _sorted_patx_settings.end(), StringSorter());
}
/**
* Load handler for settings which go in the PATX chunk
* @param osd SettingDesc struct containing all information
* @param object can be either NULL in which case we load global variables or
* a pointer to a struct which is getting saved
*/
static void LoadSettingsPatx(const SettingDesc *sd, void *object)
{
MakeSettingsPatxList(sd);
struct SettingsPatxLoad {
uint32 flags;
char name[256];
uint32 setting_length;
};
SettingsPatxLoad current_setting;
static const SaveLoad _settings_patx_desc[] = {
SLE_VAR(SettingsPatxLoad, flags, SLE_UINT32),
SLE_STR(SettingsPatxLoad, name, SLE_STRB, 256),
SLE_VAR(SettingsPatxLoad, setting_length, SLE_UINT32),
SLE_END()
};
uint32 flags = SlReadUint32();
// flags are not in use yet, reserve for future expansion
if (flags != 0) SlErrorCorruptFmt("PATX chunk: unknown chunk header flags: 0x%X", flags);
uint32 settings_count = SlReadUint32();
for (uint32 i = 0; i < settings_count; i++) {
SlObject(&current_setting, _settings_patx_desc);
// flags are not in use yet, reserve for future expansion
if (current_setting.flags != 0) SlErrorCorruptFmt("PATX chunk: unknown setting header flags: 0x%X", current_setting.flags);
// now try to find corresponding setting, this would be much easier with C++11 support...
bool exact_match = false;
struct StringSearcher {
bool &m_exact_match;
StringSearcher(bool &exact_match)
: m_exact_match(exact_match) { }
bool operator()(const SettingDesc *a, const char *b)
{
int result = strcmp(a->patx_name, b);
if (result == 0) m_exact_match = true;
return result < 0;
}
};
std::vector<const SettingDesc *>::iterator iter = std::lower_bound(_sorted_patx_settings.begin(), _sorted_patx_settings.end(), current_setting.name, StringSearcher(exact_match));
if (exact_match) {
assert(iter != _sorted_patx_settings.end());
// found setting
const SaveLoad *sld = &((*iter)->save);
size_t read = SlGetBytesRead();
void *ptr = GetVariableAddress(object, sld);
SlObjectMember(ptr, sld);
if (SlGetBytesRead() != read + current_setting.setting_length) {
SlErrorCorruptFmt("PATX chunk: setting read length mismatch for setting: '%s'", current_setting.name);
}
if (IsNumericType(sld->conv)) Write_ValidateSetting(ptr, *iter, ReadValue(ptr, sld->conv));
} else {
DEBUG(sl, 1, "PATX chunk: Could not find setting: '%s', ignoring", current_setting.name);
SlSkipBytes(current_setting.setting_length);
}
}
}
/**
* Save handler for settings which go in the PATX chunk
* @param sd SettingDesc struct containing all information
* @param object can be either NULL in which case we load global variables or
* a pointer to a struct which is getting saved
*/
static void SaveSettingsPatx(const SettingDesc *sd, void *object)
{
struct SettingsPatxSave {
uint32 flags;
const char *name;
uint32 setting_length;
};
SettingsPatxSave current_setting;
static const SaveLoad _settings_patx_desc[] = {
SLE_VAR(SettingsPatxSave, flags, SLE_UINT32),
SLE_STR(SettingsPatxSave, name, SLE_STR, 0),
SLE_VAR(SettingsPatxSave, setting_length, SLE_UINT32),
SLE_END()
};
struct SettingToAdd {
const SettingDesc *setting;
uint32 setting_length;
};
std::vector<SettingToAdd> settings_to_add;
size_t length = 8;
for (const SettingDesc *desc = sd; desc->save.cmd != SL_END; desc++) {
if (desc->patx_name == NULL) continue;
uint32 setting_length = SlCalcObjMemberLength(object, &desc->save);
if (!setting_length) continue;
current_setting.name = desc->patx_name;
// add length of setting header
length += SlCalcObjLength(&current_setting, _settings_patx_desc);
// add length of actual setting
length += setting_length;
settings_to_add.push_back({ desc, setting_length });
}
SlSetLength(length);
SlWriteUint32(0); // flags
SlWriteUint32(settings_to_add.size()); // settings count
for (size_t i = 0; i < settings_to_add.size(); i++) {
const SettingDesc *desc = settings_to_add[i].setting;
current_setting.flags = 0;
current_setting.name = desc->patx_name;
current_setting.setting_length = settings_to_add[i].setting_length;
SlObject(&current_setting, _settings_patx_desc);
void *ptr = GetVariableAddress(object, &desc->save);
SlObjectMember(ptr, &desc->save);
}
}
static void Load_OPTS()
{
/* Copy over default setting since some might not get loaded in
@ -2247,6 +2432,21 @@ static void Save_PATS()
SaveSettings(_settings, &_settings_game);
}
static void Load_PATX()
{
LoadSettingsPatx(_settings, &_settings_game);
}
static void Check_PATX()
{
LoadSettingsPatx(_settings, &_load_check_data.settings);
}
static void Save_PATX()
{
SaveSettingsPatx(_settings, &_settings_game);
}
void CheckConfig()
{
/*
@ -2261,7 +2461,8 @@ void CheckConfig()
extern const ChunkHandler _setting_chunk_handlers[] = {
{ 'OPTS', NULL, Load_OPTS, NULL, NULL, CH_RIFF},
{ 'PATS', Save_PATS, Load_PATS, NULL, Check_PATS, CH_RIFF | CH_LAST},
{ 'PATS', Save_PATS, Load_PATS, NULL, Check_PATS, CH_RIFF},
{ 'PATX', Save_PATX, Load_PATX, NULL, Check_PATX, CH_RIFF | CH_LAST},
};
static bool IsSignedVarMemType(VarType vt)

@ -111,6 +111,7 @@ struct SettingDescBase {
struct SettingDesc {
SettingDescBase desc; ///< Settings structure (going to configuration file)
SaveLoad save; ///< Internal structure (going to savegame, parts to config)
const char *patx_name; ///< Name to save/load setting from in PATX chunk, if NULL save/load from PATS chunk as normal
bool IsEditable(bool do_command = false) const;
SettingType GetType() const;

@ -131,6 +131,16 @@ char *stredup(const char *s, const char *last)
return tmp;
}
char *str_vfmt(const char *str, va_list va)
{
char buf[4096];
int len = vseprintf(buf, lastof(buf), str, va);
char *p = MallocT<char>(len + 1);
memcpy(p, buf, len + 1);
return p;
}
/**
* Format, "printf", into a newly allocated string.
* @param str The formatting string.
@ -138,15 +148,11 @@ char *stredup(const char *s, const char *last)
*/
char *CDECL str_fmt(const char *str, ...)
{
char buf[4096];
va_list va;
va_start(va, str);
int len = vseprintf(buf, lastof(buf), str, va);
char *output = str_vfmt(str, va);
va_end(va);
char *p = MallocT<char>(len + 1);
memcpy(p, buf, len + 1);
return p;
return output;
}
/**

@ -39,6 +39,7 @@ int CDECL seprintf(char *str, const char *last, const char *format, ...) WARN_FO
int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap);
char *CDECL str_fmt(const char *str, ...) WARN_FORMAT(1, 2);
char *str_vfmt(const char *str, va_list ap);
void str_validate(char *str, const char *last, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
void ValidateString(const char *str);

@ -18,8 +18,8 @@ static const SettingDesc _company_settings[] = {
[post-amble]
};
[templates]
SDT_BOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDT_BOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDT_END = SDT_END()
[defaults]
@ -34,6 +34,7 @@ load = NULL
from = 0
to = SL_MAX_VERSION
cat = SC_ADVANCED
extver = {}

@ -11,9 +11,9 @@ static const SettingDesc _currency_settings[] = {
[post-amble]
};
[templates]
SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDT_CHR = SDT_CHR($base, $var, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDT_STR = SDT_STR($base, $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDT_CHR = SDT_CHR($base, $var, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDT_STR = SDT_STR($base, $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDT_END = SDT_END()
[defaults]
@ -28,6 +28,7 @@ load = NULL
from = 0
to = SL_MAX_VERSION
cat = SC_ADVANCED
extver = {}

@ -41,13 +41,13 @@ static const SettingDesc _gameopt_settings[] = {
[post-amble]
};
[templates]
SDTG_GENERAL = SDTG_GENERAL($name, $sdt_cmd, $sle_cmd, $type, $flags, $guiflags, $var, $length, $def, $min, $max, $interval, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTG_VAR = SDTG_VAR($name, $type, $flags, $guiflags, $var, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDT_NULL = SDT_NULL($length, $from, $to),
SDTC_OMANY = SDTC_OMANY( $var, $type, $flags, $guiflags, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTG_OMANY = SDTG_OMANY($name, $type, $flags, $guiflags, $var, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDT_OMANY = SDT_OMANY($base, $var, $type, $flags, $guiflags, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $load, $cat),
SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTG_GENERAL = SDTG_GENERAL($name, $sdt_cmd, $sle_cmd, $type, $flags, $guiflags, $var, $length, $def, $min, $max, $interval, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDTG_VAR = SDTG_VAR($name, $type, $flags, $guiflags, $var, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDT_NULL = SDT_NULL($length, $from, $to, $extver),
SDTC_OMANY = SDTC_OMANY( $var, $type, $flags, $guiflags, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDTG_OMANY = SDTG_OMANY($name, $type, $flags, $guiflags, $var, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDT_OMANY = SDT_OMANY($base, $var, $type, $flags, $guiflags, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $load, $cat, $extver, NULL),
SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDT_END = SDT_END()
[defaults]
@ -62,6 +62,7 @@ load = NULL
from = 0
to = SL_MAX_VERSION
cat = SC_ADVANCED
extver = {}

@ -15,12 +15,12 @@ static const SettingDescGlobVarList _misc_settings[] = {
[post-amble]
};
[templates]
SDTG_LIST = SDTG_LIST($name, $type, $length, $flags, $guiflags, $var, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTG_MMANY = SDTG_MMANY($name, $type, $flags, $guiflags, $var, $def, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTG_OMANY = SDTG_OMANY($name, $type, $flags, $guiflags, $var, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTG_STR = SDTG_STR($name, $type, $flags, $guiflags, $var, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTG_BOOL = SDTG_BOOL($name, $flags, $guiflags, $var, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTG_VAR = SDTG_VAR($name, $type, $flags, $guiflags, $var, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTG_LIST = SDTG_LIST($name, $type, $length, $flags, $guiflags, $var, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDTG_MMANY = SDTG_MMANY($name, $type, $flags, $guiflags, $var, $def, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDTG_OMANY = SDTG_OMANY($name, $type, $flags, $guiflags, $var, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDTG_STR = SDTG_STR($name, $type, $flags, $guiflags, $var, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDTG_BOOL = SDTG_BOOL($name, $flags, $guiflags, $var, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDTG_VAR = SDTG_VAR($name, $type, $flags, $guiflags, $var, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDTG_END = SDTG_END()
[defaults]
@ -35,6 +35,7 @@ load = NULL
from = 0
to = SL_MAX_VERSION
cat = SC_ADVANCED
extver = {}

@ -61,76 +61,76 @@ static size_t ConvertLandscape(const char *value);
/* Macros for various objects to go in the configuration file.
* This section is for global variables */
#define SDTG_GENERAL(name, sdt_cmd, sle_cmd, type, flags, guiflags, var, length, def, min, max, interval, full, str, strhelp, strval, proc, from, to, cat)\
{NSD_GENERAL(name, def, sdt_cmd, guiflags, min, max, interval, full, str, strhelp, strval, proc, NULL, cat), SLEG_GENERAL(sle_cmd, var, type | flags, length, from, to)}
#define SDTG_GENERAL(name, sdt_cmd, sle_cmd, type, flags, guiflags, var, length, def, min, max, interval, full, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
{NSD_GENERAL(name, def, sdt_cmd, guiflags, min, max, interval, full, str, strhelp, strval, proc, NULL, cat), SLEG_GENERAL_X(sle_cmd, var, type | flags, length, from, to, extver), patxname}
#define SDTG_VAR(name, type, flags, guiflags, var, def, min, max, interval, str, strhelp, strval, proc, from, to, cat)\
SDTG_GENERAL(name, SDT_NUMX, SL_VAR, type, flags, guiflags, var, 0, def, min, max, interval, NULL, str, strhelp, strval, proc, from, to, cat)
#define SDTG_VAR(name, type, flags, guiflags, var, def, min, max, interval, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDTG_GENERAL(name, SDT_NUMX, SL_VAR, type, flags, guiflags, var, 0, def, min, max, interval, NULL, str, strhelp, strval, proc, from, to, cat, extver, patxname)
#define SDTG_BOOL(name, flags, guiflags, var, def, str, strhelp, strval, proc, from, to, cat)\
SDTG_GENERAL(name, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, var, 0, def, 0, 1, 0, NULL, str, strhelp, strval, proc, from, to, cat)
#define SDTG_BOOL(name, flags, guiflags, var, def, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDTG_GENERAL(name, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, var, 0, def, 0, 1, 0, NULL, str, strhelp, strval, proc, from, to, cat, extver, patxname)
#define SDTG_LIST(name, type, length, flags, guiflags, var, def, str, strhelp, strval, proc, from, to, cat)\
SDTG_GENERAL(name, SDT_INTLIST, SL_ARR, type, flags, guiflags, var, length, def, 0, 0, 0, NULL, str, strhelp, strval, proc, from, to, cat)
#define SDTG_LIST(name, type, length, flags, guiflags, var, def, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDTG_GENERAL(name, SDT_INTLIST, SL_ARR, type, flags, guiflags, var, length, def, 0, 0, 0, NULL, str, strhelp, strval, proc, from, to, cat, extver, patxname)
#define SDTG_STR(name, type, flags, guiflags, var, def, str, strhelp, strval, proc, from, to, cat)\
SDTG_GENERAL(name, SDT_STRING, SL_STR, type, flags, guiflags, var, lengthof(var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, from, to, cat)
#define SDTG_STR(name, type, flags, guiflags, var, def, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDTG_GENERAL(name, SDT_STRING, SL_STR, type, flags, guiflags, var, lengthof(var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, from, to, cat, extver, patxname)
#define SDTG_OMANY(name, type, flags, guiflags, var, def, max, full, str, strhelp, strval, proc, from, to, cat)\
SDTG_GENERAL(name, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, var, 0, def, 0, max, 0, full, str, strhelp, strval, proc, from, to, cat)
#define SDTG_OMANY(name, type, flags, guiflags, var, def, max, full, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDTG_GENERAL(name, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, var, 0, def, 0, max, 0, full, str, strhelp, strval, proc, from, to, cat, extver, patxname)
#define SDTG_MMANY(name, type, flags, guiflags, var, def, full, str, strhelp, strval, proc, from, to, cat)\
SDTG_GENERAL(name, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, var, 0, def, 0, 0, 0, full, str, strhelp, strval, proc, from, to, cat)
#define SDTG_MMANY(name, type, flags, guiflags, var, def, full, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDTG_GENERAL(name, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, var, 0, def, 0, 0, 0, full, str, strhelp, strval, proc, from, to, cat, extver, patxname)
#define SDTG_NULL(length, from, to)\
{{"", NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, STR_NULL, STR_NULL, NULL, NULL, SC_NONE}, SLEG_NULL(length, from, to)}
#define SDTG_NULL(length, from, to, extver)\
{{"", NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, STR_NULL, STR_NULL, NULL, NULL, SC_NONE}, SLEG_NULL_X(length, from, to, extver), NULL}
#define SDTG_END() {{NULL, NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, STR_NULL, STR_NULL, NULL, NULL, SC_NONE}, SLEG_END()}
#define SDTG_END() {{NULL, NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, STR_NULL, STR_NULL, NULL, NULL, SC_NONE}, SLEG_END(), NULL}
/* Macros for various objects to go in the configuration file.
* This section is for structures where their various members are saved */
#define SDT_GENERAL(name, sdt_cmd, sle_cmd, type, flags, guiflags, base, var, length, def, min, max, interval, full, str, strhelp, strval, proc, load, from, to, cat)\
{NSD_GENERAL(name, def, sdt_cmd, guiflags, min, max, interval, full, str, strhelp, strval, proc, load, cat), SLE_GENERAL(sle_cmd, base, var, type | flags, length, from, to)}
#define SDT_GENERAL(name, sdt_cmd, sle_cmd, type, flags, guiflags, base, var, length, def, min, max, interval, full, str, strhelp, strval, proc, load, from, to, cat, extver, patxname)\
{NSD_GENERAL(name, def, sdt_cmd, guiflags, min, max, interval, full, str, strhelp, strval, proc, load, cat), SLE_GENERAL_X(sle_cmd, base, var, type | flags, length, from, to, extver), patxname}
#define SDT_VAR(base, var, type, flags, guiflags, def, min, max, interval, str, strhelp, strval, proc, from, to, cat)\
SDT_GENERAL(#var, SDT_NUMX, SL_VAR, type, flags, guiflags, base, var, 1, def, min, max, interval, NULL, str, strhelp, strval, proc, NULL, from, to, cat)
#define SDT_VAR(base, var, type, flags, guiflags, def, min, max, interval, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDT_GENERAL(#var, SDT_NUMX, SL_VAR, type, flags, guiflags, base, var, 1, def, min, max, interval, NULL, str, strhelp, strval, proc, NULL, from, to, cat, extver, patxname)
#define SDT_BOOL(base, var, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat)\
SDT_GENERAL(#var, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, base, var, 1, def, 0, 1, 0, NULL, str, strhelp, strval, proc, NULL, from, to, cat)
#define SDT_BOOL(base, var, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDT_GENERAL(#var, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, base, var, 1, def, 0, 1, 0, NULL, str, strhelp, strval, proc, NULL, from, to, cat, extver, patxname)
#define SDT_LIST(base, var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat)\
SDT_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, base, var, lengthof(((base*)8)->var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, NULL, from, to, cat)
#define SDT_LIST(base, var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDT_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, base, var, lengthof(((base*)8)->var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, NULL, from, to, cat, extver, patxname)
#define SDT_STR(base, var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat)\
SDT_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, base, var, lengthof(((base*)8)->var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, NULL, from, to, cat)
#define SDT_STR(base, var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDT_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, base, var, lengthof(((base*)8)->var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, NULL, from, to, cat, extver, patxname)
#define SDT_CHR(base, var, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat)\
SDT_GENERAL(#var, SDT_STRING, SL_VAR, SLE_CHAR, flags, guiflags, base, var, 1, def, 0, 0, 0, NULL, str, strhelp, strval, proc, NULL, from, to, cat)
#define SDT_CHR(base, var, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDT_GENERAL(#var, SDT_STRING, SL_VAR, SLE_CHAR, flags, guiflags, base, var, 1, def, 0, 0, 0, NULL, str, strhelp, strval, proc, NULL, from, to, cat, extver, patxname)
#define SDT_OMANY(base, var, type, flags, guiflags, def, max, full, str, strhelp, strval, proc, from, to, load, cat)\
SDT_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, base, var, 1, def, 0, max, 0, full, str, strhelp, strval, proc, load, from, to, cat)
#define SDT_OMANY(base, var, type, flags, guiflags, def, max, full, str, strhelp, strval, proc, from, to, load, cat, extver, patxname)\
SDT_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, base, var, 1, def, 0, max, 0, full, str, strhelp, strval, proc, load, from, to, cat, extver, patxname)
#define SDT_MMANY(base, var, type, flags, guiflags, def, full, str, proc, strhelp, strval, from, to, cat)\
SDT_GENERAL(#var, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, base, var, 1, def, 0, 0, 0, full, str, strhelp, strval, proc, NULL, from, to, cat)
#define SDT_MMANY(base, var, type, flags, guiflags, def, full, str, proc, strhelp, strval, from, to, cat, extver, patxname)\
SDT_GENERAL(#var, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, base, var, 1, def, 0, 0, 0, full, str, strhelp, strval, proc, NULL, from, to, cat, extver, patxname)
#define SDT_NULL(length, from, to)\
{{"", NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, STR_NULL, STR_NULL, NULL, NULL, SC_NONE}, SLE_CONDNULL(length, from, to)}
#define SDT_NULL(length, from, to, extver)\
{{"", NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, STR_NULL, STR_NULL, NULL, NULL, SC_NONE}, SLE_CONDNULL_X(length, from, to, extver), NULL}
#define SDTC_VAR(var, type, flags, guiflags, def, min, max, interval, str, strhelp, strval, proc, from, to, cat)\
SDTG_GENERAL(#var, SDT_NUMX, SL_VAR, type, flags, guiflags, _settings_client.var, 1, def, min, max, interval, NULL, str, strhelp, strval, proc, from, to, cat)
#define SDTC_VAR(var, type, flags, guiflags, def, min, max, interval, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDTG_GENERAL(#var, SDT_NUMX, SL_VAR, type, flags, guiflags, _settings_client.var, 1, def, min, max, interval, NULL, str, strhelp, strval, proc, from, to, cat, extver, patxname)
#define SDTC_BOOL(var, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat)\
SDTG_GENERAL(#var, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, _settings_client.var, 1, def, 0, 1, 0, NULL, str, strhelp, strval, proc, from, to, cat)
#define SDTC_BOOL(var, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDTG_GENERAL(#var, SDT_BOOLX, SL_VAR, SLE_BOOL, flags, guiflags, _settings_client.var, 1, def, 0, 1, 0, NULL, str, strhelp, strval, proc, from, to, cat, extver, patxname)
#define SDTC_LIST(var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat)\
SDTG_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, _settings_client.var, lengthof(_settings_client.var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, from, to, cat)
#define SDTC_LIST(var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDTG_GENERAL(#var, SDT_INTLIST, SL_ARR, type, flags, guiflags, _settings_client.var, lengthof(_settings_client.var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, from, to, cat, extver, patxname)
#define SDTC_STR(var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat)\
SDTG_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, _settings_client.var, lengthof(_settings_client.var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, from, to, cat)
#define SDTC_STR(var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDTG_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, _settings_client.var, lengthof(_settings_client.var), def, 0, 0, 0, NULL, str, strhelp, strval, proc, from, to, cat, extver, patxname)
#define SDTC_OMANY(var, type, flags, guiflags, def, max, full, str, strhelp, strval, proc, from, to, cat)\
SDTG_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, _settings_client.var, 1, def, 0, max, 0, full, str, strhelp, strval, proc, from, to, cat)
#define SDTC_OMANY(var, type, flags, guiflags, def, max, full, str, strhelp, strval, proc, from, to, cat, extver, patxname)\
SDTG_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, _settings_client.var, 1, def, 0, max, 0, full, str, strhelp, strval, proc, from, to, cat, extver, patxname)
#define SDT_END() {{NULL, NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, STR_NULL, STR_NULL, NULL, NULL, SC_NONE}, SLE_END()}
#define SDT_END() {{NULL, NULL, {0}, {0}, 0, 0, 0, NULL, STR_NULL, STR_NULL, STR_NULL, NULL, NULL, SC_NONE}, SLE_END(), NULL}

@ -64,19 +64,19 @@ const SettingDesc _settings[] = {
[post-amble]
};
[templates]
SDTG_BOOL = SDTG_BOOL($name, $flags, $guiflags, $var, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTG_VAR = SDTG_VAR($name, $type, $flags, $guiflags, $var, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTG_OMANY = SDTG_OMANY($name, $type, $flags, $guiflags, $var, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTC_BOOL = SDTC_BOOL( $var, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTC_LIST = SDTC_LIST( $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTC_OMANY = SDTC_OMANY( $var, $type, $flags, $guiflags, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTC_STR = SDTC_STR( $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTC_VAR = SDTC_VAR( $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDT_BOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDT_OMANY = SDT_OMANY($base, $var, $type, $flags, $guiflags, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $load, $cat),
SDT_STR = SDT_STR($base, $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDT_NULL = SDT_NULL($length, $from, $to),
SDTG_BOOL = SDTG_BOOL($name, $flags, $guiflags, $var, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, $patxname),
SDTG_VAR = SDTG_VAR($name, $type, $flags, $guiflags, $var, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, $patxname),
SDTG_OMANY = SDTG_OMANY($name, $type, $flags, $guiflags, $var, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, $patxname),
SDTC_BOOL = SDTC_BOOL( $var, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, $patxname),
SDTC_LIST = SDTC_LIST( $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, $patxname),
SDTC_OMANY = SDTC_OMANY( $var, $type, $flags, $guiflags, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, $patxname),
SDTC_STR = SDTC_STR( $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, $patxname),
SDTC_VAR = SDTC_VAR( $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, $patxname),
SDT_BOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, $patxname),
SDT_OMANY = SDT_OMANY($base, $var, $type, $flags, $guiflags, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $load, $cat, $extver, $patxname),
SDT_STR = SDT_STR($base, $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, $patxname),
SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, $patxname),
SDT_NULL = SDT_NULL($length, $from, $to, $extver),
SDT_END = SDT_END()
[defaults]
@ -91,6 +91,8 @@ load = NULL
from = 0
to = SL_MAX_VERSION
cat = SC_ADVANCED
extver = {}
patxname = NULL

@ -17,8 +17,8 @@ static const SettingDescGlobVarList _win32_settings[] = {
};
#endif /* WIN32 */
[templates]
SDTG_BOOL = SDTG_BOOL($name, $flags, $guiflags, $var, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTG_VAR = SDTG_VAR($name, $type, $flags, $guiflags, $var, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDTG_BOOL = SDTG_BOOL($name, $flags, $guiflags, $var, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDTG_VAR = SDTG_VAR($name, $type, $flags, $guiflags, $var, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDTG_END = SDTG_END()
[defaults]
@ -33,6 +33,7 @@ load = NULL
from = 0
to = SL_MAX_VERSION
cat = SC_ADVANCED
extver = {}

@ -12,8 +12,8 @@ static const SettingDesc _window_settings[] = {
[post-amble]
};
[templates]
SDT_BOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat),
SDT_BOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extver, NULL),
SDT_END = SDT_END()
[defaults]
@ -29,6 +29,7 @@ load = NULL
from = 0
to = SL_MAX_VERSION
cat = SC_ADVANCED
extver = {}

Loading…
Cancel
Save