From 001100722566febc9580ab05c8df25e15328042d Mon Sep 17 00:00:00 2001 From: PiKeyAr Date: Mon, 2 Dec 2024 11:04:18 +0900 Subject: [PATCH] Set debug console to UTF8 (fix Japanese output on non-Japanese locales) --- SADXModLoader/dllmain.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/SADXModLoader/dllmain.cpp b/SADXModLoader/dllmain.cpp index c9d0b9d6..2cbc0e78 100644 --- a/SADXModLoader/dllmain.cpp +++ b/SADXModLoader/dllmain.cpp @@ -304,24 +304,28 @@ static int __cdecl SADXDebugOutput(const char* Format, ...) // Console output. if (dbgConsole) { - // TODO: Convert from Shift-JIS to CP_ACP? - fputs(buf, stdout); - fflush(stdout); + char* utf8 = SJIStoUTF8(buf); + if (utf8) + { + fputs(utf8, stdout); + fflush(stdout); + delete utf8; + } } // Screen output. if (dbgScreen) { message msg = { { buf }, 0 }; - // Remove trailing newlines if present. - while (!msg.text.empty() && - (msg.text[msg.text.size() - 1] == '\n' || - msg.text[msg.text.size() - 1] == '\r')) - { - msg.text.resize(msg.text.size() - 1); + // Remove trailing newlines if present. + while (!msg.text.empty() && + (msg.text[msg.text.size() - 1] == '\n' || + msg.text[msg.text.size() - 1] == '\r')) + { + msg.text.resize(msg.text.size() - 1); + } + msgqueue.push_back(msg); } - msgqueue.push_back(msg); - } // File output. if (dbgFile) @@ -911,6 +915,10 @@ static void __cdecl InitMods() // Is any debug method enabled? if (dbgConsole || dbgScreen || dbgFile) { + // Set console output to UTF-8 + if (dbgConsole) + SetConsoleOutputCP(CP_UTF8); + WriteJump((void*)PrintDebug, (void*)SADXDebugOutput); PrintDebug("SADX Mod Loader v" VERSION_STRING " (API version %d), built " __TIMESTAMP__ "\n",