HLE: GetModuleFileNameA answers in the ANSI code page #633

Open
github-bot wants to merge 1 commit from github-bot/gh-633 into main AGit
Owner

@⁠JFIREonFIRE on GitHub · 2026-11-24 05:57 UTC · original
JFIREonFIRE:fix/module-file-name-ansi → main · +91 −2 · 2 files · 1 commits · open

For a title image, GetModuleFileNameA (crates/victory-hle/src/modules/kernel.rs) copied the path's UTF-8 bytes. The Win32 A functions use the process's ANSI code page, and the rest of this crate already assumes that:

  • for host modules we forward to the host's GetModuleFileNameA, which returns ANSI;
  • files.rs narrow() decodes every narrow title path with MultiByteToWideChar(CP_ACP);
  • paths off the virtual drives go to the host's CreateFileA / CRT, which decode with CP_ACP too.

So when the game is installed under a folder name outside ASCII, the title's own location comes back mangled for anything it builds from it:

C:\Spiele\Grüße\game.exe, code page 1252 bytes for üß decoded with CP_ACP
before C3 BC C3 9F (UTF-8) Grüße, another folder
after FC DF Grüße

Truncation also counted UTF-8 bytes, so it could cut a character in half.

Change

  • GetModuleFileNameA converts the name with WideCharToMultiByte(CP_ACP), as the host does: characters the code page lacks become ?.
  • XLaunchNewGame gets that same path back from the title (the doc comment says Grand Theft Auto VI relaunches itself with its own path from GetModuleFileNameA). It now decodes the executable with MultiByteToWideChar(CP_ACP) instead of as UTF-8, so a relaunch from such a folder still finds its executable.
  • Two small helpers, kernel::to_ansi and kernel::from_ansi.

Paths in ASCII are unchanged.

Tests

  • New a_title_image_name_is_in_the_ansi_code_page: it registers C:\Spiele\Grüße\game.exe, checks that GetModuleFileNameA returns the CP_ACP bytes and that they decode back to the path, and, under code page 1252, checks for FC DF. It fails on main (UTF-8 bytes) and passes with the change. Under a UTF-8 code page (65001) the bytes are the same either way and it still passes.
  • cargo test --workspace passes on Windows 11 (code page 1252, RTX 3090).
  • Formatting and clippy are clean for the changed lines. No game data used.

This doesn't overlap #186 or #373, which change the last error and the null buffer of the same function, or #455, which changes the relaunch argument matching. I searched PRs and issues for GetModuleFileNameA, ANSI / code page, XLaunchNewGame and non-ASCII paths and found nothing else.

AI use: Claude Code (Claude Opus 5.5) found the issue, wrote the change and test, and ran them.

🤖 Generated with Claude Code

**@⁠JFIREonFIRE** on GitHub · 2026-11-24 05:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/633) `JFIREonFIRE:fix/module-file-name-ansi` → `main` · +91 −2 · 2 files · 1 commits · open For a title image, `GetModuleFileNameA` (`crates/victory-hle/src/modules/kernel.rs`) copied the path's **UTF-8** bytes. The Win32 `A` functions use the process's **ANSI code page**, and the rest of this crate already assumes that: - for host modules we forward to the host's `GetModuleFileNameA`, which returns ANSI; - `files.rs` `narrow()` decodes every narrow title path with `MultiByteToWideChar(CP_ACP)`; - paths off the virtual drives go to the host's `CreateFileA` / CRT, which decode with CP_ACP too. So when the game is installed under a folder name outside ASCII, the title's own location comes back mangled for anything it builds from it: | `C:\Spiele\Grüße\game.exe`, code page 1252 | bytes for `üß` | decoded with CP_ACP | |---|---|---| | before | `C3 BC C3 9F` (UTF-8) | `Grüße`, another folder | | after | `FC DF` | `Grüße` | Truncation also counted UTF-8 bytes, so it could cut a character in half. ### Change - `GetModuleFileNameA` converts the name with `WideCharToMultiByte(CP_ACP)`, as the host does: characters the code page lacks become `?`. - `XLaunchNewGame` gets that same path back from the title (the doc comment says Grand Theft Auto VI relaunches itself with its own path from `GetModuleFileNameA`). It now decodes the executable with `MultiByteToWideChar(CP_ACP)` instead of as UTF-8, so a relaunch from such a folder still finds its executable. - Two small helpers, `kernel::to_ansi` and `kernel::from_ansi`. Paths in ASCII are unchanged. ### Tests - New `a_title_image_name_is_in_the_ansi_code_page`: it registers `C:\Spiele\Grüße\game.exe`, checks that `GetModuleFileNameA` returns the CP_ACP bytes and that they decode back to the path, and, under code page 1252, checks for `FC DF`. It fails on `main` (UTF-8 bytes) and passes with the change. Under a UTF-8 code page (65001) the bytes are the same either way and it still passes. - `cargo test --workspace` passes on Windows 11 (code page 1252, RTX 3090). - Formatting and clippy are clean for the changed lines. No game data used. This doesn't overlap #186 or #373, which change the last error and the null buffer of the same function, or #455, which changes the relaunch argument matching. I searched PRs and issues for `GetModuleFileNameA`, ANSI / code page, `XLaunchNewGame` and non-ASCII paths and found nothing else. **AI use:** Claude Code (Claude Opus 5.5) found the issue, wrote the change and test, and ran them. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
For a title image, `GetModuleFileNameA` copied the path's UTF-8 bytes.
The `A` functions speak the ANSI code page: the host's own
`GetModuleFileNameA` (which we forward to for host modules) does, and our
narrow file functions (`files.rs` `narrow()`) and the host CRT decode
title paths with CP_ACP. So with an install folder outside ASCII
(`C:\Spiele\Grüße\...` under code page 1252) the title got
`Gr\xC3\xBC\xC3\x9Fe`, and any path it built from its own location named
another folder (`Grüße`).

Now the name is converted with `WideCharToMultiByte(CP_ACP)`, like the
host does. `XLaunchNewGame` receives that path back from the title
(Grand Theft Auto VI relaunches itself with it), so it decodes the
executable with `MultiByteToWideChar(CP_ACP)` instead of as UTF-8.

Test: `a_title_image_name_is_in_the_ansi_code_page` fails without the
change (UTF-8 bytes instead of 0xFC 0xDF under code page 1252).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:10:46 +00:00
Author
Owner

@⁠pickles976 on GitHub · 2026-11-24 06:01 UTC · original

Cross-checked against the sibling project (ivall/xcl) while reviewing this: their write_ansi_out already routes through WideCharToMultiByte(CP_ACP, …) for the same A-function semantics, so this class looks fixed/never-present on that side. Posting here so the cross-project bug ledger stays honest in both directions — sites and semantics transfer whether the news is good or bad.

**@⁠pickles976** on GitHub · 2026-11-24 06:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/633#issuecomment-7123495728) Cross-checked against the sibling project (ivall/xcl) while reviewing this: their `write_ansi_out` already routes through `WideCharToMultiByte(CP_ACP, …)` for the same `A`-function semantics, so this class looks fixed/never-present on that side. Posting here so the cross-project bug ledger stays honest in both directions — sites and semantics transfer whether the news is good or bad.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:31 UTC · original

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-hle/src/modules/kernel.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/633#issuecomment-7148599096) <!-- victory-triage v1 head=90bc075458372756f52c63648a6bc00bdbdebce0 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-hle/src/modules/kernel.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-hle/src/modules/kernel.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/633/head:github-bot/gh-633'
git switch 'github-bot/gh-633'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-633'
git switch 'github-bot/gh-633'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-633'
git switch 'github-bot/gh-633'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-633'
git switch 'main'
git merge --squash 'github-bot/gh-633'
git switch 'main'
git merge --ff-only 'github-bot/gh-633'
git switch 'main'
git merge 'github-bot/gh-633'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!633
No description provided.