Small scene members (.SUP, .ZGF, .SGD) and their containers¶
This file describes the three small members of a scene archive and the two containers they use: CHUNKFILE and ZPackedDataChunk. Both containers also appear inside .GMS and .BUF. All 71 instances of each member were checked. tools/port/scene/small.py reads and writes them, and python -I tools/port/scene/roundtrip.py --ext SUP --ext ZGF --ext SGD rewrites 71/71 of each byte for byte.
CHUNKFILE¶
CHUNKFILE (src/engine/zstdlib/chunk.h:6) is IOI's tree container, read in place. Every word is little-endian.
| Offset | Field | Notes |
|---|---|---|
| 0x0 | Name |
32-bit name. The code compares it with multi-character constants ('KEYS', which is the bytes SYEK on disc) or with plain numbers (0x80004, 4). |
| 0x4 | m_lTotalSize |
bits 0 to 29: chunk size in bytes, header included (GetSize). Bits 30 and 31: kind (EType). |
| 0x8 | ... | depends on the kind |
| Kind | Bits | Layout after 0x8 | Data() / GetFileLen() |
|---|---|---|---|
| plain | 0 | data | offset 8, size − 8 |
DataPieces |
0x40000000 | DataOffset, NrDataPieces, PieceSizes[n] |
DataOffset, size − DataOffset |
ChildChunks |
0x80000000 | DataOffset, NrChunks, then the children from offset 0x10 |
same |
ChildChunksAndData |
0xc0000000 | DataOffset, NrChunks, NrDataPieces, PieceSizes[n], then the children |
same |
Children follow one another, each GetSize() bytes long (Next()). FindChild (zrunparamanim.cpp:126) scans ChildCount() of them by name. small.ChunkFile keeps the name, kind, piece sizes, children, the bytes between the children and DataOffset (gap, empty on the disc) and the data. write_chunkfile derives DataOffset and the sizes.
ZPackedDataChunk¶
ZPackedDataChunk is the packed file wrapper (iozip.h:210, setCustomBuffer and unzip). It holds a u32 raw length, a u32 packed length (the whole file length on the disc), a u8 stored flag, and from offset 9 either the raw bytes (stored) or a raw deflate stream followed by the big-endian Adler-32 of the raw bytes. That is a zlib stream without its two-byte header. zlib level 6 reproduces every packed member on the disc, so small.PackedChunk keeps only the payload and re-deflates it. If recompression ever differs, it keeps the original stream.
.SUP¶
ZEngineDataBase::DoLoadScene (enginedatabase.cpp:1884 to 1898) builds the name with CalcCacheFileName("sup"), gets its size and ZDebugBreaks if the file is missing. It allocates a buffer from the top of memory, loads the file into it as a CHUNKFILE and checks that the whole file was read. Nothing uses the buffer after that, and it is never freed. The port's disc layer (port/engine/system/_sdl/disc.cpp:489) finds a scene's name inside an archive by looking for the entry that ends in .SUP.
All 71 files are the same 24 bytes:
| Offset | Value | Meaning |
|---|---|---|
| 0x00 | 0 | root name |
| 0x04 | 0x80000018 | ChildChunks, 24 bytes |
| 0x08 | 0x18 | DataOffset: no data |
| 0x0c | 1 | one child |
| 0x10 | DLCF ('FCLD', 0x46434c44) |
child name |
| 0x14 | 8 | plain, empty |
small.default_sup() builds it.
.ZGF¶
AllocSequence (lines 1068 to 1086) loads the file (GetGeomFilesData, line 496) when its size is above 0. It unpacks the ZPackedDataChunk into the draw allocator and installs the result as a memory big file named "GeomFiles" (ZSysFile::UseBig(CHUNKFILE *, name), sysfile.cpp:375). File lookups then search it before the disc until RemoveAllBigs runs after the geoms are created (line 1159), so geometry loaders can open files embedded in the scene. A missing or empty .ZGF only calls RemoveAllBigs.
The payload is a root CHUNKFILE named 'ZGFT' (the bytes TFGZ) with one child per file (ZBigFile, filesystem.cpp:203 to 450):
- The entry child's
Data()is the zero-terminated path.Findcompares it case-insensitively, after turning/into\. - The entry's first child holds the file: its
Nameis the file size (GetSizereturnsFirstChild()->GetName()), and itsData()is the contents (Load).
Every .ZGF on the disc is the same 17 bytes: raw length 8, packed length 17, stored, and the empty plain chunk 'ZGFT' of 8 bytes. small.GeomFiles exposes the entries as files (path, contents). default_zgf() builds the empty one.
.SGD¶
LoadPackedStaticGameLevelData (enginedatabase.cpp:1337) creates ZStaticGameLevelData. If GetStaticGameLevelDataSize is not −1, it loads the file and Load (static_game_level_data.cpp:38) keeps the pointer as m_pFirstDataBlock. Nothing reads it: SStaticGameLevelDataBlock is only forward-declared, and CreatePackedStaticGameLevelData is empty. The pointer is freed with the scene.
All 71 files are 8 bytes: 0xffffffff, then 0xcdcdcdcd (heap fill). The first word reads as an empty block list.
What a new scene needs¶
.SUP: required, since its absence is aZDebugBreak. Any content works; use the 24-byte default. The port needs the entry to locate the scene in its archive..ZGF: optional. Use the 17-byte default, or add files that scene loaders should find through the "GeomFiles" big file..SGD: optional. When present, the content is unread. Copy the 8-byte default.
Unknown¶
- The meaning of the
.SUPchild name'FCLD'and why the engine loads a file it never reads. Most likely it is a leftover of an older scene-include mechanism;SetAllocSequencePercent(AS_INCLUDESCENE)follows the load. - The layout of
SStaticGameLevelDataBlock. No code reads one.