Field script bytecode
Field script bytecode
Every field map in flevel.lgp carries entities, each with up to 32 script slots, each a
run of bytecode. All 256 opcodes are accounted for: across the 702 retail maps,
336,736 scripts — 1.45 M instructions — decode to a clean terminator, with no unknown
opcode and no run off the end.
Two measured properties matter more than the opcode table, because they are what make an edit safe rather than merely possible.
Branch targets are relative to the displacement address
Every forward branch targets displacementAddress + displacement. Sweeping all candidate
bases over all retail code makes that the unique conflict minimum for all eight
conditionals that ship — 490 conflicts against 9,352–19,535 for the runner-up on IFUB.
Three opcodes the published decompilation left open are settled by that margin.
A script is a contiguous byte range
The fixed-point walk stays in one unbroken run for 99.38% of scripts, and no script in the game reaches an address below its own entry point.
That is what makes insertion cheap. New code goes in at the string table's front edge, so
every existing instruction keeps its address, every existing jump displacement stays valid,
and only the edited entry PC, stringTableOffset and the AKAO offsets move. An edit that
preserves a script's size is patched in place at no cost.
Measured across all 702 maps: a no-op edit reproduces the file byte-identically 702/702, a
same-size edit patches in place 702/702, and a growing edit leaves every other script and
every dialogue string intact on 701/702. The exception is snw_w, whose string table starts
inside a run of dummy entry points.
Not here
The opcode table itself — mnemonic, operand shapes, stack effect, one row per opcode. It
belongs in _index/ as a generated table rather than hand-typed into this note, since it
comes out of the disassembler that proved the numbers above.
Facts
- Source
- measured
- Status
- verified
- Targets
- pc-1998
- pc-steam
- Updated
- 2026-08-20
technical/opcode/field-script