Docs / Plugins / Writing plugins
Compiled plugins
An .oop is to a plugin what a DLL is to a program, but sandboxed. It holds build output, not sources, and one file runs on every system.
| Kind | Source | In the .oop |
|---|---|---|
| Lua | .lua files |
one obfuscated chunk: locals renamed, strings encoded, modules bundled |
| WebAssembly | usually Rust, built for wasm32-unknown-unknown |
a stripped module |
A compiled Lua plugin behaves as its sources did, through the same API. Compiled Lua bytecode is refused, because crafted bytecode could break out of the sandbox.
A WebAssembly module calls every API function by its name (openomsi.call("ui.set", ...), arguments and results as JSON) and gets the same events, timers and watches. It runs in an interpreter (wasmi) on every system the game runs on. A call into it that runs too long stops the plugin, not the game, and it may use 256 MB of memory.
A callback the module's own call causes (its emit reaching its own handler) runs right after that call returns.
Build one#
Get the openOMSI Development Tools: a desktop app with an editor, and oopc, the same compiler on the command line.
In the app:
- Press New plugin, give it a name, choose Lua or Rust, and press Create plugin.
- Press Run in openOMSI. The first time, the app asks where openOMSI is. It copies the plugin into the game's
pluginsfolder and starts the game. With Live on, every save reaches the running game. - On the Details page, tick the permissions the plugin needs. Match my code ticks exactly what the code uses.
- On Build and publish, choose whether to sign, and press Build. The result is one
.oopfile.
From a terminal:
oopc new hello --lua # or --rust
oopc build hello # writes the .oop into hello/dist/
oopc check hello # lint: ids, versions, Lua syntax, permissions| Command | What it does |
|---|---|
oopc new <dir> --lua / --rust |
start a project from a template |
oopc build [dir] |
compile and pack into dist/; --sign <key> signs, -o <file> names the output |
oopc check [dir] |
lint the project |
oopc keygen |
make a signing key |
oopc sign <file.oop> --key <key> |
sign or re-sign a file |
oopc verify <file.oop> [--key <pub>] |
check the signature |
oopc inspect <file.oop> |
show the header and the file list |
oopc pack <dir> |
pack already prepared files |
A Rust plugin also needs the Rust toolchain and the wasm32-unknown-unknown target; the app's Settings installs the target.
A minimal Rust plugin#
Cargo.toml:
[package]
name = "hello"
version = "0.1.0"
edition = "2024"
[lib]
crate-type = ["cdylib"]
[dependencies]
openomsi-plugin-sdk = { git = "https://github.com/openOMSI-org/openOMSI-Development-Tools" }
[workspace]
[profile.release]
opt-level = "z"
lto = true
strip = true
panic = "abort"src/lib.rs:
use openomsi_plugin_sdk as omsi;
omsi::plugin!(|| {
// When the player gets into a bus, greet them by its name.
omsi::on_vehicle(|name| {
if let Some(name) = name {
let _ = omsi::api::message(&format!("Good morning! Today you drive the {name}"), Some(6.0));
}
});
// Once a second, warn if the bus is going too fast.
omsi::every(1.0, || {
if let Ok(Some(kmh)) = omsi::api::var("Velocity")
&& kmh > 50.0
{
let _ = omsi::api::message(&format!("Slow down: {kmh:.0} km/h"), Some(1.0));
}
});
});The SDK's plugin! defines the exports the game calls. omsi::api has a typed function for every API call; omsi::call(name, json!([...])) reaches any function by name, even one newer than the SDK.
The plugin manifest#
A compiled plugin's project has an openomsi-plugin.toml. Its [plugin] table becomes the .oop's header.
[plugin]
id = "com.author.hello"
name = "Hello"
version = "1.0.0"
kind = "lua" # or "rust"
entry = "main.lua" # Lua only
authors = ["you"]
description = "Greets the driver and warns above 50 km/h."
min_openomsi = "0.2.21"
permissions = ["ui"]
license = "MIT"
homepage = "https://example.org/hello"
[lua]
obfuscation_level = 2| Field | Required | Meaning |
|---|---|---|
id |
yes | reverse-domain id, com.author.name |
name |
yes | display name |
version |
yes | MAJOR.MINOR.PATCH |
kind |
yes | lua or rust |
entry |
no | Lua entry file, default main.lua |
authors |
no | list of names |
description |
no | a sentence or two |
min_openomsi |
no | the oldest openOMSI it supports |
permissions |
no | what it may do (see Permissions) |
license |
no | SPDX licence id |
homepage |
no | a web address |
[lua] option |
Meaning |
|---|---|
obfuscation_level |
0 strips formatting only, 1 renames, 2 (default) also encodes strings and numbers |
[rust] option |
Meaning |
|---|---|
features |
extra Cargo features for the build |
A Lua plugin in the catalog uses a different file, plugin.json. A theme uses theme.json (Interface themes).
What the game does with an .oop#
- It checks the whole file before any of it runs. A file changed after it was built, cut short, larger than 512 MB, or made for a newer plugin API is refused, and the log says why.
- The code stays in memory. The plugin's pictures, sounds and data files are unpacked to
plugins/.oop-cache/<name>/, where its API functions read them. - It applies the declared permissions.
- A signed plugin is logged with its author's key fingerprint (
signed by 3097:e2de:e2cb:4a34). An unsigned one is logged with a warning that its builder is unknown.
The file is encrypted, but the key is in the game, so it can be decrypted with effort. What one gets then is the stripped or obfuscated build output, never the author's sources.
Signing#
- In the app, open Signing keys and press New key, once. Keep the secret key private and back it up. The public half (
.oopkey.pub) is safe to share. - Turn on Sign this build when you build. From a terminal:
oopc build --sign <your.oopkey>. - Publish your key's fingerprint somewhere players trust. They can then confirm in the log that a plugin is yours and unchanged.
Something wrong or missing? Fix it on GitHub or open an issue.