diff options
Diffstat (limited to 'src/bin/textures.rs')
-rw-r--r-- | src/bin/textures.rs | 56 |
1 files changed, 23 insertions, 33 deletions
diff --git a/src/bin/textures.rs b/src/bin/textures.rs index 6ceabac..2e077fe 100644 --- a/src/bin/textures.rs +++ b/src/bin/textures.rs @@ -3,12 +3,10 @@ use log::warn; use std::{ env::args, fs::{File, create_dir_all}, - io::{BufReader, Seek, SeekFrom}, + io::BufReader, }; use unity_tools::{ - classes::texture2d::Texture2D, - object::{parser::FromValue, read::read_value}, - serialized_file::SerializedFile, + classes::texture2d::Texture2D, object::parser::FromValue, serialized_file::SerializedFile, unityfs::UnityFS, }; @@ -27,38 +25,30 @@ fn main() -> anyhow::Result<()> { .to_owned(); let mut cab = fs.read(&cabfile)?; - let file = SerializedFile::read(&mut cab)?; - for ob in file.objects { - cab.seek(SeekFrom::Start(ob.data_offset))?; - let typetree = if ob.type_id < 0 { - unimplemented!() - } else { - &file.types[ob.type_id as usize] - }; - if let Some(typetree) = &typetree.type_tree { - if typetree.type_string != "Texture2D" { - continue; - } - let value = read_value(typetree, file.endianness, &mut cab)?; - let mut texture = Texture2D::from_value(value)?; - if texture.image_data.is_empty() { - texture.image_data = texture.stream_data.read(&mut fs2)?; - } - let path = format!( - "/tmp/a/{}_{i}.png", - texture.name.replace("/", "-").replace(".", "-") - ); - match texture.to_image() { - Ok(im) => { - if !im.as_rgba32f().is_some() { - im.save(&path).unwrap(); - println!("{path}"); - } + let mut file = SerializedFile::read(&mut cab)?; + for ob in file.objects.clone() { + if file.get_object_type_tree(&ob)?.type_string != "Texture2D" { + continue; + } + let value = file.read_object(ob)?; + let mut texture = Texture2D::from_value(value)?; + if texture.image_data.is_empty() { + texture.image_data = texture.stream_data.read(&mut fs2)?; + } + let path = format!( + "/tmp/a/{}_{i}.png", + texture.name.replace("/", "-").replace(".", "-") + ); + match texture.to_image() { + Ok(im) => { + if !im.as_rgba32f().is_some() { + im.save(&path).unwrap(); + println!("{path}"); } - Err(e) => warn!("{e}"), } - i += 1; + Err(e) => warn!("{e}"), } + i += 1; } Ok(()) |