Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

FlagValueUse
Deleted0x20Deleted records are dropped by a query unless it asks for them
DoorHiddenFromLocalMap0x40On a REFR of a DOOR: kept with the reference, see below
Localized0x80On TES4: lstrings are string table ids
HiddenFromLocalMap0x200On a REFR of an ACTI, STAT or TREE: kept with the reference, see below
Persistent0x400On REFR: exported as a heuristic, see below
InitiallyDisabled0x800On REFR: left off the maps, see export heuristics
DataCompressed0x40000The data is compressed, see below
IsMarker0x800000On 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 typeNameLabel
0TopRecord type (BOOK, WRLD, …)
1World childrenParent WRLD FormId
2, 3Interior cell block, sub-blockBlock number
4, 5Exterior cell block, sub-blockGrid Y, X
6Cell childrenParent CELL FormId
7Topic childrenParent DIAL FormId
8, 9Cell persistent, temporary childrenParent CELL FormId
10Cell visible distant childrenParent 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:

GroupEntered when the set asks for
Top WRLDWRLD, CELL or a cell child type
Group 1 (world children), top CELLCELL or a cell child type
Group 6 (cell children)A cell child type: REFR, ACHR, LAND, NAVM, PGRE, PHZD
Top DIAL, group 7DIAL; the topic children only for INFO
Any other top groupIts 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.

SubrecordTypeField
HEDRfloat32, uint32, uint32Version, record count, next object id
CNAMzstringAuthor
SNAMzstringDescription
MAST + DATAzstring + uint64One 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.

SubrecordTypeField
EDIDzstringEditorId
VMADVMADVmad, see below
FULLlstringTitle
ICONzstringInventoryImage
DESClstringContent
KWDAformid[] (KYWD)KeywordFormIds
DATAstruct, 16 bytesFlags, Type, Teaches, Value, Weight, see below
INAMformid (STAT)MenuArtFormId
CNAMlstringDescription

DATA layout:

OffsetTypeFieldValues
0uint8Flags0x01 teaches skill, 0x02 can’t be taken, 0x04 teaches spell, 0x08 read
1uint8Type0 book or tome, 255 note or scroll
2uint8[2]unusedalways 0
4uint32TeachesActor value index with 0x01, SPEL FormId with 0x04
8uint32ValueGold
12float32Weight

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.

SubrecordTypeField
EDIDzstringEditorId
FULLlstringName
WNAMformid (WRLD)ParentWorldspaceFormId
PNAMuint16 flagsParentUseFlags
CNAMformid (CLMT)ClimateFormId
NAM2formid (WATR)WaterFormId
XLCNformid (LCTN)LocationFormId
XEZNformid (ECZN)EncounterZoneFormId
ZNAMformid (MUSC)MusicFormId
DATAuint8 flagsFlags
WCTRint16[2]FixedCenterCell
DNAMfloat32[2]LandData: default land and water heights
MNAM16 or 28 bytesMapData: map size and NW/SE cells
NAM0, NAM9float32[2] eachBounds, set only when both are present
ONAMfloat32[4]MapOffset: world map scale, then X, Y and Z offsets

Other WRLD subrecords aren’t read.

CELL

UESP CELL, CellReader.

SubrecordTypeField
EDIDzstringEditorId
XCLCint32, int32, uint32GridX, GridY; the flags aren’t read
DATAuint16 flags, sometimes one byteFlags, including “Has Water”
XCLWfloat32WaterHeight, 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.

SubrecordTypeField
VHGTfloat32, int8[33x33], 3 unusedHeights: 33x33 heights in game units
VCLRuint8[33x33x3]Colors: an RGB vertex color per vertex, on the VHGT grid
BTXTformid, uint8 quadrant, 3 unknownTextures.BaseTextures: the base LTEX of a quadrant
ATXTformid, uint8 quadrant, 1 unknown, uint16 layerTextures.Layers: one texture layer of a quadrant
VTXT8 bytes per point: uint16 position, 2 unknown, float32 opacityThe 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.

RecordSubrecordTypeField
LTEXEDIDzstringEditorId
LTEXTNAMformidTextureSetFormId, the TXST
LTEXGNAMformid, repeatedGrassFormIds, one per GRAS, in record order
TXSTEDIDzstringEditorId
TXSTTX00zstringDiffusePath, the color map, relative to textures\
TXSTTX01zstringNormalPath, the normal map, relative to textures\
TXSTDNAMuint16 flagsFlags: 0x01 no specular map, 0x02 facegen textures, 0x04 model-space normal map; null when shorter than 2 bytes
GRASEDIDzstringEditorId
GRASMODLzstringModelPath, relative to meshes\
GRASDATAuint8 Density, uint8 Min Slope, uint8 Max Slope at offsets 0, 1, 2Density, MinSlope, MaxSlope; null when DATA is shorter than 3 bytes
GRASDATAuint16 Distance from water at offset 4, uint32 How water distance is applied at 8WaterDistance, 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.

SubrecordTypeField
EDIDzstringEditorId
DATAuint32 Radius, rgb Color (0x00BBGGRR), uint32 Flags at offsets 4, 8, 12Radius, Color, Flags; null when DATA is shorter than 16 bytes

The fields not read are in not implemented.

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.

PartLayoutField
Headeruint32 unknown (12), uint32 location marker, formid worldspace, 4 bytes cell or gridSkipped
Verticesint32 count, then float32 X, Y, Z eachGeometry.Vertices, world units
Trianglesint32 count, then 16 bytes each: int16 vertex 0 to 2, int16 edge 0, uint16 edge 1 and 2, uint16 “Cover marker?”, uint16 cover flagsGeometry.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.

SubrecordTypeField
NAMEformidBaseFormId, the placed base object
DATAfloat32[6]Position, then rotation in radians
VMADVMADHasScript: presence only
XTELstruct, 32 bytesHasTeleport; TeleportDestinationFormId is the first field
XSCLfloat32Scale, null when absent
XPRMstruct, 32 bytesHasPrimitive: presence only
XRDSfloat32Radius, 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.

RecordSubrecordLayoutRead
CONTCNTOformid, uint32 countFormId
LVLILVLOuint32 level, formid, uint32 countAll three
NPC_CNTOformid, uint32 countFormId
NPC_SNAMformid, int8 rank, 3 unusedFaction FormId
FACTVENCformid (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.

OffsetTypeFieldSize from
0, 4, 8, 12floatFalloffScale, FalloffBias, NoiseUvScale, MaterialUvScale28
16float × 3ProjectionVector28
28floatNormalDampener32
32float × 3SinglePassColor, 0 to 148
44uint32SinglePass48
48uint32IsSnow52

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.

TypeValue
1Object: formid and alias id, order depends on the object format
2wstring
3int32
4float32
5bool (uint8)
11 to 15uint32 count, then items of type 1 to 5
Object formatLayout
1formid, uint16 alias, 2 zero bytes
22 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.