Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,24 @@ target_compile_features(startup_runtime_gpa_patch PRIVATE cxx_std_17)
add_test(NAME startup_runtime_gpa_patch COMMAND startup_runtime_gpa_patch)
add_test(NAME startup_runtime_gpa_patch_name_only_control COMMAND startup_runtime_gpa_patch --mutate name-only)
set_tests_properties(startup_runtime_gpa_patch_name_only_control PROPERTIES PASS_REGULAR_EXPRESSION "FAIL: ")
# X2W_DEVICE_TYPE: the OEM ConsoleMode registry read, answered or passed on, against fake registry
# functions. A source-built decoy DLL exports the same registry names and must stay unhooked. The
# control leaves the switch unset for the answered cases; the provider control matches registry
# imports by name alone. Both must FAIL.
add_library(startup_console_mode_decoy SHARED
tests/startup_console_mode_decoy.cpp
tests/startup_console_mode_decoy.def)
target_compile_features(startup_console_mode_decoy PRIVATE cxx_std_17)
add_executable(startup_console_mode tests/startup_console_mode_check.cpp)
target_include_directories(startup_console_mode PRIVATE src)
target_compile_features(startup_console_mode PRIVATE cxx_std_17)
add_dependencies(startup_console_mode startup_console_mode_decoy)
add_test(NAME startup_console_mode COMMAND startup_console_mode --decoy "$<TARGET_FILE:startup_console_mode_decoy>")
add_test(NAME startup_console_mode_control
COMMAND startup_console_mode --control --decoy "$<TARGET_FILE:startup_console_mode_decoy>")
add_test(NAME startup_console_mode_provider_control
COMMAND startup_console_mode --control provider --decoy "$<TARGET_FILE:startup_console_mode_decoy>")
set_tests_properties(startup_console_mode_control startup_console_mode_provider_control PROPERTIES PASS_REGULAR_EXPRESSION "FAIL: ")
# EXE + late-loaded package helper through the real Windows loader: proxied xgameruntime QueryApiImpl,
# unrelated same-named export stays original. Notification only enqueues; rewrite runs after link.
if (WIN32)
Expand Down
29 changes: 29 additions & 0 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,7 @@ ctest --preset dev --no-tests=error -R '^startup_trap_header(_prefix_control|_pr
| `X2W_RUNTIME_PROXY=1` | proxies the gaming runtime and logs every call. Rewrites regular-IAT `GetProcAddress` and a direct `xgameruntime.dll!QueryApiImpl` import on the main EXE and on DLLs that share its directory (package helpers). Dynamic `QueryApiImpl` / `InitializeApiImpl*` are wrapped only when the provider module's basename is `xgameruntime.dll`. `LdrRegisterDllNotification` only flags that another scan is needed. A worker holds each matching module live while rewriting after linking. Loading a helper and immediately calling it can precede the scan. The enabled proxy stays loaded until process exit. Delay-import IAT slots are not rewritten. Skips this stand-in's own `GetProcAddress` IAT so the hook does not recurse (`src/startup_stubs/runtime_gpa_patch.h`, `ctest --preset dev --no-tests=error -R '^startup_runtime_gpa_patch(_name_only_control)?$'`, and the control must print `FAIL:`; Windows also runs `startup_runtime_proxy_scope` for a late-loaded helper through the real loader) |
| `X2W_FAKE_USER=1` | answers the user, gamertag and save APIs for one local user, and creates one offline store context for that user |
| `X2W_RUNTIME_LOCAL=1` | with `X2W_RUNTIME_PROXY` and `X2W_FAKE_USER`, for a host where the system gaming runtime cannot initialize (no Gaming Services). The first failed `InitializeApiImpl*` is reported as `S_OK`, and every later initialization call returns `S_OK` without calling the real export. Once initialization failure is latched, a failed real `QueryApiImpl` call can fall back only with an exact match of both GUIDs to a supported provider/interface pair for user (including gamertag), game save, package, title, connectivity or store. Persistent local storage uses its existing fake-user gate and requires its exact provider GUID and IID. Unmatched failed queries keep the real HRESULT. The proxy clears a writable output on failure only when fake user is enabled and the initialization failure is latched. A local object's `QueryInterface` accepts only `IID_IUnknown` and the IID it was created for. The local answers above apply, calls that carry the local user or store handle fail as before, and other unanswered methods return `E_NOTIMPL`. `XUserAddAsync` and async operations completed on behalf of a local answer require the real runtime's `QueryApiImpl` to return the XAsync provider (`073b7dcb`). Those operations complete with `S_OK` through XAsync, or return the query failure if XAsync is unavailable (`ctest --preset dev --no-tests=error -R '^startup_runtime_local(_control)?$'`, and the control must print `FAIL:`). |
| `X2W_DEVICE_TYPE=<n>` | with `X2W_RUNTIME_PROXY=1`, answers the title's reads of the OEM `ConsoleMode` registry value: `6` = 0x60 (Series S), `7` = 0x64 (Series X), `1` = value missing (PC); unset, the real registry answers. See [Console profile](#console-profile) |
| `X2W_STORAGE_PATH`, `X2W_STORAGE_MB`, `X2W_TITLE_ID` | persistent local storage and the manifest values the runtime would return. The path is UTF-8, with a trailing separator added when missing. If the path is invalid or exceeds 259 bytes including the separator, the proxy logs the refusal and uses `S:\` (`src/startup_stubs/storage_root_utf8.h`, `ctest --preset release --no-tests=error -R '^startup_storage_root'`). |
| `X2W_INPUT_SCRIPT=mask@sec,...` | timed virtual gamepad presses, holds, stick or trigger values and waits for the presented picture: see [Input script](#input-script); keyboard and XInput pad 0 also work. Up to 256 entries and 4,095 characters; a longer value is ignored and logged, and dropped or malformed entries are logged (`ctest --preset dev --no-tests=error -R '^startup_gameinput_script_(long|entries|syntax)$'`) |
| `X2W_SAMPLER_HEAP=1` | `gfx2hlsl.py` translates a sampler-heap load with a run-time offset into `SamplerState qh[2048] : register(s0, space1)` and writes `smpheap 2048 1 fallback 2047`. The stand-in uses entries 0 to 2046 for the bound heap and reserves entry 2047 for unaligned or out-of-range offsets. It also accepts the original `smpheap 2048 1` manifest with all 2,048 entries available. [#1143](https://github.com/R0Y00/Xbox2Windows/issues/1143) |
Expand Down Expand Up @@ -1387,6 +1388,34 @@ together under their original name. A 16-dword table load can contain two
independent image descriptors at offsets 0 and 32 from the load address.
For a read-only census of cached shader refusals, use `python -B tools/startup/gfx2hlsl.py --refusals <cache-directory> [--json]` with a translator that supports the flag. Earlier versions treat it as `--pending` and write into the directory. See [Startup translator refusal census](experiments.md#startup-translator-refusal-census).

## Console profile

`X2W_DEVICE_TYPE` answers the two registry reads a title makes of
`HKLM\Software\Microsoft\Windows NT\CurrentVersion\OEM\ConsoleMode`
(`src/startup_stubs/console_mode.h`, `registry_console_mode.inl`): with `X2W_RUNTIME_PROXY=1` the
stand-in rewrites the registry imports of the EXE and package helpers. `6` answers 0x60 (Series S),
`7` answers 0x64 (Series X) and `1` reports the value missing (PC); unset, every call goes to the real
registry. Only registry imports that the Windows registry provides are rewritten: an IAT entry must
name `advapi32.dll`, `kernelbase.dll`, `kernel32.dll` or an `api-ms-win-core-registry-*` API set and be
bound inside the system-directory copy of the first three, and `GetProcAddress` must be called on one
of those modules. A package DLL that exports the same names keeps its own exports and is never kept as
the real registry. Opening the key and reading the value are logged a few times either way, and a
seventeenth OEM key handle open at once is logged once and not tracked. What the values mean on the
console is taken from public notes, not measured here.
`ctest --preset dev --no-tests=error -R '^startup_console_mode(_control|_provider_control)?$'` runs it
against fake registry functions and a source-built decoy DLL with the same export names, with the switch
unset and set. The control leaves the switch unset for the answered cases and the provider control
matches registry imports by name alone; both must print `FAIL:`. `startup_runtime_proxy_scope` checks the
same decoy rule through the real loader against `advapi32.dll`.

The switch changes only what the registry reads answer. A title can take a different start-up path
for each profile: on the Series S profile, one loaded an upscaler package module that the other
profiles do not, and that module met desktop refusals the other profiles did not reach
(`Device::slot76`, views with `ViewDimension` 0, and `R9G9B9E5_SHAREDEXP` textures with unordered
access, the last covered by the
[shared-exponent stand-in](#shared-exponent-render-and-unordered-access-targets)). Choosing a profile
is not evidence that the path it leads to runs.

## D3D12 resource budget

Set `X2W_D3D12_BUDGET=1` before startup to add one `x2w-budget` line to each
Expand Down
96 changes: 96 additions & 0 deletions src/startup_stubs/console_mode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Experimental (docs/startup-runtime.md): which console the title is told it runs on.
//
// Public GDK documentation describes XSystemGetDeviceType and the XSystemDeviceType values
// (Pc = 1, XboxScarlettLockhart = 6, XboxScarlettAnaconda = 7). The proxied runtime calls seen in
// startup runs include no device-type method. A public runtime reimplementation's notes
// (github.com/Marvisak/VIctory, facts only) say the value is not a runtime call: title code reads
// HKLM\Software\Microsoft\Windows NT\CurrentVersion\OEM, DWORD value ConsoleMode, where 0x60 is
// Series S, 0x64 is Series X and a missing value is a PC. Those three readings are that source's,
// not measured here.
//
// X2W_DEVICE_TYPE=<n> (with X2W_RUNTIME_PROXY) answers that one value: 6 -> 0x60, 7 -> 0x64,
// 1 -> missing. Unset or any other number passes every read to the real registry.
// Pure helpers, no Windows calls, so a source-built control can check them.
#pragma once

#include <cstddef>
#include <cstdint>

namespace x2w_console_mode {

constexpr long status_ok = 0, status_not_found = 2, status_invalid = 87, status_more_data = 234, status_wrong_type = 1630;
constexpr unsigned long type_dword = 4;
constexpr unsigned long rrf_rt_reg_dword = 0x10;
constexpr std::uint32_t series_s = 0x60, series_x = 0x64;

inline wchar_t fold(wchar_t c) noexcept
{
return (c >= L'A' && c <= L'Z') ? static_cast<wchar_t>(c - L'A' + L'a') : c;
}

inline bool equal_ci(const wchar_t* a, const wchar_t* b) noexcept
{
if (!a || !b) return false;
for (;; ++a, ++b) {
if (fold(*a) != fold(*b)) return false;
if (!*a) return true;
}
}

// Subkey of HKEY_LOCAL_MACHINE. One leading or trailing backslash is accepted.
inline bool is_oem_subkey(const wchar_t* subkey) noexcept
{
static constexpr wchar_t expect[] = L"software\\microsoft\\windows nt\\currentversion\\oem";
if (!subkey) return false;
if (*subkey == L'\\') ++subkey;
std::size_t i = 0;
for (; expect[i]; ++i)
if (fold(subkey[i]) != expect[i]) return false;
return !subkey[i] || (subkey[i] == L'\\' && !subkey[i + 1]);
}

inline bool is_console_mode_value(const wchar_t* name) noexcept
{
return equal_ci(name, L"ConsoleMode");
}

enum class Answer { pass, value, missing };

// device_set is false when X2W_DEVICE_TYPE is absent or not a number.
inline Answer answer_for(bool device_set, unsigned long device_type, std::uint32_t* mode) noexcept
{
if (!device_set) return Answer::pass;
switch (device_type) {
case 1: return Answer::missing;
case 6: if (mode) *mode = series_s; return Answer::value;
case 7: if (mode) *mode = series_x; return Answer::value;
default: return Answer::pass;
}
}

// RegQueryValueExW's output rules for one REG_DWORD.
inline long fill_query(std::uint32_t value, unsigned long* type, unsigned char* data, unsigned long* bytes) noexcept
{
if (data && !bytes) return status_invalid;
if (type) *type = type_dword;
if (!data) {
if (bytes) *bytes = sizeof(value);
return status_ok;
}
if (*bytes < sizeof(value)) {
*bytes = sizeof(value);
return status_more_data;
}
for (std::size_t i = 0; i < sizeof(value); ++i) data[i] = static_cast<unsigned char>(value >> (8 * i));
*bytes = sizeof(value);
return status_ok;
}

// RegGetValueW's: the flags must allow a DWORD (RRF_RT_REG_DWORD, part of RRF_RT_DWORD and RRF_RT_ANY).
inline long fill_get(unsigned long flags, std::uint32_t value, unsigned long* type, void* data, unsigned long* bytes) noexcept
{
if (!(flags & rrf_rt_reg_dword)) return status_wrong_type;
return fill_query(value, type, static_cast<unsigned char*>(data), bytes);
}

} // namespace x2w_console_mode
Loading
Loading