WoWDBDefs

repository·master·Indexed 43 days ago

https://github.com/wowdev/wowdbdefs

Provides human and machine-readable column and field definitions for World of Warcraft database files (DBC/DB2) to track schema changes across game builds. Includes DBDefsLib for reading/writing .DBD and .BDBD files, as well as tools for dumping raw definitions (DBDefsDumper), merging them (DBDefsMerge), and validating syntax (DBDefsValidator). Supports builds from 7.3.5.26654 to current.

Tokens
3.1K
Snippets
8
Records
16
Agent score
55%

What's inside WoWDBDefs

  1. Understand the WoWDBDefs project purpose

    master

    WoWDBDefs provides up-to-date column and field definitions for World of Warcraft database files (DBC and DB2). It serves as a human-readable and machine-readable source of truth for database structures across various WoW builds, ranging from version 7.3.5.26654 to the current version.

    Key features include:

    • Support for builds between 7.3.5.26654 and current.
    • Machine-readable formats available via C# and Python implementations.
    • A tool to convert DBD files to JSON or XML.
  2. Define columns in the DBD format

    master

    The DBD format begins with a COLUMNS section to define column names once, ensuring consistency throughout the file.

    Column Types

    • Regular: type ColName (e.g., int ColName)
    • Foreign keys: type<ForeignDB::ForeignCol> ColName
    • Localized strings: locstring ColName (equivalent to string type in 4.0+)
    • Valid types: int, string, float, locstring.

    Column Syntax Rules

    • Unverified columns: Append a ? to the name (e.g., ColName?).
    • Comments: Append // Comment goes here to the end of a line.
    • Annotations: Use $annotation$ syntax. Supported annotations include:
      • $id$: Marks a primary key. Can be inline ($id$ColName) or non-inline ($noninline,id$).
      • $relation$: Marks a relationship. Can be inline ($relation$ColName) or non-inline ($noninline,relation$).
  3. Define build versions and layouts in DBD files

    master

    After the COLUMNS section, you define which builds and layouts the subsequent column structures apply to.

    Version Keywords

    • BUILD: (Required) Specifies the build version(s). Can be a single build, a comma-separated list of exact builds, or a range.
    • LAYOUT: (Required if applicable) Specifies layout hashes. Starts with LAYOUT followed by a comma-separated list.
    • COMMENT: (Optional) A human-readable comment for the version block.

    Build Specification Formats

    • Range: BUILD 7.2.0.23436-7.2.0.23514 (Note: For current expansions, use minor version ranges to avoid conflicts).
    • Multiple exact builds: BUILD 0.7.0.3694, 0.7.1.3702, 0.7.6.3712
    • Single exact build: BUILD 0.9.1.3810
  4. Understand the db-by-checksum.json data structure

    master

    The db-by-checksum.json file provides a grouping of databases based on their filename and MD5 checksum. The data is organized by <filename, MD5 checksum> and then sorted by <expansion, build>. This structure is useful for identifying identical database files across different builds using the ChecksumGroup class.

    public class ChecksumGroup
    {
      public string Name;
      public Dictionary<string, string[]> Builds; // <checksum, builds>
    }
  5. Define unknown fields in DBDs

    master

    When new builds introduce changes, fields may appear as Field_x_x_x_xxxxx_yyy (where x is the build and y is the field index). These must be manually named to be useful.

    Mapping Strategies:

    • Minor changes: Look for fields that were added, resized, or removed.
    • Reshuffled fields: If Blizzard shifts many fields at once, compare field types and sizes between builds. You may need to inspect field content using external tools to determine the correct mapping.
    • New fields: Check Blizzard's Lua files or inspect other DB2s that changed in the same build to find clues about new features.

    Best Practice: After manually naming fields, run DBDefsValidator.dll with the rewrite flag set to true to clean up orphaned definitions or whitespace.

  6. Understand the db-row-match data structure

    master

    The db-row-match feature (currently limited to Legion) performs a byte-level comparison of matching rows between two different builds. Databases are grouped by filename and sorted by <expansion, build>. The DBDMatchGroup class captures the comparison metrics between a previous build and the current build.

    public class DBDMatchGroup
    {
      public string BuildPrev;
      public string BuildCur;
      public int RecordCountPrev;
      public int RecordCountCur;
      public int MatchCount;
      public float MatchCountPercent;
    }
  7. Create a DBD mapping file (.dbdm)

    master

    A mapping file (extra/mapping.dbdm) is used to layer metadata on top of the standard DBD format. It defines which columns should be treated as FLAGS, ENUM, or COLOR. Each definition must be on its own line.

    Supported Types

    • FLAGS: Treats a column as a bitmask. You can optionally provide a name for a definition file and a condition.
    • ENUM: Treats a column as an enumeration. You can optionally provide a name for a definition file and a condition.
    • COLOR: Treats a column as a color field.

    Conditional Metadata

    You can make flags or enums conditional based on the value of another field using the syntax (ConditionTable::ConditionColumn=ConditionalValue). The metadata will only apply if the condition is met.

    FLAGS TableName::ColumnName (Name) (ConditionTable::ConditionColumn=ConditionalValue)
    ENUM TableName::ColumnName (Name) (ConditionTable::ConditionColumn=ConditionalValue)
    COLOR TableName::ColumnName
  8. Merge raw DBD dumps with existing DBDs using DBDefsMerge

    master

    Raw DBD dumps from DBDefsDumper lack field names and are specific to a single build. To integrate them into the main definition set, use DBDefsMerge to combine them with existing DBDs that contain named fields.

    Workflow:

    1. Compile the project in code/C#/DBDefsMerge.
    2. Run the merger: dotnet DBDefsMerge.dll <dbddir> <rawdir> <outputdir>

    Details:

    • <dbddir>: The directory containing existing DBDs.
    • <rawdir>: The directory containing the raw dumps.
    • <outputdir>: The destination directory (can be the same as <dbddir>).
    • Merging Logic: The tool attempts to match entries using layouthash first. If unavailable, it falls back to build identifiers, and finally build ranges.
    dotnet DBDefsMerge.dll <dbddir> <rawdir> <outputdir>
  9. Follow DBD file handling and formatting rules

    master

    When creating or editing .dbd files, adhere to these rules:

    • Filename: Use DBName.dbd, where DBName is the exact name of the DBC/DB2.
    • Multiple structures: If a file has multiple structures for different versions, separate them with an empty new line.
    • Line endings: All files must use Unix line endings (\n).
  10. Generate raw DBD files from DBMeta using DBDefsDumper

    master

    DBMeta (or DB2Meta) contains metadata for WoW's database tables (field types, sizes, flags, etc.) inside the WoW executable. The DBDefsDumper project reads these sections to generate human-readable DBD files.

    Note: These raw dumps do not contain field names unless the binary specifically contains them. Field names must be added via the merger or manual editing.

    Workflow:

    1. Compile the project located in code/C#/DBDefsDumper.
    2. Run the dumper against your WoW executable: dotnet DBDefsDumper.dll <exepath> <outputdir> [build]

    If the dumper fails to auto-detect the build (common for versions like 1.14), provide the build version as an optional argument in x.x.x.xxxxx format.

    Troubleshooting Patterns: If dumping fails, the patterns in PatternBuilder.cs may be outdated. You may need to reverse engineer the DB2Meta structure changes by diffing structures between two builds or performing a full analysis of the new structure.

    dotnet DBDefsDumper.dll <exepath> <outputdir> <build_version>
  11. Update DBDs with newer builds (Quick Start)

    master

    Follow these steps to update DBD definitions when a new WoW build is released and nothing has broken in the underlying patterns:

    1. Locate the source projects in code/C#/DBDefsDumper.
    2. Obtain the WoW executable for the target build.
    3. Verify that the pattern in DBDefsDumper/PatternBuilder.cs is still accurate for the new executable.
    4. Compile and run the dumper: dotnet DBDefsDumper.dll <exepath> <outputdir> [build] (the build argument is an optional x.x.x.xxxxx formatted string used if auto-detection fails).
    5. Compile and run the merger: dotnet DBDefsMerge.dll <dbddir> <rawdir> <outputdir>.
    6. Manually name any new unknown fields (e.g., those starting with Field_x_x_x_xxxxx).
    7. Submit a pull request with the updated definitions.
    # Step 4: Dump raw definitions
    dotnet DBDefsDumper.dll <exepath> <outputdir> <build_version>
    
    # Step 5: Merge raw definitions with existing DBDs
    dotnet DBDefsMerge.dll <dbddir> <rawdir> <outputdir>