wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
image.hpp
Go to the documentation of this file.
1#pragma once
2
23
24#include <cstddef>
25#include <cstdint>
26#include <span>
27#include <vector>
28
29#include <wowlib/core/error.hpp>
32
33namespace wowlib::db::wdc {
35 enum class StringRefMode : std::uint8_t {
38 };
39
42 struct WdcSection {
44 bool encrypted = false;
45 std::span<const std::byte> records;
47 std::span<const std::byte> strings;
48 std::span<const std::byte> idList;
49 std::span<const std::byte> copyTable;
50 std::span<const std::byte> offsetMap;
51 std::span<const std::byte> offsetMapIds;
52 std::span<const std::byte> relationship;
53 std::vector<std::uint32_t> encryptedIds;
54 std::uint32_t stringBase = 0;
56 };
57
61 struct WdcImage {
62 std::uint32_t magic = 0;
66 std::span<const std::byte> file;
67 std::vector<WdcFieldStructure> fieldStructure;
68 std::vector<WdcFieldStorage> fieldStorage;
69 std::span<const std::byte> palletData;
70 std::span<const std::byte> commonData;
71 std::vector<WdcSection> sections;
74 std::vector<std::byte> ownedOffsetMap;
75 std::vector<std::uint32_t> ownedOffsetMapIds;
76
81 static Result<WdcImage> parse(std::span<const std::byte> data);
82
85 bool idIsNoninline() const {
86 return (header.flags & WdcFlagNoninlineId) != 0;
87 }
88
90 bool isSparse() const { return (header.flags & WdcFlagSparse) != 0; }
91
96 std::vector<std::uint32_t> fieldAdditionalOffsets() const;
97
111 std::uint64_t fieldRaw(std::size_t field,
112 std::uint32_t element,
113 std::uint32_t arrayCount,
114 std::span<const std::byte> recordBytes,
115 std::uint32_t id,
116 const std::vector<std::uint32_t>& additional) const;
117
124 std::size_t elemBitWidth(std::size_t field, std::uint32_t arrayCount) const;
125
130 bool fieldIsSigned(std::size_t field) const {
131 return field < fieldStorage.size() && fieldStorage[field].storageType == WdcCompression::BitpackedSigned;
132 }
133
134 private:
136 static Result<WdcImage> _parseWdc1(std::span<const std::byte> data);
137
140 static Result<WdcImage> _parseWdc3(std::span<const std::byte> data, std::uint32_t magic);
141
149 std::uint32_t _palletValue(std::uint32_t base,
150 std::uint32_t index,
151 std::uint32_t element,
152 std::uint32_t arraySize) const;
153
161 std::uint32_t _commonValue(std::uint32_t base, std::uint32_t size, std::uint32_t id, std::uint32_t fallback) const;
162 };
163}
The on-disk binary structures of the WDC family of .db2 formats (wowdev.wiki/DB2): WDC1 (Legion 7....
Little-endian bit streams over record buffers — the primitive the WDC family's bitpacked column stora...
The error-handling vocabulary: ErrorCode, Error and the Result<T> alias every fallible wowlib operati...
@ BitpackedSigned
Bit-addressed signed value, sign-extended (WDC2+ only; WDC1 spells it Bitpacked + flags 0x01).
Definition binary.hpp:159
@ WdcFlagSparse
Offset-map layout + inline null-terminated strings.
Definition binary.hpp:53
@ WdcFlagNoninlineId
The id lives in the idList, not the record.
Definition binary.hpp:56
StringRefMode
How a record's string-reference fields address the string data.
Definition image.hpp:35
@ FieldRelative
WDC2+: offset from the referencing field's own position.
Definition image.hpp:37
@ BlockRelative
WDC1: offset from the string block's first byte.
Definition image.hpp:36
std::expected< T, Error > Result
Every fallible wowlib operation returns Result<T>; bindings translate the error branch into a target-...
Definition error.hpp:100
The 72-byte WDC3 top header (WDC4 reuses it verbatim; WDC5 prepends Wdc5HeaderPrefix in front of the ...
Definition binary.hpp:93
The 40-byte per-section header of WDC3/WDC4/WDC5.
Definition binary.hpp:128
The 132 bytes WDC5 splices between magic and recordCount: a numeric schema version and a zero-padded ...
Definition binary.hpp:120
A parsed WDC-family file: the (normalized) header, shared tables, and located sections.
Definition image.hpp:61
std::span< const std::byte > file
Definition image.hpp:66
std::size_t elemBitWidth(std::size_t field, std::uint32_t arrayCount) const
The bit width of one element of inline field field: for the inline kinds, the field's total width div...
Definition image.cpp:308
std::vector< WdcFieldStorage > fieldStorage
Definition image.hpp:68
std::uint32_t magic
The flavor actually parsed.
Definition image.hpp:62
std::span< const std::byte > commonData
Definition image.hpp:70
Wdc5HeaderPrefix wdc5
Valid when magic == Wdc5Magic.
Definition image.hpp:64
std::uint64_t fieldRaw(std::size_t field, std::uint32_t element, std::uint32_t arrayCount, std::span< const std::byte > recordBytes, std::uint32_t id, const std::vector< std::uint32_t > &additional) const
Decode array element element of inline field field for one record.
Definition image.cpp:273
Wdc3Header header
WDC1 header fields are mapped onto this.
Definition image.hpp:63
std::vector< std::uint32_t > fieldAdditionalOffsets() const
The byte offset into palletData / commonData where each field's additional data begins (accumulated i...
Definition image.cpp:256
static Result< WdcImage > parse(std::span< const std::byte > data)
Parse and structurally validate data as a WDC-family file, sniffing the flavor off the magic.
Definition image.cpp:28
StringRefMode stringMode
Definition image.hpp:65
std::vector< WdcFieldStructure > fieldStructure
Definition image.hpp:67
std::span< const std::byte > palletData
Definition image.hpp:69
bool fieldIsSigned(std::size_t field) const
Whether field field's storage is the signed bitpacked kind (after WDC1 normalization).
Definition image.hpp:130
std::vector< WdcSection > sections
Definition image.hpp:71
std::vector< std::byte > ownedOffsetMap
Owned backing for WDC1's normalized sparse map (filtered entries + the ids the dense map only implied...
Definition image.hpp:74
std::vector< std::uint32_t > ownedOffsetMapIds
Definition image.hpp:75
bool isSparse() const
Whether this file uses the sparse offset-map layout (flag 0x01).
Definition image.hpp:90
bool idIsNoninline() const
Whether the id comes from the idList rather than a record field (flag 0x04); when false,...
Definition image.hpp:85
A located, structurally-validated section.
Definition image.hpp:42
std::span< const std::byte > records
Fixed-stride record region (non-sparse), or the variable sparse record region.
Definition image.hpp:45
Wdc3SectionHeader header
Synthesized for WDC1.
Definition image.hpp:43
std::uint32_t stringBase
Absolute file offset the section's strings start at.
Definition image.hpp:54
std::span< const std::byte > offsetMap
{uint32 offset, uint16 size} entries (sparse).
Definition image.hpp:50
std::span< const std::byte > copyTable
{uint32 newId, uint32 srcId} pairs.
Definition image.hpp:49
std::span< const std::byte > idList
uint32 ids, present when flag 0x04.
Definition image.hpp:48
std::span< const std::byte > relationship
Relationship block (map header + pairs).
Definition image.hpp:52
std::span< const std::byte > strings
Section string block (non-sparse).
Definition image.hpp:47
std::vector< std::uint32_t > encryptedIds
WDC4+: the encrypted_status id list.
Definition image.hpp:53
bool encrypted
tactKeyHash != 0 AND records zeroed.
Definition image.hpp:44
std::span< const std::byte > offsetMapIds
uint32 ids paired with offsetMap (sparse).
Definition image.hpp:51