Native mod DLLs (experimental): load them and call victory_on_title_mapped #2970

Closed
leonida/mandy
Korothi wants to merge 0 commits from native-mod-dlls into main

Pull request closed

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

Korothi commented 2026-12-01 22:02:38 +00:00

What and why

Adds experimental support for native mod DLLs, which the runtime had no way to load (Lua mods are the only mods today).

Before the title starts, every .dll in %LOCALAPPDATA%\leonida\native-mods\ (or the folder LEONIDA_NATIVE_MODS names) is loaded, in name order. Each one that exports victory_on_title_mapped(const TitleInfo *) is called once, after the title is mapped and before any title code runs, with the image base, size and the absolute exe path.

  • A DLL that fails to load is logged and left out.
  • A DLL that loads but has no such export stays loaded (its DllMain has run) and is not called.
  • A DLL whose callback returns nonzero stays loaded and the value is logged.
  • The title runs on in every case.

Start-up output starts with Mods: none or the list of loaded DLLs (a DLL without the export counts as loaded).

A mod's own dependencies are found by LoadLibraryW's standard search order (the runtime's folder, the system folders, the current folder, PATH), not in the mod's folder; docs/native-mods.md says so.

The contract (when it is called, return value, how the struct may grow under a new version) is in the new docs/native-mods.md, which marks the callback as experimental and says a fault seen with a native mod has to be reproduced without it before it is reported. The change is in d3d12/apps/leonida/src/run.rs: the folder choice, the file filter and the loader, and one call. The folder choice and the file filter are small pure functions with unit tests; the title's own folder is never a default. d3d12/docs/switches.md is regenerated for LEONIDA_NATIVE_MODS. Lua mods and the trainer menu are untouched.

It lets a script-hook style DLL start (I used ScriptHook VI's shvi_core.dll).

Open question for maintainers: whether the runtime should support native DLL mods at all. The code only notifies DLLs it loaded itself.

Tested

On Windows, built with build-nvidia.ps1, with ScriptHook VI's core DLL in the native-mods folder and its plugin files next to the title's exe: the Mods: line names the DLL, the callback returns 0 and the mod's menu opens in game. With the folder empty or absent the output says Mods: none and nothing else changes. Repeated after the review follow-up with the same result. Not tested: other mods, other builds, Linux/Proton.

  • cargo test -p leonida passes, including the new unit tests for the folder choice and the file filter.
  • python -I tests/test_d3d12_switches.py passes (20/20) and scripts/check_no_game_data.py passes.

GPUs tested: NVIDIA GeForce RTX 5090, driver 621.40, Windows 11

AI-assisted: yes

The first version was written with Claude Sonnet 5.5, which is below the model list CONTRIBUTING.md gives for new code. It was reviewed by a separate read-only agent that also ran on Claude Sonnet 5.5; its findings were fixed. The follow-up that answers the maintainer's review (helpers and tests, wording, dependency note, regenerated switches page) was also written with Claude Sonnet 5.5.

The whole change was then re-reviewed in a separate read-only session on Astra: no blocking findings and no memory-safety defect found. Optional nits (empty and relative override semantics, case-sensitive sort order, wording of the dependency search order) were not applied.

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption, including in logs or reports quoted here (scripts/check_no_game_data.py passes).
  • A new translator rule: not applicable.
## What and why Adds experimental support for native mod DLLs, which the runtime had no way to load (Lua mods are the only mods today). Before the title starts, every `.dll` in `%LOCALAPPDATA%\leonida\native-mods\` (or the folder `LEONIDA_NATIVE_MODS` names) is loaded, in name order. Each one that exports `victory_on_title_mapped(const TitleInfo *)` is called once, after the title is mapped and before any title code runs, with the image base, size and the absolute exe path. - A DLL that fails to load is logged and left out. - A DLL that loads but has no such export stays loaded (its `DllMain` has run) and is not called. - A DLL whose callback returns nonzero stays loaded and the value is logged. - The title runs on in every case. Start-up output starts with `Mods: none` or the list of loaded DLLs (a DLL without the export counts as loaded). A mod's own dependencies are found by `LoadLibraryW`'s standard search order (the runtime's folder, the system folders, the current folder, `PATH`), not in the mod's folder; `docs/native-mods.md` says so. The contract (when it is called, return value, how the struct may grow under a new `version`) is in the new `docs/native-mods.md`, which marks the callback as experimental and says a fault seen with a native mod has to be reproduced without it before it is reported. The change is in `d3d12/apps/leonida/src/run.rs`: the folder choice, the file filter and the loader, and one call. The folder choice and the file filter are small pure functions with unit tests; the title's own folder is never a default. `d3d12/docs/switches.md` is regenerated for `LEONIDA_NATIVE_MODS`. Lua mods and the trainer menu are untouched. It lets a script-hook style DLL start (I used ScriptHook VI's `shvi_core.dll`). Open question for maintainers: whether the runtime should support native DLL mods at all. The code only notifies DLLs it loaded itself. ## Tested On Windows, built with `build-nvidia.ps1`, with ScriptHook VI's core DLL in the native-mods folder and its plugin files next to the title's exe: the `Mods:` line names the DLL, the callback returns 0 and the mod's menu opens in game. With the folder empty or absent the output says `Mods: none` and nothing else changes. Repeated after the review follow-up with the same result. Not tested: other mods, other builds, Linux/Proton. - `cargo test -p leonida` passes, including the new unit tests for the folder choice and the file filter. - `python -I tests/test_d3d12_switches.py` passes (20/20) and `scripts/check_no_game_data.py` passes. GPUs tested: NVIDIA GeForce RTX 5090, driver 621.40, Windows 11 ## AI-assisted: yes The first version was written with Claude Sonnet 5.5, which is below the model list CONTRIBUTING.md gives for new code. It was reviewed by a separate read-only agent that also ran on Claude Sonnet 5.5; its findings were fixed. The follow-up that answers the maintainer's review (helpers and tests, wording, dependency note, regenerated switches page) was also written with Claude Sonnet 5.5. The whole change was then re-reviewed in a separate read-only session on Astra: no blocking findings and no memory-safety defect found. Optional nits (empty and relative override semantics, case-sensitive sort order, wording of the dependency search order) were not applied. ## Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption, including in logs or reports quoted here (`scripts/check_no_game_data.py` passes). - [x] A new translator rule: not applicable.
andrew-ai commented 2026-12-01 22:12:04 +00:00

The switch-reference check fails because LEONIDA_NATIVE_MODS is missing from d3d12/docs/switches.md. On main c4ca57615, all 20 tests in tests/test_d3d12_switches.py pass. After merging this head (1cfd799b7) locally, 19 pass and test_the_tracked_switches_page_matches_the_sources reports the missing name.

Running python -I tools/d3d12_switches.py --out d3d12/docs/switches.md on the merged tree and repeating python -I tests/test_d3d12_switches.py gives 20/20. Only the generated switch reference changed. Documentation check only; no title or native mod was loaded. Codex-assisted for #2570.

The switch-reference check fails because LEONIDA_NATIVE_MODS is missing from d3d12/docs/switches.md. On main c4ca57615, all 20 tests in tests/test_d3d12_switches.py pass. After merging this head (1cfd799b7) locally, 19 pass and test_the_tracked_switches_page_matches_the_sources reports the missing name. Running `python -I tools/d3d12_switches.py --out d3d12/docs/switches.md` on the merged tree and repeating `python -I tests/test_d3d12_switches.py` gives 20/20. Only the generated switch reference changed. Documentation check only; no title or native mod was loaded. Codex-assisted for #2570.
KelboLive reviewed 2026-12-01 22:22:39 +00:00
KelboLive left a comment
No description provided.
The shape is right: per-user opt-in folder (`%LOCALAPPDATA%\leonida\native-mods` or `LEONIDA_NATIVE_MODS`), `Mods: none` when it is absent, the callback after the exe and title imports are bound but before `spawn_main` (so DLL attach/TLS callbacks have not run, matching `docs/native-mods.md:23-25`), and load/missing-export/nonzero-return failures are logged and skipped. `TitleInfo` is `#[repr(C)]` and matches the documented fields. `check_no_game_data` passes and `cargo test -p leonida` is 47/47. Three things before merge: 1. **Blocking:** `LEONIDA_NATIVE_MODS` is read at `run.rs:316` but has no row in `d3d12/docs/switches.md`, so `tests/test_d3d12_switches.py` fails (19/20) on `test_the_tracked_switches_page_matches_the_sources`. Regenerating with `--out` fixes it. 2. **The location guard is untested.** I changed the fallback to `exe.parent()` (DLLs beside the title exe load by default) and all 47 `leonida` tests still pass. Please extract the directory/extension choice into a pure helper and test default / env override / absent dir — and explicitly that the title's directory is never the default. 3. **Dependency resolution:** `LoadLibraryW` (`:345`) resolves a mod's dependencies through the standard search order (app/game dir, system dirs, CWD, PATH), **not** the mod's own folder. Document that, or use `LoadLibraryExW` with `LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32` if dependencies should stay beside the mod. Minor wording: "A DLL without the export is left alone" actually means it is **loaded** (its `DllMain` runs) but not called; the body's "skipped" has the same ambiguity. Also, per CONTRIBUTING, new code needs a listed model: this was written/reviewed on Sonnet 5.5, so it needs a re-review on one of the listed models before merge. Merge is clean against current main.
Korothi commented 2026-12-02 00:28:41 +00:00

Pushed debb73cae addressing all three points:

  1. d3d12/docs/switches.md regenerated; tests/test_d3d12_switches.py passes 20/20.
  2. The folder and extension choice is now in pure helpers (native_mods_dir, is_native_mod_dll, native_mod_paths) with unit tests: default, env override, absent dir, extension filter, ordering. native_mods_dir takes no exe path, so the title's directory cannot be a default.
  3. Dependency resolution is documented in docs/native-mods.md and at the LoadLibraryW call, rather than switching to LoadLibraryExW, to keep the behaviour I tested. Happy to switch if you'd rather keep dependencies beside the mod.

Wording fixed: a DLL without the export stays loaded (its DllMain runs) but is not called.

Pushed debb73cae addressing all three points: 1. `d3d12/docs/switches.md` regenerated; `tests/test_d3d12_switches.py` passes 20/20. 2. The folder and extension choice is now in pure helpers (`native_mods_dir`, `is_native_mod_dll`, `native_mod_paths`) with unit tests: default, env override, absent dir, extension filter, ordering. `native_mods_dir` takes no exe path, so the title's directory cannot be a default. 3. Dependency resolution is documented in `docs/native-mods.md` and at the `LoadLibraryW` call, rather than switching to `LoadLibraryExW`, to keep the behaviour I tested. Happy to switch if you'd rather keep dependencies beside the mod. Wording fixed: a DLL without the export stays loaded (its `DllMain` runs) but is not called.
andrew-ai commented 2026-12-02 00:30:05 +00:00

Confirmed the switch-reference fix at debb73cae. The tracked table contains LEONIDA_NATIVE_MODS, the generator check exits 0, and all 20 tests in tests/test_d3d12_switches.py pass on Windows. My documentation finding is resolved. Codex-assisted.

Confirmed the switch-reference fix at debb73cae. The tracked table contains LEONIDA_NATIVE_MODS, the generator check exits 0, and all 20 tests in tests/test_d3d12_switches.py pass on Windows. My documentation finding is resolved. Codex-assisted.
Korothi commented 2026-12-02 00:41:58 +00:00

Pushed debb73c addressing all three points:

  1. d3d12/docs/switches.md regenerated; tests/test_d3d12_switches.py passes 20/20.
  2. The folder and extension choice is now in pure helpers (native_mods_dir, is_native_mod_dll, native_mod_paths) with unit tests: default, env override, absent dir, extension filter, ordering. native_mods_dir takes no exe path, so the title's directory cannot be a default.
  3. Dependency resolution is documented in docs/native-mods.md and at the LoadLibraryW call, rather than switching to LoadLibraryExW, to keep the behaviour I tested. Happy to switch if you'd rather keep dependencies beside the mod.

Wording fixed: a DLL without the export stays loaded (its DllMain runs) but is not called.

Re-review done on Astra: no blocking findings; optional nits (empty/relative override semantics, case-sensitive sort, dependency-order wording) not applied. Details are in the PR body.

Pushed debb73c addressing all three points: 1. `d3d12/docs/switches.md` regenerated; `tests/test_d3d12_switches.py` passes 20/20. 2. The folder and extension choice is now in pure helpers (`native_mods_dir`, `is_native_mod_dll`, `native_mod_paths`) with unit tests: default, env override, absent dir, extension filter, ordering. `native_mods_dir` takes no exe path, so the title's directory cannot be a default. 3. Dependency resolution is documented in `docs/native-mods.md` and at the `LoadLibraryW` call, rather than switching to `LoadLibraryExW`, to keep the behaviour I tested. Happy to switch if you'd rather keep dependencies beside the mod. Wording fixed: a DLL without the export stays loaded (its `DllMain` runs) but is not called. Re-review done on Astra: no blocking findings; optional nits (empty/relative override semantics, case-sensitive sort, dependency-order wording) not applied. Details are in the PR body.
MoonEyes commented 2026-12-02 12:19:17 +00:00

Closing: this pull request no longer applies to current main (merge conflict in d3d12/docs/switches.md), and open pull requests that have fallen out of step with main are being closed so the list stays workable. If you still want this change, rebase it on current main and reopen it (or open a new pull request); it will be looked at again.

AI-assisted (Claude Code).

Closing: this pull request no longer applies to current `main` (merge conflict in `d3d12/docs/switches.md`), and open pull requests that have fallen out of step with `main` are being closed so the list stays workable. If you still want this change, rebase it on current `main` and reopen it (or open a new pull request); it will be looked at again. AI-assisted (Claude Code).
Korothi commented 2026-12-02 13:54:38 +00:00

Rebased on current main (the conflict was only in the generated switches.md, regenerated). GitHub refused to reopen this PR, so it continues in https://github.com/ProjectLeonida/mandy/pull/3144

Rebased on current main (the conflict was only in the generated switches.md, regenerated). GitHub refused to reopen this PR, so it continues in https://github.com/ProjectLeonida/mandy/pull/3144
Sign in to join this conversation.
No description provided.