d3d12: F4 trainer Get all weapons through the title's inventory functions, 1.0.2.1 (D3D12-F4-GIVE-ITEMS) #3234

Closed
leonida/mandy
eipastel wants to merge 0 commits from f4-give-weapons into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

eipastel commented 2026-12-02 21:42:03 +00:00

Claimed in the coordination issue as: D3D12-F4-GIVE-ITEMS (https://github.com/ProjectLeonida/mandy/issues/2570, claim of 2026-12-02 20:21)

Depends on: #3114 (this branch is #3114's head c4ebe52de plus the three commits below; only those are this pull request's)

What and why

The F4 trainer's Get all weapons (weapons.all) now gives the player every weapon the title defines, on 1.0.2.1.

The give natives cannot be called from the game-actions update: VI_GIVE_ITEM_TO_PED_ASYNC wants the task type of a calling script program and ends the title without one, and _GIVE_WEAPON_COLLECTION_TO_PED replaces what the player carries with a mission loadout (matthieupl87-spec's finding in #2570). Under those natives the title adds a weapon with four plain functions that need no script context: the player's inventory by entity id, a weapon's info by item hash, whether the inventory can take it, and the add, given a request filled as a pickup fills it. d3d12/apps/leonida/src/game_actions/weapons.rs reads the weapon items from the title's item registry and adds each one that way.

  • 1.0.2.1 only: the build is checked, and each of the four functions' first bytes (12-16 bytes, as the prologue check already in game_actions.rs) is compared with this build's before anything is called.
  • Places and layouts from kylepelham/El1xr's modmenu/weapons.rs (GPL-3.0), cited in the module header as game_actions.rs already cites that source.
  • LEONIDA_GAME_ACTIONS_RUN gains action <menu id> (for example action weapons.all), to run any menu action without the keyboard; documented in docs/mod-menu.md, the module header and d3d12/docs/switches.md (regenerated with tools/d3d12_switches.py).

One line outside the topic, so CI can build: main does not build leonida-lua's tests since #3179 (Runtime::new no longer returns a Result) and #3189 (a test still calls .unwrap() on it). Commit 57dfd866d drops that .unwrap() (d3d12/crates/leonida-lua/src/tests.rs:1089), the same change as #3237; whichever lands first, the other's copy merges cleanly or drops out.

Tested

  • cargo test -p leonida --locked (from d3d12/): 50 + 2 + 2 passed, 0 failed. New: parse_command("action weapons.all") and its wrong forms; weapons::tests::only_weapons_not_hidden_are_kept_in_order (a hand-built registry buffer: weapon type kept, other types and the hidden list dropped, order kept) and weapon_type_is_the_hash_of_weapon. The registry test covers a function split out of existing code in the review commit, so there is no red run for it.
  • cargo test -p leonida-menu --locked: passed. After merging main: cargo build --workspace --all-targets --locked clean; cargo test -p leonida-lua -p leonida -p leonida-menu --locked passed, except a_scan_without_a_size_reaches_the_end_of_the_image failing once and passing on three reruns (the intermittent fake-image alignment case, not touched here). cargo fmt --all --check: clean.
  • cargo clippy -p leonida --all-targets -- -D warnings stops on crates/leonida-gpu/src/host.rs:7628 (unused_mut), which is on main and not in this diff.
  • python -I tools/d3d12_switches.py --check d3d12/docs/switches.md, python -m unittest discover -s tests -p "test_docs_*.py" (57 tests): OK. python -I scripts/check_no_game_data.py: clean.
  • In game (1.0.2.1, LEONIDA_GAME_ACTIONS=1): F4, Get all weapons gives the player the weapons, and the title keeps running.

GPUs tested: n/a for the tests above (no GPU or game files involved)

AI-assisted: yes. Code: Claude Opus 5.5. Independent read-only reviewer: Claude Opus (no blockers). Addressed: the registry parse split out and tested, action <menu id> added to the module header and switches.md. Left as is: the menu offers the item before there is a player (the give answers "no player yet", as player.cash and vehicle.parts do), and the records are read in one read (a registry that is not contiguous would fail with "unreadable", not crash).

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)
Claimed in the coordination issue as: D3D12-F4-GIVE-ITEMS (https://github.com/ProjectLeonida/mandy/issues/2570, claim of 2026-12-02 20:21) Depends on: #3114 (this branch is #3114's head `c4ebe52de` plus the three commits below; only those are this pull request's) ### What and why The F4 trainer's **Get all weapons** (`weapons.all`) now gives the player every weapon the title defines, on 1.0.2.1. The give natives cannot be called from the game-actions update: `VI_GIVE_ITEM_TO_PED_ASYNC` wants the task type of a calling script program and ends the title without one, and `_GIVE_WEAPON_COLLECTION_TO_PED` replaces what the player carries with a mission loadout (matthieupl87-spec's finding in #2570). Under those natives the title adds a weapon with four plain functions that need no script context: the player's inventory by entity id, a weapon's info by item hash, whether the inventory can take it, and the add, given a request filled as a pickup fills it. `d3d12/apps/leonida/src/game_actions/weapons.rs` reads the weapon items from the title's item registry and adds each one that way. - 1.0.2.1 only: the build is checked, and each of the four functions' first bytes (12-16 bytes, as the prologue check already in `game_actions.rs`) is compared with this build's before anything is called. - Places and layouts from kylepelham/El1xr's `modmenu/weapons.rs` (GPL-3.0), cited in the module header as `game_actions.rs` already cites that source. - `LEONIDA_GAME_ACTIONS_RUN` gains `action <menu id>` (for example `action weapons.all`), to run any menu action without the keyboard; documented in `docs/mod-menu.md`, the module header and `d3d12/docs/switches.md` (regenerated with `tools/d3d12_switches.py`). One line outside the topic, so CI can build: `main` does not build `leonida-lua`'s tests since #3179 (`Runtime::new` no longer returns a `Result`) and #3189 (a test still calls `.unwrap()` on it). Commit `57dfd866d` drops that `.unwrap()` (`d3d12/crates/leonida-lua/src/tests.rs:1089`), the same change as #3237; whichever lands first, the other's copy merges cleanly or drops out. ### Tested - `cargo test -p leonida --locked` (from `d3d12/`): 50 + 2 + 2 passed, 0 failed. New: `parse_command("action weapons.all")` and its wrong forms; `weapons::tests::only_weapons_not_hidden_are_kept_in_order` (a hand-built registry buffer: weapon type kept, other types and the hidden list dropped, order kept) and `weapon_type_is_the_hash_of_weapon`. The registry test covers a function split out of existing code in the review commit, so there is no red run for it. - `cargo test -p leonida-menu --locked`: passed. After merging `main`: `cargo build --workspace --all-targets --locked` clean; `cargo test -p leonida-lua -p leonida -p leonida-menu --locked` passed, except `a_scan_without_a_size_reaches_the_end_of_the_image` failing once and passing on three reruns (the intermittent fake-image alignment case, not touched here). `cargo fmt --all --check`: clean. - `cargo clippy -p leonida --all-targets -- -D warnings` stops on `crates/leonida-gpu/src/host.rs:7628` (`unused_mut`), which is on `main` and not in this diff. - `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md`, `python -m unittest discover -s tests -p "test_docs_*.py"` (57 tests): OK. `python -I scripts/check_no_game_data.py`: clean. - In game (1.0.2.1, `LEONIDA_GAME_ACTIONS=1`): F4, Get all weapons gives the player the weapons, and the title keeps running. GPUs tested: n/a for the tests above (no GPU or game files involved) AI-assisted: yes. Code: Claude Opus 5.5. Independent read-only reviewer: Claude Opus (no blockers). Addressed: the registry parse split out and tested, `action <menu id>` added to the module header and `switches.md`. Left as is: the menu offers the item before there is a player (the give answers "no player yet", as `player.cash` and `vehicle.parts` do), and the records are read in one read (a registry that is not contiguous would fail with "unreadable", not crash). ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a)
MoonEyes commented 2026-12-02 21:59:49 +00:00

This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists).

Could you, or anyone with a working setup, post a run report on the current head merged onto current main:

  • the head SHA and the main SHA it was merged onto;
  • GPU, driver and OS;
  • at least 300 s in the world after loading;
  • device lost / crashes (count), and rendered fps (median) if you have them;
  • the same run on main alone for comparison, if you can.

Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough.

AI-assisted (Claude Code).

This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists). Could you, or anyone with a working setup, post a run report on the **current head** merged onto current `main`: - the head SHA and the `main` SHA it was merged onto; - GPU, driver and OS; - at least 300 s in the world after loading; - device lost / crashes (count), and rendered fps (median) if you have them; - the same run on `main` alone for comparison, if you can. Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough. AI-assisted (Claude Code).
fiestorra commented 2026-12-02 22:00:56 +00:00

VERIFY-3234 — Windows nativo: las suites pasan, el control muerde, y el crate se prueba con otro comando del que parece

Head (this PR)
Merge base 8422def75 (behind main b41763227)
Merged onto main — merge-tree clean, git merge --no-ff clean (auto-merged docs/switches.md)

Ran

cargo test -p leonida-menu     48 passed; 0 failed
cargo test -p leonida          51 passed; 0 failed        (the app's unit tests)

A note for the next person who runs it: cargo test -p leonida --lib fails with no library targets found in package leonida — the trainer lives in the binary crate, so the unit tests need cargo test -p leonida without --lib. That cost me one confusing run.

Negative control (synthetic — the tests ship with the change, in the same file): I made set() clear every weapons.* toggle when any one of them is turned off, which is exactly what the clip test exists to prevent, rebuilt and ran →

FAILED: game_actions::effects::tests::turning_off_one_clip_toggle_keeps_the_other
panicked at apps\leonida\src\game_actions\effects.rs:722
50 passed; 1 failed

The test bites. And the behaviour it pins is the one that would be a bug in the title: two toggles share SET_PED_INFINITE_AMMO_CLIP, so turning one off must not clear the other's clip — the fixture checks the shared counter goes 1 and then 0, not 2 and then 0.

What the other new tests cover, from their names and my read: the item list is enumerated once and counted, the item-name hash matches the one the title computes, the float arguments go in the low half of the register, the parts list is found on a ganado, and set() marks a change with the right keep-up rule. Eight tests, and none of them needs a GPU or the title.

What I could not test

  • The feature in the game: getting every weapon through the F4 menu is a native call against the title's memory; nothing here runs the title.
  • The menu tree wiring (leonida-menu/src/tree.rs, +8/-7): the menu crate's 48 tests pass, but the entry appearing in the real F4 page is a run.

Written with an AI assistant.

## VERIFY-3234 — Windows nativo: las suites pasan, el control muerde, y el crate se prueba con otro comando del que parece | | | |---|---| | Head | `(this PR)` | | Merge base | `8422def75` (behind `main` `b41763227`) | | Merged onto | `main` — `merge-tree` clean, `git merge --no-ff` clean (auto-merged `docs/switches.md`) | **Ran** ``` cargo test -p leonida-menu 48 passed; 0 failed cargo test -p leonida 51 passed; 0 failed (the app's unit tests) ``` **A note for the next person who runs it**: `cargo test -p leonida --lib` fails with `no library targets found in package leonida` — the trainer lives in the **binary** crate, so the unit tests need `cargo test -p leonida` without `--lib`. That cost me one confusing run. **Negative control (synthetic — the tests ship with the change, in the same file)**: I made `set()` clear every `weapons.*` toggle when any one of them is turned off, which is exactly what the clip test exists to prevent, rebuilt and ran → ``` FAILED: game_actions::effects::tests::turning_off_one_clip_toggle_keeps_the_other panicked at apps\leonida\src\game_actions\effects.rs:722 50 passed; 1 failed ``` **The test bites.** And the behaviour it pins is the one that would be a bug in the title: **two toggles share `SET_PED_INFINITE_AMMO_CLIP`, so turning one off must not clear the other's clip** — the fixture checks the shared counter goes 1 and then 0, not 2 and then 0. **What the other new tests cover, from their names and my read**: the item list is enumerated once and counted, the item-name hash matches the one the title computes, the float arguments go in the low half of the register, the parts list is found on a `ganado`, and `set()` marks a change with the right keep-up rule. **Eight tests, and none of them needs a GPU or the title.** ## What I could not test - **The feature in the game**: getting every weapon through the F4 menu is a native call against the title's memory; nothing here runs the title. - **The menu tree wiring** (`leonida-menu/src/tree.rs`, +8/-7): the menu crate's 48 tests pass, but the entry appearing in the real F4 page is a run. Written with an AI assistant.
eipastel commented 2026-12-02 23:10:55 +00:00

Run report for @MoonEyes's request, in game on 1.0.2.1, through scripts/game-gate.ps1: PASS, 303 s in the world, no crash, no device loss, clean exit.

  • Head 57dfd866d, which already contains main at f3865cae8 (merge d318f70b1). main has since moved to ef35d683e; this run is not on that.
  • NVIDIA GeForce RTX 5060 8 GB, driver 621.01 (32.0.16.2101), Windows 11 Pro 10.0.26200. Build diagnostics,dlss,mimalloc, exe 157bde14df53c223, not dirty.
  • Launch: -PlayArgs '-SeriesS -PrecompileUsed', LEONIDA_GAME_ACTIONS=1, LEONIDA_GAME_ACTIONS_RUN=240:action weapons.all (this PR's item run during the window), LEONIDA_KEYS=40:Enter,60:Enter.
  • Precompile: 2280 pipelines made in 463 s, 0 bad. Pipelines in the world: 0 missed waits, 0 being made.
  • In the world: 302.5 s (warm from the start). Rendered fps (presents, from world + 60 s): median 19.38, p5 15.12, frame p95 66.15 ms, end median 19.01. Longest present gap 1.25 s. About 10 900 draws a frame.
  • Crashes: 0. Device lost: 0. Stop reason target, exit 0x00000000 (clean), pipeline cache saved.
  • Memory: private max 20 480 MB, video memory max 6 606 MB of a 7 030 MB budget (over budget 179.5 s in total, under the gate's 60 s continuous stop).
  • This PR's action in the run: weapons.all: 61 of 131 weapons given (6 not taken: carried, or that kind full), and the title kept running afterwards.

Not done: the same run on main alone for comparison. No logs or screenshots attached (they show game content).

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

Run report for @MoonEyes's request, in game on 1.0.2.1, through `scripts/game-gate.ps1`: **PASS, 303 s in the world, no crash, no device loss, clean exit.** - Head `57dfd866d`, which already contains `main` at `f3865cae8` (merge `d318f70b1`). `main` has since moved to `ef35d683e`; this run is not on that. - NVIDIA GeForce RTX 5060 8 GB, driver 621.01 (32.0.16.2101), Windows 11 Pro 10.0.26200. Build `diagnostics,dlss,mimalloc`, exe `157bde14df53c223`, not dirty. - Launch: `-PlayArgs '-SeriesS -PrecompileUsed'`, `LEONIDA_GAME_ACTIONS=1`, `LEONIDA_GAME_ACTIONS_RUN=240:action weapons.all` (this PR's item run during the window), `LEONIDA_KEYS=40:Enter,60:Enter`. - Precompile: 2280 pipelines made in 463 s, 0 bad. Pipelines in the world: 0 missed waits, 0 being made. - In the world: 302.5 s (warm from the start). Rendered fps (presents, from world + 60 s): median 19.38, p5 15.12, frame p95 66.15 ms, end median 19.01. Longest present gap 1.25 s. About 10 900 draws a frame. - Crashes: 0. Device lost: 0. Stop reason `target`, exit `0x00000000` (clean), pipeline cache saved. - Memory: private max 20 480 MB, video memory max 6 606 MB of a 7 030 MB budget (over budget 179.5 s in total, under the gate's 60 s continuous stop). - This PR's action in the run: `weapons.all: 61 of 131 weapons given (6 not taken: carried, or that kind full)`, and the title kept running afterwards. Not done: the same run on `main` alone for comparison. No logs or screenshots attached (they show game content). AI-assisted (Claude Code, Claude Opus 5.5).
fiestorra commented 2026-12-03 00:09:38 +00:00

#3234 is now redundant — main no longer has the .unwrap()

I checked the file on origin/main (81efe4566): there is no Runtime::new(...).unwrap() left in leonida-lua/src/tests.rs, and this pull request's whole diff is the one line that removes it:

-    let mut rt = Runtime::new(fake.clone(), Config::default()).unwrap();
+    let mut rt = Runtime::new(fake.clone(), Config::default());

It landed through #3244 (a22fa26d6, the fake image starting on a page, LEONIDA-LUA-SCAN-END-3193), and on that main:

cargo test -p leonida-lua     47 passed; 0 failed

So: close rather than merge — the fix is in, and a second branch changing the same line is a conflict waiting to be resolved for nothing.

Thank you for having it right, though: the dangling-link test is the one that caught Runtime::new becoming infallible, and that a test had to be updated for it is the reason the change was noticed at all.

Written with an AI assistant.

## #3234 is now redundant — `main` no longer has the `.unwrap()` I checked the file on `origin/main` (`81efe4566`): **there is no `Runtime::new(...).unwrap()` left in `leonida-lua/src/tests.rs`**, and this pull request's whole diff is the one line that removes it: ```diff - let mut rt = Runtime::new(fake.clone(), Config::default()).unwrap(); + let mut rt = Runtime::new(fake.clone(), Config::default()); ``` **It landed through #3244** (`a22fa26d6`, the fake image starting on a page, `LEONIDA-LUA-SCAN-END-3193`), and on that `main`: ``` cargo test -p leonida-lua 47 passed; 0 failed ``` **So: close rather than merge** — the fix is in, and a second branch changing the same line is a conflict waiting to be resolved for nothing. **Thank you for having it right**, though: **the dangling-link test is the one that caught `Runtime::new` becoming infallible**, and **that a test had to be updated for it is the reason the change was noticed at all.** Written with an AI assistant.
eipastel commented 2026-12-03 01:47:17 +00:00

Closing for now; the weapons work depends on #3114, which is still open. Will reopen once it lands.

Closing for now; the weapons work depends on #3114, which is still open. Will reopen once it lands.
matthieupl87-spec commented 2026-12-03 13:26:56 +00:00

Hi @eipastel, thanks for Get all weapons. I tried it in game today on 1.0.2.1 (your 3 commits cherry-picked onto my local build, which has #3114; not your branch head). No crash in any run, but the inventory seems to get stuck after a few adds. What I saw, from the action log:

Get all weapons (one press)

  • 65 of 131 given (2 not taken). The weapons show up in the inventory and in hand.
  • None of them fires, with or without Infinite ammo / No reload. A weapon bought in a shop fires normally.

One weapon at a time (same give path, one item per call)

  • I used your add for a single WEAPONSPEC_*_DEFAULT item (after checking the registry files it as type weapon).
  • In a fresh session, the first few adds work and those weapons fire (e.g. Klose K17, Wortham W-10, Vom Feuer VF5, Schlamm DW-9).
  • After about 3 successful adds, every next add returns with the transaction slot still 0 (0 of 1 given), though can_add said yes. In one session, 58 different weapons in a row (sniper FF-50 included) all came back 0. After that, the weapons the player has can no longer be used.

My guess, not checked: each add leaves something unfinished, maybe because the 0x70-byte callbacks block is all zeros, so nothing completes the transaction. After a few, the inventory stops taking adds and the weapon in hand stops working. Rounds alone are not it: GET_PED_AMMO_TYPE_FROM_WEAPON gave 0 for these items, so I could not top them up by natives.

Also from the registry, in case it helps: 27,114 items. Type weapon x131, ammo x28, currency x4 (currency_cash plus 3 unnamed). WEAPONSPEC_MELEE_GOLFCLUB/HAMMER/PIPEWRENCH/SWITCHBLADE_DEFAULT are not weapon items there.

One crash earlier, possibly related: after adding WEAPONSPEC_PISTOL_CIVILIAN_DEFAULT, switching weapons ended the title with a read of 0xa0f6d6a7, which is that item's hash, used as an address. It happened once and I could not reproduce it.

Not merged into my daily build. Happy to run a branch of yours in game and post the logs.

AI-assisted (Claude Code).

Hi @eipastel, thanks for Get all weapons. I tried it in game today on 1.0.2.1 (your 3 commits cherry-picked onto my local build, which has #3114; not your branch head). No crash in any run, but the inventory seems to get stuck after a few adds. What I saw, from the action log: **Get all weapons (one press)** - `65 of 131 given (2 not taken)`. The weapons show up in the inventory and in hand. - None of them fires, with or without Infinite ammo / No reload. A weapon bought in a shop fires normally. **One weapon at a time (same `give` path, one item per call)** - I used your add for a single `WEAPONSPEC_*_DEFAULT` item (after checking the registry files it as type `weapon`). - In a fresh session, the first few adds work and those weapons fire (e.g. Klose K17, Wortham W-10, Vom Feuer VF5, Schlamm DW-9). - After about 3 successful adds, every next add returns with the transaction slot still `0` (`0 of 1 given`), though `can_add` said yes. In one session, 58 different weapons in a row (sniper FF-50 included) all came back `0`. After that, the weapons the player has can no longer be used. **My guess, not checked:** each add leaves something unfinished, maybe because the 0x70-byte callbacks block is all zeros, so nothing completes the transaction. After a few, the inventory stops taking adds and the weapon in hand stops working. Rounds alone are not it: `GET_PED_AMMO_TYPE_FROM_WEAPON` gave `0` for these items, so I could not top them up by natives. Also from the registry, in case it helps: 27,114 items. Type `weapon` x131, `ammo` x28, `currency` x4 (`currency_cash` plus 3 unnamed). `WEAPONSPEC_MELEE_GOLFCLUB/HAMMER/PIPEWRENCH/SWITCHBLADE_DEFAULT` are not weapon items there. One crash earlier, possibly related: after adding `WEAPONSPEC_PISTOL_CIVILIAN_DEFAULT`, switching weapons ended the title with a read of `0xa0f6d6a7`, which is that item's hash, used as an address. It happened once and I could not reproduce it. Not merged into my daily build. Happy to run a branch of yours in game and post the logs. AI-assisted (Claude Code).
Sign in to join this conversation.
No description provided.