Skip to content

xgameruntime: serve XPackageImpl (IXPackageImpl3) through QueryApiImpl - #2218

Open
Dom-in wants to merge 3 commits into
ItsNotRexed:mainfrom
Dom-in:xgameruntime-package
Open

Dom-in wants to merge 3 commits into
ItsNotRexed:mainfrom
Dom-in:xgameruntime-package

Conversation

@Dom-in

@Dom-in Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Depends on #2203 → #2169 (stacked: each adds an object to QueryApiImpl's list). This PR's own change is the top commit.

What and why

libHttpClient.GDK.dll asks QueryApiImpl for XPackageImpl (af406016-…) with IXPackageImpl3's id (e2a4734b-…), through 30 thunks calling slots 3–19, 22, 24–27, 30, 32–34 and 37–40. I measured them as in #1877, disassembling the package's own DLL without running code. Every slot's argument shape matches the method at that position of xgameruntime-docs' IXPackageImpl list (slots 3–34), then IXPackageImpl2 (35–38) and IXPackageImpl3 (39–40). Some examples:

  • 10: UnregisterInstallationProgressChanged (monitor, token, bool)
  • 14: ChangeChunkInstallOrder (id, u32 count, selectors)
  • 24, 25, 26: GetMountPathSize, GetMountPath, CloseMountHandle (mount handle first)
  • 37, 38: MountWithUiAsync (id, async), MountWithUiResult (async, mount pointer)
  • 39: EnumeratePackages (kind, scope, context, callback)

The class was refused, so every XPackage call through the thunks failed, including the identifier and mount-path queries a title makes at boot.

The change

A 41-entry vtable (IUnknown + 32 + 4 + 2). The slots with an offline answer forward to the XPackage functions already on main (#1798's area), so the vtable and the named exports give the same answers:

  • 3 XPackageGetCurrentProcessPackageIdentifier, 4 XPackageIsPackagedProcess, 25 XPackageGetMountPath;
  • 11 XPackageGetUserLocale: the host user's locale name, with ERROR_INSUFFICIENT_BUFFER on a short buffer;
  • 24 XPackageGetMountPathSize: exactly the size 25 needs, terminator included;
  • 26 XPackageCloseMountHandle: nothing to release offline.

Every other slot (installation monitors, chunks, mount, enumeration, write stats, uninstall) logs its slot number once and returns E_NOTIMPL. The first boot with the executable then shows which ones the title needs, instead of a blanket "class not provided".

docs/runtime_imports.md: the XPackageImpl row lists the served slots.

Tests

xgameruntime_test (+6, 80 total):

  • the IXPackageImpl3 id;
  • slots 3 and 4 equal the named exports;
  • slot 11's locale and its short-buffer error;
  • slot 24's size fitting slot 25 exactly, while one byte less fails;
  • slots 5 and 40 return E_NOTIMPL.

ctest -R "xgameruntime|tiny_gdk|loader": 6/6, Windows 11 / MSVC.

Disclosure: written with an AI assistant (Claude Code). I reviewed it and ran the tests above.

🤖 Generated with Claude Code

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Self-check of the served slots against Microsoft's reference pages: HRESULT XPackageGetCurrentProcessPackageIdentifier(size_t, char*), bool XPackageIsPackagedProcess(), HRESULT XPackageGetUserLocale(size_t, char*), HRESULT XPackageGetMountPathSize(XPackageMountHandle, size_t*), HRESULT XPackageGetMountPath(XPackageMountHandle, size_t, char*) and void XPackageCloseMountHandle(XPackageMountHandle) all match the slot functions. Rebased on #2203's return-type fix; xgameruntime_test 82/82.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found two remaining contract gaps in the offline package object:

  1. Installation progress slot 7: the vtable uses PN(7), whose helper has the HRESULT(void*) prototype and ignores all arguments. The documented method is void XPackageGetInstallationProgress(XPackageInstallationMonitorHandle, XPackageInstallationProgress*); callers expect the output structure to be initialized. Please use the correct ABI and provide deterministic offline progress values. Microsoft reference

  2. User locale: pkg_user_locale returns GetUserDefaultLocaleName() unconditionally. XPackageGetUserLocale returns the closest locale declared by the package; if package locale information is absent, it succeeds without writing a locale. A host locale such as fr-FR can therefore be returned even when the package only declares en-US/de-DE. Please use the package's declared locale information where available, or avoid presenting an arbitrary host locale as the package locale. Microsoft reference

I reviewed this statically and did not run tests.

@ezwinxdlmao

Copy link
Copy Markdown
Contributor

Tested 34bd51f on an NVIDIA GeForce RTX 3050 Laptop GPU, driver 32.0.16.2101, Windows 11, native MSVC (VS 2022 Build Tools, Ninja, RelWithDebInfo), with llvm-mc 21.1.8 for the translated-shader tests: pass.

AI-assisted (Claude Code).

@Ingenioeren

Copy link
Copy Markdown

I tested e52ac36d and its #2169 / #2203 stack with LLVM 23.1.5 and Windows SDK 10.0.26100.0 (revision 612, with the SDK compatibility patch). The 17 selected headless tests passed.

A mapped tiny_gdk_load extension exercised QueryApiImpl → IXPackageImpl3 slots 24 and 25 with separate launcher, guest, and package directories. With LEONIDA_GAME_DIR unset and --game-dir pointing at the synthetic package, the returned mount path was the launcher directory. The existing named export falls back to that directory, and these slots use it. The environment override worked.

The attached patch reuses rt::fs::game_dir() before the launcher-directory fallback and preserves the environment override. I rebuilt and verified absolute and relative --game-dir paths, the default guest directory, the override, and the size including the terminator. A buffer one byte too short returned ERROR_INSUFFICIENT_BUFFER. All 17 headless tests still passed.

The patch adds an optional expected-root argument to the fixture. Run gta6rt --run path/to/tiny_gdk_load.exe --game-dir <synthetic-directory> -- <expected-absolute-directory> to exercise it. Synthetic inputs only. AI-assisted.

xpackage-game-dir.patch.txt

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two earlier findings remain at this head: slot 7 still uses an HRESULT(void*) thunk for XPackageGetInstallationProgress, which is a void method that writes an output structure, and XPackageGetUserLocale still returns the Windows locale instead of the package-declared locale.

Two additional ABI issues need correction:

  • Slots 8, 10, 22 and 34 are boolean methods (XPackageUpdateInstallationMonitor, the progress/package unregister methods, and XPackageUninstallPackage), but they use the generic HRESULT(void*) stub. E_NOTIMPL is nonzero in its low byte, so a caller reading the result as bool sees true, even when an operation did nothing.
  • QueryInterface accepts the class ID and IXPackageImpl3 only. It also needs to return the inherited IXPackageImpl and IXPackageImpl2 interfaces for this object; those have distinct IIDs.

Please correct the output and boolean slot signatures, support the inherited IIDs, and keep the earlier progress/locale findings in scope.

@Dom-in
Dom-in force-pushed the xgameruntime-package branch from e52ac36 to a80b585 Compare November 22, 2026 17:14
@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@Flyander thanks, all four addressed in a80b585, on the rebased #2203.

  • Slot 7: now void XPackageGetInstallationProgress(monitor, XPackageInstallationProgress*), writing an installed package (installed == total, launchable, completed).
  • Bool slots 8/10/22/34: they return false (nothing changed) / true (nothing pending) / true / false (not uninstalled), in place of the E_NOTIMPL stub.
  • Locale: the package-declared locale closest to the user's, read from MicrosoftGame.Config <Resource Language> (LEONIDA_GAME_DIR, else --game-dir), never the host locale. With none declared, it returns S_OK without writing, as documented. The test covers both cases with a synthetic config.
  • IIDs: IXPackageImpl (3720de07…) and IXPackageImpl2 (f92d8712…) are answered as well as IXPackageImpl3, and the chain is tested.

I also folded in @Ingenioeren's finding: XPackageGetMountPath now uses --game-dir (rt::fs::game_dir()) after LEONIDA_GAME_DIR and before the launcher folder, credited in the commit. xgameruntime_test 88/88; ctest -R "xgameruntime|tiny_gdk|loader" 6/6.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at a80b585. The progress output and bool slots now use their documented ABI; locale handling uses the package configuration; and the inherited package IIDs are covered. No remaining concrete issue found in this change.

@poke900310-lgtm

poke900310-lgtm commented Nov 22, 2026 •

Copy link
Copy Markdown

One thing the --game-dir fold-in introduced: when LEONIDA_GAME_DIR isn't set, XPackageGetMountPath now builds the path with rt::fs::game_dir().string() (xgameruntime.cpp:568). On MSVC's STL, path::string() throws std::system_error ("No mapping for the Unicode character exists in the target multi-byte code page") when the path has a character the ANSI code page can't represent, and gta6rt doesn't opt into a UTF-8 active code page. Under gta6rt --run, game_dir is always set, so with a game folder like C:\Users\Łukasz\Games\... on a cp1252 system the named export and slots 24/25 throw out of a shim the mapped image called. Unless the game catches it, that ends the run. On main this export never looked at the game dir (it returned LEONIDA_GAME_DIR or the launcher's own folder), so the throw is new.

Narrowing game_dir().wstring() with WideCharToMultiByte(CP_ACP, ...) (as narrow_ansi in file_system.cpp does), or failing with an HRESULT, would at least stop the throw. It won't make such a folder usable, though: a character like Ł becomes 'L' or '?' and doesn't round-trip through the CreateFileA shim. Only a UTF-8 activeCodePage in gta6rt's manifest would fix that properly.

(Edited: I corrected what main returned before, and that the CP_ACP conversion only avoids the throw.)

AI-assisted review (Claude Code), read-only; I didn't build or run it.

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main f847748. #2203 (XSystemImpl) has landed, so this PR now holds only the two XPackageImpl commits. Two changes from the rebase:

  • main reworked the named mount functions into XPackageMount plus a handle registry (content packages from LEONIDA_CONTENT_PACKAGES). Slots 23-26 now forward to those: slot 23 (XPackageMount) is served instead of E_NOTIMPL, and 24/25/26 take the one-u64 XPackageMountHandle by value. My earlier --game-dir change to the mount path is dropped, because main's mount path no longer uses the game folder.
  • The slot test now mounts a content package through slot 23, reads its path through 24/25 (exact size, short buffer refused), and checks that slot 26 closes the handle.

xgameruntime_test: OK (106 checks at this commit); ctest -R "xgameruntime|tiny_gdk": 2/2. Windows 11, MSVC Release.

AI-assisted (Claude Code).

seblessa added a commit to seblessa/Leonida that referenced this pull request Nov 22, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
seblessa added a commit to seblessa/Leonida that referenced this pull request Nov 22, 2026
Conflicts with ItsNotRexed#2218's XPackageImpl: kept both. find_object() also finds package_object(), so XGameRuntimeIsFeatureAvailable(XPackage) now follows the served XPackageImpl; the feature table reuses ItsNotRexed#2218's kPackageClass instead of a second definition. Both test blocks kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mesterember104-cpu

Copy link
Copy Markdown

Tested e52ac36 on Tiger Lake (Xe-LP) iGPU 0x9a78 (subgroup 8..32, no mesh), driver 32.0.101.7088, Windows 11, MSVC 14.44: pass

Built the stacked head as-is: base main + the #2169/#2203 commits + this PR's own top commit e52ac36 (XPackageImpl/IXPackageImpl3 through QueryApiImpl). Full ctest: 105/107 pass, 7 skipped (shader_library_corpus, bink_decode, bink_audio, vk_sync_validation, d3d12_queue_wait, d3d12_rgb9e5_rtv skip; gameinput disabled — no SDL3 wired here). The PR's own surface: ctest -R "xgameruntime|tiny_gdk|loader" is 6/6, xgameruntime_test reports OK (82 checks) including the new XPackageImpl checks: QueryApiImpl hands out XPackageImpl for IXPackageImpl3, slot 3 equals the XPackageGetCurrentProcessPackageIdentifier export, slot 4 = XPackageIsPackagedProcess, slot 11 gives the host locale and refuses a 1-byte buffer, slots 24/25 mount-path size pair, slots 5/40 E_NOTIMPL.

The 2 failing tests are pre-existing Intel-main failures this PR does not touch (its files are runtime/shims/xgameruntime.cpp, runtime/test/xgameruntime_test.cpp, runtime/test/fixtures/tiny_gdk_load.cpp, docs/runtime_imports.md): d3d12_buffer_tiles (assert line 177, tile words != expected) and d3d12_descriptor (2D LOD view 1/2 and array LOD 1.75 read 64/64 mismatched texels — the known Intel LOD/minLOD mismatch class on this driver).

AI-assisted (GLM, operated by the account owner).

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@poke900310-lgtm thanks, you were right about e52ac36d: game_dir().string() would throw out of the shim for a game folder outside the ANSI code page. That code is gone since the rebase onto main f847748 (head e3662721). main reworked the mount functions into XPackageMount plus a handle registry, which never looks at the game folder, and slots 23-26 now forward to those. git grep '\.string()' in xgameruntime.cpp on this branch finds nothing. The remaining game-folder read, MicrosoftGame.Config for the locale, opens the std::filesystem::path directly (wide on MSVC) with no narrowing, so a folder like C:\Users\Łukasz\... works there.

AI-assisted (Claude Code).

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up from checking my own reply: the --game-dir route was wide already, but LEONIDA_GAME_DIR was read with GetEnvironmentVariableA, which narrows a folder named outside the ANSI code page. f74b8eb reads it with GetEnvironmentVariableW and opens the config wide. The new check uses a folder named with U+16A0 (a runic letter no ANSI code page has). With the fix, xgameruntime_test is OK (107 checks). With the old narrow read, FAIL slot 11 reads MicrosoftGame.Config from a game folder named outside the ANSI code page. (A Polish Ł didn't catch it on this machine, since its code page is cp1250.) #3408 is rebased on top: 116 checks.

AI-assisted (Claude Code).

Dom-in and others added 3 commits November 22, 2026 22:32
libHttpClient.GDK.dll asks QueryApiImpl for XPackageImpl with IXPackageImpl3's
id through 30 thunks (slots 3-19, 22, 24-27, 30, 32-34, 37-40), each in
the argument shape of the method at that position of xgameruntime-docs'
IXPackageImpl (3-34), IXPackageImpl2 (35-38) and IXPackageImpl3 (39-40)
lists, e.g. 10 (monitor, token, bool), 14 (id, count, selectors), 24-26
the mount path trio, 39 (kind, scope, context, callback).

Slots with an offline answer forward to the XPackage functions already
on main, so the vtable and the named exports agree: 3 the package
identifier, 4 packaged process, 25 the mount path; plus 11 the host user's
locale, 24 the mount path size (exactly what 25 needs) and 26 closing a
mount (nothing to release). Every other slot logs its number once and
returns E_NOTIMPL, so the first boot lists what the title needs.

xgameruntime_test +6 (80): the IXPackageImpl3 id, 3 and 4 equal the
exports, the locale and its short-buffer error, 24/25 sizes, 5/40 stubs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, IIDs, --game-dir)

Review (@Flyander):
- slot 7 is void XPackageGetInstallationProgress(monitor,
  XPackageInstallationProgress*): it now writes an installed, launchable,
  completed package instead of an HRESULT stub ignoring its output.
- slots 8, 10, 22, 34 are bool methods (UpdateInstallationMonitor, the two
  Unregister* calls, UninstallPackage); E_NOTIMPL read as true. They return
  false / true / true / false, as documented for nothing to do offline.
- XPackageGetUserLocale returns the package-declared locale closest to the
  user's (MicrosoftGame.Config <Resource Language>, from LEONIDA_GAME_DIR or
  --game-dir), never the host locale; with none declared it succeeds
  without writing, as Microsoft documents.
- QueryInterface answers IXPackageImpl and IXPackageImpl2 too (the IDL
  chain IXPackageImpl3 : IXPackageImpl2 : IXPackageImpl).
And @Ingenioeren's finding: XPackageGetMountPath uses gta6rt's --game-dir
(rt::fs::game_dir()) after LEONIDA_GAME_DIR, before the launcher folder.

xgameruntime_test links file_system.cpp; +6 checks (88).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GetEnvironmentVariableA narrowed a game folder named outside the ANSI code page
(e.g. a runic or CJK character on cp1252), so the package locale lookup missed
its MicrosoftGame.Config. Read the variable and open the file wide. The test
uses U+16A0, which no ANSI code page has (it fails with the narrow read).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Vonsek

Vonsek commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 895f76f on Windows 11 (MSVC RelWithDebInfo): full runtime build, then ctest for the shim/loader tests (loader, pe_loader, loader_tls, dll_thread_calls, unimplemented_policy, startup_trace, xmem, process_cmdline, file_system, winhttp_offline, xgameruntime, run_tiny_*, allocator_proxy) — 27 of 27 passed. AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants