* Determines the SaveLoadFormat that is connected to the given tag. * When the given tag is known, that format is chosen and a check on the validity of the version is performed. * Otherwise a fallback to an ancient buggy format using LZO is chosen. * @param tag The tag from the header describing the savegame compression/format. * @param raw_version The raw version from the savegame header. *
| 3095 | * @return The SaveLoadFormat to use for attempting to open the savegame. |
| 3096 | */ |
| 3097 | static const SaveLoadFormat *DetermineSaveLoadFormat(uint32_t tag, uint32_t raw_version) |
| 3098 | { |
| 3099 | auto fmt = std::ranges::find(_saveload_formats, tag, &SaveLoadFormat::tag); |
| 3100 | if (fmt != std::end(_saveload_formats)) { |
| 3101 | /* Check version number */ |
| 3102 | _sl_version = (SaveLoadVersion)(TO_BE32(raw_version) >> 16); |
| 3103 | /* Minor is not used anymore from version 18.0, but it is still needed |
| 3104 | * in versions before that (4 cases) which can't be removed easy. |
| 3105 | * Therefore it is loaded, but never saved (or, it saves a 0 in any scenario). */ |
| 3106 | _sl_minor_version = (TO_BE32(raw_version) >> 8) & 0xFF; |
| 3107 | |
| 3108 | Debug(sl, 1, "Loading savegame version {}", _sl_version); |
| 3109 | |
| 3110 | /* Is the version higher than the current? */ |
| 3111 | if (_sl_version > SAVEGAME_VERSION) SlError(STR_GAME_SAVELOAD_ERROR_TOO_NEW_SAVEGAME); |
| 3112 | if (_sl_version >= SLV_START_PATCHPACKS && _sl_version <= SLV_END_PATCHPACKS) SlError(STR_GAME_SAVELOAD_ERROR_PATCHPACK); |
| 3113 | return fmt; |
| 3114 | } |
| 3115 | |
| 3116 | Debug(sl, 0, "Unknown savegame type, trying to load it as the buggy format"); |
| 3117 | _sl.lf->Reset(); |
| 3118 | _sl_version = SL_MIN_VERSION; |
| 3119 | _sl_minor_version = 0; |
| 3120 | |
| 3121 | /* Try to find the LZO savegame format; it uses 'OTTD' as tag. */ |
| 3122 | fmt = std::ranges::find(_saveload_formats, SAVEGAME_TAG_LZO, &SaveLoadFormat::tag); |
| 3123 | if (fmt == std::end(_saveload_formats)) { |
| 3124 | /* Who removed the LZO savegame format definition? When built without LZO support, |
| 3125 | * the formats must still list it just without a method to read the file. |
| 3126 | * The caller of this function has to check for the existence of load function. */ |
| 3127 | NOT_REACHED(); |
| 3128 | } |
| 3129 | return fmt; |
| 3130 | } |
| 3131 | |
| 3132 | /** |
| 3133 | * Actually perform the loading of a "non-old" savegame. |