Architecture
System map
Section titled “System map”
The desktop app and the terminal both drive the same Python CLI; the app bundles it as a PyInstaller sidecar. The rest of this page covers the asset path: how the CLI applies a mod to the game install. See SETUP.md for the repo layout.
Threat model / scope
Section titled “Threat model / scope”Three goals, in priority order:
- Don’t break the game. Mod application must be deterministic and fully reversible.
- Stay out of the game’s way.
Ravenswatch.exeis never modified. Asset mods never touch the running game: they replace data files at install time. Only Lua mods need the optional loader, which hooks a small set of game functions in memory (see Loader compatibility). - Treat a downloaded mod as hostile input. A mod archive comes from
a third party over the network. It must not be able to write outside
mods/, delete anything, ship an executable, or exhaust the disk.
Untrusted archives
Section titled “Untrusted archives”Everything that unpacks a downloaded mod — rsmm install, rsmm update
and the desktop bridge’s json install-mod — goes through one extractor,
rsmm.sdk.archive. It was previously three separate copies that had
drifted apart, which is why the rules now live in a single module:
| Guard | What it stops |
|---|---|
Component-wise containment check (is_relative_to, not startswith) |
Zip-slip, including escapes into a sibling dir sharing the prefix (mods/ → mods-evil/) |
Members read with ZipFile.open and written as regular files |
A symlink member becoming a real symlink that a later member writes through |
safe_dir_name on every id/slug joined onto mods/ |
An archive whose members all start with ../ yielding the mod id .., which --force then deletes |
| Entry count / uncompressed size / compression-ratio caps | Decompression bombs |
DANGEROUS_EXTENSIONS refusal |
Mods shipping .exe / .dll / .ps1 / .sh payloads — including under _root/, which has no exemption |
Every _root/ member reported |
Silently overwriting files in the game install root |
| Staged unpack + swap into place | A corrupt or rejected download destroying a working install as a side effect of failing |
Transport is https-only (file://, and plain HTTP against loopback, are
allowed for offline installs and local development). Downloads are size
capped and time bounded. Integrity is SHA-256 from repo.json plus an
optional Ed25519 signature — see rsmm.sdk.repo.
How v1 works
Section titled “How v1 works”The engine loads every cooked asset from
<install>/DarkTalesResources/_Cooking/<encoded>. <encoded> is the
asset’s filename run through a fixed substitution cipher
(src/rsmm/engine/cipher.py). The cooked bytes have no checksum, signature, or
embedded path; any byte-compatible file at the encoded path is accepted.
Therefore v1 is purely an install-time file applier:
src/rsmm/engine/find_iyg.pybuilds theencoded -> decodedmap by walkingDarkTalesResources/UsedRscList.otand applying the cipher.src/rsmm/cli/apply_mods.pywalksmods/, parses each manifest, collects override files, and resolves each decoded path to its encoded path. Files underassets/_root/resolve to the install root instead of_Cooking/.- For each new override: back up the original cooked file to
<file>.rsmm.bak, copy the mod’s file into place. - For each previously-active override no longer wanted: restore from
.rsmm.bak, delete the backup. - State persists in
<install>/DarkTalesResources/_Cooking/.rsmm_state.json.
flowchart LR
A["mods/<id>/<br/>manifest.toml + assets"] --> B["apply_mods.py"]
M["UsedRscList.ot"] -->|"substitution cipher<br/>(find_iyg.py)"| C["asset_map.json<br/>decoded → encoded"]
C --> B
B -->|"back up original"| D["<file>.rsmm.bak"]
B -->|"copy override"| E["_Cooking/<encoded>"]
B --> F[".rsmm_state.json"]
G["./rsmm restore --all"] -->|"restore from .bak"| E
Asset mods load no DLL into the game process and hook no engine function.
Removing the manager is ./rsmm restore --all.
Mod format
Section titled “Mod format”mods/<id>/ manifest.toml assets/ <decoded path>/<file> e.g. Ui/BookMenu/Heroes/UI_HeroPortrait_Romeo_Active.png.Texture.dxt _root/<path> files at the install root, e.g. _root/DarkTalesResources/ApplicationSettings.ot init.lua Lua mods only: run by the loader DLL on_disable.py optional cleanup hook when the mod is disabledThe full layout and the manifest’s [[content]] and [[patch]] tables are in
Authoring mods.
[mod]id = "..."name = "..."version = "..."author = "..."description = "..."enabled = trueState + backups
Section titled “State + backups”DarkTalesResources/_Cooking/.rsmm_state.json{ "version": 1, "active": { "<encoded path>": { "mod": "<mod id>", "src_sha1": "<sha1 of mod file>", "orig_sha1": "<sha1 of original cooked file>" }, ... }}Backups live next to their originals as <file>.rsmm.bak. The applier
diffs the wanted set against the active set on every run; a no-op run is
a no-op.
Asset map
Section titled “Asset map”data/asset_map.json (and data/asset_map.csv) is generated by
src/rsmm/engine/find_iyg.py. The cipher lives in src/rsmm/engine/cipher.py
as separate letter-for-letter tables for lower and upper case (LOWER_DECODE,
UPPER_DECODE). Regenerate after a game update if UsedRscList.ot changes.
What v1 cannot do
Section titled “What v1 cannot do”- Build a cooked file from nothing. New items, heroes, enemies and
the like are made by the SDK content kinds, which cook a copy of a shipped
file and edit it (see Authoring mods). A free-form
text-
.ot-> binary-.genre-encoder for arbitrary classes is still not built. - Toggle mods mid-session. Install is still install-time: the Off/On row on the in-game Mods page takes effect at the next launch.
v2: in-game UI
Section titled “v2: in-game UI”The plan written here was to edit the cooked MainMenu asset and inject a Mods
tab through a text-.ot re-encoder. It was dropped. The Mods menu that shipped
is built at runtime by the loader instead: Settings → Mods opens a second
System book page drawn by R.ui.menus, with no cooked asset changed. See
UI & the book menu for what the data-only
attempt taught.
The loader, and a parked subsystem
Section titled “The loader, and a parked subsystem”src/loader/— winhttp.dll proxy + MinHook + Lua 5.4. This is the runtime for Lua-scripted mods, installed withrsmm install-loaderand updated withrsmm update-loader. Asset-only mods do not need it. In the desktop app,update-loaderalso reinstalls a plantedwinhttp.dllthat matches no published build (another program replaced it); setRSMM_KEEP_LOADER=1to keep a hand-built DLL in place while testing with the installed app.
