Mods: LARP_HOST_NAME for mods that only start in a host program they know #87

Manually merged
github merged 1 commit from github-bot/gh-87 into main 2026-12-05 19:01:10 +00:00 AGit
Owner

@⁠kadiratesdev on GitHub · 2026-12-05 18:01 UTC · original
kadiratesdev:feat/host-name → main · +392 −3 · 6 files · 1 commits · merged 2026-12-05 19:00 UTC

Summary

Some proxy DLLs (e.g. a winmm.dll placed beside the program) and native mods
check which program they were loaded into before they do anything: in DllMain
they read GetModuleFileNameW(NULL) and compare the file name against a list of
hosts they were written for. Under larp that name is larp.exe, so such a mod
loads but stays silently inactive, even though everything else it needs (the
title mapped through the loader, its loader notification, its code at the
expected RVAs) is there.

This PR adds an opt-in LARP_HOST_NAME=<file name>. While larp loads mods, the
process' main module is shown under that file name (same folder); right after,
the real name is put back, so larp's own uses of its path (current_exe,
relaunch, nv-profile, Agility SDK lookup) are unaffected. Unset (the default),
nothing is renamed.

Changes

  • apps/larp/src/host_name.rs (new): validates the value (plain file name only),
    and swaps FullDllName / BaseDllName of the main module's loader entry
    (PEB.Ldr, entry whose DllBase == PEB.ImageBaseAddress) under the loader
    lock (LdrLockLoaderLock); a guard puts them back on drop. New strings are
    leaked (a few bytes) so no reader can ever see freed memory.
  • apps/larp/src/main.rs: run --execute applies the name first, then
    advisor::check(), then mods::load_all(guard). The name must be in place
    before advisor::check(): loading the NVIDIA API there pulls in
    nvapi64_impl.dll, which imports winmm.dll, and a winmm.dll beside
    larp.exe is found first and loaded right then. A proxy reads its host's name
    once, when it loads, so it has to see the configured name at that moment.
  • apps/larp/src/mods.rs: load_all() loads, in order, winmm.dll (a proxy
    beside larp.exe, by its full path, or finds it already loaded; else Windows'
    own), MFG Unlocker and mods\, then drops the guard. It logs (INFO) and prints
    one summary line saying which winmm.dll is in use, from where, whether it was
    already loaded at startup, and under which name the program was shown; it warns
    if a winmm.dll exists beside larp.exe but Windows' own was loaded.
  • apps/larp/build.rs: /DELAYLOAD:winmm.dll. larp imports winmm.dll only
    for timeBeginPeriod; with a normal import a proxy's DllMain ran while
    Windows started the process, before larp could do anything.
  • apps/larp/Cargo.toml: windows-sys feature Win32_System_SystemInformation
    (GetSystemDirectoryW, to tell the proxy from Windows' own).
  • docs/environment-variables.md: LARP_HOST_NAME row in "Mods".

Behaviour without the switch

The only change is when winmm.dll is loaded: at the start of run --execute
instead of at process start (other commands load it on first use, if ever).
Load order relative to MFG Unlocker and mods\ is the same as before.

Testing

  • Unit tests (cargo test -p larp, run under Wine for x86_64-pc-windows-msvc):
    name validation, folder kept, and GetModuleFileNameW(NULL) returns the new
    name while renamed and the original one after. 7/7 pass.
  • Built for x86_64-pc-windows-msvc; winmm.dll no longer appears in the
    normal import table (delay-load table instead).
  • With a third-party host-checking winmm.dll proxy beside larp.exe, under
    Wine and on Windows 11 (larp run --execute <missing file>, so no game is
    started): without LARP_HOST_NAME the proxy stays inactive (writes nothing);
    with LARP_HOST_NAME=<a host it lists> it starts (writes its log). On Windows
    the proxy is loaded by nvapi64_impl.dll during advisor::check(), which is
    why the name is applied before it.
  • Verified on real Windows 11 (RTX 3080 Ti) in a full game session with the
    Sirius Turkish subtitle proxy beside larp.exe and LARP_HOST_NAME set to a
    host that proxy lists: the proxy's own log appeared, and the user reported
    that Turkish text appears to work in-game. Fonts and Turkish capitals were
    not checked in detail.

Notes

  • This does not change what the title sees; only mods loaded in that window.
  • Mods that look the name up again later (after load_all) see larp.exe.
**@⁠kadiratesdev** on GitHub · 2026-12-05 18:01 UTC · [original](https://github.com/gamingwithhomie/larp/pull/87) `kadiratesdev:feat/host-name` → `main` · +392 −3 · 6 files · 1 commits · merged 2026-12-05 19:00 UTC ## Summary Some proxy DLLs (e.g. a `winmm.dll` placed beside the program) and native mods check which program they were loaded into before they do anything: in `DllMain` they read `GetModuleFileNameW(NULL)` and compare the file name against a list of hosts they were written for. Under larp that name is `larp.exe`, so such a mod loads but stays silently inactive, even though everything else it needs (the title mapped through the loader, its loader notification, its code at the expected RVAs) is there. This PR adds an opt-in `LARP_HOST_NAME=<file name>`. While larp loads mods, the process' main module is shown under that file name (same folder); right after, the real name is put back, so larp's own uses of its path (`current_exe`, relaunch, `nv-profile`, Agility SDK lookup) are unaffected. Unset (the default), nothing is renamed. ## Changes - `apps/larp/src/host_name.rs` (new): validates the value (plain file name only), and swaps `FullDllName` / `BaseDllName` of the main module's loader entry (`PEB.Ldr`, entry whose `DllBase == PEB.ImageBaseAddress`) under the loader lock (`LdrLockLoaderLock`); a guard puts them back on drop. New strings are leaked (a few bytes) so no reader can ever see freed memory. - `apps/larp/src/main.rs`: `run --execute` applies the name first, then `advisor::check()`, then `mods::load_all(guard)`. The name must be in place before `advisor::check()`: loading the NVIDIA API there pulls in `nvapi64_impl.dll`, which imports `winmm.dll`, and a `winmm.dll` beside `larp.exe` is found first and loaded right then. A proxy reads its host's name once, when it loads, so it has to see the configured name at that moment. - `apps/larp/src/mods.rs`: `load_all()` loads, in order, `winmm.dll` (a proxy beside `larp.exe`, by its full path, or finds it already loaded; else Windows' own), MFG Unlocker and `mods\`, then drops the guard. It logs (INFO) and prints one summary line saying which `winmm.dll` is in use, from where, whether it was already loaded at startup, and under which name the program was shown; it warns if a `winmm.dll` exists beside `larp.exe` but Windows' own was loaded. - `apps/larp/build.rs`: `/DELAYLOAD:winmm.dll`. larp imports `winmm.dll` only for `timeBeginPeriod`; with a normal import a proxy's `DllMain` ran while Windows started the process, before larp could do anything. - `apps/larp/Cargo.toml`: windows-sys feature `Win32_System_SystemInformation` (`GetSystemDirectoryW`, to tell the proxy from Windows' own). - `docs/environment-variables.md`: `LARP_HOST_NAME` row in "Mods". ## Behaviour without the switch The only change is when `winmm.dll` is loaded: at the start of `run --execute` instead of at process start (other commands load it on first use, if ever). Load order relative to MFG Unlocker and `mods\` is the same as before. ## Testing - Unit tests (`cargo test -p larp`, run under Wine for x86_64-pc-windows-msvc): name validation, folder kept, and `GetModuleFileNameW(NULL)` returns the new name while renamed and the original one after. 7/7 pass. - Built for x86_64-pc-windows-msvc; `winmm.dll` no longer appears in the normal import table (delay-load table instead). - With a third-party host-checking `winmm.dll` proxy beside `larp.exe`, under Wine and on Windows 11 (`larp run --execute <missing file>`, so no game is started): without `LARP_HOST_NAME` the proxy stays inactive (writes nothing); with `LARP_HOST_NAME=<a host it lists>` it starts (writes its log). On Windows the proxy is loaded by `nvapi64_impl.dll` during `advisor::check()`, which is why the name is applied before it. - Verified on real Windows 11 (RTX 3080 Ti) in a full game session with the Sirius Turkish subtitle proxy beside `larp.exe` and `LARP_HOST_NAME` set to a host that proxy lists: the proxy's own log appeared, and the user reported that Turkish text appears to work in-game. Fonts and Turkish capitals were not checked in detail. ## Notes - This does not change what the title sees; only mods loaded in that window. - Mods that look the name up again later (after `load_all`) see `larp.exe`.
Some proxy DLLs and mods only start in a host program they know: in DllMain
they read GetModuleFileNameW(NULL) and stay inactive otherwise. Windows takes
that name from the main module's loader entry. With LARP_HOST_NAME set, the
entry's FullDllName/BaseDllName carry that file name (same folder), swapped
under the loader lock, from the start of `run --execute` until the mods are
loaded, and then put back.

It starts before advisor::check: a library loaded early (the NVIDIA API) can
pull a winmm.dll proxy beside larp.exe in as its own dependency, and the proxy
reads the host's name once, when it loads.

winmm.dll is now delay-loaded; mods::load_all loads a proxy beside larp.exe by
its full path (or finds it already loaded), before MFG Unlocker and mods\, and
logs and prints which winmm.dll is in use, from where, and under which name.
Unset, behaviour is otherwise unchanged.

Tests (under Wine): GetModuleFileNameW(NULL) follows the name and comes back.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 18:03:36 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-12-05 18:01 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-12-05 18:01 UTC · [original](https://github.com/gamingwithhomie/larp/pull/87#pullrequestreview-6204959752) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
github manually merged commit b2aba8f20f into main 2026-12-05 19:01:08 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.