Extracts data from the World of Warcraft game files into
tools/database/wowsims.db, the SQLite database that gen_db consumes.
The flow end to end: generator-settings.json says what to extract, tact
finds the bytes inside the WoW install, wdc + dbd turn them into typed rows
(with hotfixes applied), and sqlite writes wowsims.db.
Usage
The normal entry points are make db (live client) and make ptrdb (PTR
client), which run this tool and then gen_db; DB2TOOL_FLAGS passes extra
flags through (make db DB2TOOL_FLAGS="--cdn --dbcache caches/DBCache.bin").
To run it directly, do so from the repository root (the tool is
CWD-dependent, like gen_db):
go run ./tools/db2tool -s tools/database/generator-settings.json --output tools/database/wowsims.db
Three modes:
- Local-CASC mode (default) — reads the WoW install named by the settings'
BaseDir: .build.info picks the build, files come out of local CASC
storage, and the game files' DBCache.bin hotfixes for that build are applied
to the decoded rows. BaseDir may be a symlink; the cache scan resolves it
first, and the run warns when it finds no cache for the build.
- CDN mode (
--cdn) — the same pipeline, but the build is whatever
Blizzard's version service (--region, default us) says the settings'
Product is on right now, and every file comes off the CDN: configs, the
per-archive indexes, encoding and root as loose files, the .db2 tables as
range reads out of the archives. No install required. Downloads are
verified against their hash (configs, loose files) or encoding key (every
encoded file) and kept under tools/db2tool/cdncache/ (a few hundred MB
per build, safe to delete), so a re-run of the same build is offline.
Hotfixes come from --dbcache or tools/db2tool/caches/; raidbots mirrors
the live game's cache at
https://storage.googleapis.com/raidbots-static/wow/forever/enUS/DBCache.bin,
which is what the Update DB GitHub workflow feeds it. When no cache for
the extracted build exists, --carry-hotfixes applies one from an older
build (see below).
- Offline mode (
--build <number|version>) — decodes pre-extracted .db2
files (from dbfilesclient/ or --db2dir) instead. No install required, no
hotfixes unless --dbcache is given.
Flags: --settings/-s, --output/-o, --cdn, --region <r>, --build,
--db2dir, --dbddir, --dbcache <file> (pin specific hotfix caches for
deterministic runs), --no-hotfixes, --carry-hotfixes (also apply caches
of older builds), --keys <file> (community TACT key list).
By default only a cache whose build is the extracted build applies. With
--carry-hotfixes, which needs --dbcache, every cache given for an older
build applies too, in ascending build order, then the extracted build's own
last, so its records win. That holds for its invalid records too: a row the own
cache marks invalid is dropped even when a carried cache adds it. A cache for a newer build is never carried. A
carried cache's rows decode with the extracted build's layout, so it applies
only to a table whose .dbd lists both builds in the same version block; the
run warns for every other table it holds records for, for a newer cache and
for a carried cache that applies to no table.
Every run prints one summary line, which the workflows read:
Hotfixes: build <extracted> up to push <push>, with , carried from build <cache> for each carried cache that applied, or Hotfixes: none applied for build <extracted>. The push, which BuildInfo.HotfixPush records, is the
highest server push across the extracted build's own cache and every carried
cache that applied.
Encrypted sections and TACT keys
Blizzard ships unreleased content inside the normal .db2 files as sections
encrypted with per-bundle Salsa20 keys ("TACT keys"). A section's header
names the key it needs; the bytes only become readable once that key is
known. Keys come from three places: shipped in TactKey.db2, pushed by the
server as TACTKEY hotfix records into DBCache.bin, or published by the
community at https://github.com/wowdev/TACTKeys.
Local-CASC and CDN modes gather all three before extracting: they decode
TactKeyLookup/TactKey with the hotfix overlay applied, then loads
tools/db2tool/TACTKeys.txt, which is downloaded from the community list when
missing and refreshed when older than a day (--keys <file> points at another
copy). Every encrypted BLTE chunk whose key is known is decrypted in place, so
its rows land in the database like any other. Chunks whose key is still
unknown stay zero-filled and their sections are skipped, and the run prints
one line per table naming the key and the row count it still hides:
ItemSparse: 63 rows locked by TACT key DA0E7785727A0A65
Offline mode cannot decrypt: the .db2 files it reads were written with those
chunks already zeroed. Re-run local-CASC mode once a key surfaces.
Package layout
main.go — orchestration and CLI. Parses flags, loads settings, then runs
the pipeline: open the install → extract each table → fetch its schema
definition → decode the rows → apply hotfixes → insert into SQLite.
config/ — loader for the JSON settings file (see below).
tact/ — the "get bytes out of the WoW install" layer. Blizzard stores
game files in a content-addressed archive system called CASC/TACT, so you
can't just open Spell.db2 off disk. This package walks the chain:
.build.info picks the installed build (buildinfo.go), the build config and
root manifest map a FileDataID to a content hash (build.go, config.go,
root.go), the encoding table and .idx files locate that hash inside the
big data.NNN archives (encoding.go, cascidx.go), and BLTE decompresses
the result (blte.go). cdn.go swaps the last step for the CDN: the version
service picks the build, the per-archive .index files (merged in memory,
since the CDN serves no group index) locate a key inside a remote archive,
and an HTTP range read fetches it. listfile.go handles the
community-maintained listfile.csv that maps human filenames
(dbfilesclient/spell.db2) to FileDataIDs, since the game itself only knows
numbers.
wdc/ — the DB2 file format decoder. Once tact hands over raw bytes, this
parses the WDC5 container format (wdc5.go, row.go, bitreader.go for its
bit-packed columns). hotfix.go reads the game files' DBCache.bin — Blizzard's
server-pushed data corrections — and overlays those records onto the decoded
rows so the output matches what the live game actually uses.
dbd/ — schema definitions. DB2 files don't fully describe their own
columns, so the community maintains WoWDBDefs
(.dbd files) that say "for build X, the Spell table has these fields with
these types". This package downloads and caches them (fetch.go), parses the
format (dbd.go), and picks the definition version matching our build number
(select.go).
sqlite/ — the output end: translates a dbd definition into a
CREATE TABLE statement (schema.go) and bulk-inserts the decoded rows
(insert.go).
Data directories (populated on first run, cached afterwards):
dbfilesclient/ — the extracted .db2 files. Written as a side effect in
local-CASC mode, read as input in offline --build mode.
DBDCache/ — cached .dbd definition downloads.
listfile.csv — cached filename→FileDataID mapping.
caches/ — optional extra DBCache.bin hotfix files, scanned in
local-CASC mode alongside <BaseDir>/**/DBCache.bin and on their own in
CDN mode.
cdncache/ — CDN mode's hash-addressed downloads (configs, indexes,
encoding, root and other loose files).
NOTICES.md carries license attributions for the projects the format-parsing
code was ported from.
generator-settings.json
Lives at tools/database/generator-settings.json (with a PTR variant,
ptr-generator-settings.json, which lists the same tables minus
ItemXItemEffect) and drives what
gets extracted:
Settings.BaseDir / Product — where the WoW install lives and which
product to read from it (wow_anniversary = the Anniversary client, which
is what TBC Classic ships under). An install can hold several products; this
picks the right one out of .build.info.
TargetDirectory — dbfilesclient, doing double duty: it's the path
prefix used to look up files in the listfile (dbfilesclient/Spell.db2) and
the on-disk folder the extracted .db2 files are written to.
GameTables / GameTablesOutDirectory — GameTables are a separate,
simpler thing: plain-text .txt files of per-level constants (crit chance
per agility, combat rating conversions, base HP/mana, spell scaling…).
They're extracted as-is to assets/db_inputs/basestats, where the sim's
base-stats generation reads them. No DB2 decoding involved.
Tables — the list of DB2 tables to decode into SQLite. Roughly:
everything item-related (ItemSparse, damage/armor tables, random suffixes,
upgrades, reforging, sets), everything spell-related (the ~25 Spell*
tables that the modern game files split spell data into, enchants,
procs-per-minute),
talents/glyphs, and dungeon-journal/zone tables (Map, JournalEncounter…)
used for item source info.
To add a new table to wowsims.db: add its name to Tables — that's all
it takes. The schema comes from WoWDBDefs automatically. GameTable additions
work the same way via GameTables (names match the gametables/*.txt files
in the game files).