StringToHex now writes two digits per unsigned byte (an 8-letter Cyrillic name now takes 32 hex chars instead of 128)

This commit is contained in:
Eddoursul 2026-11-15 18:38:13 +01:00
parent 84ca4208d2
commit 6c33829ccd

View File

@ -330,15 +330,15 @@ inline RE::BSFixedString GetPlayerHash()
return buf;
}
inline RE::BSFixedString StringToHex(RE::BSFixedString a_string)
// Two digits per byte, as the engine writes save names ("%.2X"). char is signed, so a byte
// above 0x7F (any UTF-8 non-ASCII character) must be widened as unsigned, or it prints as FFFFFFxx.
inline std::string StringToHex(std::string_view a_string)
{
std::string_view str(a_string);
std::stringstream sstream;
for (auto ch : str) {
sstream << std::uppercase << std::hex << static_cast<int>(ch);
std::string result;
result.reserve(a_string.size() * 2);
for (const auto ch : a_string) {
result += std::format("{:02X}", static_cast<std::uint8_t>(ch));
}
return sstream.str();
return result;
}