Skip to content

Architecture

RSMM architecture: front ends, the local Python toolchain, the game install with the loader and Lua SDK, the cloud API, release channels and the shared TypeScript packages

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.

Three goals, in priority order:

  1. Don’t break the game. Mod application must be deterministic and fully reversible.
  2. Stay out of the game’s way. Ravenswatch.exe is 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).
  3. 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.

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.

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:

  1. src/rsmm/engine/find_iyg.py builds the encoded -> decoded map by walking DarkTalesResources/UsedRscList.ot and applying the cipher.
  2. src/rsmm/cli/apply_mods.py walks mods/, parses each manifest, collects override files, and resolves each decoded path to its encoded path. Files under assets/_root/ resolve to the install root instead of _Cooking/.
  3. For each new override: back up the original cooked file to <file>.rsmm.bak, copy the mod’s file into place.
  4. For each previously-active override no longer wanted: restore from .rsmm.bak, delete the backup.
  5. State persists in <install>/DarkTalesResources/_Cooking/.rsmm_state.json.
flowchart LR
    A["mods/&lt;id&gt;/<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["&lt;file&gt;.rsmm.bak"]
    B -->|"copy override"| E["_Cooking/&lt;encoded&gt;"]
    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.

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 disabled

The full layout and the manifest’s [[content]] and [[patch]] tables are in Authoring mods.

[mod]
id = "..."
name = "..."
version = "..."
author = "..."
description = "..."
enabled = true
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.

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.

  • 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-.gen re-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.

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.

  • src/loader/ — winhttp.dll proxy + MinHook + Lua 5.4. This is the runtime for Lua-scripted mods, installed with rsmm install-loader and updated with rsmm update-loader. Asset-only mods do not need it. In the desktop app, update-loader also reinstalls a planted winhttp.dll that matches no published build (another program replaced it); set RSMM_KEEP_LOADER=1 to keep a hand-built DLL in place while testing with the installed app.