Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Papyrus compiled script (PEX)

From ReverseEngineering.wiki
Format
Magic DE C0 57 FA (little-endian files), FA 57 C0 DE (Skyrim, big-endian)
Extensions .pex
Endianness big (Skyrim) or little (Fallout 4, Fallout 76, Starfield)
On this wiki Facts · Code · Notes · Topics

Compiled Papyrus scripts (.pex) of Bethesda's Skyrim, Fallout 4, Fallout 76 and Starfield: magic 0xFA57C0DE whose byte order selects a big-endian (Skyrim) or little-endian (Fallout 4 and later) layout, a header with compile time and source name, a string table, debug info, objects with variables, properties, states and bytecode functions.

Identification

A compiled Papyrus script (Bethesda's scripting language for Skyrim, Fallout 4, Fallout 76 and Starfield; the usual extension is .pex) starts with a 32-bit magic that also tells the byte order. Champollion's reader reads the first four bytes as a little-endian u32: 0xFA57C0DE means the whole file is little-endian (bytes DE C0 57 FA: the newer Fallout 4 style layout, also used by Fallout 76 and Starfield), 0xDEC057FA means the file is big-endian (bytes FA 57 C0 DE: the Skyrim layout). Any other value is rejected with "Invalid file magic". Source: orvid/Champollion Pex/FileReader.hpp and Pex/FileReader.cpp (LGPL-3.0; the wiki records only the layout, no code).

Header

After the magic: major version u8, minor version u8, game id u16, compilation time (64-bit time_t), then three strings: source file name, user name, computer name. A string is a u16 length followed by that many bytes (no terminator). In the little-endian layout the game id selects the dialect: 4 = Starfield, 3 = Fallout 76, anything else is treated as Fallout 4; big-endian files are treated as Skyrim. Unverified: the exact game id values for Skyrim and Fallout 4 and the usual major/minor version numbers (the reader does not check them).

Privacy note: the header stores the user name and computer name of whoever compiled the script, so do not copy those values into a wiki page.

Layout after the header

  1. String table: u16 count, then that many strings. Everywhere else a name is a u16 index into this table (an index past the end is an error).
  2. Debug info: a u8 flag; if non-zero a modification time (64-bit), a u16 function count and per function: object name, state name, function name (string indices), function type u8, u16 instruction count and one u16 source line number per instruction. Only the little-endian layout continues with property groups (object, group name, doc string, user flags u32, name list) and struct orders (object, order name, name list).
  3. User flags: u16 count of (name index, flag bit index u8).
  4. Objects (classes): u16 count; per object: name index, a u32 that the reader skips (Unverified: probably the byte size of the object data), parent class name, doc string, [little-endian only: const flag u8], user flags u32, auto state name, [little-endian only: struct infos], variables, [Starfield only: guards], properties, states.
  5. Variables: name, type name, user flags u32, default value, [little-endian only: const flag u8]. Struct infos (little-endian): struct name, members (name, type, user flags, default value, const flag, doc string).
  6. Properties: name, type, doc string, user flags u32, flags u8; if the auto-var flag is set an auto variable name follows, otherwise a read function body when readable and a write function body when writable.
  7. States: name, then functions (name, then body). A function body is return type, doc string, user flags u32, flags u8, parameters (name and type pairs), locals (same), and instructions.
  8. Instruction: opcode u8, a fixed number of values by opcode, and for opcodes with variable arguments an integer value giving the extra count followed by that many values.

A value is a type byte then data: 0 none, 1 identifier (string index), 2 string (string index), 3 integer (32-bit), 4 float (32-bit), 5 bool (u8).

Opcodes

The reader's table has 51 opcodes numbered in this order: nop, iadd, fadd, isub, fsub, imul, fmul, idiv, fdiv, imod, not, ineg, fneg, assign, cast, cmp_eq, cmp_lt, cmp_lte, cmp_gt, cmp_gte, jmp, jmpt, jmpf, callmethod, callparent, callstatic, return, strcat, propget, propset, array_create, array_length, array_getelement, array_setelement, array_findelement, array_rfindelement (these 36 exist in Skyrim); new in Fallout 4: is, struct_create, struct_get, struct_set, array_findstruct, array_rfindstruct, array_add, array_insert, array_removelast, array_remove, array_clear; new in Fallout 76: array_getallmatchingstructs; new in Starfield: lock_guards, unlock_guards, try_lock_guards. The three call opcodes and the guard opcodes take variable argument lists. Unverified: jump operands are relative instruction offsets (not read in the decompiler source).

Tools

  • Champollion (orvid/Champollion, LGPL-3.0): PEX to Papyrus source decompiler; its Pex/ directory is a readable description of the format.
  • Unverified: the Creation Kit ships the Papyrus compiler that produces these files, and plugins attach scripts to records through VMAD subrecords.

Related: Format:Bethesda archive (BSA and BA2) (scripts ship inside archives), Format:Bethesda plugin (ESP, ESM, ESL).

Code & repositories

  • https://github.com/orvid/Champollion @ bc961a0bdfb4831f8240e6dacee0818b4bf81e00 · license: LGPL-3.0
    Champollion: Papyrus PEX decompiler for Skyrim, Fallout 4, Fallout 76 and Starfield; Pex/ holds the binary reader
    Tested on: source read, not run · checked 2026-10-19; last activity 2023-10-17; Note: the latest release ships binaries; the wiki links only the source, never the binaries