upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs/gameinput.md
diff options
context:
space:
mode:
authorOreoFR <tony37160@hotmail.fr>2026-11-30 11:29:46 +0100
committerOreoFR <tony37160@hotmail.fr>2026-11-30 11:29:46 +0100
commitca71fd7f5c04ca3ec269fd3983e7201ac3344b8b (patch)
treec92cfb77f76f7fd422f7efefcc8468526384af17 /docs/gameinput.md
parente76cabc17a7400d6ab73da0e2689554b182df52a (diff)
parent012b79a6787cd47d31dcf023eb2b67a1eac6d77f (diff)
Merge remote-tracking branch 'origin/main' into reprise-1837
Diffstat (limited to 'docs/gameinput.md')
-rw-r--r--docs/gameinput.md290
1 files changed, 268 insertions, 22 deletions
diff --git a/docs/gameinput.md b/docs/gameinput.md
index feed39153..1819f0543 100644
--- a/docs/gameinput.md
+++ b/docs/gameinput.md
@@ -37,14 +37,57 @@ SDL3 is available in one of these ways:
37- **A local copy of that tarball**: extract it and pass `-DFETCHCONTENT_SOURCE_DIR_SDL3=<path to SDL3-3.4.20>`; it is 37- **A local copy of that tarball**: extract it and pass `-DFETCHCONTENT_SOURCE_DIR_SDL3=<path to SDL3-3.4.20>`; it is
38 built the same way, without a download. 38 built the same way, without a download.
39 39
40Without any of these, or with `-DLEONIDA_SDL3=OFF`, configure prints a message and `gta6rt` is built without the shim: 40Without any of these, or with `-DLEONIDA_SDL3=OFF`, configure prints a message and `gta6rt` is built without the SDL3
41it has no `GameInputCreate`, as before, so the loader binds it to the host's `GameInput.dll` or the unimplemented 41shim. It links `runtime/shims/gameinput_no_sdl.cpp` instead, which still serves `GameInputCreate` (by name and as
42thunk. `gameinput_test` and `gameinput_probe` are not built, and CTest lists `gameinput` as not run (disabled) rather 42`gameinput.dll!#1`): with no devices, or with `LEONIDA_INPUT_SCRIPT` set with one scripted pad (see
43than failing. 43[Scripted input without SDL3](#scripted-input-without-sdl3)). `gameinput_test` and `gameinput_probe` are not built,
44and CTest lists `gameinput` and `gameinput_script` as not run (disabled) rather than failing; `gameinput_no_sdl` and
45`gameinput_no_sdl_script` run instead.
46
47### Scripted input without SDL3
48
49The Windows artifacts of CI and offline builds have no SDL3. Without a device, the title waits at its first "press A"
50prompt forever, so no headless or CI run could get past it. With `LEONIDA_INPUT_SCRIPT` set, such a build serves one
51scripted pad, driven by the script alone:
52
53- **The device:** an Xbox One gamepad named `Scripted pad (Leonida)`, connected from the first `GameInputCreate`. It
54 is reported by `RegisterDeviceCallback` enumeration (blocking on the caller's thread, async from a thread of the
55 shim, or through `IGameInputDispatcher::Dispatch` once the title made a dispatcher) and found by `FindDeviceFromId`.
56 It is already connected, so a callback registered without enumeration hears nothing.
57- **The readings:** `GetCurrentReading`, `GetNextReading` and `GetPreviousReading`, with gamepad, UI navigation,
58 controller axis and controller button state. A reading is taken when the title asks for one, so no thread polls,
59 but it first adds one reading for every change the script made since the last, stamped with the script's own time:
60 a press that starts and ends between two reads of the title is still in the history, where `GetNextReading` finds
61 it, and the readings are the same however often the title reads. The history keeps the last 64 readings.
62- **The timeline:** the same as with SDL3 (`runtime/shims/gameinput_script.h` holds the parser, the timeline and the
63 log lines for both): seconds from the first `GameInputCreate`, each press held 300 ms (or its own `:hold`, see
64 `LEONIDA_INPUT_SCRIPT` below), then released.
65- **Not served:** reading callbacks, aggregate devices, rumble and every other device. Those slots answer `E_NOTIMPL`
66 and log the slot once. Controllers and the [keyboard pad](#keyboard-pad) still need SDL3.
67
68The start of the run logs one line with the counts, and each press logs the same lines as with SDL3:
69
70```text
71[rt] gameinput: served without SDL3: one scripted pad for LEONIDA_INPUT_SCRIPT (3 scripted press(es), 0 rejected); controllers and the keyboard pad need SDL3
72[rt] gameinput: scripted press of button 0 at 40.0 s
73[rt] gameinput: press a@40.0 (Scripted pad (Leonida))
74```
75
76A press is logged at the next reading the title asks for, with the script's time of the press, so a press is logged
77once the title reads its pad again. `LEONIDA_INPUT_LOG=0` turns the `press` lines off. `LEONIDA_INPUT_TRACE=1`
78(diagnostic, this shim only) logs what the title asks for: the first 128 `GetCurrentReading`, `GetNextReading` and
79`GetPreviousReading` calls, then every one that returns a pressed button and every 1000th, the device callbacks and
80`RegisterDeviceCallback` calls, and the first few calls of each reading method. Without `LEONIDA_INPUT_SCRIPT`, the shim serves no devices and answers `E_NOTIMPL` for
81every slot past `Release`, as before.
82
83`LEONIDA_INPUT_FILE=<path>` drives a run whose display takes no keyboard input (a headless session): every line
84appended to that file names one button of the script's table (`a`, `down`, ...) and becomes a press at once, held
85like a scripted one. The file is read again at most every 250 ms. It is for local runs only.
44 86
45`scripts/build_runtime.ps1` (what `make_game.py` runs) builds the shim only on its CMake path, when Visual Studio's 87`scripts/build_runtime.ps1` (what `make_game.py` runs) builds the shim only on its CMake path, when Visual Studio's
46C++ CMake tools are installed. Its direct-`cl.exe` fallback compiles a fixed file list without the shim and warns 88C++ CMake tools are installed. Its direct-`cl.exe` fallback compiles a fixed file list without the shim and warns
47about it. 89about it. `make_game.py`'s runtime stage on Windows runs it with `-FetchSdl3`, so a build made the usual way has
90controller, keyboard and mouse input; `--no-sdl3` leaves the download out (an installed SDL3 is still used).
48 91
49## Mapping 92## Mapping
50 93
@@ -77,11 +120,14 @@ controller-button array (`GetControllerButtonState`, indexed in SDL's `SDL_Gamep
77 120
78## Keyboard pad 121## Keyboard pad
79 122
80The title reads gamepads only, so keyboard input has to arrive as a gamepad. With `LEONIDA_KEYBOARD_PAD` set, the 123The title reads gamepads only, so keyboard input has to arrive as a gamepad. The shim attaches one SDL virtual
81shim attaches one SDL virtual gamepad named `Keyboard pad (Leonida)` and presses its buttons from the keyboard on 124gamepad named `Keyboard pad (Leonida)` and presses its buttons from the keyboard on every poll. It then goes
82every poll. It then goes through the same path as a real pad: a device object, the next free player slot, readings, 125through the same path as a real pad: a device object, the next free player slot, readings, reading and device
83reading and device callbacks, and UI navigation derived from its buttons. It reports no rumble motors. It is off by 126callbacks, and UI navigation derived from its buttons. It reports no rumble motors. It is on by default in the
84default. 127focused mode, so a player without a pad can still play; `LEONIDA_KEYBOARD_PAD=off` removes it.
128
129If SDL fails to attach or open the keyboard pad, the shim retries after one second while the pad is
130enabled. Only the first failure in a continuous series is logged; turning the pad off and back on retries immediately.
85 131
86| key | button | 132| key | button |
87|---|---| 133|---|---|
@@ -120,13 +166,16 @@ sensor, about a pixel at Windows' default pointer speed without acceleration, so
120 166
121With raw input on and a window of this process in the foreground, the cursor is kept inside that window's client 167With raw input on and a window of this process in the foreground, the cursor is kept inside that window's client
122area (`ClipCursor`, re-applied every 100 ms) so that a click cannot land on another window; it is released when focus 168area (`ClipCursor`, re-applied every 100 ms) so that a click cannot land on another window; it is released when focus
123moves away or the keyboard pad is turned off. The cursor stays visible: hiding it has to happen on the thread that 169moves away or the keyboard pad is turned off. It is also released while the window is moved or sized, while a
170menu loop runs, and while a mouse press that began outside the client area (on the title bar or a border) is held, so
171the window can still be dragged; it comes back once the button is released. The cursor stays visible: hiding it has to happen on the thread that
124owns the game's window, which is the title's, not the shim's. 172owns the game's window, which is the title's, not the shim's.
125 173
126Keys are read with `GetAsyncKeyState`, which needs no window or message loop (SDL's keyboard is part of its video 174Keys are read with `GetAsyncKeyState`, which needs no window or message loop (SDL's keyboard is part of its video
127subsystem, which this build leaves out) and works under Wine. With `LEONIDA_KEYBOARD_PAD=1` keys count only while a 175subsystem, which this build leaves out) and works under Wine. By default (or with `LEONIDA_KEYBOARD_PAD=1`), keys
128window of this process is in the foreground. Losing focus releases keyboard and mouse input. The cursor is read 176count only while a window of this process is in the foreground. Losing focus releases keyboard and mouse input.
129afresh on return so the right stick does not jump. Scripted presses run with or without focus for unattended runs. 177The cursor is read afresh on return so the right stick does not jump. Scripted presses run with or without focus
178for unattended runs.
130`LEONIDA_KEYBOARD_PAD=always` reads physical input whatever has focus; a console tool such as 179`LEONIDA_KEYBOARD_PAD=always` reads physical input whatever has focus; a console tool such as
131 `gameinput_probe` needs it, because its console window belongs to the terminal, not to the tool. 180 `gameinput_probe` needs it, because its console window belongs to the terminal, not to the tool.
132- Force feedback and haptics run through a fake haptic backend (`rt::gameinput::set_haptic_source`), because SDL's 181- Force feedback and haptics run through a fake haptic backend (`rt::gameinput::set_haptic_source`), because SDL's
@@ -141,6 +190,189 @@ afresh on return so the right stick does not jump. Scripted presses run with or
141 190
142To try it by hand: `set LEONIDA_KEYBOARD_PAD=always`, then `gameinput_probe --seconds 20` and press keys. 191To try it by hand: `set LEONIDA_KEYBOARD_PAD=always`, then `gameinput_probe --seconds 20` and press keys.
143 192
193## The keyboard-and-mouse pad of the D3D12 runtime
194
195The D3D12 runtime (`d3d12/`) has its own GameInput module (`d3d12/crates/leonida-hle/src/modules/gameinput.rs`)
196with a stand-in pad made from the keyboard and mouse, present while no host pad is connected (or beside one, with
197`LEONIDA_ONE_PAD`, the default). Keys and mouse buttons count only while a window of the runtime has focus.
198
199### Grand Theft Auto V's layout: one table on foot, one in a vehicle
200
201The title reads a pad only, and on a pad one button is two actions: the right trigger shoots on foot and accelerates
202in a vehicle, the left trigger aims and brakes. One table of keys cannot be a PC layout then, so there are two
203(`gameinput/kbm.rs`), and the stand-in pad uses the one of what the player is in. The keys are Grand Theft Auto V's
204PC defaults (its key bindings as listed in BisectHosting's "GTA V controls guide" and on StrategyWiki's controls
205page). The pad button of each action is the title's default pad layout as far as it is known: the table below is the
206one that came with the PC prompt glyphs (a contributor's notes on the Xbox layout), not measured here.
207
208| pad | on foot | in a vehicle |
209|---|---|---|
210| left stick, click | move, run | steer (lean on a bike), horn |
211| right stick, click | camera, look behind (zoom while aiming) | camera, look behind |
212| A / B / X / Y | jump and climb / crouch / melee and reload / interact, enter a vehicle | handbrake / duck, headlights / not known / leave the vehicle |
213| LB / RB | loadout wheel, holster / cover | loadout wheel / shoot from the vehicle |
214| LT / RT | aim / shoot | brake and reverse / accelerate |
215| d-pad up, down, left, right | phone, HUD and objective, radio menu, partner menu | the same |
216| Menu / View | pause / map | the same |
217
218| key | on foot | in a vehicle |
219|---|---|---|
220| W, S | left stick up, down: move | RT, LT (fully): accelerate, brake and reverse |
221| A, D | left stick left, right: move | the same: steer |
222| mouse | right stick: camera (mouse look, below) | the same |
223| left mouse button | RT: shoot | RB: shoot from the vehicle |
224| right mouse button | LT: aim | nothing (the button that aims from a vehicle is not known) |
225| Space | A: jump, climb | A: handbrake |
226| Left Shift | left stick click: run | left stick up: lean forward on a bike, nose down in an aircraft |
227| Left Ctrl | B: crouch (GTA V's stealth) | left stick down: lean back, nose up |
228| Num 8, Num 5, Num 4, Num 6 | nothing | left stick up, down, left, right (GTA V's aircraft keys) |
229| Q | RB: cover | d-pad left: radio menu (GTA V's radio wheel) |
230| E | Y: interact (GTA V's context action) | left stick click: horn |
231| F | Y: enter a vehicle | Y: leave it |
232| R | X: reload, melee | X (the same button; GTA V's cinematic camera has none known) |
233| X, H | nothing | B: duck, headlights |
234| Tab | LB: loadout wheel (hold), holster | LB |
235| C | right stick click: look behind | the same |
236| M | View: map | the same |
237| Esc, P | Menu: pause | the same |
238| arrows | d-pad: phone (up) and its menus | the same |
239| Enter, Backspace | A, B: accept and back in the phone and menus | the same |
240| Z | d-pad down: HUD and objective (GTA V's radar zoom, the same press on its pad) | the same |
241| Y; I J K L | Y; right stick (kept from the layout before; GTA V has nothing on them on foot) | the same |
242
243GTA V keys left without a binding, because the title's pad button for the action is not known: V (camera view), G
244(grenade; landing gear), O (heavy melee), the number keys (weapon slots), `[` `]` `,` `.` `=` `-` (zoom, radio), T, B,
245N, the F keys (character switch), Insert, Page Up and Page Down, the middle mouse button, and Caps Lock (GTA V's
246special ability), which is the switch described below. Left Alt (GTA V's character switch) would be the partner
247menu, d-pad right, and is left out because every Alt+Tab would press it; the right arrow is that button. For the
248same reason Tab, Enter, Space and Esc give nothing while an Alt key is down. The mouse wheel (GTA V's next and previous weapon, and zoom
249while aiming) is not bound either: the pad has no button known for the next weapon, and the host source polls key
250states (`GetAsyncKeyState`), which a wheel does not have; it would have to be counted from `WM_MOUSEWHEEL` in the
251window procedure of `lifecycle.rs`. The layout before had Z and V as the triggers, X as X, H as a second right stick
252click and Left Ctrl as a second left stick click; those went where GTA V has another meaning for the key.
253`LEONIDA_KBM=classic` brings the table of before back whole (`FALLBACK_BUTTONS`: W A S D and I J K L the sticks,
254Space or Enter A, R or Backspace B, X, F or Y, Q and E the shoulders, Left Shift or Left Ctrl and C or H the stick
255clicks, Z or the right mouse button LT, V or the left mouse button RT, Esc Menu, Tab View).
256
257In an aircraft A and D are the left stick (roll), not GTA V's rudder: only "in a vehicle" is known, not which kind.
258
259### Which table counts
260
261`gameinput::set_player_context(OnFoot | InVehicle | Unknown)` tells the stand-in pad, lock-free from any thread; a
262context that is not set again for 500 ms is unknown (and the pad only lets go of a known one after 100 ms of
263unknown). Unknown is the on-foot table, and then **Caps Lock** switches to the driving table and back by hand, with a
264line in the log at every change of table; driving by hand also ends when F (leave the vehicle) is pressed, so that W
265cannot stay the right trigger on foot. While a context is measured Caps Lock does nothing: it is GTA V's special
266ability key, and a press out of habit on foot must not make W a shot. `gameinput::driving_controls()` says which
267table is in use (for whoever draws key prompts).
268
269**The hand-over** when the table changes: a key that is another pad input in the other table (W, S, the mouse buttons,
270Left Shift, Left Ctrl, Q, E, X, H) and is down at that moment gives nothing until it has been let go and pressed
271again, and no such key gives anything for 400 ms after the change (`LEONIDA_KBM_SETTLE_MS`, 0 to 3000). So the left
272mouse button held on foot never becomes the accelerator and W held in a car never becomes a shot; the price is that W
273held while getting in has to be pressed again to drive off. Keys that are the same pad input in both tables (A, D,
274Space, F, ...) carry over as a real pad's button would. Unit-tested over every set of held keys in both directions
275(`cargo test -p leonida-hle gameinput`).
276
277**Who tells.** `d3d12/apps/leonida/src/player_context.rs` reads the title every 16 ms from a thread of its own
278(`ReadProcessMemory` on the own process: nothing is written and no title code is called, so it does not need
279`LEONIDA_GAME_ACTIONS=1`; without the game actions it looks the two globals up itself at start, two more passes over
280the image's code, about 0.15 s together on the retail executable's 99.9 MB of code). It tells `Unknown` while there is no player ped, and a change counts after three equal reads. What
281says "in a vehicle" is, in this order:
282
2831. `LEONIDA_PED_VEHICLE_AT=0x<offset>`: a field of the player's ped that points at its vehicle and is null on foot.
284 None is known (see below why there may be none), so this is unset by default.
2852. The title's own global of the player's vehicle (`Site::PlayerVehicle` in `leonida-loader/src/game_actions.rs`,
286 found by a pattern that is in the 1.0.2.1 executable once; `LEONIDA_PLAYER_VEHICLE_AT=0x<offset in the image>`
287 names another, `=off` turns it off). **Read from the code, not yet seen in the running title:**
288 - The title keeps what belongs to a ped apart from the ped's entity, in tables looked up by the entity's id
289 (`+9Ch`; a ped's id has `60000h` under the mask `3E0000h`, its index is the low 17 bits, and a 16-bit slot of
290 `FFFFh` means "none"). Its "the vehicle this ped is in" (the function at `4DD7510h`) takes column `47h` of
291 those tables and gives the pointer at `+898h` of it when bit `20h` of the byte at `+10h` is set, else null: the
292 shape of GTA V's `GetVehiclePedInside`, a "my vehicle" pointer that outlives the ride plus a flag. That is why a
293 pointer in the ped that is null on foot may not exist at all.
294 - The global at `AB760C8h` is written by one function (`CA4DE0h`), which has three callers: one passes a
295 vehicle (in a function of 129Fh bytes, taken to be where a ped is put in a vehicle), one passes null after
296 testing that the ped's id is the player's (taken to be where a ped is taken out), and the function that sets
297 the player's ped passes what `4DD7510h` gives for the new ped. The first two are methods of that same column
298 `47h` record: the first begins by reading its `+10h` and `+898h` and testing bit `20h`, the second tests
299 other bits beside it (`+12h`). 167 places in the code read the global; the vehicle cheats read a type byte
300 at `+FAh` of what it points at.
301 - Not known until it has run: that it is null in every on-foot state (after a crash through the windscreen, a
302 vehicle that blows up, a cutscene), and when during getting in and out it changes compared with the title's own
303 switch of its controls. The reader logs every change with its time, and warns when the ped moves at 12 m/s for
304 a second while it says "on foot", or the vehicle is 60 m from the ped while it says "in a vehicle".
3053. `LEONIDA_KBM_SPEED=1`: the speed rule. From the ped's position (taken every 0.2 s): 12 m/s (43 km/h; a sprint is
306 about 7) or more for a second without a break is "in a vehicle", until 3 s have passed below that speed; a fall
307 (more down than along) and a jump of the position (a teleport, a respawn) do not count. Its limits are why it is
308 off unless asked for: it never says "on foot" (a car at a red light and a ped standing are the same to it), it
309 cannot see a drive begin, so it never switches from a standstill and the first metres of every drive are on the
310 on-foot keys, and so the meaning of W and of the mouse buttons would change in the middle of a drive, at every
311 stop. It always runs as the check named above.
312
313With none of the three the context stays unknown: the on-foot table, and Caps Lock.
314
315| switch | effect |
316|---|---|
317| `LEONIDA_KBM=classic` | the single table of before; nothing reads the title |
318| `LEONIDA_KBM_DRIVE=on` / `off` / `auto` | forces the driving table on or off (a test; nothing reads the title and Caps Lock does nothing then); `auto` is the default |
319| `LEONIDA_KBM_SETTLE_MS=<ms>` | the pause after a change of table, 400 |
320| `LEONIDA_PED_VEHICLE_AT`, `LEONIDA_PLAYER_VEHICLE_AT`, `LEONIDA_KBM_SPEED` | what says "in a vehicle", above |
321| `LEONIDA_PED_DUMP=<folder>` | for measuring: F8 in the game's window, or a file named `dump` in that folder (its text is the label), writes the first 4000h bytes of the player's ped to `ped-<date>-<time>-<label>.bin`, the first 1000h of the vehicle the global names to `vehicle-...bin`, and a line to `index.txt` (time, addresses, the ped's id, position, speed, what was read). The folder must be outside the repository; the files are the title's memory and are never committed. |
322
323The mouse buttons are not passed to the title while the F1 settings menu or the F4 trainer menu is open, and they
324never reach the title as keyboard keys.
325
326**Mouse look (D3D12 runtime).** The console title turns its camera with the right stick only; it does not read the
327mouse for that. A left click in the game window makes the window hold the mouse: the cursor is hidden and kept in the
328window, and the mouse's motion becomes a right-stick push (`MouseLook` in `d3d12/crates/leonida-hle/src/modules/
329gameinput.rs`): its speed over the last 40 ms, a full push at 1600 pixels a second, lifted past a 0.24 dead zone with a
3300.6 power curve, merged with the pad's own stick. That click is not a shot; the mouse buttons reach the title as
331triggers only while the window holds the mouse. Esc (which also pauses), the F1 or F4 menu, or another window in front
332gives the mouse back. Settings: `LEONIDA_MOUSE_SENSITIVITY` (1, 0.1..10), `LEONIDA_MOUSE_INVERT_Y=1`,
333`LEONIDA_MOUSE_DEADZONE` (0.24), `LEONIDA_MOUSE_CURVE` (0.6), `LEONIDA_MOUSE_LOOK=0` (off: the old behaviour, buttons
334whenever the window has focus). Unit-tested (`mouse_look_turns_speed_into_a_stick_past_the_dead_zone`); the dead zone
335and curve are first guesses at the title's own stick response, not measured.
336
337## PlayStation pads and the active input of the D3D12 runtime
338
339The D3D12 runtime has no SDL. Besides XInput it reads Sony pads (vendor `054C`: DualSense `0CE6`, DualSense Edge `0DF2`,
340DualShock 4 `05C4`, `09CC`, USB adapter `0BA0`) over Windows HID directly (`gameinput/hid.rs`), on USB and Bluetooth,
341written from the public report layouts (the Linux `hid-playstation` driver documents them). One thread per pad reads
342input reports; a rescan every 2 s finds pads that came or went. A Bluetooth pad is moved to its full report by reading
343calibration feature report `0x05`.
344
345| | USB input | Bluetooth input | USB output | Bluetooth output |
346|---|---|---|---|---|
347| DualSense | `0x01`, 64 bytes, data from byte 1 | `0x31`, 78 bytes, data from byte 2 | `0x02`, 63 | `0x31`, 78, CRC-32 last |
348| DualShock 4 | `0x01`, 64 bytes, data from byte 1 | `0x11`, data from byte 3 | `0x05`, 32 | `0x11`, 78, CRC-32 last |
349
350Buttons: Cross, Circle, Square, Triangle are A, B, X, Y; L1/R1 the shoulders; L2/R2 the triggers (analog byte, the
351digital bit is ignored); L3/R3 the stick clicks; Options is Menu; Create (Share) and the touchpad click are View;
352the PS and mute buttons are not passed. Sticks are 0..255, centre 128. Rumble: the big motor of the title's
353`SetRumbleState` goes to the pad's left motor, the small one to its right (`rumble_report`; on Bluetooth the CRC is
354seeded with `0xA2`). Trigger effects and the lightbar are not driven. A Sony pad takes the first slot XInput leaves
355empty (all pads are one pad for the title anyway, `LEONIDA_ONE_PAD`).
356
357A pad that Steam Input or DS4Windows already shows through XInput is not read twice: when input comes on an XInput pad and
358on a readable Sony pad within 150 ms of each other, they are one controller for the next 10 s, and the Sony pad's own
359reading is left out of what the title sees. A Sony pad present but not openable (hidden by HidHide, held exclusively)
360counts the same way: input on XInput is then PlayStation input.
361
362**Active input.** `gameinput::active_family()` (`leonida-hle`, readable from any thread, lock-free) says which kind of
363device was used last: `Family::Xbox`, `Family::PlayStation` or `Family::KeyboardMouse`; `family_generation()` goes up by one
364with each change. It follows the rules of [Active input](#active-input) above (an edge counts, the first reading of a
365device is its baseline), with the keyboard and mouse as a third family (a key going down, or mouse look pushing the
366stick past 0.35). A switch is immediate: the first deliberate input of another family changes the answer, however long
367the one before was in use; only the change after that one waits, `LEONIDA_PROMPTS_SWITCH_MS` = 300 ms from the switch,
368so two devices used at once change it at most about three times a second. Before the first input it is what is
369connected when the runtime first looks: PlayStation with a Sony pad, Xbox with any other pad, the keyboard and mouse
370with no pad at all (a wireless pad still asleep counts as none: `LEONIDA_PROMPTS=xbox` is the way round it). One line
371is logged on each change (`input in use: PlayStation (Sony pad input)`).
372`LEONIDA_PROMPTS=xbox|playstation|keyboard|auto` forces it. The button prompts follow it at the title's one read of its
373glyph movie: see [prompt_glyphs.md](prompt_glyphs.md). Unit-tested on hand-made report bytes and the family rules; not
374run against a real pad yet.
375
144## Rumble and triggers 376## Rumble and triggers
145 377
146`IGameInputDevice::SetRumbleState` takes four motor levels, 0..1. The two body motors go to `SDL_RumbleGamepad` on 378`IGameInputDevice::SetRumbleState` takes four motor levels, 0..1. The two body motors go to `SDL_RumbleGamepad` on
@@ -301,8 +533,8 @@ line is logged when it takes effect); tracking goes on underneath, so clearing i
301| `LEONIDA_PROMPTS` | `auto` | forces the [active input](#active-input) family: `xbox`, `playstation` (or `ps5`), `ps4`, `ps3`, `nintendo` or `keyboard`; `auto` follows the devices | 533| `LEONIDA_PROMPTS` | `auto` | forces the [active input](#active-input) family: `xbox`, `playstation` (or `ps5`), `ps4`, `ps3`, `nintendo` or `keyboard`; `auto` follows the devices |
302| `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms | 534| `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms |
303| `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | 535| `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) |
304| `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus | 536| `LEONIDA_KEYBOARD_PAD` | `1` | the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus; `off` removes it |
305| `LEONIDA_INPUT_SCRIPT` | unset | With the keyboard pad enabled, set comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. The first pad update reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons and invalid times (including negative or non-finite values) are counted and ignored. | 537| `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad (on unless `LEONIDA_KEYBOARD_PAD=off`); without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms, or `hold` seconds when the entry is `button@seconds:hold` (more than 0, at most 600). With SDL3 a press then stays down until the title has read the pads six times since it began, but never past 5 s from its start (or its hold, if longer). A title reads its pad once a frame, so at a few seconds a frame a 300 ms press can fall between two reads and never arrive: on the retail title's "Couldn't autosave" prompt, three 300 ms `b` presses did nothing, while 120 presses 0.5 s apart got through; one `b@1100:3` replaces them. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons, invalid times (including negative or non-finite values) and invalid holds (0 or less, more than 600, not a number) are counted and ignored. |
306| `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 | 538| `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 |
307 539
308SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to 540SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to
@@ -318,7 +550,11 @@ button) run on that thread, as GameInput runs them on its own threads. Once the
318`IGameInputDispatcher::Dispatch` runs them on the title's thread, oldest first, within its quota: at least one queued 550`IGameInputDispatcher::Dispatch` runs them on the title's thread, oldest first, within its quota: at least one queued
319event per call (a quota of 0 runs exactly one), no further event once the quota has passed, and only the events 551event per call (a quota of 0 runs exactly one), no further event once the quota has passed, and only the events
320queued when the call started (later ones wait for the next call, so even an unlimited quota returns). The wait 552queued when the call started (later ones wait for the next call, so even an unlimited quota returns). The wait
321handle is signalled again while events remain. 553handle is signalled again while events remain. An event is queued only when a registered callback wants it (a
554reading with no reading callback, say, is no work), so readings nobody hears cannot build a backlog that a title
555running one item a frame (`Dispatch(0)`) never catches up on, with a later pad's connect event stuck behind it. The
556first few `RegisterDeviceCallback` calls (filter, kind, status filter, enumeration) and the first `CreateDispatcher`
557and `Dispatch` calls are logged, since they decide how the title hears of a pad plugged in after start.
322 558
323The API surface: 559The API surface:
324 560
@@ -407,8 +643,10 @@ holds stays valid after it leaves the history.
407| nothing newer, or nothing older after the horizon | `GAMEINPUT_E_READING_NOT_FOUND` | 643| nothing newer, or nothing older after the horizon | `GAMEINPUT_E_READING_NOT_FOUND` |
408 644
409After a pad is plugged back in, its last reading before the unplug leads to the reconnect snapshot, older ones are 645After a pad is plugged back in, its last reading before the unplug leads to the reconnect snapshot, older ones are
410`REFERENCE_READING_TOO_OLD`, and sequence numbers carry on. Timestamps are poll times, so a change shorter than one poll 646`REFERENCE_READING_TOO_OLD`, and sequence numbers carry on. Each poll drains SDL's gamepad button and axis events.
411(2 ms with the thread) is not seen. 647For each connected pad, events with the same SDL timestamp form one sample. Intermediate samples reach the history
648and reading or Guide callbacks, while the final reading uses the current pad snapshot. GameInput timestamps still
649record when the shim polled. A short press is recoverable when the SDL backend reports its two edges with distinct timestamps.
412 650
413### Device identity 651### Device identity
414 652
@@ -457,11 +695,19 @@ rests on a transcription rather than on a side-by-side compile.
457 button, the touchpad, a trigger or a stick, stick drift and a one-count mouse jitter ignored, a real mouse movement 695 button, the touchpad, a trigger or a stick, stick drift and a one-count mouse jitter ignored, a real mouse movement
458 counted, the 300 ms window on the real clock, and `LEONIDA_PROMPTS` forcing, changing, ignoring an unknown value 696 counted, the 300 ms window on the real clock, and `LEONIDA_PROMPTS` forcing, changing, ignoring an unknown value
459 and clearing. 697 and clearing.
698- `gameinput_no_sdl_test` (CTest, only in a build without SDL3, no controller): `gameinput_no_sdl` checks the
699 identity-only object (both names served, `AddRef`/`Release`, `E_NOTIMPL` without touching the out-parameter).
700 `gameinput_no_sdl_script` sets `LEONIDA_INPUT_SCRIPT` with overlapping presses, a mixed-case name, `rsup` and three
701 rejected entries, puts the shim on a fake clock and checks the scripted pad: blocking, async and dispatcher
702 enumeration (and none without enumeration, for another status or another kind), the device info, `FindDeviceFromId`,
703 the buttons, UI navigation and right stick read at chosen times (held for 0.3 s, a later press of the same button
704 not cut short, nothing after the script), no new reading without a change, `GetPreviousReading` and
705 `GetNextReading`, no motion, and reading callbacks answering `E_NOTIMPL`.
460- `gameinput_test` (CTest, no controller): turns SDL's real backends off and drives the shim through 706- `gameinput_test` (CTest, no controller): turns SDL's real backends off and drives the shim through
461 `rt::shims::find` with SDL virtual joysticks, an Xbox-style pad with trigger motors, a DualSense (Sony 707 `rt::shims::find` with SDL virtual joysticks, an Xbox-style pad with trigger motors, a DualSense (Sony
462 `054c:0ce6`) and a pad without trigger motors. It checks enumeration and device callbacks, the button, stick, 708 `054c:0ce6`) and a pad without trigger motors. It checks enumeration and device callbacks, the button, stick,
463 trigger and UI-navigation mapping, reading callbacks and sequence numbers, the reading history (a tap read after 709 trigger and UI-navigation mapping, reading callbacks and sequence numbers, the reading history (a button and trigger
464 the fact, both directions, two pads interleaved and filtered by device, ageing out, held readings, unplug and 710 tapped between two shim polls, both directions, two pads interleaved and filtered by device, ageing out, held readings, unplug and
465 replug), the guide button, motor and trigger 711 replug), the guide button, motor and trigger
466 rumble as SDL receives them, the DualSense effect bytes in each `LEONIDA_DS_TRIGGERS` mode, the lightbar, a 712 rumble as SDL receives them, the DualSense effect bytes in each `LEONIDA_DS_TRIGGERS` mode, the lightbar, a
467 dispatcher and its quota, async and blocking enumeration, unregistering, unplugging and replugging, and three identical pads 713 dispatcher and its quota, async and blocking enumeration, unregistering, unplugging and replugging, and three identical pads
@@ -511,7 +757,7 @@ These need the game executable or a test on hardware:
511 built against one of those, the vtables need a second set. 757 built against one of those, the vtables need a second set.
512- **IIDs.** `QueryInterface` answers the v0 IIDs from the public header. 758- **IIDs.** `QueryInterface` answers the v0 IIDs from the public header.
513- **Reading history.** Microsoft's [next reading](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getnextreading) 759- **Reading history.** Microsoft's [next reading](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getnextreading)
514 and [previous reading](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getpreviousreading) pages describe half a second of readings per device and failure when old readings leave the stream. The table above records the shim's HRESULT choices. Changes faster than the poll are not seen. 760 and [previous reading](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getpreviousreading) pages describe half a second of readings per device and failure when old readings leave the stream. The table above records the shim's HRESULT choices.
515 `GetTemporalReading` returns `E_NOTIMPL` with a null reading on purpose: Microsoft's 761 `GetTemporalReading` returns `E_NOTIMPL` with a null reading on purpose: Microsoft's
516 [reference page](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/deprecated/interfaces/igameinput/methods/igameinput_gettemporalreading) 762 [reference page](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/deprecated/interfaces/igameinput/methods/igameinput_gettemporalreading)
517 says it "was never implemented in v0" and returns `E_NOTIMPL`, and v1 removed it. The v0 header (NuGet 763 says it "was never implemented in v0" and returns `E_NOTIMPL`, and v1 removed it. The v0 header (NuGet