1use std::{
5 fs,
6 io::{Cursor, Read, Seek, Write},
7 path::Path,
8};
9
10use binrw::{binrw, BinReaderExt, BinResult, BinWrite};
11
12#[cfg(feature = "serde")]
13use serde::{Deserialize, Serialize};
14
15#[binrw]
17#[brw(magic = b"FNV\0", little)]
18#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
19#[derive(Debug)]
20pub struct FnvFile {
21 #[br(temp)]
22 #[bw(calc = 1u32)]
23 unk1: u32,
24
25 #[br(temp)]
26 #[bw(calc = entries.len() as u32)]
27 entry_count: u32,
28
29 #[br(count = entry_count)]
30 pub entries: Vec<FnvEntry>,
31}
32
33impl FnvFile {
34 pub fn read<R: Read + Seek>(reader: &mut R) -> BinResult<Self> {
36 let fnv = reader.read_le::<Self>()?;
37
38 Ok(fnv)
39 }
40
41 pub fn from_file<P: AsRef<Path>>(path: P) -> BinResult<Self> {
43 let mut file = Cursor::new(fs::read(path)?);
44 let fnv = file.read_le::<Self>()?;
45
46 Ok(fnv)
47 }
48
49 pub fn write<W: Write + Seek>(&self, writer: &mut W) -> BinResult<()> {
51 self.write_le(writer)
52 }
53
54 pub fn write_to_file<P: AsRef<Path>>(&self, path: P) -> BinResult<()> {
56 let mut cursor = Cursor::new(Vec::new());
57
58 self.write_le(&mut cursor)?;
59 fs::write(path, cursor.get_mut())?;
60
61 Ok(())
62 }
63}
64
65#[binrw]
67#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
68#[derive(Debug)]
69pub struct FnvEntry {
70 pub fighter_num: u32,
71 pub volume: Volume,
72}
73
74#[binrw]
76#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
77#[derive(Debug)]
78pub struct Volume {
79 pub other: f32,
80 pub sound_attr: f32,
81 pub se_fighter_step: f32,
82 pub se_fighter_landing: f32,
83 pub se_collision_step: f32,
84 pub se_collision_landing: f32,
85 pub se_stage: f32,
86 pub bgm: f32,
87}