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

Merged
Dufftwt merged 1 commit from upstream-pr/111 into main 2026-11-24 07:50:16 +00:00
Dufftwt commented 2026-11-24 00:36:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dufftwt on 2026-11-24T00:36:54Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6571885556 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/111). Originally posted by [Dufftwt](https://github.com/Dufftwt) on 2026-11-24T00:36:54Z. --- ## 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.
DaviTostes commented 2026-11-24 06:54:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:12:02Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118860214 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/111#issuecomment-7118860214). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:12:02Z. --- 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.
upstream-sync closed this pull request 2026-11-24 08:01:48 +00:00
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!111
No description provided.