Load order and merging
A GlobalFormId identifies a record across plugins. This page covers the exporter side: which plugins load in which order, and how records from several plugins fold into one.
The engine clears a form and reloads it from each override; this codebase merges field by field instead, see Rule of One merge.
Load order
Game/LoadOrders/LoadOrder.cs holds the plugins a command merges and the BSA archives that make up its
archive file system, both in load order. You choose it with --load-order:
| Value | Plugins |
|---|---|
se | Skyrim.esm, Update.esm, Dawnguard.esm, HearthFires.esm, Dragonborn.esm |
ae | se, then ccBGSSSE001-Fish.esm, ccBGSSSE025-AdvDSGS.esm, ccBGSSSE037-Curios.esl, ccQDRSSE001-SurvivalMode.esl |
custom | The plugins of --load-order-plugins, see Custom load order |
ae adds the Creation Club content bundled with the Anniversary Edition upgrade, not separately
bought content. export:books, export:worldspace-maps:* and the terrain
LOD commands default to se; the other debug commands read one file unless --load-order is
given, see One file or a load order.
Game/GameSource.cs finds the plugins in the data directory, warns about each missing one and
logs an error when none is found. The session reads each plugin on its own thread and merges the
results in load order, see Architecture.
export:books writes the plugins it found and the archives it opened to export.json (see
Export manifest).
Archive file system
A load order’s archives are opened once per session, by Game/GameArchives.cs, as one
Game/Bsa/ArchiveFileSystem.cs: a single path index over every archive. Each lookup (a texture, a
NIF, a string table, a fontconfig, a terrain LOD tile) searches that whole index by path. When a
path is in several archives, the last archive in the list wins, see
Assumptions. An archive missing from
Data is skipped, and --verbose lists it.
Archive names only set the order:
- The vanilla archives of
Game/Vanilla/Archives.cs, inSkyrim_Default.ini’ssResourceArchiveListthensResourceArchiveList2order. - For each plugin beyond the five vanilla masters, in plugin order,
<plugin>.bsathen<plugin> - Textures.bsa. The engine loads both with the plugin, see Assumptions. The vanilla masters ship their resources in the sharedSkyrim - *.bsaarchives.
No code picks an archive by its name to find a kind of file: a texture in My Mod.bsa is found
the same way as one in Skyrim - Textures3.bsa.
Loose files
A file in a folder of Data (a loose file) overrides the same path in every archive, whatever the
load order: the engine looks for a loose file before it searches the archives. The archive file
system indexes them once per session, when it opens the archives, and every lookup checks them
first. This covers every kind of file the exporter reads: textures, NIFs, SWF font libraries,
fontconfig.txt, string tables, LOD settings and terrain LOD tiles. A translation that ships its
string tables loose in Data\Strings adds its language to export:books this way.
| Rule | Why |
|---|---|
| A loose file wins over every archive | Engine behavior, see Assumptions |
| Paths match ignoring case | The game runs on Windows: Textures\Landscape\Rocks01.DDS overrides textures\landscape\rocks01.dds |
Files at the root of Data aren’t indexed | Plugins, archives and ini files sit there; every resource path starts with a folder |
| A single archive file read on its own reads no loose file | The debug commands then show that archive’s content |
The log names a loose file’s origin loose where it would name an archive. --verbose lists the
files ignored because another one has the same path ignoring case, possible on Linux.
The data directory is scanned with all its subfolders. A lone plugin file reads the loose files of
its own folder, so pass a plugin that sits in Data, not in a large folder such as your home.
Custom load order
--load-order custom merges the plugins you list, in the order you list them:
| Option | Required | Value |
|---|---|---|
--load-order-plugins | Yes | Plugin file names (.esm, .esp, .esl) |
--load-order-archives | No | BSA file names (.bsa) |
Both options take either a comma-separated list or the path of a text file. A text file holds
one name per line; a line can also hold a comma-separated list. Blank lines and lines starting
with # are skipped:
# vanilla
Skyrim.esm
Update.esm
# mods
MoonAndStar_MAS.esp
A value that ends with a listed extension is always a name, never a list file, so Skyrim.esm
never reads a Skyrim.esm file in the current directory as a list. Every name is a file name in
the Data directory, without a path. A name listed twice, an unexpected extension or an empty
list is a parse error. Both options are parse errors with se or ae.
Names are matched to the files in Data ignoring case, as the game does on Windows, so
skyrim.esm finds Skyrim.esm on Linux.
Without --load-order-archives, the archive file system is built as for se and ae: the vanilla
archives, then the archives named after each listed plugin that exist in Data. With it, the
archive file system is exactly the archives you list, in order. List the vanilla archives
yourself when you need their string tables, fonts, textures or meshes.
BookAtlas.Exporter export:books Data -o export \
--load-order custom --load-order-plugins "Skyrim.esm,Update.esm,MoonAndStar_MAS.esp"
BookAtlas.Exporter export:books Data -o export \
--load-order custom --load-order-plugins plugins.txt --load-order-archives archives.txt
load-orders/ae-mods.txt is an example: the vanilla masters, the Creation Club content of Data
in Skyrim.ccc order, then a few mods ordered by their master flag and their masters.
The plugin list isn’t checked against each plugin’s masters. A master missing from the list shows up as unresolved FormIds in the merge reports.
The merge step
Datasets/Merging/RecordMerge.cs is shared by every merger:
- Resolve the record’s FormId with the writing plugin’s
PluginMasters. When it doesn’t resolve, drop the record and report it. - Build the merged value. FormIds inside the record (items, entries, destinations) are resolved here too: after merging, the writing plugin is no longer known.
- Insert it, or combine it with the value from earlier plugins.
The combine step is per record type. By default a non-null incoming field replaces the existing one and a null field leaves it alone:
| Field | Rule | Why |
|---|---|---|
| Scalar subrecords (EDID, FULL, DATA, XCLC, VENC, …) | Latest non-null wins | An override only carries what it changes |
Lists (CNTO, LVLO, SNAM) | Replaced whole when the override has any entry | Entries aren’t individually addressable |
REFR cell and interior flag | Latest wins | A move to another cell is an override |
REFR Persistent flag | Latest wins | Header flags are always present |
REFR HasScript | Latest wins | The engine clears script data on every override |
REFR HasTeleport | Or-ed across overrides | XTEL clearing isn’t documented |
BOOK DATA fields (flags, type, teaches, weight) | Replaced together by an override with DATA | One subrecord: an override that clears a teaches flag also clears what it taught |
Mergers:
| Merger | Records | Output |
|---|---|---|
Datasets/Books/BookMerger.cs | BOOK | One MergedBook per book, in first-seen order, with the plugin that last set each field |
Datasets/Locations/LocationMerger.MergeRecords | WRLD, CELL, REFR/ACHR, CONT, LVLI, NPC_, FACT | MergedLocations, one dictionary per type |
Datasets/Worldspaces/WorldspaceMerger.cs | WRLD and exterior cell headers | Worldspace details and cell counts |
MergedLocations is used both by book placement (below) and by the interior commands
(through the LocationRecords dataset), so every command sees the same merged references.
Localized text is resolved per plugin before merging, see Localization.
Merging locations
Datasets/Locations/BookReachability.cs finds where each book can be found in MergedLocations. Each
placed REFR or ACHR with a base object and a position is checked in turn:
| Base object | Placement source |
|---|---|
| The book itself | Direct |
A CONT whose items lead to the book | Container, or Vendor when the container is a vendor chest |
An NPC_ whose items lead to the book | Npc, or Vendor when the NPC is in a vendor faction |
“Leads to” follows nested leveled lists: an LVLO entry can be another LVLI. Results are
cached per FormId and a cycle stops the walk. ComputeLeveledListMemberships inverts the same
graph into “which lists can produce this book”.
Vendor chest resolution
A faction’s VENC names a placed chest REFR, not a CONT. The chain is faction, chest REFR,
its base CONT, then that container’s items. The chest is usually placed somewhere the player
never goes (Urag gro-Shub’s spell tomes, for example), so a vendor NPC’s stock is its own items
plus its vendor factions’ chest items, all at the NPC’s placement: that’s where the trade menu is.
A chest that is placed somewhere reachable is also reported as a Vendor placement.