Commit Graph

9 Commits

Author SHA1 Message Date
f4333dea6b Find the local player's transform in memory (LEONIDA_FIND_PLAYER) and write a new position into it
Diagnostics: lists unit-axis transforms in writable memory, samples them against the held keys, ranks the ones
that move with W/S/D and stay put otherwise, then searches pointer paths from the title's image to the best
ones (paths.txt). player.rs follows those paths and moves the player (LEONIDA_TELEPORT).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 02:45:49 -05:00
130ada08ba Offer a mimalloc build of the runtime (cargo feature, off by default)
What was wrong: nothing by default. The runtime allocates through the system
heap, and some builds want to compare another allocator on the CPU-bound
translation threads.

What changes: a cargo feature `mimalloc` on the leonida app (-> leonida-hle
-> leonida-gpu, optional workspace dependency mimalloc 0.1.52, no default
features) installs mimalloc as the global allocator. With diagnostics on
Windows, the counting allocator in copystat wraps mimalloc instead of the
system heap, so the allocation counters keep working. Default off: with the
feature off the code is unchanged (the system allocator, same counters), and
the only difference in the tree is the unused optional dependency in
Cargo.lock. How much mimalloc helps is not measured here. Only the allocator
part of the fork commit is ported, not its descriptor-count reporting.

Source: from TaynanGT/Vice-Tay dfdb8b4, GPL-3.0 (allocator part only).

Tests: cargo check -p leonida --features diagnostics (default) and
--features diagnostics,mimalloc; cargo check -p leonida-gpu --features
mimalloc. Not run on the game. AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 01:16:38 -05:00
4451198973 leonida-gpu, hle, app: wire the Lua mods into the renderer, the input shim and the start-up
What: the renderer starts the mods' thread where it makes the presenter
(leonida_lua::start(), before the menu's, so the F4 menu has its Mods page), calls
leonida_lua::tick() once per present (one atomic load with LEONIDA_LUA=0), draws the
mods' overlay with a second trainer Overlay at the place the drawing says
(Frame::origin), before the F4 menu, and lends the mods checked reads and writes of
the title's memory (host::lua_read over read_into; lua_write over safecopy::copy,
or NtWriteVirtualMemory with LEONIDA_SAFE_COPY=0). The input shim adds the keys mods
hold (knobs::injected_keys) to what it already feeds the title for LEONIDA_KEYS and
LEONIDA_KEYS_FILE. The app tells the mods where the title's image is mapped.
Why: the pieces of the last two commits were not connected to anything.
How checked: cargo check --profile diag -p leonida --features diagnostics and
cargo check -p leonida-gpu --features diagnostics --tests (no new warnings). NOT run:
no GPU test (the GPU was in use) and not the title; plain `cargo check -p leonida`
(no diagnostics) already fails on the base at gameinput.rs `held_from_file()`, which
only exists with the feature - left as it is. AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 00:11:49 -05:00
312dfeac0d leonida-lua: a sandboxed Lua 5.4 modding API (events, overlay, settings, menu pages, checked memory)
What: a new crate that runs the Lua mods of mods\<name>\ (mod.json with
"script": "main.lua", enabled unless it says false) in one Lua 5.4 state (mlua,
vendored, MIT) on a thread of its own. The `leonida` table (api_version 1):
on("frame"|"key"|"menu_open"), key_down, pad, hold_keys/release_keys, text/rect
(a draw list cleared each pass), get/set for fps_cap, dlss_sharpness, panel,
menu_scale and game_speed only, menu.page():toggle/number/action, memory
read/write u8..f64/bytes, scan with wildcards and base, log, screenshot, frame,
time, read_file/write_file in the mod's folder, require of the mod's own .lua.
Sandbox: each mod gets an environment of copies of the safe base functions and
coroutine/table/string/utf8/math and os.time/clock/date/difftime. No io, package,
debug, dofile, loadfile, string.dump, os.execute/remove/rename/exit/getenv, no
precompiled chunks, no network. A mod's error, a call that outlives its 200 ms
budget (also inside pcall and coroutines) or 128 MiB for the state switches that
mod off and nothing else. The host is behind a Platform trait; the renderer
wiring follows in the next commit. mod.json is read by a small JSON reader of
its own (json.rs): serde_json in the build made `assert_eq!(vec_of_u32, [])`
ambiguous in leonida-gpu's tests.
Why: mods can use what the runtime controls (the title's own script functions
are not reachable: docs/mod-menu.md).
How checked: cargo test -p leonida-lua --lib (34 passed): forbidden functions
gone, event dispatch, one mod failing (syntax, runtime, table errors, endless
loops, memory) leaving the others, memory reads and writes of a local buffer
with unmapped, protected and out-of-range addresses, scan across chunks and
holes, overlay list, menu pages and callbacks, settings, files, require,
manifests, the JSON reader, API version. Cargo.lock gains mlua, mlua-sys,
lua-src and their small dependencies. scripts/check_no_game_data.py on the
files. AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 00:11:49 -05:00
0d0e0fa4d3 leonida-hle: keep the trainer menu's keys from the title; serve its clock at the menu's rate
a938911fc (leonida/mod-menu) on the main line after the renderer merge.
gameinput.rs changed on both sides since db723a4c4 (Leonida's keyboard
layout for the stand-in pad, LEONIDA_KEYS_FILE, and upstream's F1 check);
all of it is kept, and this adds beside it:

gameinput: while the trainer menu is open, its keys (arrows, Enter,
Backspace, F4, numpad 8/2/4/6/5/0) and the pad's d-pad, A and B are not
seen by the title; a key held as the menu closes stays kept until let go.
The stand-in pad is made of the keys read, so it does not see them
either. Closed, nothing changes. The F1 settings menu still takes the
whole keyboard while it is shown (upstream's check, before this one).
Scripted keys (LEONIDA_KEYS, LEONIDA_KEYS_FILE) are the title's and reach
it with the menu open too: a test started with LEONIDA_MENU_OPEN=1 can
still drive the title.

clock: the title's QueryPerformanceCounter import (the profile API set) is
served at the rate the menu sets (World, Game speed), continuously; the
host's count passes through until the rate is first changed. Not served
with LEONIDA_MENU=0.

Checked: cargo check -j 4 --profile diag -p leonida --features diagnostics
(no new warnings); cargo test -j 4 -p leonida-hle --features diagnostics
--lib -- gameinput clock registry (14 passed). Without the diagnostics
feature leonida-hle does not compile on the main line either
(gameinput.rs: scripted() calls held_from_file(), which is
diagnostics-only, since 2441991ca); left as it is here.
Not run in the title.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-26 22:59:28 -05:00
b6c06f9ecb leonida-gpu: draw the trainer menu at present, beside the F1 menu and the F3 panel
f44a22add (leonida/mod-menu) drew the trainer menu from host/menu.rs on the
renderer of db723a4c4. The merged renderer (00698e1e8) has its own
host/menu.rs (the F1 settings menu), lays the two planes over each other
with a pixel shader straight into the back buffer (compose.rs), may send
the present's list ahead of the card, and has its own frame-rate cap, DLSS
and frame generation. So this is that commit made again for it, not a
merge of it:

- host/trainer.rs (was host/menu.rs): the overlay. One blended quad onto
  the swap chain's buffer, recorded where the panel and the F1 menu are
  copied onto it (after the composite or the copy, before Present), so
  with frame generation it is treated as they are. The picture's texture
  has a view heap of its own, and every list keeps what it draws with
  (texture, heap, upload, pipeline), because a present's list may now run
  after the next one is recorded. In every build; F1 and F3 stay
  diagnostics-only as upstream has them.
- A present asks leonida_menu::work() once: one atomic load, and nothing
  else while the menu is closed and no screenshot is asked for. The
  menu's thread starts when the presenter is made.
- F3's panel and the trainer both stand in the upper left corner: while
  the panel is shown the trainer stands below it (panel::lines_taken).
  While the F1 menu is shown it has the keyboard and the trainer reads
  the pads only.
- The frame-rate cap item is upstream's cap (LEONIDA_FPS_CAP,
  frame::set_cap), set the way the F1 menu sets it; the cap this commit
  used to add after Present is gone. Sharpen strength is DLSS's sharpness
  (LEONIDA_DLSS_SHARPNESS, read by dlss.rs at every upscale), there when
  the build has the dlss feature and LEONIDA_UPSCALE=dlss; the compose
  pass's LEONIDA_SHARPEN no longer exists. The F1 menu re-reads its live
  settings when it opens, so it shows what F3 or the trainer changed.
- Screenshots and recording use capture.rs (diagnostics builds): a
  screenshot is the present's own read-back (capture::read_back, the
  title's picture before panel and menus), saved at full size with
  capture::png; frame recording makes and removes the rec file
  capture::recording looks for. capture.rs itself is unchanged.
- leonida-menu: work() is inline.

Checked: cargo check -j 4 --profile diag -p leonida --features diagnostics
and --features diagnostics,dlss (no new warnings), cargo check -p
leonida-gpu without diagnostics, cargo test -p leonida-gpu --features
diagnostics --lib -- host::trainer host::menu host::panel frame:: (10
passed; the overlay test draws the menu with this pipeline onto an
offscreen texture on the local D3D12 device, at its place and below the
panel's, and reads both back), cargo test -p leonida-menu (34 passed).
Not run in the title: where it lands on the real back buffer, with
presents sent ahead and with frame generation, is unverified.

AI-assisted.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-26 22:59:28 -05:00
12cbaab996 leonida-menu: the trainer menu's model, input, settings and painter
A new crate with no platform in its core: pages of items (submenus,
toggles, numbers, choices, actions) with a cursor and back stack that wrap
round and scroll; keys and pad buttons to presses with repeat and
debounce, and which keys are kept from the title while it is open; the
run-time settings the rest of the runtime reads (sharpen strength,
frame-rate cap, FPS panel and frame recorder switches, screenshots, the
title's clock rate); Leonida's pages grouped as single-player trainers
group them (Player, Vehicle, Weapons, World, Time, Weather, Teleport,
Misc, Settings); script features behind a GameActions backend that says
why they are not available yet. The menu is painted on the CPU in the
classic trainer layout, in two layers (unselected and selected rows) so
the highlight can slide on the card; glyphs come from the system's fonts
through GDI at run time (Segoe Script, Segoe UI), the built-in dot font
elsewhere. Its own thread polls F4 / RB+Left and paints only on change.
LEONIDA_MENU=0 turns it off. 30 unit tests, no GPU needed.

Cherry-picked from 996fbd522 (leonida/mod-menu, written against db723a4c4)
onto the main line after the upstream renderer merge (00698e1e8). The crate
is as it was; Cargo.lock names it for the workspace only, since leonida-gpu
and leonida-hle take it in the commits that follow. The settings are fitted
to the merged renderer in the next commit.

Checked: cargo test -j 4 -p leonida-menu (30 passed).

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-26 22:59:28 -05:00
00698e1e84 d3d12: the runtime takes trustno1-coder/VIctory-NVIDIA b190242 (CGBJ's renderer, DLSS, frame generation, F1 menu)
Upstream's four commits past 6a31e43 (5b36758, 9e7ab9d, 6395727, b190242;
GPL-3.0), brought in as a three-way merge: upstream's trees before and after
written under Leonida's names (crates leonida-*, LEONIDA_* settings) and the
difference merged onto Leonida's own changes. What comes with it, by its
authors:
- the renderer of codec-d/cool_fox f4b48ad (CGBJ) with trustno1-coder's NVIDIA
  fixes on top (residency.rs, stretch.rs, the title's upscale dispatch);
- DLSS for the title's upscale, from avatarmanz/VIctory-7900XTX pull request
  203 (feature dlss, LEONIDA_UPSCALE=dlss): the game renders its own 720p and
  DLSS takes it to 1080p on the Series S profile;
- DLSS frame generation through NVIDIA Streamline (streamline.rs, fg.rs), an
  F1 settings menu (host/menu.rs), LEONIDA_FPS_CAP, real ray tracing as an
  option (LEONIDA_BVH_BUILDER=1: the structure builder runs on NVIDIA).
NVIDIA's own files (DLSS, Streamline) are not part of the repository:
d3d12/Get-NVIDIA-DLSS.cmd fetches them from NVIDIA's GitHub into
d3d12/nvidia-sdk/ (git-ignored).

Where both sides had changed the same lines:
- compose.rs is upstream's (planes drawn by a pixel shader into the back
  buffer); Leonida's LEONIDA_SHARPEN lived in the compute pass it replaces
  and is not in this commit (DLSS has its own sharpness setting).
- draw.rs keeps Leonida's slow-beat texture re-check (300 frames by default);
  upstream's switch of the same name is dropped.
- ambient.rs keeps LEONIDA_AMBIENT_MOST and the reflection guard.
- play-nvidia.ps1 is upstream's with Leonida's defaults put back while rays
  are off: strict indirect batches (INDIRECT_BATCH=1), the light stand-in
  (AMBIENT=0.8, AMBIENT_MOST=2), ray walks ended at the root and the
  ray-resolve skip list. With upstream's defaults (stand-in off, no skip
  list) shade was black and the sky white in the world, and the card worked
  33-50 ms a frame (run n1).
- scripts/play-d3d12.ps1 follows the new launcher: DLSS by default, a shader
  cache of its own (cache-2), -NoDlss, -RayTracing, -Capture, -Log.

Builds with and without the dlss feature (cargo build --profile diag
-p leonida --features diagnostics[,dlss]). In the world on an RTX 4060 Ti 16 GB
(driver as installed) and a Ryzen 5 7600X: DLSS starts (1280x720 to
1920x1080), about 14 fps where it was 13.4. The picture is not right yet: a
posterized look in run n2 is being traced. AI-assisted.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-26 21:48:18 -05:00
fee07ff779 d3d12: Leonida's D3D12 runtime under its own name
What changed:
- victory/ is now d3d12/;
- its crates are leonida-* (leonida_* code paths);
- the program is leonida.exe;
- settings are LEONIDA_*, and the older VICTORY_* names still work through apps/leonida/src/leonida.rs;
- the config file is leonida.toml;
- log names and user-facing text say Leonida.

What did not change: lines that credit upstream projects or people, URLs, copyright notices and the
GPL-3.0 LICENSE. d3d12/README.md opens with a Leonida section that says the runtime grew from
Marvisak/VIctory through trustno1-coder/VIctory-NVIDIA. The rest of that README is labelled as
trustno1-coder's.

The launchers (scripts/play-d3d12.ps1, scripts/play-linux.sh), docs/linux.md and
scripts/sync_victory.py (prefix d3d12) follow the move. Future upstream merges will need a
mapping from upstream's names onto these.

Builds with `cargo build --profile diag -p leonida --features diagnostics`. The settings alias
tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 16:11:32 -05:00