From 6c33829ccdc6244f4f0189079b04d40b5d9074d1 Mon Sep 17 00:00:00 2001 From: Eddoursul Date: Sun, 15 Nov 2026 18:38:13 +0100 Subject: [PATCH] StringToHex now writes two digits per unsigned byte (an 8-letter Cyrillic name now takes 32 hex chars instead of 128) --- source/Enderal DLL/src/Util.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/Enderal DLL/src/Util.h b/source/Enderal DLL/src/Util.h index fb2d119f5..fe8b13384 100644 --- a/source/Enderal DLL/src/Util.h +++ b/source/Enderal DLL/src/Util.h @@ -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(ch); + std::string result; + result.reserve(a_string.size() * 2); + for (const auto ch : a_string) { + result += std::format("{:02X}", static_cast(ch)); } - - return sstream.str(); + return result; }