1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
//! Two-pass parser for World of Warcraft ADT terrain files using binrw.
//!
//! This library implements a clean, type-safe parser for ADT (A Dungeon Terrain) files
//! from World of Warcraft using the binrw serialization framework. It supports all
//! ADT format versions from Vanilla (1.12.1) through Mists of Pandaria (5.4.8).
//!
//! ## Architecture
//!
//! The parser follows a two-pass architecture:
//!
//! **Pass 1 (Discovery)**: Fast chunk enumeration without parsing chunk data. Identifies
//! version, file type, and chunk locations for selective parsing.
//!
//! **Pass 2 (Parse)**: Type-safe extraction of chunk data into binrw-derived structures
//! with automatic offset resolution.
//!
//! ## Supported Versions
//!
//! - **Vanilla (1.x)** - Basic terrain chunks (MVER, MHDR, MCNK)
//! - **The Burning Crusade (2.x)** - Flight boundaries (MFBO chunk)
//! - **Wrath of the Lich King (3.x)** - Enhanced water/lava system (MH2O chunk)
//! - **Cataclysm (4.x)** - Split file architecture, texture amplifiers (MAMP chunk)
//! - **Mists of Pandaria (5.x)** - Texture parameters (MTXP chunk)
//!
//! Version detection is automatic based on chunk presence and structure analysis.
//!
//! ## Quick Start
//!
//! ```no_run
//! use std::fs::File;
//! use std::io::BufReader;
//! use wow_adt::{parse_adt, ParsedAdt};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Parse any ADT file with automatic version detection
//! let file = File::open("world/maps/azeroth/azeroth_32_32.adt")?;
//! let mut reader = BufReader::new(file);
//! let adt = parse_adt(&mut reader)?;
//!
//! // Access terrain data based on file type
//! match adt {
//! ParsedAdt::Root(root) => {
//! println!("Version: {:?}", root.version);
//! println!("Terrain chunks: {}", root.mcnk_chunks.len());
//! println!("Textures: {}", root.textures.len());
//!
//! // Access water data (WotLK+)
//! if let Some(water) = &root.water_data {
//! for (idx, entry) in water.entries.iter().enumerate() {
//! if entry.header.has_liquid() {
//! println!("Chunk {} has {} water layer(s)",
//! idx, entry.instances.len());
//! }
//! }
//! }
//! }
//! ParsedAdt::Tex0(tex) => {
//! println!("Texture file with {} entries", tex.textures.len());
//! }
//! ParsedAdt::Obj0(obj) => {
//! println!("Object file with {} models", obj.models.len());
//! }
//! _ => {}
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Example: Fast Chunk Discovery
//!
//! ```no_run
//! use std::fs::File;
//! use wow_adt::{discover_chunks, ChunkId};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut file = File::open("terrain.adt")?;
//! let discovery = discover_chunks(&mut file)?;
//!
//! println!("Total chunks: {}", discovery.total_chunks);
//!
//! // Check for specific chunks without full parsing
//! if discovery.has_chunk(ChunkId::MH2O) {
//! println!("File contains advanced water (WotLK+)");
//! }
//!
//! // Selective parsing: only parse specific chunks
//! for chunk_id in discovery.chunk_types() {
//! println!("Found chunk: {}", chunk_id.as_str());
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Example: Building ADT Files
//!
//! ```no_run
//! use wow_adt::builder::AdtBuilder;
//! use wow_adt::{AdtVersion, DoodadPlacement};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let adt = AdtBuilder::new()
//! .with_version(AdtVersion::WotLK)
//! .add_texture("terrain/grass_01.blp")
//! .add_texture("terrain/dirt_01.blp")
//! .add_model("doodad/tree_01.m2")
//! .add_doodad_placement(DoodadPlacement {
//! name_id: 0,
//! unique_id: 1,
//! position: [1000.0, 1000.0, 100.0],
//! rotation: [0.0, 0.0, 0.0],
//! scale: 1024,
//! flags: 0,
//! })
//! .build()?;
//!
//! adt.write_to_file("world/maps/custom/custom_32_32.adt")?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Example: Loading Split Files (Cataclysm+)
//!
//! ```no_run
//! use wow_adt::AdtSet;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Load complete split file set (automatically discovers _tex0, _obj0, _lod files)
//! let adt_set = AdtSet::load_from_path("World/Maps/Azeroth/Azeroth_30_30.adt")?;
//!
//! // Check if complete set
//! if adt_set.is_complete() {
//! println!("Complete Cataclysm+ split file set");
//! println!("Version: {:?}", adt_set.version());
//! }
//!
//! // Merge split files into unified structure
//! let merged = adt_set.merge()?;
//! println!("Merged {} MCNK chunks", merged.mcnk_chunks.len());
//! println!("Textures: {}", merged.textures.len());
//! println!("Models: {}", merged.models.len());
//! # Ok(())
//! # }
//! ```
//!
//! ## Features
//!
//! - **Automatic version detection** - Identifies WoW client version from chunk analysis
//! - **Split file support** - Cataclysm+ `_tex0`, `_obj0`, `_obj1`, `_lod` file handling
//! - **Type-safe parsing** - binrw derives for zero-overhead serialization
//! - **Fast discovery** - <10ms chunk inventory for selective parsing
//! - **Builder API** - Fluent builder for programmatically constructing ADT files
//!
//! ## Modules
//!
//! - [`adt_set`] - High-level API for loading complete split file sets (Cataclysm+)
//! - [`api`] - Core parser API (parse_adt, ParsedAdt enum)
//! - [`builder`] - Fluent builder API for constructing ADT files
//! - [`merger`] - Utilities for merging split files into unified structures
//! - [`split_set`] - Split file discovery and path management
//! - [`chunk_discovery`] - Discovery phase for fast chunk enumeration
//! - [`chunk_header`] - ChunkHeader binrw structure (8-byte magic + size)
//! - [`chunk_id`] - ChunkId type with reversed magic constants
//! - [`version`] - AdtVersion enum and detection logic
//! - [`file_type`] - AdtFileType enum (Root, Tex0, Obj0, etc.)
//! - [`error`] - AdtError types with detailed context
//! - [`chunks`] - Chunk structure definitions (MVER, MHDR, MCNK, etc.)
//!
//! ## References
//!
//! Based on information from:
//! - [WoW.dev ADT Format](https://wowdev.wiki/ADT) - Format specification
//! - [TrinityCore](https://github.com/TrinityCore/TrinityCore) - Server reference
//! - [noggit-red](https://github.com/Marlamin/noggit-red) - Map editor reference
// Public API modules
// Internal parser modules
pub
pub
// Public re-exports for convenience
pub use AdtSet;
pub use ;
pub use ;
pub use ;
pub use ChunkHeader;
pub use ChunkId;
pub use CombinedAlphaMap;
pub use ;
pub use AdtFileType;
pub use AdtVersion;
// Chunk structure re-exports
pub use ;