English
Sign in

Plugin host: core design

The first step of the plugin suite (docs/plugins_plan.md, phase 1). It fixes how plugins are found, run, isolated and called, and the shape of the API every later phase extends.

1. Where things live

pathwhat
native/third_party/luau/Luau 0.743 (MIT): Common, Ast, Bytecode, Compiler, VM. Built as cs_luau.
native/game/src/plugins/The host, inside the game (it has the players, the rules and the entities, and calls the engine directly).
native/game/src/plugins/api.tomlThe API schema: functions, classes, events, option tables.
tools/gen_plugin_api.pyGenerates from the schema the C++ bindings (plugins/generated/bindings.inc), the Luau type definitions (data/plugin_sdk/cs.d.luau) and the reference (docs/plugins_reference.md). The generated files are committed; --check fails when they are stale.
<user>/plugins/<name>/, data/plugins/<name>/Installed plugins (the user's folder wins by name).
<user>/plugin_data/<name>/The only place a plugin may write (kept apart, so a plugin folder can be replaced whole).

2. A plugin

plugins/hello/
  plugin.toml
  main.luau
  lib/greetings.luau      (require("./lib/greetings"))
name = "hello"            # folder name; [a-z0-9_]
version = "1.0.0"
author = "someone"
description = "Says hello."
api = 1                   # the API version it was written for
main = "main.luau"        # default
enabled = true            # false: installed, not loaded
depends = []              # plugins that must load first (S4c)
permissions = []          # "raw_properties", "raw_sockets", "raw_messages", "server_console"
hosts = []                # what its network may reach (section 5m)
cs.on("player_join", function(ev)
	cs.chat(ev.player, "{green}Hello{default}, " .. ev.player.name)
end)

cs.command("hello", function(player, args)
	cs.reply(player, "hello " .. (args[1] or "world"))
end, { help = "says hello" })

3. Running plugins

4. Events

Phase 1 events: plugin_start, plugin_end (the plugin's own), map_start, map_end, frame, player_connect (before: ev:reject(reason)), player_join, player_leave (ev.map_change: a map change makes every player leave and connect again), chat (before: block hides the line; ev.text, ev.team, read only in this phase), cvar_change. Bots join like players (player_connect after, player_join).

5. Phase 1 API

5b. Phase 2 API: the world, game events, rules, menus, notices

The full list, with every field and option, is docs/plugins_reference.md (generated); this is the shape of it.

Two rules of the host matter here: a hook added while its own event runs starts after that event (a hook for another event starts at once; add hooks at load time, and switch them with a flag); and the cs table's chains (cs.game.rounds) are looked up on every use, never cached when the chunk loads.

5b2. Content: models, sprites and sounds

A plugin may bring its own files in a content/ folder beside main.luau (content/models/..., content/sprites/..., content/sound/...). The folder joins the game's search path at the lowest priority, so it never replaces a game file. cs.precache(path) readies one (a model or sprite, a sound under sound/, or any other file players should download) and works only inside a map_start handler; it returns false when the file is missing. Players without the file download it like a map's own resources, and check it: the resource list carries the SHA-256 of each file found in a plugin's content/ (reserved byte 0 0xC5, then 31 bytes of the hash; files the consistency list checks keep its marks), and a client keeps a download only when its hash matches (a wrong copy from the web mirror, sv_downloadurl, is refused and asked of the server itself). The files' licence goes in plugin.toml (content_license = "CC-BY-4.0") or a content/LICENSE; the host warns when there is none, and plugin info shows it.

5c. Data: files and JSON

Each plugin has a data folder, <user folder>/plugin_data/<plugin>/, made when first used; it never sees anything outside it. Paths are relative, /-separated, made of letters, digits, _, - and . (no part starting or ending with ., none named as a Windows device: con, nul, aux, prn, com1...), at most 8 levels and 200 characters; anything else is an error.

5d. Movement

5e. What one player sees, effects

5f. HTTP

cs.http(url, {method, body, headers, timeout}, callback) sends an http:// or https:// request (a web API) to a host the manifest lists (section 5m). The callback gets {status, ok, body, headers, error} on a later frame, never inside the call. Each request is one connection on the network thread, closed after the answer (8 MB at most, 64 connections at once per plugin, 10 s by default). An unloaded plugin's requests are dropped.

5g. Bots a plugin moves

cs.add_bot(name, {team, model}) adds a bot no AI drives (a replay): not solid, not hurt, never moved by the game, nothing in the world reacts to it, and it stays where bot:pose({origin, angles, velocity, buttons, ducking, on_ground, teleport}) puts it. The game animates it from the pose (running, crouching, a jump when it leaves the ground); spectators can watch it. player.puppet tells such a bot; bot:kick() removes it, and a plugin's bots go when it unloads.

5h. Sounds, voices, the scoreboard, maps

player.hear_players = false keeps the other players' sounds from that player (steps, weapons, shots and their events; a weapon's sounds count as its owner's); they still hear their own, and as spectators the player they watch. player:mute_voice(speaker, true) silences one voice for one listener, on top of the game's voice rules. Setting frags or deaths updates everyone's scoreboard at once. cs.maps() lists the loadable maps; cs.game.description (at most 63 characters) is the server list's Mode while no mode runs (a running mode's title goes first), until the plugin that set it unloads.

5i. Key binds, a player's own sounds, the takeoff

A command named +name / -name is a key's press and release (bind mouse3 +hook), from the console only. player:play_sound(sample, {pitch}) plays a sound only that player hears, not placed in the world. player_move gives with jumped the takeoff: jump_origin and jump_velocity, the velocity right after the jump, before the rest of the move (jump stats, FOG).

5j. The event model (S1)

Every event can have both sides: before handlers (by priority) may change the writable fields and, where the event is blockable, ev:block(); then the game acts; then the after handlers see the result. A blocked event has no after side. Events with an entity filter take { class = "...", entity = e } in the hook options, so a handler on think for func_door costs nothing for the other entities.

tools/plugin_events_test.sh runs the events test plugin on cs_office with four bots: blocking, changing and the after side of each group. plugin prof [reset] shows each plugin's handler calls and time per event and per server frame; tools/plugin_bench.sh runs 20 bots with and without twenty handlers on the busiest events (2026-10-22: about 30 us a frame, tick 0.14 to 0.18 ms average).

5k. Properties, raw access and the game objects (S2)

Every entity variable is an Entity property under our name (next_think, view_offset, iuser1...); the ones without a hand-written property are generated from the [[entvar]] table in api.toml.

Raw access reads and writes any field by name: the entity variables and every public member of the game's classes (players, weapons, grenades, hostages, doors, trains... and the game rules), found by the generator in the game's headers. It needs permissions = ["raw_properties"] in plugin.toml, since a member may hold what the game expects to stay consistent.

ent:get("m_iTeam")                  -- a member of the entity's class
ent:set("health", 50)               -- our name, `pev_health` or `EV_FL_health`
ent:get("controller", 2)            -- an element (1-based)
ent:get("EV_BYTE_controller2")      -- the same element by its classic name
cs.game:set("m_iRoundTime", 120)    -- a member of the game rules
for _, f in cs.fields(ent) do ... end -- name, class, type, count, writable, classic

Each name resolves to the member of the entity's actual class (checked at run time); a name of another class, an index out of range, a value of the wrong type and a read-only field are errors that name the call and the field. The kinds are integer, number, boolean, vector, string (string_t and char arrays) and Entity (pointers and handles; setting one checks the entity's class). The generator's kind of each member is checked against its C++ type at compile time. docs/plugins_fields.md lists every field with its classic names; S7's get_member/get_entvar and S8's translator use the same table.

The game objects stay valid while their entity exists: Player.active_weapon, Player:weapons() and Entity.weapon give a Weapon (clip, ammo, timers, recoil state, silencer and burst modes, top speed); cs.grenades() and Entity.grenade a Grenade (kind, thrower, fuse, damage, detonate()); cs.game.bomb the planted Bomb (planter, site, explode time, defuser), cs.game.bomb_carrier who carries the C4; cs.hostages() and Entity.hostage a Hostage (leader, settable, alive, rescued); cs.team("t"|"ct") a Team (score, count, alive, players).

tools/plugin_bots_test.sh fields runs the fields test plugin on cs_office with four bots: every entity variable, player, weapon and rules member read, written back and read again (about 1,850 values), the properties against raw, the classic names, the refusals and each object.

5l. Movement and visibility (S3)

player:set_movement({...}) gives one player their own movement: accelerate, air_accelerate, friction, stop_speed, jump_height, bhop_cap (0: no bunny hop cap), auto_bhop, stamina (the slowdown after landing and jumping), max_velocity, ladder_speed, duck_speed, swim_speed, can_jump, can_duck. Given fields replace the server's for that player, the others stay; player:movement() reads what is in effect, player:reset_movement() goes back to the server's. Gravity and top speed stay player.gravity and player.maxspeed.

ramp_fix (off by default) is for surf and slide servers. A badly built slide ramp can have seams where a fast slide hits the next brush's edge and stops dead in the middle of the ramp; with ramp_fix the player slides on instead. It only acts when a move along a slide ramp (steeper than a floor, not a wall) makes no progress at all from at least 200 u/s, so walls (wall bugs), floors, pixel surf and every move that goes anywhere stay exactly as they are. Like the other settings it is predicted, so the player sees no correction.

They are short keys in the player's physics info (\mv\1\jh\60...), which the client receives in its clientdata; the shared movement code reads them once at the start of each move (movement::load_tuning) on the server and in the prediction, so a player with their own settings is predicted exactly. A player without any pays one string search per move and moves exactly as before (the oracles stay at zero). Everything has to fit the 256 bytes of the physics info: a call that would not fit changes nothing and fails.

The move tells what it did, from each command (any frame rate): player_jump (takeoff origin and velocity), player_land (fall speed), player_ladder (on or off), player_water (level and old level) and player_duck (ducked or stood up). They are told after the move, not before: what a server handler changed inside a move would not be in the client's prediction. Changing how a player moves goes through the settings above (predicted), and S9's shared movement scripts.

entity_visible is AddToFullPack's place: before each entity goes into what one player is sent, its handlers may change how that player sees it (origin, model, skin, body, effects, render mode, amount, fx and color) or block it (that player is not sent it). It runs once per viewer and entity, only while some plugin listens; { class = } and { entity = } filter it. Player:hide and Player:render stay the cheap way for fixed choices.

cs.game.semiclip is off, team (teammates pass through each other) or all. Living players under the rule leave each other out of their movement and reach each other's clients as not solid, so the prediction agrees; bullets still hit. Player:pass_through adds single pairs.

tools/plugin_move_test.sh runs the movement test plugin with a predicting network client (port 27018). On cs_office the client moves with its own settings (auto bunny hop, jump height 60, air acceleration 150, no stamina...) through a frozen bot kept in its way with semiclip on, while two other bots reach it changed and hidden; the prediction must stay as exact as without plugins (2026-10-22: 2 of 3131 off, the same as the base; with semiclip off 10, with the client not reading its settings 13), and the client must see the bots as the plugin chose. On as_oilrig the client is put in deep water and on a ladder.

5m. Services: I/O threads, data, network (S4)

The game and every callback run on one thread. Work that waits on the disk or the network runs on the host's I/O threads (three, started at the first job): a job carries copies of what it needs, never touches the game, a VM or the engine, and its result comes back as a callback on a later frame. A plugin that unloads meanwhile is never called back.

tools/plugin_bots_test.sh services checks all of it, and that a query of several seconds leaves every frame on time.

Network. One network thread owns every socket and TLS session (Mbed TLS); the tick only queues and reads.

tools/plugin_net_test.sh checks HTTPS (a trusted certificate, a rogue one, a name mismatch, a timeout), WebSocket and WSS (echo, binary, ping, fragments, both closes, a refused upgrade), TCP with and without TLS, UDP and the hosts list against local servers (tools/plugin_net_server.py) with a CA made for the run.

5n. Between plugins (S4)

tools/plugin_share_test.sh checks all of it with the plugins in native/game/src/plugins/tests/share.

5o. Languages and admins (S4)

tools/plugin_people_test.sh checks both with two clients.

5p. Mods (S5)

tools/plugin_mods_test.sh checks them (a client buys by its script and prints the catalog it got, cs_netclient -buymenu; it buys the golden AK, fires and reloads it, and its predicted weapon, clip and next attack are compared with the server's, -predict -weapons; then it throws an HE and a fire grenade with a blast of the plugin's own). tools/plugin_modes_test.sh runs a deathmatch mode: a client asks for the closed team, auto-joins, dies and respawns; the server's info and the client's team look (cs_netclient -teamlook) are checked; the client answers a vote and downloads the plugin's content file, refusing a wrong copy from a web mirror (cs_netclient -download).

5q. Demos the server records

tools/server_demo_test.sh runs the test plugin tests/demos (recordings from the console, the plugin and automatic ones; the recording time against the commands read back; reading, in pieces too; removing; a bot playing one to the end, looping and stopped).

5r. A player's sky, voices, sprays and the ban list

tools/plugin_extras_test.sh runs the test plugin tests/extras (a client that sprays twice and talks for two seconds; the fog and weather messages it got are counted).

5s. HUD texts

Every HUD text is drawn as light added to the picture, as in CS 1.6 games. The AMXX layer (set_hudmessage, show_hudmessage, ShowSyncHudMsg, ClearSyncHud, set_dhudmessage, show_dhudmessage) now sends these messages, with their effects.

tools/hud_text_test.sh runs the test plugin tests/hudtext (channels in turn, refused options, replacing and taking off by id, twenty texts at once) and checks what a client's HUD shows.

6. The schema

api.toml declares, for the generator:

[[function]]
name = "chat"
doc = "Writes in the chat of one player, some, or everyone (nil)."
args = [ { name = "to", type = "Players?" }, { name = "text", type = "string" } ]

[[class]]
name = "Player"
[[class.property]]
name = "name"
type = "string"
doc = "The player's name."

[[event]]
name = "player_connect"
before = true
doc = "A player connects; before handlers may refuse it."
fields = [ { name = "player", type = "Player" } ]
methods = [ { name = "reject", args = [ { name = "reason", type = "string" } ] } ]

Types: number, integer, boolean, string, vector, function, Player, Players (a player or a list), option tables ([[options]]), classes, T? for optional. The generator writes a checked wrapper per function, an __index/__newindex per class and per event object, the event structs with their handler counters, the Luau declarations (declare cs: { ... }, for luau-lsp) and the reference.

7. Verification