scmJS docs

The fidelity model

A CHK file is a flat sequence of NAME + length + payload chunks. The same section can appear more than once, and the game resolves the repeats in a specific way, so a parser that keeps only the last occurrence of each section will silently change what a protected map does.

src/formats/chk/reader.ts therefore parses the container into a ChkFile that keeps every section in file order, repeats included. src/formats/chk/sections/registry.ts declares each section's combine mode and the fixed buffer size the game reads it into:

Mode Meaning
last a later occurrence replaces the earlier one outright
overlay a later occurrence overwrites only its own prefix of the buffer
append occurrences concatenate into one list

src/formats/chk/scenario.ts then decodes the sections the editor models into typed fields on a Scenario. Scenario.dirty is a set of section names, and serializeScenario re-encodes only the dirty ones. Everything else is emitted byte for byte, in its original order and with its original repeats. Saving a map the editor only partly understands does not damage the parts it does not.

Any code that mutates scenario state has to call markDirty(scn, "NAME") for every section it affects, or the change never reaches the file.