1
0
Fork 0

Codechange: Make non-generic GRF string ids unique per feature.

This prevents engine name strings conflicting with generic strings if more than 53,248 engines are defined.
pull/13588/head
Peter Nelson 2025-01-19 11:30:25 +00:00 committed by Peter Nelson
parent 154896ce55
commit 0af5d5a9e6
2 changed files with 5 additions and 2 deletions

View File

@ -6366,6 +6366,9 @@ static void FeatureNewName(ByteReader &buf)
GrfMsg(6, "FeatureNewName: About to rename engines {}..{} (feature 0x{:02X}) in language 0x{:02X}",
id, endid, feature, lang);
/* Feature overlay to make non-generic strings unique in their feature. We use feature + 1 so that generic strings stay as they are. */
uint32_t feature_overlay = generic ? 0 : ((feature + 1) << 16);
for (; id < endid && buf.HasData(); id++) {
const std::string_view name = buf.ReadString();
GrfMsg(8, "FeatureNewName: 0x{:04X} <- {}", id, StrMakeValid(name));
@ -6378,7 +6381,7 @@ static void FeatureNewName(ByteReader &buf)
if (!generic) {
Engine *e = GetNewEngine(_cur.grffile, (VehicleType)feature, id, _cur.grfconfig->flags.Test(GRFConfigFlag::Static));
if (e == nullptr) break;
StringID string = AddGRFString(_cur.grffile->grfid, GRFStringID{e->index.base()}, lang, new_scheme, false, name, e->info.string_id);
StringID string = AddGRFString(_cur.grffile->grfid, GRFStringID{feature_overlay | e->index.base()}, lang, new_scheme, false, name, e->info.string_id);
e->info.string_id = string;
} else {
AddGRFString(_cur.grffile->grfid, GRFStringID{id}, lang, new_scheme, true, name, STR_UNDEFINED);

View File

@ -13,7 +13,7 @@
#include "core/strong_typedef_type.hpp"
/** Type for GRF-internal string IDs. */
using GRFStringID = StrongType::Typedef<uint16_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer>;
using GRFStringID = StrongType::Typedef<uint32_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer>;
static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT{0xD000}; ///< Miscellaneous GRF text range.