Registry views: one typed view over every registry and resource type
Since 0.2.0-dev.32 (experimental, KILNX031). One read-only view over everything Kiln can name in the game's data:
- stable views are the registries (
items,recipes,loot,drops,balanceand every registry a later schema adds): their fields read what the registry resolved, mapped and proven per game build as the registry is. They are written as before, throughMod.OnRegistry,Registries.Changeand a data pack'sregistrysection. - advanced views are every other resource type of the running build: quests, NPC dialogs, materials, UI data, the long tail no registry covers yet. Their names are Kiln's, derived from the game's reflection, and the view only reads them (tier Advanced, tiers.md: verified per game build, not lab-proven).
Mods never name a game type, member, offset or address here: views, ids and fields are Kiln names.
C#
using Kiln.Registry;
if (!RegistryViews.Available) return; // kiln.registry.view: every read below needs it
if (RegistryViews.Find("quest") is { } quests)
{
foreach (var id in quests.Select("game:quest_*"))
{
var quest = quests[id];
if (quest.TryGet<int>("xpReward", out var xp, out var why)) Log.Info($"{id.Value}: {xp} xp");
else Log.Info(why); // this entry has no value of it, in Kiln words
}
var reward = quests["game:quest_main"].Get<RegistryId>("rewardItems[0].item"); // another view's entry
}
var maxStack = RegistryViews.Find("items")!["game:material_t1_wood_logs"].Get<int>("maxStack"); // the registry's value
| Member | What |
|---|---|
RegistryViews.All, Find(name) |
every view, stable ones first; one by its name |
RegistryView.Tier |
Stable (a registry) or Advanced |
RegistryView.Fields, Field(path) |
the fields on this build: Kiln path, type, element type, values, the view an id names (Ref), ReadOnly, State (Readable, Unread, Removed; a registry field Mapped, Unmapped, Unproven), Reason, and CoveredBy ("items.maxStack": the registry field over the same member; of several, the one that maps it one to one, else the one whose own member it is, never a formula that only reads it), Exact when that field holds the same number or true/false (not an enum's own names, a formula or another conversion) |
RegistryView.Select(selector) |
ids by an id, a case-insensitive glob over ids, or an entry's debug name (a stable view reads it as a registry edit does: Material_T1_Wood_Logs is game:material_t1_wood_logs, Material_* game:material_*); on an advanced view also guid:<GUID>, the Kiln id of a GUID a live API gave you (below) |
view[id].Get<T>(field), TryGet<T>(field, out value, out reason) |
one field, typed (int, long, double, bool, string, string[], RegistryId, TimeSpan, JsonNode) |
view.TryRead(id, field, out JsonNode? value, out string? reason) |
one field as JSON |
view[id].Snapshot() |
every field of one entry, and per field why the others did not read |
RegistryView.Kind("<field>[<kind>]"), RegistryViewField.Kinds, Covers |
a variant field's kinds and one kind's fields (below; since 0.2.0-dev.32) |
RegistryViews.EntryOf(registry, id), <Entry>.Template |
the view entry of a registry's entry (impacts, creatures, storage: its template) |
RegistryView.DisplayName, view[id].DisplayName, Snapshot().DisplayName (and DisplayNameSource) |
the names players see, never empty (since 0.2.0-dev.32 final): a view's Kiln name as words ("Npc Dialog"); a stable view's entry has its registry entry's name, a template entry (an entry's Template) its template's, a perk entry its perk's, another advanced view's entry a name made from its id. Reads no field (display names) |
Get throws KilnUnavailableException (with the reason) when the field does not read for this entry and
KeyNotFoundException when the view has no such entry or field on this build; TryGet and TryRead return false with the
reason instead. An id that names no entry reads as null: null into RegistryId?, string or JsonNode, and
InvalidCastException (TryGet: false) into RegistryId or another value type. Any thread. Nothing is cached in the C# objects: each read asks Kiln, so it follows the game's data (a
data pack's or a registry's change shows in the next read).
Some first calls are slow; make them off the game's thread (Task.Run, a load screen), never in a tick. Measured on the
lab's server build:
- a stable view reads what the registry resolved, and the registry's values are prepared once per start. Since 0.2.0-dev.32 a mod
whose code uses
RegistryViews(Kiln.Host sees it in the mod's DLLs) has them prepared while the game loads, as a mod that uses the registry API does, so its first read takes milliseconds (lab: 1 ms at content ready; it was 7.2 s on the tick before; the game's load took about 5 s longer for it on that busy lab machine). A first read from code Kiln.Host cannot see (another DLL, native code) waits for the values: they are prepared on Kiln's worker from the first view call on, and nothing else of the registry waits meanwhile. A mod that reads only advanced views never needs those values: its kiln.mod.json says"views": "advanced"and the start skips preparing them for it (kiln.log:... reads advanced registry views only ...); the default,"prepare", is the behaviour above (manifest.md); - the catalog (every view's fields) is built once per process, about 0.1 to 0.2 s on the lab's server. Since 0.2.0-dev.32 a start
whose load order has a mod that reads views (Kiln.Host sees
RegistryViews,RegistryView,RegistryViewEntry, an entry'sTemplate, or an edit through a view,RegistryStage.View) builds it on Kiln's worker at the end of the registry stage, and Kiln.Registry reads it once on a pool thread at the registry's ready (each view's fields and kinds are then asked once per process), so the first call from a tick finds it built; that matters for an edit through a view, whichRegistries.Changemakes on the tick. A call while the worker builds it waits for it. A mod Kiln.Host cannot see (another DLL, native code), or one that calls in the first moments after the stage, can build it itself: callRegistryViews.Find(...)fromTask.Runat load to be sure. Each kind's fields are derived at the first call that needs them (about 1.3 ms each); - an advanced view's first
Select, read orSnapshotlists its entries, reading each one's name: about 0.2 s foritemInfo(4,268 entries) ortemplate(12,269); Kiln keeps the listing until the type's resources change; - a
Snapshotdecodes every field, every element of every list: up to about 1.2 s for one resource with long lists (gameKnowledge,recipeRegistry); read the fields you need instead.
A call holds back no other: other views, the registries and the catalog answer meanwhile; only a call that needs the same view's listing waits for it.
Kinds of value: a template's components
Since 0.2.0-dev.32 (J1d). Some members hold one of several kinds of value: a template's components (components: a lifetime,
a level, a collider, ... 687 kinds on the current server build, each with its own fields), a sequence's events, a collider's shapes. Such a field
has the type Variant (a list of them: element Variant), and its Kinds are Kiln names: the type's last name in lower camel
case (lifeTime, level, colliderResourceComponent). Each kind has fields of its own, and a path names one kind with a
selector:
| Path | Reads |
|---|---|
components[lifeTime].lifeTime |
the template's first lifeTime component, its lifeTime (seconds) |
components[lifeTime#1].lifeTime |
the second one (#k: the k-th of that kind, from 0) |
components[level].dataStorage[0] |
an element of a list inside a kind |
components[colliderResourceComponent].colliders[0].dataArray[sphereColliderData].shape |
a kind inside a kind (a collider's shapes are a variant too): the first sphere's radius (a struct of one number reads as that number, as everywhere in the views; impacts.radius covers it) |
components[lifeTime] |
the component whole: an object of its fields with "$kind": "lifeTime" |
components[3] |
the fourth component, whatever its kind ("$kind" says which) |
components |
every component, as such objects |
<member>[<kind>].<field> |
a member that holds one value of some kind (no list): read when it holds that kind, else "no value of it" |
if (!RegistryViews.Available) return; // the views open after the stage
var templates = RegistryViews.Find("template")!;
var fireball = templates["game:projectile_player_staff_fireball_1"];
TimeSpan life = fireball.Get<TimeSpan>("components[lifeTime].lifeTime"); // 5 s
double gravity = fireball.Get<double>("components[staticGravityModifier].modifier"); // 0.1
RegistryViewField comps = templates.Field("components")!; // Element Variant, Kinds [...]
RegistryViewKind? kind = templates.Kind("components[lifeTime]"); // that kind's fields
RegistryViewField row = templates.Field("components[lifeTime].lifeTime")!; // CoveredBy "impacts.lifetime"
From a registry whose entries are templates (impacts, creatures, storage), an entry's generated Template property is its template
in this view: stage.Impacts["game:projectile_player_staff_fireball_1"].Template.Get<double>("components[staticGravityModifier].modifier")
(RegistryViews.EntryOf(registry, id); a template has the same id in the registry and in the view).
- Kinds' names. A name two of a field's types derive is none of theirs: each gets its namespaced form (
ecsHealth) or<name>_<8 hex>, and the plain name is refused naming them (KindsRefused); Kiln's alias table keeps a kind's name when a game update renames its type ("kinds"below), as it does for views. - A kind's fields are asked once per kind and kept (
RegistryView.Kind).Fieldslists the variant field with its kinds;Field(path)finds a kind's row ("components[lifeTime].lifeTime","components[level].dataStorage[0]"). - Registry fields over a kind. A row's
CoveredBynames the registry field over the whole row;Coversthe ones that map one element of it, an index or the k-th of a kind (components[level].dataStorage[0]iscreatures.level,[1]iscreatures.levelMax), each withExact,Entry(the registry's entries are this view's) andWritable. - Refusals, per entry: a template without the kind (or without a k-th one) "has no value of it on this game build"; a kind
name the field does not have is
KeyNotFoundException; a malformed#kor index isArgumentException.
Edits through a view
A view only reads. An edit through a view's path is the registry edit of the field that covers it, with your mod as its owner:
if (!Registries.Available) return; // kiln.registry.live
Registries.Change(stage => stage.View("template")["game:projectile_player_staff_fireball_1"]
.Set("components[lifeTime].lifeTime", TimeSpan.FromSeconds(2.5))); // impacts.lifetime
RegistryStage.View(view)[id].Set(path, value) is stage.Entries("impacts")[id].Set("lifetime", value) (Target(path) says
which field). It takes a path whose covering registry field maps it one to one (Exact: the same number or true/false), over
the registry's own entries (Entry), and takes edits; every other path is read-only (ArgumentException naming why and the
registry field to edit instead, if any). Today that is the template paths the impacts and creatures registries map: a
component's lifetime, gravity factor, sphere radius, level and level cap, scale, speeds, resistances, loot slots, sight and
the like; an enum (creatures.faction), a formula or a configuration (impacts.pushBack, inside the configuration list the view
does not read) is edited through its registry field. A registry field covers a view's path through the view only when the
registry's ids are the view's (Entry): the template registries (keyed by the templates) and perks (the perk view names perks
as perks does). items (over itemInfo) and abilities (over actorSequence) name their entries by rules of their own, so
an id in the view can be another entry there: their fields show as CoveredBy, are read-only through the view, and are edited
as registry fields. A template that is no entry of that registry (a template without an Impact
component, for impacts) is refused per entry at the change, with the reason in registry.json.
Not inside GameStart. Views open after the registry stage, so an edit through a view works at WorldLoad, HotReload, ModLoad
after the stage and in Registries.Change; inside a GameStart pass Set throws InvalidOperationException ("an edit through a
registry view does not work inside GameStart (views open after the registry stage) ..."): there, edit the covering registry field
itself (stage.Impacts[id].Lifetime).
Writing a registry by name, from code that does not know the registry's typed property (a registry a later schema adds):
RegistryStage.Entries("creatures")["game:enemy_vukah_melee"].Set("health.perPlayer", 1.2) inside OnRegistry or
Registries.Change. The generic RegistryEntry makes the same edits as the generated entry types and checks the value against
the field's schema type first.
Names
| What | Stable view | Advanced view |
|---|---|---|
| view | the registry's name | the type's name without its namespaces and a Resource suffix, lower camel case (npcDialog); a name a registry holds, or that two or more types derive, is none of theirs: each gets its namespaced form (ecsTemplate) where only it derives that, else <name>_<8 hex> (below) |
| entry ids | the registry's (README.md) | the same rule: game:<debug name in lower case>, clash suffixes ~<8 hex>; an entry without a name game:<view in lower case>_<first 8 hex of its GUID>; a resource in several parts is one entry per part (below). A GUID's text is the game's (023b8911-d151-4d56-887b-40c0f09da660, as the registries, the game's data and Guid.ToString() write it; before 0.2.0-dev.32 final the views wrote the first three groups' bytes the other way round). A view whose entries are a registry's (template: the impacts, creatures and storage registries are keyed by the templates; perk) keeps its ids with that registry's pins from Kiln's build record, so an entry has one id in both on every game build; the alias table's ids rows pin the other advanced views' |
| fields | the schema's | each member's name in lower camel case, dotted through structs (setup.radius); a list is a field of its own and its elements' fields are <list>[].<field>; read one with an index (rewardItems[2].count), or every element's at once with [] (a column, below) |
| values | the schema's | numbers, true/false, an enum's or flags' values in lower camel case, ids, text, lists |
The Kiln id of a GUID a live API gave you. Live APIs name game data by GUID (a spawned entity's Template, a boss kill's
template); Select("guid:" + guid) on an advanced view turns it into the entry's Kiln id, which every view and registry read takes:
// template: a GUID a live API gave you (Kiln.Spawn's Template of a spawned entity, a boss kill's template)
if (!RegistryViews.Available) return; // the views open after the stage
if (RegistryViews.Find("template") is { } templates && templates.Select("guid:" + template) is [var id, ..])
Log.Info($"{id.Value}: level {templates[id].Get<int>("components[level].dataStorage[0]")}");
The GUID is its usual text in any case (Guid.ToString(), braces allowed); a GUID no entry has selects none, and a malformed one
is ArgumentException. A resource in several parts gives part 0's id first, then its parts'. A template's id is its id in the
impacts, creatures and storage registries too. A registry's own view takes no guid: selector (ArgumentException): use its
entry view (template). Since 0.2.0-dev.32.
A resource in several parts (the world scene: one resource of sceneEntityChunk, its 1,601 chunks as parts, part z * 40 + x
for the 40 by 40 chunks of 256 m and part 1600 the global chunk with the map's spires, shrines and wells) is one entry per part,
each reading that part's own data. Part 0 has the resource's id (the id it always had), part k is <that id>.p<k>
(game:<scene>.p1600; a clash suffix stays last: game:<scene>.p3~1a2b3c4d, and a part id another entry already holds takes
its GUID's hex as the suffix). A selector by name, and an id field that names the resource by its GUID, name part 0;
Select("game:<scene>.p*") lists the other parts. The part numbers are the game's: an alias-table pin names a resource by its
GUID and its parts follow its id, and a game update that changes a resource's parts moves what those ids name (the maintainer's
check below warns, and the release notes say so). Since 0.2.0-dev.32 (review of J1d); before, a view listed part 0 alone.
The advanced names start as the game's on the first build Kiln maps and are Kiln's from then on: when a game update renames
a type, a member or an enum's value, Kiln's alias table (regmap/views.json, Kiln's part like the rest of regmap/) keeps the
Kiln name on the renamed one (types, fields, and since 0.2.0-dev.32 values: {"<view>": {"<field>": {"<Kiln value>": "<the game's value>"}}} and kinds: {"<view>": {"<variant field>": {"<Kiln kind>": "<the game's type>"}}}), and a member a
build removes keeps its name refused (never given to another member); a value name the table pins is never given to another
value, also on a build without that value; a pinned kind whose type the build lacks is refused, never given to another type. A
fields or removed row may name a kind's field ("components[lifeTime].life"). The table holds deltas only (identifiers,
never a list of the game's names); with no row, a name is the derived one.
Name collisions. A view name never moves to other data without a refusal:
- a name two or more of a build's types derive is none of theirs: every call naming it is refused (
KILN_ERR_NOT_FOUND,quest names more than one kind of game data on this game build (quest_1a2b3c4d, storyQuest): name one of those), and kiln.log says so once; until Kiln's alias table pins the name to the type it named before (a Kiln update); - a name the alias table pins to a type the running build lacks stays held and is refused (
journal: its game data is not on this game build (a Kiln update is needed)), never given to another type; - a registry's name is never an advanced view's (a later registry of an advanced view's name takes it: the release notes say so, and the maintainer's check below fails until they do).
The catalog (views_json) lists every name a type derived but did not get (collisions: the name, who holds it, the views the
types got instead) and every advanced view's type hash (an identifier). kiln.content writes it for each game build to
<game>/kiln/data/content/registry/views-<side>-<exe sha256>.json, and again when a Kiln update changes it (the registries and
the alias table are Kiln's part of it); since 0.2.0-dev.32 the file also lists each view's variant fields' kinds with their type
hashes, and how many parts a view's resources have ("parts", when more than one). tools/registrygen/views_check.py --old <proven build's> --new <new build's> is the maintainer's check before a release (errors: a view or kind name that names other
data, a name the new build refuses or a registry took; warnings: a name or kind gone, a view whose resources have other parts
now), and without arguments it checks the alias table (tools/check.sh; an ids row that names a part, <id>.p<k>, is an
error: pin the resource).
A column: one member of every element of a list. A path with [] and no index reads that member of each element, in the
list's order, as the list read whole holds it, without reading the elements' other members: rewardItems[].count is [1, 2, 3],
entities[].templateIndex every entity of a chunk's template index (a world scene's chunk has hundreds). <list>[] is the list
itself; <list>[].$kind is each element's kind of a list of kinds of value (components[].$kind: ["lifeTime", "level", ...], an
empty element null). One [] a path, a member below it (no index or kind below the []); a member of a list of kinds is read
by element (components[2]) or by kind (components[lifeTime].lifeTime). Refused in Kiln words: [] twice, a member of a list
of kinds (it names <list>[].$kind), a field that is not a list. Advanced views; since 0.2.0-dev.32.
Refusals
Per entry and per field, in Kiln words, each distinct one logged once in kiln.log (registry view: ..., at most 256 lines a
start):
| Case | Code (native) | Reason starts |
|---|---|---|
| before the registry stage ran (the game's resources are not loaded yet) | KILN_ERR_UNAVAILABLE |
the game's resources are not loaded yet |
| no such view, entry or field on this build | KILN_ERR_NOT_FOUND |
there is no view ..., quest has no entry ..., quest has no field ... |
| a view name two kinds of game data derive, or whose pinned type is gone (Name collisions) | KILN_ERR_NOT_FOUND |
quest names more than one kind of game data ..., journal: its game data is not on this game build ... |
| a member of a kind the view does not read in this release (an optional, a configuration list, a list of lists, deeper than 8 levels; a variant whose kinds this build's reflection does not list) | KILN_ERR_UNAVAILABLE |
quest.maybe: an optional member: ... |
| a kind a variant field does not have, or a name two of its kinds derive (since 0.2.0-dev.32) | KILN_ERR_NOT_FOUND |
template.components has no kind ..., template.components[health] names more than one kind of value ... |
| this entry has no element of that kind (or no k-th one), or its member holds another kind | KILN_ERR_UNAVAILABLE |
template[game:stone].components[lifeTime].lifeTime: this entry has no value of it on this game build |
a malformed kind selector or index ([lifeTime#x]) |
KILN_ERR_INVALID_ARGUMENT |
template.components[lifeTime#x].lifeTime: a kind is named by its Kiln name ... |
| this entry has no value of the field | KILN_ERR_UNAVAILABLE |
quest[game:quest_side].bonus: this entry has no value of it on this game build |
| an enum value or flag Kiln has no name for | KILN_ERR_UNAVAILABLE |
quest[...].kind: the game holds a value Kiln has no name for on this build |
| a member the alias table says a build removed | KILN_ERR_UNAVAILABLE |
quest.repeatable was removed by game build ... |
| a stable field not mapped or not proven on this build | KILN_ERR_UNAVAILABLE |
the registry's reason |
| the answer could not be made (out of memory, the game's text in bytes that are not UTF-8; since 0.2.0-dev.32) | KILN_ERR_INTERNAL |
kiln.registry.view: the answer could not be made: ... |
Native: kiln.registry.view v1
native/core/abi/services/kiln_registry_view.h (64 bytes since 0.2.0-dev.32, 56 with J1d's kind_fields_json, 48 before; served
by kiln-content.dll on both sides): views_json, fields_json(view), read(view, id, field), select(view, selector),
entry_json(view, id), and at the tail kind_fields_json(view, "<field>[<kind>]") (check header.size >= 56; Kiln.Registry
does, and an older table refuses kinds while its other members answer) and read_many_json(view, request) (header.size >= 64).
A view of views_json may name entryView (the advanced view whose entries are that registry's). On a refusal the call returns
its code and copies the reason into the buffer the same way it copies an answer. Any thread; an advanced read decodes the
resident resource bytes under kiln.content's store lock, so it never sees a half-written value (and waits for a data-pack
application in progress). The catalog is built once per process at the first call after the stage; an advanced view's
entries are listed at the first call that needs them (about 0.2 s for thousands of entries, above) and again when its type's
resources change, and a call keeps the listing it started on.
Many fields of many entries in one call (read_many_json, since 0.2.0-dev.32): the request
{"ids": ["<id>" or "guid:<GUID>", ...] or "<selector>", "fields": ["<field>", ...], "reasons": true} (at most 65,536 ids and
256 fields; "*" every entry in the view's order; a call reads at most 65,536 entries, a selector's too, and 1,048,576 values,
entries times fields, and answers at most 64 MiB of its own text, the Kiln values counted exactly as they are written, each value
stopping where it would go over (a list one element at a time; an answer of exactly 64 MiB is made whole); a value whose game data
alone is more than 64 MiB of text refuses the call too, read it alone: over one, KILN_ERR_INVALID_ARGUMENT, ask fewer a call) answers
{"view", "fields", "refused"?: {"<k>": "<reason>"}, "entries": [{"id", "guid"?, "values": [...], "refused"?: [<k>, ...], "reasons"?: {"<k>": "<reason>"}} or {"id", "missing"}]}: each value and each refusal as read gives it, in the order asked; a
field no entry reads (no such field on this build) is named once in the top refused, a field an entry has no value of is null
in its values and named in its refused. The view is prepared, listed and each field resolved once for the whole call, and
for a kind of a list of kinds that is the root's member (components[bossHealthBar].displayName) each entry's kinds are read
once and a kind it does not hold is refused without a walk to it. Kiln's world progress index reads the world scene this way: the
GUID map in one call, the templates 2,048 a call, a chunk part in one or two (INT3b: one field a call, ~110k calls, 31.6 s for
the bosses where the game's bytes take 0.33 s). A call whose answer does not fit the buffer (KILN_ERR_BUFFER_TOO_SMALL) keeps
it: the same call next on the same thread, within 2 s, copies it instead of making it again (every member of the table, since
0.2.0-dev.32) when it fits that call's buffer, no registry change was applied (a live edit, a re-authored pass landing, a mod's
declared registry changing, before its report is published) or published and no world started or stopped meanwhile; else the
call reads the game's values again.
Advanced list and column reads decode the requested values under the content store lock and convert each value with the lock released. When another thread took the lock while a value was converted, the reader verifies the decoded values together before returning them (else they are one snapshot already: every writer of the store holds that lock). If the resource changes during conversion, the reader discards the partial result and retries once. A resource that changes again is reported as unavailable for that field. An unreadable byte encountered during a streamed list read also refuses the field. A pack callback running under the content store lock can read views after the lock is released.
Not in this release
- Writing an advanced view other than through the registry field that covers a path one to one (
RegistryStage.View, above). Where none does, write through the old path (a data pack section, a resource patch); a member that mods need to write becomes a registry field. Read-only through views: every path no registry field maps one to one over its own entries, enum, formula and configuration rows (edit those registry fields), and everything inside GameStart. - Optional members and the game's configuration lists (an item's or an impact's configs): listed as
unreadfields with that reason; their registry fields read them (items.manaCost,impacts.pushBack,buffs.configs). - Lab-proven read times for advanced fields (they are read as the game holds them now; when the game reads them is not traced).