Difference between revisions of "BRRES Sub Files (File Format)"

From Custom Mario Kart
Jump to navigation Jump to search
(Updated with information from SZS Modifier, CTools, Brawl and Dolphin)
m (Added MDL 11 pointer to pointer)
Line 140: Line 140:
 
|-
 
|-
 
| MDL || 10 || 0038 || {{yes|23891 / 23891}} || {{yes}} || -
 
| MDL || 10 || 0038 || {{yes|23891 / 23891}} || {{yes}} || -
 +
|-
 +
| MDL || 11 || 0004 || {{opt|CTools}} || {{yes}} || Pointer to a pointer. Follow twice to get string.
 
|-
 
|-
 
| PAT || —|| 0028 || {{opt|CTools}} || {{yes}} || offset relative to begin of PAT
 
| PAT || —|| 0028 || {{opt|CTools}} || {{yes}} || offset relative to begin of PAT

Revision as of 17:19, 3 May 2011

BRRES files contain many Sub Files. Each of these obeys a similar format.

Common Format

Each files starts with the same header:

Offset Size Description
0x00 4 A magic to identify the sub file
0x04 4 Length of the sub file
0x08 4 Varies
0x0c 4 Offset to outer BRRES File (negative value)
0x10 4 * N N section offsets
0x14 + 4 * N 4 Name string offset

The known values for the magic are given below, along with the purpose, and which folder within the BRRES they are in.

Identifier Folder Description
MDL0 3DModels(NW4R) Model files.
TEX0 Textures(NW4R) Texture files.
SRT0 AnmTexSrt(NW4R) Texture movement animations.
CHR0 AnmChr(NW4R) Model movement animations.
PAT0 AnmTexPat(NW4R) Texture swapping animations.
CLR0 AnmClr(NW4R) Colour changing animations.
SHP0 AnmShp(NW4R) ?
SCN0 AnmScn(NW4R) ?
Not seen Palettes(NW4R) Known to exist from main.dol
Not seen AnmVis(NW4R) Known to exist from main.dol
Not seen LightSet(NW4R) Known to exist from main.dol
Not seen AmbLights(NW4R) Known to exist from main.dol
Not seen Lights(NW4R) Known to exist from main.dol
Not seen Fogs(NW4R) Known to exist from main.dol
Not seen Cameras(NW4R) Known to exist from main.dol

String Pool & Extraction

Nearly all sub files have a directory structure like BRRES files. For this directory structure file names are needed. Most sub files has also some more strings. All these strings of the main BRRES file and of all sub files are stored in common string pool, unique string only once. The string are sorted in ASCII order. The string pool is placed at the end of the BRRES file behind all other data and outside of the sub files.

If extracting only the raw data of a sub file the pointers into the string pool becomes invalid and the names are lost. To avoid this, Chadderz and Wiimm are on the way to define a file format for extracted sub files that includes an local string pool. It is important to understand, that this is not a Nintendo specification!.

If the raw data of a sub file is extracted it is modified with the following rules:

  • The local string pool is added at the end of the file, aligned at a multiple of 4 relative to file start.
  • The size value of the sub file header (offset 4) will not be changed. This helps to find the end of the original sub file when creating a new BRRES file. This position with respect to the aligning is also the start of the string pool.
  • The back reference to beginning of BRRES file is set to the beginning of the new file. This means: Set it to value 0.
  • Sort the string pool in ASCII order without duplicates like Nintendo does.

The last 2 points are important for comparing extracted sub files.

Strings

For extracting it is also important to find all string positions in the different sub files.

The following table is based on a statistical analysis. It shows the position of pointers into the string table. The offset is relative to the begin of data for each group entry. The hit count is the number of string found at this position and the total count is the number of tested BRRES entries. Confirming is necessary!

File
type
Group
index
Offset Hit / Total
counter
Verified Comment
CHR 0018 CTools Yes offset relative to begin of CHR
CHR 00 0000 373161 / 373161 Yes -
CLR 0018 CTools Yes offset relative to begin of CLR
CLR 00 0000 483 / 483 Yes -
MDL 0048 (section count * 4 + 10) CTools Yes offset relative to begin of MDL
MDL 01 0008 30566 / 30566 Yes -
MDL 02 000c 23798 / 23798 Yes -
MDL 03 000c 20878 / 20878 Yes -
MDL 04 000c 18540 / 18540 Yes -
MDL 05 000c 22266 / 22266 Yes -
MDL 06 0008 66 / 66 No -
MDL 06 0448 54 / 66 No -
MDL 08 0008 22469 / 22535 Yes -
MDL 10 0038 23891 / 23891 Yes -
MDL 11 0004 CTools Yes Pointer to a pointer. Follow twice to get string.
PAT 0028 CTools Yes offset relative to begin of PAT
PAT 00 0000 6191 / 6191 Yes -
SCN 00 0020 61 / 61 No -
SHP 00 0004 45 / 45 No -
SRT 0018 CTools Yes offset relative to begin of CLR
SRT 00 0000 2137 / 2137 Yes -
TEX 0014 CTools Yes offset relative to begin of TEX