From 2ee2f1af847dbc9f1292baefc9fd652167b9103a Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 22 Mar 2025 17:18:39 +0100 Subject: relative file ids --- src/classes/pptr.rs | 60 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 25 deletions(-) (limited to 'src/classes/pptr.rs') diff --git a/src/classes/pptr.rs b/src/classes/pptr.rs index 366e17c..0e66b5f 100644 --- a/src/classes/pptr.rs +++ b/src/classes/pptr.rs @@ -15,13 +15,19 @@ pub struct PPtr { #[serde(skip, default)] pub(crate) _class: PhantomData, pub class: String, + pub source_file: usize, pub file_id: i32, pub path_id: i64, } impl FromValue for PPtr { fn from_value(v: Value) -> Result { - let Value::Object { class, fields } = v else { + let Value::Object { + class, + fields, + file, + } = v + else { bail!("PPtr expected but not an object") }; let inner = class @@ -32,6 +38,7 @@ impl FromValue for PPtr { Ok(PPtr { class: inner.to_owned(), _class: PhantomData, + source_file: file, file_id: fields["m_FileID"] .as_i32() .ok_or(anyhow!("PPtr m_FileID is not i32"))?, @@ -47,6 +54,7 @@ impl PPtr { PPtr { _class: PhantomData, class: self.class, + source_file: self.source_file, file_id: self.file_id, path_id: self.path_id, } @@ -59,30 +67,32 @@ impl PPtr { "loading PPtr<{}> file_id={} path_id={}", self.class, self.file_id, self.path_id ); - match self.file_id { - 0 => { - let ob = bundle - .main - .objects - .iter() - .find(|o| o.path_id == self.path_id) - .ok_or(anyhow!("object with path id {} not found", self.path_id))? - .to_owned(); - bundle.main.read_object(ob)?.parse() - } - 1 => { - let file = bundle.shared_assets.as_mut().ok_or(anyhow!( - "shared assets referenced but not included in bundle" - ))?; - let ob = file - .objects - .iter() - .find(|o| o.path_id == self.path_id) - .ok_or(anyhow!("object with path id {} not found", self.path_id))? - .to_owned(); - file.read_object(ob)?.parse() - } - _ => unimplemented!(), + let main_file = match (self.source_file, self.file_id) { + (0, 0) => true, + (0, 1) => false, + (1, 0) => false, + _ => unreachable!(), + }; + if main_file { + let ob = bundle + .main + .objects + .iter() + .find(|o| o.path_id == self.path_id) + .ok_or(anyhow!("object with path id {} not found", self.path_id))? + .to_owned(); + bundle.main.read_object(ob)?.parse() + } else { + let file = bundle.shared_assets.as_mut().ok_or(anyhow!( + "shared assets referenced but not included in bundle" + ))?; + let ob = file + .objects + .iter() + .find(|o| o.path_id == self.path_id) + .ok_or(anyhow!("object with path id {} not found", self.path_id))? + .to_owned(); + file.read_object(ob)?.parse() } } } -- cgit v1.2.3-70-g09d2