Mega Files (extension: .MEG) in Petroglyph's games are used to store the collection of game files. By packing these files into a single large file, the operating-system overhead of storing and opening each individual file is removed and it helps avoid fragmentation.
Each Mega File begins with a header, followed by the Filename Table, the File Table and finally, the file data. All fields are in little-endian format.
Header: +0000h numFilenames uint32 ; Number of filenames in the Filename Table +0004h numFiles uint32 ; Number of files in the File Table Filename Table record: +0000h length uint16 ; Length of the filename, in characters +0004h name length ; The ASCII filename File Table record: +0000h crc uint32 ; CRC-32 of the filename +0004h index uint32 ; Index of this record in the table +0008h size uint32 ; Size of the file, in bytes +000Ch start uint32 ; Start of the file, in bytes , from the start of the Mega File +0010h name uint32 ; Index in the Filename Table of the filename
This format is an extension on format #1 by adding extra fields in the header.
Header: +0000h id1 uint32 ; Unknown field, always 0xFFFFFFFF +0004h id2 uint32 ; Unknown field, always 0x3F7D70A4 +0008h dataStart uint32 ; Offset in file of start of data +000Ch numFilenames uint32 ; Number of filenames in the Filename Table +0010h numFiles uint32 ; Number of files in the File Table Filename Table record: +0000h length uint16 ; Length of the filename, in characters +0004h name length ; The ASCII filename File Table record: +0000h crc uint32 ; CRC-32 of the filename +0004h index uint32 ; Index of this record in the table +0008h size uint32 ; Size of the file, in bytes +000Ch start uint32 ; Start of the file, in bytes, from the start of the Mega File +0010h name uint32 ; Index in the Filename Table of the filename
This format is an extension on format #2 by adding extra fields in the header and reformatting the file table record.
Mega Files in this format can be encrypted. This is indicated by the flags field in the header being 0x8FFFFFFF. Encrypted MegaFiles encrypt the following fragments:
Header: +0000h flags uint32 ; Flags field, 0xFFFFFFFF or 0x8FFFFFFF (unencrypted file, encrypted file resp.) +0004h id uint32 ; Unknown field, always 0x3F7D70A4 +0008h dataStart uint32 ; Offset in file of start of data +000Ch numFilenames uint32 ; Number of filenames in the Filename Table +0010h numFiles uint32 ; Number of files in the File Table +0014h filenamesSize uint32 ; Size, in bytes, of the Filename Table Filename Table record: +0000h length uint16 ; Length of the filename, in characters +0004h name length ; The ASCII filename File Table record: +0000h flags uint16 ; 1 if entry is encrypted, 0 otherwise. +0002h crc uint32 ; CRC-32 of the filename +0006h index uint32 ; Index of this record in the table +000Ah size uint32 ; Size of the file, in bytes +000Eh start uint32 ; Start of the file, in bytes, from the start of the Mega File +0012h name uint16 ; Index in the Filename Table of the filename +0014h (padding) 14 bytes ; If this entry is encrypted, the record data (everything after the flags) is padded to 32 bytes
It is common or just possible for Petroglyph's games to have multiple Mega Files, and even Mega Files for user mods. All used Mega Files are listed in MegaFiles.xml in a game directory. Petroglyph's games read this file and, load all Mega Files and merge their File Table to create one Master File Table. If a file occurs in multiple Mega Files, the file in the Mega File listed last in MegaFiles.xml will be used.
Some games using the Mega File format use the encryption capability offered with version 3. To be able to read and write such files, the AES key must be known. Listed below are the known keys for various games.