wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
header.hpp
Go to the documentation of this file.
1#pragma once
2
12
13#include <array>
14#include <bit>
15#include <cstdint>
16
17#include <welder/vocabulary.hpp>
18
21
23 enum class [[
24 =welder::weld,
25 =welder::flags,
26 =welder::doc("Per-cell MCNK header flag bits (SMChunk.flags).")
27 ]] MapChunkFlags : std::uint32_t {
28 HasMcsh [[=welder::doc("The cell has a baked shadow map (MCSH sub-chunk).")
29 ]] = 0x1,
30 Impassable [[=welder::doc("Impassable terrain (no walking).")]] = 0x2,
31 LqRiver [[=welder::doc("Legacy (MCLQ) river liquid present.")]] = 0x4,
32 LqOcean [[=welder::doc("Legacy (MCLQ) ocean liquid present.")]] = 0x8,
33 LqMagma [[=welder::doc("Legacy (MCLQ) magma liquid present.")]] = 0x10,
34 LqSlime [[=welder::doc("Legacy (MCLQ) slime liquid present.")]] = 0x20,
36 welder::doc("The cell has vertex colors (MCCV sub-chunk, WotLK+).")]] =
37 0x40,
38 unknown_0x80 [[=welder::doc("Unknown (0x80).")]] = 0x80,
39 DoNotFixAlphaMap [[=welder::doc(
40 R"(The MCAL/MCSH maps are stored in their full
41 64x64 form rather than the 63x63 "unfixed"
42 form the client repairs on load. wowlib always
43 stores the full 64x64 edit surface and sets this
44 flag on write.)")]] = 0x8000,
45 HighResHoles [[=welder::doc(
46 R"(The cell uses the 64-bit high-resolution hole mask
47 (stored in the 8 bytes at header offset 0x14, ~5.3+)
48 instead of the 16-bit holes_low_res field.)")
49 ]] = 0x10000
50 };
51
56 struct [[
57 =welder::weld,
58 =welder::weld_as("SMChunk"),
59 =welder::doc(R"(
60 A terrain cell header (MCNK, 128 bytes): the flags, its (x, y) position in
61 the 16x16 cell grid, the area id, the terrain hole mask and the origin.
62 The sub-chunk offset/size/count fields are binary bookkeeping wowlib derives
63 on write, so they are not exposed. See https://wowdev.wiki/ADT/v18#MCNK_chunk.)")
64 ]] SMChunk {
65 [[=welder::doc("Flags; MapChunkFlags bits.")]]
67
68 [[=welder::doc("The cell's column index in the 16x16 grid (0-15).")]]
69 std::uint32_t indexX = 0;
70
71 [[=welder::doc("The cell's row index in the 16x16 grid (0-15).")]]
72 std::uint32_t indexY = 0;
73
74 [[=welder::mark::exclude]] std::uint32_t nLayers = 0;
75 [[=welder::mark::exclude]] std::uint32_t nDoodadRefs = 0;
76 // 0x14/0x18: pre-5.3 the derived MCVT/MCNR offsets; with the HighResHoles
77 // flag these 8 bytes are the 64-bit hole mask instead (see holesHighRes()).
78 [[=welder::mark::exclude]] std::uint32_t ofsHeight = 0;
79 [[=welder::mark::exclude]] std::uint32_t ofsNormal = 0;
80 [[=welder::mark::exclude]] std::uint32_t ofsLayer = 0;
81 [[=welder::mark::exclude]] std::uint32_t ofsRefs = 0;
82 [[=welder::mark::exclude]] std::uint32_t ofsAlpha = 0;
83 [[=welder::mark::exclude]] std::uint32_t sizeAlpha = 0;
84 [[=welder::mark::exclude]] std::uint32_t ofsShadow = 0;
85 [[=welder::mark::exclude]] std::uint32_t sizeShadow = 0;
86
87 [[=welder::doc(
88 "The cell's area id (a foreign key into AreaTable; in the alpha "
89 "clients, packed zone/subzone u16s).")]]
90 std::uint32_t areaId = 0;
92 [[=welder::mark::exclude]] std::uint32_t nMapObjRefs = 0;
93
94 [[=welder::doc(
95 "The 16-bit low-resolution terrain hole mask (a 4x4 bitfield); used "
96 "unless the high_res_holes flag selects holes_high_res.")]]
97 std::uint16_t holesLowRes = 0;
98
99 [[=welder::doc("Unknown but written (padding in the alpha clients).")]]
100 std::uint16_t unknownButUsed = 0;
101
102 [[=welder::doc(
103 R"(The "really low quality" predominant-texture map: an 8x8 grid of
104 2-bit layer indices (16 bytes), naming the detail doodads to
105 show per sub-cell.)")]]
106 std::array<std::uint8_t, 16> predominantTexture{};
107
108 [[=welder::doc(
109 "An 8x8 bitfield (8 bytes): 1 disables detail doodads in that "
110 "sub-cell (WoD may store it as an explicit MCDD chunk).")]]
111 std::array<std::uint8_t, 8> noEffectDoodad{};
113 [[=welder::mark::exclude]] std::uint32_t ofsSndEmitters = 0;
114 [[=welder::mark::exclude]] std::uint32_t nSndEmitters = 0;
115 [[=welder::mark::exclude]] std::uint32_t ofsLiquid = 0;
116 [[=welder::mark::exclude]] std::uint32_t sizeLiquid = 0;
117
118 [[=welder::doc(
119 "The cell origin in world space; MCVT heights are relative to it.")]]
120 C3Vector position{};
121
122 [[=welder::mark::exclude]] std::uint32_t ofsMccv = 0;
123 [[=welder::mark::exclude]] std::uint32_t ofsMclv = 0;
124 [[=welder::mark::exclude]] std::uint32_t unused = 0;
126 [[nodiscard]]
127 [[=welder::getter,
128 =welder::doc(
129 "The 64-bit high-resolution hole mask (the 8 bytes at header offset "
130 "0x14), valid when the high_res_holes flag is set.")]]
131 std::uint64_t holesHighRes() const {
132 return (static_cast<std::uint64_t>(ofsNormal) << 32) | ofsHeight;
135 [[=welder::doc(
136 "Set the 64-bit high-resolution hole mask (and the high_res_holes "
137 "flag).")]]
138 void setHolesHighRes(std::uint64_t holes) {
139 ofsHeight = static_cast<std::uint32_t>(holes & 0xFFFFFFFF);
140 ofsNormal = static_cast<std::uint32_t>(holes >> 32);
143
144 bool operator==(const SMChunk&) const = default;
145 };
146
147 static_assert(sizeof(SMChunk) == 0x80);
148
149 enum class [[
150 =welder::weld,
151 =welder::flags,
152 =welder::doc("Tile header flag bits (MHDRData.flags).")
153 ]] MapHeaderFlags : std::uint32_t {
154 HasMfbo [[=welder::doc("The tile has a flying bounds chunk (MFBO).")]] = 0x1,
155 Northrend [[=welder::doc("Set on some Northrend tiles; meaning unknown.")]] = 0x2
156 };
157
158
161 struct [[
162 =welder::weld,
163 =welder::weld_as("MHDRData"),
164 =welder::doc(R"(
165 The tile header (MHDR, 64 bytes): flags plus offsets to the tile's other
166 chunks. wowlib derives every offset from the written layout, so only the
167 flags and the Cata+ inline MAMP alpha-downscale value are exposed. See
168 https://wowdev.wiki/ADT/v18#MHDR_chunk.)")
169 ]] MHDRData {
170 [[=welder::doc("Flags; MapHeaderFlags bits.")]]
171 MapHeaderFlags flags{};
172
173 [[=welder::mark::exclude]] std::uint32_t ofsMcin = 0;
174 [[=welder::mark::exclude]] std::uint32_t ofsMtex = 0;
175 [[=welder::mark::exclude]] std::uint32_t ofsMmdx = 0;
176 [[=welder::mark::exclude]] std::uint32_t ofsMmid = 0;
177 [[=welder::mark::exclude]] std::uint32_t ofsMwmo = 0;
178 [[=welder::mark::exclude]] std::uint32_t ofsMwid = 0;
179 [[=welder::mark::exclude]] std::uint32_t ofsMddf = 0;
180 [[=welder::mark::exclude]] std::uint32_t ofsModf = 0;
181 [[=welder::mark::exclude]] std::uint32_t ofsMfbo = 0;
182 [[=welder::mark::exclude]] std::uint32_t ofsMh2O = 0;
183 [[=welder::mark::exclude]] std::uint32_t ofsMtxf = 0;
184
185 [[=welder::doc(
186 "The inline MAMP alpha-map downscale value (Cata+): the alpha texture "
187 "size is 64 / (2^value); an explicit MAMP chunk overrides it.")]]
188 std::uint8_t mampValue = 0;
189
190 [[=welder::mark::exclude]] std::array<std::uint8_t, 3> padding{};
191 [[=welder::mark::exclude]] std::array<std::uint32_t, 3> unused{};
192
193 bool operator==(const MHDRData&) const = default;
194 };
195
196 static_assert(sizeof(MHDRData) == 0x40);
197
200 struct [[
201 =welder::weld,
202 =welder::doc(R"(
203 The flying bounds (MFBO, BC+): a maximum and a minimum plane, each a 3x3
204 grid of int16 heights, limiting where a player may fly on this tile.)")
205 ]] MFBOPlanes {
206 [[=welder::doc("The maximum plane: 3x3 int16 heights (row-major).")]]
207 std::array<std::int16_t, 9> maximum{};
208
209 [[=welder::doc("The minimum plane: 3x3 int16 heights (row-major).")]]
210 std::array<std::int16_t, 9> minimum{};
211
212 bool operator==(const MFBOPlanes&) const = default;
213 };
214
215 static_assert(sizeof(MFBOPlanes) == 36);
216}
Flag-testing convenience for the binary formats' bit-mask enums.
ADT chunk binary structs (the MCNK cell header, texture layers, liquid records, flying bounds) and th...
Definition header.hpp:22
MapChunkFlags
Per-cell MCNK header flag bits (SMChunk.flags).
Definition header.hpp:24
@ Impassable
Impassable terrain (no walking).
Definition header.hpp:26
@ HasMccv
The cell has vertex colors (MCCV sub-chunk, WotLK+).
Definition header.hpp:31
@ LqRiver
Legacy (MCLQ) river liquid present.
Definition header.hpp:27
@ LqOcean
Legacy (MCLQ) ocean liquid present.
Definition header.hpp:28
@ LqSlime
Legacy (MCLQ) slime liquid present.
Definition header.hpp:30
@ LqMagma
Legacy (MCLQ) magma liquid present.
Definition header.hpp:29
@ HasMcsh
The cell has a baked shadow map (MCSH sub-chunk).
Definition header.hpp:25
MapHeaderFlags
Tile header flag bits (MHDRData.flags).
Definition header.hpp:112
@ HasMfbo
The tile has a flying bounds chunk (MFBO).
Definition header.hpp:113
@ Northrend
Set on some Northrend tiles; meaning unknown.
Definition header.hpp:114
constexpr void setFlag(E &value, E flag, bool on=true)
Set (or clear) flag bit flag in the enum-typed field value.
Definition flags.hpp:48
The flying bounding box (MFBO, BC+): two 3x3 grids of int16 heights — a maximum plane you fall throug...
Definition header.hpp:149
std::array< std::int16_t, 9 > minimum
The minimum plane: 3x3 int16 heights (row-major).
Definition header.hpp:154
bool operator==(const MFBOPlanes &) const =default
std::array< std::int16_t, 9 > maximum
The maximum plane: 3x3 int16 heights (row-major).
Definition header.hpp:151
The tile header (MHDR, 64 bytes, root/monolithic).
Definition header.hpp:120
MapHeaderFlags flags
Flags; MapHeaderFlags bits.
Definition header.hpp:122
std::array< std::uint8_t, 3 > padding
Definition header.hpp:139
std::uint8_t mampValue
The inline MAMP alpha-map downscale value (Cata+): the alpha texture size is 64 / (2^value); an expli...
Definition header.hpp:137
std::array< std::uint32_t, 3 > unused
Definition header.hpp:140
bool operator==(const MHDRData &) const =default
The per-cell MCNK header — 128 bytes, memcpy'd verbatim.
Definition header.hpp:42
std::uint32_t areaId
The cell's area id (a foreign key into AreaTable; in the alpha clients, packed zone/subzone u16s).
Definition header.hpp:66
MapChunkFlags flags
Flags; MapChunkFlags bits.
Definition header.hpp:44
bool operator==(const SMChunk &) const =default
std::uint16_t unknownButUsed
Unknown but written (padding in the alpha clients).
Definition header.hpp:74
std::uint32_t indexY
The cell's row index in the 16x16 grid (0-15).
Definition header.hpp:50
std::array< std::uint8_t, 16 > predominantTexture
Definition header.hpp:76
C3Vector position
The cell origin in world space; MCVT heights are relative to it.
Definition header.hpp:87
std::uint64_t holesHighRes() const
The 64-bit high-resolution hole mask (the 8 bytes at header offset 0x14), valid when the high_res_hol...
Definition header.hpp:95
std::uint16_t holesLowRes
The 16-bit low-resolution terrain hole mask (a 4x4 bitfield); used unless the high_res_holes flag sel...
Definition header.hpp:71
std::uint32_t indexX
The cell's column index in the 16x16 grid (0-15).
Definition header.hpp:47
std::array< std::uint8_t, 8 > noEffectDoodad
An 8x8 bitfield (8 bytes): 1 disables detail doodads in that sub-cell (WoD may store it as an explici...
Definition header.hpp:79
void setHolesHighRes(std::uint64_t holes)
Set the 64-bit high-resolution hole mask (and the high_res_holes flag).
Definition header.hpp:100
A 3D float vector — the workhorse: positions, normals, rotations-as-Euler-degrees in placements.
Definition types.hpp:49
The binary-level math and color primitives shared across WoW file formats (wowdev....