Initial stubs for extending the save/load version checking/upgrade code,
with support for tests on individually versioned features as well as savegame versions. This is mainly for improved handling of features added to patchpacks. The current status-quo of picking a random number for the savegame version when releasing a patch breaks loading of savegames from newer trunk savegame versions, with or without the same patch applied, as savegame upgrade code is not run, which can also lead to crashes on load. Instead don't change the savegame version (but set the high bit to keep trunk versions away), but instead include the versions of individual features using a separate mechanism.
This commit is contained in:
@@ -486,7 +486,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 +585,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 +1381,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 +1839,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 +2050,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 +2067,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 +2161,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);
|
||||
|
Reference in New Issue
Block a user