BTP File Format

Contents


  1. Quick Intro
  2. General vocabulary
  3. BTP definitions
  4. BIN BTP file format
  5. BIN BTP file example
  6. CSV BTP file format
  7. Notes for Super Mario Galaxy


Quick Intro


BTP is JSYSTEM file format used on several Wii games. It is a file that contains the information of texture swap animations that take place on the materials of a BMD/BDL 3D model. This file format description is based on the BTP files found on Super Mario Galaxy. The main page (and the only one at the time) from where some information was found about this file format was in the BTP file format page on The Wind Waker's (TWW) CloudModding wiki.

Due to the incompleteness of information presented on said page I had to test some SMG BTP files (mostly from SMG's Mario model) with the J3D Animation Editor (or JAE) and j3dview programs that can read these files. Even with that, it was a very good and nice starting point (so thanks to the ones involved in the writing process). At the end, I managed to describe most data blocks of this file excluding ones I suppose are used for information separation purposes (I am unsure about this). Data blocks which purpose was not able to be discovered yet are tagged with "Unknown". Also, BTP files store data in Big Endian mode (BTPs from 3D All-Stars store data in Little Endian).

If there is any issue on the information provided please open an issue on this NotABug repository to let me know.



General vocabulary


The types of variables/definitions used in the file format need to be defined for the compression of its structure. Some (almost all) definitions were created as they did not exist in the information consulted. The BTP file format is a file written in Big Endian mode so the functions to read the file must be written considering such data storing convention. The vocabulary needed for the types of variables used in the BTP file format is as follows:



BTP definitions


The list of definitions used on the BTP file format is as follows:


Image could not be loaded.

(Fig. 0 - Ilustration of how the BTP Animation Length affects the animation data for each material to be shown in game, see Animation Length for a Material)



BIN BTP file format


In the following table it is shown the structure of the BTP file format.

BLOCK: Relevant data block number

DESCRIPTION: Description of what the block of data contains

There will be a total of 27 blocks for the important information on a BIN BTP file.

BLOCK DESCRIPTION
$$ BTP header
00 BTP file start (char[4])
01 BTP ID (char[4])
02 BTP file size in bytes (u32)
03 Number of sections on the BTP file (u32, always 00 00 00 01?)
04 Unknown 1 (16 bytes, always FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF?).
$$ TPT1 section
05 TPT1 section start (char[4])
06 TPT1 section size in bytes (u32)
07 Loop Mode (u8)
08 Unknown 2 (1 byte, always FF?)
09 BTP Animation Length (u16)
10 Animated Material Count (u16)
11 Animated Material Length Summation (u16)
12 Offset of the TPT1 section with respect to the start of the BTP header (u32, always 00 00 00 20?)
13 Offset of the Texture Swap Table with respect to the start of the TPT1 section (u32)
14 Offset of the Material Position Table with respect to the start of the TPT1 section (u32)
15 Offset of the Material Name Table with respect to the start of the TPT1 section (u32)
16 Start of the Animation Table
The following (Number of materials * 8) bytes are:
17 Start of the Texture Swap Table
The following (Number of materials * 2) bytes are:
  • Texture swap animation data of the first material stored on the BTP (u16 array of length defined by the data in BLOCK 16). See the Texture Swap Table definition to understand what each u16 number represents in this table.
  • ... (repeat for the second, third... material given the number of materials set for the BTP animation)
18 Padding 1 (until the nearest offset that is a multiple of 4)
19 Start of the Material Position Table
The next (Number of materials * 2) bytes are:
  • Numeric position of the first material stored on the BTP in the "material array" of the BMD/BDL file (u16)
  • ... (repeat for the second, third... material given the number of materials set for the BTP animation)
20 Padding 2 (until the nearest offset that is a multiple of 4)
21 Start of the Material Name Table
22 Unknown 5 (2 bytes, always FF FF?)
23 Information specific to the name of each material to be animated.
The following (Number of materials * 4) bytes are:
  • String weight of the name of the first material stored on the BTP (truncated into u16).
  • Offset of the string of the name of the first material stored on the BTP with respect to the Material Name Table start (u16, with respect to BLOCK 21)
  • ... (repeat for the second, third... material given the number of materials set for the BTP animation)
24 Start of the string array with the names of the materials to be animated on the BTP file
  • It contains (Number of materials) strings (null terminated) that represent the names of each material.
25 Padding 3 (until the nearest offset that is a multiple of 32)
26 END OF FILE


BIN BTP file example


The following images are from a BTP file from Super Mario Galaxy. Specifically, it is the iceflick.btp contained on the MarioAnime.arc file from the ObjectData folder. This BTP file contains information for 3 materials but there is only relevant data on the EyeLid_v material (the second one). In the other materials, the texture to be used in the animation is exactly the same on all frames.

Image could not be loaded.

(Fig. 1 - iceflick.btp file opened on ImHex a hex editor, relevant data blocks are colored following the file structure mentioned above in the same order)


Image could not be loaded.

(Fig. 2 - Continuation of figure 2's color block names)


Notice how Padding 1 does not exist in this file as the Animation Table finishes on address 19B. Address 19C, the address in which more information can be then put, is already a multiple of 4 address. You can see better the behaviour with Padding 2

Also, the BTP Animation Length indicates that the animation of all materials will end after 53 frames so the animation length of all materials is 53 frames. 54 frames is the Animation Length for all materials on this particular BTP so every texture number data of the Texture Swap Table, except the last of each material texture swap data, is used for the actual BTP animation that will show in game.



CSV BTP file format


A normal CSV (Comma Separated Values) file that is humanly readable/editable and that is formatted so that the relevant/important information about the BIN BTP file can be stored on it. This format was got from the j3d animation editor program and, in my opinion, it is a very good intermediate file format for the BIN BTP file.

In Fig. 3 the CSV BTP file equivalent from the iceblick.btp is shown in a normal text editor with their respective data blocks named. Each data block data purpose can be understood by using the BIN BTP file format table from above.

Image could not be loaded.

(Fig. 3 - iceblick.btp CSV BTP equivalent)


Description of the numbers from Fig. 3:

The j3d animation editor (this program came out first) and bean (I made this one >:]) programs are able to convert BIN BTPs into their respective CSV BTP equivalent and convert said CSV BTPs back to a BIN BTP file.



Notes for Super Mario Galaxy


In this section there will be information about how Super Mario Galaxy handles all of the data blocks mentioned above for a BTP file. Some might need futher investigation and some are just confusing. Either way, if you got more info about how JSYSTEM games treat BTP files open an issue here and let me know!

Details about the tests:

Notes:

DATA BLOCK PROPERTIES
BTP file start FATAL
BTP ID FATAL
BTP file size GOOD
BTP section count HUH?
  • 00 00 00 00 does not make the game to crash but the BTP animation does not load.
  • 00 00 00 02 does not make the game to crash and the BTP animation loads without issues.
  • All other values make the game to crash (cannot test all values).
Unknown 1 GOOD
TPT1 section start HUH?
  • anything that isn't "TPT1" does not make the game to crash but BTP animation does not load.
TPT1 section size GOOD
Loop Mode HUH?
  • Any number outside the 0 - 4 range will act as if the animation is in loop mode 0.
Unknown 2 GOOD
BTP Animation Length HUH?

If loop mode is set to 2 (loop infinitely).

  • 00 00 does not make the game to crash, animation is reproduced and it stops in last frame.
  • 00 01 does not make the game to crash, animation gets to its first frame.
  • 00 02 does not make the game to crash, animation is looped around the first 2 frames.
  • 00 03 does not make the game to crash, animation is looped around the first 3 frames.
  • [NUMBER] does not make the game to crash, animation is looped around the first [NUMBER] frames.

I would expect the above behaviour to happen as well with the other loop modes (adjusted to what the other loop modes do).

Animated Material Count HUH?

BTP with one material only:

  • 00 00 does not crash the game but the BTP animation does not load.
  • 00 01 does not crash the game and the animation the material on the BTP is playing (the normal behaviour).
  • 00 02 makes the game to crash.
  • Higher values make the game to crash.

BTP with 2 materials:

  • 00 00 does not crash the game but the BTP animation does not load.
  • 00 01 does not crash the game and the animation of the first material on the BTP plays.
  • 00 02 does not crash the game and the animation of both materials on the BTP are playing (the normal behaviour).
  • 00 03 makes the game crash.
  • Higher values make the game to crash.

This data block is the number of materials to be animated (and it does not have to be equal to the number of materials on the BTP file). If there are 3 materials and Animated Material Count is set to 2 only the first 2 materials on the BTP file will get its animation displayed on game.

Material Animation Length Summation GOOD
TPT1 section offset DUNNO
Texture Swap Table offset DUNNO
Material Position Table offset GOOD
Material Name Table offset DUNNO
Animation Length for a Material HUH?
  • If set to 0 seems to not load any texture? (Can't realy tell).
Material Animation Data Position HUH?
  • As the texture swap number can be literally anything (because of what I say below) this number can also be anything (RAM can be read and the BTP animation will still go lol, I expect a great possibility of a game crash to occur if reading outside the file). Game crashes occur but not exactly when the scene loads but a bit after, probably, it is because the number makes it so that reading occurs outside the file.
Unknown 3 HUH?
  • The zero has to be zero otherwise the animation of the specific material related to this unknown 3 won't load/show on the model.
Unknown 4 GOOD
Texture Swap Number HUH?
  • Can be literally any number and the game wont crash. If you use texture numbers that are larger than the last texture number in the respective model, in the game, the animation will still load but I cannot predict the textures that will show in the animation. The textures loaded can be from the same model or the model can completely dissapear (I don't know how those "impossible numbers" dissapearing/another valid texture, probably some memory loaded textures?). Also, far object textures are affected when the BTP tries to load these "impossible textures" on the test model depending on the camera and movement around it (the original texture is replaced by some random one, when you move it will probably change to another one).
Padding 1 GOOD
Material Position on BDL GOOD
Padding 2 GOOD
Animated Material Count (the repeated one) HUH?
  • Has to be higher or equal to the Animated Material Count that shows first on the BTP file otherwise the game will crash. The BTP animation plays normally when this number follows that rule.
Unknown 5 GOOD
Material String Weight GOOD
Material String Offset HUH?
  • Has to point to a string containing the name of a material that exists on the BDL model for a texture swap animation to play. The game does not crash if a not valid material name is read.
Material Name String HUH?
  • Can be anything (and the game does not crash) but only an animation will be played if that string is the name of a material on the BDL to animate (read the above data block).
Padding 3 GOOD