Skip to content
Axiom/SDK
SDK / Writing a pack

Writing a pack

A pack is how Axiom learns where one game keeps its world. The backend knows how to read a process; the pack says which bytes in it are the entities, where each one is, and what the camera sees. Mods never see the difference: they call entity.query@1 and get an answer, whichever of the two gave it. This page is how to write one, check it against a game, and publish it.

Packs in the docs is the idea in brief. This is the reference.

What a pack answers

A pack answers the questions its game lets it and stays silent on the rest. Silence is not an offer: the host publishes a capability only for an answer the pack has, so a mod that needs one the pack is silent on is refused when it loads, not mid-frame.

Section
Answers
Gives mods
[entities]
Which entities are alive
entity.query@1
position in [entities]
Where each one is
entity.transform@1
writes in [entities]
That mods may move them
entity.transform@1 set_position
[camera]
The view, projection and eye
camera@1 and project@1

A pack has at most one pool. One pack answers for a game at a time.

The header

Key
What it says
id
The pack's id, in a namespace you hold: io.github.<login>.packs.<game> for a GitHub namespace.
name
A display name. Needed to package the pack.
version
A strict semantic version, 0.1.0. Needed to package the pack; the registry publishes it under this version.
game
The game key it answers for, such as colossalorder.citiesskylines.
builds
The builds of that game it is written for: a range like >=1.2.0, or an exact build.

A game build is not a semantic version, and is compared only with builds of the same game. A build with a letter in it, such as Cities: Skylines' 1.21.1-f9, orders against nothing: match it exactly, builds = "1.21.1-f9", because a range like >=1.21.0 never matches it and is refused.

A flat pool

For a native game that keeps a dense array of fixed-size records, and a live count, at symbols the backend can resolve:

PACK.TOMLa flat pool and a fixed camera
id = "io.github.alice.packs.mygame"
name = "My Game"
version = "0.1.0"
game = "alice.mygame"
builds = ">=1.2.0"

[entities]
kind = "flat"
count = "entityCount"       # a symbol, resolved to an address at attach
array = "entityBuffer"
stride = 32                 # bytes from one record to the next
generation = 0              # offset of a u32 that changes when a slot is reused
position = 8                # optional: offset of a Vec3, answers transform

[camera]
kind = "fixed"
view = "cameraView"
projection = "cameraProjection"
position = "cameraEye"

It names symbols, not addresses. A game loads at a different address every run, so the pack names where the pool is and the backend resolves that at attach. The numbers are offsets within one record.

A sparse pool

For a managed game whose world is objects, where a field's offset is decided by the runtime, not written down anywhere. This is the shape Cities: Skylines needs, and its real pack:

PACK.TOMLpacks/com.axiommods.packs.citiesskylines
id = "com.axiommods.packs.citiesskylines"
version = "0.1.0"
name = "Cities: Skylines"
game = "colossalorder.citiesskylines"
builds = "1.21.1-f9"

[entities]
kind = "sparse"
array = "ColossalFramework.Singleton<VehicleManager>.sInstance.m_vehicles.m_buffer"
record = "Vehicle"
live = "m_flags"
mask = 1
position = ["m_frame0.m_position", "m_frame1.m_position", "m_frame2.m_position", "m_frame3.m_position"]
frame = "m_lastFrame"
writes = ["position"]

It names types and fields, not offsets, and the backend resolves each against the build that is installed. A game update that moves a field moves the offset with it, and a field that is gone is a pack that does not build rather than one that reads the wrong bytes.

Key
What it names
array
The path to the array of records: a static field, then instance fields, dotted, ending at an array. Generic types are written as the game does, with their namespace.
record
The array's element type. Its size comes from the game's assemblies.
live
A field read as a u32. A slot is alive when it has any bit of mask set.
mask
The bits of live that mean in use. Cities: Skylines' Created flag is 1.
generation
Optional. A u32 field that changes when a slot is reused. Without one, every entity has generation zero, and the host's per-frame handles are what go stale.
position
One field, or up to four for a game that keeps interpolation frames. A dotted name reaches a field of a nested struct.
frame
With several positions, a byte field saying which was written last.

The slot count is read from the array every frame, never written in the pack, because mods that raise a game's limits grow its arrays.

Letting mods write

writes = ["position"] lets mods move entities with set_position. position is the only thing a pack can name there, and it needs position named too: a pack writes only what it reads. With several position frames, a write goes into every one, so the game has no old frame to slide back from. Nothing else in the record is touched.

Naming it is what the pack says. Whether the game may be written at all is the backend's call: it writes only to a vouched build, single-player, and only the bytes of that field (Entities and the camera).

Checking a pack

Terminal
$ axiom pack verify
$ axiom pack verify --managed "<Game>_Data/Managed"

axiom pack verify reads and checks the pack in this directory, or the one --path names, with no game. Every fault is reported at once:

  • a pack that answers nothing is refused, and a key nothing reads is a fault;
  • a name that does not resolve means no pack, because a missing address is never guessed;
  • a resolved offset that would put a field past the end of its record, a record of no bytes or more than 64 KiB, and an array of no slots or more than two million are each refused.

With --managed, for a sparse pack on a Unity game on Mono, it resolves the record and every field from the game's own assemblies, read only, with no game running, and prints each offset. Point it at the Managed directory beside the game: <Game>_Data/Managed, or Contents/Resources/Data/Managed inside a macOS app. Where the array is in memory is the one thing only the running game can say.

On a running Unity game, axiom pack read --pid <pid> goes one step further: it observes the game from its files, asks the gate, and reads the live entities and their positions through the pack in this directory (or --path), printing the first five (or --show), without writing anything.

Building and publishing

Terminal
$ axiom pack build
$ axiom pack publish io.github.alice.packs.mygame-0.1.0.axpkg --key main

axiom pack build writes <id>-<version>.axpkg from the directory as it stands (or --path, to --out), with pack.toml as the package's manifest. A directory with both a pack.toml and an axiom.toml is refused. axiom pack publish publishes it the way axiom publish publishes a mod, after checking the file is a pack, and is signed with the same key (Signing and publishing).

Installing and picking

Terminal
$ axiom pack install io.github.alice.packs.mygame
$ axiom pack list --game alice.mygame
$ axiom pack switch io.github.alice.packs.mygame --game alice.mygame
$ axiom pack status --game alice.mygame

A pack installs from the registry, signed, to packs/<id>/ in Axiom's data directory, and answers only from that signed package: every read checks its seal and signature. A pack.toml put there by hand never answers, and says so. A pack has no dependencies, never ships inside a mod, and a mod's dependencies cannot name one.

With one pack installed for a game, it answers. With several, none does until the person picks one with axiom pack switch, and the pick is kept. A pick whose pack was removed leaves the game unanswered rather than falling back to another.

Running it

Terminal
$ axiom attach colossalorder.citiesskylines --pid $(pgrep -x Cities) --pack <dir> --surface surface.imports

axiom attach --pid runs the Unity backend against a running game: it checks every enabled mod's signature, observes the game, asks the gate, walks to the pack's array and runs the mods on a tick. At the end it says how many ticks ran, where the array was found, how many times it moved and how many entities were live. On macOS the CLI needs the debugger entitlement to read another process, or sudo; the Axiom repository's scripts/SignReader.sh signs a build with it.

Not built yet

  • A pack written as code, for a shape pack.toml cannot describe, such as a free list or an entity component system. A package can carry the code today, and nothing hosts it.
  • Packs for other runtimes. The flat shape is read and tested, and no backend that resolves native symbols attaches yet. Sparse packs resolve on Unity games on Mono, x64; IL2CPP is not in the first release.
  • A camera on Unity. Its camera belongs to the Unity backend, and is not read yet.
  • pack new, pack test and pack fork.