gameinput: StopCallback and UnregisterCallback take the current-callback token #46

Closed
Andretuta wants to merge 1 commit from upstream-pr/46 into main
Andretuta commented 2026-11-24 02:07:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:07:09Z.


Carried over from old PR 9769 by Joaco9020 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9769, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
Joaco9020: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Claim: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7115375665 (from @Maraco91's finding: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7115359105)

Depends on: none. Overlaps: #9264 and #5109 also edit UnregisterCallback / the delivery path in runtime/shims/gameinput.cpp; this change adds two lines at the top of StopCallback and UnregisterCallback and a guard in call(), so whichever lands second needs a small rebase.

What and why

GAMEINPUT_CURRENT_CALLBACK_TOKEN_VALUE (0xFFFFFFFFFFFFFFFF) names the callback that is running on the calling thread. The host's GameInput (0.2309, Windows 11, measured in the finding) treats it that way: inside a callback UnregisterCallback(CURRENT, 0) removes that callback and returns true, and StopCallback(CURRENT) stops it; outside a callback the token names nothing and UnregisterCallback returns false. The shim compared the constant with the registered tokens, matched none, and the callback kept firing, also after a title had freed its context.

  • gameinput_abi.h: kCurrentCallbackToken.
  • gameinput.cpp: call() records the running callback's token in a thread_local, restored on return (so a callback that drives another delivery keeps its own); StopCallback and UnregisterCallback resolve the constant through it, and with no running callback do nothing / return false.
  • gameinput_test.cpp: a reading callback on the virtual Xbox pad that cancels itself with the constant on its first call must run once for four button changes, once with UnregisterCallback (which must return true, after which the real token is gone) and once with StopCallback (the callback stays registered); the constant outside a callback returns false.

Tested

Windows 11, MSVC 19.44 (VS 2022 Build Tools), SDL3 fetched with -DLEONIDA_SDL3_FETCH=ON, on main 5d74c2723:

  • gameinput_test: 348 checks, 0 failures (7 new).
  • Negative control: the new test against the old gameinput.cpp (only the header constant added): 348 checks, 3 failures, exactly the three new behaviour checks.
  • gameinput_probe and gta6rt build with the change.

No game files, no controller (SDL virtual pads only). Whether the retail title passes the constant is not measured.

AI-assisted: yes (Claude).

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5464711809 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/46). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T02:07:09Z. --- > Carried over from **old PR 9769** by `Joaco9020` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9769`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `Joaco9020`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Claim: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7115375665 (from `@Maraco91`'s finding: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7115359105) Depends on: none. Overlaps: `#9264` and `#5109` also edit `UnregisterCallback` / the delivery path in `runtime/shims/gameinput.cpp`; this change adds two lines at the top of `StopCallback` and `UnregisterCallback` and a guard in `call()`, so whichever lands second needs a small rebase. ### What and why `GAMEINPUT_CURRENT_CALLBACK_TOKEN_VALUE` (`0xFFFFFFFFFFFFFFFF`) names the callback that is running on the calling thread. The host's GameInput (0.2309, Windows 11, measured in the finding) treats it that way: inside a callback `UnregisterCallback(CURRENT, 0)` removes that callback and returns true, and `StopCallback(CURRENT)` stops it; outside a callback the token names nothing and `UnregisterCallback` returns false. The shim compared the constant with the registered tokens, matched none, and the callback kept firing, also after a title had freed its context. - `gameinput_abi.h`: `kCurrentCallbackToken`. - `gameinput.cpp`: `call()` records the running callback's token in a `thread_local`, restored on return (so a callback that drives another delivery keeps its own); `StopCallback` and `UnregisterCallback` resolve the constant through it, and with no running callback do nothing / return false. - `gameinput_test.cpp`: a reading callback on the virtual Xbox pad that cancels itself with the constant on its first call must run once for four button changes, once with `UnregisterCallback` (which must return true, after which the real token is gone) and once with `StopCallback` (the callback stays registered); the constant outside a callback returns false. ### Tested Windows 11, MSVC 19.44 (VS 2022 Build Tools), SDL3 fetched with `-DLEONIDA_SDL3_FETCH=ON`, on `main` `5d74c2723`: - `gameinput_test`: **348 checks, 0 failures** (7 new). - **Negative control**: the new test against the old `gameinput.cpp` (only the header constant added): 348 checks, **3 failures**, exactly the three new behaviour checks. - `gameinput_probe` and `gta6rt` build with the change. No game files, no controller (SDL virtual pads only). Whether the retail title passes the constant is not measured. AI-assisted: yes (Claude). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
aslan2142 commented 2026-11-24 19:17:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-24T19:17:49Z.


This carry-over of old upstream PR 9769 has been taken over in #1095, so I'm closing this draft as #17 describes. The branch old-pr/9769 stays.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7141889120 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/46#issuecomment-7141889120). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-24T19:17:49Z. --- This carry-over of old upstream PR 9769 has been taken over in #1095, so I'm closing this draft as #17 describes. The branch `old-pr/9769` stays. AI-assisted (Claude Code, Claude Opus 5.5).

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!46
No description provided.