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

From Custom Mario Kart
Jump to: navigation, search
m (typos)
m (Common Format)
Line 60: Line 60:
 
|- style="background-color:#e0ffe0"
 
|- style="background-color:#e0ffe0"
 
| rowspan=2 | [[SCN0 (File Format)|SCN0]]
 
| rowspan=2 | [[SCN0 (File Format)|SCN0]]
| rowspan=2 | <tt>AnmScn(NW4R)</tt><br/>?
+
| rowspan=2 | <tt>AnmScn(NW4R)</tt><br/>Polygon morphing animations.
 
| 4 ||  6 ||    3 ||    3 || 0x2f4 || <tt>old_mario_gc_*.szs</tt>
 
| 4 ||  6 ||    3 ||    3 || 0x2f4 || <tt>old_mario_gc_*.szs</tt>
 
|- style="background-color:#e0ffe0"
 
|- style="background-color:#e0ffe0"
Line 89: Line 89:
  
 
File '''main.dol''' seems to support some more sub file formats:
 
File '''main.dol''' seems to support some more sub file formats:
* <tt>Palettes(NW4R)</tt>
+
* <tt>Palettes(NW4R) (does only exist in Brawl)</tt>
* <tt>AnmVis(NW4R)</tt>
+
* <tt>AnmVis(NW4R) (not seen in Mario Kart Wii)</tt>
* <tt>LightSet(NW4R)</tt>
+
* Subfiles which ''SCN0'' use
* <tt>AmbLights(NW4R)</tt>
+
** <tt>LightSet(NW4R)</tt>
* <tt>Lights(NW4R)</tt>
+
** <tt>AmbLights(NW4R)</tt>
* <tt>Fogs(NW4R)</tt>
+
** <tt>Lights(NW4R)</tt>
* <tt>Cameras(NW4R)</tt>
+
** <tt>Fogs(NW4R)</tt>
 +
** <tt>Cameras(NW4R)</tt>
  
 
== String Pool & Extraction ==
 
== String Pool & Extraction ==

Revision as of 23:57, 29 June 2012

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

Preamble

This page contain many statistical information. It is based on a combined DVD created from Mario Kart Wii PAL and NTSC:

Summary:

  • The combined DVD has 1834 SZS file.
  • The combined DVD has 17 BRRES files.
  • If extracting all SZS files, the combined DVD has 4871 BRRES files. This is the test suite for all following statistics.

If you need more list or want to find files with special content, then download mkw-brres-statistics.zip (1.2MB). It contains different file and sub file lists.

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 Sub file version number. The number of sections (N) is dependent of this version number. See next table 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

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

Magic Folder and
description
Version Num of
sections
File
count
Subfile
count
Section size
found in MKW
Found in files
CHR0 AnmChr(NW4R)
Model movement animations.
3 1 5 8 0x120..0x8dc Race/Course/Object/*
5 2 2205 23704 0x80..0x7a70 *
CLR0 AnmClr(NW4R)
Colour changing animations.
4 2 99 190 0x60..0x1a60 *
MDL0 3DModels(NW4R)
Model files.
8 11 14 14 Race/Course/Object/*
old_mario_gc_*.szs
11 14 4773 11161 0xc80..0xaa280 *
PAT0 AnmTexPat(NW4R)
Texture swapping animations.
4 6 973 5828 0x98..0x1cc *
SCN0 AnmScn(NW4R)
Polygon morphing animations.
4 6 3 3 0x2f4 old_mario_gc_*.szs
5 7 12 16 0xf4..0x45c *
SHP0 AnmShp(NW4R)
?
4 3 29 31 0xd4..0xe78 *
SRT0 AnmTexSrt(NW4R)
Texture movement animations.
4 1 3 3 0xac old_mario_gc_*.szs
5 2 966 1834 0x68..0x66c *
TEX0 Textures(NW4R)
Texture files.
1 1 14 83 0x860..0x40060 Race/Course/Object/*
old_mario_gc_*.szs
2 2 10 72 0x240..0x80040 draw_demo*.szs
3 1 4655 30189 0x60..0xaaac0 *

File main.dol seems to support some more sub file formats:

  • Palettes(NW4R) (does only exist in Brawl)
  • AnmVis(NW4R) (not seen in Mario Kart Wii)
  • Subfiles which SCN0 use
    • LightSet(NW4R)
    • AmbLights(NW4R)
    • Lights(NW4R)
    • Fogs(NW4R)
    • Cameras(NW4R)

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!.

Definition

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.
  • Each string is prefix by a 32 bit length value, but the offsets always points to the first character of the string.
  • Each string is terminated by a single NULL character and a padding with more NULL characters until the next 4-align.
  • 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.

Wiimms ISO Tools has implemented this since v0.07a.

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 of all BRRES files of the test suite (see »Preamble« for details). The table shows the position of pointers into the string table.

The data is divided into 2 tables. The first table is a summary of old sub and not important formats. The second table contains all data needed for geame play.

Old Formats

File
type
Group
index
[1]
Offset
[2]
Entry
name
[3]
Comment Implemented [4]
SM CT WS
CHR v3 0x0014 Yes Offset relative to begin of CHR. This is the name string of the sub file header. No No Yes
CHR v3 00 0x0000 Yes No No Yes
MDL v8 0x003c Yes Offset relative to begin of MDL. This is the name string of the sub file header. No Yes Yes
SCN v4 0x0028 Yes Offset relative to begin of SCN. This is the name string of the sub file header. No No Yes
SCN v4 00 0x0020 Yes No No Yes
SRT v4 0x0014 Yes Offset relative to begin of SRT. This is the name string of the sub file header. No No Yes
SRT v4 00 0x0000 Yes No No Yes
TEX v1 0x0014 Yes Offset relative to begin of TEX. This is the name string of the sub file header. No Yes Yes
TEX v2 0x0018 Yes Offset relative to begin of TEX. This is the name string of the sub file header. No No Yes

These old formats only appear in the following files:

  • Directory /Race/Course/ files old_mario_gc_hayasi.szs, old_mario_gc_narita.szs, old_mario_gc_yabuki.szs, draw_demo.szs and draw_demo_d.szs.
  • Directory /Race/Course/Object/ files castle_tree1.brres, castle_tree2.brres, choropu.brres, kinoko_lift1.brres, kuribo.brres, npc_mii_a.brres, pakkun_f.brres and pendulum.brres.

Current Formats

File
type
Group
index
[1]
Offset
[2]
Entry
name
[3]
Comment Implemented [4]
SM CT WS
CHR v5 0x0018 Yes Offset relative to begin of CHR. This is the name string of the sub file header. No Yes Yes
CHR v5 00 0x0000 Yes No Yes Yes
CLR v4 0x0018 Yes Offset relative to begin of CLR. This is the name string of the sub file header. No Yes Yes
CLR v4 00 0x0000 Yes No Yes Yes
MDL v11 0x0048 Yes Offset relative to begin of MDL. This is the name string of the sub file header. Yes Yes Yes
MDL v11 01 0x0008 Yes Yes Yes Yes
MDL v11 02 0x000c Yes Yes Yes Yes
MDL v11 03 0x000c Yes Yes Yes Yes
MDL v11 04 0x000c Yes Yes Yes Yes
MDL v11 05 0x000c Yes Yes Yes Yes
MDL v11 08 0x0008 Yes Yes Yes Yes
MDL v11 08 N=[0x2c/32]; OFF=[0x30/32];
for I=0..N-1: OFF+I*0x34
No N is a 32 bit number at offset 0x2c and the number of layers. OFF is a 32 bit number at offset 0x30 and the base offset of the first layer. The size of each layer is 0x34. Each layer starts with a string offset relative to the current layer. →Details Yes Yes Yes
MDL v11 10 0x0038 Yes Yes Yes Yes
PAT v4 0x0028 Yes Offset relative to begin of PAT. This is the name string of the sub file header. No Yes Yes
PAT v4 00 0x0000 Yes No Yes Yes
PAT 00 list
with
strings
No The last section contains a list with string. →Details No Yes Yes
SCN v5 0x002c Yes Offset relative to begin of SCN. This is the name string of the sub file header. No No Yes
SCN v5 00 0x0020 Yes No No Yes
SHP v4 0x001c Yes Offset relative to begin of SHP. This is the name string of the sub file header. No No Yes
SHP v4 00 0x0004 Yes No No Yes
SRT v5 0x0018 Yes Offset relative to begin of SRT. This is the name string of the sub file header. No Yes Yes
SRT v5 00 0x0000 Yes No Yes Yes
TEX v3 0x0014 Yes Offset relative to begin of TEX. This is the name string of the sub file header. Yes Yes Yes

Footnotes

[1] : This is the index of the BRRES Index Group.

[2] : The offset is relative to the begin of data for each group entry (but see comments for exceptions). Before adjusting a string offset, check the value. If it is zero, don't modify it. Zero offsets can only be found in the 5 excluded files.

[3] : Yes means: The string pointers points always (no exception found) to same same string as the name pointer of the entry within the BRRES Index Group. This is important for a creation process.

[4] : Tool abbreviations:


All about BRRES files

BRRES fileIndex GroupSub Files

CHR0CLR0MDL0PAT0SCN0SHP0SRT0TEX0