Skip to content

hle, app, docs: implement XGameUi message and error dialogs - #26

Merged
simnJS merged 4 commits into
MiamiGame:mainfrom
PrivacyOnion:hle/xgameui-dialogs
Nov 25, 2026
Merged

simnJS merged 4 commits into
MiamiGame:mainfrom
PrivacyOnion:hle/xgameui-dialogs

Conversation

@PrivacyOnion

@PrivacyOnion PrivacyOnion commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Implement XGameUiShowMessageDialogAsync/Result (slots 0x18/0x20) and XGameUiShowErrorDialogAsync/Result (slots 0x70/0x78) in crates/xtp-hle/src/modules/xgameui.rs:

  • Message dialogs run on a worker thread via xasync::pending_with, show an in-memory Win32 modal dialog (DialogBoxIndirectParamW) with up to three buttons, preserve each visible button's original XGameUiMessageDialogButton enum value (0, 1, 2) across null/empty label gaps, focus default_button in WM_INITDIALOG, escape & mnemonics, and return the chosen button (S_OK). Pressing Esc or closing the window completes with S_OK and cancel_button; E_ABORT is returned only when no window can be opened (or on XAsyncCancel).
  • Error dialogs run on a worker thread via xasync::pending_with, log the HRESULT and context, show a modal MessageBoxW error dialog, and complete with S_OK when dismissed or E_ABORT when no window can be opened.
  • Unattended / CI / autopilot runs: setting XTP_DIALOGS=auto (or xgameui::set_auto_dismiss(true), enabled automatically under --autopilot in apps/xtp/src/run.rs) logs a warning and completes message dialogs immediately with S_OK + cancel_button and error dialogs with S_OK, without opening a window (text entry is unaffected).

Size note: +699/−25 changed lines across 4 files (including ~250 lines of unit tests, the in-memory Win32 dialog template/procedure, XTP_DIALOGS=auto + --autopilot wiring, and docs).

Fixes: #8
Depends on: none

Area

  • crates/xtp-hle/src/modules/xgameui.rs
  • apps/xtp/src/run.rs (enable xgameui::set_auto_dismiss(true) under --autopilot)
  • README.md (update "Runtime services" row and document XTP_DIALOGS=auto)
  • docs/analysis/hle.md (mark R5 done)

Tests

  • cargo xtask pr-check passes on my machine
  • New or changed behaviour has tests that need no game files, or I explain below why it cannot
  • Ran on the title: no

Unit tests in crates/xtp-hle/src/modules/xgameui.rs (asserting only on the test thread, with worker hooks recording requests into a Mutex):

  • message_dialog_buttons_gaps_default_cancel_and_auto_dismiss: verifies button 2 (BUTTON_SECOND), button 3 (BUTTON_THIRD) across a null-second-button gap, default_button and cancel_button propagation, Esc -> cancel_button (S_OK), null result_button returning E_INVALIDARG, unattended auto-dismiss returning cancel_button (S_OK), headless/no-window returning E_ABORT, and & mnemonic escaping.
  • error_dialog_completes_auto_dismisses_or_cancels_without_window: verifies normal dismissal (S_OK), auto-dismiss (S_OK), and no-window (E_ABORT).
  • message_proc_helpers_map_focus_esc_and_gapped_buttons: directly tests focus_button_id (default button and fallback) and command_to_button (Esc -> cancel_button, visible gapped button, absent button ignored).

Provenance

  • I wrote all of this change myself for XTP, or it only moves code already in XTP.
  • Some of it comes from elsewhere. Each source, its licence and the files concerned are listed here, and every licence is compatible with GPL-3.0-or-later:

Written from scratch for XTP following the existing dialog::ask in-memory Win32 dialog pattern in xgameui.rs and public Microsoft Learn documentation for XGameUI.h. Neither I nor the AI assistant read xcl's api.rs.

AI assistance: Antigravity assisted with implementation, review fixes, and unit tests; all changes were reviewed and verified locally.

Checklist

  • No game data, keys, console SDK code or headers, and nothing that circumvents DRM (asset policy)
  • No code copied from xcl or AnyPS5 (references only: read them to understand, write your own)
  • I agree to license this contribution under GPL-3.0-or-later
  • Title and every commit follow <area>: <summary>; one topic; under 400 changed lines, or the reason is above
  • Docs updated where behaviour, commands or variables changed (README, docs/)

@github-actions github-actions Bot added overlap another open PR changes the same files area/hle touches crates/xtp-hle area/docs docs/, Markdown size/L 400 to 999 changed lines labels Nov 24, 2026

@simnJS simnJS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for picking up #8. The ABI matches the public XGameUI.h docs and the slot table, the in-memory template is correctly aligned, and keeping the real dialogs out of test builds is the right approach. A few things need to change before this can land:

  1. cancelButton (blocking). The docs define cancelButton as "the button that represents the cancel action", and resultButton as the button the user selected. Esc and the close box should complete with S_OK and report cancel_button. Keep E_ABORT for "could not show the dialog" (and for XAsyncCancel). Right now cancel_button is only logged (L63/L81) and is missing from MessageDialogRequest, and Esc/close give E_ABORT (L406–410, L418–421).

  2. Button indices (blocking). Dropping null or empty labels (L68–72) changes the index you report: with first = null, second = "OK", clicking OK returns First. Please keep each visible button's enum value with its label, use BTN_BASE + value as the control id, and compare default_button and cancel_button against those values.

  3. Default button. Returning 1 from WM_INITDIALOG (L398–401) puts the focus on the first tab stop, so button 0 becomes the effective default and Enter picks it. Please SetFocus the default button and return 0, as dialog::ask does.

  4. Unattended runs (blocking for us). XTP runs unattended sessions (--autopilot, cloud runs), and nothing there can answer a Win32 modal dialog, so a title that waits on the error dialog would stall. Until now these slots returned E_NOTIMPL at once. Please add a switch that answers without opening a window and logs a warning:

    • the message dialog completes with cancel_button (S_OK);
    • the error dialog completes with S_OK at once.

    For example, an XTP_DIALOGS=auto variable (the name is open to discussion), documented in the README. Please also turn it on in autopilot runs; if you prefer, we can file the autopilot wiring and text entry as a follow-up, but the switch should exist when these dialogs land.

  5. Tests. The assert_eq! calls inside the hooks (L680–681, L735–736) run on the xasync worker thread. If one fails, that thread panics, the call never completes, and XAsyncGetStatus(.., true) hangs the CI job instead of failing it. Have the hook only record the request and return the answer, then assert on the test thread after completion. Please also cover:

    • the third button;
    • Esc mapping to cancel_button;
    • labels with a gap (a null second button);
    • the default button.

Smaller points:

  • add SS_NOPREFIX to the content label, and consider & in button captions;
  • the 40-unit content label clips long text;
  • return E_INVALIDARG reads better than put(null, 0) at L112;
  • please mark R5 in docs/analysis/hle.md:176.

Thanks for disclosing the AI help, and for the honest "untested live" in the README. We found a separate cancel issue in xasync::pending_with on main while reviewing this; we'll fix that on our side, so you don't need to.

@PrivacyOnion PrivacyOnion changed the title hle, docs: implement XGameUi message and error dialogs hle, app, docs: implement XGameUi message and error dialogs Nov 24, 2026
@PrivacyOnion

Copy link
Copy Markdown
Contributor Author

Addressed all review items:

  1. cancel_button: Esc (IDCANCEL) and the close box (WM_CLOSE) now complete with S_OK and report cancel_button; E_ABORT is kept for when a dialog cannot open.
  2. Button indices: MessageDialogRequest::buttons preserves each visible button's original XGameUiMessageDialogButton enum value (0 | 1 | 2) alongside its label, using BTN_BASE + value as the control ID so gaps (e.g. null second button) never shift the reported index.
  3. Default button focus: WM_INITDIALOG calls SetFocus on the default button control (falling back to the first visible button) and returns 0.
  4. Unattended runs: added XTP_DIALOGS=auto (documented in README.md) and xgameui::set_auto_dismiss(true) wired into --autopilot in apps/xtp/src/run.rs so message dialogs complete immediately with cancel_button (S_OK) and error dialogs complete with S_OK without opening a window.
  5. Tests: moved all assertions off the xasync worker thread (hooks only record the request into a Mutex and return the answer) and added coverage for the third button, a null-second-button gap, default_button, Esc -> cancel_button, and unattended auto-dismiss.
  6. Smaller points: added SS_NOPREFIX to the content label, escaped & to && in button captions, enlarged the dialog/content area (280×104, 66-unit content height), returned E_INVALIDARG on null result_button, and marked R5 done in docs/analysis/hle.md.

@github-actions github-actions Bot added the area/app apps/ label Nov 24, 2026

@simnJS simnJS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, this addresses all the blocking points:

  • cancel_button with S_OK on Esc and the close box;
  • button values kept across gaps;
  • focus on the default button;
  • XTP_DIALOGS=auto, wired into --autopilot.

The tests now assert only on the test thread.

Before merge:

  1. Please update the branch onto current main. CI ran against c38f95c, which predates the xasync cancel fix (4100a24) and #23/#25, so we need a green run on main.
  2. Please refresh the PR description. It still says dismissing gives E_ABORT and quotes 451 lines (it is now +635/−23, about 211 of them tests), and the Area list is missing apps/xtp/src/run.rs and docs/analysis/hle.md.

Small things, here or as a follow-up:

  • The module doc (L2-5) now implies that text entry only aborts when it can't open, but Cancel/Esc still returns E_ABORT.
  • Long content is still clipped at 66 DLU; a read-only multiline edit with a scroll bar would do.
  • Mark R5 "(done)" in its section heading and in the order table too, as was done for R7.
  • The Esc and default-button tests go through the fake, so message_proc's mapping is untested; small pure helpers would make it testable.

As a follow-up: text entry still opens a window under XTP_DIALOGS=auto and --autopilot, so either cover it or reword the doc at L37.

@fogydes fogydes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Independent maintainer review of head c309096f (base c38f95ca0), full diff read, CI state checked, xasync API compared against current main (df510eee4). This PR is the only eligible open PR right now; #28 is owned by a separate reviewer.

What I verified as correct (static, from the diff)

  • Slots and ABI. 0x18/0x20 = message dialog async/result, 0x70/0x78 = error dialog async/result, matching the existing vtable comments. XGameUiShowMessageDialogAsync takes the three button labels plus default_button/cancel_button as u32 (the GDK enum is 4 bytes); the result is written as a 4-byte XGameUiMessageDialogButton. message_dialog_result rejects a null out-pointer with E_INVALIDARG and otherwise follows the exact XAsyncGetResult pattern of the existing text_entry_result; error_dialog_result mirrors profile_card_result (0/null/null). No ABI issues found.
  • Cancel semantics. Esc (IDCANCEL) and the close box (WM_CLOSE) now complete with S_OK and report cancel_button; E_ABORT is reserved for "could not open a window" — matches the public XGameUI.h docs. The unit test pins Esc → cancel_button.
  • Button indices. MessageDialogRequest::buttons keeps each visible button's original enum value next to its label and uses BTN_BASE + value as the control id, so a null/empty label never shifts the reported index; message_proc maps the control id back and only accepts ids in button_ids. The gap case (null second button → third still reports BUTTON_THIRD) is tested.
  • Default focus. WM_INITDIALOG calls SetFocus on the default button (falling back to the first visible) and returns 0, same as the existing dialog::ask.
  • Unattended runs. XTP_DIALOGS=auto (documented in the README variable table) plus xgameui::set_auto_dismiss(true) wired into --autopilot in apps/xtp/src/run.rs: message dialogs complete immediately with S_OK + cancel_button, error dialogs with S_OK, both with a warn! log and no window. This closes the stall risk for autopilot/cloud runs.
  • Template construction. The in-memory DLGTEMPLATE/DLGITEMTEMPLATE layout (DWORD alignment before each item, 0xFFFF class atoms, creation-count 0, SS_NOPREFIX on the content label, && escaping in button captions) follows the existing dialog::ask pattern and is consistent.
  • Tests. Hooks are #[cfg(test)]-only, the real dialogs #[cfg(not(test))]; tests serialize on TEST_LOCK and only record (not assert) on the worker thread. Coverage includes button gaps, default/cancel, auto-dismiss, and the no-window E_ABORT path. No game files needed; synthetic only.
  • Policy/provenance. Win32 host APIs only, no game data, no console SDK material, no xcl/AnyPS5 code; AI assistance disclosed. New windows-sys usage is inside existing features already enabled for the crate.

Still blocking at this head (concurs with the code owner's CHANGES_REQUESTED)

  1. Rebase onto current main. Base c38f95ca0 predates the xasync cancel fix (4100a24: a cancelled pending_with worker no longer touches a reused block) and the #23/#25 merges. I compared xasync.rs at c38f95ca0 vs main: the public API this PR uses (pending_with, finished, XAsyncGetResult, XAsyncGetStatus, AsyncBlock) is signature-identical, so I expect no code change — but the green run 45472476499 tested c309096f against the then-main, not today's df510eee4. The cancel fix is directly relevant to this PR's dialog workers, so a green CI run on the rebased merge is required evidence, not a formality. (mergeable is currently true.)
  2. PR description is stale at c309096f. It still says dismissing a message dialog completes with E_ABORT (now S_OK + cancel_button), still quotes "451 changed lines" (actual: +635/−23), and the Area list is missing apps/xtp/src/run.rs and docs/analysis/hle.md.

Minor, non-blocking

  • docs/analysis/hle.md: only the comparison-table row is marked "Done (R5)"; the ### R5. section heading and the order-table row still read as open — please mark those too, as was done for R7 in #23.
  • The module doc still implies text entry only aborts when it cannot open; Esc/Cancel on text entry still returns E_ABORT (or reword).
  • message_proc's id→button mapping is only exercised through the fake; small pure helpers would make it directly testable. Long content is still clipped at 66 DLU.

CI state

All required checks pass on head c309096f (run 45472476499: fmt, clippy, clippy-diagnostics, test, policy, conventions, actionlint, conflicts, labels, overlap; welcome skipped as a returning contributor). Note this run predates main moving to df510eee4 — see blocker 1. Green CI here is static/build evidence only; it says nothing about runtime dialog behavior.

Remaining runtime verification

The description says "Ran on the title: no". Still to verify on a real host: an actual message dialog render/click-through, Esc and close-box paths in the real message_proc, and XTP_DIALOGS=auto under --autopilot in a real unattended session. None of this is covered by the unit tests, which use hooks.

@github-actions github-actions Bot added the conflict conflicts with its base branch label Nov 24, 2026
@github-actions

Copy link
Copy Markdown

This pull request now conflicts with its base branch. Please rebase it on main (or merge main into it) and resolve the conflicts; the conflict label goes away by itself once it merges cleanly.

@github-actions github-actions Bot removed the overlap another open PR changes the same files label Nov 24, 2026

@fogydes fogydes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Independent review follow-up (head unchanged at c309096f4; my full review of this head is #pullrequestreview-6047220994). Since then main moved to 8d503f912 and this PR now reports CONFLICTING/DIRTY, so the rebase blocker from that review is now concrete: please rebase onto current main (which includes the 4100a24 xasync cancel fix your dialog workers rely on) and get a fresh green CI run on the rebased head before this can merge. The stale-description point also still stands (dismiss is now S_OK + cancel_button, not E_ABORT; area list is missing apps/xtp/src/run.rs and docs/analysis/hle.md). No new code findings at this head.

@github-actions github-actions Bot removed the conflict conflicts with its base branch label Nov 25, 2026
@PrivacyOnion

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto current main (448bb93, including the 4100a24 xasync cancel fix) and refreshed the PR description (accurate behavior, +699/-25 line count, and complete Area list).

Also addressed the minor follow-ups:

  • Clarified module and DIALOGS_ENV docs regarding text entry (E_ABORT on Cancel/Esc, unaffected by XTP_DIALOGS=auto).
  • Marked R5 (done) in its section heading and order table in docs/analysis/hle.md.
  • Extracted focus_button_id and command_to_button pure helpers used by message_proc and added a unit test covering default focus fallback, Esc -> cancel_button, and gapped button IDs.

@simnJS

simnJS commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Thanks, this addresses everything from both rounds: Esc and the close box report cancel_button with S_OK, button values survive gaps, focus goes to the default button, XTP_DIALOGS=auto is documented and switched on under --autopilot, the tests assert only on the test thread, and the new focus_button_id / command_to_button helpers put the dialog procedure's mapping under test. The branch is rebased onto 448bb93; main's later commits touch only xtp-gpu/src/host.rs, so nothing conflicts. The description and the R5 markers are accurate now, and test is green on the rebased head.

We'll approve once gpu-debug-layer finishes: it is currently stalling on main as well, unrelated to this change, and we're looking into it.

Follow-ups, not blocking:

  • long content is still clipped at 66 DLU (a read-only multiline edit with a scroll bar would fix it);
  • in auto mode, finished_with would complete the message dialog without starting a thread;
  • a live check (click, Esc, close box, autopilot) would still be welcome, since the unit tests run against the fake.

@simnJS simnJS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the rebase and the follow-ups. Everything from the last round is addressed: the branch is now on a main that includes the xasync cancel fix, the description matches the code, the module doc and README say text entry is not auto-dismissed, R5 is marked done in its heading and in the order table, and focus_button_id/command_to_button let the tests cover message_proc's mapping directly.

I compared the new head with c309096: apart from the rebase, the only changes are the extracted helpers, their test and the doc fixes, so the earlier checks still hold.

CI: the required checks pass. gpu-debug-layer was cancelled at its 60-minute limit while stuck in an xtp-gpu test (descriptor::host::tests::a_translated_program_reads_and_writes_through_the_heaps_table). That job only runs the xtp-gpu tests, which don't depend on xtp-hle, so this PR didn't cause it. I'm updating the branch from main for a clean run and will merge once it is green.

A follow-up, not blocking: long content is still clipped at 66 DLU (xgameui.rs ~L436). A read-only multiline edit with a vertical scroll bar would show all of it.

Approving. Thanks for the careful iterations.

@github-actions github-actions Bot added the overlap another open PR changes the same files label Nov 25, 2026
@github-actions

Copy link
Copy Markdown

Other open pull requests change the same files. Check that they do not do the same work, and agree with their authors on which lands first: the other one will then need a rebase.

Pull request Files changed by both
#47 apps/xtp/src/run.rs, docs/analysis/hle.md
#48 README.md

This comment is kept up to date automatically and removed when the overlap ends.

@simnJS
simnJS merged commit bc24294 into MiamiGame:main Nov 25, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/app apps/ area/docs docs/, Markdown area/hle touches crates/xtp-hle overlap another open PR changes the same files size/L 400 to 999 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Message and error dialogs (XGameUi) as host task dialogs

3 participants