victory: add VICTORY_LOAD_DLLS / VICTORY_HOST_EXE_DIR host DLL hook #464

Open
github-bot wants to merge 2 commits from github-bot/gh-464 into main AGit
Owner

@⁠Rockstar-1998 on GitHub · 2026-12-04 13:14 UTC · original
Rockstar-1998:main → main · +75 −0 · 1 files · 2 commits · open

Add an opt-in Windows host DLL loader hook (VICTORY_LOAD_DLLS) before spawning the title's main thread so external tools (e.g. ScriptHook / trainer loaders) can attach cleanly after imports are bound.

  • VICTORY_LOAD_DLLS=<path>;<path>: loads each host DLL via LoadLibraryW and calls victory_on_title_mapped(&TitleInfo) if exported (missing files/exports or non-zero returns are logged and skipped).
  • VICTORY_HOST_EXE_DIR=<dir>: optional directory override for TitleInfo::exe_path (keeping the original executable name), allowing host DLLs to write state outside a read-only game dump directory.
  • No-op when VICTORY_LOAD_DLLS is unset; gated on #[cfg(windows)].
**@⁠Rockstar-1998** on GitHub · 2026-12-04 13:14 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/464) `Rockstar-1998:main` → `main` · +75 −0 · 1 files · 2 commits · open Add an opt-in Windows host DLL loader hook (`VICTORY_LOAD_DLLS`) before spawning the title's main thread so external tools (e.g. ScriptHook / trainer loaders) can attach cleanly after imports are bound. - `VICTORY_LOAD_DLLS=<path>;<path>`: loads each host DLL via `LoadLibraryW` and calls `victory_on_title_mapped(&TitleInfo)` if exported (missing files/exports or non-zero returns are logged and skipped). - `VICTORY_HOST_EXE_DIR=<dir>`: optional directory override for `TitleInfo::exe_path` (keeping the original executable name), allowing host DLLs to write state outside a read-only game dump directory. - No-op when `VICTORY_LOAD_DLLS` is unset; gated on `#[cfg(windows)]`.
victory: add VICTORY_LOAD_DLLS / VICTORY_HOST_EXE_DIR host DLL hook
victory: add VICTORY_LOAD_DLLS / VICTORY_HOST_EXE_DIR host DLL hook
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 13:15:07 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-12-04 13:14 UTC · original · edited 2026-12-04 13:16 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T13:16:54.867273Z 826dcf8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-12-04 13:14 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/464#issuecomment-7412586844) · edited 2026-12-04 13:16 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"826dcf8ae72d0b7f8a47bd9982bcc608660b927a","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-12-04T13:16:54.867273Z">2026-12-04T13:16:54.867273Z</relative-time> | `826dcf8` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-12-04 13:16 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 826dcf8ae7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-12-04 13:16 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/464#pullrequestreview-6189665510) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `826dcf8ae7` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
@ -499,0 +542,4 @@
for path in list.split(';').map(str::trim).filter(|p| !p.is_empty()) {
let path_w = wide(std::ffi::OsStr::new(path));
// SAFETY: a NUL-terminated path; the module stays loaded for the run.
let module = unsafe { LoadLibraryW(path_w.as_ptr()) };
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-12-04 13:16 UTC · original

P2 Badge Search each host DLL's directory for dependencies

When a requested DLL has a private dependency beside it, this LoadLibraryW call resolves that dependency using the host process's normal search order, which does not include the requested DLL's directory. The load then fails and the hook never runs; use a DLL-directory-aware search policy so plugin bundles can load.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-12-04 13:16 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/464#discussion_r4800302155) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Search each host DLL's directory for dependencies** When a requested DLL has a private dependency beside it, this `LoadLibraryW` call resolves that dependency using the host process's normal search order, which does not include the requested DLL's directory. The load then fails and the hook never runs; use a DLL-directory-aware search policy so plugin bundles can load. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 14:17 UTC · original

Tested 826dcf8 natively on Windows (MSVC toolchain from rust-toolchain.toml, not Wine). I didn't launch a game. I drove load_host_dlls directly from a throwaway unit test (not pushed) with small test DLLs built locally as cdylibs. Each one counts its DllMain attach and writes what it receives from victory_on_title_mapped.

With VICTORY_LOAD_DLLS unset the function returns at run.rs:526-528 before doing anything, so the default path is the same as main apart from the call site at run.rs:459-460. cargo test -p victory --bins -- --test-threads=2 gives 27 passed, 0 failed. Clippy has no warnings pointing at run.rs.

What worked

  • Absolute path, path with spaces, forward slashes (C:/.../x.dll) all load. DllMain runs once and the export gets struct_size 32, version 1, and the base, size and exe path passed in.
  • Two entries with stray spaces and an empty entry ( a.dll ;; b.dll ;) load both and skip the blank (run.rs:542).
  • A missing file logs not loaded (... os error 126) and the loop moves on. A DLL with no export (version.dll) logs and moves on. A nonzero return is only logged (run.rs:569-570). The doc comment says those DLLs are "skipped", but nothing runs after the call anyway, so this is just wording.
  • VICTORY_HOST_EXE_DIR only changes the string handed to the DLL (run.rs:530-541). The original file name is kept, and a whitespace-only value falls back to the real exe path. It doesn't touch SetDllDirectory, the current directory or the process search path, so other DLL loads aren't affected.
  • Ordering looks right. The hook runs before spawn_main (run.rs:459-462), and the title DLL attaches, TLS callbacks and entry point all run inside the thread that spawn_main starts (victory-loader/src/windows.rs:402, 405, 412). So host DLLs are notified before any title code runs.

Things I'd change

  1. I can confirm the Codex note on run.rs:545. I built a test DLL that imports a second DLL sitting in the same folder and loaded it by absolute path. It fails with not loaded (os error 126), and the message names the host DLL, not the missing dependency, which is confusing to debug. Swapping in LoadLibraryExW(path, NULL, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS) loaded the same DLL fine in my test. Per the docs those flags also take PATH and the current directory out of the search for the DLL's own dependencies. I didn't test that part.
  2. Relative names go through the normal search order. rel\x.dll resolved against the current directory, and a bare x.dll was picked up from the current directory too. Since the env var is set by the user this isn't a security hole, but a bare name can silently load a different copy depending on where you launched from. With the flags above a relative path is rejected (os error 87, which I saw), so that would also force absolute paths. Logging the resolved module path (GetModuleFileNameW) next to the given name would help either way.
  3. Quoted entries ("C:\Program Files\x.dll" with the quotes) fail with 126 because quotes aren't stripped. Probably fine, but worth a line in the doc since paths copied from Explorer come with quotes.
  4. The same DLL listed twice in one list (a.dll;a.dll) gets victory_on_title_mapped called twice while DllMain runs once, because LoadLibraryW just hands back the loaded module. The init has to be idempotent, or the list could be deduplicated.

Smaller notes

  • DllMain runs under the real loader lock like any LoadLibraryW, and some of our own threads are already running at that point, for example the hang watch (run.rs:443). A host DLL that waits on another thread inside DllMain could hang. That's the usual DllMain rule, but one sentence in the doc pointing people to victory_on_title_mapped for real work would help. I didn't see a hang in testing.
  • run.rs:458 still has the old SAFETY comment right above the new one at 461.
  • TitleInfo and the export signature only exist inside the function (run.rs:513-519, 567). A short doc block with the struct layout would make this easier for DLL authors to use.
  • Both commits are titled "Add files via upload". Squashing them with a real message would be nicer.

Overall the opt-in design is sound and does nothing when unset. Point 1 is the one I'd fix before merging.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-04 14:17 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/464#issuecomment-7414100956) Tested 826dcf8 natively on Windows (MSVC toolchain from rust-toolchain.toml, not Wine). I didn't launch a game. I drove `load_host_dlls` directly from a throwaway unit test (not pushed) with small test DLLs built locally as cdylibs. Each one counts its DllMain attach and writes what it receives from `victory_on_title_mapped`. With `VICTORY_LOAD_DLLS` unset the function returns at run.rs:526-528 before doing anything, so the default path is the same as main apart from the call site at run.rs:459-460. `cargo test -p victory --bins -- --test-threads=2` gives 27 passed, 0 failed. Clippy has no warnings pointing at run.rs. What worked - Absolute path, path with spaces, forward slashes (`C:/.../x.dll`) all load. DllMain runs once and the export gets struct_size 32, version 1, and the base, size and exe path passed in. - Two entries with stray spaces and an empty entry (` a.dll ;; b.dll ;`) load both and skip the blank (run.rs:542). - A missing file logs `not loaded (... os error 126)` and the loop moves on. A DLL with no export (`version.dll`) logs and moves on. A nonzero return is only logged (run.rs:569-570). The doc comment says those DLLs are "skipped", but nothing runs after the call anyway, so this is just wording. - `VICTORY_HOST_EXE_DIR` only changes the string handed to the DLL (run.rs:530-541). The original file name is kept, and a whitespace-only value falls back to the real exe path. It doesn't touch SetDllDirectory, the current directory or the process search path, so other DLL loads aren't affected. - Ordering looks right. The hook runs before `spawn_main` (run.rs:459-462), and the title DLL attaches, TLS callbacks and entry point all run inside the thread that `spawn_main` starts (victory-loader/src/windows.rs:402, 405, 412). So host DLLs are notified before any title code runs. Things I'd change 1. I can confirm the Codex note on run.rs:545. I built a test DLL that imports a second DLL sitting in the same folder and loaded it by absolute path. It fails with `not loaded (os error 126)`, and the message names the host DLL, not the missing dependency, which is confusing to debug. Swapping in `LoadLibraryExW(path, NULL, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS)` loaded the same DLL fine in my test. Per the docs those flags also take PATH and the current directory out of the search for the DLL's own dependencies. I didn't test that part. 2. Relative names go through the normal search order. `rel\x.dll` resolved against the current directory, and a bare `x.dll` was picked up from the current directory too. Since the env var is set by the user this isn't a security hole, but a bare name can silently load a different copy depending on where you launched from. With the flags above a relative path is rejected (os error 87, which I saw), so that would also force absolute paths. Logging the resolved module path (GetModuleFileNameW) next to the given name would help either way. 3. Quoted entries (`"C:\Program Files\x.dll"` with the quotes) fail with 126 because quotes aren't stripped. Probably fine, but worth a line in the doc since paths copied from Explorer come with quotes. 4. The same DLL listed twice in one list (`a.dll;a.dll`) gets `victory_on_title_mapped` called twice while DllMain runs once, because LoadLibraryW just hands back the loaded module. The init has to be idempotent, or the list could be deduplicated. Smaller notes - DllMain runs under the real loader lock like any LoadLibraryW, and some of our own threads are already running at that point, for example the hang watch (run.rs:443). A host DLL that waits on another thread inside DllMain could hang. That's the usual DllMain rule, but one sentence in the doc pointing people to `victory_on_title_mapped` for real work would help. I didn't see a hang in testing. - run.rs:458 still has the old SAFETY comment right above the new one at 461. - `TitleInfo` and the export signature only exist inside the function (run.rs:513-519, 567). A short doc block with the struct layout would make this easier for DLL authors to use. - Both commits are titled "Add files via upload". Squashing them with a real message would be nicer. Overall the opt-in design is sound and does nothing when unset. Point 1 is the one I'd fix before merging. AI-assisted: yes
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/464/head:github-bot/gh-464'
git switch 'github-bot/gh-464'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-464'
git switch 'github-bot/gh-464'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-464'
git switch 'github-bot/gh-464'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-464'
git switch 'main'
git merge --squash 'github-bot/gh-464'
git switch 'main'
git merge --ff-only 'github-bot/gh-464'
git switch 'main'
git merge 'github-bot/gh-464'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.