diff --git a/d3d12/README.md b/d3d12/README.md index b406ac074..e4886a5be 100644 --- a/d3d12/README.md +++ b/d3d12/README.md @@ -383,6 +383,48 @@ Series X profile (sharper, much slower; DLSS there with `-Dlss`); `-Quality` giv stretched bodies, slower; `-RayTracing` turns the title's real ray tracing on. The fork's own `scripts\play.ps1` is still there for AMD cards. +### Keyboard and mouse + +The game itself only knows an Xbox controller, so the keyboard and mouse press that controller's buttons for you, +laid out as in Grand Theft Auto V on PC. Click in the game's window once to give it the mouse (that click is not a +shot); Esc pauses and frees the mouse again. + +| | on foot | in a vehicle | +|---|---|---| +| W A S D | move | W accelerate, S brake and reverse, A D steer | +| mouse | look around | look around | +| left mouse button | shoot | shoot from the vehicle | +| right mouse button | aim | (nothing yet) | +| Space | jump, climb | handbrake | +| Left Shift | run | lean forward on a bike (also Num 8) | +| Left Ctrl | crouch | lean back on a bike (also Num 5) | +| F | get into a vehicle | get out | +| E | interact | horn | +| Q | take cover | radio | +| R | reload, melee | (the same button) | +| X, H | | duck, headlights | +| Tab | weapon wheel (hold) | weapon wheel | +| C | look behind | look behind | +| M | map | map | +| Esc or P | pause | pause | +| arrow keys | phone (up) and its menus; down, left and right are the HUD, the radio and the partner menu | the same | +| Enter, Backspace | accept, back (phone and menus) | the same | +| Z | HUD and objective | the same | + +A key you were holding when you got in or out counts again once you have let it go and pressed it again: W held +while climbing in does not drive off by itself, and a held mouse button does not start to fire. + +The runtime reads from the game whether you are in a vehicle. Where it cannot (another version of the game), the +keys stay the on-foot ones and **Caps Lock** is the switch: press it once you sit in a vehicle for the driving keys, +and again, or F to get out, for the on-foot keys. Without it a vehicle still drives the old way: left mouse button +accelerates, right mouse button brakes. Should the runtime get it wrong, `-More @{LEONIDA_PLAYER_VEHICLE_AT='off'}` +stops it reading and leaves the switch to Caps Lock. + +Not bound, because it is not known yet which controller button does it in this game: V (camera), G (grenade), the +number keys and the mouse wheel (weapons), aiming from a vehicle. A controller keeps working beside the keyboard at +all times. `LEONIDA_KBM=classic` (with `-More @{LEONIDA_KBM='classic'}`) brings back the keys of before; the +details, the mouse settings and the other switches are in [docs/gameinput.md](../docs/gameinput.md). + ### Picking a resolution There is one script per console and resolution in `scripts\`. Each one runs diff --git a/d3d12/apps/leonida/src/game_actions.rs b/d3d12/apps/leonida/src/game_actions.rs index d65fdda30..a35f5eadb 100644 --- a/d3d12/apps/leonida/src/game_actions.rs +++ b/d3d12/apps/leonida/src/game_actions.rs @@ -495,6 +495,9 @@ impl Game { ); let ped = self.ped(); let _ = writeln!(s, " player ped {ped:x?}, position {:?}, forward {:?}", self.position(), self.forward()); + // The global `player_context` reads: the vehicle the player is in, null on foot. + let vehicle = self.at(Site::PlayerVehicle).and_then(mem::read_u64); + let _ = writeln!(s, " player's vehicle {vehicle:x?}"); // SAFETY: forwarded from this function's contract. let wanted = ped.and_then(|ped| unsafe { self.wanted_level(ped) }); let _ = writeln!(s, " wanted level {wanted:?}, clock {:?}", self.clock()); @@ -820,16 +823,24 @@ fn run_script(script: Vec<(f32, Command)>) { } /// With `LEONIDA_GAME_ACTIONS=1`: finds the title's code in the image just mapped, hooks its cheat update and -/// lends the menu the actions. Nothing is changed in the title otherwise. +/// lends the menu the actions. Nothing is changed in the title otherwise. Gives what it found of the title (for +/// who else reads it: `player_context`), `None` when it did not look. /// /// # Safety /// `base` is the title's executable `info` describes, mapped, and none of its code runs yet. -pub unsafe fn install(base: usize, info: &leonida_pe::ImageInfo) { +pub unsafe fn install(base: usize, info: &leonida_pe::ImageInfo) -> Option { if !places::wanted() { - return; + return None; } // SAFETY: forwarded from this function's contract; the hook is a function of this program. let (sites, hooked) = unsafe { places::install(base, info, frame_hook as extern "win64" fn() as usize) }; + let found = sites.clone(); + start(base, info, sites, hooked); + Some(found) +} + +/// The rest of [`install`]: the actions, when the hook is in. +fn start(base: usize, info: &leonida_pe::ImageInfo, sites: Sites, hooked: Result<(), String>) { for line in &sites.missing { println!("game actions not found: {line}"); } diff --git a/d3d12/apps/leonida/src/main.rs b/d3d12/apps/leonida/src/main.rs index 08df7abe8..6ad3b6719 100644 --- a/d3d12/apps/leonida/src/main.rs +++ b/d3d12/apps/leonida/src/main.rs @@ -14,6 +14,8 @@ mod replay; mod game_actions; #[cfg(windows)] mod player; +#[cfg(windows)] +mod player_context; #[cfg(all(windows, feature = "diagnostics"))] mod player_find; mod run; diff --git a/d3d12/apps/leonida/src/player_context.rs b/d3d12/apps/leonida/src/player_context.rs new file mode 100644 index 000000000..9cd0c03f4 --- /dev/null +++ b/d3d12/apps/leonida/src/player_context.rs @@ -0,0 +1,815 @@ +//! What the player is in, on foot or in a vehicle, read from the title and told to the keyboard and mouse layout +//! (`leonida_hle::modules::gameinput`, `kbm`): the right trigger shoots on foot and accelerates in a vehicle, so +//! the layout has two tables and has to know which one counts (`docs/gameinput.md`). +//! +//! A thread of ours reads a few words of the title's memory every 16 ms, through `ReadProcessMemory` on the own +//! process (a page that is gone is a failed read, not a fault). Nothing is written to the title and none of its +//! code is called, so this needs no `LEONIDA_GAME_ACTIONS=1`: it only needs the two globals found, by the +//! patterns of `leonida_loader::game_actions`. +//! +//! What says "in a vehicle", the first of these that there is: +//! +//! - `LEONIDA_PED_VEHICLE_AT=0x`: a field of the player's ped that points at its vehicle and is null on +//! foot (for a measured offset; none is known). +//! - `LEONIDA_PLAYER_VEHICLE_AT=0x`: a global of the title that holds the player's vehicle +//! and is null on foot. Without the variable this is `Site::PlayerVehicle`, found by its pattern; +//! `LEONIDA_PLAYER_VEHICLE_AT=off` leaves it unused. +//! - `LEONIDA_KBM_SPEED=1`: how fast the ped moves ([`SpeedRule`]). It only ever says "in a vehicle", and only +//! once the ped has been faster than anyone runs for a second, so it is off unless asked for: the keys' meaning +//! would change in the middle of a drive. It always runs as a check of the two above, into the log. +//! +//! With none of them the context stays unknown, and the layout is the on-foot one with Caps Lock as the switch. +//! +//! `LEONIDA_PED_DUMP=` (outside the repository) is for measuring: F8 in the game's window, or a file named +//! `dump` in that folder (its text is the dump's label; it is removed as it is seen), writes the first 0x4000 +//! bytes of the player's ped to `ped-