Skip to content

Creating Mods

A mod is a folder or a .zip archive with a mod.json manifest, Lua 5.5 scripts, and files that replace or add game assets. Through the obm Lua table a mod can read and change the running mission, draw its own HUD and Dear ImGui windows, replace the game's textures, sounds and disc files, add .glb models and props, become a gamemode with its own rules and saves, and talk to the compiled mission scripts through their 716 script interfaces. Mods run in the SDL3 port only; the PlayStation 2 build has no mod support.

Several features of the port are mods written against the same API: the live rating, the cheat menu, photo mode, Instinct, slow aim, the alternative HUD styles (Reprisal and World of Assassination) and the Randomiser gamemode. They are the built-in mods in port/builtin_mods/, and the clearest examples of the API in use.

  • For new levels with their own geometry, characters and mission, see New Levels.
  • For how the engine underneath works, see Glacier Internals.
Page Contents
Built-in Mods The seven mods the port ships, their settings and bindings, and how they differ from user mods
The Manifest mod.json: the id and card, the entry script, dependencies and conflicts, settings, key bindings, gamemodes and custom levels
Assets and Models Replacing textures, sounds and disc files, and adding or replacing .glb models
The Lua Runtime Events and the order they run in, the sandbox, instruction and memory budgets, errors, limits, API versions and the security model
API Reference Every table and function of obm, from obm.world and obm.player to obm.hud, obm.ui, obm.debug and obm.net
Console, Testing and Hotkeys The F12 console, test runs from a working folder, environment variables, hotkeys and community contracts
Example Mods The 20 example mods in port/mods/examples/ and what each shows
The Randomiser The built-in Randomiser gamemode: presets, what each layer changes, how its rules are checked, seed codes, and curating a level's data

Quick start

Create hello_world in the mods/ folder of your user directory with these two files. See Where mods live.

mods/
  hello_world/
    mod.json
    scripts/main.lua

mod.json:

{
  "schema_version": 1,
  "id": "example.hello_world",
  "name": "Hello World",
  "version": "1.0.0",
  "author": "You",
  "description": "Shows the scene name and counts kills."
}

scripts/main.lua (the default entry file, so mod.json does not need an entry):

local kills = 0

obm.on("scene_loaded", function(scene)
  kills = 0
  obm.log("entered " .. scene)
end)

obm.on("actor_killed", function(actor)
  kills = kills + 1
end)

obm.on("hud_draw", function()
  if not obm.scene.is_gameplay() then return end
  local size = obm.hud.size()
  obm.hud.text(size.w * 0.02, size.h * 0.02, size.h * 0.02, 0xf2eee6, 1.0,
               string.format("%s  kills: %d", obm.scene.name(), kills))
end)

Start the port, open MODS in the launcher and enable "Hello World" (new mods start disabled), then play a mission. To enable it without the launcher, start the port with OPENBLOOD_ENABLE_MOD=example.hello_world.

In the mission:

  • F12 opens the mod console. print output appears there and in the SDL log (the terminal the port runs in); obm.log goes to the SDL log; errors appear in both. The REPL tab runs Lua, for example return obm.world.player().x.
  • Edit main.lua and press F6 to reload every mod without leaving the mission.

Editor support

modsdk/obm.lua, at the top of every release archive (in the repository, port/modsdk/obm.lua), declares the whole obm API for lua-language-server, the language server behind the Lua extension for VS Code; other editors with LSP support can run it too. It gives every function's parameters and results, the fields of the tables the API returns (obm.world.player(), obm.world.actor(ref), obm.rating.live()...), the arguments obm.on passes to each event's listener, the tables obm.mission.define, obm.projectiles.spawn and obm.scripts.replace take, and a description of each.

Put a .luarc.json beside the mod's mod.json and open that folder in the editor:

{
  "runtime.version": "Lua 5.5",
  "runtime.path": ["scripts/?.lua", "?.lua"],
  "runtime.builtin": { "io": "disable", "os": "disable", "package": "disable", "debug": "disable" },
  "workspace.library": ["C:/Games/Open Blood Money/modsdk"]
}

workspace.library names the folder that holds obm.lua. runtime.path makes require find a module where the port does (scripts/<name>.lua, then <name>.lua), and runtime.builtin removes the libraries the sandbox leaves out. The repository's own .luarc.json does the same for the built-in and example mods.

The editor then completes obm. names, shows each function's description, and warns about an unknown function or field, an argument of the wrong type, and a result that can be nil used without a test (obm.world.player() is nil in a menu). Functions that return several values that are all nil together are typed so that testing one is enough: the first value of obm.world.get_pos, obm.player.get_forward, obm.ai.get_forward and obm.net.poll, and the third (on_screen) of obm.hud.world_to_screen. Script interfaces (obm.api.<Name>) are typed only as functions of integers, numbers and strings; obm.scripts.signature gives their parameters.

Where mods live

See Where your files are for the user directory on each platform.

Path in the user directory Contents
mods/ Installed mods: folders with a mod.json, or .zip or .obmod archives (on Android, in the app's external storage)
obm.config.json Load order, enabled mods, the active gamemode and mod settings
mod_saves/<mod id>/<key>.json What obm.storage.write stores
mod_saves/<gamemode id>/ The game's saves while a gamemode with separate_save is active
contracts/*.json Community contracts (on Android, in the app's external storage)

The port looks for mods in three places, in this order:

  1. the folder named by OPENBLOOD_MODS_DIR, if set;
  2. mods/ in the user directory (app external storage on Android);
  3. mods/ next to the executable.

In each folder, every subfolder and every .zip or .obmod file is a candidate, up to 256 entries per folder. .obmod is a .zip with another extension. In an archive, mod.json may be at the root or inside one top-level folder (my_mod/mod.json); paths in the mod are relative to the folder that holds mod.json.

Two packages with the same id: the one found first is used and the second is rejected, with the reason on its card. Within a folder, packages are taken in file-name order. A package whose mod.json is missing, is not valid JSON or has an invalid id is listed with the error and never loaded. At most 64 mods are listed.

With --no-mods or OPENBLOOD_NO_MODS=1 (safe mode), the port does not scan any mods folder: no user mod is listed, loaded or used for file overrides. The built-in mods still load, since they are part of the port.

Enabling, order and gamemodes

Copy a mod folder or ZIP into the user directory’s mods/ folder. Enable it on the Mods screen. Q/E or the shoulder buttons change load order. When several gamemodes are installed, select the active one there.

A mod is active when it is enabled, it is not a gamemode or it is the selected gamemode, all its dependencies are active and no active mod conflicts with it. Only active mods run scripts or override files.

  • Scripts load in list order, top to bottom, except that a mod's dependencies load before it: the list is sorted so that dependencies come first and the order is otherwise kept. Mods in a dependency cycle are not loaded. The listeners for any one event run in load order.
  • File overrides: when several active mods contain the same path, the one that loads last (normally the lowest in the list) wins.
  • A mod with a gamemode block is a gamemode. Only one gamemode, or the stock campaign, runs at a time: ACTIVE GAMEMODE on the MODS screen chooses it among the enabled gamemodes. Enabling a gamemode when none is selected selects it.
  • A mod whose dependency is missing or not active, or that conflicts with an active mod, is not activated; its card says why.

Where the code is

The code is in port/engine/mods/_sdl/. The game reaches it through the functions the port replaces (OBM_FN definitions in src/, listed in port/overrides.json; see overrides.md), so the PS2 build is unchanged.

File What it does
modmanager.cpp Finds mods, reads mod.json, keeps the list, enabled flags and load order, settings, gamemodes and custom levels, and resolves file overrides (the mod file system)
modlua.cpp The Lua runtime: sandbox, obm table, events, the runtime systems behind the API (patrols, projectiles, ghosts, lights, actions), the .c script bridge and the F12 console
modluagame.cpp Bindings, gamepad and mouse input, pausing, debug overlay tabs, cheats, quick save, movies, highlights and the other helpers the built-in mods are made of
modluaworld.cpp, modluapresentation.cpp World queries, cameras and presentation
modluagameplay.cpp, modluaequipment.cpp Gameplay and equipment bindings
modluascripts.cpp, modluamission.cpp Scene script hooks and mission helpers
modluaconsole.cpp Lua console bindings
modglb.cpp, modglbparse.cpp .glb loading, model replacement, props and obm.draw3d
modcontracts.cpp Community contract files
modnet.cpp UDP sockets for obm.net
modjson.cpp, modzip.cpp JSON reader and writer, .zip reader