TXD: Difference between revisions

From MultimediaWiki
Jump to navigation Jump to search
(This was difficult)
(Added detail)
Line 10: Line 10:
   uint32_t id;
   uint32_t id;
   uint32_t chunk_size;      // does not include id, chunk_size and marker
   uint32_t chunk_size;      // does not include id, chunk_size and marker
   uint32_t marker;           // 0x1803ffff or 0x1003ffff
   uint32_t rw_version;
   uint8_t  data[chunk_size];
   uint8_t  data[chunk_size];
  } txd_chunk_t;
  } txd_chunk_t;
Line 19: Line 19:
   uint32_t id;              // 0x16 (22)
   uint32_t id;              // 0x16 (22)
   uint32_t chunk_size        // file_size - 12
   uint32_t chunk_size        // file_size - 12
   uint32_t marker;
   uint32_t rw_version;
   uint8_t  data[chunk_size];
   uint8_t  data[chunk_size];
  } txd_file_t;
  } txd_file_t;
Line 26: Line 26:
   uint32_t id;              // 0x01 (1)
   uint32_t id;              // 0x01 (1)
   uint32_t chunk_size;      // 0x04 (4)
   uint32_t chunk_size;      // 0x04 (4)
   uint32_t marker;
   uint32_t rw_version;
   uint16_t count;            // number of textures in the dictionary
   uint16_t count;            // number of textures in the dictionary
   uint16_t unknown;
   uint16_t unknown;
Line 34: Line 34:
   uint32_t id;              // 0x15 (21)
   uint32_t id;              // 0x15 (21)
   uint32_t chunk_size;
   uint32_t chunk_size;
   uint32_t marker;
   uint32_t rw_version;
   uint8_t  data[chunk_size];
   uint8_t  data[chunk_size];
  } txd_texture_t;
  } txd_texture_t;
Line 41: Line 41:
   uint32_t id;                        // 0x01 (1)
   uint32_t id;                        // 0x01 (1)
   uint32_t chunk_size;
   uint32_t chunk_size;
   uint32_t marker;
   uint32_t rw_version;
   uint32_t version;                    // 0x08 (8) or 0x09 (9)
   uint32_t version;                    // 0x08 (8) or 0x09 (9)
   uint32_t filter_flags;
   uint32_t filter_flags;
Line 66: Line 66:
   uint32_t id;              // 0x03 (3)
   uint32_t id;              // 0x03 (3)
   uint32_t chunk_size;
   uint32_t chunk_size;
   uint32_t marker;
   uint32_t rw_version;
   uint8_t  data[chunk_size];
   uint8_t  data[chunk_size];
  } txd_extra_info_t;
  } txd_extra_info_t;


''direct3d_texture_format'' can be one of:
===<code>direct3d_texture_format</code>===
* [[S3TC]] FourCC
This is the format of the texture data found in <code>txd_texture_data_t::data</code>. This value must be known if the textures are to be extracted.
* 0x21 - RGBA32
It can be one of:
* 0x22 - RGB32
* <code>0x21</code> - RGBA32
* 0x00 and flags & 1 is set - [[S3TC]] DXT1 compression (used in old version 8 files)
* <code>0x22</code> - RGB32
* <code>0x00</code> and <code>flags & 1</code> is set - [[S3TC]] DXT1 compression (used in old version 8 files)
 
Additionally, <code>direct3d_texture_format</code> may be a four character code ("FourCC") relating to a DXT format. In such cases, the unsigned integer value is actually the concatenated bytes of the FourCC. For example, <code>0x44585431</code> is "DXT1" (<code>44 58 54 31</code>).
 
===<code>rw_version</code>===
This is the identifier of the version of the RenderWare engine that the file is for. It can be found in many types of RenderWare binary stream file.
{| class="wikitable" style="text-align: center;"
|-
! style="width:15em;" |<code>rw_version</code> Hex
! style="width:15em;" |RenderWare Version
|-
|<code>0x0003FFFF</code>
|3.0.0.3
|-
|<code>0x0800FFFF</code>
|3.?.?.?
|-
|<code>0x00000310</code>
|3.1.0.0
|-
|<code>0x0C02FFFF</code>
|3.3.0.2
|-
|<code>0x1003FFFF</code>
|3.4.0.3
|-
|<code>0x1803FFFF</code>
|3.6.0.3
|-
|}


==Basic file structure==
==Basic file structure==


Indentation means the chunks are sub-chunks (see above):
Chunks other than <code style="color: red">txd_file_t</code> (which has no parent chunk) are nested within the parent chunk's <code>data</code> array. For example, <code style="color: indigo">txd_info_t</code> is found within <code>txd_file_t::data</code>.
 
<code style="color: red">txd_file_t</code>
:<code style="color: indigo">txd_info_t</code>
:<code style="color: green">txd_texture_t</code>
::<code style="color: blue">txd_texture_data_t</code>
::<code style="color: blue">txd_extra_info_t</code>
:<code style="color: green">txd_texture_t</code>
::<code style="color: blue">txd_texture_data_t</code>
::<code style="color: blue">txd_extra_info_t</code>
:<code style="color: green">txd_texture_t</code>
::<code style="color: blue">txd_texture_data_t</code>
::<code style="color: blue">txd_extra_info_t</code>
:<code style="color: green">txd_texture_t...*</code>
 
:<code style="color: indigo">txd_extra_info_t</code>


* txd_file_t
** txd_info_t
** txd_texture_t
*** txd_texture_data_t
*** txd_extra_info_t
** txd_texture_t
*** txd_texture_data_t
*** txd_extra_info_t
** ...
** txd_extra_info_t


&#42;<code style="color: green">txd_texture_t...</code> represents the repetition of the blocks seen above it. The number of repetitions differs between files, and is dictated by the value of <code>txd_info_t::count</code>.
==Notes==
==Notes==



Revision as of 11:42, 15 March 2020

Renderware TeXture Dictionary. Used by the Renderware Game Engine, which is used by games like Grand Theft Auto: San Andreas, Sonic The Hedgehog and NRL Rugby League. The format has undergone some changes over the years. The one described here is that in use by Grand Theft Auto: San Andreas. Other versions might be slightly different.

Generic chunk lay-out

TXD files consist of chunks and sub-chunks, which are really just chunks encapsulated in the data field of other chunks. All chunks have the following basic structure:

typedef struct txd_chunk_s {
 uint32_t id;
 uint32_t chunk_size;       // does not include id, chunk_size and marker
 uint32_t rw_version;
 uint8_t  data[chunk_size];
} txd_chunk_t;

Known chunks

typedef struct txd_file_s {
 uint32_t id;               // 0x16 (22)
 uint32_t chunk_size        // file_size - 12
 uint32_t rw_version;
 uint8_t  data[chunk_size];
} txd_file_t;
typedef struct txd_info_s {
 uint32_t id;               // 0x01 (1)
 uint32_t chunk_size;       // 0x04 (4)
 uint32_t rw_version;
 uint16_t count;            // number of textures in the dictionary
 uint16_t unknown;
} txd_info_t;
typedef struct txd_texture_s {
 uint32_t id;               // 0x15 (21)
 uint32_t chunk_size;
 uint32_t rw_version;
 uint8_t  data[chunk_size];
} txd_texture_t;
typedef struct txd_texture_data_s {
 uint32_t id;                         // 0x01 (1)
 uint32_t chunk_size;
 uint32_t rw_version;
 uint32_t version;                    // 0x08 (8) or 0x09 (9)
 uint32_t filter_flags;
 char     texture_name[32];
 char     alpha_name[32];
 uint32_t alpha_flags;
 uint32_t direct3d_texture_format;    // see below
 uint16_t width;
 uint16_t height;
 uint8_t  depth;
 uint8_t  mipmap_count;
 uint8_t  texcode_type;
 uint8_t  flags;
 uint8_t  palette[depth==8 ? 256 * 4 : 0];
 uint32_t data_size;
 uint8_t  data[data_size];
 struct mipmaps_s {
  uint32_t data_size;
  uint8_t  data[data_size];
 } mipmaps[mipmap_count - 1];
} txd_texture_data_t;
typedef struct txd_extra_info_s {
 uint32_t id;               // 0x03 (3)
 uint32_t chunk_size;
 uint32_t rw_version;
 uint8_t  data[chunk_size];
} txd_extra_info_t;

direct3d_texture_format

This is the format of the texture data found in txd_texture_data_t::data. This value must be known if the textures are to be extracted. It can be one of:

  • 0x21 - RGBA32
  • 0x22 - RGB32
  • 0x00 and flags & 1 is set - S3TC DXT1 compression (used in old version 8 files)

Additionally, direct3d_texture_format may be a four character code ("FourCC") relating to a DXT format. In such cases, the unsigned integer value is actually the concatenated bytes of the FourCC. For example, 0x44585431 is "DXT1" (44 58 54 31).

rw_version

This is the identifier of the version of the RenderWare engine that the file is for. It can be found in many types of RenderWare binary stream file.

rw_version Hex RenderWare Version
0x0003FFFF 3.0.0.3
0x0800FFFF 3.?.?.?
0x00000310 3.1.0.0
0x0C02FFFF 3.3.0.2
0x1003FFFF 3.4.0.3
0x1803FFFF 3.6.0.3

Basic file structure

Chunks other than txd_file_t (which has no parent chunk) are nested within the parent chunk's data array. For example, txd_info_t is found within txd_file_t::data.

txd_file_t

txd_info_t
txd_texture_t
txd_texture_data_t
txd_extra_info_t
txd_texture_t
txd_texture_data_t
txd_extra_info_t
txd_texture_t
txd_texture_data_t
txd_extra_info_t
txd_texture_t...*
txd_extra_info_t


*txd_texture_t... represents the repetition of the blocks seen above it. The number of repetitions differs between files, and is dictated by the value of txd_info_t::count.

Notes

  • Chunk id's are scope-dependent. For example, within the txd_file_t chunk, a chunk with id 0x01 is a txd_info_t chunk, but within a txd_texture_t chunk, id 0x01 is used by txd_texture_data_t chunks.