PAT0 (File Format)
The general file format
This table descibes the general file format for all BRRES sub files:
|0x00||4||The magic "PAT0" to identify the sub file. See »BRRES Sub Files« for other magics.|
|0x04||4||Length of the sub file.|
|0x08||4||Sub file version number. The number of sections (N) is dependent of this version number. See »BRRES Sub Files« for details.|
|0x0C||4||Offset to outer BRRES File (negative value).|
|0x10||N*4||N section offsets. N is implied in the version number (offset 0x08).|
|0x10+N*4||4||String offset to the name of this sub file. This name equal to the name of the entry name of the BRRES Index Group pointing to this data.|
|0x14+N*4||End of this header|
File Format PAT v4
The following information is only valid for PAT version 4. For other versions it is unknown.
Version 4 use 6 sections (numbered from 0 to 5). In Mario Kart Wii a PAT0 file of version 4 have 4 relevant data areas:
- A header with 16 bytes (8 16-bit values?)
- Section #0 with the animation data.
- Section #1 with a string offset list.
- Section #3 with a attributes for each string.
The section #2, #4 and #5 are always empty.
PAT v4 Header
The File Header is followed by a PAT Header (you can also see it as an extension of the file header above). The offset relative to file begin is 0x2c.
|0x00||2||Unknown. Always 0 in MKW.|
|0x02||2||Unknown. Always 0 in MKW.|
|0x04||2||Frame count; values between 2 and 179 in MKW.|
|0x06||2||N_BASE := number of base entries of section #0; 1 or 2 in MKW.|
|0x08||2||N_STR := number of strings in section #1 and #3; values between 2 and 12 in MKW.|
|0x0A||2||Unknown. Always 0 in MKW.|
|0x0C||2||Unknown. Always 0 in MKW.|
|0x0E||2||Cyclic (0=disabled, 1=enabled, other values not used in MKW).|
|0x10||End of this header|
Section #0: Animation data
The animation data consists of 2 blocks: The base data and a string reference. Both blocks have an included list.
|0x00||4||HEAD_SIZE := Size of this structure = 0x18 + N_BASE*0x10|
|0x04||2||Unknown. Always 0 in MKW.|
|0x06||2||N_BASE := number of base entries of this section. In MKW always the same value as N_BASE of PAT header.|
|0x08||2||Unknown. Always 0xFFFF in MKW.|
|0x0A||2||Unknown. Always 0 in MKW.|
|0x0C||2||N_UNKNOWN. Mostly same as N_BASE. Only in 2 tracks (old_heyho_gba/model and old_koopa_gba/vrcorn), N_BASE is set to 2 and N_UNKNOWN to 1.|
|0x0E||2||Unknown. Always 0 in MKW.|
|0x10||2||Unknown. Always 0 in MKW.|
|0x12||2||Unknown. Always 0 in MKW.|
|0x14||2||Unknown. Always 0 in MKW.|
|0x16||2||Unknown. Always 0 in MKW.|
|0x18||N_BASE*0x10|| A list with base data:
|HEAD_SIZE||End of this header|
The base header is followed by the string reference list. The string reference list itself have 2 separated parts:
- The Reference Header: A list with info and an offset to the string list.
- The String List. The list has also an additional header element.
The Reference Header starts at the offset declared by the Base Header:
|0x00||4||Name of element. Offset (relative to beginning of this Reference Header) into the string pool.|
|0x04||2||Unknown. Maybe MSB of type, always 0 in MKW.|
|0x06||2||type, always 5 in MKW.|
|0x08||4||Offset (relative to beginning of this Reference Header) to the related String List.|
|0x0C||End of this header|
Each String List starts at the offset declared by the Reference Header. Each element contains 8 bytes. The very first element is the list header:
|0x00||2||N_ELEM := number of following elements.|
|0x02||2||Padding (always 0).|
|0x04||4|| A factor (float) := 1.0/(MAX-MIN).|
MIN and MAX are the minimal and maximal time values found in the following list. Probably it is used to normalize the range from 0.000 – 1.000.
A fine analysis of all Nintendo PAT files shows up, that Nintendo used 0.9999999/(MAX-MIN) to get little smaller values (and never 1.0 for the maximum).
|0x08||End of this header|
The following elements have this format:
|0x00||4||Probably a time (float). All floats of the list are in ascending order. The first value is mostly 0.000, and sometimes negative (-1.000).|
|0x04||2||Zero based String index into section #1 and #3.|
|0x08||2||Padding (always 0).|
|0x08||End of this element|
Section #1: String list
Section #1 contains N_STR u32 string offsets. Each offset is relative to the start of this section. Each points to a string at the end of the BRRES file. This is used to store the names of the textures to swap.
Section #3 contains N_STR u32 attributes. The assumption is, that each attributes is related to a string of section #1. All attributes are NULL at MKWii.