From d28799ef1806a36d92edd91cde2517a6530183b5 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 21 Jul 2019 22:41:18 +0100 Subject: [PATCH] Remove user strings --- src/openrct2-ui/windows/Player.cpp | 1 - src/openrct2/Game.cpp | 10 -- src/openrct2/GameState.cpp | 1 - src/openrct2/interface/InteractiveConsole.cpp | 8 -- src/openrct2/localisation/Localisation.cpp | 10 +- src/openrct2/localisation/Localisation.h | 11 -- src/openrct2/localisation/User.cpp | 100 ------------------ src/openrct2/localisation/User.h | 12 --- src/openrct2/rct12/RCT12.cpp | 5 + src/openrct2/rct12/RCT12.h | 2 + src/openrct2/rct2/S6Importer.cpp | 14 +-- 11 files changed, 13 insertions(+), 161 deletions(-) delete mode 100644 src/openrct2/localisation/User.cpp delete mode 100644 src/openrct2/localisation/User.h diff --git a/src/openrct2-ui/windows/Player.cpp b/src/openrct2-ui/windows/Player.cpp index a1794e3167..a8281f6333 100644 --- a/src/openrct2-ui/windows/Player.cpp +++ b/src/openrct2-ui/windows/Player.cpp @@ -475,7 +475,6 @@ void window_player_statistics_close(rct_window* w) { if (w->error.var_480) { - user_string_free(w->error.var_480); w->error.var_480 = 0; } } diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index a3ac034fcd..809108a81b 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -555,16 +555,6 @@ void game_convert_strings_to_utf8() gScenarioName = rct2_to_utf8(gScenarioName, RCT2_LANGUAGE_ID_ENGLISH_UK); gScenarioDetails = rct2_to_utf8(gScenarioDetails, RCT2_LANGUAGE_ID_ENGLISH_UK); - // User strings - for (auto* string : gUserStrings) - { - if (!str_is_null_or_empty(string)) - { - rct2_to_utf8_self(string, RCT12_USER_STRING_MAX_LENGTH); - utf8_remove_formatting(string, true); - } - } - // News items game_convert_news_items_to_utf8(); } diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index a7cd4c6698..2bd343b31e 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -59,7 +59,6 @@ void GameState::InitAll(int32_t mapSize) date_reset(); climate_reset(CLIMATE_COOL_AND_WET); news_item_init_queue(); - user_string_clear_all(); gInMapInitCode = false; diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index e1fe97e630..7b22bd82e9 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -28,7 +28,6 @@ #include "../interface/Chat.h" #include "../interface/Colour.h" #include "../localisation/Localisation.h" -#include "../localisation/User.h" #include "../management/Finance.h" #include "../management/Research.h" #include "../network/network.h" @@ -1153,12 +1152,6 @@ static int32_t cc_object_count(InteractiveConsole& console, [[maybe_unused]] con return 0; } -static int32_t cc_reset_user_strings([[maybe_unused]] InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv) -{ - reset_user_strings(); - return 0; -} - static int32_t cc_open(InteractiveConsole& console, const arguments_t& argv) { if (!argv.empty()) @@ -1691,7 +1684,6 @@ static constexpr const console_command console_command_table[] = { { "quit", cc_close, "Closes the console.", "quit" }, { "remove_park_fences", cc_remove_park_fences, "Removes all park fences from the surface", "remove_park_fences" }, { "remove_unused_objects", cc_remove_unused_objects, "Removes all the unused objects from the object selection.", "remove_unused_objects" }, - { "reset_user_strings", cc_reset_user_strings, "Resets all user-defined strings, to fix incorrectly occurring 'Chosen name in use already' errors.", "reset_user_strings" }, { "rides", cc_rides, "Ride management.", "rides " }, { "save_park", cc_save_park, "Save current state of park. If no name specified default path will be used.", "save_park [name]" }, { "say", cc_say, "Say to other players.", "say " }, diff --git a/src/openrct2/localisation/Localisation.cpp b/src/openrct2/localisation/Localisation.cpp index a4ee8c3a22..bb5472c864 100644 --- a/src/openrct2/localisation/Localisation.cpp +++ b/src/openrct2/localisation/Localisation.cpp @@ -386,7 +386,7 @@ static void format_append_string(char** dest, size_t* size, const utf8* string) } } -static void format_append_string_n(char** dest, size_t* size, const utf8* string, size_t maxlen) +[[maybe_unused]] void format_append_string_n(char** dest, size_t* size, const utf8* string, size_t maxlen) { if ((*size) == 0) return; @@ -1257,16 +1257,14 @@ static void format_string_part(utf8** dest, size_t* size, rct_string_id format, } else if (format <= USER_STRING_END) { + // User strings should no longer be used + assert(false); + // Custom string format -= 0x8000; // Bits 10, 11 represent number of bytes to pop off arguments *args += (format & 0xC00) >> 9; - format &= ~0xC00; - - format_append_string_n(dest, size, gUserStrings[format], USER_STRING_MAX_LENGTH); - if ((*size) > 0) - *(*dest) = '\0'; } else if (format <= REAL_NAME_END) { diff --git a/src/openrct2/localisation/Localisation.h b/src/openrct2/localisation/Localisation.h index 7f42da87b0..820e740762 100644 --- a/src/openrct2/localisation/Localisation.h +++ b/src/openrct2/localisation/Localisation.h @@ -51,9 +51,6 @@ int32_t get_string_length(const utf8* text); money32 string_to_money(const char* string_to_monetise); void money_to_string(money32 amount, char* buffer_to_put_value_to, size_t buffer_len, bool forceDecimals); -void user_string_clear_all(); -rct_string_id user_string_allocate(int32_t base, const utf8* text); -void user_string_free(rct_string_id id); bool is_user_string_id(rct_string_id stringId); #define MAX_USER_STRINGS 1024 @@ -64,18 +61,10 @@ bool is_user_string_id(rct_string_id stringId); #define REAL_NAME_START 0xA000 #define REAL_NAME_END 0xDFFF -// Constants used by user_string_allocate -enum -{ - USER_STRING_HIGH_ID_NUMBER = 1 << 2, - USER_STRING_DUPLICATION_PERMITTED = 1 << 7 -}; - // Real name data extern const char real_name_initials[16]; extern const char* real_names[1024]; -extern utf8 gUserStrings[MAX_USER_STRINGS][USER_STRING_MAX_LENGTH]; extern thread_local char gCommonStringFormatBuffer[512]; extern thread_local uint8_t gCommonFormatArgs[80]; extern thread_local uint8_t gMapTooltipFormatArgs[40]; diff --git a/src/openrct2/localisation/User.cpp b/src/openrct2/localisation/User.cpp deleted file mode 100644 index fa91b549d8..0000000000 --- a/src/openrct2/localisation/User.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2019 OpenRCT2 developers - * - * For a complete list of all authors, please refer to contributors.md - * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 - * - * OpenRCT2 is licensed under the GNU General Public License version 3. - *****************************************************************************/ - -#include "User.h" - -#include "../Game.h" -#include "../ride/Ride.h" -#include "../util/Util.h" -#include "Localisation.h" - -utf8 gUserStrings[MAX_USER_STRINGS][USER_STRING_MAX_LENGTH]; - -static bool user_string_exists(const utf8* text); - -/** - * - * rct2: 0x006C4209 - */ -void user_string_clear_all() -{ - std::memset(gUserStrings, 0x00, MAX_USER_STRINGS * USER_STRING_MAX_LENGTH); -} - -/** - * - * rct2: 0x006C421D - */ -rct_string_id user_string_allocate(int32_t base, const utf8* text) -{ - int32_t highBits = (base & 0x7F) << 9; - bool allowDuplicates = base & USER_STRING_DUPLICATION_PERMITTED; - - if (!allowDuplicates && user_string_exists(text)) - { - gGameCommandErrorText = STR_CHOSEN_NAME_IN_USE_ALREADY; - return 0; - } - - for (int32_t i = 0; i < MAX_USER_STRINGS; i++) - { - char* userString = gUserStrings[i]; - - if (userString[0] != 0) - continue; - - safe_strcpy(userString, text, USER_STRING_MAX_LENGTH); - return USER_STRING_START + (i | highBits); - } - gGameCommandErrorText = STR_TOO_MANY_NAMES_DEFINED; - return 0; -} - -/** - * - * rct2: 0x006C42AC - */ -void user_string_free(rct_string_id id) -{ - if (!is_user_string_id(id)) - return; - - id %= MAX_USER_STRINGS; - gUserStrings[id][0] = 0; -} - -static bool user_string_exists(const utf8* text) -{ - char* userString; - for (int32_t i = 0; i < MAX_USER_STRINGS; i++) - { - userString = gUserStrings[i]; - if (userString[0] == 0) - continue; - - if (strcmp(userString, text) == 0) - return true; - } - return false; -} - -bool is_user_string_id(rct_string_id stringId) -{ - return stringId >= 0x8000 && stringId < 0x9000; -} - -void reset_user_strings() -{ - for (int32_t i = 0; i < MAX_USER_STRINGS; i++) - { - gUserStrings[i][0] = 0; - } - - ride_reset_all_names(); -} diff --git a/src/openrct2/localisation/User.h b/src/openrct2/localisation/User.h deleted file mode 100644 index d20633ed0f..0000000000 --- a/src/openrct2/localisation/User.h +++ /dev/null @@ -1,12 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2019 OpenRCT2 developers - * - * For a complete list of all authors, please refer to contributors.md - * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 - * - * OpenRCT2 is licensed under the GNU General Public License version 3. - *****************************************************************************/ - -#pragma once - -void reset_user_strings(); diff --git a/src/openrct2/rct12/RCT12.cpp b/src/openrct2/rct12/RCT12.cpp index 017a71f932..e9d01d628c 100644 --- a/src/openrct2/rct12/RCT12.cpp +++ b/src/openrct2/rct12/RCT12.cpp @@ -408,3 +408,8 @@ uint8_t RCT12BannerElement::GetAllowedEdges() const { return flags & 0b00001111; } + +bool is_user_string_id(rct_string_id stringId) +{ + return stringId >= 0x8000 && stringId < 0x9000; +} diff --git a/src/openrct2/rct12/RCT12.h b/src/openrct2/rct12/RCT12.h index d4a721cacf..e41e8d773b 100644 --- a/src/openrct2/rct12/RCT12.h +++ b/src/openrct2/rct12/RCT12.h @@ -538,3 +538,5 @@ struct RCT12Banner assert_struct_size(RCT12Banner, 8); #pragma pack(pop) + +bool is_user_string_id(rct_string_id stringId); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index af480721c3..57ebe48ce6 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -371,9 +371,6 @@ public: String::Set(gScenarioFileName, sizeof(gScenarioFileName), _s6.scenario_filename); } std::memcpy(gScenarioExpansionPacks, _s6.saved_expansion_pack_names, sizeof(_s6.saved_expansion_pack_names)); - // Clear all of the strings, since we will probably have a higher limit on user strings in the future than RCT2. - user_string_clear_all(); - std::memcpy(gUserStrings, _s6.custom_strings, sizeof(_s6.custom_strings)); gCurrentTicks = _s6.game_ticks_1; gCurrentRealTimeTicks = 0; @@ -456,15 +453,8 @@ public: map_count_remaining_land_rights(); determine_ride_entrance_and_exit_locations(); - // Park name, must be after user strings are loaded - // Eventually format_string should be something that the S6 user strings can be passed directly to - { - char parkName[128]{}; - format_string(parkName, sizeof(parkName), _s6.park_name, &_s6.park_name_args); - auto& park = OpenRCT2::GetContext()->GetGameState()->GetPark(); - park.Name = parkName; - user_string_free(_s6.park_name); - } + auto& park = OpenRCT2::GetContext()->GetGameState()->GetPark(); + park.Name = GetUserString(_s6.park_name); // We try to fix the cycles on import, hence the 'true' parameter check_for_sprite_list_cycles(true);