* Actually perform the loading of a "non-old" savegame. * @param reader The filter to read the savegame from. * @param load_check Whether to perform the checking ("preview") or actually load the game. * @return Return the result of the action. #SL_OK or #SL_REINIT ("unload" the game) */
| 3136 | * @return Return the result of the action. #SL_OK or #SL_REINIT ("unload" the game) |
| 3137 | */ |
| 3138 | static SaveOrLoadResult DoLoad(std::shared_ptr<LoadFilter> reader, bool load_check) |
| 3139 | { |
| 3140 | _sl.lf = std::move(reader); |
| 3141 | |
| 3142 | if (load_check) { |
| 3143 | /* Clear previous check data */ |
| 3144 | _load_check_data.Clear(); |
| 3145 | /* Mark SL_LOAD_CHECK as supported for this savegame. */ |
| 3146 | _load_check_data.checkable = true; |
| 3147 | } |
| 3148 | |
| 3149 | uint32_t hdr[2]; |
| 3150 | if (_sl.lf->Read((uint8_t*)hdr, sizeof(hdr)) != sizeof(hdr)) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE); |
| 3151 | |
| 3152 | /* see if we have any loader for this type. */ |
| 3153 | const SaveLoadFormat *fmt = DetermineSaveLoadFormat(hdr[0], hdr[1]); |
| 3154 | |
| 3155 | /* loader for this savegame type is not implemented? */ |
| 3156 | if (fmt->init_load == nullptr) { |
| 3157 | SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, fmt::format("Loader for '{}' is not available.", fmt->name)); |
| 3158 | } |
| 3159 | |
| 3160 | _sl.lf = fmt->init_load(_sl.lf); |
| 3161 | _sl.reader = std::make_unique<ReadBuffer>(_sl.lf); |
| 3162 | _next_offs = 0; |
| 3163 | |
| 3164 | if (!load_check) { |
| 3165 | ResetSaveloadData(); |
| 3166 | |
| 3167 | /* Old maps were hardcoded to 256x256 and thus did not contain |
| 3168 | * any mapsize information. Pre-initialize to 256x256 to not to |
| 3169 | * confuse old games */ |
| 3170 | InitializeGame(256, 256, true, true); |
| 3171 | |
| 3172 | _gamelog.Reset(); |
| 3173 | |
| 3174 | if (IsSavegameVersionBefore(SLV_4)) { |
| 3175 | /* |
| 3176 | * NewGRFs were introduced between 0.3,4 and 0.3.5, which both |
| 3177 | * shared savegame version 4. Anything before that 'obviously' |
| 3178 | * does not have any NewGRFs. Between the introduction and |
| 3179 | * savegame version 41 (just before 0.5) the NewGRF settings |
| 3180 | * were not stored in the savegame and they were loaded by |
| 3181 | * using the settings from the main menu. |
| 3182 | * So, to recap: |
| 3183 | * - savegame version < 4: do not load any NewGRFs. |
| 3184 | * - savegame version >= 41: load NewGRFs from savegame, which is |
| 3185 | * already done at this stage by |
| 3186 | * overwriting the main menu settings. |
| 3187 | * - other savegame versions: use main menu settings. |
| 3188 | * |
| 3189 | * This means that users *can* crash savegame version 4..40 |
| 3190 | * savegames if they set incompatible NewGRFs in the main menu, |
| 3191 | * but can't crash anymore for savegame version < 4 savegames. |
| 3192 | * |
| 3193 | * Note: this is done here because AfterLoadGame is also called |
| 3194 | * for TTO/TTD/TTDP savegames which have their own NewGRF logic. |
| 3195 | */ |
no test coverage detected