BFRES (File Format)/Wii U

From Wexos's Wiki
Jump to navigationJump to search
Under Construction
This article is not finished. Help improve it by adding accurate information or correcting grammar and spelling.

BFRES (Binary caFe RESources) is a file format used on Wii U. It contains model data, texture data, animation data and shader data. All offsets are relative to themselves, and may be 0 if it links to nothing (null).

File Format

Header

The file starts with the following header:

Offset Type Description
0x00 Char[4] File magic. Always FRES in ASCII.
0x04 UInt32 Version number.
0x08 UInt16 Byte-order-mark. FE FF for big endian, FF FE for little endian.
0x0A UInt16 Size of this header. This value is always 0x10, thus it doesn't include the whole header.
0x0C UInt32 Size of the whole file in bytes.
0x10 UInt32 File alignment. GPU data needs to be aligned, and this value sets the alignment required by this file.
0x14 Int32 File name offset. Points to the name of this file.
0x18 UInt32 Size of the whole string table in bytes.
0x1C Int32 String table offset. Points to the first string of the string table.
0x20 Int32 Model dictionary offset.
0x24 Int32 Texture dictionary offset.
0x28 Int32 Skeleton animation dictionary offset.
0x2C Int32 Shader parameter animation dictionary offset.
0x30 Int32 Color animation dictionary offset.
0x34 Int32 Texture SRT animation dictionary offset.
0x38 Int32 Texture pattern dictionary offset.
0x3C Int32 Bone visibility animation dictionary offset.
0x40 Int32 Material visibility animation dictionary offset.
0x44 Int32 Shape animation dictionary offset.
0x48 Int32 Scene animation dictionary offset.
0x4C Int32 Embedded file dictionary offset.
0x50 UInt16 Number of FMDL models.
0x52 UInt16 Number of FTEX textures.
0x54 UInt16 Number of FSKA skeleton animations.
0x56 UInt16 Number of FSHU shader parameter animations.
0x58 UInt16 Number of FSHU color animations.
0x5A UInt16 Number of FSHU texture SRT animations.
0x5C UInt16 Number of FTXP texture pattern animations.
0x5E UInt16 Number of FVIS bone visibility animations.
0x60 UInt16 Number of FVIS material visibility animations.
0x62 UInt16 Number of FSHA shape animations.
0x64 UInt16 Number of FSCN scene animations.
0x66 UInt16 Number of embedded files.
0x68 UInt32 User pointer.

Dictionary

A dictionary is a common structure used in many different structures. It is used for fast name look-up, in order to find a specific array item by its name. It starts with the following structure:

Offset Type Description
0x00 UInt32 Total size of this structure in bytes.
0x04 Int32 Number of nodes following this structure (excluding root node).

A root node follow, and then comes the specified amount of nodes. Each node has the following structure:

Offset Type Description
0x00 UInt32 Search value. Specifies the first difference between two strings.
0x04 UInt16 Left index. Specifies the left node.
0x06 UInt16 Right index. Specifies the right node.
0x08 Int32 Name offset. Points to the key used to perform fast look-up.
0x0C Int32 Data offset. Points to the underlying data this node represents. What data this is depends on where it's used.

User Data

User data is data stored in the game which can be accessed by the game to do anything. It can be retrieved by a game at runtime for any purpose. It has the following structure:

Offset Type Description
0x00 Int32 Name offset. Points to the key of this user data.
0x04 UInt16 N = number of elements stored in the array.
0x06 Byte Type of the elements.
Value Type Description
0 Int32 The data consists of 4-bytes integers.
1 Float The data consists of 4-bytes floating point numbers.
2 String The data consists of strings using the ASCII character set.
3 String The data consists of strings using the UCS-2 character set (like UTF-16, fixed 2 bytes per character).
4 Byte The data consists of bytes.
0x07 Byte Padding.
Numbers

Numerical user data follows directly after this header as an array of N elements.

Strings

Textual data is stored as an array of offsets which point to strings following directly afterwards - they are not located in the file-wide string table. The strings are encoded in UTF-8 with the character set given above, and 0-terminated (there is no 4-byte length prefix as with strings stored in the string table). New lines should be represented with CRLF characters.

Offset Type Description
0x00 Int32[N] N offsets to the strings. The strings are null-terminated and come directly after this array. They are not stored in the string table.

Animation Curve

The animation curve stores the values of an animation. It is a common structure used in all sub files. Each curve has the following structure:

Offset Type Description
0x00 UInt16 Flags. xxxxxxxx xAAABBCC.
  • AAA determines what kind of curve data is stored, resulting in a different number of elements stored per key. They are used to set the key values and control the interpolation from one key to the next.
Value Description Elements per Key
0 Cubic Single 4 (hermite interpolation)
1 Linear Single 2 (linear interpolation)
2 Baked Single 1 (no interpolation)
4 Step Integer 1 (no interpolation)
5 Baked Integer 1 (no interpolation)
6 Step Boolean 1 (no interpolation)
7 Baked Boolean 1 (no interpolation)
  • BB determines the data type of key frames.
Value Size Type
0 4 Single
1 2 Int16
2 1 SByte
  • CC determines the data type of the frame values.
Value Size Type
0 4 Single
1 2 16-bit fixed point value (1 bit sign, 10 bits integral and 5 bits fractional).
2 1 Byte
0x02 UInt16 Number of key frames.
0x04 UInt32 Target offset, an offset in bytes into the corresponding owning structure to animate the field at that relative address.
0x08 Single Start key frame, the first frame at which a key is placed.
0x0C Single End key frame, the last frame at which a key is placed.
0x10 Int32 / Single Data scale, multitplier to the raw frame values to get the final result. Together with Data offset, it is chosen carefully to consider an optimal granularity between the stored values.
0x14 Single Data offset, added to the raw values (after multiplying them with Data scale) to get the final frame value.
If version ≥ 3.4.0.0
0x18 Single Data delta, stores the difference between the first and last key frame value.
0x1C Int32 Key frame array offset.
0x20 Int32 Frame value array offset.
Else
0x18 Int32 Key frame array offset.
0x1C Int32 Frame value array offset.

String Table

The string table stores all strings used in many different sections. It consists of null-terminated strings. All offsets points directly to the string. Before each string there is a UInt32 which stores the length of the string (excluding the null byte). The string length field is aligned by 4.

FMDL

The FMDL section (caFe MoDeL) stores model data. It contains the vertex data, skeleton data, materials and shape data, split into 4 different sections. Each model has the following structure:

Offset Type Description
0x00 Char[4] Section magic. Always FMDL in ASCII.
0x04 Int32 Name offset. Points to the name of this model.
0x08 Int32 Original path offset. Points to the full path of the original file.
0x0C Int32 FSKL skeleton offset.
0x10 Int32 FVTX vertex array offset.
0x14 Int32 FSHP shape dictionary offset.
0x18 Int32 FMAT material dictionary offset.
0x1C Int32 User data dictionary offset.
0x20 UInt16 Number of FVTX vertices.
0x22 UInt16 Number of FSHP shapes.
0x24 UInt16 Number of FMAT materials.
0x26 UInt16 Number of user datas.
0x28 UInt32 Number of processed vertices.
0x2C UInt32 User pointer.

FSKL

FVTX

FSHP

FMAT

FTEX

The FTEX section (caFe TEXture) stores textures data. Each texture has the following structure:

Offset Type Description
0x00 Char[4] Section magic. Always FTEX in ASCII.
0x04 UInt32 Surface dimension.
Value Type
0x00 1D texture
0x01 2D texture
0x02 3D texture
0x03 Cube texture
0x04 1D array texture
0x05 2D array texture
0x06 2D MSAA texture
0x07 2D MSAA array texture
0x08 UInt32 Width of image in pixels.
0x0C UInt32 Height of image in pixels.
0x10 UInt32 Depth of image in pixels.
0x14 UInt32 Total number of images.
0x18 UInt32 Image format.
0x1C UInt32 Anti aliasing mode.
Value Type
0x00 1X anti aliasing
0x01 2X anti aliasing
0x02 4X anti aliasing
0x03 8X anti aliasing
0x20 UInt32 Surface usage.
Value Type
0x00 Texture
0x01 Color buffer
0x02 Depth buffer
0x04 Scan buffer
0x80000000 FTX
0x24 UInt32 Size of the main level image in bytes.
0x28 UInt32 Data pointer, set at runtime.
0x2C UInt32 Size of all mipmaps in bytes.
0x30 UInt32 Mipmap pointer, set at runtime.
0x34 UInt32 Tile mode.
Value Type
0x00 Default
0x01 Linear Aligned
0x02 Tiled 1D Thin 1
0x03 Tiled 1D Thick
0x04 Tiled 2D Thin 1
0x05 Tiled 2D Thin 2
0x06 Tiled 2D Thin 4
0x07 Tiled 2D Thick
0x08 Tiled 2B Thin 1
0x09 Tiled 2B Thin 2
0x0A Tiled 2B Thin 4
0x0B Tiled 2B Thick
0x0C Tiled 3D Thin 1
0x0D Tiled 3D Thick
0x0E Tiled 3B Thin 1
0x0F Tiled 3B Thick
0x10 Linear Special
0x38 UInt32 Swizzle value. A value between 0 and 7 which controlls how the image is swizzled.
0x3C UInt32 Texture alignment.
0x40 UInt32 Pitch.
0x44 UInt32[13] Mipmap offsets. Points to a maximum amount of 13 mipmaps, unused are set to 0. The first offset is relative to the main level image.
0x78 UInt32 First mipmap.
0x7C UInt32 Total number of images.
0x80 UInt32 First slice.
0x84 UInt32 Number of slices.
0x88 Byte[4] Component selector. Swizzles the different components, for red, green, blue and alpha respectively.
Value Type
0x00 Red
0x01 Green
0x02 Blue
0x03 Alpha
0x04 Zero
0x05 One
0x8C UInt32[5] Texture registers. Unknown use.
0xA0 UInt32 Texture handle pointer, set at runtime.
0xA4 UInt32 Array length.
0xA8 Int32 Name offset. Points to the name of this texture.
0xAC Int32 Original path offset. Points to the full path of the original file.
0xB0 Int32 Data offset. Points to the image data.
0xB4 Int32 Mipmap data offset. Points to the mipmap data.
0xB8 Int32 User data dictionary offset.
0xBC UInt16 Number of user datas.
0xBE UInt16 Padding.

FSKA

The FSKA section (caFe SKeleton Animation) stores skeleton animations. Each animation has the following structure:

Offset Type Description
0x00 Char[4] Section magic. Always FSKA in ASCII.
0x04 Int32 Name offset. Points to the name of this animation.
0x08 Int32 Original path offset. Points to the full path of the original file.
0x0C UInt32 Flags. Set of bits controlling how data is stored, packed as xxxxxxxx xxxxxxxx xxxAxxBB xxxxxCxD.
  • A controls the rotation mode. Quaternion = 0, Euler XYZ = 1.
  • BB controls how to perform scaling:
Value Description
0 No scaling
1 Standard scaling
2 Maya scaling
3 Softimage scaling
  • C controls whether the animation is looping.
  • D determines whether curves are baked.
If version ≥ 3.4.0.0
0x10 UInt32 Number of frames.
0x14 UInt16 Number of bone animations.
0x16 UInt16 Number of user datas.
0x18 UInt32 Number of curves.
0x1C UInt32 Baked size.
Else
0x10 UInt16 Number of frames.
0x12 UInt16 Number of bone animations.
0x14 UInt16 Number of user datas.
0x16 UInt16 Number of curves.
0x18 UInt32 Baked size.
0x1C UInt32 Unknown.
0x20 Int32 Bone animation array offset.
0x24 Int32 FSKL skeleton pointer, set at runtime.
0x28 Int32 Bind index array offset. Each element in this array is a UInt16.
0x2C Int32 User data dictionary offset.

Bone Animation

Each bone animation structure stores animation for a specific bone. There are curves for each transformation type, which is linked by this structure. Each entry has the following structure:

Offset Type Description
0x00 UInt32 Flags. Sets of bits packed as xxxxAAAA Axxxxxxx BBBBBBBB BBCCCxxx determining if initial transformational values exist.
  • AAAA A are additional combinable flags which apparently describe how bones affect transformations.
Value Description
1 Segment Scale Compensate
2 Scale Uniform
4 Scale Volume One
8 Rotate Zero
16 Translate Zero
  • BBBBBBBB BB are combinable flags apparently describing what kind of Curves are available.
Value Description
1 Scale X
2 Scale Y
4 Scale Z
8 Rotate X
16 Rotate Y
32 Rotate Z
64 Translate X
128 Translate Y
256 Translate Z
  • CCC are combinable flags determining if data is available in the Bone Animation Data to animate specific transformations:
Value Data Type
1 Scaling, a 3-component Single vector
2 Rotate, a 4-component Single vector, storing an euler XYZ (last component unused) or quaternion rotation.
4 Translate, a 3-component Single vector
0x04 Int32 Bone name offset of the bone to be transformed.
0x08 Byte Start rotation, exact purpose unknown.
0x09 Byte Start translation, exact purpose unknown.
0x0A Byte Number of curves.
0x0B Byte Base bone animation data translate offset, an offset into the base Bone Animation Data structure to retrieve the initial bone translation for resetting it.
0x0C Byte Start curve index, relative to the whole FSKA subfile.
0x0D Byte[3] Padding.
0x10 Int32 Curve array offset.
0x14 Int32 Base Bone Animation Data offset, storing the initial state of the bone.

Bone Animation Data

The Bone Animation header points to an array of float values, which have to be interpreted as 3- or 4-component vectors. Only the elements appearing in the Flags are stored, in the order as follows. The Curve target type is an offset into this structure to animate the corresponding field.

Size Type Description
12 Single[3] Scaling.
16 Single[4] Rotation, either euler XYZ or quaternion.
12 Single[3] Translation.

FSHU

The FSHU section (caFe SHader Uber animation) is used as three different types of animations which are treated the same way. It's used as shader parameter animations, color animations and texture SRT animations. Each animation has the following structure:

FTXP

The FTXP section (caFe TeXture Pattern animation) stores texture pattern animations. Each animation has the following structure:

FVIS

The FVIS section (caFe VISibility animation) is used as two different types of animations which are treated the same way. It's used as both bone visibility animation and material visibility animation. Each animation has the following structure:

FSHA

The FSHA section (caFe SHApe animation) stores shape animations. Each animation has the following structure:

FSCN

The FSCN section (caFe SCeNe) stores scene animations. Each scene animation contains three different types of animations, camera, fog and light. Each animation has the following structure:

Embedded File

Embedded files are generic file data which is stored inside the BFRES file. It can contain any data, however, usually it is used to store a BFSHA shader file. Each entry has the following structure:

Offset Type Description
0x00 Int32 Offset to file data. Points to the start of the generic file.
0x04 UInt32 Length of the file in bytes.

Version List

Version Found in
2.2.0.3
2.2.0.6
3.0.0.1
3.2.0.1
3.3.0.1
3.4.0.2
3.4.0.4
3.5.0.2
3.5.0.3

Tools

The following tools can handle BFRES files: