This page collects what the project has learned, usually the hard way, about the file formats used by the Infinity Engine games. It is aimed at readers who know programming but have not met these formats before.
The Infinity Engine stores game data as many small resources, each identified by a name of up to eight characters (a resref) and a type (for example ARE for an area, WED for the map layout of an area, TIS for its graphics tiles). Resources are either loose files or packed inside large archives called BIFF files (.bif). A master index, CHITIN.KEY, records for each resref which archive holds it and where. PlanarForge reads the index, locates the archive, extracts the bytes, and interprets them with a YAML schema.
Two community projects document these formats and are the project's constant companions:
- IESDP, the Infinity Engine Structures Description Project, is the written specification of the formats.
- Near Infinity is a Java viewer and editor for the same files, widely used for checking what a file really contains.
IESDP is an excellent but human-maintained document, and it is sometimes wrong or incomplete. The project's rule of thumb, in order of authority:
- What the bytes actually contain, checked in a hex editor.
- What Near Infinity shows for the same file.
- What IESDP says.
When these disagree, the disagreement is worth recording. Known cases:
- Size of a WED tilemap entry. Earlier project notes record IESDP as giving 8 bytes, while Near Infinity and hex dumps showed 10. The current IESDP WED V1.3 page ends the structure with three unknown bytes at offset
0x0007, which gives 10, so the upstream error appears to have been fixed. The schemawed_v1_3.yamluses 10. - Area flags and area type in the ARE header. The double word at
0x14holds the area flags (save, rest, travel and similar) and the word at0x48holds the area type (outdoor, city, dungeon and so on). IESDP and the project schemas use those names; Near Infinity labels the two fields the other way round, "Area type" and "Location". The flag meanings themselves agree between IESDP and Near Infinity: bit 0 is Save not allowed, not "save allowed" as the ARE schemas once had it (issue #67).
Other IESDP errors were found during earlier work but were not written down. They are to be recovered and listed here as the maintainer re-reviews the code.
A TIS file holds the picture tiles of an area. It is only graphics; where each tile goes is described by the area's WED file. IESDP's TIS V1 page describes two variants:
- Palette-based. Each tile carries its own 256-colour palette followed by one byte per pixel. For 64 by 64 tiles that is 1,024 bytes of palette plus 4,096 bytes of pixels, 5,120 bytes in all.
- PVRZ-based. Enhanced Edition games only. Each tile is a small record pointing at a block of pixels inside a separate compressed texture file (
.pvrz). In the project's reading of the format, each record is 12 bytes.
A loose TIS file begins with a 24-byte header. Inside a BIFF archive the layout is different, and two behaviours have caused bugs:
- Each TIS has its own tileset entry, found by the entry's locator, not by its position. A BIFF tileset entry has its own resource locator, and bits 14 to 19 of it are matched against the tileset index in the KEY locator (BIFF V1). In
AREA150C.bif, AR0072 has KEY tileset index 1, but its 1,211-tile entry is at position 0 and its locator carries tileset bits 1. Using the KEY index as a table position read AR0072 from the neighbouring 822-tile entry, which gave the right textures in the wrong places and left AR1516 unloadable (issue #47). A scan of BG2EE's 460 TIS found 349 that the position-based lookup read from the wrong entry and 111 it could not load at all. - An earlier "shared pool" explanation was a misdiagnosis. The project once held that one tileset entry packs the tiles of many TIS and that the KEY
resource_indexnames the first tile. In BG2EE everyresource_indexis 0, no tileset entry is claimed by more than one TIS, and none is unclaimed, so such a rule would never have had any effect. Its symptom, another area's tiles, is what the locator bug above produces. The tool therefore ignoresresource_indexfor tilesets (issue #52). This is verified for BG2EE only; other games' BIFFs are unverified untilpython tools/tis_diagnostic.py --scanis run against them. - PVRZ pages are a size prefix plus one zlib stream holding a PVR v3 file. IESDP says only that PVRZ files are "basically ZLIB-compressed PVR files" and that desktop Enhanced Edition textures are DXT1 or DXT5; the 4-byte uncompressed-size prefix is documented in a community thread (gibberlings3, "PVRZ info"). The PVR v3 header is 52 bytes, with the pixel format at 0x08 (DXT1 = 7, DXT5 = 11), the mip count at 0x2C and the metadata size at 0x30 (PVR File Format Specification 3.0.0).
tools/pvrz_scan.pyfound exactly this in all 3,680 BG2EE and 1,036 IWDEE pages: every size field equals the decompressed length, every header is PVR v3 with no metadata and one mip level, and the texture data is exactly the top level. The decoder accepts only that and raisesPvrzError(aValueError) for anything else, so a corrupt page can never pass for a blank one. PSTEE has not been scanned. The DXT5 colour block is always decoded in four-colour mode; thec0 <= c1three-colour mode applies to DXT1 only (issue #39). - There is no per-resource header, so one must be synthesised. The archive stores tile payloads without the 24-byte TIS header, so the tool builds a header for the schema parser, taking the tile count and tile size from the tileset entry. IESDP also notes that Planescape: Torment can only load TIS files that live in a BIFF.
Choosing the palette or PVRZ schema is done by looking at the tile_data_block_size field of the header (12 or 5,120). The single tis_v1.yaml is split into tis_v1_palette.yaml and tis_v1_pvrz.yaml for this purpose.
The original Planescape: Torment (PST) and the Enhanced Edition (PSTEE) share a lot of structure, and the later EE versions of several other formats resemble PST variants. Naive identification by a single field is therefore dangerous. The known example is area (ARE) files, where actor records are 268 bytes in the PST layout and 272 bytes in the EE layout. The loader currently decides by reading the double word at 0x84 of the header, but in the PST layout that field is offset_to_ambients, not an actor offset, so the test is unreliable (issue #7). Format identification should rest on field-level verification, not on resemblance.
In PSTEE area (ARE) files the header pointers for song_entries, rest_interruptions, automap_notes and projectile_traps are short. The real position of each section is the header value plus 76 × count_of_animations, as if the pointers had been computed without the animations block. The pointer to song_entries therefore equals the one to animations, which looked like two sections sharing an offset; they do not, the song entries follow the animations.
This was checked byte by byte in AR1001 and AR13WZ and by file-size arithmetic in AR3017 (issue #68). In AR1001 the file is 2616 bytes: the last header pointer says 2464, and 2464 + 2 × 76 = 2616. BG2EE AR0300 is consistent with the normal rule. Near Infinity reads the same wrong bytes as the parser did.
The schema states the rule with offset_displacement: {section: animations} on each affected section. The parser adds the displacement when it seeks, and the writer subtracts it when it repacks, so header pointers keep the original convention and an unmodified file still round trips byte for byte.
Two things are still open:
- Only PSTEE has been checked. Whether the original PST shares the quirk needs the original game, and whether the engine follows the pointers or reads sections in sequence decides how serious the quirk is.
AR13WZhas 456 extra bytes, apparently six more animation-like records, between the header's song pointer and the real song entries. They are unexplained.
The original PST layout also has the overlapping-pointer symptom recorded in issue #6: a writer that emits sections one after another cannot step backwards. That symptom is probably the same cause, but this has not been confirmed on the original PST.
These recur across the project's history and are summarised here so that they are not rediscovered:
- The schema is the single source of truth. The same YAML drives parsing, writing, enum and bitmask resolution, and user-interface field generation. Structural knowledge is not duplicated in code.
- Keep schemas lean. Do not redeclare enum or bitmask values, repeat display metadata, or create per-variant files where a single schema with a
games:tag will do. Naming conventions are in the Schema Naming Style Guide, and the available field types in the Field Types Reference. - Preserve what is unknown. A bitmask keeps bits the schema does not name, so that an unmodified file can be written back byte for byte. Editing is different: once a resource is modified, a clean repacked file is the goal. See Round-trip Fidelity.