Changeset - r28772:5bdd1bea8cf0
[Not reviewed]
master
0 2 0
Rubidium - 10 months ago 2024-02-16 06:28:32
rubidium@openttd.org
Codechange: Add support for NULL strings in SaveLoadCompat
2 files changed with 27 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/saveload/saveload.cpp
Show inline comments
 
@@ -623,9 +623,16 @@ static inline byte SlCalcConvFileLen(Var
 
{
 
	static const byte conv_file_size[] = {0, 1, 1, 2, 2, 4, 4, 8, 8, 2};
 

	
 
	uint8_t type = GetVarFileType(conv);
 
	assert(type < lengthof(conv_file_size));
 
	return conv_file_size[type];
 
	switch (GetVarFileType(conv)) {
 
		case SLE_FILE_STRING:
 
			return SlReadArrayLength();
 

	
 
		default:
 
			uint8_t type = GetVarFileType(conv);
 
			if (type >= lengthof(conv_file_size)) fmt::println("{}", type);
 
			assert(type < lengthof(conv_file_size));
 
			return conv_file_size[type];
 
	}
 
}
 

	
 
/** Return the size in bytes of a reference (pointer) */
 
@@ -1864,7 +1871,7 @@ std::vector<SaveLoad> SlCompatTableHeade
 
			/* In old savegames there can be data we no longer care for. We
 
			 * skip this by simply reading the amount of bytes indicated and
 
			 * send those to /dev/null. */
 
			saveloads.push_back({"", SL_NULL, SLE_FILE_U8 | SLE_VAR_NULL, slc.length, slc.version_from, slc.version_to, 0, nullptr, 0, nullptr});
 
			saveloads.push_back({"", SL_NULL, GetVarFileType(slc.null_type) | SLE_VAR_NULL, slc.null_length, slc.version_from, slc.version_to, 0, nullptr, 0, nullptr});
 
		} else {
 
			auto sld_it = key_lookup.find(slc.name);
 
			/* If this branch triggers, it means that an entry in the
src/saveload/saveload.h
Show inline comments
 
@@ -715,10 +715,11 @@ struct SaveLoad {
 
 * to make that happen.
 
 */
 
struct SaveLoadCompat {
 
	std::string name;             ///< Name of the field.
 
	uint16_t length;                ///< Length of the NULL field.
 
	std::string name; ///< Name of the field.
 
	VarTypes null_type; ///< The type associated with the NULL field; defaults to SLE_FILE_U8 to just count bytes.
 
	uint16_t null_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.
 
	SaveLoadVersion version_to; ///< Save/load the variable before this savegame version.
 
};
 

	
 
/**
 
@@ -1183,18 +1184,26 @@ inline constexpr bool SlCheckVarSize(Sav
 
 * 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(name) {name, SLE_FILE_U8, 0, SL_MIN_VERSION, SL_MAX_VERSION}
 

	
 
/**
 
 * Empty space in every savegame version.
 
 * @param length Length of the empty space.
 
 * @param length Length of the empty space in bytes.
 
 * @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(length, from, to) {{}, SLE_FILE_U8, length, from, to}
 

	
 
/**
 
 * Empty space in every savegame version that was filled with a string.
 
 * @param length Number of strings in the empty space.
 
 * @param from   First savegame version that has the empty space.
 
 * @param to     Last savegame version that has the empty space.
 
 */
 
#define SLC_NULL_STR(length, from, to) {{}, SLE_FILE_STRING, length, from, to}
 

	
 
/** End marker of compat variables save or load. */
 
#define SLC_END() {{}, 0, SL_MIN_VERSION, SL_MIN_VERSION}
 
#define SLC_END() {{}, 0, 0, SL_MIN_VERSION, SL_MIN_VERSION}
 

	
 
/**
 
 * Checks whether the savegame is below \a major.\a minor.
0 comments (0 inline, 0 general)