PKG File Format
Previous  Top  Next

Psychonauts .PKG File Format:
By Bgbennyboy


Offsets are relative to the beginning of the file unless otherwise stated.

In the XBox version the .pkg file is zlib compressed. There is a 16 byte header then a compressed zlib archive. The format of this header is:

4 bytes: Header 'ZLIB'
4 bytes: Version
4 bytes: Size of file when decompressed
4 bytes: Size of compressed file (minus the 16 byte header)


Structure of file:
Section
Size (in bytes)


Header:
512 bytes
File records:
16 * Number of Files
Unknown data:
Offset of Name Directory - End of File Records
Name directory:
Offset of File Types - Offset of Name Directory
File Types directory:
End of File Types Dir - Offset of File Types Dir
File data:
Rest of file



File Header:
4 bytes: Header 'ZPKG'
4 bytes: Version
4 bytes: End of File Types Directory
4 bytes: Number of files
4 bytes: End of File Records
4 bytes: ?
4 bytes: Offset of Name Directory
4 bytes: Offset of File Types Directory


File Records:
Each file record is 16 bytes long:
1 byte: Null
2 bytes: File Extension Offset (relative to start of file ext dir)
1 byte: Null
4 bytes: Offset of name in Name Directory (relative to start of name dir)
4 bytes: Offset of file data
4 bytes: File data size


Name Directory:
This contains the name of every file (without the file extension).
Each filename is null terminated (00)
To get the filename, read the 'Offset of name in Name Directory' value from the file record and seek to this value + 'Offset of Name Directory'.
Be aware that some files share the same filename.


File Types Directory:
This lists the file extensions of the various files in the .PKG.
Each file extension is null terminated.


Dumping files:
To dump a file:
1) Read the file record
2) Seek to (Offset of name in Name Directory + Start offset of Name Directory)
3) Read the filename and add the correct file extension according to the identifier
4) Seek to 'Offset of file data'
5) Copy out 'File data size' bytes