1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-24 20:54:08 +01:00

Fix #13849: Settings in old saves could be overridden by defaults. (#13874)

Resolved by resetting settings to default values before the OPTS and PATS chunks are loaded.
This commit is contained in:
Peter Nelson
2025-03-23 15:55:55 +00:00
committed by GitHub
parent 21d2a94809
commit 8b4114d709
4 changed files with 52 additions and 45 deletions

View File

@@ -45,6 +45,7 @@
#include "../strings_type.h"
#include "../newgrf_railtype.h"
#include "../newgrf_roadtype.h"
#include "../settings_internal.h"
#include "saveload_internal.h"
#include "saveload_filter.h"
@@ -2852,6 +2853,22 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
extern bool AfterLoadGame();
extern bool LoadOldSaveGame(const std::string &file);
/**
* Reset all settings to their default, so any settings missing in the savegame
* are their default, and not "value of last game". AfterLoad might still fix
* up values to become non-default, depending on the saveload version.
*/
static void ResetSettings()
{
for (auto &desc : GetSaveLoadSettingTable()) {
const SettingDesc *sd = GetSettingDesc(desc);
if (sd->flags.Test(SettingFlag::NotInSave)) continue;
if (sd->flags.Test(SettingFlag::NoNetworkSync) && _networking && !_network_server) continue;
sd->ResetToDefault(&_settings_game);
}
}
/**
* Clear temporary data that is passed between various saveload phases.
*/
@@ -2861,6 +2878,7 @@ static void ResetSaveloadData()
ClearRailTypeLabelList();
ClearRoadTypeLabelList();
ResetOldWaypoints();
ResetSettings();
}
/**