Native mod DLLs (experimental): load them and call victory_on_title_mapped #3144
Code
Clone this repository
Checkout
From your project repository, check out a new branch and test the changes.
git fetch -u origin "github-pr/3144:github-pr/3144" git switch "github-pr/3144"
Open
leonida/mandy
Korothi wants to merge 2 commits from
github-pr/3144 into main
pull from: github-pr/3144
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!3144
Loading…
Reference in a new issue
No description provided.
Delete branch "github-pr/3144"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This branch is out-of-date with the base branch
Reviewers 0 approvals
Details
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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
.dllin%LOCALAPPDATA%\leonida\native-mods\(or the folderLEONIDA_NATIVE_MODSnames) is loaded, in name order. Each one that exportsvictory_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.DllMainhas run) and is not called.Start-up output starts with
Mods: noneor 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.mdsays so.The contract (when it is called, return value, how the struct may grow under a new
version) is in the newdocs/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 ind3d12/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.mdis regenerated forLEONIDA_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: theMods:line names the DLL, the callback returns 0 and the mod's menu opens in game. With the folder empty or absent the output saysMods: noneand nothing else changes. Repeated after the review follow-up with the same result. Not tested: other mods, other builds, Linux/Proton.cargo test -p leonidapasses, including the new unit tests for the folder choice and the file filter.python -I tests/test_d3d12_switches.pypasses (20/20) andscripts/check_no_game_data.pypasses.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
mainand merges cleanly.scripts/check_no_game_data.pypasses).Ran natively on Windows 11, head
776a6c0d3merged into currentmain(43fc605ed, merges cleanly), toolchain 1.98.1 fromrust-toolchain.toml,--locked.cargo test -p leonida --lockednative_mod_testsincluded)cargo clippy -p leonida --tests --lockedleonida; the oneunused_mutinleonida-gpu/src/host.rsis already on mainpython -I tests/test_d3d12_switches.py/tools/d3d12_switches.py --check/scripts/check_no_game_data.pyNo title was run. To exercise
load_native_modsitself I added a throwaway#[ignore]test (not pushed) that calls it with a dummy base/size and a fake exe path, one process per case, withLOCALAPPDATAandLEONIDA_NATIVE_MODSpointed at scratch folders. The mod DLLs are tinycdylibs built for this. So "the exe's folder" below is the test binary's folder, not the runtime's.Mods: nonereturned 0. Nothing else enables it: the folder existing is the switchLEONIDA_NATIVE_MODS=(empty)Mods: none(does not fall back to the default folder)DllMainran, listed inMods:, "not called" line, as documented.dllvoidreturned 1(whatever is left inrax), i.e. reported as declinedexe_pathcorrectstruct_size/versionseen by the modThings that look worth a change:
A relative
LEONIDA_NATIVE_MODScan load a different file than the one listed.read_dirresolves the relative folder against the current folder, butLoadLibraryWgets the relative path (relmods\x.dll) and, for a relative path, uses the standard search, which starts in the executable's folder. Withrelmods\x.dllin both places (two different DLLs), the one listed came from the current folder but the one loaded and run was the one beside the exe. With the copy beside the exe removed, the current-folder one loaded.LEONIDA_NATIVE_MODS=.loads every DLL in the current folder, andLEONIDA_NATIVE_MODS=0(the usual "off" value inswitches.md) names a folder0in the current folder instead of turning it off. Making the folder absolute (std::path::absolute) before listing would make the listed and the loaded file the same.A mod's dependencies come from the current folder and
PATH. A mod importingmoddep.dll:moddep.dllplacedmoddep.dllis then loaded as a mod of its own (listed inMods:, "no export")PATHPATHcopyPATHPATHcopy is used, and the mods-folder copy is loaded a second time as a "mod"This matches what
docs/native-mods.mdsays, so it is a design choice rather than a bug, but the repo already loads a third-party DLL differently:leonida-gpu/src/fsr.rsusesLoadLibraryExW(path, NULL, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32), which takes dependencies from the DLL's own folder and System32 and never from the current folder orPATH. The same flags here would remove the current-folder/PATHlookup and make "put the dependency next to the mod" work. Dependencies would still be listed as mods unless they go in a sub-folder.A mod that faults leaves no
Mods:line. TheMods:line and the per-mod lines are collected and printed only after the loop. Witha_good.dll,b_crash.dll(writes to address 8 in the callback) andc_good.dll, the process ends with0xc0000005. With the runtime'sreport_crashes()installed first, asrun()does, the report namesb_crash.dll+0x14b4, but nothing in the output says thata_good.dllwas loaded and called, andc_good.dllis never loaded. A fault in a mod'sDllMainwould look the same. Printing each line as it happens (or theMods:line before the callbacks) would keep "this run was modded" in the log the docs ask reporters to include.Calling convention: x64 only, where
extern "C"andextern "system"are the same, so a__stdcallexport behaves the same. Not a separate test. DLLs are never unloaded (FreeLibraryis not called), as the docs say.Not checked: a real title run, any real mod, the non-diagnostics/diagnostics feature split, Linux/Proton builds, a mod that starts threads or hooks before returning.
GPUs tested: n/a (CPU-only tests).
AI-assisted: yes (Claude Code).
Verified on the surface this pull request has, which is code plus documentation and no end-to-end test: it builds, its own test passes, and the repository's documentation checks pass on it.
And the three things I would look at in review, all of which are right:
native_mods_dirprefersLEONIDA_NATIVE_MODSand falls back to%LOCALAPPDATA%\leonida\native-mods, and the title's own folder is never a default - the comment says why ("its DLLs are the title's, not mods"), and that is the decision that keeps a mod folder from becoming an arbitrary DLL load;docs/README.mdlinksnative-mods.mdandswitches.mdnamesLEONIDA_NATIVE_MODS, so the switch is documented where the repository's own check looks for it;load_native_modsis called before any title code runs, with the mapped base andSizeOfImage, which is the only moment a mod can hook something.What I could not test, and it is the whole of the experimental feature: loading a DLL and calling
victory_on_title_map- that needs a real mod DLL and a title mapped, and this machine cannot run the title. The code pathload_native_modsitself is not exercised by the test above, only the folder decision is.AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.
Code review only, not built (Windows-only
leonidabinary). The code is sound, but whether to ship it is a maintainer decision.776a6c0d3, merge base72d143c45, 46 behind currentmain45dc41f95. A trial merge is clean.action_required).Review of
d3d12/apps/leonida/src/run.rs:native_mods_dir,is_native_mod_dll,native_mod_paths) are tested, including that the title's folder is never a default and that sub-folders are ignored.load_native_modsruns after imports are bound and beforespawn_main, as documented.exe_wis leaked deliberately so the pointer outlives the call, andTitleInfocarriesstruct_sizeandversionfor growth.extern "C", which is the same assystemon x64.Points for the maintainer decision:
.dllin%LOCALAPPDATA%\leonida\native-modsis loaded with no opt-in. Any process running as the user can drop a DLL there and have it injected into every run. An opt-in, such as requiringLEONIDA_NATIVE_MODSor a launcher toggle, would close that. Folder trust is the reason I would gate it.DllMainor callback takes the runtime down before theMods:line prints, because the line is printed after the loop. Printing each mod's name before calling it would make crash reports attributable.Verdict: ready on code. Whether native DLL mods are supported, and whether loading is opt-in, is for a maintainer to decide.
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by 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:mainSHA it was merged onto;mainalone 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).
VERIFY-3144 — Windows nativo:
red then greenen las pruebas de los mods nativos776a6c0d3—apps/leonida/src/run.rs(+177),docs/switches.md(5)Ran at the head (the binary's own tests:
-p leonida, not--lib, which finds nothing for a binary crate)Negative control (synthetic): I made
native_mods_dirignore the environment (from_env.filter(|_| false)), rebuilt and ran:It bites.
What the change is, and the review points it answers are the right ones:
native_mods_dir(from_env, local_app_data)takes its two inputs as arguments — so the default folder, the override and "neither" are all testable without setting a variable;the_titles_folder_is_never_the_default— the one that matters: a mod folder inside the title's own directory would be deleted or overwritten by a game update, and the test pins that it is not chosen;is_native_mod_dll—.dllin any case, because a mod authored on a case-insensitive filesystem says.DLL.And a detail worth crediting: the tests are
#[cfg(any(windows, test))], so the helpers exist on non-Windows too for the tests' sake — the same seam#3164was missing tonight.What I could not test
Written with an AI assistant.
This pull request has a merge conflict with current
main(d9b618f10), so it can't be run in game or merged as it is. Could you merge the latestmaininto it (or rebase onto it) and resolve the conflict? Once the head is updated, the in-game gate run can be done on the new head.AI-assisted (Claude Code).
Tres más, estas de dos commits cada una, rebasadas contra
d9b618f10y empujadasEl resolvedor funcionó igual, porque el conflicto de cada commit es la misma línea del recuento (el
whileresuelve y sigue hasta que el rebase termina, en vez de asumir un solo bloque):Las tres: 0 marcadores,
pytest tests/test_d3d12_switches.py20 passed, ycargo test -p leonida-gpu --libcon el fallo de la iGPU de siempre.Y el desglose de tests, que es lo que separa estas tres de
#3009y#3126:leonida-gpu#3144#3171#3248O sea que de las cinco rebasadas hoy, tres no añaden tests (
#3009,#3126,#3144) y dos sí (#3171,#3248) — y todas tocan código de runtime. Quien fusione tiene ahora el dato delante en vez de descubrirlo después.Ramas
pr-3144-rebased,pr-3171-rebasedypr-3248-rebaseden el fork.Lo que esto ya permite decir: de los 22 conflictos, seis están resueltos y empujados (
#3009,#3126,#3140,#3144,#3171,#3248) más los cuatro de antes (#3233,#3253,#3269,#3289) más#3225y#3308— doce en total, y todos con el mismo patrón: una línea del recuento que se recalcula contando el fichero.Lo que no he resuelto: los que chocan en un
.rs(#2567,#2856,#3115,#3197) y los de varios commits con código (#2580,#3124,#3130,#3209,#3214) — esos no son una línea y no los toco sin leer el cambio.Rebased onto current main (b053a1813); head is now c40c78673. Only the generated switches.md conflicted, regenerated. cargo test -p leonida and the switches tests pass.