From bb9ce9057520097f5c9497d531454769a04a8d2b Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Wed, 4 Nov 2026 22:55:23 +0000 Subject: [PATCH] Decompile fn_16993 (UIWindow::WrapPixelText) Batch #10556 by cremane: 0 byte-identical, 1 confirmed by peer review. - fn_16993 UIWindow::WrapPixelText: logic confirmed by peer review Peer-reviewed-by: ragnarok-clanker, Yommy, dori, StrawberrysherbetIX Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/UI/Text/PixelTextWrapping.cpp | 81 ++++++++++++---------------- 1 file changed, 34 insertions(+), 47 deletions(-) diff --git a/Source/UI/Text/PixelTextWrapping.cpp b/Source/UI/Text/PixelTextWrapping.cpp index b6e74415..5af49243 100644 --- a/Source/UI/Text/PixelTextWrapping.cpp +++ b/Source/UI/Text/PixelTextWrapping.cpp @@ -1,5 +1,6 @@ #include "Client/Input/InputCharset.h" #include "Render/Text/TextContext.h" +#include "UI/Text/ColoredText.h" #include "UI/Text/PixelTextWrapping.h" #include "UI/Window/UIWindow.h" #include "Network/TextEncoding.h" @@ -7,25 +8,6 @@ #include #include -namespace { - // INLINED - unsigned Digit(unsigned char value) { - if (value >= '0' && value <= '9') { - return value - '0'; - } - - if (value >= 'a' && value <= 'f') { - return value - 'a' + 10; - } - - if (value >= 'A' && value <= 'F') { - return value - 'A' + 10; - } - - return 0; - } -} - // OFFSET: 0x00A82310 // FUNCTION: fn_16993 void UIWindow::WrapPixelText(const char* text, std::vector& lines, int width) { @@ -33,23 +15,9 @@ void UIWindow::WrapPixelText(const char* text, std::vector& lines, return; } - const auto measure = [&](const char* part, int bytes) { - if (bytes == 0) { - bytes = static_cast(std::strlen(part)); - } - - if (bytes == 0) { - return 0; - } - - TextContext context(*this->geometry.surface); - context.SetFont(0, 12, 0, 0); - return static_cast(context.Measure(part, bytes).cx); - }; - const int bytes = static_cast(std::strlen(text)); - if (measure(text, bytes) <= 0) { + if (this->TextWidth(text, bytes, 0, 12, 0, 0) <= 0) { return; } @@ -76,11 +44,11 @@ void UIWindow::WrapPixelText(const char* text, std::vector& lines, const char* next = g_serverLanguage->NextChar(current, static_cast(end - current)); const int length = static_cast(next - current); - extent = (extent + measure(current, length)); + extent = (extent + this->TextWidth(current, length, 0, 12, 0, 0)); count = (count + length); if (length == 1 && (*current == '\r' || *current == '\n')) { - measure("\n", 1); + this->TextWidth("\n", 1, 0, 12, 0, 0); newline = true; if (current + 1 < end && current[1] == '\n') { @@ -91,11 +59,23 @@ void UIWindow::WrapPixelText(const char* text, std::vector& lines, } if (*current == '^') { - const unsigned color = (Digit(current[2]) + 16 * Digit(current[1])) | ((Digit(current[4]) + 16 * Digit(current[3])) << 8) | - ((Digit(current[6]) + 16 * Digit(current[5])) << 16); + const unsigned char red = static_cast(g_hexDigits[current[1]] * 16 + g_hexDigits[current[2]]); + const unsigned char green = static_cast(g_hexDigits[current[3]] * 16 + g_hexDigits[current[4]]); + const unsigned char blue = static_cast(g_hexDigits[current[5]] * 16 + g_hexDigits[current[6]]); + const std::uint32_t color = red | (green << 8) | (blue << 16); - if (color != 0 || std::strncmp(current, "^000000", 7) == 0) { - extent = (extent - measure("^000000", 7)); + if (color != 0) { + extent = (extent - this->TextWidth("^000000", 7, 0, 12, 0, 0)); + } else { + char* code = new char[8]; + std::memcpy(code, current, 7); + code[7] = '\0'; + + if (std::strcmp(code, "^000000") == 0) { + extent = (extent - this->TextWidth("^000000", 7, 0, 12, 0, 0)); + } + + delete[] code; } } @@ -104,8 +84,8 @@ void UIWindow::WrapPixelText(const char* text, std::vector& lines, if (close) { const int bracketBytes = static_cast(reinterpret_cast(close) - current) + 1; - const int bracketWidth = measure(current, bracketBytes); - const int characterWidth = measure(current, length); + const int bracketWidth = this->TextWidth(current, bracketBytes, 0, 12, 0, 0); + const int characterWidth = this->TextWidth(current, length, 0, 12, 0, 0); if (((extent + bracketWidth) - characterWidth) > width && bracketWidth <= width) { count = previous; @@ -126,16 +106,23 @@ void UIWindow::WrapPixelText(const char* text, std::vector& lines, continue; } - std::string line(begin, static_cast(count)); + char* buffer = new char[count + 1]; + std::memcpy(buffer, begin, count); if (newline) { - line[static_cast(count - 1)] = '\0'; - line.resize(std::strlen(line.c_str())); - lines.push_back(line.empty() ? " " : line); + buffer[count - 1] = '\0'; + + if (std::strlen(buffer) == 0) { + lines.push_back(" "); + } else { + lines.push_back(buffer); + } } else { - lines.push_back(std::move(line)); + buffer[count] = '\0'; + lines.push_back(buffer); } + delete[] buffer; offset = (offset + count); } }