From 7cc1ed9594cc6cc884bb0dd115e358e1ff66bfbf Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 4 Sep 2023 08:12:51 +0100 Subject: [PATCH] Codechange: Allow using more than 65536 NewGRF string IDs. NewGRF string allocation allowed up to 524288 strings, however stringid was passed as uint16_t which limits to 2^16. (cherry picked from commit e4613fc04c0c7aca665d7d4f7cf73e7aa03d5e06) --- src/newgrf_text.cpp | 8 ++++---- src/newgrf_text.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index 6a01f8d847..4589aa094f 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -670,7 +670,7 @@ const char *GetDefaultLangGRFStringFromGRFText(const GRFTextList &text_list) return default_text; } -static std::array, 16> _grf_string_ptr_log; +static std::array, 16> _grf_string_ptr_log; static unsigned int _grf_string_ptr_log_next = 0; /** @@ -693,7 +693,7 @@ const char *GetDefaultLangGRFStringFromGRFText(const GRFTextWrapper &text) /** * Get a C-string from a stringid set by a newgrf. */ -const char *GetGRFStringPtr(uint16 stringid) +const char *GetGRFStringPtr(uint32 stringid) { #if 0 assert_msg(stringid < _grf_text.size(), "stringid: %u, size: %u", stringid, (uint)_grf_text.size()); @@ -711,7 +711,7 @@ const char *GetGRFStringPtr(uint16 stringid) str = GetStringPtr(_grf_text[stringid].def_string); } - _grf_string_ptr_log[_grf_string_ptr_log_next] = std::pair(stringid, str); + _grf_string_ptr_log[_grf_string_ptr_log_next] = std::pair(stringid, str); _grf_string_ptr_log_next = (_grf_string_ptr_log_next + 1) % _grf_string_ptr_log.size(); return str; @@ -917,7 +917,7 @@ uint RemapNewGRFStringControlCode(uint scc, char *buf_start, char **buff, const uint32 grfid = 0; for (uint entry = 0; entry < _grf_string_ptr_log.size(); entry++) { const char *txt = _grf_string_ptr_log[entry].second; - uint16 stringid = _grf_string_ptr_log[entry].first; + uint32 stringid = _grf_string_ptr_log[entry].first; if (txt != nullptr && buffer >= txt && buffer < txt + 8192 && buffer < txt + strlen(txt) && diff --git a/src/newgrf_text.h b/src/newgrf_text.h index 401a40c616..66155506c7 100644 --- a/src/newgrf_text.h +++ b/src/newgrf_text.h @@ -37,7 +37,7 @@ const char *GetGRFStringFromGRFText(const GRFTextList &text_list); const char *GetGRFStringFromGRFText(const GRFTextWrapper &text); const char *GetDefaultLangGRFStringFromGRFText(const GRFTextList &text_list); const char *GetDefaultLangGRFStringFromGRFText(const GRFTextWrapper &text); -const char *GetGRFStringPtr(uint16 stringid); +const char *GetGRFStringPtr(uint32 stringid); void CleanUpStrings(); void SetCurrentGrfLangID(byte language_id); std::string TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newlines, const std::string &str, StringControlCode byte80 = SCC_NEWGRF_PRINT_WORD_STRING_ID);