Yet Another Gamecube Documentation

15  Game File Formats


This Section contains information about files used in, or produced by the official SDK, and thus is primarily useful for those who are hacking retail games.
index

15.1  AFC (audio stream)


index

15.2  AST (audio stream)


like afc but with tags?
index

15.3  ARC (RARC Archive)


This file is an archive file and contains several other files.
index

15.3.1  Header


The file starts with an Rarc-Header:
start end size description
    4 type - 'RARC'
    4 size, size of the file
    4 unknown
    4 dataStartOffset, where does the actual data start? You have to add 0x20 to this value.
    16 unknown
    4 numNodes
    8 unknown
    4 fileEntriesOffset
    4 unknown
    4 stringTableOffset, where is the string table stored? You have to add 0x20 to this value.
    8 unknown

index

15.3.2  Nodes


Next are RarcHeader.numNodes Node structures:
start end size description
    4 type
    4 filenameOffset, directory name, offset into string table
    2 unknown
    2 numFileEntries, how many files belong to this node?
    4 firstFileEntryOffset

Each RARC file contains at least one Node, the 'ROOT' node. For each subdirectory in the archive, there's another Node (so each Node represents a directory). Each Node contains files and directories, represented by FileEntry structures:
index

15.3.3  File Entries


start end size description
    2 id, file id. If this is 0xFFFF, then this entry is a subdirectory link
    2 unknown
    2 unknown
    2 filenameOffset, file/subdir name, offset into string table
    4 dataOffset, offset to file data (for subdirs: index of Node representing the subdir)
    4 dataSize, size of data
    4 zero, seems to be always '0'

To read the archive, you read the root node and its file entries. For each subdir in the root node's fileentries, you read the corresponding node and its file entries. For each file in the fileentries, you dump its data.
index

15.4  ARC (audio stuff)


if a .arc file doesnt start with 'RARC' it may contain audio data
index

15.5  ASN


audio related, contains strings
index

15.6  AW ("audio wave"?)


index

15.7  BAS ("audio script" ?)


seems to have to do with audio (check mkdd file names...)
index

15.8  BCA


looks very similar to a .col file, only with some tags in it
index

15.9  BCK (animation of a .bmd skeleton)


index

15.10  BDL


same as .bmd
index

15.11  BFN (font)


images of characters + mapping from character code to corresponding image part
index

15.12  BIN (binary file)


scene.bin in sms contains scene layout
index

15.13  BLO (screen layout for dialog screens)


index

15.14  BMD (3d model with texture and skeleton)


index

15.15  BMG


messages, subtitles, ... (text)
index

15.16  BMP (window bitmap (!))


index

15.17  BMT


seems to contain a MAT3 block of a .bmd file
index

15.18  BCK ("Pack" file)


index

15.19  BRK


animation stuff? rotation keys?
index

15.20  BTI


Note: some .bti files are Yaz0-compressed (if the first 4 bytes are 'Yaz0'), if this is the case you have to uncompress them first. A .bti file stores a single image, but can store several mipmaps. The file starts with a texture-header (which is used in the TEX! section of bmd/bdl and jpa files to store textures aswell):
index

15.20.1  Texture Header


start end size description
0x00   1 format
     
0 I4 (4 bit intensity, 8x8 tiles)
1 I8 (8 bit intensity, 8x4 tiles)
2 IA4 (4 bit intensity with 4 bit alpha, 8x4 tiles)
3 IA8 (8 bit intensity with 8 bit alpha, 4x4 tiles)
4 RGB565 (4x4 tiles)
5 RGB5A3 (*) (4x4 tiles)
6 RGBA8 (4x4 tiles in two cache lines - first is AR and second is GB)
8 CI4 (4 bit color index, 8x8 tiles)
9 CI8 (8 bit color index, 8x4 tiles)
10 CI14X2 (14 bit color index, 4x4 tiles)
14 CMP (S3TC compressed, 2x2 blocks of 4x4 tiles)
0x01   1 unknown
0x02 0x03 2 width
0x04 0x05 2 height
0x06 0x07 2 unknown
0x08   1 unknown
0x09   1 Palette Format
     
0 IA8
1 RGB565
2 RGB5A3 (*)
0x0a 0x0b 2 Palette Entries - number of entries in the Palette
0x0c 0x0f 4 Palette Offset - offset to Palette Data
0x10 0x13 4 unknown
0x14 0x15 2 unknown
0x16 0x17 2 unknown
0x18   1 mipmap count
0x19   1 unknown
0x1a 0x1b 2 unknown
0x1c 0x1f 4 Data Offset - offset to image Data
 
 
(*) RGB5A3 is RGB5 if color value is negative and RGB4A3 otherwise. Offsets are relative to the Texture Header (this is important in bmd/bdl files).
index

15.21  BTP


99% sure that this contains texture animation (NOT texture coordinate animation)
index

15.22  BTK


(curves??? kinematics??) translation keys? probably some material animation as well (texture coord anim?)
index

15.23  COL (collision triangles)


index

15.24  DZB


collision data ?
index

15.25  H4M


a proprietary Movie Format found on some Gamecube Game DVDs. Probably related to the HVQ (Hirarchical Vector Quantization) format developed by Hudson.
index

15.26  JPA (particle data)


(TEX1 section contains .bti images)
index

15.27  JPC


collection of .jpa files ("Particle paCk"?)
index

15.28  MTH ('Mute thp?')


video format, has the same video frame format as thp, but headers are a bit different
index

15.29  PAD


recorded controller data?
index

15.30  PRM ('Parameters?')


index

15.31  REL (relocatable module)


some kind of .dll or similar, contains text and data sections and relocation info
index

15.32  SB


?, contains a stringtable
index

15.33  SZS (packed RARC Archive)


This is a Yaz0-compressed RARC archive
index

15.34  THP (video format)


.thp is a video format on the gamecube. The video frames are independent "quasi-jpegs", and if audio frames are present, they are in an adpcm format (described below).
index

15.34.1  Header data


The file starts with a thp header:
start end size description
0x00 0x03 4 Magic Bytes, 0x54485000 ('THP0')
0x04 0x07 4 Version
     
0x00010000 v1.0
0x00011000 v1.1
0x08 0x0b 4 maxBufferSize - maximal buffer size needed for one complete frame (header + video + audio)
0x0c 0x0f 4 maxAudioSamples - != 0 if sound is stored in file, maximal number of samples in one frame.
0x10 0x13 4 FPS (float value)
     
0x41efc28f ~29; NTSC
   
0x14 0x17 4 numFrames - number of frames in the thp file
0x18 0x1b 4 firstFrameSize - size of first frame (header + video + audio)
0x1c 0x1f 4 dataSize - size of all frames (not counting the thp header structures)
0x20 0x23 4 componentDataOffset - ThpComponents stored here (see below)
0x24 0x27 4 offsetsDataOffset - if != 0, offset to table with offsets of all frames?
0x28 0x2b 4 firstFrameOffset - offset to first frame's data
0x2c 0x2f 4 lastFrameOffset - offset to last frame's data

index

15.34.2  Components structure


At ThpHeader.componentDataOffset, a ThpComponents structure is stored:
start end size description
0x00 0x03 4 numComponents - usually 1 or 2 (video or video + audio)
0x04 0x13 16 componentTypes - each byte specifies the type of one component as follows:
     
0x00 video
0x01 audio
0xff no component

The first ThpComponents.numComponents entries of ThpComponents.componentTypes are valid. For each component, an information structure is stored after the ThpComponents struct.
index

15.34.3  VideoInfo Structure


Component type 0 is video, a ThpVideoInfo struct looks like this:
start end size description
0x00 0x03 4 width
0x04 0x07 4 height
0x08 0x0b 4 unknown (only v1.1 files)

index

15.34.4  AudioInfo Structure


Component type 1 is audio (not always included), a ThpAudioInfo struct looks like this:
start end size description
0x00 0x03 4 numChannels
0x04 0x07 4 frequency
0x08 0x0b 4 numSamples
0x0c 0x0f 4 numData (only for v1.1 files) - amount of audio blocks stored after each video block

index

15.34.5  Frame data


A frame is made up of a frame header followed by a video frame followed by ThpAudioInfo.numData audio frames (only if the video contains sound). The frame header consists of 3 (or 4, if the video contains sound) 32bit values:
start end size description
0x00 0x03 4 nextTotalSize - total size of NEXT frame (frame header, video and audio)
0x04 0x07 4 prevTotalSize - total size of PREVIOUS frame
0x08 0x0b 4 imageSize - size of image frame of THIS frame
0x0c 0x0f 4 audioSize - size of one audio frame of THIS frame (only if the file contains audio)

Directly after the frame header FrameHeader.imageSize bytes video information follow. Directly after the video information, ThpAudioInfo.numData audio frames follow, each Frameheader.audioSize bytes large (only if the file contains audio).
index

15.34.6  Video Frames


A video frame is more or less a jpeg image. A jpeg file is structured by several markers. A marker is a two-byte code, the first of the two bytes is 0xff. The jpeg standard states that if you want to store the value 0xff, you have to store it as 0xff 0x00 (else it would be confused with a marker). This is NOT the case in .thp files, the value 0xff is stored simply as 0xff in the image data. So if you want to use jpeglib to read the frame, you have to convert the thp "quasi-jpeg" to a real jpeg by converting 0xff values to 0xff 0x00 in the image data. You have to be careful that you don't convert the terminating End-Of-Image marker, though. - search for Start-Of-Image marker (0xff 0xda) - search for End-Of-Image marker (0xff 0xd9) (start search at end of buffer and search backwards!) - convert each 0xff between image data start and image data end to 0xff 0x00
- the resulting buffer can be passed to jpeglib to let it decode the image for you
index

15.34.7  Audio Frames


An audio frame starts with a ThpAudioFrameHeader (total size is 80 bytes)
start end size description
0x00 0x03 4 channelSize - size of one channel in bytes (*1)
0x04 0x07 4 numSamples - number of samples/channel
0x08 0x27 32 table for first channel (*2)
0x28 0x47 32 table for second channel (stored for one channel videos as well) (*2)
0x48 0x49 2 signed value, channel1Prev1
0x4a 0x4b 2 signed value, channel1Prev2
0x4c 0x4d 2 signed value, channel2Prev1
0x4e 0x4f 2 signed value, channel2Prev2

(*1) audio frame size = sizeof(ThpAudioFrameHeader) + ThpAudioInfo.numChannels * ThpAudioFrameHeader.channelSize
(*2) tables stored as 16bit signed 5.11 fixed point numbers Directly after the ThpAudioFrameHeader ThpAudioFrameHeader.channelSize bytes follow for the first channel, and if the video is stereo (ThpAudioInfo.numChannels = 2), that many bytes follow for the second channel. The audio data is made up of small packets of 8 byte, each packet contains 14 samples. Some kind of adpcm coding is used. A sample is calculated like this: newSample = previousSample*factor1 + sampleBeforePreviousSample*factor2 + (sampleData * 2^exponent);
For each packet, the first byte stores factor1, factor2 and exponent: u8 index = (firstByte > > 4) & 0x7; //highest bit of byte is ignored
u8 exponent = firstByte & 0xf;
float factor1 = ThpAudioFrameHeader.table[2*index]/pow(2.f, 11);
float factor2 = ThpAudioFrameHeader.table[2*index + 1]/pow(2.f, 11);
The following 7 bytes store 14 sampleData (each 4 bit, interpreted as a signed two's complement number).
index

15.35  TPL (Texture Palette)


Another custom GameCube file format that holds texture and texture palette data. Many textures can be stored in one TPL file format, and it is commonly used by the SDK to hold texture data for GameCube games.

note: appearently there are different formats of .TPL files, the following applies only to those with the magic 0x00,0x20,0xaf,0x30.

TPL Header

start end size description
0x0000 0x0003 4 Magic (0x00, 0x20, 0xAF, 0x30)
0x0004 0x0007 4 ntextures - Number of Textures in File
0x0008 0x000b 4 size of Header (always 0x0c in files with this structure)


TPL Texture

After the header goes 'ntextures' times the TPLTexture structure:

start end size description
    4 Texture Header Offset
    4 Texture Palette Offset (0 if no palette)


TPL Texture Header

For every texture at position 'Texture Header Offset' there is the TPL Texture Header:

start end size description
    2 height
    2 width
    4 format
     
0 I4 (4 bit intensity, 8x8 tiles)
1 I8 (8 bit intensity, 8x4 tiles)
2 IA4 (4 bit intensity with 4 bit alpha, 8x4 tiles)
3 IA8 (8 bit intensity with 8 bit alpha, 4x4 tiles)
4 RGB565 (4x4 tiles)
5 RGB5A3 (*) (4x4 tiles)
6 RGBA8 (4x4 tiles in two cache lines - first is AR and second is GB)
8 CI4 (4 bit color index, 8x8 tiles)
9 CI8 (8 bit color index, 8x4 tiles)
10 CI14X2 (14 bit color index, 4x4 tiles)
14 CMP (S3TC compressed, 2x2 blocks of 4x4 tiles)
    4 offset to Texture Data
    4 wrap s
    4 wrap t
    4 min filter
    4 mag filter
    4 lod bias (float value)
    1 edge lod
    1 min lod
    1 max lod
    1 unpacked


TPL Palette Header

For every palette (not every texture has one) there is the TPL Palette Header:

start end size description
    2 nitems
    1 unpacked
    1 pad
    4 format
     
0 IA8
1 RGB565
2 RGB5A3 (*)
    4 offset to Palette Data
 
 
(*) RGB5A3 is RGB5 if color value is negative and RGB4A3 otherwise.
index

15.36  YMP (height map)


index