Plugin (ESM/ESP/ESL) file format
Implemented in CreationEngineFormats/Plugin/. Reference:
UESP Mod File Format, with one sub-page
per record type. Field types (zstring, lstring, formid, …) follow
UESP File Format Conventions.
Where the code departs from these pages, the entry is in
Spec deviations.
A plugin is one TES4 record followed by top-level GRUPs, one per record type.
PluginWalker.ReadHeader reads the TES4 record and returns the offset of the first group.
Record header
The 24-byte header (RecordHeader.cs) follows the spec: type, data size (header excluded),
flags, FormId, then version control fields the code doesn’t read.
RecordFlags.cs lists every flag of the UESP table. The ones this codebase reads:
| Flag | Value | Use |
|---|---|---|
Deleted | 0x20 | Deleted records are dropped by a query unless it asks for them |
DoorHiddenFromLocalMap | 0x40 | On a REFR of a DOOR: kept with the reference, see below |
Localized | 0x80 | On TES4: lstrings are string table ids |
HiddenFromLocalMap | 0x200 | On a REFR of an ACTI, STAT or TREE: kept with the reference, see below |
Persistent | 0x400 | On REFR: exported as a heuristic, see below |
InitiallyDisabled | 0x800 | On REFR: left off the maps, see export heuristics |
DataCompressed | 0x40000 | The data is compressed, see below |
IsMarker | 0x800000 | On a base object: ResolvedBaseObject.IsMarker |
When DataCompressed is set, the data is a uint32 decompressed size followed by a zlib stream.
Compression.DecompressIfNeeded handles it; every reader calls it first. This is independent
of BSA compression.
Groups
A GRUP header is also 24 bytes, but its size field includes the header. Its label’s meaning
depends on the group type:
| Group type | Name | Label |
|---|---|---|
| 0 | Top | Record type (BOOK, WRLD, …) |
| 1 | World children | Parent WRLD FormId |
| 2, 3 | Interior cell block, sub-block | Block number |
| 4, 5 | Exterior cell block, sub-block | Grid Y, X |
| 6 | Cell children | Parent CELL FormId |
| 7 | Topic children | Parent DIAL FormId |
| 8, 9 | Cell persistent, temporary children | Parent CELL FormId |
| 10 | Cell visible distant children | Parent CELL FormId, not in the UESP table |
Walking a plugin
PluginWalker visits the records a RecordTypeSet asks for. It follows this topology:
GRUP top WRLD
WRLD
GRUP 1 (world children)
CELL (persistent cell) + GRUP 6
GRUP 4 > GRUP 5 > CELL + GRUP 6
GRUP top CELL
GRUP 2 > GRUP 3 > CELL + GRUP 6
GRUP 6 (cell children)
GRUP 8 | 9 | 10 > REFR, ACHR, LAND, NAVM, PGRE, PHZD
GRUP top DIAL
DIAL + GRUP 7 (topic children) > INFO
GRUP top <any other type>
records of that type
A CELL has a children group only if one immediately follows it: the walker reads the next
header and leaves it to the enclosing level when it isn’t the matching group. Interior versus
exterior comes from which top group the walk is in, not from CELL’s DATA flags.
The walker enters a group only when a requested type can be inside it, and otherwise moves straight to the group’s end:
| Group | Entered when the set asks for |
|---|---|
Top WRLD | WRLD, CELL or a cell child type |
Group 1 (world children), top CELL | CELL or a cell child type |
| Group 6 (cell children) | A cell child type: REFR, ACHR, LAND, NAVM, PGRE, PHZD |
Top DIAL, group 7 | DIAL; the topic children only for INFO |
| Any other top group | Its own type, or every top group record |
Each visited record comes with its header, the offset of its data in the file and its enclosing
worldspace and cell (LocationContext). Deleted records are visited too: dropping them is the
caller’s choice, see Reading plugins with queries.
The walker checks every header against the end of the file, and throws InvalidDataException
on a truncated entry, a group smaller than its own header, or a nested group where the spec
allows none (anything but group 7 inside a top group, anything inside groups 7 to 10).
Subrecords
Each subrecord is a 4-byte tag, a uint16 size, then the data. An XXXX subrecord carries a
uint32 that replaces the size of the next subrecord. SubrecordCursor hides it.
Records read
Every reader returns nullable fields: an override record only carries the subrecords it changes, and merging is the caller’s job (see Load order and merging). A subrecord shorter than its spec size is skipped.
TES4
UESP TES4, TES4Reader.
| Subrecord | Type | Field |
|---|---|---|
HEDR | float32, uint32, uint32 | Version, record count, next object id |
CNAM | zstring | Author |
SNAM | zstring | Description |
MAST + DATA | zstring + uint64 | One master; DATA is always 0 |
The order of MAST entries is the master index a FormId’s top byte refers to.
BOOK
UESP BOOK, BookReader.
| Subrecord | Type | Field |
|---|---|---|
EDID | zstring | EditorId |
VMAD | VMAD | Vmad, see below |
FULL | lstring | Title |
ICON | zstring | InventoryImage |
DESC | lstring | Content |
KWDA | formid[] (KYWD) | KeywordFormIds |
DATA | struct, 16 bytes | Flags, Type, Teaches, Value, Weight, see below |
INAM | formid (STAT) | MenuArtFormId |
CNAM | lstring | Description |
DATA layout:
| Offset | Type | Field | Values |
|---|---|---|---|
| 0 | uint8 | Flags | 0x01 teaches skill, 0x02 can’t be taken, 0x04 teaches spell, 0x08 read |
| 1 | uint8 | Type | 0 book or tome, 255 note or scroll |
| 2 | uint8[2] | unused | always 0 |
| 4 | uint32 | Teaches | Actor value index with 0x01, SPEL FormId with 0x04 |
| 8 | uint32 | Value | Gold |
| 12 | float32 | Weight |
A truncated DATA keeps the fields it fully holds. A type outside 0 and 255 is kept as read;
the exporter reports it. KSIZ (the keyword count) isn’t read: KWDA’s length gives the count,
see Assumptions.
INAM points at a STAT whose model carries the artwork; map-like Creation Club books use it
instead of text. MODL, MICO, OBND, DEST, YNAM and ZNAM aren’t read, see
Not implemented.
Named records
NamedRecordReader reads EDID (zstring) and FULL (lstring) from any record type. The
exporter uses it for the SPEL, AVIF and KYWD records a BOOK points at. KYWD has no
FULL.
ActorValues maps the 18 skill actor value indices (6 to 23) to their name and their AVIF
FormId in Skyrim.esm, from UESP Actor Value Indices.
WRLD
UESP WRLD, WorldspaceReader.
| Subrecord | Type | Field |
|---|---|---|
EDID | zstring | EditorId |
FULL | lstring | Name |
WNAM | formid (WRLD) | ParentWorldspaceFormId |
PNAM | uint16 flags | ParentUseFlags |
CNAM | formid (CLMT) | ClimateFormId |
NAM2 | formid (WATR) | WaterFormId |
XLCN | formid (LCTN) | LocationFormId |
XEZN | formid (ECZN) | EncounterZoneFormId |
ZNAM | formid (MUSC) | MusicFormId |
DATA | uint8 flags | Flags |
WCTR | int16[2] | FixedCenterCell |
DNAM | float32[2] | LandData: default land and water heights |
MNAM | 16 or 28 bytes | MapData: map size and NW/SE cells |
NAM0, NAM9 | float32[2] each | Bounds, set only when both are present |
ONAM | float32[4] | MapOffset: world map scale, then X, Y and Z offsets |
Other WRLD subrecords aren’t read.
CELL
UESP CELL, CellReader.
| Subrecord | Type | Field |
|---|---|---|
EDID | zstring | EditorId |
XCLC | int32, int32, uint32 | GridX, GridY; the flags aren’t read |
DATA | uint16 flags, sometimes one byte | Flags, including “Has Water” |
XCLW | float32 | WaterHeight, as stored |
An XCLW can be a “no water” marker instead of a height. CellWaterHeight.IsWater sorts them
out, see Deviations.
LAND
UESP LAND, LandscapeReader. The
walker yields a LAND without reading it; only the map water layer and the raster-records
background parse it. VNML and DATA are not read.
| Subrecord | Type | Field |
|---|---|---|
VHGT | float32, int8[33x33], 3 unused | Heights: 33x33 heights in game units |
VCLR | uint8[33x33x3] | Colors: an RGB vertex color per vertex, on the VHGT grid |
BTXT | formid, uint8 quadrant, 3 unknown | Textures.BaseTextures: the base LTEX of a quadrant |
ATXT | formid, uint8 quadrant, 1 unknown, uint16 layer | Textures.Layers: one texture layer of a quadrant |
VTXT | 8 bytes per point: uint16 position, 2 unknown, float32 opacity | The points of the ATXT before it |
The float of VHGT is the south-west vertex. Each value of the first column offsets its row and
every row to the north; each other value offsets the rest of its row. One unit is 8 game units, the
offset included. Rows run south to north, columns west to east, 128 units apart.
The quadrants are 0 south-west, 1 south-east, 2 north-west, 3 north-east. A quadrant without a
BTXT, or with a zero LTEX, is drawn with dirt02.dds. The Skyrim page doesn’t describe VTXT;
its layout and the mapping of its points to the 33x33 grid are in
assumptions. A part whose subrecords are
missing or too short is null. A BTXT or ATXT with a quadrant past 3, the VTXT after such an
ATXT, a VTXT point past position 288 and a trailing partial point are dropped.
LTEX, TXST and GRAS
UESP LTEX (LandscapeTextureReader),
UESP TXST (TextureSetReader) and
UESP GRAS (GrassReader).
A LAND texture points at an LTEX, which points at the TXST holding the texture paths and at
the GRAS it grows.
| Record | Subrecord | Type | Field |
|---|---|---|---|
LTEX | EDID | zstring | EditorId |
LTEX | TNAM | formid | TextureSetFormId, the TXST |
LTEX | GNAM | formid, repeated | GrassFormIds, one per GRAS, in record order |
TXST | EDID | zstring | EditorId |
TXST | TX00 | zstring | DiffusePath, the color map, relative to textures\ |
TXST | TX01 | zstring | NormalPath, the normal map, relative to textures\ |
TXST | DNAM | uint16 flags | Flags: 0x01 no specular map, 0x02 facegen textures, 0x04 model-space normal map; null when shorter than 2 bytes |
GRAS | EDID | zstring | EditorId |
GRAS | MODL | zstring | ModelPath, relative to meshes\ |
GRAS | DATA | uint8 Density, uint8 Min Slope, uint8 Max Slope at offsets 0, 1, 2 | Density, MinSlope, MaxSlope; null when DATA is shorter than 3 bytes |
GRAS | DATA | uint16 Distance from water at offset 4, uint32 How water distance is applied at 8 | WaterDistance, WaterMode (GrassWaterMode, numbered from 0, see deviations); null when DATA is shorter than 12 bytes |
A GNAM shorter than a formid is skipped. The units of the GRAS fields are in
assumptions and
water distance; the fields not read are in
not implemented.
LIGH
UESP LIGH, LightReader. A light
placed in a cell is a REFR whose base is a LIGH; its XRDS changes the radius, see
REFR and ACHR.
| Subrecord | Type | Field |
|---|---|---|
EDID | zstring | EditorId |
DATA | uint32 Radius, rgb Color (0x00BBGGRR), uint32 Flags at offsets 4, 8, 12 | Radius, Color, Flags; null when DATA is shorter than 16 bytes |
The fields not read are in not implemented.
NAVM
UESP NAVM and
NVNM, NavmeshReader. Only the
roads layer of the maps parses a NAVM; the crop locates it from its header. Of NVNM, the reader
reads the vertices and the triangles, then stops: edge links, door triangles, cover triangles and
the grid are not read, nor are ONAM, PNAM and NNAM.
| Part | Layout | Field |
|---|---|---|
| Header | uint32 unknown (12), uint32 location marker, formid worldspace, 4 bytes cell or grid | Skipped |
| Vertices | int32 count, then float32 X, Y, Z each | Geometry.Vertices, world units |
| Triangles | int32 count, then 16 bytes each: int16 vertex 0 to 2, int16 edge 0, uint16 edge 1 and 2, uint16 “Cover marker?”, uint16 cover flags | Geometry.Triangles: vertices and the “Cover marker?” field as Flags |
The page names no bit of “Cover marker?”; what the code reads in it is in
assumptions. An NVNM whose counts run
past the subrecord, or with a triangle naming a vertex that isn’t there, leaves Geometry null.
REFR and ACHR
UESP REFR, ReferenceReader. An
ACHR (placed actor) has the same NAME and DATA layout and goes through the same reader.
| Subrecord | Type | Field |
|---|---|---|
NAME | formid | BaseFormId, the placed base object |
DATA | float32[6] | Position, then rotation in radians |
VMAD | VMAD | HasScript: presence only |
XTEL | struct, 32 bytes | HasTeleport; TeleportDestinationFormId is the first field |
XSCL | float32 | Scale, null when absent |
XPRM | struct, 32 bytes | HasPrimitive: presence only |
XRDS | float32 | Radius, null when absent; on a light, an offset to its base’s radius, see light radius |
XTEL marks a cell transition: its destination is the REFR on the other side. An XTEL too
short for the destination still sets HasTeleport.
A REFR’s header flags change meaning with its base’s record type: 0x200 hides an ACTI, STAT
or TREE from the local map but makes a LIGH cast shadows. ReferenceFlags.IsHiddenFromLocalMap
reads the bit the base gives that meaning, see
assumptions.
The Persistent record flag marks an always-loaded reference. Bethesda sets it on quest-critical
placements but also elsewhere, so the export presents it as “possibly quest-related”.
CONT, LVLI, NPC_ and FACT
These are definitions, not placements, so they have no enclosing cell.
| Record | Subrecord | Layout | Read |
|---|---|---|---|
| CONT | CNTO | formid, uint32 count | FormId |
| LVLI | LVLO | uint32 level, formid, uint32 count | All three |
| NPC_ | CNTO | formid, uint32 count | FormId |
| NPC_ | SNAM | formid, int8 rank, 3 unused | Faction FormId |
| FACT | VENC | formid (REFR) | Vendor chest |
An LVLO entry can be another LVLI, so reachability walks the list graph. VENC names a
placed chest REFR, not a CONT. How these combine into book locations is in
Load order and merging.
Base objects
ModeledObjectReader reads EDID, MODL and OBND from any record type: a REFR’s base object
can be a STAT, FURN, DOOR, CONT and a dozen more, all with their model path in MODL.
An ARMO is the exception: its MODL are the FormIDs of its ARMA armatures, and its model on
the ground is MOD2, else MOD4, see armor ground model.
OBND is six int16: x1, y1,
z1, x2, y2, z2, the object’s bounding box in its own space. An OBND shorter than 12 bytes
leaves Bounds null. A STAT’s DNAM gives Material: its Max Angle, its MATO and, in SSE, Considered
Snow. A DNAM under 8 bytes, or naming no material, leaves it null.
MATO
UESP MATO, xEdit for the fields by form version
(DirectionalMaterialReader). Its size tells which fields a DATA has, see
Projected materials.
| Offset | Type | Field | Size from |
|---|---|---|---|
| 0, 4, 8, 12 | float | FalloffScale, FalloffBias, NoiseUvScale, MaterialUvScale | 28 |
| 16 | float × 3 | ProjectionVector | 28 |
| 28 | float | NormalDampener | 32 |
| 32 | float × 3 | SinglePassColor, 0 to 1 | 48 |
| 44 | uint32 | SinglePass | 48 |
| 48 | uint32 | IsSnow | 52 |
A DATA under 28 bytes, or none, leaves Data null. DNAM, the properties of a multipass material, isn’t read.
VMAD
UESP VMAD field,
VmadReader. Decodes the header (version, object format, script count), each script (name,
status from version 4, properties) and each property (name, type, status from version 4,
value). The “Fragments” block of QUST, PERK, SCEN, INFO and PACK isn’t decoded.
Its wstrings are UTF-8, see VMAD string encoding.
| Type | Value |
|---|---|
| 1 | Object: formid and alias id, order depends on the object format |
| 2 | wstring |
| 3 | int32 |
| 4 | float32 |
| 5 | bool (uint8) |
| 11 to 15 | uint32 count, then items of type 1 to 5 |
| Object format | Layout |
|---|---|
| 1 | formid, uint16 alias, 2 zero bytes |
| 2 | 2 zero bytes, uint16 alias, formid |
Truncated data throws InvalidDataException. Only BOOK scripts are exported; REFR only
reports whether a VMAD exists. debug:dump:plugin:vmad
decodes the VMAD of every record type it scans.
lstrings
An lstring is inline text or a string table id, decided once per plugin by the TES4
Localized flag. BufferDecode.LString is the only place that branches on it. Resolving an id
is described in Localization.