-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnd.rs
66 lines (48 loc) · 1.42 KB
/
snd.rs
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
use binrw::binrw;
use serde::{Serialize, Deserialize};
use super::{NuccBinaryParsed, NuccBinaryType};
const STR_LEN: usize = 0x20;
#[binrw]
#[derive(Serialize, Deserialize, Debug)]
pub struct Entry {
#[br(map = |x: Vec<u8>| String::from_utf8_lossy(&x).trim_end_matches('\u{0}').to_string(), count = STR_LEN)] // Need to trim the null bytes
#[bw(map = |x: &String| (x.clone() + String::from('\u{0}').repeat(STR_LEN - x.len()).as_str()).into_bytes())]
pub sound_name: String,
#[brw(pad_before = 0x2)]
pub volume: f32,
pub unk1: i16,
pub unk2: i16,
pub unk3: i16,
pub pitch: i16,
pub unk4: f32,
pub timing: f32,
pub index: i16,
pub unk6: i16,
pub unk7: i16,
pub unk8: f32,
}
#[binrw]
#[derive(Serialize, Deserialize, Debug)]
pub struct Snd {
#[bw(calc = self.entries.len() as u16)]
pub entry_count: u16,
#[br(count = entry_count)]
pub entries: Vec<Entry>
}
impl NuccBinaryParsed for Snd {
fn binary_type(&self) -> NuccBinaryType {
NuccBinaryType::Snd
}
fn extension(&self) -> String {
String::from(".json")
}
fn serialize(&self) -> Vec<u8> {
serde_json::to_string_pretty(self).unwrap().into()
}
fn deserialize(data: &[u8]) -> Self
where
Self: Sized,
{
serde_json::from_slice(data).unwrap()
}
}