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 e4613fc04c
)
This commit is contained in:

committed by
Jonathan G Rennison

parent
2178ff1e80
commit
7cc1ed9594
@@ -670,7 +670,7 @@ const char *GetDefaultLangGRFStringFromGRFText(const GRFTextList &text_list)
|
|||||||
return default_text;
|
return default_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::array<std::pair<uint16, const char *>, 16> _grf_string_ptr_log;
|
static std::array<std::pair<uint32, const char *>, 16> _grf_string_ptr_log;
|
||||||
static unsigned int _grf_string_ptr_log_next = 0;
|
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.
|
* Get a C-string from a stringid set by a newgrf.
|
||||||
*/
|
*/
|
||||||
const char *GetGRFStringPtr(uint16 stringid)
|
const char *GetGRFStringPtr(uint32 stringid)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
assert_msg(stringid < _grf_text.size(), "stringid: %u, size: %u", stringid, (uint)_grf_text.size());
|
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);
|
str = GetStringPtr(_grf_text[stringid].def_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
_grf_string_ptr_log[_grf_string_ptr_log_next] = std::pair<uint16, const char *>(stringid, str);
|
_grf_string_ptr_log[_grf_string_ptr_log_next] = std::pair<uint32, const char *>(stringid, str);
|
||||||
_grf_string_ptr_log_next = (_grf_string_ptr_log_next + 1) % _grf_string_ptr_log.size();
|
_grf_string_ptr_log_next = (_grf_string_ptr_log_next + 1) % _grf_string_ptr_log.size();
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
@@ -917,7 +917,7 @@ uint RemapNewGRFStringControlCode(uint scc, char *buf_start, char **buff, const
|
|||||||
uint32 grfid = 0;
|
uint32 grfid = 0;
|
||||||
for (uint entry = 0; entry < _grf_string_ptr_log.size(); entry++) {
|
for (uint entry = 0; entry < _grf_string_ptr_log.size(); entry++) {
|
||||||
const char *txt = _grf_string_ptr_log[entry].second;
|
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 &&
|
if (txt != nullptr &&
|
||||||
buffer >= txt && buffer < txt + 8192 &&
|
buffer >= txt && buffer < txt + 8192 &&
|
||||||
buffer < txt + strlen(txt) &&
|
buffer < txt + strlen(txt) &&
|
||||||
|
@@ -37,7 +37,7 @@ const char *GetGRFStringFromGRFText(const GRFTextList &text_list);
|
|||||||
const char *GetGRFStringFromGRFText(const GRFTextWrapper &text);
|
const char *GetGRFStringFromGRFText(const GRFTextWrapper &text);
|
||||||
const char *GetDefaultLangGRFStringFromGRFText(const GRFTextList &text_list);
|
const char *GetDefaultLangGRFStringFromGRFText(const GRFTextList &text_list);
|
||||||
const char *GetDefaultLangGRFStringFromGRFText(const GRFTextWrapper &text);
|
const char *GetDefaultLangGRFStringFromGRFText(const GRFTextWrapper &text);
|
||||||
const char *GetGRFStringPtr(uint16 stringid);
|
const char *GetGRFStringPtr(uint32 stringid);
|
||||||
void CleanUpStrings();
|
void CleanUpStrings();
|
||||||
void SetCurrentGrfLangID(byte language_id);
|
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);
|
std::string TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newlines, const std::string &str, StringControlCode byte80 = SCC_NEWGRF_PRINT_WORD_STRING_ID);
|
||||||
|
Reference in New Issue
Block a user