1
0
Fork 0

Codechange: Treat reading incorrect parameter type as a string error.

Previously reading a string as a number would return 0 instead.
pull/12718/head
Peter Nelson 2024-08-01 17:04:21 +01:00 committed by Peter Nelson
parent 3d8d0e0d26
commit d1463f415f
2 changed files with 14 additions and 4 deletions

View File

@ -253,14 +253,24 @@ void GetStringWithArgs(StringBuilder &builder, StringID string, StringParameters
switch (tab) {
case TEXT_TAB_TOWN:
if (index >= 0xC0 && !game_script) {
GetSpecialTownNameString(builder, index - 0xC0, args.GetNextParameter<uint32_t>());
try {
GetSpecialTownNameString(builder, index - 0xC0, args.GetNextParameter<uint32_t>());
} catch (const std::runtime_error &e) {
Debug(misc, 0, "GetStringWithArgs: {}", e.what());
builder += "(invalid string parameter)";
}
return;
}
break;
case TEXT_TAB_SPECIAL:
if (index >= 0xE4 && !game_script) {
GetSpecialNameString(builder, index - 0xE4, args);
try {
GetSpecialNameString(builder, index - 0xE4, args);
} catch (const std::runtime_error &e) {
Debug(misc, 0, "GetStringWithArgs: {}", e.what());
builder += "(invalid string parameter)";
}
return;
}
break;

View File

@ -94,7 +94,7 @@ public:
const auto &param = GetNextParameterReference();
const uint64_t *data = std::get_if<uint64_t>(&param.data);
if (data != nullptr) return static_cast<T>(*data);
return T{};
throw std::runtime_error("Attempt to read string parameter as integer");
}
/**
@ -108,7 +108,7 @@ public:
const auto &param = GetNextParameterReference();
const std::string *data = std::get_if<std::string>(&param.data);
if (data != nullptr) return data->c_str();
return nullptr;
throw std::runtime_error("Attempt to read integer parameter as string");
}
/**