Skip to content

xgameruntime: answer the registry key a title's own XSystemGetDeviceType reads, so it is not told "PC" - #3775

Open
kotorvr wants to merge 1 commit into
ItsNotRexed:mainfrom
kotorvr:claude/console-mode-registry
Open

kotorvr wants to merge 1 commit into
ItsNotRexed:mainfrom
kotorvr:claude/console-mode-registry

Conversation

@kotorvr

@kotorvr kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claim (new RT item, no ID assigned yet)

AI-assisted (Claude Code). I ran everything under "Tested" on Windows.

Problem

runtime/shims/xgameruntime.cpp exports XSystemGetDeviceType (Series X, or LEONIDA_DEVICE_TYPE). A title never calls that export. xgameruntime.lib links the function into the title, and that copy asks the registry:

  1. it opens HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\OEM;
  2. it reads the DWORD value ConsoleMode and closes the key;
  3. it turns the value into an XSystemDeviceType. If the key or the value is missing, its answer is PC.

The package's own XCurl.dll and libHttpClient.GDK.dll both carry that function (read statically; nothing was run). The first imports RegOpenKeyW, RegQueryValueExW and RegCloseKey from api-ms-win-core-registry-l1-1-0.dll and -l2-1-0.dll, the second from advapi32.dll.

No shim served those calls, so they went to the host, where that key does not exist. The title's function therefore answered PC, whatever the shim's export or LEONIDA_DEVICE_TYPE said. The new test prints what the sequence returns against the host's registry before it runs: 1 (PC) on this machine.

Other layers: sammwyy/xvalkyrie (GPL-3.0) describes the same read in docs/research/gdk-titles.md and reports a retail title that indexes a jump table with the result and crashes on the PC value. ivall/xcl (crates/xcl/src/hle/kernelx.rs, GPL-2.0-only) and omonkeyz/xbox-emulator (crates/compat/compat-common/src/gdk/hook.rs, GPL-3.0) answer the same key; those two share lineage, so together they are one reading, and xvalkyrie is a separate code base. Facts only, and the code is my own. I read xcl's source (GPL-2.0-only) while working on this, so please check the provenance.

Change

  • xgameruntime.cpp serves RegOpenKeyW, RegOpenKeyExW, RegQueryValueExW and RegCloseKey under the three DLL names above. For that one key (any case, separators around it tolerated) they answer a pseudo-key whose only value is the DWORD ConsoleMode, set from the device type the export reports. Every other key, root and handle goes to the host's function unchanged.
  • LEONIDA_DEVICE_TYPE now reaches the title: 2..8 pick the matching ConsoleMode; 1 (PC) leaves the key to the host, which is how a PC answers (on a machine that really has that key, the title then reads the host's value); 0 answers a value the title does not know.
  • registry.cpp: advapi32.dll joins the host modules of which only a few functions are replaced, so a title's LoadLibrary("advapi32.dll") still gets the host module and not a pseudo-handle. That list feeds owns_dll for every caller; nothing registered advapi32.dll names before, and the full ctest run below shows nothing relied on the old answer.
  • docs/runtime_imports.md: a section describing the read. docs/related_projects.md: an entry for xvalkyrie.

Not done: RegGetValueW, the ANSI forms, and the enumeration and subkey functions (RegEnumValueW, an open with the pseudo-key as its root) are not served, because neither DLL imports them for this read. Given the pseudo-key, the host's function answers ERROR_INVALID_HANDLE. If the executable reads the key another way, --dry-run shows the import.

Test

xgameruntime_test gains test_console_mode_registry. It has a stand-in for the title's function (open, query with a 4-byte buffer, close, map the value) and runs it against the registry functions the loader would bind:

  • it reads 7 (Series X) by default and follows LEONIDA_DEVICE_TYPE 2..8; with 1 it reads 1 through the host (checked only when the host has no such key, which the test asks the host first);
  • the pseudo-key answers a size query (REG_DWORD, 4 bytes), ERROR_MORE_DATA for a short buffer, ERROR_FILE_NOT_FOUND for any other value name, and closes;
  • another HKLM key opened through the shim returns the same CurrentBuild bytes as the host does directly; a key that merely ends in OEM, and the same path under HKEY_CURRENT_USER, are the host's;
  • advapi32.dll is not a module the shims own.

Tested

Windows 11 (build 26200), MSVC 19.44.35222, Visual Studio's CMake and ctest 3.31.6 with Ninja, RelWithDebInfo, built by scripts/build_runtime.ps1. Base f847748c (main).

  • xgameruntime_test with the new test on main's shims: 1 of 95 checks failed (the twelve registry names do not resolve; the test stops there, after printing that the sequence answers 1 against the host's registry). With the change: OK, 110 checks.
  • gta6rt --dry-run on my own copy of the two DLLs: the four registry imports of each are now shim (XCurl.dll shim=28 host=112, libHttpClient.GDK.dll shim=30 host=168, 0 unimplemented).
  • ctest --test-dir runtime/build -C RelWithDebInfo with LEONIDA_GAME_DIR set, on this head: 140 run, 134 passed, 6 skipped, 0 failed (gameinput is disabled, no SDL3 here). NVIDIA GeForce RTX 4090, driver 32.0.16.2114, for the Vulkan tests in that run; this change needs no GPU.
  • python -I on tests/test_docs_links.py, test_docs_repo_paths.py, test_docs_list_items.py, test_docs_design_rows.py, test_i18n_index.py: OK.
  • No game data: the change names two registry strings and the imports' DLL names; no bytes or offsets of the package.

Overlap: several open PRs add runtime classes to xgameruntime.cpp (#3363, #3408, #3476, #3505, #3550, #3657). This adds one block after XSystemGetDeviceType and its own small shim table, apart from the class tables and the big export table. #3601 (mine) adds a docs/related_projects.md entry in a different place.

🤖 Generated with Claude Code

…ype reads

A title does not import XSystemGetDeviceType: xgameruntime.lib links it in, and
that copy opens HKLM\Software\Microsoft\Windows NT\CurrentVersion\OEM and reads the
DWORD ConsoleMode; a missing key or value means PC. The package's XCurl.dll and
libHttpClient.GDK.dll both carry it. No shim served those registry calls, so they
reached the host, which has no such key, and the title was told it runs on a PC
whatever the shim's export or LEONIDA_DEVICE_TYPE said.

RegOpenKeyW, RegOpenKeyExW, RegQueryValueExW and RegCloseKey are now served under
advapi32.dll and the two registry API sets those DLLs import them by. They answer
that one key with the ConsoleMode of the device type the export reports and pass
every other key, root and handle to the host. advapi32.dll stays a host module.

xgameruntime_test runs the title's sequence against the registry functions the
loader would bind. docs: the sequence in runtime_imports.md; an entry for xvalkyrie.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested 42f3708 on Windows 11, MSVC (VS 2022 Build Tools) RelWithDebInfo, with RTX 5080 (driver 616.92) and AMD Radeon iGPU gfx1036 (driver 26.10.1) each selected in turn (LEONIDA_VK_DEVICE, VK_LOADER_LAYERS_DISABLE=~implicit~; these tests need no GPU):

  • ctest -R "^(xgameruntime|loader)$": 2/2 per run. xgameruntime_test: OK (110 checks), and it printed bound to the host's registry, the title's function answers 1 (1 is a PC) for this host. loader: 79 checks, 0 failed.
  • pe_loader, pe_loader_bounds, loader_tls (for the advapi32.dll host-module change): 3/3.

No negative control run.

AI-assisted.

@lunisahdidouch

Copy link
Copy Markdown

Tested 42f3708 on Windows 11 (26300), RX 9070 (AMD 26.11.1), VS 2022 Build Tools, RelWithDebInfo with SDL3: pass

Full ctest: 141 tests, 0 failed, including xgameruntime and gameinput. The 7 skips are the same as on main (the five package tests, vk_sync_validation, d3d12_first_light). The docs tests (test_docs_links, test_docs_repo_paths, test_docs_list_items, test_docs_design_rows) pass too.

AI-assisted

@shayderrr shayderrr 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.

Review

Reviewed change in PR #3775: xgameruntime: answer the registry key a title's own XSystemGetDeviceType reads, so it is not told "PC".

Scope: docs/related_projects.md, docs/runtime_imports.md, runtime/shims/registry.cpp, +2 more
Diff: +259 / -1 across 5 file(s).

The change stays inside the stated scope and the touched files line up with the description. No unrelated production paths are pulled in, and the stated behavior is directly exercised by the diff. I'm approving this one.

Reviewed by shayderrr via automated batch review.

@shayderrr

Copy link
Copy Markdown
Collaborator

Thanks @kotorvr - I went through xgameruntime: answer the registry key a title's own XSystemGetDeviceType reads, so it i... and the diff around docs/related_projects.md. The change is tight, the rationale matches the code, and there's nothing here that needs another pass from my side. Approved and squash-merging it into main now. Nice work.

@Kam471 Kam471 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.

Reviewed head 42f3708d81b38298b35395335f46851ca00410f6. Windows 11 26200, MSVC 19.44.35207, Ninja, RelWithDebInfo, Vulkan 1.4.363.

xgameruntime 1/1, 151 checks, git diff --check clean. New checks: the four registry calls resolve under advapi32 and both api-ms registry sets; the title's own XSystemGetDeviceType reads 7 (Series X); ConsoleMode is 0x64; LEONIDA_DEVICE_TYPE 2..8 reaches it; a key merely ending in OEM and the same path under HKCU are not answered. Red: reverting runtime/shims/xgameruntime.cpp exits 1 with 1 of 136 checks failed (the block stops at the missing bindings).

Verdict: ready to merge. advapi32 stays a host module; only the four names are overridden at import binding, and the test confirms another key still answers as the host does. Limitation: GetProcAddress on the host advapi32 still returns the host function, so a title resolving these dynamically is unaffected.

First-frame: without this, a retail title is told it runs on a PC and takes its PC device path. Related: #4821 changes the same device-type policy (Series S default), so the two will need a small rebase together.

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.

5 participants