PAT0 (File Format)

From Custom Mario Kart
Revision as of 20:35, 15 June 2017 by Wexos (talk | contribs)
Jump to navigation Jump to search

This page describes the Mario Kart Wii PAT0 file format, as found within BRRES files. PAT0 files are texture pattern animation files.

The general file format

This table descibes the general file format for all BRRES sub files:

Offset Type Description
0x00 String The magic "PAT0" to identify the sub file. See »BRRES Sub Files« for other magics.
0x04 UInt32 Length of the sub file.
0x08 UInt32 Sub file version number. The number of sections (N) is dependent of this version number. See »BRRES Sub Files« for details.
0x0C Int32 Offset to outer BRRES File.
0x10 Int32[N] N section offsets. N is implied in the version number (offset 0x08).
0x10+N*4 Int32 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 info is only valid for PAT version 4. For other versions it is unknown. The exists also an old (and faulty) description.

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.

offset size description
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.

Base Header

Section #0: Base Header
offset size description
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:
offset size description
0x00 2 Unknown. Values between 0x19 and 0x96 in MKW.
0x02 2 Unknown. Always 0 in MKW.
0x04 2 Unknown. Values between 0 and 2 in MKW. Value is only >0, if N_BASE >1.
0x06 2 Unknown. 1 or 2 in MKW. Value is never the same as the value before (offset 0x04) and only 2, if N_BASE >1.
0x08 4 Name of element. Offset (relative to beginning of this Base Header) into the string pool.
0x0C 4 Offset (relative to beginning of this Base Header) to the related Reference Header.
HEAD_SIZE End of this header

Reference List

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:

Section #0: Reference Header
offset size description
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:

Section #0: String List Header
offset size description
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:

Section #0: String List Element
offset size description
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: String related attributes

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.

All about BRRES files

BRRES fileIndex GroupSub Files

CHR0CLR0MDL0PAT0SCN0SHP0SRT0TEX0