From 22d431d4104584442feb65816f2c30424723affe Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 25 Feb 2025 19:45:36 -0500 Subject: [PATCH] Add actual members of DATriggerData --- src/enum_property.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + src/structs.rs | 12 ++++++++++-- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/enum_property.rs diff --git a/src/enum_property.rs b/src/enum_property.rs new file mode 100644 index 0000000..cfa190c --- /dev/null +++ b/src/enum_property.rs @@ -0,0 +1,45 @@ +use binrw::binrw; +use crate::common::{read_string_with_length, write_string_with_length}; + +#[binrw] +#[derive(Debug)] +pub struct EnumProperty { + #[br(pad_before = 8)] // unk + #[br(parse_with = read_string_with_length)] + #[bw(write_with = write_string_with_length)] + pub enum_type: String, + + #[br(pad_before = 1)] + #[br(parse_with = read_string_with_length)] + #[bw(write_with = write_string_with_length)] + pub value: String, +} + +#[cfg(test)] +mod tests { + use super::*; + use binrw::{BinRead, BinWrite}; + use std::io::Cursor; + + #[test] + fn read_zero() { + // Persistent.sav + let data = [ + 0x29, 0x00, 0x00, + 0x00, 0x00, 0x00, + 0x00, 0x00, 0x18, + 0x00, 0x00, 0x00, + 0x45, 0x44, 0x41, + 0x57, 0x65, 0x61, + 0x70, 0x6f, 0x6e, + 0x4d, 0x6f, 0x64, + 0x75, 0x6c, 0x65, + 0x50, 0x6f, 0x73, + 0x69, 0x74, 0x69, + 0x6f, 0x6e, 0x00, + 0x00 + ]; + let mut cursor = Cursor::new(data); + let decoded = EnumProperty::read_le(&mut cursor).unwrap(); + } +} diff --git a/src/lib.rs b/src/lib.rs index f4d705a..261a5d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ pub mod set_property; pub mod str_property; pub mod struct_property; mod structs; +mod enum_property; use binrw::helpers::until_eof; use std::fs::write; diff --git a/src/structs.rs b/src/structs.rs index af8a796..54af307 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -14,6 +14,7 @@ use crate::primary_asset_type::PrimaryAssetTypeStruct; use crate::str_property::StrProperty; use binrw::{BinRead, BinResult, binrw}; use std::fmt::Debug; +use crate::enum_property::EnumProperty; #[binrw] #[derive(Debug)] @@ -207,10 +208,17 @@ pub struct DAModuleColorStruct { pub glow: LinearColorStruct, } -#[binrw] +#[paramacro::serialized_struct] #[derive(Debug)] pub struct DATriggerDataStruct { - pub unk: [u8; 319], // trigger weapon config in game + #[paramacro::serialized_field = "A"] + pub a: EnumProperty, + + #[paramacro::serialized_field = "B"] + pub b: EnumProperty, + + #[paramacro::serialized_field = "C"] + pub c: EnumProperty, } #[paramacro::serialized_struct]