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
//! # eff_data
//!
//! eff_data is a high-level library built off [eff_lib](https://crates.io/crates/eff_lib) for reading and writing EFF files from Super Smash Bros. Ultimate.
use std::{
fs,
io::{self, Read, Seek, Write},
path::Path,
};
use binrw::BinResult;
use eff_lib::{EffFile, EffectGroupElement, EffectHandle, EffectHandleFlags, EffectModelEntry};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/// The data associated with an [`EffFile`].
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq)]
pub struct EffData {
/// Collection of effect handles.
pub effect_handles: Vec<EffectHandleData>,
/// Collection of effect model entries.
pub effect_model_entries: Vec<EffectModelEntryData>,
/// Data buffer for the contained file resource.
#[cfg_attr(feature = "serde", serde(skip))]
pub resource_data: Option<Vec<u8>>,
}
impl EffData {
/// Reads the data from the given file path.
pub fn from_file<P: AsRef<Path>>(path: P) -> BinResult<Self> {
Ok(EffFile::from_file(path)?.into())
}
/// Reads the data from the given reader.
pub fn read<R: Read + Seek>(reader: &mut R) -> BinResult<Self> {
Ok(EffFile::read(reader)?.into())
}
/// Writes the data to the given writer.
pub fn write<W: Write + Seek>(&self, writer: &mut W) -> BinResult<()> {
EffFile::from(self).write(writer)
}
/// Writes the data to the given file path.
pub fn write_to_file<P: AsRef<Path>>(&self, path: P) -> BinResult<()> {
EffFile::from(self).write_to_file(path)
}
/// Writes the data from the resource data buffer to the given file path.
pub fn write_resource_to_file<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
if let Some(resource_data) = &self.resource_data {
fs::write(path, resource_data)?;
}
Ok(())
}
}
/// The data associated with an [`EffectHandle`].
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq)]
pub struct EffectHandleData {
/// Name of the effect handle.
pub name: String,
/// Flags representing the attributes of an effect.
pub flags: EffectHandleDataFlags,
/// Positive index to the emitter set.
pub emitter_set_handle: i32,
/// Name of the effect model.
pub effect_model_name: String,
/// Collection of effect group elements.
pub effect_group: Vec<EffectGroupElementData>,
}
/// Flags for an [`EffectHandleData`] representing the attributes of an effect.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct EffectHandleDataFlags {
pub unk_01: bool,
pub unk_02: bool,
pub unk_03: bool,
pub unk_04: bool,
pub unk_05: bool,
pub unk_06: bool,
pub unk_07: bool,
// pub unk_08: bool,
pub unk_09: bool,
pub unk_10: bool,
// pub unk_11: bool,
// pub unk_12: bool,
pub unk_13: bool,
pub unk_14: bool,
pub unk_15: bool,
pub unk_16: bool,
pub unk_17: bool,
// pub unk_18: bool,
pub hit_effect: bool,
pub unk_20: bool,
pub unk_21: bool,
// pub unk_22: bool,
pub unk_23: bool,
pub update_always: bool,
pub unk_25: bool,
pub unk_26: bool,
// pub unk_27: bool,
// pub unk_28: bool,
pub unk_29: bool,
pub unk_30: bool,
pub unk_31: bool,
pub unk_32: bool,
}
/// The data associated with an [`EffectGroupElement`].
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq)]
pub struct EffectGroupElementData {
/// Frame to request the emitter set on.
pub emitter_set_start_frame: i16,
/// Positive index to the emitter set.
pub emitter_set_handle: i16,
/// Joint name to parent the emitter set to.
pub parent_joint_name: String,
}
/// The data associated with an [`EffectModelEntry`].
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq)]
pub struct EffectModelEntryData {
/// Name of the effect model.
pub name: String,
// TODO: Determine the purpose of this field.
pub unk: i8,
}
impl From<EffFile> for EffData {
fn from(value: EffFile) -> Self {
Self::from(&value)
}
}
impl From<&EffFile> for EffData {
fn from(value: &EffFile) -> Self {
Self {
effect_handles: value
.effect_handles
.iter()
.zip(value.effect_handle_names.iter())
.map(|(handle, name)| EffectHandleData {
name: name.to_string().unwrap(),
flags: EffectHandleDataFlags {
unk_01: handle.flags.unk_01(),
unk_02: handle.flags.unk_02(),
unk_03: handle.flags.unk_03(),
unk_04: handle.flags.unk_04(),
unk_05: handle.flags.unk_05(),
unk_06: handle.flags.unk_06(),
unk_07: handle.flags.unk_07(),
// unk_08: handle.flags.unk_08(),
unk_09: handle.flags.unk_09(),
unk_10: handle.flags.unk_10(),
// unk_11: handle.flags.unk_11(),
// unk_12: handle.flags.unk_12(),
unk_13: handle.flags.unk_13(),
unk_14: handle.flags.unk_14(),
unk_15: handle.flags.unk_15(),
unk_16: handle.flags.unk_16(),
unk_17: handle.flags.unk_17(),
// unk_18: handle.flags.unk_18(),
hit_effect: handle.flags.hit_effect(),
unk_20: handle.flags.unk_20(),
unk_21: handle.flags.unk_21(),
// unk_22: handle.flags.unk_22(),
unk_23: handle.flags.unk_23(),
update_always: handle.flags.update_always(),
unk_25: handle.flags.unk_25(),
unk_26: handle.flags.unk_26(),
// unk_27: handle.flags.unk_27(),
// unk_28: handle.flags.unk_28(),
unk_29: handle.flags.unk_29(),
unk_30: handle.flags.unk_30(),
unk_31: handle.flags.unk_31(),
unk_32: handle.flags.unk_32(),
},
emitter_set_handle: handle.emitter_set_handle,
effect_model_name: if handle.effect_model_entry_handle != 0 {
value.effect_model_names[handle.effect_model_entry_handle as usize - 1]
.to_string()
.unwrap()
} else {
String::new()
},
effect_group: if handle.effect_group_element_count != 0 {
let start = handle.effect_group_element_start as usize - 1;
let end = start + handle.effect_group_element_count as usize;
value.effect_group_elements[start..end]
.iter()
.zip(value.parent_joint_names[start..end].iter())
.map(|(element, parent_joint_name)| EffectGroupElementData {
emitter_set_start_frame: element.emitter_set_start_frame,
emitter_set_handle: element.emitter_set_handle,
parent_joint_name: parent_joint_name.to_string().unwrap(),
})
.collect()
} else {
Vec::new()
},
})
.collect(),
effect_model_entries: value
.effect_model_entries
.iter()
.zip(value.effect_model_names.iter())
.map(|(model, name)| EffectModelEntryData {
name: name.to_string().unwrap(),
unk: model.unk,
})
.collect(),
resource_data: value.resource_data.clone(),
}
}
}
impl From<EffData> for EffFile {
fn from(value: EffData) -> Self {
Self::from(&value)
}
}
impl From<&EffData> for EffFile {
fn from(value: &EffData) -> Self {
let mut effect_group_start_index: i16 = 0;
Self {
effect_handles: value
.effect_handles
.iter()
.map(|handle| EffectHandle {
flags: EffectHandleFlags::new()
.with_unk_01(handle.flags.unk_01)
.with_unk_02(handle.flags.unk_02)
.with_unk_03(handle.flags.unk_03)
.with_unk_04(handle.flags.unk_04)
.with_unk_05(handle.flags.unk_05)
.with_unk_06(handle.flags.unk_06)
.with_unk_07(handle.flags.unk_07)
// .with_unk_08(handle.flags.unk_08)
.with_unk_09(handle.flags.unk_09)
.with_unk_10(handle.flags.unk_10)
// .with_unk_11(handle.flags.unk_11)
// .with_unk_12(handle.flags.unk_12)
.with_unk_13(handle.flags.unk_13)
.with_unk_14(handle.flags.unk_14)
.with_unk_15(handle.flags.unk_15)
.with_unk_16(handle.flags.unk_16)
.with_unk_17(handle.flags.unk_17)
// .with_unk_18(handle.flags.unk_18)
.with_hit_effect(handle.flags.hit_effect)
.with_unk_20(handle.flags.unk_20)
.with_unk_21(handle.flags.unk_21)
// .with_unk_22(handle.flags.unk_22)
.with_unk_23(handle.flags.unk_23)
.with_update_always(handle.flags.update_always)
.with_unk_25(handle.flags.unk_25)
.with_unk_26(handle.flags.unk_26)
// .with_unk_27(handle.flags.unk_27)
// .with_unk_28(handle.flags.unk_28)
.with_unk_29(handle.flags.unk_29)
.with_unk_30(handle.flags.unk_30)
.with_unk_31(handle.flags.unk_31)
.with_unk_32(handle.flags.unk_32),
emitter_set_handle: handle.emitter_set_handle,
effect_model_entry_handle: value
.effect_model_entries
.iter()
.position(|model| model.name == handle.effect_model_name)
.map_or(0, |i| i + 1) as i32,
effect_group_element_start: if !handle.effect_group.is_empty() {
let effect_group_element_start = effect_group_start_index + 1;
effect_group_start_index += handle.effect_group.len() as i16;
effect_group_element_start
} else {
0
},
effect_group_element_count: handle.effect_group.len() as i16,
})
.collect(),
effect_group_elements: value
.effect_handles
.iter()
.flat_map(|handle| {
handle
.effect_group
.iter()
.map(|element| EffectGroupElement {
emitter_set_start_frame: element.emitter_set_start_frame,
emitter_set_handle: element.emitter_set_handle,
})
})
.collect(),
effect_model_entries: value
.effect_model_entries
.iter()
.map(|model| EffectModelEntry { unk: model.unk })
.collect(),
effect_handle_names: value
.effect_handles
.iter()
.map(|handle| handle.name.clone().into())
.collect(),
effect_model_names: value
.effect_model_entries
.iter()
.map(|model| model.name.clone().into())
.collect(),
parent_joint_names: value
.effect_handles
.iter()
.flat_map(|handle| {
handle
.effect_group
.iter()
.map(|element| element.parent_joint_name.clone().into())
})
.collect(),
resource_data: value.resource_data.clone(),
}
}
}