blob: 3eb4dc03ed2bc10d968de2cc691b5c46d0c5132e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
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::<Material>()?;
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(())
}
|