use anyhow::anyhow; use std::{env::args, fs::File, io::BufReader}; use unity_tools::{classes::material::Material, serialized_file::SerializedFile, unityfs::UnityFS}; fn main() -> anyhow::Result<()> { env_logger::init_from_env("LOG"); let file = BufReader::new(File::open(args().nth(1).unwrap()).unwrap()); let fs = UnityFS::open(file)?; let mode = args().nth(2).unwrap(); let cabfile = fs .find_main_file() .ok_or(anyhow!("no CAB file found"))? .to_owned(); let cab = fs.read(&cabfile)?; let mut file = SerializedFile::read(cab)?; let mut sharedassets = file .find_fs_shared_assets(&fs) .map(|n| { let f = fs.read(&n)?; let f = SerializedFile::read(f)?; Ok::<_, anyhow::Error>(f) }) .transpose()?; for ob in file.objects.clone() { if file.get_object_type_tree(&ob)?.type_string != "Material" { continue; } let mat = file.read_object(ob)?.parse::()?; match mode.as_str() { "material" => { println!("{}", mat.name) } "shader" => { println!( "{}", mat.shader .load(&mut file, sharedassets.as_mut())? .parsed .name ) } x => panic!("unknown mode {x:?}"), } } Ok(()) }