From e6eee5581067b2ce2881b54e065be7db3126fbb2 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 7 Dec 2025 21:44:33 +0100 Subject: [PATCH] fix: Editing of WString, String16, String32 in data inspector --- .../builtin/source/content/data_inspector.cpp | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/plugins/builtin/source/content/data_inspector.cpp b/plugins/builtin/source/content/data_inspector.cpp index c9ad23d17..2a285e220 100644 --- a/plugins/builtin/source/content/data_inspector.cpp +++ b/plugins/builtin/source/content/data_inspector.cpp @@ -589,9 +589,18 @@ namespace hex::plugin::builtin { return [value, copyValue] { ImGuiExt::TextFormatted("L\"{0}\"", value.c_str()); return copyValue; }; }, [](const std::string &value, std::endian endian) -> std::vector { - std::ignore = endian; + auto utf8 = hex::decodeByteString(value); + auto wstring = wolv::util::utf8ToWstring({ utf8.begin(), utf8.end() }); + if (!wstring.has_value()) + return {}; - return hex::decodeByteString(value); + for (auto &c : wstring.value()) { + c = hex::changeEndianness(c, endian); + } + + std::vector bytes(wstring->size() * sizeof(wchar_t), 0x00); + std::memcpy(bytes.data(), wstring->data(), bytes.size()); + return bytes; } ); @@ -626,9 +635,18 @@ namespace hex::plugin::builtin { return [value, copyValue] { ImGuiExt::TextFormatted("u\"{0}\"", value.c_str()); return copyValue; }; }, [](const std::string &value, std::endian endian) -> std::vector { - std::ignore = endian; + auto utf8 = hex::decodeByteString(value); + auto utf16 = wolv::util::utf8ToUtf16({ utf8.begin(), utf8.end() }); + if (!utf16.has_value()) + return {}; - return hex::decodeByteString(value); + for (auto &c : utf16.value()) { + c = hex::changeEndianness(c, endian); + } + + std::vector bytes(utf16->size() * sizeof(char16_t), 0x00); + std::memcpy(bytes.data(), utf16->data(), bytes.size()); + return bytes; } ); @@ -663,9 +681,18 @@ namespace hex::plugin::builtin { return [value, copyValue] { ImGuiExt::TextFormatted("U\"{0}\"", value.c_str()); return copyValue; }; }, [](const std::string &value, std::endian endian) -> std::vector { - std::ignore = endian; + auto utf8 = hex::decodeByteString(value); + auto utf32 = wolv::util::utf8ToUtf32({ utf8.begin(), utf8.end() }); + if (!utf32.has_value()) + return {}; - return hex::decodeByteString(value); + for (auto &c : utf32.value()) { + c = hex::changeEndianness(c, endian); + } + + std::vector bytes(utf32->size() * sizeof(char32_t), 0x00); + std::memcpy(bytes.data(), utf32->data(), bytes.size()); + return bytes; } );