From 3557c7c8eb8586b793a5f20cf311328e66f3d249 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 7 May 2016 13:58:36 +0100 Subject: [PATCH] add S6 importer and chunk loading --- openrct2.vcxproj | 2 + openrct2.vcxproj.filters | 2 + src/rct2/S6Importer.cpp | 130 +++++++++++++++++++++++++++++++++++++++ src/rct2/S6Importer.h | 45 ++++++++++++++ 4 files changed, 179 insertions(+) create mode 100644 src/rct2/S6Importer.cpp create mode 100644 src/rct2/S6Importer.h diff --git a/openrct2.vcxproj b/openrct2.vcxproj index fc17260493..51cb591bc9 100644 --- a/openrct2.vcxproj +++ b/openrct2.vcxproj @@ -112,6 +112,7 @@ + @@ -370,6 +371,7 @@ + diff --git a/openrct2.vcxproj.filters b/openrct2.vcxproj.filters index 8a5673ba04..c7fa8868ba 100644 --- a/openrct2.vcxproj.filters +++ b/openrct2.vcxproj.filters @@ -270,6 +270,7 @@ + @@ -382,6 +383,7 @@ + diff --git a/src/rct2/S6Importer.cpp b/src/rct2/S6Importer.cpp new file mode 100644 index 0000000000..351bd33621 --- /dev/null +++ b/src/rct2/S6Importer.cpp @@ -0,0 +1,130 @@ +#pragma region Copyright (c) 2014-2016 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 + +#include "../core/Exception.hpp" +#include "../core/IStream.hpp" +#include "S6Importer.h" + +extern "C" +{ + #include "../util/sawyercoding.h" +} + +S6Importer::S6Importer() +{ + memset(&_s6, 0, sizeof(_s6)); +} + +void S6Importer::LoadSavedGame(const utf8 * path) +{ + SDL_RWops * rw = SDL_RWFromFile(path, "rb"); + if (rw == nullptr) { + throw IOException("Unable to open SV6."); + } + + LoadSavedGame(rw); + + SDL_RWclose(rw); + + _s6Path = path; +} + +void S6Importer::LoadScenario(const utf8 * path) +{ + SDL_RWops * rw = SDL_RWFromFile(path, "rb"); + if (rw == nullptr) { + throw IOException("Unable to open SV6."); + } + + LoadScenario(rw); + + SDL_RWclose(rw); + + _s6Path = path; +} + +void S6Importer::LoadSavedGame(SDL_RWops *rw) +{ + sawyercoding_read_chunk(rw, (uint8*)&_s6.header); + + // Read packed objects + // TODO try to contain this more and not store objects until later + if (_s6.header.num_packed_objects > 0) { + int j = 0; + for (uint16 i = 0; i < _s6.header.num_packed_objects; i++) + { + j += object_load_packed(rw); + } + if (j > 0) + { + object_list_load(); + } + } + + sawyercoding_read_chunk(rw, (uint8*)&_s6.objects); + sawyercoding_read_chunk(rw, (uint8*)&_s6.elapsed_months); + sawyercoding_read_chunk(rw, (uint8*)&_s6.map_elements); + sawyercoding_read_chunk(rw, (uint8*)&_s6.dword_010E63B8); + sawyercoding_read_chunk(rw, (uint8*)&_s6.guests_in_park); + sawyercoding_read_chunk(rw, (uint8*)&_s6.expenditure_table); + sawyercoding_read_chunk(rw, (uint8*)&_s6.last_guests_in_park); + sawyercoding_read_chunk(rw, (uint8*)&_s6.dword_01357BD0); + sawyercoding_read_chunk(rw, (uint8*)&_s6.park_rating); + sawyercoding_read_chunk(rw, (uint8*)&_s6.park_rating_history); + sawyercoding_read_chunk(rw, (uint8*)&_s6.active_research_types); + sawyercoding_read_chunk(rw, (uint8*)&_s6.balance_history); + sawyercoding_read_chunk(rw, (uint8*)&_s6.current_expenditure); + sawyercoding_read_chunk(rw, (uint8*)&_s6.weekly_profit_history); + sawyercoding_read_chunk(rw, (uint8*)&_s6.park_value); + sawyercoding_read_chunk(rw, (uint8*)&_s6.park_value_history); + sawyercoding_read_chunk(rw, (uint8*)&_s6.completed_company_value); +} + +void S6Importer::LoadScenario(SDL_RWops *rw) +{ + sawyercoding_read_chunk(rw, (uint8*)&_s6.header); + + // Read packed objects + // TODO try to contain this more and not store objects until later + if (_s6.header.num_packed_objects > 0) { + int j = 0; + for (uint16 i = 0; i < _s6.header.num_packed_objects; i++) + { + j += object_load_packed(rw); + } + if (j > 0) + { + object_list_load(); + } + } + + sawyercoding_read_chunk(rw, (uint8*)&_s6.objects); + sawyercoding_read_chunk(rw, (uint8*)&_s6.elapsed_months); + sawyercoding_read_chunk(rw, (uint8*)&_s6.map_elements); + sawyercoding_read_chunk(rw, (uint8*)&_s6.dword_010E63B8); + sawyercoding_read_chunk(rw, (uint8*)&_s6.guests_in_park); + sawyercoding_read_chunk(rw, (uint8*)&_s6.last_guests_in_park); + sawyercoding_read_chunk(rw, (uint8*)&_s6.park_rating); + sawyercoding_read_chunk(rw, (uint8*)&_s6.active_research_types); + sawyercoding_read_chunk(rw, (uint8*)&_s6.current_expenditure); + sawyercoding_read_chunk(rw, (uint8*)&_s6.park_value); + sawyercoding_read_chunk(rw, (uint8*)&_s6.completed_company_value); +} + +void S6Importer::Import() +{ + +} diff --git a/src/rct2/S6Importer.h b/src/rct2/S6Importer.h new file mode 100644 index 0000000000..f0da502f82 --- /dev/null +++ b/src/rct2/S6Importer.h @@ -0,0 +1,45 @@ +#pragma region Copyright (c) 2014-2016 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 "../common.h" +#include "../core/List.hpp" + +extern "C" +{ + #include "../scenario.h" +} + +/** + * Class to import RollerCoaster Tycoon 2 scenarios (*.SC6) and saved games (*.SV6). + */ +class S6Importer +{ +public: + S6Importer(); + + void LoadSavedGame(const utf8 * path); + void LoadSavedGame(SDL_RWops *rw); + void LoadScenario(const utf8 * path); + void LoadScenario(SDL_RWops *rw); + void Import(); + +private: + const utf8 * _s6Path; + rct_s6_data _s6; + uint8 _gameVersion; +};