blob: 5cfaaa78ac174a9da4b4c40a2b2220df98578adc (
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
|
use std::{
env::args,
fs::{File, create_dir_all},
io::{BufReader, Seek, SeekFrom},
};
use unity_tools::{
classes::{FromValue, texture2d::Texture2d},
object::read_value,
serialized_file::read_serialized_file,
unityfs::UnityFS,
};
fn main() -> anyhow::Result<()> {
env_logger::init_from_env("LOG");
let file = BufReader::new(File::open(args().nth(1).unwrap())?);
let mut fs = UnityFS::open(file)?;
let mut i = 0;
create_dir_all("/tmp/tex").unwrap();
for node in fs.nodes().to_vec() {
if node.name.ends_with(".resource") || node.name.ends_with(".resS") {
continue;
}
let mut cab = fs.read(&node)?;
let file = read_serialized_file(&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 texture = Texture2d::from_value(value).unwrap();
if texture.image_data.len() > 0 {
let path = format!("/tmp/tex/{i}.png");
println!("{path}");
texture.to_image().unwrap().save(path).unwrap();
i += 1;
}
}
}
}
Ok(())
}
|