From d4f97041a083baf5ca06024e04e1cb440c81b0af Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Thu, 5 Nov 2026 03:36:50 +0000 Subject: [PATCH] Decompile fn_13833 (WrapRichText) Batch #11568 by cremane: 0 byte-identical, 1 confirmed by peer review. - fn_13833 WrapRichText: logic confirmed by peer review Peer-reviewed-by: Yommy, KWDev Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/UI/Text/TextWrapping.cpp | 85 +++++++++----------------------- Source/Utility/Text/TextTokens.h | 1 + 2 files changed, 23 insertions(+), 63 deletions(-) diff --git a/Source/UI/Text/TextWrapping.cpp b/Source/UI/Text/TextWrapping.cpp index f56b8fb3..beb4cc55 100644 --- a/Source/UI/Text/TextWrapping.cpp +++ b/Source/UI/Text/TextWrapping.cpp @@ -56,28 +56,6 @@ void WrapPlainText(const char* text, std::vector& lines, int width) } } -namespace { - // INLINED - bool Hex(unsigned char value) { - return (value >= '0' && value <= '9') || (value >= 'a' && value <= 'f') || (value >= 'A' && value <= 'F'); - } - - // INLINED - bool Color(const char* text, std::size_t bytes) { - if (bytes <= 6 || *text != '^') { - return false; - } - - for (unsigned index = 1; index <= 6; ++index) { - if (!Hex(static_cast(text[index]))) { - return false; - } - } - - return true; - } -} - // OFFSET: 0x009B4730 // FUNCTION: fn_13833 void WrapRichText( @@ -104,49 +82,30 @@ void WrapRichText( continue; } - if (Color(current, end - current)) { + int length; + int id; + + if (IsHexColorToken(current, end)) { current += 7; limit += 7; breakAt = current; + } else if (ParseItemIdTag(current, end, length, id)) { + lines.emplace_back(begin, current); + current += length; + limit += length; + begin = current; + + if (id != 0) { + ITEM_INFO item; + item.SetItemId(id); + + char name[260]; + int capacity = sizeof(name); + item.sub_6D5810(name, capacity, 0); + lines.push_back(name); + } } else { - unsigned digits = 0; - - if (std::strncmp(current, "^nItemID^", 9) == 0) { - while (current + digits < end && Hex(static_cast(current[9 + digits]))) { - ++digits; - } - } - - if (digits != 0) { - char number[12]; - - if (digits >= 10) { - __fastfail(FAST_FAIL_RANGE_CHECK_FAILURE); - } - - std::memcpy(number, current + 9, digits); - number[digits] = '\0'; - const int id = std::atoi(number); - - lines.emplace_back(begin, current); - current += 9 + digits; - limit += 9 + digits; - begin = current; - - if (id != 0) { - ITEM_INFO item; - char itemId[16]; - std::sprintf(itemId, "%d", id); - item.itemId = itemId; - - char name[260]; - int capacity = sizeof(name); - item.sub_6D5810(name, capacity, 0); - lines.emplace_back(name); - } - } else { - current = g_serverLanguage->NextChar(current, static_cast(end - current)); - } + current = g_serverLanguage->NextChar(current, static_cast(end - current)); } while (*current == ' ') { @@ -196,9 +155,9 @@ void WrapRichText( lines.emplace_back(begin, current); } - if (g_inlineCharset && *marker != '\0' && marker < end) { + if (g_inlineCharset && marker && *marker != '\0' && marker < end) { for (std::size_t index = 1; index < lines.size(); ++index) { - const unsigned position = Color(lines[index].data(), lines[index].size()) ? 7 : 0; + const unsigned position = IsHexColorToken(lines[index].data(), lines[index].data() + lines[index].size()) ? 7 : 0; lines[index].insert(position, marker, 3); } } diff --git a/Source/Utility/Text/TextTokens.h b/Source/Utility/Text/TextTokens.h index 858ec070..b5abd3e7 100644 --- a/Source/Utility/Text/TextTokens.h +++ b/Source/Utility/Text/TextTokens.h @@ -9,6 +9,7 @@ extern unsigned char g_inlineCharset; bool IsPipeColorToken(const char* text); bool IsHexColorToken(const char* text, const char* end); +int ParseItemIdTag(const char* text, const char* end, int& length, int& itemId); std::string __stdcall StripColorTokens(const char* text, std::uint32_t length); #endif