[pr-fix] hle: the narrow (A) text surface uses the ANSI code page #404
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
hle
input
INTEL
lighting
linux-proton
memory
MULDER
needs-info
needs-logs
needs-rebase
NVIDIA
performance
post-merge
pr-diagnostics
pr-docs
pre-merge
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
relevance
high
relevance
low
relevance
medium
relevance
very-high
rendering
report
roadmap-proposal
saves
series-s
shaders
startup
status
blocked-by-rework
status
needs-test-report
status
needs-triage
status
ready-for-review
status
stale
status
superseded
status
wip
tools
ui
upstream
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
TrustNo1/Darner!404
Loading…
Reference in a new issue
No description provided.
Delete branch "qnjk/Darner:hle-ansi-narrow"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Contributor role (optional)
What it changes
The problem on main: the narrow (A-suffix) text surface encodes UTF-8 where Windows uses the ANSI code page.
pathis a RustString, soas_bytes()is UTF-8;CString::new(&str)keeps the UTF-8 bytes too. The wide twin encodes properly (path.encode_utf16(),kernel.rs:117), andGetCommandLineA, six hundred lines below, already writes the code page (host::ansi(&wide),kernel.rs:736, helper at:1469) with a doc that says the narrow line "is the wide one in the ANSI code page, as Windows gives it".files::narrowdecodes every path the title hands back asCP_ACP. So one non-ASCII character made our own APIs disagree with each other and with the host:C:\Spiele\Zoë\game.exe,GetModuleFileNameAwroteZoëasC3 ABand returned 23 whereGetModuleFileNameWreturned 22. A title that took its directory from there and opened a file under it handed us those same bytes, whichCP_ACPreads asë: the file is not found.__p___argvcarried5A 6F C3 ABwhileGetCommandLineAcarried the code page's bytes for the same text — the very pair the doc atkernel.rs:740-744says matches.This change encodes both with
host::ansi, through one newnarrow_arghelper for argv, and decodesXLaunchNewGame's path and argument line withCP_ACPinstead of UTF-8 (crates/darner-hle/src/modules/xgame.rs). That last part is required by the same change:launch_new_gamegets the title's own path, which the doc it carries says comes fromGetModuleFileNameA; leaving it ontext()(UTF-8) would turn a correct ANSI path into a wrong one for a non-ASCII install folder.How it was tested
9acd1d4(one commit onf3840d7).cargo test --locked -p darner-hle --lib— 495 passed, 0 failed, 15 ignored.kernel::tests::the_narrow_module_name_is_in_the_ansi_code_page— recordsC:\Spiele\Zoë\game.exewithruntime::set_image_path, comparesGetModuleFileNameA's bytes withhost::ansiof the same path and its count withGetModuleFileNameW's, asserts the bytes are not UTF-8 whenGetACP() != 65001, and checks an ASCII path is unchanged byte for byte.kernel::tests::the_titles_arguments_are_in_the_ansi_code_page— readstitle_argv("darner.exe", &["-name=Zoë", "-x=1"])back as bytes and compares entry 1 withhost::ansi, entry 0 and 2 with ASCII.195, 171iszoë's UTF-8ë; the right-hand bytes are whatWideCharToMultiByte(CP_ACP, …)writes on this machine (its best-fit mapsëtoe).cargo clippy --workspace --all-targets --locked -- -D warnings: passes.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.cargo test --workspace --locked: not green on this machine, and not because of this change. Three pre-existing failures, each covered by an open pull request:darner-gpustands still in parallel on the test deadlock #224 describes, and serially finishes 1772 passed and 1 failed (pipeline::make::tests::a_capped_draw_waits_once_then_drops, which passes on its own) beside the order-dependentwatch::tests::ask_once_by_res_splits_reservations_without_refusalsandtexture::ahead::tests::drain_waits_until_then_callbacks_have_runflakes of #150;darner-shaderfailsemit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders, whose fixture #227 fixes.darner-hle's own suite is green.main.GetACP()); the tests say so and skip the "not UTF-8" assertion on a UTF-8 code page.GetModuleFileNameAand__p___argvare converted. Other narrow surfaces keep their own encoding decisions and are not part of this change; thetext()helper is still used for the protocol-activation URI, which is not a path the title produced from an A API. No non-ASCII run was done.Checklist
mainand pass here.main.docs/asset-policy.md. (cargo xtask policy: 555 files ok.)Checked for overlap
crates/darner-hle/src/modules/kernel.rsorxgame.rs(checked against the file list of all 161 open pull requests), and no open or closed issue mentionsGetModuleFileName,CP_ACP, the code page orargv.Tested on Windows 11 (Ryzen 7 9800X3D, RTX 5080): the new tests pass, and the full
darner-hlesuite passes (495 passed, 0 failed, 15 ignored, plus 2 integration tests).Review: this fixes a real path-handling bug: a title that took its directory from
GetModuleFileNameAand opened a file under it was handed UTF-8 bytes its own code page never produced. The fix is consistent across all three surfaces (module name, narrowargv, andXLaunchNewGame), and decoding the relaunch arguments withMultiByteToWideChar(CP_ACP)matches how they were written. One note on coverage: the tests' "not UTF-8" assertions only run on a non-65001 ACP. This machine is 1252 so they did run, but on an ACP-65001 machine they would be skipped and the test would pass even with the old behavior.Drafted with AI assistance (OpenCode).
Thanks for the run and the review. The note about the ACP is right, and it is worth saying why that skip cannot hide a regression: on an ACP-65001 machine the two behaviours are byte-identical. Today's code writes
path.as_bytes(), which is UTF-8; the fix writeshost::ansi(..), which isWideCharToMultiByte(CP_ACP, ..)and withCP_ACP = 65001is UTF-8 as well. Same bytes, same count, so there is nothing on such a machine for a test to distinguish -- the fix is a no-op there, and theassert_ne!that is skipped is the only assertion that could differ.What still runs on every machine is what pins the contract: the bytes equal
host::ansiof the same path (which is what the host's own A APIs produce), the ASCII path is unchanged byte for byte, and the count equalsGetModuleFileNameW's. The gate mirrors the neighbouringthe_narrow_command_line_is_in_the_ansi_code_page, which skips its "not UTF-8" assertion the same way for the same reason.For a UTF-8 ACP install the honest statement is that this change cannot be observed, not that the test is weak; I have not been able to construct a case where the old and the new code disagree there.