Skip to content

Scene geometry list (.GMS)

Every scene archive holds one .GMS, the compiled geometry tree of the scene. ZEngineDataBase::AllocSequence loads it (GetGeomsData, src/engine/enginedata/enginedatabase.cpp:398, called at line 1067), unpacks it into the draw allocator (lines 1098 to 1117) and passes it to CreateGeoms (line 550). That function creates one ZBaseGeom per record, attaches each to its group, then streams the .PRP properties onto the new geoms in the same order. The header also locates the light lists, the pathfinder data and the resource geoms in the .GMS, and four blocks in the .BUF.

This file was checked against all 71 .GMS members on the disc. tools/port/scene/gms.py reads and writes the format, and python -I tools/port/scene/roundtrip.py --ext GMS rewrites all 71 byte for byte. The disc holds 198,583 geoms in 35,318 groups.

Container

The file is a ZPackedDataChunk (src/engine/zstdlib/iozip.h:210, setCustomBuffer and unzip at iozip.cpp:776):

Offset Type Field Notes
0x0 u32 raw length m_iRawDataLength, the size of the unpacked data
0x4 u32 packed length m_iPackedDataLength. Every file on the disc stores the whole file length here. inflate gets it as avail_in.
0x8 u8 stored flag nonzero means STORED: the raw bytes follow uncompressed
0x9 stream raw deflate (inflateInit2(-15), zlib 1.1.3), then the big-endian Adler-32 of the raw data

The stream is a zlib stream without its two-byte header, so zlib.compress(raw, 6)[2:] reproduces every .GMS on the disc exactly. All 71 are zipped. A STORED file also works, because unzip copies m_pPackedData + 9. AllocSequence asks the draw allocator for the unpacked size rounded up to 16 bytes, and ZDebugBreaks if it does not fit (line 1109).

Unpacked layout

All offsets in the unpacked data are byte offsets from its start, and every section starts on a 16-byte boundary. Padding between sections is zero. The writer's order is the disc's order:

  1. SPackedGeomsHeader (0x48 bytes, padded to 0x50).
  2. The geom area: positions, matrices and SCompiledGeom records.
  3. Group counters (StartQuad[5]).
  4. Light table (StartQuad[6]).
  5. Room environment list (m_lRoomEnvironmentListOffset).
  6. Packed geoms tree (StartQuad[0]).
  7. Pathfinder data (m_lOffsetPathfinder4Data).
  8. Geom resources (m_lGeomResourcesOffset), only in 25 scenes.
  9. Geom resource headers (m_lGeomResourcesHeadersOffset), only in 25 scenes.
  10. Geom type counts (StartQuad[4]).

SPackedGeomsHeader (src/engine/enginedata/geombuffer.h:78)

Offset Field Points into Read by Values on the disc
0x00 StartQuad[0] GMS: packed geoms tree CreateGeoms (enginedatabase.cpp:573), Get_My_Data (loader_sequence_player_ps2.cpp:223)
0x04 StartQuad[1] nothing 0
0x08 StartQuad[2] nothing 0
0x0c StartQuad[3] nothing 4
0x10 StartQuad[4] GMS: geom type counts CreateGeoms line 565, then CountNrGeoms (line 906)
0x14 StartQuad[5] GMS: group counters CreateGeoms line 597
0x18 StartQuad[6] GMS: light table, 0 for none CreateGeoms line 781, skipped when m_bDisableLight is set always present
0x1c StartQuad[7] bytes, not an offset CreateGeoms line 572: the event buffer is this plus 0x57800 (0x70800 for m10_main, 0x53000 for m09_main), at least 0x40000 0 to 0x4ae48
0x20 m_lGeomResourcesHeadersOffset GMS, 0 for none ZGeomBuffer::InitResourceGeoms (geombuffer.cpp:381)
0x24 m_lGeomResourcesOffset GMS, 0 for none InitResourceGeoms
0x28 m_lRoomEnvironmentListOffset GMS nothing always present
0x2c m_iCollisionDataOffset nothing 0
0x30 m_iMaterialDescOffset BUF: material description database ZMaterialDescriptionDB::Create (AllocSequence line 1129). This is always read, so it must be valid.
0x34 m_lOffsetPathfinder4Data GMS, 0 for none AllocSequence lines 1138 to 1142, InitPathfinder4Data (line 971) always present
0x38 m_lPhysicsDataOffset BUF, 0xffffffff for none AllocSequence line 1143, ZDynamicsExtendRuntime::ReadDataBuffer 0xffffffff, except 2 scenes
0x3c m_iHighestGeomNr count CreateGeoms line 580: the remap table has this + 1 entries largest m_iGeomNr + 1
0x40 m_iWeaponPrimsOffset BUF, 0 for none ZHM3GameData::InitWeaponHandles (AllocSequence lines 1119 and 1150). In _main scenes it also triggers PurgePrimBuffer. 64 scenes
0x44 m_iExcludedAnimNamesOffset BUF nothing (ZGameData::InitExcludedAnimNames has no caller) always present

A zero physics offset would make AllocSequence parse the .BUF magic as physics data, and the parse would fail and ZDebugBreak. A scene without physics must store 0xffffffff.

Geom area

The area starts at 0x50 and ends at the group counters. For each tree entry in order, the writer emits the entry's position if no earlier entry used it, then its matrix if not yet emitted, then its SCompiledGeom. Each item is padded to 16 bytes. Positions and matrices are pooled by offset: the disc's 198,583 geoms share 97,764 positions and 21,270 matrices. gms.py keeps them as positions and matrices lists in first-use order, and the geoms index into them.

Item Size Layout
position 12 (0x10 padded) V3: x, y, z floats
matrix 36 (0x30 padded) M33: 9 floats, row major
SCompiledGeom 0x38 (0x40 padded) below

The engine does not read the position and matrix. A geom's Matrix, Position and Prim come from its ZGEOM properties in the .PRP (ZGEOM::SetMatrix, SetPosition and SetPrim in the property graph, src/hitman3/hitman3/hm3properties.cpp around line 6820). The copies in the .GMS are the packer's.

SCompiledGeom (src/engine/zstdlib/zbasegeom.h:317)

Offset Field Meaning Read by Disc values
0x00 lOffsetName BUF offset of the zero-terminated geom name CreateGeoms line 682 (AllocGeom keeps the pointer as the geom's name) always set
0x04 lOffsetMat GMS offset of the matrix nothing
0x08 lOffsetPos GMS offset of the position nothing
0x0c lPrim prim handle in the scene's .PRM (0: none) Get_My_Data and the port's FindScript (port/engine/drawing/_sdl/loadersequencesdl.cpp:159) for the ZLoader_Sequence_Setup geom, where it is a byte offset of the script text in Loader_Sequence.PRM. Normal geoms take the handle from the .PRP. 0 to 22,851
0x10 iColiId nothing 0
0x14 lGeomType geometry class id; bit 0x100000 marks a group class CreateGeoms (AllocGeom, group counting at line 733), GetBaseGeomListType (zbasegeom.cpp:1980), CountNrGeoms 0x200002 (GEOMCLASS_StdObj) on 108,513 geoms, 0x100001 (groups) on 10,487, then 0x2000ff, 0x200046, 0x10002e and others
0x18 lEvents only CanExtraGeomBeZero, which ForceExtraGeom (true) skips 0
0x1c lGeomAndGroupCon bits 0 to 19 are ZBaseGeom control bits, bits 24 to 31 are ZGROUP group control CreateGeoms lines 716 to 746. If 0x8080 is set the geom keeps its light list. BASEGEOM_Dynamic (0x40000) geoms are queued for MakeDynamicGeomsDynamic, and BASEGEOM_AutoRoomAssign (0x4000) for MakeAutoAssignGeomsAutoAssign.
0x20 lExData BUF offset of a CHUNKFILE of extra init data, 0 for none CreateGeoms lines 701 to 711 (pExData->_ExtraInitData). It is referenced in place, because it lies inside the static buffer. 2,142 geoms, 856 distinct chunks
0x24 lDataBlock nothing 0
0x28 lWorldFileId nothing nonzero on 18,706 geoms
0x2c lScripts only CanExtraGeomBeZero 0
0x30 m_iGeomNr the geom's 1-based number, used by references CreateGeoms line 749: pRemaps[m_iGeomNr - 1] = REF unique per scene. Gaps are allowed (66 scenes have them).
0x34 cLightCon nothing 0
0x35 cAssumedGeomDrawList base-geom list bank CreateGeoms line 684: list type is GetBaseGeomListType + 8 * value 0 (179,762), 1 (15,341), 2 (3,480)
0x36 cDummy[2] nothing 0

m_iGeomNr is how the other members address geoms. CreateGeoms remaps these numbers through pRemaps in the pathfinder's door links (RemapDoorRefs), in g_pGameData->RemapRefs, in ZROOM::RemapRefs for every room, and in the material database's scene-resource properties (ZMaterialDescriptionDB::RemapGeoms, materialdescriptiondb.cpp:19).

Packed geoms tree (StartQuad[0])

The tree is a u32 count followed by SPackedGeomsTree entries (src/engine/drawing/_ps2/loader_sequence_player_ps2.h:10), one per geom in creation order. The .PRP holds one property object per entry, plus one for the root, in the same order.

Offset Field Meaning
0x0 lCompiledGeomOffset bits 0 to 23: word offset of the SCompiledGeom (byte offset / 4). Bit 24: the entries that follow are this geom's children. Bits 25 to 31: the number of groups to close before this entry (pZGroup = pZGroup->Parent()).
0x4 lLightListID word index of this geom's list in the light table's static buffer, or 0 for none. CreateGeoms stores it in ZBaseGeom::m_uListID and clears it unless control bit 0x8080 is set.

Entries start under the root (ZROOM "ROOT", type 0x100021, allocated by AllocRootGroup). Up to 5 groups close at one entry on the disc. Only group-class geoms open groups. gms.py stores the flags as opens_group and parents_closed. It stores the light list as an index into light_table.lists and derives the word offsets when writing.

Group counters (StartQuad[5])

The counters are a u32 count followed by that many SGeomTypeCounters rows of 24 u32 (enginedatabase.h:65). Row 0 belongs to the root. Row k belongs to the k-th group-class geom (lGeomType & 0x100000) in tree order, because CreateGeoms increments lGroupNr for every such geom (line 733), whether or not it has children. When a group's first child arrives, CreateGeoms allocates as many ZBaseGeoms as the row sums and hands them out per list type: index GetBaseGeomListType (0 group, 1 std obj, 2 light, 3 other) + 8 × cAssumedGeomDrawList. On the disc there is one row per group-class geom plus one, and each row sums to the group's direct child count. gms.check() tests both. A wrong row makes geoms share base-geom slots.

Geom type counts (StartQuad[4])

The type counts are a u32 count followed by SGeomTypeCount rows (enginedatabase.h:51): m_lGeomType, m_lGeomCount and m_lNoNeedExtraGeom, 12 bytes each and sorted by type. CountNrGeoms sizes the base-geom buffer (count × 0x70, at least 0x40000) and the extra-geom buffer (count × the class's m_lSize, or 0x10 for an unknown class, at least 0x40000) from them. In 25 scenes the counts exceed the tree's geoms, because they include resource geoms that are created later. gms.compute_type_counts gives the plain counts. m_lNoNeedExtraGeom is unused, because ForceExtraGeom returns true.

CountNrGeoms then adjusts by scene name (enginedatabase.cpp:927). When m_sDefaultScene contains _main but not m00, it subtracts 0x708 base geoms and 0x32000 bytes, or 0x8fc/0x76c geoms and 0x4b000 bytes for m09 and m10. All arithmetic is unsigned, so a new _main scene with few geoms wraps to a huge buffer. Name a small scene without _main.

Light table (StartQuad[6])

The light table is a u32 byte size followed by the CListUser buffer (src/engine/enginedata/listuser.cpp:534). CreateGeoms copies it into a new allocation and calls ConvertOffsetsToRefs on the copy (line 787).

Word Field
0 m_uSizeOfStaticBuf, the static part in words, these four included
1 m_uSizeOfDynamicBuf, pool words (0x2800, larger in 14 scenes)
2 m_uSizeOfRuntimeBuf, pool words (0xfa0 everywhere)
3 0xffffffff everywhere; nothing reads it
4 ... static lists
static ... dynamic and runtime pools: (word 1 + word 2) × 4 bytes, all 0xcd on the disc (the packer's heap fill)

Each list is a dynamic-head word (0 in the file; at run time it points to SDynBlock chains) followed by entries until one has bit 0 set (LISTUSER_END). An entry is a base-geom reference in bits 3 to 31. FixMember (listuser.cpp:521) resolves it as REF (entry & ~7) + 0x60 | 0x40000000, which is base-geom slot (entry + 0x60) / 0x70. Bit 1 (LISTUSER_FROMTO) makes the entry the start of a range that runs to the next entry. An empty list is the single entry 1. On the disc, every list is used by exactly one geom: 98,877 lists with 283,700 entries.

Room environment list (m_lRoomEnvironmentListOffset)

The list is a u32 count followed by pairs of u32. Nothing in the engine reads it. 26 scenes have entries, 1 to 159 of them. The values are offsets in an unknown space: some coincide with GMS records, most do not. gms.py keeps the pairs as they are.

Pathfinder data (m_lOffsetPathfinder4Data)

The pathfinder data is a u32 length followed by the PF4RunTime::ZData::LoadDataBlock input (src/engine/pathfinder4/pf4runtime.cpp:659). InitPathfinder4Data copies it and creates the pathfinder only when the length is nonzero. Scenes without navigation store a 0x1c-byte block of zero counts. The block starts with 14 ZIndex (16-bit) counts, then one packed array per count, in this order, with no alignment. The arrays fill the length exactly on the disc.

Count Record (pf4runtime.h) Size Fields
m_iSplitTreeCount ZSplitTree 0x10 m_iSide[2], eqn[3]
m_iHeightTreeCount ZSplitTree 0x10 same
m_iPlaneEquationCount ZPlaneEquation 0xc m_fA, m_fB, m_fC
m_iComponentCount ZComponent 0x14 m_Corners, m_SubNodes, m_ObstacleIds, pad, m_MetaNodes (u32), m_Graph, m_FirstCorner, m_FirstSubNode, m_FirstObstacleId, m_FirstHeightTree, 2 pad
m_iGraphCount ZGraph 0x30 12 ZIndex (m_iNodes ... m_iEquations, m_iFirstExitDist unsigned), ZBBox m_BBox (min, max)
m_iNodeCount ZNode 0x14 m_kPos (x, z), m_fHeight, m_iFirstLink, m_iLastLink, m_iComponent, m_iGraph
m_iVertexCount ZVertex 0x14 m_kPos, m_fHeight, m_kNormal
m_iLinkCount ZLink 0x10 m_fCost, m_iNode, m_Graph, m_Type, m_iAction, m_iKeyMask, 2 pad, m_rDoorController. The controller is a geom number, which RemapDoorRefs turns into a REF.
m_iExitDistCount ZIndex 2
m_iCornerCount ZCorner 4 m_iComponent, m_iVertex
m_iSubNodeCount ZSubNode 8 m_Node, m_Divider, m_SourceComponent, m_Component
m_iStaticObstacleIdCount ZIndex 2
m_iStaticObstacleCount ZStaticObstacle 4 m_FirstVertex, m_Vertices
(iTemp) read and discarded; 0 on the disc

Several components in one graph join through corners whose m_iComponent names the neighbour, and a node plus one sub-node per side on each shared edge; build_scene.level_pathfinder builds that from rectangles and NPC routes cross between rooms on it (new-scene.md). 26 scenes have navigation data. The largest arrays are 9,781 split trees, 3,163 nodes, 6,840 vertices, 22,400 exit distances and 10,816 corners. No scene has static obstacles.

Geom resources (m_lGeomResourcesOffset, m_lGeomResourcesHeadersOffset)

InitResourceGeoms copies both tables. Resources are a u32 count followed by SGeomResources rows (m_lGeomType, m_lNrUnusedGeoms). Headers are a u32 count followed by SGeomResourcesHeader rows (m_lId, m_lGeomResourcesStart, m_lNrGeomResources). On the disc the header ids are the four-character constants 'ITEM' (25 scenes) and 'ZCOB' (14 scenes), and they slice the resource table. Both offsets are 0 in the other 46 scenes.

What a new scene needs

  • A zipped (or STORED) packed chunk whose raw length matches.
  • A header with physics 0xffffffff, a valid .BUF material database offset, weapon prims 0 (or a table), and the excluded-anim offset pointing at any BUF block (it is unread; the disc uses a zero count).
  • One SCompiledGeom per geom, with name, type, control, m_iGeomNr (unique, from 1) and cAssumedGeomDrawList 0. Position, matrix and prim may be anything, since the .PRP sets them, but every record needs some position and matrix offset.
  • A tree whose nesting matches the .PRP children counts. Group counters with 1 + (group-class geoms) rows, each summing to the group's direct children and split by base-geom list type. m_iHighestGeomNr = largest geom number + 1.
  • Type counts covering every class used, so the base-geom and extra-geom buffers are big enough.
  • A light table (the four header words and no lists is valid, as in attractmode) or offset 0, a room environment list (count 0), pathfinder data (a zero-count block, or offset 0), and no resources.
  • event_length large enough for the scene's controllers. 0 still leaves 0x57800 bytes.

gms.check(geom_list) reports structural problems. gms.write derives every offset and tree word.

Unknown

  • StartQuad[1..3] (0, 0, 4 everywhere) and light-table word 3 (0xffffffff): written by the packer, read by nothing.
  • The room environment pairs: offsets into a space that is not this file.
  • iColiId, lEvents, lDataBlock, lScripts, cLightCon and cDummy, which are zero everywhere, and lWorldFileId, which is nonzero on 18,706 geoms. Nothing reads them.
  • Why 25 scenes' type counts exceed their tree. They include resource geoms, but the exact rule is not checked.