compat-common: hand out a stand-in IGameInput when the host has no GameInput #326
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!326
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/326/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@GDAgent on GitHub · 2026-11-23 19:03 UTC · original
GDAgent:fix/compat-gameinput-standalone→main· +246 −0 · 1 files · 1 commits · closed without mergingLibrary / area:
compat-common(gamepad.rs)Exports changed (exports.txt rows): none
Source of the behaviour: observed behaviour of a very popular AAA title on native Windows 11 (not run under Proton); GDK
IGameInputreference for the vtable layout; the repo's existing virtual-pad hooks.What
When the real
GameInputCreatefails, the hook now returnsS_OKwith a static stand-inIGameInputinstead of passing the failure on. The stand-in goes through the samepatch_objectpath as a real object, so the virtual Xbox gamepad, the control channel and the host-pad bridge attach exactly as they do to a host GameInput. If a real object was patched before, the stand-in is not adopted and the original HRESULT is returned.now_uskeeps its behaviour; its QueryPerformanceCounter fallback moves intoqpc_usso the stand-in timestamp does not recurse.Why
On a console
GameInputCreatenever fails and titles use the returned interface without checking the HRESULT. A very popular AAA title calls a method on the null interface right after a failedGameInputCreateand dies with an access violation 5.7 s into the run. Hosts without a running GameInput service (a fresh VM or Windows Sandbox, whereGameInputSvcstops right after START_PENDING) return0xd0000034from the real call.Relation to #293 (which says GameInput on such hosts is solved by shipping Microsoft's
GameInputredistributable): that remains the way to get real host devices (keyboard, XInput and other pads through the host). This change does not replace it. It only applies when the realGameInputCreatehas already failed, so nothing changes on hosts where the redistributable or the service works. It removes the need for the redistributable just to get a virtual pad and a title that does not crash on a null interface; host devices stay unavailable in that mode.Behaviour of the stand-in, method by method
Each of the 22 methods either really works (backed by the virtual pad or the host clock) or returns a real error code. Nothing claims a host device exists.
Real (virtual pad, through the existing hooks that wrap the stand-in):
GetCurrentReading/GetNextReading/GetPreviousReading/GetTemporalReadingfor the virtual pad or any-device queries: the virtual pad's readings, as with a host object.RegisterDeviceCallbackfor the pad: the registration is recorded and the virtual pad is announced, as with a host object.FindDeviceFromId/FindDeviceFromObjectfor the virtual pad: the virtual device.GetCurrentTimestamp: QueryPerformanceCounter in microseconds.Stand-in behaviour for everything that is not the virtual pad (there are no host devices):
GetCurrentReading,GetNextReading,GetPreviousReading,GetTemporalReading:GAMEINPUT_E_READING_NOT_FOUND, null reading.RegisterReadingCallback:E_NOTIMPL, zero token (same answer the virtual pad already gets; callback-driven readings are not supported).RegisterDeviceCallback,RegisterSystemButtonCallback,RegisterKeyboardLayoutCallback: a registration with a unique token that is remembered. These are event subscriptions whose sources do not exist here, so they never fire. A null token pointer isE_INVALIDARG.StopCallback,UnregisterCallback: forget only tokens that were issued;UnregisterCallbackreturns false for an unknown or already removed token.CreateDispatcher,CreateAggregateDevice:E_NOTIMPL, null out pointer.FindDeviceFromId,FindDeviceFromObject,FindDeviceFromPlatformHandle,FindDeviceFromPlatformString(anything but the virtual pad):E_NOTFOUND(HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) with a null out pointer.EnableOemDeviceSupport,SetFocusPolicy: accepted with no effect, because there are no host devices to apply them to. The return type ofEnableOemDeviceSupportwas not checked against the public header; the stand-in returns 0.QueryInterfacereturns the object for any IID (andAddRef), like the other virtual objects of this module;Releasenever frees the static object.Tests
gamepad::tests::failed_create_hands_out_a_standin_gameinput_with_the_virtual_pad: adopts the stand-in twice (same object, patched vtable), refuses a null out pointer, and calls QI, Release, the timestamp,GetCurrentReading(READING_NOT_FOUND, null out),RegisterReadingCallback(E_NOTIMPL, zero token),RegisterDeviceCallbackandRegisterSystemButtonCallback(distinct non-zero tokens; null token pointer isE_INVALIDARG),StopCallback,UnregisterCallback(issued token true once, then false; stopped and unknown tokens false),CreateDispatcher(E_NOTIMPL),FindDeviceFromId(virtual pad found, other idE_NOTFOUND),FindDeviceFromObject,EnableOemDeviceSupportandSetFocusPolicythrough the patched vtable.cargo test -p compat-common --lib gamepad: 22 passed, 0 failed.Not verified
In a title: not re-run in a title after this exact change; the null-interface crash that motivated it was seen in a very popular AAA title. The stand-in was not tested on a host without GameInput (the unit test adopts the stand-in directly).
E_NOTFOUNDas the code for an unknown device and0forEnableOemDeviceSupportwere not compared against a real GameInput.If a real
GameInputCreatefailed first and succeeded later in the same process, the real object would not be wrapped (its vtable differs from the stand-in's). Not handled; hosts do not change GameInput availability mid-run in practice.No real-device behaviour (keyboard, XInput) is provided in stand-in mode.
cargo test -p compat-common(gamepad tests) passesNo game or console files and no binaries included
No fake success; anything not possible is left
missingwith a note@omonkeyz on GitHub · 2026-11-25 13:49 UTC · original
Applied on main in
9af87c0(cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.Pull request closed