DB2: Difference between revisions

From wowdev
Jump to navigation Jump to search
mNo edit summary
(Let documentation resemble DBC files. Fix unknown field in header to be timestamp of last write.)
Line 1: Line 1:
Documented by VX.
DB2 files are the new version of client side databases, introduced in Cataclysm, containing data about items, NPCs, environment, world and a lot more. Except for their header they are pretty much equivalent to [[DBC|DBC files]]. You may want to also look at those. The structure described here is also used in [[ADB|ADB files]], which are a cache of dynamically streamed database entries / hotfixes.
==File structure==
{|class="wikitable"
!section
!description
!notes
|-
!header
|main information about file contains
|
|-
!rowspan="2"|table indexes
|used rows counter
|rowspan="2"|not exist if a string columns not present
|-
|sum of lengths of all strings in row
|-
!main table
|
|
|-
!strings
|all strings in table
|if string columns not present, one zero byte exist anyway
|}


I think would be more handy explain this on sample
=Table content structures=
This page describes the structure of [[DB2]] files. For a list of existing DB2 files and their contents see the categories [[:Category:DBC|DBC]], [[:Category:DBC_Vanilla|Vanilla]], [[:Category:DBC_BC|Burning Crusade]], [[:Category:DBC_WotLK|Wrath of the Lich King]], [[:Category:DBC_Cataclysm|Cataclysm]] and [[:Category:DBC_MoP|Mists of Pandaria]]. If you add documentation for a file, please add the correct categories (also the build number) as well.


'''Item-sparse.db2''' is more useful because contain a string type columns
=Structure=
struct db2_header
{
  uint32_t magic;                                              // 'WDB2' for .db2 (database), 'WCH2' for .adb (cache)
  uint32_t record_count;
  uint32_t field_count;
  uint32_t record_size;
  uint32_t string_table_size;                                  // string block always contains at least one zero-byte
  uint32_t table_hash;
  uint32_t build;
  uint32_t timestamp_last_written;                              // set to time(0); when writing in WowClientDB2_Base::Save()
  uint32_t min_id;
  uint32_t max_id;
  uint32_t locale;                                              // as seen in [[Loc|TextWowEnum]]
  uint32_t unk2;
};
template<typename record_type>
struct db2_file
{
  db2_header header;
  // static_assert (header.record_size == sizeof (record_type));
  if (header.max_id != 0)
  {
    int indices[header.max_id - header.min_id + 1];            // maps from id to row index in records[] below
    short string_lengths[header.max_id - header.min_id + 1];    // sum of lengths of all strings in row
  }
 
  record_type records[header.record_count];
  char string_block[header.string_block_size];
};


==Header==
==String Block==
{|class="wikitable"
Equivalent to [[DBC]] version. See [[DBC#String_Block|documentation there]].
!offset
!0 1 2 3
! reference
!4 5 6 7
! reference
!8 9 A B
! reference
!C D E F
! reference
|-
!00000000
|57444232
| *1
|E0C00000
| *2
|83000000
| *3
|0C020000
| *4
|-
!00000010
|B8BA1500
| *5
|4EE59B91
| *6
|37350000
| *7
|00000000
| *8
|-
!00000020
|19000000
| *9
|CF0C0100
| *10
|01000000
| *11
|00000000
| *12
|}
* 1 "WDB2" just a file header
* 2 number of rows (h0000C0E0 = 49376 rows)
* 3 number of columns (h00000083 = 131 columns)
* 4 bytes per row. originally all columns size is 4 bytes, but not always (for sample in KeyChain.db2 only first column size is 4 bytes, but all other is 1 byte per column)
* 5 size of strings data block (h0015BAB8 = 1424056 bytes)
* 6 unknown. looks like a some hash and different for different files, but stay static for different version of same files
* 7 client minor version (revision). also read reversed i.e. h00003537 = 13623
* 8 unknown. always saw only as zero
* 9 first row index. it's a first used row in table (h00000019 = 25). zero, if string columns not present.
* 10 last row index h00010CCF = 68815. zero, if string columns not present.
* 11 locale code. for eu clients is:
:{|class="wikitable"
!code
!locale
|-
|08000000
|deDE
|-
|01000000
|enGB
|-
|40000000
|esES
|-
|04000000
|frFR
|-
|00010000
|ruRU
|}
* 12 unknown. always saw only as zero
 
==Table indexes==
this section separated on two:
* used rows counter
* sum of lengths of all strings in row
 
===used rows counter===
this section is a solid 4 byte cells from first used index till last include unused. it's ordinary counter what skip unused rows.
 
for sample, if you have array with used "rows" 4,5,7,10 it means this section for this array would be:
{|-
!cell value
!in hex
!array (row) index
|-
!colspan="3"| begin of section
|-
|1
|01000000
|4 - first used row. value from field *9 of header)
|-
|2
|02000000
|5
|-
|0
|00000000
|unused
|-
|3
|03000000
|7
|-
|0
|00000000
|unused
|-
|0
|00000000
|unused
|-
|4
|04000000
|10 - last used row. (value from field *10 of header)
|-
!colspan="3"| end of section
|}
 
===Length of strings in row===
this section simple like previous, but has 2 byte per cell. as previous from first used row till last include unused. value for unused rows equal zero too, but value for used rows is a length of all strings from all columns in this row include zero separator for each.
 
for sample, if you row has a 3 string field:
"str1","string2","string 3"
length would be = length1+1 + length2+1 + length3+1 = 4+1 + 7+1 + 8+1 = 22 = h1600
 
==Main table==
contain only used rows data. have no idea how it detect field (column) type.
 
string column contain an offset to used string. for sample, if strings section begins from h019116FA and offset is 11, it means string must be at h0191170B. uses till first zero byte.
 
==Strings==
*contain all strings separated by zero byte.
*section begins and ends by zero byte.
*if section is not used (no string columns in table), one zero byte exists anyway.
 
==Thanks==
Carlos Ramzuel. files converted by his parser was greatly useful.


=Localization=
[[DB2]] records can contain localized strings. In contrast to [[DBC|DBCs]], a [[DB2]] file only contains localized values for a given locale (header.locale).


[[Category:Format]]
[[Category:Format]]

Revision as of 16:01, 5 July 2014

DB2 files are the new version of client side databases, introduced in Cataclysm, containing data about items, NPCs, environment, world and a lot more. Except for their header they are pretty much equivalent to DBC files. You may want to also look at those. The structure described here is also used in ADB files, which are a cache of dynamically streamed database entries / hotfixes.

Table content structures

This page describes the structure of DB2 files. For a list of existing DB2 files and their contents see the categories DBC, Vanilla, Burning Crusade, Wrath of the Lich King, Cataclysm and Mists of Pandaria. If you add documentation for a file, please add the correct categories (also the build number) as well.

Structure

struct db2_header
{
  uint32_t magic;                                               // 'WDB2' for .db2 (database), 'WCH2' for .adb (cache)
  uint32_t record_count;
  uint32_t field_count;
  uint32_t record_size;
  uint32_t string_table_size;                                   // string block always contains at least one zero-byte
  uint32_t table_hash;
  uint32_t build;
  uint32_t timestamp_last_written;                              // set to time(0); when writing in WowClientDB2_Base::Save()
  uint32_t min_id;
  uint32_t max_id;
  uint32_t locale;                                              // as seen in TextWowEnum
  uint32_t unk2;
};

template<typename record_type>
struct db2_file
{
  db2_header header;
  // static_assert (header.record_size == sizeof (record_type));

  if (header.max_id != 0)
  {
    int indices[header.max_id - header.min_id + 1];             // maps from id to row index in records[] below
    short string_lengths[header.max_id - header.min_id + 1];    // sum of lengths of all strings in row
  }
 
  record_type records[header.record_count]; 
  char string_block[header.string_block_size];
};

String Block

Equivalent to DBC version. See documentation there.

Localization

DB2 records can contain localized strings. In contrast to DBCs, a DB2 file only contains localized values for a given locale (header.locale).