Skip to content

xgameruntime: serve XGameUiImpl (offline system dialogs) through QueryApiImpl - #3657

Closed
romainveurrier wants to merge 1 commit into
ItsNotRexed:mainfrom
romainveurrier:rt/xgameuiimpl
Closed

romainveurrier wants to merge 1 commit into
ItsNotRexed:mainfrom
romainveurrier:rt/xgameuiimpl

Conversation

@romainveurrier

Copy link
Copy Markdown
Contributor

Item: new RT item, claimed in #3574 (claim).

Why

A GDK title links the XGameUi* functions statically (xgameruntime.lib). Each thunk asks QueryApiImpl for XGameUiImpl and calls one slot with the function's own arguments after this, the mechanism docs/runtime_imports.md measures on the package's DLLs. QueryApiImpl refused the class, so a title that reports a problem through a system dialog (a corrupt save, a lost connection, a confirmation) got "class not provided" instead of an answer.

What

runtime/shims/xgameruntime_ui.cpp, in its own file, hooked into QueryApiImpl with one line, like #3363 (XUserImpl) and #3550 (XStoreImpl). The three PRs touch adjacent lines there, so the later ones need a one-line rebase.

  • Sources: class and interface ids and the slot order come from xgameruntime-docs (facts only). Signatures and enum values come from Microsoft's public GDK reference (the XGameUi pages), each checked on its page. No GDK header or library code is used.
  • Interfaces: unlike XUserImpl and XStoreImpl, the class id isn't IXGameUiImpl's id. The class id (which the thunks pass as the interface id too) and IXGameUiImpl–4 all answer with the same 51-slot vtable (3 + 27 + 10 + 2 + 9).
  • Dialogs are answered at once, the way a player would answer without reading, and what the player would have seen goes to the log:
    • Message dialog: title, content and buttons are printed, and it's answered with its default button. A default naming a button without text falls back to the first; no first button is E_INVALIDARG.
    • Error dialog: the HRESULT and context are printed, and it's closed.
    • Text entry: answered with the title's default text, as if OK were pressed without typing, cut to maxTextLength. The reference documents no cancellation code, so none is invented.
    • Profile card, achievements, game invite, multiplayer activity invite, state share: shown and closed (S_OK).
    • Notification position hint: the six documented positions are accepted, anything else is E_INVALIDARG.
  • Not available offline: the player picker and web authentication need the network (a friends list, a sign-in page). They fail before starting with HRESULT_FROM_WIN32(ERROR_NETWORK_UNREACHABLE), so no XAsyncBlock is left waiting.
  • E_NOTIMPL: the docs' unknown slots, the in-game text-entry handles (IXGameUiImpl2) and the custom-UI callbacks (IXGameUiImpl4), so a title falls back to the system dialogs above. Every documented function here returns an HRESULT, so E_NOTIMPL reads as a failure (no bool slot to misread). Each logs once.

Nothing here touches licensing or online services.

Not measured yet: no package DLL calls an XGameUi* slot, so the slot order rests on xgameruntime-docs until the executable's first boot. docs/runtime_imports.md says so.

Tests

xgameruntime_ui_test (26 checks) gets the class through rt::shims::find("xgameruntime.dll", "QueryApiImpl") and calls the served slots with the documented arguments.

  • Ids: every interface id is parsed from its text as xgameruntime-docs prints it, so mistyped GUID bytes would fail.
  • Message dialogs: one, two and three buttons, a default naming a missing button, no first button.
  • Text entry: result size with the terminator, the default text, cutting to maxTextLength, no default text, and a buffer too short (on its own call, since xtaskqueue releases a call whose result buffer is too small).
  • Other calls: the error dialog, the five shown-and-closed dialogs, the notification position hint, the two network-only dialogs, and the E_NOTIMPL slots.

Tested

Fedora 44, clang-cl 22.1.8 with xwin (SDK 10.0.26100), /W4: no warnings in the new files.

  • Under Wine 11.21: xgameruntime and xgameruntime_ui pass.
  • Full suite: 139/141. device_proxy also fails on main; winhttp_offline is intermittent (HANDLE_CLOSING timing) and builds only winhttp_offline.cpp + registry.cpp.
  • scripts/build_runtime.ps1's source list includes the new file. Not run: MSVC, native Windows.

No game files. AI-assisted (Claude Code).

🤖 Generated with Claude Code

…yApiImpl

A GDK title links the XGameUi* functions statically (xgameruntime.lib);
each thunk asks QueryApiImpl for XGameUiImpl and calls one slot.
QueryApiImpl refused the class, so a title reporting a problem through a
system dialog (XGameUiShowMessageDialogAsync, XGameUiShowErrorDialogAsync)
got "class not provided" instead of an answer.

runtime/shims/xgameruntime_ui.cpp serves it, in its own file, hooked into
QueryApiImpl with one line:

- ids and slot order from xgameruntime-docs (facts only), signatures and
  enums from the public GDK reference; the class id (not IXGameUiImpl's)
  and IXGameUiImpl..4 answer with one 51-slot vtable;
- message dialogs are printed to the log and answered with their default
  button; error dialogs are printed and closed; text entry is answered
  with the title's default text (cut to maxTextLength);
- profile card, achievements, invites and state share are shown and
  closed at once; player picker and web authentication need the network
  and fail before starting;
- unknown slots, in-game text-entry handles and custom-UI callbacks
  answer E_NOTIMPL (every documented function returns an HRESULT) and
  log once.

xgameruntime_ui_test (26 checks) drives the served slots.

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

Copy link
Copy Markdown

Code review of a80f07c (AI-assisted), with probe calls added to xgameruntime_ui_test in a private copy, built with MSVC on Windows 11 23H2. Nothing was pushed. The PR's 26 checks and xgameruntime_test (94 checks) pass.

  1. Cancelling a dialog never gives E_ABORT; it completes with the default button (proved). None of the three providers (xgameruntime_ui.cpp ~L60–64, ~L76–91, ~L96–114) handles XAsyncOp::Cancel. The vendored XAsyncCancel (third_party/xtaskqueue/Source/Task/AsyncLib.cpp ~L794) only forwards Cancel to the provider and doesn't complete the call itself.
    • Message dialog ("Delete"/"Keep", default First, cancel Second) on a manual queue, then XAsyncCancel, then dispatch:
      final status=0x00000000 (E_ABORT=0x80004004) Result hr=0x00000000 button=0
      
      Text entry behaves the same way (text cancel: status=0x00000000).
    • So a title that cancels a pending dialog (e.g. on suspend) gets success and "Delete". It cancels before DoWork even runs.
    • Fix: on Cancel, XAsyncComplete(async, E_ABORT, 0).
    • Related (~L129): the offline answer is defaultButton. Answering cancelButton instead, the B-button choice and usually the non-destructive one, would be safer. Today a boot-time "delete corrupt save? [Delete*] [Keep]" deletes the save.
  2. Text entry: maxTextLength == 0 returns an empty string (proved). answer->resize(max_length) (~L177) truncates to 0, while the GDK page for XGameUiShowTextEntryAsync says 0 means a 1024-character maximum: maxTextLength=0 default "Player": size=1 text="".
  3. Text entry: the Password scope is still truncated (proved). The same page says maxTextLength is ignored for that scope (always 1024): Password scope max=4 default "hunter22": text="hunt". Also (~L178), the password default is logged in clear to stderr.
  4. Text entry: truncation counts bytes, not characters, and splits UTF-8 (proved). maxTextLength is a number of characters in the GDK, and std::string::resize counts bytes: max=3 default "Zoë" (3 chars, 4 bytes): bytes=5a 6f c3 valid_utf8=0. The title gets invalid UTF-8 instead of "Zoë".
  5. Minor:
    • An empty-string button isn't treated as absent (~L130): with second="" and default Second, it answers button 1, a button the player would never have seen (proved).
    • firstButtonText is _In_opt_ in the GDK, but a null first button returns E_INVALIDARG (~L127) (reasoned).

Checked and found correct:

  • All 51 slots and the class/interface GUIDs, against xgameruntime-docs (IXGameUiImpl..4); the notification-hint enum 0–5.
  • Completion is never synchronous (proved): 0x8000000a pending after the Async call returns, no callback after dispatching only the work port, and the callback runs on the title's thread once the completion port is dispatched.
  • ResultSize includes the terminator; an empty default gives size 1; a too-small buffer gives 0x8007007a.
  • Text-entry context freed exactly once on the XAsyncBegin and scheduling failure paths.
  • Network-only dialogs (player picker, web authentication) fail before starting, so no XAsyncBlock is left waiting.
  • No MessageBox, console prompt or window: nothing can block a headless or CI run.

Not checked: the E_NOTIMPL "unknown" slots (20–23, 28–29, 32–33) can't be checked without their signatures. If one isn't HRESULT-returning, a caller could misread E_NOTIMPL.

@sh1shu1

sh1shu1 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested a80f07c on NVIDIA RTX 4070 SUPER (driver 616.92), Windows 11 26200, MSVC 14.44, Vulkan SDK 1.4.363, RelWithDebInfo: pass, no regression against main f847748.

  • ctest: 141/141 passed, same 8 skips as main f847748
  • xgameruntime_ui: 1/1
  • run_gpu_tests (LEONIDA_VK_VALIDATION=1): 153/199 native, 184/199 with LEONIDA_W64_EMULATE=1, 0 failed; identical to main f847748
    AI-assisted (Claude Code, Claude Fable 5.1).

@FaKL-Code

Copy link
Copy Markdown
Contributor

Tested a80f07c (merged onto main f847748) on NVIDIA GeForce RTX 4060 Ti, driver 610.88 (32.0.16.1088), Windows 11 26200, MSVC 14.51.36231 (VS 2026), Vulkan SDK 1.4.363.0: pass

  • Merges cleanly; no new compiler warnings against main.
  • ctest: 132 of 132 pass (main's 131 plus the new xgameruntime_ui; same 8 skips as main). Loader test passes; validation run: 52 tests clean (2 skipped, as on main).
  • xgameruntime_ui -V: "0 of 26 checks failed". That covers the player picker and web authentication failing before they start, and the E_NOTIMPL slots (slot 20, IXGameUiImpl2 text entry, IXGameUiImpl4 callbacks).
  • As the body says, it overlaps xgameruntime: serve XStoreImpl (offline store) through QueryApiImpl #3550: git merge-tree against xgameruntime: serve XStoreImpl (offline store) through QueryApiImpl #3550's current head reports conflicts in docs/runtime_imports.md, runtime/CMakeLists.txt, runtime/shims/xgameruntime.cpp and scripts/build_runtime.ps1, so it's more than the one QueryApiImpl line. Each looks like two additions in the same place.
  • Main has moved since (aa2988c): this branch now also conflicts with it in runtime/CMakeLists.txt.

AI-assisted (Claude).

@romainveurrier

Copy link
Copy Markdown
Contributor Author

Closing: superseded by main's XGameUiImpl in runtime/shims/xgameruntime_offline.cpp (ec34b54). It answers dialogs the same way: logged, then the default button. Thanks @sh1shu1 and @FaKL-Code for testing a80f07c on Windows. The one behaviour #3657 had that main doesn't: XGameUiShowTextEntryAsync answered with the title's default text, as if OK were pressed, instead of failing. I'm claiming that as a small follow-up in the coordination issue. 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.

4 participants