Skip to content

feat(wow-cdbc): add JSON import support for DBC files#53

Merged
danielsreichenbach merged 4 commits into
mainfrom
feat/dbc-import
Jun 8, 2026
Merged

feat(wow-cdbc): add JSON import support for DBC files#53
danielsreichenbach merged 4 commits into
mainfrom
feat/dbc-import

Conversation

@danielsreichenbach

Copy link
Copy Markdown
Member

Summary

  • Add dbc import CLI subcommand: reads a JSON file + schema YAML and writes a valid WDBC-format DBC binary
  • Add import_from_json to wow-cdbc library: builds a RecordSet from JSON with type coercion and string block deduplication
  • Fix dbd_to_yaml binary to produce schemas compatible with the schema loader (type_name field, per-build layout, array sizes)
  • Fix generate_yaml_schema in dbd.rs to omit key_field when no $id$ marker exists in the build definition
  • Fix schema_loader::to_schema to return an error instead of panicking on unknown key field names

Usage

# 1. Convert a WoWDBDefs definition to a YAML schema
dbd_to_yaml Spell.dbd Spell.yaml

# 2. Export a DBC to JSON (existing command)
warcraft-rs dbc export --schema Spell.yaml --format json Spell.dbc --output Spell.json

# 3. Edit Spell.json as needed, then import back
warcraft-rs dbc import --schema Spell.yaml --output Spell_modified.dbc Spell.json

Test plan

  • cargo test --workspace passes (all tests green, zero failures)
  • cargo clippy --workspace --all-features passes (no warnings)
  • Three new unit tests in export.rs: JSON round-trip, missing field error, type mismatch error
  • Manual smoke test with real 3.3.5a AttackAnimTypes.dbc: validate → export → modify → import → validate

Add `dbc import` CLI subcommand and `import_from_json` library function
to convert JSON data back into valid DBC binary files.

- `warcraft-rs dbc import --schema <yaml> --output <dbc> <json>` reads a
  JSON array exported by `dbc export`, applies the schema for type
  coercion and string interning, and writes a WDBC-format DBC file.
- `import_from_json` in `wow-cdbc` builds a `RecordSet` from JSON,
  deduplicating strings into a fresh string block before handing off to
  the existing `DbcWriter`.
- `StringBlock::from_bytes` adds an in-memory constructor needed by the
  importer.
- Fix `dbd_to_yaml` binary to use `convert_to_yaml_schemas` (correct
  `type_name` field, per-build layout, array sizes) instead of the broken
  column-dump approach.
- Fix `generate_yaml_schema` to omit `key_field` when no `$id$` marker
  exists in the build definition, preventing schema load panics.
- Fix `schema_loader::to_schema` to use `try_set_key_field` and return a
  proper error instead of panicking on unknown key field names.

Three unit tests cover: JSON round-trip, missing field error, and type
mismatch error.
@SmashingQuasar

Copy link
Copy Markdown

Hey,

I tried to test this PR since I am the original requester.

I am quite struggling to be honest.
I built the software from source from this branch. I am told that the command dbd_to_yaml does not exist.
Because I do not want to pollute my machine with hundreds of crates nor any of the Rust environment since I do not develop in Rust, each test takes several minutes since cargo run somehow recompiles the software again.

Could you provide more detail on how to test this, please?

@SmashingQuasar

Copy link
Copy Markdown

So it turns out the command is dbd convert. Regardless, it does not work on my end.
I can't find how to specify which build I want to use for the conversion and when running cargon run dbd convert Achievement.dbd it produces a yaml which seems correct. However, I did try to extract my MPQs with it. When running the command dbc export it tells me the Achievement.dbc has 62 fields.

@danielsreichenbach

Copy link
Copy Markdown
Member Author
  1. Clone the definitions and the tool
git clone https://github.com/wowdev/WoWDBDefs.git
git clone https://github.com/wowemulation-dev/warcraft-rs.git
cd warcraft-rs
  1. Build the CLI (release for speed)
cargo build --release -p warcraft-rs
BIN=./target/release/warcraft-rs
  1. Convert one DBD to a YAML schema for your target build.

--version is a substring filter against BUILD lines (use the major.minor.patch).

$BIN dbd convert ../WoWDBDefs/definitions/Map.dbd \
    --version 3.3.5 \
    -o ./schemas
  1. Export a DBC to JSON using that schema.
$BIN dbc export /path/to/your/dbc/Map.dbc \
    --schema ./schemas/Map_3_3_0_10958-3_3_5_12340.yaml \
    --format json \
    --output ./json/Map.json

Notes:

  • The generated YAML filename is derived from the first build in the matched DBD group — it isn't always ..._12340.yaml. Just point --schema at whatever file
    dbd convert printed.
  • Pick --version to match the client your DBCs came from: 1.12, 2.4.3, 3.3.5, 4.3.4, 5.4.8.
  • For a bulk run, iterate over each *.dbc, look up the matching *.dbd in WoWDBDefs/definitions/ (case-insensitive), convert, then export.

@danielsreichenbach

Copy link
Copy Markdown
Member Author

I pushed one fix for localize string fields and build selection from the source files.

Anyway, the above instructions are what I use myself frequently and they work.

@danielsreichenbach danielsreichenbach merged commit a8bd7e0 into main Jun 8, 2026
13 of 16 checks passed
@danielsreichenbach danielsreichenbach deleted the feat/dbc-import branch June 8, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants