Definitions baked at build
The game reads its quest journal, its skill tree, its VFX and its materials once, when it starts, before a mod's code runs. What a mod defines in data files is there at the first start. What it defines in code used to be written to Kiln's data folder at run time and built from the next start. Since 0.2.0-dev.27, Kiln.Sdk's build bakes what the code defines into the mod. The first start then has it too, on the server and on every player's game that installs the mod.
| Kind | Defined in code with | Baked into the mod as | Read at start by |
|---|---|---|---|
| Quests, quest NPCs, dialogues shown by the game | Quests.Define, Quests.DefineNpc, QuestBlock and DialogueBlock in C# |
quests/generated/<id>.json |
kiln.quests' start-up build (quests.md) |
| Nodes in the game's skill tree | GameTree.Define / GameTree.DefineJson |
skills/<id>.generated.json ("gameTree") |
kiln.skills (../services/skills.md, part A) |
| VFX and materials | Blocks.Define(name, VfxBlock) / MaterialBlock |
blocks/generated/<id>.json |
kiln.vfx (vfx.md, materials.md) |
| World-table blocks (explicit opt-in) | C# building/terrain materials, tweaks, blueprints, crafting props and material pools, with KilnBakeWorldTables=true |
blocks.tables.json |
kiln.worldtables (../services/worldtables.md) |
| World programs | nothing to bake: they are declared in kiln.programs.json, which the SDK already copies |
kiln.world (ecs-programs.md) | |
| Affix kinds and pools | nothing to bake: they are Kiln's own, not the game's, and defined when the mod loads (Blocks.Define, Affixes.Define, blocks/*.json) |
Kiln.Blocks (affixes.md) |
<id> is the mod's id. Each file's "comment" says the build wrote it, and Kiln goes by that comment.
How it runs
The target KilnBake (managed/Kiln.Sdk/Sdk/Kiln.Bake.targets) runs after KilnManifest. It is on by default when
KilnServices names Quests, Skills, Blocks or Vfx. It runs the built mod with Kiln's own loader under
KilnHarness, with no game: the mod's OnLoad, the server's start and its first 10 steps. During that run,
Kiln.Quests, Kiln.Skills and Kiln.Vfx record what the code defines instead of handing it to the game. The step then writes
the files into the output folder, so KilnDeploy and KilnPack ship them.
<PropertyGroup>
<KilnBake>false</KilnBake> <!-- no bake: the next start, as before -->
<KilnBakeSteps>30</KilnBakeSteps> <!-- define something in a later step? run longer (default 10) -->
<KilnBakeWorldTables>true</KilnBakeWorldTables> <!-- opt in only for world-table definitions independent of runtime conditions -->
<KilnBakeTimeoutSeconds>300</KilnBakeTimeoutSeconds> <!-- the whole bake's deadline (default 120) -->
</PropertyGroup>
The mod's own file wins. If the project ships its own file at one of these paths, the bake leaves it alone and says so.
What the bake wrote never outlives what the code defines. A file of an earlier bake goes from the output folder in these cases:
- the code no longer defines anything of that kind;
- the mod does not load without the game (below);
- the bake fails;
- the bake is turned off (
KilnBake=false); - the file is named for another mod id (left from a rename).
KilnDeployalso removes the baked output paths from the deployed folder before it copies, so one the output folder no longer has does not stay on the server. What goes is told by the file's own marker, not by a list, so an author's file now at a path an earlier bake wrote stays, and nothing is left when the build's bookkeeping is gone.A mod that does not load without the game is not baked. A build line says so (
Kiln.Sdk.Bake: <id>: not baked: ...). That is a limit of the bake, not a fault of the mod, and the build goes on.Warning
KILN030: a node whose icon cannot be baked, or an error the mod logs while it is baked.Error
KILN032: a bake that crashes, or does not end withinKilnBakeTimeoutSeconds(anOnLoadthat never returns). The bake process is ended, and the build fails, namingKilnBake=false. Nothing of an earlier bake is left: the process removes it at its own deadline, and the build removes it again by marker after any failure. A thread the mod leaves running does not keep the bake alive: the process ends when the bake is done.It bakes again when the mod, its data files (every
NoneorContentitem copied to the output,PreserveNewestorAlways), the SDK,KilnBakeSteps,KilnBakeWorldTablesorKilnBakeTimeoutSecondschange, or a file the last bake wrote is gone from the output folder.An IDE's design-time build never bakes, so it never runs the mod's code.
The mod's code runs with invariant globalization, as Kiln.Host does in the game. The files are the same on every build machine, and the same definitions in another order give the same file.
Why it runs the code. The other route was attributes read by a source generator. A generator sees only constants. A mod computes its definitions: a loop over its own table, names built from strings, a helper library's builders, blocks compiled from JSON. Only the code that runs in the game gives what the game gets, so the bake runs that code.
At run time
Nothing changes for a mod built with an older SDK. A mod built with this SDK defines the same things again when it runs, and Kiln compares them with what it shipped:
| Kind | Same as baked | Not the same |
|---|---|---|
| Quests | kiln.log: quests: <id>: what it defines in code matches quests/generated/<id>.json; Kiln's data file keeps only what the baked file does not have |
warning naming each quest, NPC or dialogue that differs, is new, or is gone. The baked quests, NPCs and dialogues win at every start: Kiln's data file leaves out every id the baked file has, so the game shows the baked version |
| Game-tree nodes | the node is left as kiln.skills read it at boot: in the tree, nothing cached for the next start | warning per node. The tree keeps the baked node, read at start, and the code's version is defined as before (pending, cached). The baked file still wins at every start |
| VFX, materials | the builder reports the block registered (the same definition it built at start) |
it is kept in kiln/data/vfx/pending/<id>/ as before. At start the baked one is read first, and the builder keeps the first of two blocks with one name (kiln.log says so). The warning and the toast say to rebuild the mod, not to restart |
The rule in all three cases: the baked file is part of the mod and wins at start. If code defines something else after
the build, rebuild the mod to bring the file up to date. A mod whose definitions depend on settings, other mods or the
game's data should set KilnBake=false.
A mod's folder is input from the internet, so kiln.vfx reads its JSON with limits. Nothing is allocated or parsed past them.
| Folder | Entries looked at | JSON files | Each | In all | Nesting |
|---|---|---|---|---|---|
blocks/generated/ (baked) |
1024 | 16 | 4 MiB | 16 MiB | 64 |
blocks/ (the author's data files) |
4096 | 256 | 16 MiB | 64 MiB | 64 |
- Both readers: the limits of
blocks/hold for kiln.vfx's reader at boot and for Kiln.Blocks' managed reader of the same files (BlockJson.Read), which also reads no file that is reached through a link or lies outside the mod's folder. The managed reader checks a path for links and then opens it, so on every system a file swapped between the two could still be read; it stays under the size limits. - Why these numbers: real block files are a few KiB and a handful per mod; the repository's largest is 6 KiB, and its most in one mod is 6. The author's limits are generous so no real mod meets them, and use the same size and depth kiln.quests' start-up build takes for the same files.
- Too many files: the folder listing stops there and none of that folder is read.
- Links: each folder and file is opened first, then checked: its final path must lie inside the mod's folder, and
nothing on the way down from the mod's folder may be a link or reparse point. Only then is it read, from that handle.
So a link, a junction (on
blocksitself too) or a path swapped between the check and the read cannot lead out. - Under Wine (the Linux server, Proton): Wine resolves no link in a handle's final path. It marks a link to a folder
as a reparse point, so that link is refused, on
blocksitself too. A link to a file looks like a plain file there, so it is read, within the same size, count and depth limits. Lab, GE-Proton:mods/tests/bake-test/fixtures/make-limit-probes.sh. - Kiln's managed side: it reads a baked file only to compare it (the warnings above), with the same bounds: at most 4 MiB, no link on the way, nothing outside the mod's folder.
Each refusal is a line in kiln.log (vfx: <id>: blocks/<file>: not read: ...), and the file is left out.
What is not baked
- A mod that does not load without the game. The harness has no game, and a block that lowers onto kiln.assets or
kiln.content throws there: statuses, effects, items, spells and talent blocks. A talent block needs kiln.assets for its
generated Impact program. The build says
not baked: the mod does not load without the gameand bakes nothing for that mod; setKilnBake=falseto skip the try. - What
OnBootstages (since 0.2.0-dev.28). A boot mod'sOnBootruns first in the bake, through the test kit's boot phase (KilnHarness.BootPhase), as a start runs it: once, on an instance of its own, with the same staging and the same lowering. When it throws, or a definition it stages does not lower (one that names another mod's block, for example:BootReferenceOutside), the bake fails with that reason (error KILN032), as the start would leave the mod out. What it staged is not baked: on a server with the boot phase it is in from the first start (onboot.md), and a baked copy would be a data file of the mod with the same names, which wins over the staged definition and moves it back to run time. The build lists what it staged (Kiln.Sdk.Bake: <id>: a boot mod: its OnBoot staged ...); the mod then loads in the harness as a committed boot mod, and what itsOnLoaddefines is baked as for any mod. A talent itsOnBootstages gets noskills/<id>.generated.json(its node is in the boot generation), and one an earlier bake wrote is removed. Where one identity has several sources, the collectors keep the first of: the mod's data file, its baked or generated file, itsOnBootdefinition, the pending cache of earlier runs. A data file of the same kind and name wins over a staged block, with a warning. - A node whose
IconFilelies outside the mod's folder. That path is the build machine's, not the mod's. A path inside the folder is baked relative to it, as kiln.skills reads a mod file's paths. A relative path in a definition from code is the kiln folder's, as kiln.skills reads code definitions, and is resolved there first. - A baked file over 4 MiB (what every reader of baked files takes): it is not written, an earlier bake's goes, and the build warns; those definitions are there from the next start.
- A client-only mod (
"side": "client"): the harness is a server. - A mod whose required dependency is not there, since the harness loads this mod only. Definitions made after the
first steps: raise
KilnBakeSteps. - NPC blocks from code (
kiln/data/kiln-quests/native/<id>.blocks.json) keep their next-start rule. - C# world-table blocks keep their next-start rule by default.
KilnBakeWorldTables=trueopts into recording every world-table section from the offline run, including crafting props, pools, strengths and surfaces. Use it only when those definitions do not depend on runtime settings, the world, available services or client/server conditions: the baked definitions win at every start, even if the runtime code changes or omits them. Data files andOnBootare first-start routes without runningOnLoadin the bake. Turning this option off removes an earlier SDK artifact. Since 0.2.0-dev.30.5, this includesToolMaterialPoolBlockpolicy metadata and thetoolBrushShapesdescriptors computed for aBuildingToolBlock. They remain pending during the offline run, but ship inblocks.tables.jsonfor admission by the first boot merge. Tool pools do not create extra game-visible material-pool rows. With this option, item, recipe and clone blocks may lower without a live content registry: those declarations are rebuilt at runtime, not baked as live items or recipes. Calls that actually read or change the game's content still require the game and can prevent a bake. No native tool action, picker, payment or undo is tested by the bake.
Checked
managed/tests/Kiln.Sdk.Tests(25 tests):- the recorders, the files and their marks, an author's file left alone, a stale file removed, and a mod that does not load;
mods/tests/bake-test, built with the step: its three files, and the same files from a second bake;- its quests under KilnHarness, equal to the baked ones;
- a run-time
GameTree.Defineagainst a fake kiln.skills: the node as baked is not sent again, and a changed one is; - fixture mods in the bake's own process:
- a thread
OnLoadleaves running does not keep the process alive; - an
OnLoadthat never returns ends at the deadline (KILN032); - a throwing
OnLoad, and one that needs kiln.assets, leave nothing of an earlier bake (a renamed id's file included) and keep the author's;
- a thread
- the same file from the same definitions in another order, and on a German build machine;
- malformed and other SDKs' files left alone, relative icons, baked dialogues ahead of Kiln's data file, and the "rebuild" note;
- the targets on a stub project through
dotnet msbuild: turned off, deploy, a missing output, changed settings, design-time.
- Lab,
mods/tests/bake-teston a dedicated server (server 26430253), started with an emptykiln/dataandkiln/config/vfx.json {"sim": true}:- At that first start, the two quests are in the game's journal (
NativeQuests.ShownByGame), the node is in the game's tree (in-tree, read fromskills/bake-test.generated.json, andGameTree.Defineleft it so), and the VFX isregistered. - Kiln keeps nothing for the next start of any kind: 10 PASS.
- With the lab's copies of the three files edited to differ from the code, each kind warns, the VFX warning says to rebuild, and Kiln writes no quests data file (every id is the baked file's).
- At that first start, the two quests are in the game's journal (
- A freshly packed SDK (
managed/Kiln.Sdk/pack.shinto a local feed) and a mod restored from it:- the bake runs from the package (
bake/beside Kiln.Api'skiln/lib), andKilnDeployships the files; - with the quests taken out of the code, their file goes from the output and the deployed folder;
- with
KilnBake=false, the rest goes too.
- the bake runs from the package (
- Not checked: a player's game (a client reads the same files with the same readers).