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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
// converter.rs - Version conversion for ADT files
use crate::Adt;
use crate::chunk::*;
use crate::error::{AdtError, Result};
use crate::liquid_converter::{convert_mclq_to_mh2o, convert_mh2o_to_mclq};
use crate::mcnk_subchunks::MclqSubchunk;
use crate::version::AdtVersion;
/// Convert an ADT from one version to another
pub fn convert_adt(source: &Adt, target_version: AdtVersion) -> Result<Adt> {
if source.version() == target_version {
// No conversion needed
return Ok(source.clone());
}
match (source.version(), target_version) {
// Vanilla to TBC
(AdtVersion::Vanilla, AdtVersion::TBC) => vanilla_to_tbc(source),
// TBC to WotLK
(AdtVersion::TBC, AdtVersion::WotLK) => tbc_to_wotlk(source),
// WotLK to Cataclysm
(AdtVersion::WotLK, AdtVersion::Cataclysm) => wotlk_to_cataclysm(source),
// Downgrading
(AdtVersion::TBC, AdtVersion::Vanilla) => tbc_to_vanilla(source),
(AdtVersion::WotLK, AdtVersion::TBC) => wotlk_to_tbc(source),
(AdtVersion::Cataclysm, AdtVersion::WotLK) => cataclysm_to_wotlk(source),
// Multiple version jumps - chain conversions
(from, to) if from < to => {
// Upgrading through multiple versions
let mut current = source.clone();
// Chain conversions (convert to each intermediate version)
let versions = upgrade_path(from, to);
for (_v_from, v_to) in versions {
current = convert_adt(¤t, v_to)?;
}
Ok(current)
}
(from, to) if from > to => {
// Downgrading through multiple versions
let mut current = source.clone();
// Chain conversions (convert to each intermediate version)
let versions = downgrade_path(from, to);
for (_v_from, v_to) in versions {
current = convert_adt(¤t, v_to)?;
}
Ok(current)
}
_ => {
// Conversion not supported
Err(AdtError::VersionConversionUnsupported {
from: source.version().to_string(),
to: target_version.to_string(),
})
}
}
}
/// Generate a path of version pairs for upgrading
fn upgrade_path(from: AdtVersion, to: AdtVersion) -> Vec<(AdtVersion, AdtVersion)> {
let mut path = Vec::new();
let mut current = from;
while current < to {
let next = match current {
AdtVersion::Vanilla => AdtVersion::TBC,
AdtVersion::TBC => AdtVersion::WotLK,
AdtVersion::WotLK => AdtVersion::Cataclysm,
AdtVersion::Cataclysm => AdtVersion::MoP,
AdtVersion::MoP => AdtVersion::WoD,
AdtVersion::WoD => AdtVersion::Legion,
AdtVersion::Legion => AdtVersion::BfA,
AdtVersion::BfA => AdtVersion::Shadowlands,
AdtVersion::Shadowlands => AdtVersion::Dragonflight,
AdtVersion::Dragonflight => break, // No higher version
};
path.push((current, next));
current = next;
}
path
}
/// Generate a path of version pairs for downgrading
fn downgrade_path(from: AdtVersion, to: AdtVersion) -> Vec<(AdtVersion, AdtVersion)> {
let mut path = Vec::new();
let mut current = from;
while current > to {
let next = match current {
AdtVersion::Dragonflight => AdtVersion::Shadowlands,
AdtVersion::Shadowlands => AdtVersion::BfA,
AdtVersion::BfA => AdtVersion::Legion,
AdtVersion::Legion => AdtVersion::WoD,
AdtVersion::WoD => AdtVersion::MoP,
AdtVersion::MoP => AdtVersion::Cataclysm,
AdtVersion::Cataclysm => AdtVersion::WotLK,
AdtVersion::WotLK => AdtVersion::TBC,
AdtVersion::TBC => AdtVersion::Vanilla,
AdtVersion::Vanilla => break, // No lower version
};
path.push((current, next));
current = next;
}
path
}
/// Convert from Vanilla to TBC
fn vanilla_to_tbc(source: &Adt) -> Result<Adt> {
// Create a clone of the source to modify
let mut result = source.clone();
// Update the version
result.version = AdtVersion::TBC;
// Update MVER chunk to match the new version
result.mver.version = AdtVersion::TBC.to_mver_value();
// Add TBC-specific chunks (empty ones)
// Add MFBO (default flight boundaries with 9 values per plane)
result.mfbo = Some(MfboChunk {
max: [0; 9], // 9 int16 values for max plane
min: [0; 9], // 9 int16 values for min plane
});
// Update MHDR to include TBC fields
if let Some(ref mut mhdr) = result.mhdr {
// Add MFBO offset field
mhdr.mfbo_offset = Some(0); // Will be updated during writing
}
Ok(result)
}
/// Convert from TBC to WotLK
fn tbc_to_wotlk(source: &Adt) -> Result<Adt> {
// Create a clone of the source to modify
let mut result = source.clone();
// Update the version
result.version = AdtVersion::WotLK;
// Update MVER chunk to match the new version
result.mver.version = AdtVersion::WotLK.to_mver_value();
// Convert liquid data in MCNK chunks from MCLQ to MH2O format
// Collect all MCLQ chunks from MCNKs
let mut mclq_chunks = Vec::new();
for _mcnk in &source.mcnk_chunks {
// MCLQ chunks would need to be extracted from the original file
// For now, create a placeholder based on the liquid data in the MCNKs
let mclq = MclqSubchunk {
x_vertices: 9, // Default grid size
y_vertices: 9,
base_height: 0.0, // This would come from the actual MCLQ data
vertices: Vec::new(), // This would be filled with actual vertices
};
mclq_chunks.push(mclq);
}
// Convert MCLQ data to MH2O format
let mh2o = convert_mclq_to_mh2o(&mclq_chunks, &source.mcnk_chunks)?;
result.mh2o = Some(mh2o);
// Update MHDR to include WotLK fields
if let Some(ref mut mhdr) = result.mhdr {
// Add MH2O offset field
mhdr.mh2o_offset = Some(0); // Will be updated during writing
}
Ok(result)
}
/// Convert from WotLK to Cataclysm
fn wotlk_to_cataclysm(source: &Adt) -> Result<Adt> {
// Create a clone of the source to modify
let mut result = source.clone();
// Update the version
result.version = AdtVersion::Cataclysm;
// Update MVER chunk to match the new version
result.mver.version = AdtVersion::Cataclysm.to_mver_value();
// Add Cataclysm-specific chunks (empty ones)
// Add MTFX (empty texture effects)
result.mtfx = Some(MtfxChunk {
effects: Vec::new(),
});
// Update MHDR to include Cataclysm fields
if let Some(ref mut mhdr) = result.mhdr {
// Add MTFX offset field
mhdr.mtfx_offset = Some(0); // Will be updated during writing
}
Ok(result)
}
/// Convert from TBC to Vanilla
fn tbc_to_vanilla(source: &Adt) -> Result<Adt> {
// Create a clone of the source to modify
let mut result = source.clone();
// Update the version
result.version = AdtVersion::Vanilla;
// Update MVER chunk to match the new version
result.mver.version = AdtVersion::Vanilla.to_mver_value();
// Remove TBC-specific chunks
result.mfbo = None;
// Update MHDR to remove TBC fields
if let Some(ref mut mhdr) = result.mhdr {
mhdr.mfbo_offset = None;
}
Ok(result)
}
/// Convert from WotLK to TBC
fn wotlk_to_tbc(source: &Adt) -> Result<Adt> {
// Create a clone of the source to modify
let mut result = source.clone();
// Update the version
result.version = AdtVersion::TBC;
// Update MVER chunk to match the new version
result.mver.version = AdtVersion::TBC.to_mver_value();
// Convert water data in MCNK chunks from MH2O to MCLQ format
if let Some(ref mh2o) = source.mh2o {
let mclq_chunks = convert_mh2o_to_mclq(mh2o, &source.mcnk_chunks)?;
// Update MCNKs with MCLQ data
// In a real implementation, we'd update each MCNK's liquid data
// For now, just store the liquid offset in the MCNK header
for (i, mcnk) in result.mcnk_chunks.iter_mut().enumerate() {
if i < mclq_chunks.len() && !mclq_chunks[i].vertices.is_empty() {
// Mark this MCNK as having liquid data
mcnk.liquid_offset = 1; // Placeholder, would be set during writing
mcnk.liquid_size = 1; // Placeholder
} else {
// No liquid data
mcnk.liquid_offset = 0;
mcnk.liquid_size = 0;
}
}
}
// Remove WotLK-specific chunks
result.mh2o = None;
// Update MHDR to remove WotLK fields
if let Some(ref mut mhdr) = result.mhdr {
mhdr.mh2o_offset = None;
}
Ok(result)
}
/// Convert from Cataclysm to WotLK
fn cataclysm_to_wotlk(source: &Adt) -> Result<Adt> {
// Create a clone of the source to modify
let mut result = source.clone();
// Update the version
result.version = AdtVersion::WotLK;
// Update MVER chunk to match the new version
result.mver.version = AdtVersion::WotLK.to_mver_value();
// Remove Cataclysm-specific chunks
result.mtfx = None;
// Update MHDR to remove Cataclysm fields
if let Some(ref mut mhdr) = result.mhdr {
mhdr.mtfx_offset = None;
}
Ok(result)
}