diff options
author | metamuffin <metamuffin@disroot.org> | 2025-03-22 17:18:39 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-03-22 17:18:39 +0100 |
commit | 2ee2f1af847dbc9f1292baefc9fd652167b9103a (patch) | |
tree | dfadbd29afdd00c80ab31e8dfaee217045102d95 /src/classes | |
parent | d780d420a69fe239bdb93ce7d1899e380a682062 (diff) | |
download | unity-tools-2ee2f1af847dbc9f1292baefc9fd652167b9103a.tar unity-tools-2ee2f1af847dbc9f1292baefc9fd652167b9103a.tar.bz2 unity-tools-2ee2f1af847dbc9f1292baefc9fd652167b9103a.tar.zst |
relative file ids
Diffstat (limited to 'src/classes')
-rw-r--r-- | src/classes/pptr.rs | 60 | ||||
-rw-r--r-- | src/classes/streaminginfo.rs | 5 |
2 files changed, 39 insertions, 26 deletions
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<T = Value> { #[serde(skip, default)] pub(crate) _class: PhantomData<T>, pub class: String, + pub source_file: usize, pub file_id: i32, pub path_id: i64, } impl<T> FromValue for PPtr<T> { fn from_value(v: Value) -> Result<Self> { - 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<T> FromValue for PPtr<T> { 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<T: FromValue> PPtr<T> { 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<T: FromValue> PPtr<T> { "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() } } } diff --git a/src/classes/streaminginfo.rs b/src/classes/streaminginfo.rs index e308f1c..d593a5b 100644 --- a/src/classes/streaminginfo.rs +++ b/src/classes/streaminginfo.rs @@ -28,7 +28,10 @@ impl FromValue for StreamingInfo { impl StreamingInfo { pub fn read(&self, fs: &UnityFS<impl Read + Seek>) -> Result<Vec<u8>> { if !self.path.starts_with("archive:") { - bail!("StreamingInfo path does not start on archive:") + bail!( + "StreamingInfo path does not start on 'archive:' ({:?})", + self.path + ) } let nodeinfo = fs .header |