MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / loadStringTable

Function loadStringTable

src/OpenLoco/src/Objects/ObjectStringTable.cpp:67–127  ·  view source on GitHub ↗

0x00472172

Source from the content-addressed store, hash-verified

65
66 // 0x00472172
67 StringTableResult loadStringTable(std::span<const std::byte> data, const LoadedObjectHandle& handle, uint8_t index)
68 {
69 StringTableResult res;
70 auto iter = data.begin();
71 const char* engBackupStr = nullptr;
72 const char* anyStr = nullptr;
73 const char* targetStr = nullptr;
74 const auto targetLang = Localisation::getDescriptorForLanguage(Config::get().language).locoOriginalId;
75 for (; iter != data.end() && *iter != static_cast<std::byte>(0xFF); ++iter)
76 {
77 const auto lang = static_cast<Localisation::LocoLanguageId>(*iter++);
78 const auto str = reinterpret_cast<const char*>(&*iter);
79 if (lang == Localisation::LocoLanguageId::english_uk)
80 {
81 engBackupStr = str;
82 }
83 else if (lang == Localisation::LocoLanguageId::english_us && engBackupStr == nullptr)
84 {
85 engBackupStr = str;
86 }
87 if (lang == targetLang)
88 {
89 targetStr = str;
90 }
91 if (engBackupStr == nullptr && targetStr == nullptr)
92 {
93 anyStr = str;
94 }
95 iter += strlen(str);
96 }
97 iter++;
98 res.tableLength = std::distance(data.begin(), iter);
99 const auto* chosenStr = [=]() {
100 if (targetStr != nullptr)
101 {
102 return targetStr;
103 }
104 if (engBackupStr != nullptr)
105 {
106 return engBackupStr;
107 }
108 return anyStr;
109 }();
110
111 if (isTemporaryObjectLoad())
112 {
113 res.str = kTemporaryObjectStringIds[index];
114 StringManager::swapString(res.str, chosenStr);
115 return res;
116 }
117
118 res.str = StringIds::object_strings_begin + index;
119 for (auto objType = ObjectType::interfaceSkin; enumValue(objType) < enumValue(handle.type); objType = static_cast<ObjectType>(enumValue(objType) + 1))
120 {
121 res.str += static_cast<uint16_t>(getMaxObjects(objType)) * kNumStringsPerObjectType[enumValue(objType)];
122 }
123 res.str += kNumStringsPerObjectType[enumValue(handle.type)] * handle.id;
124

Callers 15

loadMethod · 0.85
loadMethod · 0.85
loadMethod · 0.85
loadMethod · 0.85
loadMethod · 0.85
loadMethod · 0.85
loadMethod · 0.85
loadMethod · 0.85
loadMethod · 0.85
loadMethod · 0.85
loadMethod · 0.85
loadMethod · 0.85

Calls 7

isTemporaryObjectLoadFunction · 0.85
swapStringFunction · 0.85
enumValueFunction · 0.85
getMaxObjectsFunction · 0.85
getFunction · 0.50
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected