Skip to content

Commit

Permalink
Set debug console to UTF8 (fix Japanese output on non-Japanese locales)
Browse files Browse the repository at this point in the history
  • Loading branch information
PiKeyAr committed Dec 2, 2024
1 parent 4abd451 commit 0011007
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions SADXModLoader/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 0011007

Please sign in to comment.