From ed6ed7a62217369544f3e31ef9a886f459f0c21b Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 15 Mar 2025 21:31:40 +0100 Subject: assetbundle struct to abstract over unityfs and serializedfile --- src/classes/pptr.rs | 19 +++++++++---------- src/classes/streaminginfo.rs | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src/classes') diff --git a/src/classes/pptr.rs b/src/classes/pptr.rs index 9b54cbb..366e17c 100644 --- a/src/classes/pptr.rs +++ b/src/classes/pptr.rs @@ -1,6 +1,6 @@ use crate::{ + assetbundle::AssetBundle, object::{Value, parser::FromValue}, - serialized_file::SerializedFile, }; use anyhow::{Result, anyhow, bail}; use log::debug; @@ -13,7 +13,7 @@ use std::{ #[derive(Debug, Serialize)] pub struct PPtr { #[serde(skip, default)] - _class: PhantomData, + pub(crate) _class: PhantomData, pub class: String, pub file_id: i32, pub path_id: i64, @@ -54,27 +54,26 @@ impl PPtr { pub fn is_null(&self) -> bool { self.path_id == 0 && self.file_id == 0 } - pub fn load( - &self, - file: &mut SerializedFile, - shared_assets: Option<&mut SerializedFile>, - ) -> Result { + pub fn load(&self, bundle: &mut AssetBundle) -> Result { debug!( "loading PPtr<{}> file_id={} path_id={}", self.class, self.file_id, self.path_id ); match self.file_id { 0 => { - let ob = 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(); - file.read_object(ob)?.parse() + bundle.main.read_object(ob)?.parse() } 1 => { - let file = shared_assets.unwrap(); + let file = bundle.shared_assets.as_mut().ok_or(anyhow!( + "shared assets referenced but not included in bundle" + ))?; let ob = file .objects .iter() diff --git a/src/classes/streaminginfo.rs b/src/classes/streaminginfo.rs index 21029f4..e308f1c 100644 --- a/src/classes/streaminginfo.rs +++ b/src/classes/streaminginfo.rs @@ -26,7 +26,7 @@ impl FromValue for StreamingInfo { } impl StreamingInfo { - pub fn read(&self, fs: &mut UnityFS) -> Result> { + pub fn read(&self, fs: &UnityFS) -> Result> { if !self.path.starts_with("archive:") { bail!("StreamingInfo path does not start on archive:") } -- cgit v1.2.3-70-g09d2