wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
root.hpp
Go to the documentation of this file.
1#pragma once
2
9
10#include <cstdint>
11#include <vector>
12
15#include <wowlib/core/lang.hpp>
23
25 using namespace wowlib::formats::wdt::root::chunks;
26
36 struct [[
37 =welder::weld,
38 =welder::weld_as("WDTRoot"),
40 =welder::doc(R"(
41 A WDT main file, abstract over the client version. The main file says
42 which map tiles exist (and, since 8.1, which FileDataIDs serve them),
43 or references the one global WMO of an object-only map. Construct a
44 concrete version with WDTRoot.for_version(expansion); the per-version
45 WDTRoot* classes are subclasses. See https://wowdev.wiki/WDT.)")
46 ]] WDTRootBase {};
47
48 namespace detail {
49 // --- version-range trait bases (unwelded) ---------------------------------
50 // One struct per availability range; members keep their chunk/since/until/
51 // doc/marks (read off the declaring class, so flattening preserves them).
54 struct Root81 {
55 [[
56 =chunk("MAID"),
59 =welder::mark::no_reassign,
60 =welder::doc(
61 R"(Per-tile FileDataIDs (MAID, 8.1.0.28294+): 64 x 64 records in
62 row-major order (y outer, x inner), one per map tile —
63 engaged by the has_maid header flag. WMO-only maps omit
64 it.)")]]
65 std::vector<MapFileDataIDs> mapFdids;
66 };
67
69 struct Root90 {
70 [[
71 =chunk("MANM"),
74 =welder::doc(
75 R"(Map anima paths (MANM, 9.0+): the Shadowlands anima stream
76 cables and their node chains. A versioned variable-length
77 layout, kept opaque.)")]]
79 };
80 }
81
82 namespace detail {
94 template <ClientVersion V>
95 struct [[
96 =welder::weld,
97 =welder::doc(R"(
98 A WDT main file for one client version: the map header, the 64x64
99 tile table (row-major, y outer), the per-tile FileDataIDs (8.1+) and
100 the global WMO of object-only maps. An instance read from a client
101 file rewrites byte-for-byte until modified. See
102 https://wowdev.wiki/WDT.)")
103 ]] WDTRoot
113 =welder::doc("The WDT format version; 18 for every supported client.")]]
114 std::uint32_t mver = WdtVersion18;
115
116 [[
117 =chunk("MPHD"),
118 =welder::doc(
119 "The map header (MPHD): flags and, since 8.1, the satellite "
120 "FileDataIDs.")]]
122
123 [[
124 =chunk("MAIN"),
125 =welder::mark::no_reassign,
126 =welder::doc(
127 R"(The tile table (MAIN): 64 x 64 records in row-major order
128 (y outer, x inner), flagging which tiles have an ADT.)")
129 ]]
130 std::vector<SMAreaInfo> tiles;
131
132 [[
133 =chunk("MWMO"),
135 =welder::doc(
136 R"(The global-WMO filename (MWMO) of a WMO-only map, as a string
137 block holding the one zero-terminated path (at most 0x100
138 bytes). Terrain maps of pre-8.1 clients still carry the chunk
139 empty; FileDataID-era terrain maps drop it.)")]]
140 StringBlock globalWmoName;
141
142 [[
143 =chunk("MODF"),
145 =welder::mark::no_reassign,
146 =welder::doc(
147 R"(The global-WMO placement (MODF) of a WMO-only map; at most one
148 record. Its name_id is unused — the client always loads the
149 MWMO content (or, in FileDataID-era files without MWMO, treats
150 name_id as the WMO FileDataID).)")]]
151 std::vector<SMMapObjDef> globalWmo;
152
158 static constexpr std::array ChunkOrder = {
159 fourcc("MVER"),
160 fourcc("MPHD"),
161 fourcc("MAIN"),
162 fourcc("MAID"),
163 fourcc("MWMO"),
164 fourcc("MODF"),
165 fourcc("MANM"),
166 };
167
173 [[=welder::mark::exclude]]
174 void validateExtra(ValidationReport& report) const {
175 // the client addresses a tile as tiles[y * 64 + x]; a short table
176 // silently reads the wrong tiles rather than failing
177 if (!tiles.empty() && tiles.size() != WdtTileSlots) report.addError(
178 "tiles", std::format("the MAIN table holds {} records, not 64*64", tiles.size()));
179
180 // MAID is the same grid: engaged, it must cover every tile
181 if constexpr (requires { this->mapFdids; })
182 if (!this->mapFdids.empty() && this->mapFdids.size() != WdtTileSlots)
183 report.addError("mapFdids",
184 std::format("the MAID table holds {} records, not 64*64", this->mapFdids.size()));
185
186 // a WMO-only map places exactly one global object
187 if (globalWmo.size() > 1)
188 report.addError("globalWmo",
189 std::format("{} global WMO placements; a map has at most one", globalWmo.size()));
190 }
191 };
192 }
193
199 template <ClientVersion V>
200 using WDTRoot = root::detail::WDTRoot<canonicalVersion(V, WdtRootPivots, WdtVersions)>;
201}
The chunk framework, vocabulary and engine in one header.
void addError(std::string path, std::string message)
Record an error finding (see add()).
Named ClientVersion constants for the exact client builds format features appeared (or vanished) at —...
Client version identity, the flavor axis that separates a client's CONTENT version from the engine ge...
FourCC chunk identifiers: compile-time conversion of the four-letter codes to the host integers chunk...
Binding-language identities welder's core does not name.
#define WOWLIB_CS_FAMILY_SURFACE
The C# rod's family-surface opt-in, spellable in every build.
Definition lang.hpp:44
The map-placement binary records SHARED across the world file formats (namespace wowlib::formats::com...
constexpr ClientVersion SL_Alpha_33978
shadowlands alpha, 9.0.1 build 33978 (WFV3/EDGF/NERF/DBOC; PFDC is dated here by wowdev but reached l...
constexpr ClientVersion BfA_TidesOfVengeance_28294
BfA, Tides of Vengeance, 8.1.0 build 28294 (WDT MAID and the MPHD FileDataID layout — the namehash re...
The 32-byte MPHD map header.
Definition header.hpp:61
detail::SMMapHeader< canonicalVersion(V, WdtHeaderPivots, WdtVersions)> SMMapHeader
The MPHD header — the canonicalizing face of detail::SMMapHeader (WdtHeaderPivots: the FileDataID rel...
Definition header.hpp:119
The WDT main-file entity: WDTRoot and its per-version classes.
Definition header.hpp:20
root::detail::WDTRoot< canonicalVersion(V, WdtRootPivots, WdtVersions)> WDTRoot
A WDT main file — the canonicalizing face of detail::WDTRoot: every client version maps to its range'...
Definition root.hpp:145
constexpr std::array WdtRootPivots
WDTRoot: the MPHD/MAID pivot plus MANM (the Shadowlands map anima).
constexpr std::array WdtVersions
The versions WDT is instantiated (and welded) for: every targeted last-minor-of-major release,...
constexpr std::uint32_t WdtVersion18
The WDT format version every supported client uses (the .wdt and _occ.wdt MVER payload; _lgt/_fogs/_m...
constexpr std::size_t WdtTileSlots
The tile-table slot count of a map: the 64x64 grid MAIN (and, since 8.1, MAID) covers,...
constexpr std::uint32_t fourcc(const char(&cc)[5], FourCCEndian endian=FourCCEndian::Reversed)
The host integer a scanned chunk id compares equal to for code cc.
Definition fourcc.hpp:33
constexpr ClientVersion canonicalVersion(ClientVersion v, std::span< const ClientVersion > pivots, std::span< const ClientVersion > grid)
The canonical version v collapses to: the FIRST grid version in v's range.
constexpr detail::OptionalSpec Optional
Mark a chunk member the format does not require: absence on read is fine.
consteval detail::ExpectedValueSpec expectedValue(std::uint32_t value)
Declare an exact-value contract on an integral data member (format version fields: WMO MVER is always...
consteval detail::ChunkSpec chunk(const char(&cc)[5], FourCCEndian endian=FourCCEndian::Reversed)
Declare the chunk a member maps to.
consteval detail::SinceSpec since(ClientVersion v)
Restrict a member to entity versions >= v (inclusive).
std::conditional_t<(V.formatLineage() >=Since &&V.formatLineage()< Until), Trait, Absent< Trait > > Slot
A version-gated base: the entity inherits Trait (flattening its chunk members in) iff Since <= V < Un...
StringBlock — the decoded representation of a chunk of zero-terminated strings (MOTX,...
An unparsed chunk payload, preserved verbatim for round-trip.
The serialization face of a chunked entity, mixed in CRTP-style: an entity struct E : ChunkedFile<E> ...
The version-agnostic base of every WDTRoot<V> (welded as "WDTRoot").
Definition root.hpp:42
8.1+ main-file chunks (the FileDataID era).
Definition root.hpp:50
std::vector< MapFileDataIDs > mapFdids
Definition root.hpp:52
A WDT main file for one client version.
Definition root.hpp:79
void validateExtra(ValidationReport &report) const
Validation hook (see formats::detail::validateValue): the map-wide tables the client indexes POSITION...
Definition root.hpp:119
The conditional-base mechanism that gives a versioned chunked entity exactly the fields its client ve...
WDT version grids and per-family canonicalization pivots.
WDT main-file chunk binary structs (namespace wowlib::formats::wdt::root::chunks): the MPHD map heade...