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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
use std::io::{Read, Write};
use crate::Guid;
use crate::tbc::{
MovementBlock, MovementFlags, ObjectType, SplineFlag, TransportInfo, UpdateFlag,
UpdateMask, UpdateType, Vector3d,
};
/// Auto generated from the original `wowm` in file [`wow_message_parser/wowm/world/gameobject/smsg_update_object_2_4_3.wowm:92`](https://github.com/gtker/wow_messages/tree/main/wow_message_parser/wowm/world/gameobject/smsg_update_object_2_4_3.wowm#L92):
/// ```text
/// struct Object {
/// UpdateType update_type;
/// if (update_type == VALUES) {
/// PackedGuid guid1;
/// UpdateMask mask1;
/// }
/// else if (update_type == MOVEMENT) {
/// PackedGuid guid2;
/// MovementBlock movement1;
/// }
/// else if (update_type == CREATE_OBJECT
/// || update_type == CREATE_OBJECT2) {
/// PackedGuid guid3;
/// ObjectType object_type;
/// MovementBlock movement2;
/// UpdateMask mask2;
/// }
/// else if (update_type == OUT_OF_RANGE_OBJECTS
/// || update_type == NEAR_OBJECTS) {
/// u32 count;
/// PackedGuid[count] guids;
/// }
/// }
/// ```
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub enum Object {
Values {
guid1: Guid,
mask1: UpdateMask,
},
Movement {
guid2: Guid,
movement1: MovementBlock,
},
CreateObject {
guid3: Guid,
mask2: UpdateMask,
movement2: MovementBlock,
object_type: ObjectType,
},
CreateObject2 {
guid3: Guid,
mask2: UpdateMask,
movement2: MovementBlock,
object_type: ObjectType,
},
OutOfRangeObjects {
guids: Vec<Guid>,
},
NearObjects {
guids: Vec<Guid>,
},
}
impl Object {
pub(crate) fn write_into_vec(&self, mut w: impl Write) -> Result<(), std::io::Error> {
// update_type: UpdateType
w.write_all(&(self.as_int().to_le_bytes()))?;
match &self {
Object::Values {
guid1,
mask1,
} => {
// guid1: PackedGuid
crate::util::write_packed_guid(&guid1, &mut w)?;
// mask1: UpdateMask
mask1.write_into_vec(&mut w)?;
}
Object::Movement {
guid2,
movement1,
} => {
// guid2: PackedGuid
crate::util::write_packed_guid(&guid2, &mut w)?;
// movement1: MovementBlock
movement1.write_into_vec(&mut w)?;
}
Object::CreateObject {
guid3,
mask2,
movement2,
object_type,
} => {
// guid3: PackedGuid
crate::util::write_packed_guid(&guid3, &mut w)?;
// object_type: ObjectType
w.write_all(&(object_type.as_int().to_le_bytes()))?;
// movement2: MovementBlock
movement2.write_into_vec(&mut w)?;
// mask2: UpdateMask
mask2.write_into_vec(&mut w)?;
}
Object::CreateObject2 {
guid3,
mask2,
movement2,
object_type,
} => {
// guid3: PackedGuid
crate::util::write_packed_guid(&guid3, &mut w)?;
// object_type: ObjectType
w.write_all(&(object_type.as_int().to_le_bytes()))?;
// movement2: MovementBlock
movement2.write_into_vec(&mut w)?;
// mask2: UpdateMask
mask2.write_into_vec(&mut w)?;
}
Object::OutOfRangeObjects {
guids,
} => {
// count: u32
w.write_all(&(guids.len() as u32).to_le_bytes())?;
// guids: PackedGuid[count]
for i in guids.iter() {
crate::util::write_packed_guid(i, &mut w)?;
}
}
Object::NearObjects {
guids,
} => {
// count: u32
w.write_all(&(guids.len() as u32).to_le_bytes())?;
// guids: PackedGuid[count]
for i in guids.iter() {
crate::util::write_packed_guid(i, &mut w)?;
}
}
}
Ok(())
}
}
impl Object {
pub(crate) fn read<R: std::io::Read>(mut r: R) -> Result<Self, crate::errors::ParseErrorKind> {
// update_type: UpdateType
let update_type = crate::util::read_u8_le(&mut r)?.try_into()?;
let update_type_if = match update_type {
UpdateType::Values => {
// guid1: PackedGuid
let guid1 = crate::util::read_packed_guid(&mut r)?;
// mask1: UpdateMask
let mask1 = UpdateMask::read(&mut r)?;
Object::Values {
guid1,
mask1,
}
}
UpdateType::Movement => {
// guid2: PackedGuid
let guid2 = crate::util::read_packed_guid(&mut r)?;
// movement1: MovementBlock
let movement1 = MovementBlock::read(&mut r)?;
Object::Movement {
guid2,
movement1,
}
}
UpdateType::CreateObject => {
// guid3: PackedGuid
let guid3 = crate::util::read_packed_guid(&mut r)?;
// object_type: ObjectType
let object_type = crate::util::read_u8_le(&mut r)?.try_into()?;
// movement2: MovementBlock
let movement2 = MovementBlock::read(&mut r)?;
// mask2: UpdateMask
let mask2 = UpdateMask::read(&mut r)?;
Object::CreateObject {
guid3,
mask2,
movement2,
object_type,
}
}
UpdateType::CreateObject2 => {
// guid3: PackedGuid
let guid3 = crate::util::read_packed_guid(&mut r)?;
// object_type: ObjectType
let object_type = crate::util::read_u8_le(&mut r)?.try_into()?;
// movement2: MovementBlock
let movement2 = MovementBlock::read(&mut r)?;
// mask2: UpdateMask
let mask2 = UpdateMask::read(&mut r)?;
Object::CreateObject2 {
guid3,
mask2,
movement2,
object_type,
}
}
UpdateType::OutOfRangeObjects => {
// count: u32
let count = crate::util::read_u32_le(&mut r)?;
// guids: PackedGuid[count]
let guids = {
let mut guids = Vec::with_capacity(count as usize);
let allocation_size = u64::from(count);
if allocation_size > crate::errors::MAX_ALLOCATION_SIZE {
return Err(crate::errors::ParseErrorKind::AllocationTooLargeError(allocation_size));
}
for _ in 0..count {
guids.push(crate::util::read_packed_guid(&mut r)?);
}
guids
};
Object::OutOfRangeObjects {
guids,
}
}
UpdateType::NearObjects => {
// count: u32
let count = crate::util::read_u32_le(&mut r)?;
// guids: PackedGuid[count]
let guids = {
let mut guids = Vec::with_capacity(count as usize);
let allocation_size = u64::from(count);
if allocation_size > crate::errors::MAX_ALLOCATION_SIZE {
return Err(crate::errors::ParseErrorKind::AllocationTooLargeError(allocation_size));
}
for _ in 0..count {
guids.push(crate::util::read_packed_guid(&mut r)?);
}
guids
};
Object::NearObjects {
guids,
}
}
};
Ok(update_type_if)
}
}
impl Object {
pub(crate) fn size(&self) -> usize {
(match self {
Self::Values {
guid1,
mask1,
} => {
1
+ crate::util::packed_guid_size(&guid1) // guid1: PackedGuid
+ mask1.size() // mask1: UpdateMask
}
Self::Movement {
guid2,
movement1,
} => {
1
+ crate::util::packed_guid_size(&guid2) // guid2: PackedGuid
+ movement1.size() // movement1: MovementBlock
}
Self::CreateObject {
guid3,
mask2,
movement2,
..
} => {
1
+ crate::util::packed_guid_size(&guid3) // guid3: PackedGuid
+ mask2.size() // mask2: UpdateMask
+ movement2.size() // movement2: MovementBlock
+ 1 // object_type: ObjectType
}
Self::CreateObject2 {
guid3,
mask2,
movement2,
..
} => {
1
+ crate::util::packed_guid_size(&guid3) // guid3: PackedGuid
+ mask2.size() // mask2: UpdateMask
+ movement2.size() // movement2: MovementBlock
+ 1 // object_type: ObjectType
}
Self::OutOfRangeObjects {
guids,
} => {
1
+ 4 // count: u32
+ guids.iter().fold(0, |acc, x| acc + crate::util::packed_guid_size(x)) // guids: PackedGuid[count]
}
Self::NearObjects {
guids,
} => {
1
+ 4 // count: u32
+ guids.iter().fold(0, |acc, x| acc + crate::util::packed_guid_size(x)) // guids: PackedGuid[count]
}
}) // update_type: Object
}
}
impl Default for Object {
fn default() -> Self {
// First enumerator without any fields
Self::Values {
guid1: Default::default(),
mask1: Default::default(),
}
}
}
impl Object {
pub(crate) const fn as_int(&self) -> u8 {
match self {
Self::Values { .. } => 0,
Self::Movement { .. } => 1,
Self::CreateObject { .. } => 2,
Self::CreateObject2 { .. } => 3,
Self::OutOfRangeObjects { .. } => 4,
Self::NearObjects { .. } => 5,
}
}
}
impl std::fmt::Display for Object {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Values{ .. } => f.write_str("Values"),
Self::Movement{ .. } => f.write_str("Movement"),
Self::CreateObject{ .. } => f.write_str("CreateObject"),
Self::CreateObject2{ .. } => f.write_str("CreateObject2"),
Self::OutOfRangeObjects{ .. } => f.write_str("OutOfRangeObjects"),
Self::NearObjects{ .. } => f.write_str("NearObjects"),
}
}
}