English
Sign in

Game modules

A game module is an add-on for the game itself, not for a server: a native library that adds a tab of servers to the server browser, a way to reach servers (a transport), folders of content mounted while one of its connections lasts, and a page in the settings. Server plugins are something else (docs/plugins_api.md).

Without a modules/ folder in the user folder nothing of this runs: no file is read, no thread started, and the game is the same as without the module host.

Installing

A module travels as a .csmod, a package signed with its author's Ed25519 key. A player installs it in Settings > Modules > Install a module…, which enables it (it loads at once when no module ran yet, else at the next start). Official modules also install from the WORKSHOP page, for an account that owns the game (docs/workshop_plan.md). Authors make and install them with cs_plugin (docs/plugins_tools.md):

cs_plugin check <folder>            # module.toml and its libraries
cs_plugin pack <folder> [--key FILE] # <id>-<version>.csmod
cs_plugin install <file.csmod> [--user DIR]

install checks the package's signatures and every file's hash, keeps the author's key for the module's updates (modules/authors.toml), and puts the module in <user folder>/modules/<id>/. With it go the package's manifest (.manifest.toml) and its signature (.signature), which the game checks each time it loads the module.

The game loads a module at start-up when:

development = true in modules.toml loads a module that is not signed (a module's author's own copy); the log says so.

A module's folder

<id>/
  module.toml
  lib/linux/<name>.so
  lib/windows/<name>.dll
  lang/en.toml            (its texts: one file a language, optional)
  lang/es.toml
  lang/pt_BR.toml
  ...                     (anything else it needs: content/, data)

module.toml:

id = "hello"            # the folder's name: a-z, 0-9, _
name = "Hello"
version = "1.0.0"
author = "Someone"
description = "What it does."
language = "en"         # the language of its own texts (default en)
api = 1
# Optional: its servers' drop reasons that are passing (a service of
# theirs lost a moment): the game joins the same server again at once,
# twice in two minutes at most. Matched whole, also inside 'Kicked :"..."'.
passing_drops = ["Lost the link for a moment"]

[library]
linux = "lib/linux/hello.so"
windows = "lib/windows/hello.dll"

Languages

A module speaks the language the game shows, without asking the player: host->text(ctx, key) gives a key's text from lang/<language>.toml in its package. The file names are the game's languages (en, es, pt_BR, in any case); anyone can add one, a new file being a new language. A file holds flat keys or tables ([menu] and title is menu.title):

# lang/es.toml
greeting = "¡Hola, {1}!"
"Join a server" = "Entrar a un servidor"   # an English text as its own key

[module]
description = "Lo que hace."               # Settings > Modules shows it

The language's file is read first, then its base's (pt for pt_BR), then the module's own (language in module.toml), so a text missing in one shows in the module's language. A key in no file comes back as it is: a module may write its texts in English and use them as keys, with no en.toml. module.name and module.description replace the manifest's on Settings > Modules. The player may change the language while playing: read host->setting(ctx, "language") each frame and ask for the texts again when it changes (filling in {1}-like values is the module's own). text may be called from any thread.

A module runs native code without a sandbox: it can do whatever the game can. That is why it loads only when the player enabled it and trusts its author.

The ABI

data/module_sdk/cs_module.h, C. The library exports cs_game_module_load(const cs_module_host *) (non-zero: loaded), and optionally cs_game_module_frame(double now) (once a frame) and cs_game_module_unload(void). Every call either way is on the game's main thread; a module may run threads of its own and hand their results over in its frame or with post.

What the game gives (cs_module_host): a log; the module's data folder (<user folder>/module_data/<id>/) and its package folder; the game's settings by console name (name, rate, cl_updaterate, cl_cmdrate, language, cl_lw, cl_lc, model); the player's account certificate; a signature with this computer's key (sign_with_device: the key the certificate names, so a module's own service can tell that the player holds it; what is signed is "CS-MODULE:" + id + "\0" + message, which serves for nothing else); opening an http or https page in the player's browser; and the registrations:

The sample

samples/module/hello (C) has a tab with one server, a page with buttons (one signs with the computer's key) and a text field, and a transport, hello://<demo>, that plays a recorded game (.csdem) back as if a server sent it, with the module's content/ mounted meanwhile. tools/module_test.sh packs, signs, installs and loads it, and checks that a changed package does not install and that a changed library, an author not trusted and a module not enabled do not load.