From 8713a4835101b2feaa969d2865371df5c07c61ad Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 23 Feb 2025 16:14:44 -0500 Subject: [PATCH] De-duplicate all the GUID structs, implement better debug display This replaces several of the duplicate GUID-like structs, and throws them into a struct that more closely resembles FGuid. --- src/guid.rs | 17 +++++++++++++++++ src/lib.rs | 1 + src/map_property.rs | 31 ++++--------------------------- src/struct_property.rs | 8 ++------ src/structs.rs | 4 +++- 5 files changed, 27 insertions(+), 34 deletions(-) create mode 100644 src/guid.rs diff --git a/src/guid.rs b/src/guid.rs new file mode 100644 index 0000000..572beee --- /dev/null +++ b/src/guid.rs @@ -0,0 +1,17 @@ +use std::fmt; +use binrw::binrw; + +// See https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Core/Misc/FGuid +#[binrw] +pub struct Guid { + pub a: u32, + pub b: u32, + pub c: u32, + pub d: u32 +} + +impl fmt::Debug for Guid { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(&format!("{:02X}{:02X}{:02X}{:02X}", self.a, self.b, self.c, self.d)) + } +} diff --git a/src/lib.rs b/src/lib.rs index 19fbc09..319b041 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,7 @@ pub mod set_property; pub mod str_property; pub mod struct_property; mod structs; +mod guid; use binrw::helpers::{until, until_eof}; diff --git a/src/map_property.rs b/src/map_property.rs index a52269a..6ebf305 100644 --- a/src/map_property.rs +++ b/src/map_property.rs @@ -3,6 +3,7 @@ use crate::struct_property::Struct; use crate::structs::PrimaryAssetNameProperty; use binrw::helpers::until_exclusive; use binrw::{BinRead, BinResult, binrw}; +use crate::guid::Guid; // A struct without a name #[binrw] @@ -80,12 +81,6 @@ pub struct MapSubEnumProperty { pub value: String, } -#[binrw] -#[derive(Debug)] -pub struct GuidStruct { - pub guid: [u8; 16], -} - // Used in MapProperty exclusively, seems to be a shortened version of some Properties #[binrw] #[derive(Debug)] @@ -107,24 +102,6 @@ pub enum MabSubProperty { Enum(MapSubEnumProperty), } -#[binrw] -#[derive(Debug)] -pub struct GuidStructThing { - pub guid: [u8; 16], -} - -#[binrw] -#[derive(Debug)] -pub struct SomeIDStruct { - pub guid: [u8; 16], -} - -#[binrw] -#[derive(Debug)] -pub struct SomeID2Struct { - pub guid: [u8; 16], -} - #[binrw] #[derive(Debug)] pub struct StringMapKey { @@ -146,11 +123,11 @@ pub enum MapKeyProperty { #[br(pre_assert(*magic == KeyType::EnumAgain))] EnumAgain(MapSubEnumProperty), #[br(pre_assert(*magic == KeyType::GUID))] - GUID(GuidStructThing), + GUID(Guid), #[br(pre_assert(*magic == KeyType::SomeID))] - SomeID(SomeIDStruct), + SomeID(Guid), #[br(pre_assert(*magic == KeyType::SomeID2))] - SomeID2(SomeID2Struct), + SomeID2(Guid), } #[binrw] diff --git a/src/struct_property.rs b/src/struct_property.rs index 98510bd..8699359 100644 --- a/src/struct_property.rs +++ b/src/struct_property.rs @@ -1,10 +1,6 @@ -use crate::structs::{ - CarryCountProperty, DAAssembleIdDataStruct, DABuildDataStruct, DACharacterCommonStatusStruct, - DALoadOptionStruct, DAMachineColoringDataStruct, DAModuleColorStruct, DAModuleItemDataStruct, - DateTimeStruct, GuidStruct, LinearColorStruct, PrimaryAssetIdStruct, PrimaryAssetNameProperty, - SaveSlotInfoStruct, -}; +use crate::structs::{CarryCountProperty, DAAssembleIdDataStruct, DABuildDataStruct, DACharacterCommonStatusStruct, DALoadOptionStruct, DAMachineColoringDataStruct, DAModuleColorStruct, DAModuleItemDataStruct, DateTimeStruct, GuidStruct, LinearColorStruct, PrimaryAssetIdStruct, PrimaryAssetNameProperty, SaveSlotInfoStruct}; use binrw::binrw; +use crate::guid::Guid; #[binrw] #[derive(Debug)] diff --git a/src/structs.rs b/src/structs.rs index 3a5195d..b8c8c67 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -1,6 +1,7 @@ use crate::Property; use binrw::binrw; use crate::common::read_string_with_length; +use crate::guid::Guid; #[binrw] #[derive(Debug)] @@ -82,7 +83,8 @@ pub struct DAAssembleIdDataStruct { #[binrw] #[derive(Debug)] pub struct GuidStruct { - pub unk: [u8; 33], + #[br(pad_before = 17)] + pub guid: Guid } #[binrw]