Files: send rewritten narrow paths to the host, not to our wide wrappers #111

Manually merged
github merged 1 commit from gh-pr/111/head into gh-pr/111/base 2026-11-26 03:50:36 +00:00
Owner

@⁠Dufftwt on GitHub · 2026-11-24 00:36 UTC · original
Dufftwt:fix/narrow-paths-translated-twice → main · +88 −16 · 1 files · 1 commits · merged 2026-11-24 07:50 UTC

What's wrong

The title sees its console drives because VIctory mounts host folders as drive letters. The game folder is always G: and the temp folder is always T:. Every file call the title makes goes through a wrapper in files.rs that turns G:\... into the real host path.

Five of the narrow (char*) wrappers rewrite the path correctly, but then hand the result to our own wide wrapper instead of to Windows:

  • CreateFileA → our CreateFileW
  • GetFileAttributesA → our GetFileAttributesW
  • fopen → our _wfopen
  • fopen_s → our _wfopen_s
  • std::_Fiopen (what std::ifstream / std::ofstream use) → our wide _Fiopen

The wide wrapper rewrites the path a second time. Usually that does nothing, because the host path starts with a letter that isn't mounted. But G: and T: are fixed letters. So if the game is installed on a host G: drive, the host path starts with G: as well and is rewritten again:

title asks for    G:\x64\a.rpf
first rewrite     G:\GTA6\x64\a.rpf          <- correct
second rewrite    G:\GTA6\GTA6\x64\a.rpf     <- does not exist

On that setup, every narrow open of a game file fails, or creates a file in the wrong folder. The wide calls are fine, so the failures look random. The same happens with T: if the data folder is on a host T: drive.

The other narrow wrappers in the same file already do this correctly: DeleteFileA, SetCurrentDirectoryA, _open, _stat64i32 and remove pass the rewritten path straight to the host's wide function.

What the fix does

The five wrappers now call the host's wide function directly, using the existing host! macro, just like their siblings. A narrow path is now rewritten exactly once, the same as a wide path. The module comment now explains why they must not go through our wide wrappers.

How it behaves after the fix

  • With the game on any drive, including a host G: or T:, a narrow call and its wide twin open the same file.
  • Every other setup works exactly as before. The first rewrite is unchanged, and the second rewrite never did anything in those setups.

Tests

The new test narrow_paths_are_rewritten_once in files.rs:

  1. mounts a temporary folder as one drive letter;
  2. mounts a subfolder of it, given by its path on that virtual drive, as a second letter. This is the same shape as a game folder on a host G: drive mounted as G:;
  3. checks that each of the five narrow calls behaves like its wide twin and creates nothing behind a twice-rewritten path.

I ran cargo test --workspace --no-fail-fast on GitHub's windows-latest with Rust 1.98.1 from rust-toolchain.toml:

  • This PR: the new test passes; victory-hle has 82 passed and 0 failed.
  • The new test alone on main: it fails. GetFileAttributesA finds the file through the doubled path (left: 32, right: 4294967295).
  • In both runs the only other failure is victory-gpu's root::tests::host_serialized_blobs_create_root_signatures. It fails the same way on unmodified main on that runner, and #36 changes that test.

Not tested: a real run of the game installed on a G: drive.

**@⁠Dufftwt** on GitHub · 2026-11-24 00:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/111) `Dufftwt:fix/narrow-paths-translated-twice` → `main` · +88 −16 · 1 files · 1 commits · merged 2026-11-24 07:50 UTC ## What's wrong The title sees its console drives because VIctory mounts host folders as drive letters. The game folder is always `G:` and the temp folder is always `T:`. Every file call the title makes goes through a wrapper in `files.rs` that turns `G:\...` into the real host path. Five of the narrow (`char*`) wrappers rewrite the path correctly, but then hand the result to **our own** wide wrapper instead of to Windows: - `CreateFileA` → our `CreateFileW` - `GetFileAttributesA` → our `GetFileAttributesW` - `fopen` → our `_wfopen` - `fopen_s` → our `_wfopen_s` - `std::_Fiopen` (what `std::ifstream` / `std::ofstream` use) → our wide `_Fiopen` The wide wrapper rewrites the path a **second** time. Usually that does nothing, because the host path starts with a letter that isn't mounted. But `G:` and `T:` are fixed letters. So if the game is installed on a host `G:` drive, the host path starts with `G:` as well and is rewritten again: ``` title asks for G:\x64\a.rpf first rewrite G:\GTA6\x64\a.rpf <- correct second rewrite G:\GTA6\GTA6\x64\a.rpf <- does not exist ``` On that setup, every narrow open of a game file fails, or creates a file in the wrong folder. The wide calls are fine, so the failures look random. The same happens with `T:` if the data folder is on a host `T:` drive. The other narrow wrappers in the same file already do this correctly: `DeleteFileA`, `SetCurrentDirectoryA`, `_open`, `_stat64i32` and `remove` pass the rewritten path straight to the host's wide function. ## What the fix does The five wrappers now call the host's wide function directly, using the existing `host!` macro, just like their siblings. A narrow path is now rewritten exactly once, the same as a wide path. The module comment now explains why they must not go through our wide wrappers. ## How it behaves after the fix - With the game on any drive, including a host `G:` or `T:`, a narrow call and its wide twin open the same file. - Every other setup works exactly as before. The first rewrite is unchanged, and the second rewrite never did anything in those setups. ## Tests The new test `narrow_paths_are_rewritten_once` in `files.rs`: 1. mounts a temporary folder as one drive letter; 2. mounts a subfolder of it, given by its path on that virtual drive, as a second letter. This is the same shape as a game folder on a host `G:` drive mounted as `G:`; 3. checks that each of the five narrow calls behaves like its wide twin and creates nothing behind a twice-rewritten path. I ran `cargo test --workspace --no-fail-fast` on GitHub's `windows-latest` with Rust 1.98.1 from `rust-toolchain.toml`: - **This PR:** the new test passes; `victory-hle` has 82 passed and 0 failed. - **The new test alone on `main`:** it fails. `GetFileAttributesA` finds the file through the doubled path (`left: 32, right: 4294967295`). - In both runs the only other failure is `victory-gpu`'s `root::tests::host_serialized_blobs_create_root_signatures`. It fails the same way on unmodified `main` on that runner, and #36 changes that test. **Not tested:** a real run of the game installed on a `G:` drive.
CreateFileA, GetFileAttributesA, fopen, fopen_s and the narrow
std::_Fiopen turn the title's virtual-drive path into a host path and
then passed it to our own wide wrapper, which looked it up a second time.
When the host path starts with a letter that is itself mounted, it was
rewritten again: with the game on a host G: drive (say G:\GTA6), the
title's G:\x64\a.rpf became G:\GTA6\x64\a.rpf and then
G:\GTA6\GTA6\x64\a.rpf, so every narrow open of a title file failed.
The same happens for T: when the data folder is on a host T: drive.

They now call the host's wide function directly, as DeleteFileA,
SetCurrentDirectoryA, _open, _stat64i32 and remove already do.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:50:33 +00:00
github manually merged commit 27b530e7e1 into gh-pr/111/base 2026-11-26 03:50:36 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:12 UTC · original

Tested 27b530e: pass (no regression).

  • Tested the Windows build under Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), cargo xwin ... --target x86_64-pc-windows-msvc -p victory-hle: 81 passed, 1 failed, including the 1 test this PR adds.
  • The one failure is modules::net::tests::only_loopback_is_reachable (Wine lacks WSAConnectByList, as in #118), not this PR.

No game data used.

**@⁠DaviTostes** on GitHub · 2026-11-24 01:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/111#issuecomment-7118860214) Tested `27b530e`: **pass (no regression)**. - Tested the Windows build under **Wine 11.22 + vkd3d-proton 3.1** on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), `cargo xwin ... --target x86_64-pc-windows-msvc -p victory-hle`: **81 passed, 1 failed**, including the 1 test this PR adds. - The one failure is `modules::net::tests::only_loopback_is_reachable` (Wine lacks `WSAConnectByList`, as in #118), not this PR. No game data used.
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!111
No description provided.