Skip to content

Commit

Permalink
fix locale switch for names with non-ascii characters (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady authored Jul 28, 2024
1 parent d5f2ebd commit e47485e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Server/Source/core_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1778,18 +1778,18 @@ class Core final : public ICore, public PlayerConnectEventHandler, public Consol
#ifdef BUILD_WINDOWS
_lock_locales();
UINT oldCP = 0;
char oldLocale[64] = { 0 };
wchar_t oldLocale[64] = { 0 };
bool oldLocaleSaved = false;
if (utf8)
{
oldCP = GetConsoleOutputCP();
SetConsoleOutputCP(CP_UTF8);

/* Getting current locale */
const char* old_locale_ptr = std::setlocale(LC_CTYPE, nullptr);
const wchar_t* old_locale_ptr = _wsetlocale(LC_CTYPE, nullptr);
if (old_locale_ptr != nullptr)
{
strcpy_s(oldLocale, old_locale_ptr);
wcscpy_s(oldLocale, old_locale_ptr);
oldLocaleSaved = true;

std::setlocale(LC_CTYPE, ".UTF-8");
Expand Down Expand Up @@ -1867,7 +1867,7 @@ class Core final : public ICore, public PlayerConnectEventHandler, public Consol
{
if (oldLocaleSaved)
{
std::setlocale(LC_CTYPE, oldLocale);
_wsetlocale(LC_CTYPE, oldLocale);
}
SetConsoleOutputCP(oldCP);
}
Expand Down

0 comments on commit e47485e

Please sign in to comment.