Handles and statuses
A mod never holds a pointer to anything in the game or the host. It holds handles: an entity, a panel, a list. And every call that can fail returns a status rather than trapping, so a mod decides what to do about it. This page is both.
What a handle is
A handle is two numbers, an index and a generation, and crosses as both:
The host owns the table behind them. The index is checked against the table before anything is read, and nothing in a handle is ever treated as an address. The generation is drawn from the operating system's random generator for each slot, so a mod cannot guess one it was never given.
A handle lasts one frame
Handles are minted for the frame they were handed out in. Use them in that frame and ask again in the next; a handle kept into a later frame is stale, even when the same entity is still alive.
/* Wrong: a handle kept from an earlier frame. */ AxiomEntityQueryEntityId s_Held; __attribute__((export_name("on_frame"))) OnFrame() { AxiomVec3 at; (axiom_entity_transform_position(s_Held.index, s_Held.generation, &at) != 0) { /* Status 1 every frame after the first: the handle is stale. */ } }
/* Right: ask this frame's handles, and use them this frame. */ __attribute__((export_name("on_frame"))) OnFrame() { AxiomEntityQueryEntityId ids[64]; uint32_t alive = axiom_entity_query_alive(ids, 64); (uint32_t at = 0; at < alive; ++at) { AxiomVec3 position; (axiom_entity_transform_position(ids[at].index, ids[at].generation, &position) != 0) { continue; } /* ... */ } }
This is what makes a handle safe in a game that reuses slots. Cities: Skylines has sixteen thousand vehicle slots and no generations of its own, so a vehicle freed and another created in its slot look the same to the game. A handle from last frame stops resolving rather than reading the new vehicle.
The overlay works the same way today: a panel and its lists are opened each frame, and an id from an earlier frame names nothing.
Forged handles
A handle no correct mod could hold, such as an index past the end of the table, a generation of zero, or the wrong generation for a slot minted this frame, is a forgery. Each one a mod presents is counted. Past sixteen in a session, the host stops resolving anything that mod presents, real handles included, so a guess that eventually lands buys nothing. Other mods are unaffected. A handle kept too long is a bug rather than an attack, and is not counted.
Statuses
A call that can fail returns an int32_t status. 0 is success, and the result, if there is one, was
written through the out pointer. Anything else means nothing was written. The numbers count the
capability's declared errors from 1, in the order the IDL lists them.
A pack answers every way a read can fail with 1 today, so a stale handle and a slot the pack could not read are the same status. A distinct status for each is planned.
Calls that return a count, such as axiom_entity_query_alive and axiom_entity_query_count, cannot
fail: they return how many they wrote. A bool, such as axiom_entity_transform_writable, is 0 or 1.
Statuses are not faults
A status is the host saying no, and the mod carries on. A fault is the mod doing something no correct mod does, such as passing an out pointer outside its own memory, and it ends the callback and counts towards suspension (Frames and fuel). Check every status, and the host never needs to fault you.
Not built yet
TrackedEntityId, an identity that follows one entity across frames for the mod that needs it, is designed and not in the surface yet. A pack would have to declare it, because a game whose slot reuse is invisible cannot honestly offer it.