| 232 | typedef bool LoadOldMainProc(LoadgameState &ls); |
| 233 | |
| 234 | bool LoadOldSaveGame(std::string_view file) |
| 235 | { |
| 236 | LoadgameState ls{}; |
| 237 | |
| 238 | Debug(oldloader, 3, "Trying to load a TTD(Patch) savegame"); |
| 239 | |
| 240 | _bump_assert_value = 0; |
| 241 | _settings_game.construction.freeform_edges = false; // disable so we can convert map array (SetTileType is still used) |
| 242 | |
| 243 | /* Open file */ |
| 244 | ls.file = FioFOpenFile(file, "rb", NO_DIRECTORY); |
| 245 | |
| 246 | if (!ls.file.has_value()) { |
| 247 | Debug(oldloader, 0, "Cannot open file '{}'", file); |
| 248 | SetSaveLoadError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE); |
| 249 | return false; |
| 250 | } |
| 251 | |
| 252 | SavegameType type; |
| 253 | std::tie(type, std::ignore) = DetermineOldSavegameTypeAndName(*ls.file); |
| 254 | |
| 255 | LoadOldMainProc *proc = nullptr; |
| 256 | |
| 257 | switch (type) { |
| 258 | case SGT_TTO: proc = &LoadTTOMain; break; |
| 259 | case SGT_TTD: proc = &LoadTTDMain; break; |
| 260 | default: |
| 261 | Debug(oldloader, 0, "Unknown savegame type; cannot be loaded"); |
| 262 | break; |
| 263 | } |
| 264 | |
| 265 | _savegame_type = type; |
| 266 | |
| 267 | bool game_loaded; |
| 268 | try { |
| 269 | game_loaded = proc != nullptr && proc(ls); |
| 270 | } catch (...) { |
| 271 | game_loaded = false; |
| 272 | } |
| 273 | |
| 274 | if (!game_loaded) { |
| 275 | SetSaveLoadError(STR_GAME_SAVELOAD_ERROR_DATA_INTEGRITY_CHECK_FAILED); |
| 276 | ls.file.reset(); |
| 277 | return false; |
| 278 | } |
| 279 | |
| 280 | _pause_mode = PauseMode::SaveLoad; |
| 281 | |
| 282 | return true; |
| 283 | } |
| 284 | |
| 285 | std::string GetOldSaveGameName(std::string_view file) |
| 286 | { |
no test coverage detected