From 64e5e893d379ea482b91df87653bb3b33becfa09 Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Thu, 5 Nov 2026 04:03:27 +0000 Subject: [PATCH] Decompile 3 functions in Source/Utility/Text/FormatString.cpp Batch #11646 by cremane: 2 byte-identical, 1 confirmed by peer review. - fn_03451 StringFormat: byte-identical - fn_07595 ?GetBuffer@ThreadSafeBuffer@?A0xfae978cd@@QAEPADXZ: logic confirmed by peer review - fn_18252 FormatOwnedString: byte-identical 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/Utility/Text/FormatString.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Source/Utility/Text/FormatString.cpp b/Source/Utility/Text/FormatString.cpp index e121f122..41a984f0 100644 --- a/Source/Utility/Text/FormatString.cpp +++ b/Source/Utility/Text/FormatString.cpp @@ -15,14 +15,12 @@ static char s_numberBuffer[1024]; // OFFSET: 0x005BAEF0 // FUNCTION: fn_03451 int StringFormat(char* buffer, std::size_t sizeInBytes, std::size_t count, const char* format, ...) { + int result; va_list args; - va_start(args, format); - const int result = __stdio_common_vsnprintf_s(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, buffer, sizeInBytes, count, format, nullptr, args); - va_end(args); - if (result < 0) { - return -1; - } + va_start(args, format); + result = _vsnprintf_s_l(buffer, sizeInBytes, count, format, nullptr, args); + va_end(args); return result; } @@ -45,21 +43,21 @@ namespace { private: /* 0004 */ CRITICAL_SECTION m_criticalSection; - /* 001C */ std::map> m_buffers; + /* 001C */ std::map> m_buffers; }; // OFFSET: 0x00734390 // FUNCTION: fn_07595 char* ThreadSafeBuffer::GetBuffer() { NSyncObject lock(&this->m_criticalSection); - HANDLE thread = GetCurrentThread(); + const int thread = reinterpret_cast(GetCurrentThread()); - auto it = this->m_buffers.find(thread); - if (it == this->m_buffers.end()) { - it = this->m_buffers.emplace(thread, std::array{}).first; + if (this->m_buffers.find(thread) == this->m_buffers.end()) { + std::array buffer{}; + this->m_buffers[thread] = buffer; } - return it->second.data(); + return this->m_buffers[thread].data(); } } @@ -82,10 +80,12 @@ const char* FormatString(const char* format, ...) { std::string FormatOwnedString(const char* format, ...) { char buffer[4096]; va_list arguments; + va_start(arguments, format); - _vsnprintf_s(buffer, sizeof(buffer), static_cast(-1), format, arguments); + _vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, format, arguments); va_end(arguments); - return std::string(buffer, std::strlen(buffer)); + + return std::string(buffer); } // OFFSET: 0x00A95590