diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index a5b31e1440..dacc5bc7ae 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -36,8 +36,8 @@ #include "core/String.hpp" #include "core/Util.hpp" #include "drawing/IDrawingEngine.h" +#include "localisation/Localisation.h" #include "FileClassifier.h" -#include "HandleParkLoad.h" #include "network/network.h" #include "object/ObjectManager.h" #include "object/ObjectRepository.h" @@ -559,52 +559,80 @@ namespace OpenRCT2 try { auto result = parkImporter->LoadFromStream(stream, info.Type == FILE_TYPE::SCENARIO, false, path.c_str()); - if (result.Error == PARK_LOAD_ERROR_OK) + // _objectManager->LoadObjects(result.RequiredObjects.data(), result.RequiredObjects.size()); + parkImporter->Import(); + String::Set(gScenarioSavePath, Util::CountOf(gScenarioSavePath), path.c_str()); + String::Set(gCurrentLoadedPath, Util::CountOf(gCurrentLoadedPath), path.c_str()); + gFirstTimeSaving = true; + game_fix_save_vars(); + sprite_position_tween_reset(); + gScreenAge = 0; + gLastAutoSaveUpdate = AUTOSAVE_PAUSE; + if (info.Type == FILE_TYPE::SAVED_GAME) { - parkImporter->Import(); - String::Set(gScenarioSavePath, Util::CountOf(gScenarioSavePath), path.c_str()); - String::Set(gCurrentLoadedPath, Util::CountOf(gCurrentLoadedPath), path.c_str()); - gFirstTimeSaving = true; - game_fix_save_vars(); - sprite_position_tween_reset(); - gScreenAge = 0; - gLastAutoSaveUpdate = AUTOSAVE_PAUSE; - if (info.Type == FILE_TYPE::SAVED_GAME) + if (network_get_mode() == NETWORK_MODE_CLIENT) { - if (network_get_mode() == NETWORK_MODE_CLIENT) - { - network_close(); - } - game_load_init(); - if (network_get_mode() == NETWORK_MODE_SERVER) - { - network_send_map(); - } + network_close(); } - else + game_load_init(); + if (network_get_mode() == NETWORK_MODE_SERVER) { - scenario_begin(); - if (network_get_mode() == NETWORK_MODE_SERVER) - { - network_send_map(); - } - if (network_get_mode() == NETWORK_MODE_CLIENT) - { - network_close(); - } + network_send_map(); } - // This ensures that the newly loaded save reflects the user's - // 'show real names of guests' option, now that it's a global setting - peep_update_names(gConfigGeneral.show_real_names_of_guests); - return true; } else { - handle_park_load_failure_with_title_opt(&result, path, loadTitleScreenFirstOnFail); + scenario_begin(); + if (network_get_mode() == NETWORK_MODE_SERVER) + { + network_send_map(); + } + if (network_get_mode() == NETWORK_MODE_CLIENT) + { + network_close(); + } } + // This ensures that the newly loaded save reflects the user's + // 'show real names of guests' option, now that it's a global setting + peep_update_names(gConfigGeneral.show_real_names_of_guests); + return true; } - catch (const std::exception &e) + catch (const ObjectLoadException& e) { + // This option is used when loading parks from the command line + // to ensure that the title sequence loads before the window + if (loadTitleScreenFirstOnFail) + { + title_load(); + } + // The path needs to be duplicated as it's a const here + // which the window function doesn't like + auto intent = Intent(WC_OBJECT_LOAD_ERROR); + intent.putExtra(INTENT_EXTRA_PATH, path); + intent.putExtra(INTENT_EXTRA_LIST, (void *)e.MissingObjects.data()); + intent.putExtra(INTENT_EXTRA_LIST_COUNT, (uint32)e.MissingObjects.size()); + + auto windowManager = _uiContext->GetWindowManager(); + windowManager->OpenIntent(&intent); + } + catch (const UnsupportedRCTCFlagException& e) + { + // This option is used when loading parks from the command line + // to ensure that the title sequence loads before the window + if (loadTitleScreenFirstOnFail) + { + title_load(); + } + + auto windowManager = _uiContext->GetWindowManager(); + set_format_arg(0, uint16, e.Flag); + windowManager->ShowError(STR_FAILED_TO_LOAD_IMCOMPATIBLE_RCTC_FLAG, STR_NONE); + } + catch (const std::exception& e) + { + // If loading the SV6 or SV4 failed for a reason other than invalid objects + // the current park state will be corrupted so just go back to the title screen. + title_load(); Console::Error::WriteLine(e.what()); } } diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 937456c228..f39b11b8f7 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -245,22 +245,15 @@ namespace Editor */ static bool ReadS6(const char * path) { - ParkLoadResult * loadResult = nullptr; - const char * extension = path_get_extension(path); + auto extension = path_get_extension(path); if (_stricmp(extension, ".sc6") == 0) { - loadResult = load_from_sc6(path); + load_from_sc6(path); } else if (_stricmp(extension, ".sv6") == 0) { - loadResult = load_from_sv6(path); + load_from_sv6(path); } - if (ParkLoadResult_GetError(loadResult) != PARK_LOAD_ERROR_OK) - { - ParkLoadResult_Delete(loadResult); - return false; - } - ParkLoadResult_Delete(loadResult); ClearMapForEditing(true); diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index b0934b7565..8123a8ea04 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -25,7 +25,6 @@ #include "Editor.h" #include "FileClassifier.h" #include "Game.h" -#include "HandleParkLoad.h" #include "Input.h" #include "interface/Screenshot.h" #include "interface/Viewport.h" @@ -1324,50 +1323,6 @@ void game_fix_save_vars() fix_park_entrance_locations(); } -void handle_park_load_failure_with_title_opt(const ParkLoadResult * result, const std::string & path, bool loadTitleFirst) -{ - if (ParkLoadResult_GetError(result) == PARK_LOAD_ERROR_MISSING_OBJECTS) - { - // This option is used when loading parks from the command line - // to ensure that the title sequence loads before the window - if (loadTitleFirst) - { - title_load(); - } - // The path needs to be duplicated as it's a const here - // which the window function doesn't like - auto intent = Intent(WC_OBJECT_LOAD_ERROR); - intent.putExtra(INTENT_EXTRA_PATH, path); - intent.putExtra(INTENT_EXTRA_LIST, (void *) ParkLoadResult_GetMissingObjects(result)); - intent.putExtra(INTENT_EXTRA_LIST_COUNT, (uint32) ParkLoadResult_GetMissingObjectsCount(result)); - context_open_intent(&intent); - } - else if (ParkLoadResult_GetError(result) == PARK_LOAD_ERROR_UNSUPPORTED_RCTC_FLAG) - { - // This option is used when loading parks from the command line - // to ensure that the title sequence loads before the window - if (loadTitleFirst) - { - title_load(); - } - - set_format_arg(0, uint16, ParkLoadResult_GetFlag(result)); - context_show_error(STR_FAILED_TO_LOAD_IMCOMPATIBLE_RCTC_FLAG, STR_NONE); - - } - else if (ParkLoadResult_GetError(result) != PARK_LOAD_ERROR_OK) - { - // If loading the SV6 or SV4 failed for a reason other than invalid objects - // the current park state will be corrupted so just go back to the title screen. - title_load(); - } -} - -void handle_park_load_failure(const ParkLoadResult * result, const std::string & path) -{ - handle_park_load_failure_with_title_opt(result, path, false); -} - void game_load_init() { rct_window * mainWindow; diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index a154e57767..9616f34132 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -172,7 +172,7 @@ sint32 game_do_command_p(uint32 command, sint32 * eax, sint32 * ebx, sint32 * ec void game_log_multiplayer_command(int command, const int * eax, const int * ebx, const int * ecx, int * edx, int * edi, int * ebp); void game_load_or_quit_no_save_prompt(); -ParkLoadResult * load_from_sv6(const char * path); +void load_from_sv6(const char * path); void game_load_init(); void game_pause_toggle(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp); void pause_toggle(); diff --git a/src/openrct2/HandleParkLoad.h b/src/openrct2/HandleParkLoad.h deleted file mode 100644 index fb19dde1f8..0000000000 --- a/src/openrct2/HandleParkLoad.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma region Copyright (c) 2014-2018 OpenRCT2 Developers -/***************************************************************************** - * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. - * - * OpenRCT2 is the work of many authors, a full list can be found in contributors.md - * For more information, visit https://github.com/OpenRCT2/OpenRCT2 - * - * OpenRCT2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * A full copy of the GNU General Public License can be found in licence.txt - *****************************************************************************/ -#pragma endregion - -#pragma once - -#include - -#include "common.h" - -struct ParkLoadResult; - -void handle_park_load_failure_with_title_opt(const ParkLoadResult * result, const std::string & path, bool loadTitleFirst); -void handle_park_load_failure(const ParkLoadResult * result, const std::string & path); diff --git a/src/openrct2/ParkImporter.cpp b/src/openrct2/ParkImporter.cpp index d43c66043f..fd22b97d43 100644 --- a/src/openrct2/ParkImporter.cpp +++ b/src/openrct2/ParkImporter.cpp @@ -22,81 +22,6 @@ #include "object/ObjectRepository.h" #include "ParkImporter.h" -ParkLoadResult::ParkLoadResult(PARK_LOAD_ERROR error) - : Error(error), - Flag(0) -{ -} - -ParkLoadResult::ParkLoadResult(PARK_LOAD_ERROR error, const std::vector &missingObjects) - : Error(error), - MissingObjects(missingObjects), - Flag(0) -{ -} - -ParkLoadResult::ParkLoadResult(PARK_LOAD_ERROR error, const uint8 flag) - : Error(error), - Flag(flag) -{ -} - -ParkLoadResult ParkLoadResult::CreateOK() -{ - return ParkLoadResult(PARK_LOAD_ERROR::PARK_LOAD_ERROR_OK); -} - -ParkLoadResult ParkLoadResult::CreateInvalidExtension() -{ - return ParkLoadResult(PARK_LOAD_ERROR::PARK_LOAD_ERROR_INVALID_EXTENSION); -} - -ParkLoadResult ParkLoadResult::CreateMissingObjects(const std::vector &missingObjects) -{ - return ParkLoadResult(PARK_LOAD_ERROR::PARK_LOAD_ERROR_MISSING_OBJECTS, missingObjects); -} - -ParkLoadResult ParkLoadResult::CreateUnknown() -{ - return ParkLoadResult(PARK_LOAD_ERROR::PARK_LOAD_ERROR_UNKNOWN); -} - -ParkLoadResult ParkLoadResult::CreateUnsupportedRCTCflag(uint8 classic_flag) -{ - return ParkLoadResult(PARK_LOAD_ERROR::PARK_LOAD_ERROR_UNSUPPORTED_RCTC_FLAG, classic_flag); -} - -PARK_LOAD_ERROR ParkLoadResult_GetError(const ParkLoadResult * t) -{ - return t->Error; -} - -size_t ParkLoadResult_GetMissingObjectsCount(const ParkLoadResult * t) -{ - return t->MissingObjects.size(); -} - -uint8 ParkLoadResult_GetFlag(const ParkLoadResult * t) -{ - return t->Flag; -} - -const rct_object_entry * ParkLoadResult_GetMissingObjects(const ParkLoadResult * t) -{ - return t->MissingObjects.data(); -} - -void ParkLoadResult_Delete(ParkLoadResult * t) -{ - delete t; -} - -ParkLoadResult * ParkLoadResult_CreateInvalidExtension() -{ - return new ParkLoadResult(ParkLoadResult::CreateInvalidExtension()); -} - - namespace ParkImporter { std::unique_ptr Create(const std::string &hintPath) diff --git a/src/openrct2/ParkImporter.h b/src/openrct2/ParkImporter.h index eb775ac1b2..724bb1e4a2 100644 --- a/src/openrct2/ParkImporter.h +++ b/src/openrct2/ParkImporter.h @@ -42,20 +42,12 @@ struct scenario_index_entry; struct ParkLoadResult final { public: - const PARK_LOAD_ERROR Error; - const std::vector MissingObjects; - const uint8 Flag; + std::vector const RequiredObjects; - static ParkLoadResult CreateOK(); - static ParkLoadResult CreateInvalidExtension(); - static ParkLoadResult CreateMissingObjects(const std::vector &missingObjects); - static ParkLoadResult CreateUnknown(); - static ParkLoadResult CreateUnsupportedRCTCflag(uint8 classic_flag); - -private: - explicit ParkLoadResult(PARK_LOAD_ERROR error); - ParkLoadResult(PARK_LOAD_ERROR error, const std::vector &missingObjects); - ParkLoadResult(PARK_LOAD_ERROR error, const uint8 flag); + explicit ParkLoadResult(std::vector&& requiredObjects) + : RequiredObjects(requiredObjects) + { + } }; /** @@ -88,6 +80,28 @@ namespace ParkImporter bool ExtensionIsScenario(const std::string &extension); } +class ObjectLoadException : std::exception +{ +public: + std::vector const MissingObjects; + + explicit ObjectLoadException(std::vector&& missingObjects) + : MissingObjects(missingObjects) + { + } +}; + +class UnsupportedRCTCFlagException : std::exception +{ +public: + uint8 const Flag; + + explicit UnsupportedRCTCFlagException(uint8 flag) + : Flag(flag) + { + } +}; + void park_importer_load_from_stream(void * stream, const utf8 * hintPath); bool park_importer_extension_is_scenario(const utf8 * extension); diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index e53bc9f93c..4b9a2112da 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -57,7 +57,183 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -67,4 +243,4 @@ - + \ No newline at end of file diff --git a/src/openrct2/rct1/RCT1.h b/src/openrct2/rct1/RCT1.h index 083a78aa31..8f2072919e 100644 --- a/src/openrct2/rct1/RCT1.h +++ b/src/openrct2/rct1/RCT1.h @@ -1238,7 +1238,7 @@ enum { RCT1_LANDSCAPE_DOOR_OPEN = 3, }; -ParkLoadResult * load_from_sv4(const char *path); -ParkLoadResult * load_from_sc4(const char *path); +void load_from_sv4(const char *path); +void load_from_sc4(const char *path); #endif diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index f30d445682..32558a9308 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -108,7 +108,7 @@ public: class S4Importer final : public IParkImporter { private: - const utf8 * _s4Path = nullptr; + std::string _s4Path; rct1_s4 _s4 = { 0 }; uint8 _gameVersion = 0; uint8 _parkValueConversionFactor = 0; @@ -174,51 +174,16 @@ public: ParkLoadResult LoadFromStream(IStream * stream, bool isScenario, - bool skipObjectCheck = false, - const utf8 * path = String::Empty) override + bool skipObjectCheck, + const utf8 * path) override { - size_t dataSize = stream->GetLength() - stream->GetPosition(); - auto deleter_lambda = [dataSize](uint8 * ptr) { Memory::FreeArray(ptr, dataSize); }; - auto data = std::unique_ptr(stream->ReadArray(dataSize), deleter_lambda); - auto decodedData = std::unique_ptr)>(Memory::Allocate(sizeof(rct1_s4)), &Memory::Free); + _s4 = ReadAndDecodeS4(stream, isScenario); + _s4Path = path; - size_t decodedSize; - sint32 fileType = sawyercoding_detect_file_type(data.get(), dataSize); - if (isScenario && (fileType & FILE_VERSION_MASK) != FILE_VERSION_RCT1) - { - decodedSize = sawyercoding_decode_sc4(data.get(), decodedData.get(), dataSize, sizeof(rct1_s4)); - } - else - { - decodedSize = sawyercoding_decode_sv4(data.get(), decodedData.get(), dataSize, sizeof(rct1_s4)); - } - - if (decodedSize == sizeof(rct1_s4)) - { - std::memcpy(&_s4, decodedData.get(), sizeof(rct1_s4)); - if (_s4Path) - { - Memory::Free(_s4Path); - } - _s4Path = String::Duplicate(path); - - if (!skipObjectCheck) - { - InitialiseEntryMaps(); - CreateAvailableObjectMappings(); - - auto missingObjects = GetInvalidObjects(); - if (!missingObjects.empty()) - { - return ParkLoadResult::CreateMissingObjects(missingObjects); - } - } - } - else - { - throw std::runtime_error("Unable to decode park."); - } - return ParkLoadResult::CreateOK(); + // Only determine what objects we required to import this saved game + InitialiseEntryMaps(); + CreateAvailableObjectMappings(); + return ParkLoadResult(GetRequiredObjects()); } void Import() override @@ -333,6 +298,36 @@ public: } private: + rct1_s4 ReadAndDecodeS4(IStream * stream, bool isScenario) + { + rct1_s4 s4; + size_t dataSize = stream->GetLength() - stream->GetPosition(); + auto deleter_lambda = [dataSize](uint8 * ptr) { Memory::FreeArray(ptr, dataSize); }; + auto data = std::unique_ptr(stream->ReadArray(dataSize), deleter_lambda); + auto decodedData = std::unique_ptr)>(Memory::Allocate(sizeof(rct1_s4)), &Memory::Free); + + size_t decodedSize; + sint32 fileType = sawyercoding_detect_file_type(data.get(), dataSize); + if (isScenario && (fileType & FILE_VERSION_MASK) != FILE_VERSION_RCT1) + { + decodedSize = sawyercoding_decode_sc4(data.get(), decodedData.get(), dataSize, sizeof(rct1_s4)); + } + else + { + decodedSize = sawyercoding_decode_sv4(data.get(), decodedData.get(), dataSize, sizeof(rct1_s4)); + } + + if (decodedSize == sizeof(rct1_s4)) + { + std::memcpy(&s4, decodedData.get(), sizeof(rct1_s4)); + return s4; + } + else + { + throw std::runtime_error("Unable to decode park."); + } + } + void Initialise() { _gameVersion = sawyercoding_detect_rct1_version(_s4.game_version) & FILE_VERSION_MASK; @@ -1890,17 +1885,34 @@ private: } } - std::vector GetInvalidObjects() + void AppendRequiredObjects(std::vector& entries, uint8 objectType, const EntryList& entryList) { - std::vector missingObjects; - GetInvalidObjects(OBJECT_TYPE_RIDE, _rideEntries.GetEntries(), missingObjects); - GetInvalidObjects(OBJECT_TYPE_SMALL_SCENERY, _smallSceneryEntries.GetEntries(), missingObjects); - GetInvalidObjects(OBJECT_TYPE_LARGE_SCENERY, _largeSceneryEntries.GetEntries(), missingObjects); - GetInvalidObjects(OBJECT_TYPE_WALLS, _wallEntries.GetEntries(), missingObjects); - GetInvalidObjects(OBJECT_TYPE_PATHS, _pathEntries.GetEntries(), missingObjects); - GetInvalidObjects(OBJECT_TYPE_PATH_BITS, _pathAdditionEntries.GetEntries(), missingObjects); - GetInvalidObjects(OBJECT_TYPE_SCENERY_GROUP, _sceneryGroupEntries.GetEntries(), missingObjects); - GetInvalidObjects(OBJECT_TYPE_BANNERS, std::vector({ + AppendRequiredObjects(entries, objectType, entryList.GetEntries()); + } + + void AppendRequiredObjects(std::vector& entries, uint8 objectType, const std::vector& objectNames) + { + for (const auto objectName : objectNames) + { + rct_object_entry entry{}; + entry.flags = ((OBJECT_SOURCE_RCT2 << 4) & 0xF0) | (objectType & 0x0F); + std::memset(entry.name, ' ', sizeof(entry.name)); + std::strncpy(entry.name, objectName, sizeof(entry.name)); + entries.push_back(entry); + } + } + + std::vector GetRequiredObjects() + { + std::vector result; + AppendRequiredObjects(result, OBJECT_TYPE_RIDE, _rideEntries); + AppendRequiredObjects(result, OBJECT_TYPE_SMALL_SCENERY, _smallSceneryEntries); + AppendRequiredObjects(result, OBJECT_TYPE_LARGE_SCENERY, _largeSceneryEntries); + AppendRequiredObjects(result, OBJECT_TYPE_WALLS, _wallEntries); + AppendRequiredObjects(result, OBJECT_TYPE_PATHS, _pathEntries); + AppendRequiredObjects(result, OBJECT_TYPE_PATH_BITS, _pathAdditionEntries); + AppendRequiredObjects(result, OBJECT_TYPE_SCENERY_GROUP, _sceneryGroupEntries); + AppendRequiredObjects(result, OBJECT_TYPE_BANNERS, std::vector({ "BN1 ", "BN2 ", "BN3 ", @@ -1909,11 +1921,10 @@ private: "BN6 ", "BN7 ", "BN8 ", - "BN9 " - }), missingObjects); - GetInvalidObjects(OBJECT_TYPE_PARK_ENTRANCE, std::vector({ "PKENT1 " }), missingObjects); - GetInvalidObjects(OBJECT_TYPE_WATER, _waterEntry.GetEntries(), missingObjects); - return missingObjects; + "BN9 " })); + AppendRequiredObjects(result, OBJECT_TYPE_PARK_ENTRANCE, std::vector({ "PKENT1 " })); + AppendRequiredObjects(result, OBJECT_TYPE_WATER, _waterEntry); + return result; } void GetInvalidObjects(uint8 objectType, const std::vector &entries, std::vector &missingObjects) @@ -2843,44 +2854,20 @@ std::unique_ptr ParkImporter::CreateS4() return std::make_unique(); } -ParkLoadResult * load_from_sv4(const utf8 * path) +void load_from_sv4(const utf8 * path) { - ParkLoadResult * result = nullptr; auto s4Importer = std::make_unique(); - try - { - result = new ParkLoadResult(s4Importer->LoadSavedGame(path)); - if (result->Error == PARK_LOAD_ERROR_OK) - { - s4Importer->Import(); - } - } - catch (const std::exception &) - { - delete result; - result = new ParkLoadResult(ParkLoadResult::CreateUnknown()); - } - return result; + auto result = s4Importer->LoadSavedGame(path); + // TODO load objects + s4Importer->Import(); } -ParkLoadResult * load_from_sc4(const utf8 * path) +void load_from_sc4(const utf8 * path) { - ParkLoadResult * result = nullptr; auto s4Importer = std::make_unique(); - try - { - result = new ParkLoadResult(s4Importer->LoadScenario(path)); - if (result->Error == PARK_LOAD_ERROR_OK) - { - s4Importer->Import(); - } - } - catch (const std::exception &) - { - delete result; - result = new ParkLoadResult(ParkLoadResult::CreateUnknown()); - } - return result; + auto result = s4Importer->LoadScenario(path); + // TODO load objects + s4Importer->Import(); } static uint8 GetPathType(rct_tile_element * tileElement) diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 08e85956e7..a71fc1ca90 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -857,52 +857,35 @@ std::unique_ptr ParkImporter::CreateS6(std::shared_ptr(objectRepository, objectManager); } -ParkLoadResult * load_from_sv6(const char * path) +void load_from_sv6(const char * path) { - ParkLoadResult * result = nullptr; auto context = OpenRCT2::GetContext(); - auto s6Importer = new S6Importer(context->GetObjectRepository(), context->GetObjectManager()); + auto s6Importer = std::make_unique(context->GetObjectRepository(), context->GetObjectManager()); try { - result = new ParkLoadResult(s6Importer->LoadSavedGame(path)); - - // We mustn't import if there's something - // wrong with the park data - if (result->Error == PARK_LOAD_ERROR_OK) - { - s6Importer->Import(); - - game_fix_save_vars(); - sprite_position_tween_reset(); - } + auto result = s6Importer->LoadSavedGame(path); + // TODO load objects + s6Importer->Import(); + game_fix_save_vars(); + sprite_position_tween_reset(); + gScreenAge = 0; + gLastAutoSaveUpdate = AUTOSAVE_PAUSE; } - catch (const ObjectLoadException &) + catch (const ObjectLoadException&) { gErrorType = ERROR_TYPE_FILE_LOAD; gErrorStringId = STR_FILE_CONTAINS_INVALID_DATA; } - catch (const IOException &) + catch (const IOException&) { gErrorType = ERROR_TYPE_FILE_LOAD; gErrorStringId = STR_GAME_SAVE_FAILED; } - catch (const std::exception &) + catch (const std::exception&) { gErrorType = ERROR_TYPE_FILE_LOAD; gErrorStringId = STR_FILE_CONTAINS_INVALID_DATA; } - delete s6Importer; - - if (result == nullptr) - { - result = new ParkLoadResult(ParkLoadResult::CreateUnknown()); - } - if (result->Error == PARK_LOAD_ERROR_OK) - { - gScreenAge = 0; - gLastAutoSaveUpdate = AUTOSAVE_PAUSE; - } - return result; } /**