Decompile 4 functions in Source/Network/TextEncoding.cpp

Batch #12152 by cremane: 4 byte-identical, 0 confirmed by peer review.

- fn_18243 ToUtf8: byte-identical
- fn_18257 LowercaseText: byte-identical
- fn_18258 DecodeText: byte-identical
- fn_18264 FromUtf8: byte-identical

Merged automatically: every function is byte-identical to the original.
This commit is contained in:
ragnarok-clanker 2026-11-05 11:53:04 +00:00
commit 880ec06f38

View file

@ -67,80 +67,32 @@ std::string FromUtf8(std::string text) {
// OFFSET: 0x00AF87B0
// FUNCTION: fn_18264
std::string FromUtf8(const std::string& text, UINT codePage) {
int wideLength = MultiByteToWideChar(CP_UTF8, 0, text.data(), static_cast<int>(text.size()), nullptr, 0);
if (!wideLength) {
return {};
std::wstring wide = DecodeText(CP_UTF8, text);
if (wide.empty()) {
return "";
}
BSTR wide = SysAllocStringLen(nullptr, wideLength);
if (!wide) {
return {};
std::string result = EncodeText(codePage, wide);
if (result.empty()) {
return "";
}
if (!MultiByteToWideChar(CP_UTF8, 0, text.data(), static_cast<int>(text.size()), wide, wideLength)) {
SysFreeString(wide);
return {};
}
int length = WideCharToMultiByte(codePage, 0, wide, -1, nullptr, 0, nullptr, nullptr);
if (!length) {
SysFreeString(wide);
return {};
}
char* converted = static_cast<char*>(std::malloc(length));
if (!converted) {
SysFreeString(wide);
return {};
}
std::string result;
if (WideCharToMultiByte(codePage, 0, wide, -1, converted, length, nullptr, nullptr)) {
result.assign(converted);
}
std::free(converted);
SysFreeString(wide);
return result;
}
// OFFSET: 0x00AF4050
// FUNCTION: fn_18243
std::string ToUtf8(const std::string& text, UINT codePage) {
int wideLength = MultiByteToWideChar(codePage, 0, text.data(), static_cast<int>(text.size()), nullptr, 0);
if (!wideLength) {
return {};
std::wstring wide = DecodeText(codePage, text);
if (wide.empty()) {
return "";
}
BSTR wide = SysAllocStringLen(nullptr, wideLength);
if (!wide) {
return {};
std::string result = EncodeText(CP_UTF8, wide);
if (result.empty()) {
return "";
}
if (!MultiByteToWideChar(codePage, 0, text.data(), static_cast<int>(text.size()), wide, wideLength)) {
SysFreeString(wide);
return {};
}
int length = WideCharToMultiByte(CP_UTF8, 0, wide, -1, nullptr, 0, nullptr, nullptr);
if (!length) {
SysFreeString(wide);
return {};
}
char* converted = static_cast<char*>(std::malloc(length));
if (!converted) {
SysFreeString(wide);
return {};
}
std::string result;
if (WideCharToMultiByte(CP_UTF8, 0, wide, -1, converted, length, nullptr, nullptr)) {
result.assign(converted);
}
std::free(converted);
SysFreeString(wide);
return result;
}
@ -148,10 +100,12 @@ std::string ToUtf8(const std::string& text, UINT codePage) {
// FUNCTION: fn_18257
void LowercaseText(std::string& text) {
for (unsigned index = 0; index < text.size(); ++index) {
if (static_cast<signed char>(text[index]) <= 0) {
if (static_cast<signed char>(text[index]) > 0) {
if (std::isupper(text[index]) != 0) {
text[index] += 32;
}
} else {
++index;
} else if (std::isupper(text[index]) != 0) {
text[index] += 32;
}
}
}
@ -161,15 +115,15 @@ void LowercaseText(std::string& text) {
std::wstring DecodeText(UINT codePage, const std::string& text) {
const int length = MultiByteToWideChar(codePage, 0, text.data(), static_cast<int>(text.size()), nullptr, 0);
if (length == 0) {
return {};
return L"";
}
BSTR converted = SysAllocStringLen(nullptr, length);
if (converted == nullptr) {
return {};
return L"";
}
if (MultiByteToWideChar(codePage, 0, text.data(), static_cast<int>(text.size()), converted, length) == 0) {
SysFreeString(converted);
return {};
return L"";
}
std::wstring result(converted);
SysFreeString(converted);