Skip to content

runtime: answer the console-type registry key (ConsoleMode) from LEONIDA_DEVICE_TYPE - #6990

Open
AwkGrep256 wants to merge 1 commit into
ItsNotRexed:mainfrom
AwkGrep256:console-mode-registry
Open

AwkGrep256 wants to merge 1 commit into
ItsNotRexed:mainfrom
AwkGrep256:console-mode-registry

Conversation

@AwkGrep256

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as part of: #6750 (comment) (FSR in the Series X render path; this is its first, standalone step and also matters for RT-5).

What and why

The retail executable does not ask XSystemGetDeviceType for its console type. It reads the registry: RegOpenKeyW(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion\OEM"), then the REG_DWORD ConsoleMode, and maps the value itself (a static look at my own copy, nothing executed; RegOpenKeyW, RegQueryValueExW and RegCloseKey are its only advapi32.dll imports, and that query is RegOpenKeyW's only caller):

ConsoleMode XSystemDeviceType
key or value missing 1 Pc
0x60 6 XboxScarlettLockhart (Series S)
0x64 7 XboxScarlettAnaconda (Series X)
0x68 8 XboxScarlettDevkit
0x58 / 0x50 / 0x40 5 / 4 / 3 (Xbox One X devkit, One X, One S)
0x10, 0x20, 0x21, 0x30, 0x31 2 XboxOne
anything else 0 Unknown

A PC has no such key, so under gta6rt the title saw Pc while XSystemGetDeviceType (and LEONIDA_DEVICE_TYPE) said Series X. One thing that hangs on it: the title picks its upscaler from it. Series S gets AMD's FFX upscaler (the amd_fidelityfx_loader_xbox.dll path), every other type the title's own.

The change

  • runtime/shims/advapi32_registry.cpp (new): RegOpenKeyW, RegQueryValueExW and RegCloseKey answer that one key from XSystemGetDeviceType, looked up in the shim table, so the two can't disagree: 0x64 by default, 0x60 with LEONIDA_DEVICE_TYPE=6, no key for 1 (Pc), as the title's mapping reads them back. The key and value names match case-insensitively. Every other key goes to the host's registry.
  • runtime/shims/registry.cpp: advapi32.dll joins the host DLLs (owns_dll) like kernel32 and user32, so its other names (and the package DLLs' advapi32 imports) still bind to the host's.
  • runtime/README.md: the LEONIDA_DEVICE_TYPE row says the registry follows it.

Tested

Windows cross-build (clang-cl + xwin), run under Wine 11 on CachyOS:

  • xgameruntime_test: OK, 153 checks. New: the three names are shims and advapi32.dll stays a host DLL; ConsoleMode is 0x64 by default and 0x60 with LEONIDA_DEVICE_TYPE=6; 1 gives no key; case-insensitive key; a size query gives 4; a 2-byte buffer gets ERROR_MORE_DATA and 4; another value is ERROR_FILE_NOT_FOUND; another key opens and closes in the host's registry.
  • ctest -R "loader|pe_loader|xmem|process_cmdline|winhttp_offline|run_tiny|xgameruntime": 30 of 31 pass. run_tiny_game_abort_exit_codes fails the same way on main 1cc6e3c1 under Wine (native abort exit codes), so it's unrelated.
  • Not run: the title's --run (it doesn't reach the query yet on Linux), native Windows.

Nothing from the executable is in the repository or here: only the import names, the public registry path the GDK uses, and the value mapping.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…IDA_DEVICE_TYPE

The title reads its console type from HKLM\Software\Microsoft\Windows NT\
CurrentVersion\OEM, value ConsoleMode, not from XSystemGetDeviceType. A PC
has no such key, so the title saw Pc while the xgameruntime shim reported
Series X. advapi32.dll's RegOpenKeyW, RegQueryValueExW and RegCloseKey now
answer that one key from XSystemGetDeviceType (LEONIDA_DEVICE_TYPE, default
Series X: 0x64); advapi32.dll stays a host DLL, so every other key and
name reaches the host's registry. xgameruntime_test checks it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwkGrep256 added a commit to AwkGrep256/Leonida that referenced this pull request Nov 23, 2026
docs/README.md lists modding.md; the README says how to turn
mods/fsr_series_x on. modding.md names the registry change by its PR
(ItsNotRexed#6990) instead of a file this branch doesn't have.

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

Copy link
Copy Markdown

Independent Windows CPU check of dab41122066cad1141f6b5b6dc3046354a752914, Windows 11 build 26300, MSVC 19.44.35230. The CMake build passed, xgameruntime_test passed 153 checks, 31 focused CTests passed, and 45 additional synthetic registry checks passed. A mapped synthetic guest also resolved the intended shim exports and reported the expected ConsoleMode for default, Series S/X/devkit and PC controls. No retail code or registry writes.

The cl.exe fallback is missing the new shim. CMake includes shims/advapi32_registry.cpp, but the $files list in scripts/build_runtime.ps1 does not. python -I tests/test_build_runtime_fallback.py -v failed 1/8 at test_the_launcher_compiles_every_source_cmake_gives_gta6rt, reporting precisely that file. Please include it in the fallback source list and rerun that check before merging.

AI-assisted.

@465d6a0eac

Copy link
Copy Markdown
Contributor

Tested dab411220 merged onto main f283b1378 on Windows 11 (build 26300), RTX 3070 Ti (driver 610.88): pass. Build: MSVC 19.44.35230, Windows SDK 10.0.26100, RelWithDebInfo with Ninja, LEONIDA_D3D12=vulkan. The retail executable is from my own 1.0.2.1 copy, and its SHA-256 matches docs/runtime_imports.md. Counts and outcomes only.

  • Build and tests. The build is clean, and xgameruntime_test passes with 153 checks. The full ctest -j 8 passes 233 of 234. The one failure is d3d12_vulkan_device (line 6564: tiles == 1), which is the slot 78 regression from d3d12_xs: route the public HLE's Xbox device slots 48/73/78/79/80 #6935: it fails the same way on main without this PR, and d3d12_vulkan_device: check PC CreateReservedResource2 behind the Xbox proxy, not through slot 78 #7125 fixes it.
  • --dry-run against main.
    • game_scarlett_master.exe: shim 54 → 57 and host 432 → 429. Unimplemented stays at 29.
    • libHttpClient.GDK.dll: shim 28 → 31 and host 170 → 167. It imports the same three ADVAPI32 functions, so they reach this shim too. Its other keys go to the host registry through the shim's pass-through, as before.
    • The other three modules don't change.
  • --run, 3 runs. The stop is the same as main: the title's int3 (0x80000003) at the same site, right after the XMemVirtualAlloc attribute events. There is no new unimplemented call.
  • Is the query on the boot path? Yes, and it is consumed before that stop. I added a temporary log line to the shim (not part of this PR) and mapped the return address against the startup trace's map events:
    • The OEM key is opened twice before the stop, both times from game_scarlett_master.exe (not from libHttpClient).
    • Each time it reads ConsoleMode = 0x64 (Series X, the LEONIDA_DEVICE_TYPE default).

AI-assisted (Claude Code).

@moistman7

Copy link
Copy Markdown

Tested dab41122 merged onto main 4da521de (clean) on native Windows 11 26200 (not Wine), MSVC 2022 Build Tools, RelWithDebInfo, RTX 5090 (617.42): pass.

@DatGuySnowfox

Copy link
Copy Markdown

Your mapping table matches what I read statically, independently and down to the value groupings, so that is two reads agreeing. One thing I found that is not in the table and makes four of its rows unusable rather than merely wrong.

The title asserts on the mapped id. The function that calls D3D12ConfigureVirtualMemoryX reads the same id first and __debugbreaks unless it is 1, 6, 7 or 8:

ConsoleMode id reaches the device
key or value missing 1 Pc yes
0x60 6 Lockhart yes
0x64 7 Anaconda yes
0x68 8 Devkit yes
0x58 / 0x50 / 0x40 5 / 4 / 3 no, fatal assert
0x10, 0x20, 0x21, 0x30, 0x31 2 XboxOne no, fatal assert
anything else 0 Unknown no, fatal assert

It fires in virtual-memory setup, before the device is created, so it is early and it has no diagnostic: an unhandled int3 there exits with C0000374 or C0000005 during teardown rather than 80000003, as retail_boot_chain.md notes. It would read as an unrelated allocation failure.

Your default of 0x64 is safe and LEONIDA_DEVICE_TYPE=6 is safe, so nobody will have hit this. But the shim now accepts LEONIDA_DEVICE_TYPE values that map to 2, 3, 4, 5 and 0, and any of those kills the title at that assert. Worth either rejecting them in the shim with a clear message, or saying in the LEONIDA_DEVICE_TYPE row that only 1, 6, 7 and 8 are usable with the retail title.

Also, on scope: the upscaler is the visible consequence but it is a long way from the only one. The title reduces the id to one cached boolean, id == 6, and 63 functions read that boolean across 71 call sites. Besides the upscaler it selects:

  • the two startup XMemVirtualAlloc reserves, 24 GiB each on every accepted id except id 6, where they are 16 GiB;
  • the D3D12ConfigureVirtualMemoryX count at +4 of its 32-byte block, 3 against 2;
  • a ten-entry memory budget table written in one block, whose largest entry is 6,236 MiB against 3,977 MiB;
  • an asset variant suffix, ":xbsx" against ":xbss", combined with a name and looked up in one of the title's name tables;
  • two render target dimensions that are right-shifted by one under id 6, and two others clamped to 1024.

So LEONIDA_DEVICE_TYPE=6 is not a small switch: it halves some surfaces and changes which asset variants the title asks the archives for. Probably worth a line in the LEONIDA_DEVICE_TYPE row to that effect, since the natural reading of the current row is that it only affects the device type answer.

All static, on my own copy, nothing executed, so the assert is a shape I read rather than one I have tripped.

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