From 7037524759d15e0629e24d4f3e204958bdb7eb73 Mon Sep 17 00:00:00 2001 From: Duncan Date: Sun, 28 Nov 2021 21:53:40 +0000 Subject: [PATCH] Remove and cleanup RCT2 string code --- src/openrct2/Game.cpp | 68 -------------------------------- src/openrct2/Game.h | 7 ---- src/openrct2/rct2/S6Importer.cpp | 10 ++++- 3 files changed, 9 insertions(+), 76 deletions(-) diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 8f42589603..a15f82c21c 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -40,7 +40,6 @@ #include "object/Object.h" #include "object/ObjectList.h" #include "platform/Platform2.h" -#include "rct1/RCT1.h" #include "ride/Ride.h" #include "ride/RideRatings.h" #include "ride/Station.h" @@ -326,42 +325,6 @@ static void load_landscape() context_open_intent(&intent); } -void utf8_to_rct2_self(char* buffer, size_t length) -{ - auto temp = utf8_to_rct2(buffer); - - size_t i = 0; - const char* src = temp.data(); - char* dst = buffer; - while (*src != 0 && i < length - 1) - { - if (*src == static_cast(static_cast(0xFF))) - { - if (i < length - 3) - { - *dst++ = *src++; - *dst++ = *src++; - *dst++ = *src++; - } - else - { - break; - } - i += 3; - } - else - { - *dst++ = *src++; - i++; - } - } - do - { - *dst++ = '\0'; - i++; - } while (i < length); -} - void rct2_to_utf8_self(char* buffer, size_t length) { if (length > 0) @@ -371,37 +334,6 @@ void rct2_to_utf8_self(char* buffer, size_t length) } } -/** - * Converts all the user strings and news item strings to UTF-8. - */ -void game_convert_strings_to_utf8() -{ - // Scenario details - gScenarioCompletedBy = rct2_to_utf8(gScenarioCompletedBy, RCT2LanguageId::EnglishUK); - gScenarioName = rct2_to_utf8(gScenarioName, RCT2LanguageId::EnglishUK); - gScenarioDetails = rct2_to_utf8(gScenarioDetails, RCT2LanguageId::EnglishUK); -} - -/** - * Converts all the user strings and news item strings to RCT2 encoding. - */ -void game_convert_strings_to_rct2(RCT2::S6Data* s6) -{ - // Scenario details - utf8_to_rct2_self(s6->scenario_completed_name, sizeof(s6->scenario_completed_name)); - utf8_to_rct2_self(s6->scenario_name, sizeof(s6->scenario_name)); - utf8_to_rct2_self(s6->scenario_description, sizeof(s6->scenario_description)); - - // User strings - for (auto* userString : s6->custom_strings) - { - if (!str_is_null_or_empty(userString)) - { - utf8_to_rct2_self(userString, RCT12::Limits::MaxUserStringLength); - } - } -} - // OpenRCT2 workaround to recalculate some values which are saved redundantly in the save to fix corrupted files. // For example recalculate guest count by looking at all the guests instead of trusting the value in the file. void game_fix_save_vars() diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index d348352ce7..ec212aa5ca 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -14,10 +14,6 @@ #include struct ParkLoadResult; -namespace RCT2 -{ - struct S6Data; -} enum class GameCommand : int32_t { @@ -172,9 +168,6 @@ void save_game_as(); void save_game_cmd(const utf8* name = nullptr); void save_game_with_name(const utf8* name); void game_autosave(); -void game_convert_strings_to_utf8(); -void game_convert_strings_to_rct2(RCT2::S6Data* s6); -void utf8_to_rct2_self(char* buffer, size_t length); void rct2_to_utf8_self(char* buffer, size_t length); void game_fix_save_vars(); void start_silent_record(); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 14c58e1eb8..750e6e5192 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -477,7 +477,7 @@ namespace RCT2 // Fix and set dynamic variables map_strip_ghost_flag_from_elements(); - game_convert_strings_to_utf8(); + ConvertScenarioStringsToUTF8(); map_count_remaining_land_rights(); determine_ride_entrance_and_exit_locations(); @@ -492,6 +492,14 @@ namespace RCT2 ClearRestrictedScenery(); } + void ConvertScenarioStringsToUTF8() + { + // Scenario details + gScenarioCompletedBy = rct2_to_utf8(gScenarioCompletedBy, RCT2LanguageId::EnglishUK); + gScenarioName = rct2_to_utf8(gScenarioName, RCT2LanguageId::EnglishUK); + gScenarioDetails = rct2_to_utf8(gScenarioDetails, RCT2LanguageId::EnglishUK); + } + void FixLandOwnership() const { if (String::Equals(_s6.scenario_filename, "Europe - European Cultural Festival.SC6"))