XGameRuntime: fix XPackageGetIdentifier crash, atomic GameSave, locale fallback, and controller ID #97

Manually merged
github merged 1 commit from gh-pr/97/head into gh-pr/97/base 2026-11-26 04:09:53 +00:00
Owner

@⁠raylitebull on GitHub · 2026-11-23 11:11 UTC · original
raylitebull:fix/xgameruntime-package-and-saves → main · +400 −19 · 5 files · 1 commits · merged 2026-11-23 11:25 UTC

Summary

Fixes a crash, save-atomicity/NTFS bugs, locale fallback, and controller lookup in crates/xcl/src/hle/xgameruntime/ and crates/xcl/src/manifest.rs:

  1. XPackageGetIdentifier (slot 27) 3-arg signature crash (mod.rs, api.rs):

    • gdk_table.rs already maps IID 0b9d556eab7043f4baa09999ac4cb040 slot 27 to "XPackageGetIdentifier" (verified against Windows xgameruntime.dll — this is a wrong function wiring on the already-correct IID/slot layout, not GDK version drift).
    • Previously slot 27 was wired to 2-arg XPackageGetCurrentProcessPackageIdentifier(size, buf) instead of 3-arg XPackageGetIdentifier(pathOrName, size, buf), causing the caller's bufferSize (e.g. 64) to be dereferenced as a pointer (0xC0000005).
    • Added proper 3-arg XPackageGetIdentifier and wired slot 27 to it.
  2. XGameSave atomic writes, temp-name isolation, NTFS case-insensitivity, and null out check (gamesave.rs):

    • Replaced path.with_extension("xcltmp") (which overwrote real .xcltmp blobs, made .xcltmp writes in-place, collided across concurrent writes like slot.sav/slot.meta, skipped sync_all(), and was enumerated as a real blob by blobs_of()) with write_atomic() using unique sibling temp files ~xcltmp.<pid>.<counter> (unreachable from enc() since ~ encodes to %7E), File::sync_all(), and MoveFileExW(..., MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) with cleanup on failure. blobs_of() skips ~xcltmp. files.
    • Applied ASCII case-insensitive matching for NTFS in each_container, each_blob, and read_layout (preferring exact matches first) so overwriting "Meta" as "meta" and reading "meta" works on NTFS.
    • Validated !out.is_null() in XGameSaveInitializeProviderResult before XAsyncGetResult so null out returns E_INVALIDARG without consuming the result or leaking Box<Provider>.
  3. XPackageGetUserLocale MicrosoftGame.Config <Resources> fallback (launcher.rs, manifest.rs, api.rs):

    • Parsed <Resources><Resource Language="..."/></Resources> into Manifest::languages (respecting existing UTF-8/UTF-16 decoding and XML comment stripping).
    • Matched the OS user locale against declared languages: exact case-insensitive match (-/_ normalized) -> primary-language subtag match (e.g. fr-CA -> fr-FR) -> first declared language (e.g. hr-HR -> en-US) -> raw OS locale only when <Resources> is absent.
  4. XUserFindControllerForUserWithUiAsync device ID (mod.rs):

    • Returned gameinput::gamepad_device_id() instead of 32 zero bytes so IGameInput::FindDeviceFromId matches the emulated controller.

(Note: The XGameSaveDeleteContainer(p, "") empty-name root-wipe data-loss fix was submitted separately in #95 so it can land independently.)

Testing

  • Before (origin/main):
    • Calling XPACKAGE slot 27 with (path, 64, buf) crashed with 0xC0000005 writing to 0x40.
    • Writing save.dat destroyed save.xcltmp, and leftover .xcltmp files appeared in blob enumeration.
    • Overwriting "Meta" as "meta" caused reading "meta" to return E_GS_BLOB_NOT_FOUND.
    • XGameSaveInitializeProviderResult(blk, null) consumed the async result and returned S_OK.
    • XPackageGetUserLocale returned raw OS locale instead of matching <Resources> languages.
    • XUserFindControllerForUserWithUiAsync returned 32 zero bytes.
  • After (new/updated regression tests):
    • xpackage_get_identifier_slot_27_uses_three_args & legacy_console_iids_map_to_their_own_slots
    • atomic_writes_preserve_xcltmp_blobs_and_skip_leftover_temps
    • case_insensitive_blob_and_container_matching_on_ntfs
    • initialize_provider_result_rejects_null_out_without_consuming_async
    • parses_declared_resources_languages_with_comments_and_utf16 & user_locale_selection_matches_manifest_resources
    • user_device_association_and_controller_lookup
  • Verified on origin/main (60599a9): cargo build --workspace and cargo test --workspace -- --test-threads=4 pass with 0 failures and 0 new warnings.
**@⁠raylitebull** on GitHub · 2026-11-23 11:11 UTC · [original](https://github.com/xcl-dev/xcl/pull/97) `raylitebull:fix/xgameruntime-package-and-saves` → `main` · +400 −19 · 5 files · 1 commits · merged 2026-11-23 11:25 UTC ## Summary Fixes a crash, save-atomicity/NTFS bugs, locale fallback, and controller lookup in `crates/xcl/src/hle/xgameruntime/` and `crates/xcl/src/manifest.rs`: 1. **`XPackageGetIdentifier` (slot 27) 3-arg signature crash (`mod.rs`, `api.rs`):** - `gdk_table.rs` already maps IID `0b9d556eab7043f4baa09999ac4cb040` slot 27 to `"XPackageGetIdentifier"` (verified against Windows `xgameruntime.dll` — this is a wrong function wiring on the already-correct IID/slot layout, not GDK version drift). - Previously slot 27 was wired to 2-arg `XPackageGetCurrentProcessPackageIdentifier(size, buf)` instead of 3-arg `XPackageGetIdentifier(pathOrName, size, buf)`, causing the caller's `bufferSize` (e.g. `64`) to be dereferenced as a pointer (`0xC0000005`). - Added proper 3-arg `XPackageGetIdentifier` and wired slot 27 to it. 2. **`XGameSave` atomic writes, temp-name isolation, NTFS case-insensitivity, and null `out` check (`gamesave.rs`):** - Replaced `path.with_extension("xcltmp")` (which overwrote real `.xcltmp` blobs, made `.xcltmp` writes in-place, collided across concurrent writes like `slot.sav`/`slot.meta`, skipped `sync_all()`, and was enumerated as a real blob by `blobs_of()`) with `write_atomic()` using unique sibling temp files `~xcltmp.<pid>.<counter>` (unreachable from `enc()` since `~` encodes to `%7E`), `File::sync_all()`, and `MoveFileExW(..., MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)` with cleanup on failure. `blobs_of()` skips `~xcltmp.` files. - Applied ASCII case-insensitive matching for NTFS in `each_container`, `each_blob`, and `read_layout` (preferring exact matches first) so overwriting `"Meta"` as `"meta"` and reading `"meta"` works on NTFS. - Validated `!out.is_null()` in `XGameSaveInitializeProviderResult` before `XAsyncGetResult` so null `out` returns `E_INVALIDARG` without consuming the result or leaking `Box<Provider>`. 3. **`XPackageGetUserLocale` `MicrosoftGame.Config` `<Resources>` fallback (`launcher.rs`, `manifest.rs`, `api.rs`):** - Parsed `<Resources><Resource Language="..."/></Resources>` into `Manifest::languages` (respecting existing UTF-8/UTF-16 decoding and XML comment stripping). - Matched the OS user locale against declared languages: exact case-insensitive match (`-`/`_` normalized) -> primary-language subtag match (e.g. `fr-CA` -> `fr-FR`) -> first declared language (e.g. `hr-HR` -> `en-US`) -> raw OS locale only when `<Resources>` is absent. 4. **`XUserFindControllerForUserWithUiAsync` device ID (`mod.rs`):** - Returned `gameinput::gamepad_device_id()` instead of 32 zero bytes so `IGameInput::FindDeviceFromId` matches the emulated controller. *(Note: The `XGameSaveDeleteContainer(p, "")` empty-name root-wipe data-loss fix was submitted separately in #95 so it can land independently.)* ## Testing - **Before (`origin/main`):** - Calling `XPACKAGE` slot 27 with `(path, 64, buf)` crashed with `0xC0000005` writing to `0x40`. - Writing `save.dat` destroyed `save.xcltmp`, and leftover `.xcltmp` files appeared in blob enumeration. - Overwriting `"Meta"` as `"meta"` caused reading `"meta"` to return `E_GS_BLOB_NOT_FOUND`. - `XGameSaveInitializeProviderResult(blk, null)` consumed the async result and returned `S_OK`. - `XPackageGetUserLocale` returned raw OS locale instead of matching `<Resources>` languages. - `XUserFindControllerForUserWithUiAsync` returned 32 zero bytes. - **After (new/updated regression tests):** - `xpackage_get_identifier_slot_27_uses_three_args` & `legacy_console_iids_map_to_their_own_slots` - `atomic_writes_preserve_xcltmp_blobs_and_skip_leftover_temps` - `case_insensitive_blob_and_container_matching_on_ntfs` - `initialize_provider_result_rejects_null_out_without_consuming_async` - `parses_declared_resources_languages_with_comments_and_utf16` & `user_locale_selection_matches_manifest_resources` - `user_device_association_and_controller_lookup` - Verified on `origin/main` (`60599a9`): `cargo build --workspace` and `cargo test --workspace -- --test-threads=4` pass with 0 failures and 0 new warnings.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:09:52 +00:00
github manually merged commit 2d946991c3 into gh-pr/97/base 2026-11-26 04:09:53 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-23 11:25 UTC · original

Merged. It conflicted with #95 in gamesave.rs (both added tests at the same place, #95 also the empty-name check in XGameSaveDeleteContainer); resolved keeping both. Merged together with #95–#102 and checked on Windows 11 with an RX 9070: cargo test --workspace green with the retail samples (shader pack, console DLLs, texture archive), lib tests also with XCL_SPLIT_WAVE64=1; XDefiant (title screen, a scripted A reaches its "Xbox network unavailable" dialog), Unicorn Overlord and Minecraft run. Thanks!

**@⁠ivall** on GitHub · 2026-11-23 11:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/97#issuecomment-7099630622) Merged. It conflicted with #95 in `gamesave.rs` (both added tests at the same place, #95 also the empty-name check in `XGameSaveDeleteContainer`); resolved keeping both. Merged together with #95–#102 and checked on Windows 11 with an RX 9070: `cargo test --workspace` green with the retail samples (shader pack, console DLLs, texture archive), lib tests also with `XCL_SPLIT_WAVE64=1`; XDefiant (title screen, a scripted A reaches its "Xbox network unavailable" dialog), Unicorn Overlord and Minecraft run. Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.