upleb.uk

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

summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorNotRexed <therealnothingfn@gmail.com>2026-11-27 18:06:59 -0500
committerNotRexed <therealnothingfn@gmail.com>2026-11-27 18:06:59 -0500
commit0d8fcf4a030d945f119fb9cf08c38d38f70d46ef (patch)
tree66973a5a2b9090fa64a78e5f766278ac89c5712b /docs
parent34025b5be60d74a8529212cabf223b1b5c1ff252 (diff)
parentf33c963a5c2e905cd1d474c07418f5593619b1f4 (diff)
Merge remote-tracking branch 'old/port/kbm' into next
# Conflicts: # docs/gameinput.md
Diffstat (limited to 'docs')
-rw-r--r--docs/gameinput.md179
-rw-r--r--docs/mod-menu.md10
2 files changed, 185 insertions, 4 deletions
diff --git a/docs/gameinput.md b/docs/gameinput.md
index e0df71085..b5d6cc6f7 100644
--- a/docs/gameinput.md
+++ b/docs/gameinput.md
@@ -184,6 +184,185 @@ afresh on return so the right stick does not jump. Scripted presses run with or
184 184
185To try it by hand: `set LEONIDA_KEYBOARD_PAD=always`, then `gameinput_probe --seconds 20` and press keys. 185To try it by hand: `set LEONIDA_KEYBOARD_PAD=always`, then `gameinput_probe --seconds 20` and press keys.
186 186
187## The keyboard-and-mouse pad of the D3D12 runtime
188
189The D3D12 runtime (`d3d12/`) has its own GameInput module (`d3d12/crates/leonida-hle/src/modules/gameinput.rs`)
190with a stand-in pad made from the keyboard and mouse, present while no host pad is connected (or beside one, with
191`LEONIDA_ONE_PAD`, the default). Keys and mouse buttons count only while a window of the runtime has focus.
192
193### Grand Theft Auto V's layout: one table on foot, one in a vehicle
194
195The title reads a pad only, and on a pad one button is two actions: the right trigger shoots on foot and accelerates
196in a vehicle, the left trigger aims and brakes. One table of keys cannot be a PC layout then, so there are two
197(`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
198PC defaults (its key bindings as listed in BisectHosting's "GTA V controls guide" and on StrategyWiki's controls
199page). The pad button of each action is the title's default pad layout as far as it is known: the table below is the
200one that came with the PC prompt glyphs (a contributor's notes on the Xbox layout), not measured here.
201
202| pad | on foot | in a vehicle |
203|---|---|---|
204| left stick, click | move, run | steer (lean on a bike), horn |
205| right stick, click | camera, look behind (zoom while aiming) | camera, look behind |
206| A / B / X / Y | jump and climb / crouch / melee and reload / interact, enter a vehicle | handbrake / duck, headlights / not known / leave the vehicle |
207| LB / RB | loadout wheel, holster / cover | loadout wheel / shoot from the vehicle |
208| LT / RT | aim / shoot | brake and reverse / accelerate |
209| d-pad up, down, left, right | phone, HUD and objective, radio menu, partner menu | the same |
210| Menu / View | pause / map | the same |
211
212| key | on foot | in a vehicle |
213|---|---|---|
214| W, S | left stick up, down: move | RT, LT (fully): accelerate, brake and reverse |
215| A, D | left stick left, right: move | the same: steer |
216| mouse | right stick: camera (mouse look, below) | the same |
217| left mouse button | RT: shoot | RB: shoot from the vehicle |
218| right mouse button | LT: aim | nothing (the button that aims from a vehicle is not known) |
219| Space | A: jump, climb | A: handbrake |
220| Left Shift | left stick click: run | left stick up: lean forward on a bike, nose down in an aircraft |
221| Left Ctrl | B: crouch (GTA V's stealth) | left stick down: lean back, nose up |
222| Num 8, Num 5, Num 4, Num 6 | nothing | left stick up, down, left, right (GTA V's aircraft keys) |
223| Q | RB: cover | d-pad left: radio menu (GTA V's radio wheel) |
224| E | Y: interact (GTA V's context action) | left stick click: horn |
225| F | Y: enter a vehicle | Y: leave it |
226| R | X: reload, melee | X (the same button; GTA V's cinematic camera has none known) |
227| X, H | nothing | B: duck, headlights |
228| Tab | LB: loadout wheel (hold), holster | LB |
229| C | right stick click: look behind | the same |
230| M | View: map | the same |
231| Esc, P | Menu: pause | the same |
232| arrows | d-pad: phone (up) and its menus | the same |
233| Enter, Backspace | A, B: accept and back in the phone and menus | the same |
234| Z | d-pad down: HUD and objective (GTA V's radar zoom, the same press on its pad) | the same |
235| Y; I J K L | Y; right stick (kept from the layout before; GTA V has nothing on them on foot) | the same |
236
237GTA V keys left without a binding, because the title's pad button for the action is not known: V (camera view), G
238(grenade; landing gear), O (heavy melee), the number keys (weapon slots), `[` `]` `,` `.` `=` `-` (zoom, radio), T, B,
239N, the F keys (character switch), Insert, Page Up and Page Down, the middle mouse button, and Caps Lock (GTA V's
240special ability), which is the switch described below. Left Alt (GTA V's character switch) would be the partner
241menu, d-pad right, and is left out because every Alt+Tab would press it; the right arrow is that button. For the
242same 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
243while aiming) is not bound either: the pad has no button known for the next weapon, and the host source polls key
244states (`GetAsyncKeyState`), which a wheel does not have; it would have to be counted from `WM_MOUSEWHEEL` in the
245window procedure of `lifecycle.rs`. The layout before had Z and V as the triggers, X as X, H as a second right stick
246click and Left Ctrl as a second left stick click; those went where GTA V has another meaning for the key.
247`LEONIDA_KBM=classic` brings the table of before back whole (`FALLBACK_BUTTONS`: W A S D and I J K L the sticks,
248Space 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
249clicks, Z or the right mouse button LT, V or the left mouse button RT, Esc Menu, Tab View).
250
251In an aircraft A and D are the left stick (roll), not GTA V's rudder: only "in a vehicle" is known, not which kind.
252
253### Which table counts
254
255`gameinput::set_player_context(OnFoot | InVehicle | Unknown)` tells the stand-in pad, lock-free from any thread; a
256context that is not set again for 500 ms is unknown (and the pad only lets go of a known one after 100 ms of
257unknown). Unknown is the on-foot table, and then **Caps Lock** switches to the driving table and back by hand, with a
258line in the log at every change of table; driving by hand also ends when F (leave the vehicle) is pressed, so that W
259cannot stay the right trigger on foot. While a context is measured Caps Lock does nothing: it is GTA V's special
260ability key, and a press out of habit on foot must not make W a shot. `gameinput::driving_controls()` says which
261table is in use (for whoever draws key prompts).
262
263**The hand-over** when the table changes: a key that is another pad input in the other table (W, S, the mouse buttons,
264Left Shift, Left Ctrl, Q, E, X, H) and is down at that moment gives nothing until it has been let go and pressed
265again, and no such key gives anything for 400 ms after the change (`LEONIDA_KBM_SETTLE_MS`, 0 to 3000). So the left
266mouse button held on foot never becomes the accelerator and W held in a car never becomes a shot; the price is that W
267held while getting in has to be pressed again to drive off. Keys that are the same pad input in both tables (A, D,
268Space, F, ...) carry over as a real pad's button would. Unit-tested over every set of held keys in both directions
269(`cargo test -p leonida-hle gameinput`).
270
271**Who tells.** `d3d12/apps/leonida/src/player_context.rs` reads the title every 16 ms from a thread of its own
272(`ReadProcessMemory` on the own process: nothing is written and no title code is called, so it does not need
273`LEONIDA_GAME_ACTIONS=1`; without the game actions it looks the two globals up itself at start, two more passes over
274the 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
275says "in a vehicle" is, in this order:
276
2771. `LEONIDA_PED_VEHICLE_AT=0x<offset>`: a field of the player's ped that points at its vehicle and is null on foot.
278 None is known (see below why there may be none), so this is unset by default.
2792. The title's own global of the player's vehicle (`Site::PlayerVehicle` in `leonida-loader/src/game_actions.rs`,
280 found by a pattern that is in the 1.0.2.1 executable once; `LEONIDA_PLAYER_VEHICLE_AT=0x<offset in the image>`
281 names another, `=off` turns it off). **Read from the code, not yet seen in the running title:**
282 - The title keeps what belongs to a ped apart from the ped's entity, in tables looked up by the entity's id
283 (`+9Ch`; a ped's id has `60000h` under the mask `3E0000h`, its index is the low 17 bits, and a 16-bit slot of
284 `FFFFh` means "none"). Its "the vehicle this ped is in" (the function at `4DD7510h`) takes column `47h` of
285 those tables and gives the pointer at `+898h` of it when bit `20h` of the byte at `+10h` is set, else null: the
286 shape of GTA V's `GetVehiclePedInside`, a "my vehicle" pointer that outlives the ride plus a flag. That is why a
287 pointer in the ped that is null on foot may not exist at all.
288 - The global at `AB760C8h` is written by one function (`CA4DE0h`), which has three callers: one passes a
289 vehicle (in a function of 129Fh bytes, taken to be where a ped is put in a vehicle), one passes null after
290 testing that the ped's id is the player's (taken to be where a ped is taken out), and the function that sets
291 the player's ped passes what `4DD7510h` gives for the new ped. The first two are methods of that same column
292 `47h` record: the first begins by reading its `+10h` and `+898h` and testing bit `20h`, the second tests
293 other bits beside it (`+12h`). 167 places in the code read the global; the vehicle cheats read a type byte
294 at `+FAh` of what it points at.
295 - Not known until it has run: that it is null in every on-foot state (after a crash through the windscreen, a
296 vehicle that blows up, a cutscene), and when during getting in and out it changes compared with the title's own
297 switch of its controls. The reader logs every change with its time, and warns when the ped moves at 12 m/s for
298 a second while it says "on foot", or the vehicle is 60 m from the ped while it says "in a vehicle".
2993. `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
300 about 7) or more for a second without a break is "in a vehicle", until 3 s have passed below that speed; a fall
301 (more down than along) and a jump of the position (a teleport, a respawn) do not count. Its limits are why it is
302 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
303 cannot see a drive begin, so it never switches from a standstill and the first metres of every drive are on the
304 on-foot keys, and so the meaning of W and of the mouse buttons would change in the middle of a drive, at every
305 stop. It always runs as the check named above.
306
307With none of the three the context stays unknown: the on-foot table, and Caps Lock.
308
309| switch | effect |
310|---|---|
311| `LEONIDA_KBM=classic` | the single table of before; nothing reads the title |
312| `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 |
313| `LEONIDA_KBM_SETTLE_MS=<ms>` | the pause after a change of table, 400 |
314| `LEONIDA_PED_VEHICLE_AT`, `LEONIDA_PLAYER_VEHICLE_AT`, `LEONIDA_KBM_SPEED` | what says "in a vehicle", above |
315| `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. |
316
317The mouse buttons are not passed to the title while the F1 settings menu or the F4 trainer menu is open, and they
318never reach the title as keyboard keys.
319
320**Mouse look (D3D12 runtime).** The console title turns its camera with the right stick only; it does not read the
321mouse for that. A left click in the game window makes the window hold the mouse: the cursor is hidden and kept in the
322window, and the mouse's motion becomes a right-stick push (`MouseLook` in `d3d12/crates/leonida-hle/src/modules/
323gameinput.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
3240.6 power curve, merged with the pad's own stick. That click is not a shot; the mouse buttons reach the title as
325triggers only while the window holds the mouse. Esc (which also pauses), the F1 or F4 menu, or another window in front
326gives the mouse back. Settings: `LEONIDA_MOUSE_SENSITIVITY` (1, 0.1..10), `LEONIDA_MOUSE_INVERT_Y=1`,
327`LEONIDA_MOUSE_DEADZONE` (0.24), `LEONIDA_MOUSE_CURVE` (0.6), `LEONIDA_MOUSE_LOOK=0` (off: the old behaviour, buttons
328whenever the window has focus). Unit-tested (`mouse_look_turns_speed_into_a_stick_past_the_dead_zone`); the dead zone
329and curve are first guesses at the title's own stick response, not measured.
330
331## PlayStation pads and the active input of the D3D12 runtime
332
333The D3D12 runtime has no SDL. Besides XInput it reads Sony pads (vendor `054C`: DualSense `0CE6`, DualSense Edge `0DF2`,
334DualShock 4 `05C4`, `09CC`, USB adapter `0BA0`) over Windows HID directly (`gameinput/hid.rs`), on USB and Bluetooth,
335written from the public report layouts (the Linux `hid-playstation` driver documents them). One thread per pad reads
336input reports; a rescan every 2 s finds pads that came or went. A Bluetooth pad is moved to its full report by reading
337calibration feature report `0x05`.
338
339| | USB input | Bluetooth input | USB output | Bluetooth output |
340|---|---|---|---|---|
341| DualSense | `0x01`, 64 bytes, data from byte 1 | `0x31`, 78 bytes, data from byte 2 | `0x02`, 63 | `0x31`, 78, CRC-32 last |
342| DualShock 4 | `0x01`, 64 bytes, data from byte 1 | `0x11`, data from byte 3 | `0x05`, 32 | `0x11`, 78, CRC-32 last |
343
344Buttons: Cross, Circle, Square, Triangle are A, B, X, Y; L1/R1 the shoulders; L2/R2 the triggers (analog byte, the
345digital bit is ignored); L3/R3 the stick clicks; Options is Menu; Create (Share) and the touchpad click are View;
346the PS and mute buttons are not passed. Sticks are 0..255, centre 128. Rumble: the big motor of the title's
347`SetRumbleState` goes to the pad's left motor, the small one to its right (`rumble_report`; on Bluetooth the CRC is
348seeded with `0xA2`). Trigger effects and the lightbar are not driven. A Sony pad takes the first slot XInput leaves
349empty (all pads are one pad for the title anyway, `LEONIDA_ONE_PAD`).
350
351A pad that Steam Input or DS4Windows already shows through XInput is not read twice: when input comes on an XInput pad and
352on 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
353reading is left out of what the title sees. A Sony pad present but not openable (hidden by HidHide, held exclusively)
354counts the same way: input on XInput is then PlayStation input.
355
356**Active input.** `gameinput::active_family()` (`leonida-hle`, readable from any thread, lock-free) says which kind of
357device was used last: `Family::Xbox`, `Family::PlayStation` or `Family::KeyboardMouse`; `family_generation()` goes up by one
358with each change. It follows the rules of [Active input](#active-input) above (an edge counts, the first reading of a
359device is its baseline, a change waits `LEONIDA_PROMPTS_SWITCH_MS` = 300 ms), with the keyboard and mouse as a third
360family (a key going down, or mouse look pushing the stick past 0.35). Before the first input it is PlayStation if a Sony pad is
361present and Xbox otherwise. One line is logged on each change (`input in use: PlayStation (Sony pad input)`).
362`LEONIDA_PROMPTS=xbox|playstation|keyboard|auto` forces it. The button prompts follow it: see
363[prompt_glyphs.md](prompt_glyphs.md). Unit-tested on hand-made report bytes and the family rules; not run against a
364real pad yet.
365
187## Rumble and triggers 366## Rumble and triggers
188 367
189`IGameInputDevice::SetRumbleState` takes four motor levels, 0..1. The two body motors go to `SDL_RumbleGamepad` on 368`IGameInputDevice::SetRumbleState` takes four motor levels, 0..1. The two body motors go to `SDL_RumbleGamepad` on
diff --git a/docs/mod-menu.md b/docs/mod-menu.md
index 064fa1390..18023dd0f 100644
--- a/docs/mod-menu.md
+++ b/docs/mod-menu.md
@@ -194,9 +194,11 @@ menu.
194 way). Our hook is the one 194 way). Our hook is the one
195 `call` of the cheat input function: it calls that function, then, if something was asked, gives the same queue 195 `call` of the cheat input function: it calls that function, then, if something was asked, gives the same queue
196 a closure of its own. So our work runs exactly where a cheat of the title's would. 196 a closure of its own. So our work runs exactly where a cheat of the title's would.
197- **Finding it again.** Ten places are named by patterns of 24 to 77 bytes (19 to 36 of them fixed, `??` for 197- **Finding it again.** Eleven places are named by patterns of 24 to 77 bytes (19 to 36 of them fixed, `??` for
198 what another build changes: short signatures, no longer than they must be), which give 19 things: 8 functions, 198 what another build changes: short signatures, no longer than they must be), which give 20 things: 8 functions,
199 the hook's call, 9 globals and the place of the level in the wanted state. Each 199 the hook's call, 10 globals and the place of the level in the wanted state (the eleventh place, the global of
200 the player's vehicle, is for the keyboard and mouse layout and is looked up without the game actions too:
201 `docs/gameinput.md`). Each
200 pattern is in the 99.9 MB of code exactly once (`cargo test -p leonida-loader game_actions` with 202 pattern is in the 99.9 MB of code exactly once (`cargo test -p leonida-loader game_actions` with
201 `LEONIDA_GAME_DIR` set checks it, and that functions lie in code and globals behind it). None contains a load 203 `LEONIDA_GAME_DIR` set checks it, and that functions lie in code and globals behind it). None contains a load
202 of the thread's TLS array, which the loader rewrites. A place that is not found leaves its items saying so; the 204 of the thread's TLS array, which the loader rewrites. A place that is not found leaves its items saying so; the
@@ -396,7 +398,7 @@ interpreter is simply not found by these signatures, which is why the run-time s
396 Skipped without a D3D12 device. 398 Skipped without a D3D12 device.
397- `cargo test -p leonida-hle --features diagnostics --lib -- gameinput clock`: the input shim with the kept keys in 399- `cargo test -p leonida-hle --features diagnostics --lib -- gameinput clock`: the input shim with the kept keys in
398 place, and the title's clock. 400 place, and the title's clock.
399- `cargo test -p leonida-loader --lib game_actions`: the ten places on made-up code (found wherever they lie, 401- `cargo test -p leonida-loader --lib game_actions`: the eleven places on made-up code (found wherever they lie,
400 displacements and numbers read, a place missing, twice or pointing outside left out), the hook on made-up code 402 displacements and numbers read, a place missing, twice or pointing outside left out), the hook on made-up code
401 that runs (the update step calls a function of ours and returns as before) and, with `LEONIDA_GAME_DIR` set to 403 that runs (the update step calls a function of ours and returns as before) and, with `LEONIDA_GAME_DIR` set to
402 the package's folder, every place once in the retail executable, functions in code and globals behind it. 404 the package's folder, every place once in the retail executable, functions in code and globals behind it.