Game Resource File Formats by Mike Melanson (mike at multimedia.cx) v1.2: January 4, 2004 ======================================================================== NOTE: The information in this document, along with hundreds of other GRAFs, is now maintained at: http://wiki.xentax.com/ ======================================================================== Copyright (c) 2002-2004 Mike Melanson Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". Contents -------- * Introduction * Wing Commander III & IV TRE * Wing Commander Prophecy TRE * Descent II MVL * Westwood Studios MIX, type 1 * Westwood Studios MIX, type 2 * Baldur's Gate BIFF * Chaos Control GB * Sierra ITK * References * Changelog * GNU Free Documentation License Introduction ------------ Many computer games package a number of individual data files into one or more resource files. Reasons for this method probably include maintaining data file integrity as well as making it marginally more difficult for curious gamers to understand the game's data files. This document is a guide to the specific file formats used in various computer games. A note about the byte ordering: Each of these descriptions states which byte ordering the resource file uses to store multi-byte numbers (little endian/Intel ordering or big endian/Motorola ordering). However, this implies nothing about the byte ordering of the constituent data files. Wing Commander III & IV TRE --------------------------- Origin's Wing Commander III and IV titles use resource files with the extension .TRE to store multiple data files. All multi-byte numbers are little endian. A TRE resource is laid out as follows: bytes 0-3 'XTRE' file signature bytes 4-7 unknown bytes 8-11 absolute file offset of ID table bytes 12-15 absolute file offset of optional filename table bytes 16-19 absolute file offset of file data offset table bytes 20-23 absolute file offset of start of file data [ID table] [optional filename table] [file data offset table] [file data] The TRE resource may or may not contain a filename table. If it does not contain a filename table the offset of the optional filename table will be equal to the offset of the file data offset table. The ID table contains a list of file IDs and offsets that index into the filename table. Each 32-bit file ID entry is actually a special checksum calculated over all of the bytes of the data file. Each entry is laid out as: bytes 0-3 32-bit file ID bytes 4-7 absolute file offset that points into the next table If there is no file in the TRE resource that corresponds to a particular entry, the ID will be all 0's and the filename offset will be all 1's. If the TRE resource has a filename table the offset in bytes 4-7 will point into the filename table. Otherwise, bytes 4-7 will point into the file data offset table. The filename table contains a list of MS-DOS-style filenames and offsets that index into the file data offset table. Each entry is laid out as: byte 0 length (n) of filename string, including length byte bytes 1-n filename bytes n+1->n+4 absolute file offset that points into file data offset table The file data offset table contains absolute file offsets that point to the start of individual files within the TRE resource. Each 4-byte entry is an absolute offset that points to the file's data within the main body of the TRE resource. Wing Commander Prophecy TRE --------------------------- Origin's Wing Commander Prophecy game packages multiple data files in resource files bearing the extension .TRE. This is the same extension as the resource format used in WC3 and WC4 but this format is different. All multi-byte numbers are little endian. The resource file begins with the following 16- (0x10-)byte header: bytes 0-3 number of files in TRE resource bytes 4-15 unknown, might be reserved and set to 0 Following the header is a series of 272- (0x110-)byte records, one for each file in the resource as specified in the header. The layout of each record is: bytes 0-3 unknown, might be a checksum like in the previous TRE version bytes 4-7 file size bytes 8-11 absolute offset of file within resource bytes 12-15 unknown, might be reserved and set to 0 bytes 16-271 filename, NULL-padded Descent II MVL ------------- Interplay's Descent 2 title bundles multiple data files within resource files with a .MVL extension. All multi-byte numbers are little endian. A MVL resource file begins with the following 8-byte header: bytes 0-3 signature: 'DMVL' bytes 4-7 number of files in MVL resource Following the header is a series of variable-length records: bytes 0-n variable-length filename, NULL-terminated bytes n+1->n+3 3 unknown bytes bytes n+4->n+7 file size The first file starts immediately after these records. Westwood Studios MIX, type 1 ---------------------------- A variety of games published by Westwood Studios packages multiple data files using resource files with the extension MIX. Two such titles are Command & Conquer and Lands of Lore: Guardians of Destiny. All multi-byte numbers are little endian. A MIX file begins with a 6-byte header: bytes 0-1 number of files in MIX resource bytes 2-5 total size of resource data (resource file size minus the header and file records) Following the header is a series of 12- (0xC-)byte file records, one for each file as specified by the header. Each record is laid out as follows: bytes 0-3 file ID bytes 4-7 relative offset of data file from start of resource body bytes 8-11 file size Westwood Studios MIX, type 2 ---------------------------- There are some Westwood Studios titles that apparently use a different MIX resource format. One such title is Command & Conquer: Red Alert (in the downloadable demo, at least). The structure of this format is yet to be determined. Baldur's Gate BIFF ------------------ Interplay's Baldur's Gate title uses a resource format with the extension .BIF to store multiple data files. All multi-byte numbers are little endian. A BIFF resource file begins with a 16- (0x10-)byte header: bytes 0-3 file signature: 'BIFF' bytes 4-7 resource version, padded with space chars, ex: 'V1 ' bytes 8-11 number of files in resource bytes 12-15 unknown The header is followed by a series of 16- (0x10-)records, one for each file as specified by the header. Each record is laid out as follows: bytes 0-7 unknown bytes 8-11 absolute offset of file within resource bytes 12-15 length of file Chaos Control GB ---------------- In 1995, Philips/Infogrames/I-Motion published a game called Chaos Control. Its CD-ROM contains 4 files: A game executable, an installation executable, a readme.txt file, and a 200 MB chaos.gb resource file which contains the game's data. All of the multi-byte numbers in the chaos.gb resource file are little endian. The chaos.gb resource begins with a variable-length header. This header has the following format: bytes 0-3 signature: '\x1UBA' bytes 4-7 size of header, including signature and this size field bytes 8.. header Bytes 8-n of the header contain a series of 25- (0x19-)byte records with the following layout: bytes 0-12 DOS filename, NULL-padded bytes 13-16 absolute offset of file within resource bytes 17-20 file size bytes 21-24 unknown Sierra ITK ---------- In 1995, Sierra published a title called The Last Dynasty. The 2-disc game used a resource format with the extension .itk. All of the multi-byte numbers in a .itk file are little endian. The resource format begins with a 16-bit number indicating the number of files in the resource. This number is followed by a series of 22- (0x16-)byte records. Each record has the following format: bytes 0-12 DOS filename, NULL-padded bytes 13-16 file size bytes 17-20 absolute offset of file within resource byte 21 unknown, may be reserved and set to 0 References ---------- Command & Conquer Technical Page http://www.geocities.com/SiliconValley/8682/cnc.html Changelog --------- v1.2: January 4, 2004 - added Sierra ITK format v1.1: March 13, 2003 - licensed under GNU Free Documentation License v1.0: December 29, 2002 - initial release GNU Free Documentation License ------------------------------ see http://www.gnu.org/licenses/fdl.html