diff options
| author | Dominik <55330408+Dom-in@users.noreply.github.com> | 2026-11-22 21:10:40 +0000 |
|---|---|---|
| committer | Dominik <55330408+Dom-in@users.noreply.github.com> | 2026-11-22 21:10:40 +0000 |
| commit | f74b8eb87e2bc35a3d31d583d8b261cb5c31c829 (patch) | |
| tree | a180a60776bdccf42a2832aa2a8a39e73ea348f6 /runtime | |
| parent | e3662721ea213d0b4a2161ee3ada022c3c6bd9dc (diff) | |
xgameruntime: read LEONIDA_GAME_DIR wide for MicrosoftGame.Config
GetEnvironmentVariableA narrowed a game folder named outside the ANSI code page
(e.g. a runic or CJK character on cp1252), so the package locale lookup missed
its MicrosoftGame.Config. Read the variable and open the file wide. The test
uses U+16A0, which no ANSI code page has (it fails with the narrow read).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/shims/xgameruntime.cpp | 9 | ||||
| -rw-r--r-- | runtime/test/xgameruntime_test.cpp | 20 |
2 files changed, 25 insertions, 4 deletions
diff --git a/runtime/shims/xgameruntime.cpp b/runtime/shims/xgameruntime.cpp index 5e6846d66..fd7c8267a 100644 --- a/runtime/shims/xgameruntime.cpp +++ b/runtime/shims/xgameruntime.cpp | |||
| @@ -731,11 +731,12 @@ bool STDMETHODCALLTYPE pkg_is_packaged(void*) { return XPackageIsPackagedProcess | |||
| 731 | // the game folder (LEONIDA_GAME_DIR, else --game-dir). Empty when there is no config or it declares none. | 731 | // the game folder (LEONIDA_GAME_DIR, else --game-dir). Empty when there is no config or it declares none. |
| 732 | std::vector<std::string> package_locales() { | 732 | std::vector<std::string> package_locales() { |
| 733 | std::vector<std::string> out; | 733 | std::vector<std::string> out; |
| 734 | char env[MAX_PATH] = {}; | 734 | // Wide on purpose: a game folder outside the ANSI code page (e.g. C:\Users\Łukasz) must reach the file intact. |
| 735 | const DWORD n = GetEnvironmentVariableA("LEONIDA_GAME_DIR", env, sizeof(env)); | 735 | wchar_t env[MAX_PATH] = {}; |
| 736 | const std::filesystem::path dir = (n > 0 && n < sizeof(env)) ? std::filesystem::path(env) : rt::fs::game_dir(); | 736 | const DWORD n = GetEnvironmentVariableW(L"LEONIDA_GAME_DIR", env, MAX_PATH); |
| 737 | const std::filesystem::path dir = (n > 0 && n < MAX_PATH) ? std::filesystem::path(env) : rt::fs::game_dir(); | ||
| 737 | if (dir.empty()) return out; | 738 | if (dir.empty()) return out; |
| 738 | std::ifstream f(dir / "MicrosoftGame.Config", std::ios::binary); | 739 | std::ifstream f(dir / L"MicrosoftGame.Config", std::ios::binary); |
| 739 | if (!f) return out; | 740 | if (!f) return out; |
| 740 | const std::string xml{std::istreambuf_iterator<char>(f), {}}; | 741 | const std::string xml{std::istreambuf_iterator<char>(f), {}}; |
| 741 | for (size_t at = 0; (at = xml.find("<Resource", at)) != std::string::npos; ++at) { | 742 | for (size_t at = 0; (at = xml.find("<Resource", at)) != std::string::npos; ++at) { |
diff --git a/runtime/test/xgameruntime_test.cpp b/runtime/test/xgameruntime_test.cpp index fe7942ff0..12c47a157 100644 --- a/runtime/test/xgameruntime_test.cpp +++ b/runtime/test/xgameruntime_test.cpp | |||
| @@ -466,6 +466,26 @@ void check_run_time_load() { | |||
| 466 | DeleteFileA((game + "\\MicrosoftGame.Config").c_str()); | 466 | DeleteFileA((game + "\\MicrosoftGame.Config").c_str()); |
| 467 | RemoveDirectoryA(game.c_str()); | 467 | RemoveDirectoryA(game.c_str()); |
| 468 | SetEnvironmentVariableA("LEONIDA_GAME_DIR", nullptr); | 468 | SetEnvironmentVariableA("LEONIDA_GAME_DIR", nullptr); |
| 469 | { | ||
| 470 | // A game folder outside every ANSI code page (U+16A0, a runic letter) reaches MicrosoftGame.Config intact. | ||
| 471 | wchar_t wtmp[MAX_PATH] = {}; | ||
| 472 | GetTempPathW(MAX_PATH, wtmp); | ||
| 473 | const std::wstring wide = std::wstring(wtmp) + L"leonida_xpackage_\u16a0ocale"; | ||
| 474 | CreateDirectoryW(wide.c_str(), nullptr); | ||
| 475 | SetEnvironmentVariableW(L"LEONIDA_GAME_DIR", wide.c_str()); | ||
| 476 | const std::wstring wconfig = wide + L"\\MicrosoftGame.Config"; | ||
| 477 | if (FILE* f = _wfopen(wconfig.c_str(), L"wb")) { | ||
| 478 | std::fputs("<Game><Resources><Resource Language=\"qq-QQ\"/></Resources></Game>", f); | ||
| 479 | std::fclose(f); | ||
| 480 | } | ||
| 481 | char wlocale[32] = {}; | ||
| 482 | check(reinterpret_cast<Locale>(slot(pk, 11))(pk, sizeof(wlocale), wlocale) == S_OK && | ||
| 483 | std::strcmp(wlocale, "qq-QQ") == 0, | ||
| 484 | "slot 11 reads MicrosoftGame.Config from a game folder named outside the ANSI code page"); | ||
| 485 | DeleteFileW(wconfig.c_str()); | ||
| 486 | RemoveDirectoryW(wide.c_str()); | ||
| 487 | SetEnvironmentVariableW(L"LEONIDA_GAME_DIR", nullptr); | ||
| 488 | } | ||
| 469 | // Slots 23-26 are the named exports' content-package mounts: XPackageMount, the path size and path of the | 489 | // Slots 23-26 are the named exports' content-package mounts: XPackageMount, the path size and path of the |
| 470 | // handle, and closing it. XPackageMountHandle is one u64, passed by value. | 490 | // handle, and closing it. XPackageMountHandle is one u64, passed by value. |
| 471 | using Mount = HRESULT(STDMETHODCALLTYPE*)(void*, const char*, uint64_t*); | 491 | using Mount = HRESULT(STDMETHODCALLTYPE*)(void*, const char*, uint64_t*); |