diff options
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/gltf.rs | 22 | ||||
-rw-r--r-- | src/bin/json.rs | 34 | ||||
-rw-r--r-- | src/bin/meshes.rs | 59 | ||||
-rw-r--r-- | src/bin/probe.rs | 21 | ||||
-rw-r--r-- | src/bin/textures.rs | 55 | ||||
-rw-r--r-- | src/bin/typegraph.rs | 124 | ||||
-rw-r--r-- | src/bin/yaml.rs | 50 |
7 files changed, 0 insertions, 365 deletions
diff --git a/src/bin/gltf.rs b/src/bin/gltf.rs deleted file mode 100644 index 323b6d2..0000000 --- a/src/bin/gltf.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![feature(array_chunks)] -use anyhow::anyhow; -use std::{env::args, fs::File, io::BufReader}; -use unity_tools::{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 mut fs = UnityFS::open(file())?; - // let mut fs2 = UnityFS::open(file())?; - - let cabfile = fs - .find_main_file() - .ok_or(anyhow!("no CAB file found"))? - .to_owned(); - - let mut cab = fs.read(&cabfile)?; - let file = SerializedFile::read(&mut cab)?; - for _ob in file.objects {} - - Ok(()) -} diff --git a/src/bin/json.rs b/src/bin/json.rs deleted file mode 100644 index dd83de6..0000000 --- a/src/bin/json.rs +++ /dev/null @@ -1,34 +0,0 @@ -use std::{ - env::{args, var}, - fs::File, - io::{BufReader, stdout}, -}; -use unity_tools::{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())?); - let mut fs = UnityFS::open(file)?; - let filter = args().nth(2); - let pretty = var("PRETTY").is_ok(); - - let node = fs.find_main_file().unwrap().to_owned(); - let mut cab = fs.read(&node)?; - let mut file = SerializedFile::read(&mut cab)?; - for ob in file.objects.clone() { - if let Some(f) = &filter { - if file.get_object_type_tree(&ob)?.type_string != *f && ob.path_id.to_string() != *f { - continue; - } - } - let value = file.read_object(ob)?; - if pretty { - serde_json::to_writer_pretty(stdout(), &value.to_json()).unwrap(); - } else { - serde_json::to_writer(stdout(), &value.to_json()).unwrap(); - } - println!() - } - - Ok(()) -} diff --git a/src/bin/meshes.rs b/src/bin/meshes.rs deleted file mode 100644 index e3758c4..0000000 --- a/src/bin/meshes.rs +++ /dev/null @@ -1,59 +0,0 @@ -#![feature(array_chunks)] -use anyhow::anyhow; -use std::{ - env::args, - fs::{File, create_dir_all}, - io::{BufReader, BufWriter, Write}, -}; -use unity_tools::{ - classes::mesh::{Mesh, VertexDataChannel}, - object::parser::FromValue, - 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 mut fs = UnityFS::open(file())?; - - let mut i = 0; - create_dir_all("/tmp/a").unwrap(); - - let cabfile = fs - .nodes() - .iter() - .find(|n| !n.name.ends_with(".resource") && !n.name.ends_with(".resS")) - .ok_or(anyhow!("no CAB file found"))? - .to_owned(); - - let mut cab = fs.read(&cabfile)?; - let mut file = SerializedFile::read(&mut cab)?; - for ob in file.objects.clone() { - if file.get_object_type_tree(&ob)?.type_string != "Mesh" { - continue; - } - let value = file.read_object(ob)?; - let mesh = Mesh::from_value(value).unwrap(); - let mut obj = BufWriter::new(File::create(format!( - "/tmp/a/{}_{i}.obj", - mesh.name.replace("/", "-").replace(".", "-") - ))?); - - let (pos_dims, positions) = mesh - .vertex_data - .read_channel(VertexDataChannel::Position) - .unwrap(); - assert_eq!(pos_dims, 3); - - for [x, y, z] in positions.array_chunks() { - writeln!(obj, "v {x} {y} {z}")?; - } - for [a, b, c] in mesh.read_indecies() { - writeln!(obj, "f {} {} {}", a + 1, b + 1, c + 1)?; - } - i += 1; - } - - Ok(()) -} diff --git a/src/bin/probe.rs b/src/bin/probe.rs deleted file mode 100644 index feca633..0000000 --- a/src/bin/probe.rs +++ /dev/null @@ -1,21 +0,0 @@ -use anyhow::Result; -use std::{env::args, fs::File, io::BufReader}; -use unity_tools::{serialized_file::SerializedFileHeader, unityfs::UnityFS}; - -fn main() -> Result<()> { - let file = BufReader::new(File::open(args().nth(1).unwrap())?); - let mut fs = UnityFS::open(file)?; - - let node = fs.find_main_file().unwrap().to_owned(); - let mut cab = fs.read(&node)?; - let ch = SerializedFileHeader::read(&mut cab)?; - - if fs.unity_version.is_ascii() && ch.generator_version.is_ascii() && ch.format < 100 { - println!( - "{}\t{}\t{}\t{}", - fs.file_version, fs.unity_version, ch.format, ch.generator_version - ); - } - - Ok(()) -} diff --git a/src/bin/textures.rs b/src/bin/textures.rs deleted file mode 100644 index 2e077fe..0000000 --- a/src/bin/textures.rs +++ /dev/null @@ -1,55 +0,0 @@ -use anyhow::anyhow; -use log::warn; -use std::{ - env::args, - fs::{File, create_dir_all}, - io::BufReader, -}; -use unity_tools::{ - classes::texture2d::Texture2D, object::parser::FromValue, 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 mut fs = UnityFS::open(file())?; - let mut fs2 = UnityFS::open(file())?; - - let mut i = 0; - create_dir_all("/tmp/a").unwrap(); - - let cabfile = fs - .find_main_file() - .ok_or(anyhow!("no CAB file found"))? - .to_owned(); - - let mut cab = fs.read(&cabfile)?; - 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; - } - - Ok(()) -} diff --git a/src/bin/typegraph.rs b/src/bin/typegraph.rs deleted file mode 100644 index ea55e05..0000000 --- a/src/bin/typegraph.rs +++ /dev/null @@ -1,124 +0,0 @@ -#![feature(random)] -use std::{ - collections::{BTreeMap, BTreeSet}, - env::args, - fs::File, - io::BufReader, -}; -use unity_tools::{ - serialized_file::{SerializedFile, TypeTreeNode}, - 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 filter_prims = args().any(|a| a == "no_primitives"); - - let mut edges = BTreeSet::new(); - let node = fs.find_main_file().unwrap().to_owned(); - let mut cab = fs.read(&node)?; - let file = SerializedFile::read(&mut cab)?; - - for ob in file.objects { - let typetree = if ob.type_id < 0 { - unimplemented!() - } else { - &file.types[ob.type_id as usize] - }; - fn print_types( - edges: &mut BTreeSet<(String, String)>, - filter_prims: bool, - tt: TypeTreeNode, - ) { - for c in tt.children { - let mut c = vec![c]; - loop { - let mut nc = Vec::new(); - let mut f = false; - for mut c in c { - if let Some(inner) = c.type_string.strip_prefix("PPtr<") { - c.type_string = inner.strip_suffix(">").unwrap().to_owned(); - f = true; - } else if matches!( - c.type_string.as_str(), - "Array" | "pair" | "map" | "vector" - ) { - nc.extend(c.children); - f = true - } else { - nc.push(c); - }; - } - c = nc; - if !f { - break; - } - } - for c in c { - if filter_prims && is_primitive(&c.type_string) { - continue; - } - edges.insert((tt.type_string.to_owned(), c.type_string.to_owned())); - print_types(edges, filter_prims, c); - } - } - } - - if let Some(tree) = &typetree.type_tree { - print_types(&mut edges, filter_prims, tree.clone()); - } - } - let nodes = edges - .iter() - .flat_map(|(k, v)| [k, v]) - .collect::<BTreeSet<_>>(); - let ids = nodes - .into_iter() - .enumerate() - .map(|(i, n)| (n, i)) - .collect::<BTreeMap<_, _>>(); - - println!("digraph {{"); - for (name, id) in &ids { - println!("t{id} [label={name:?}]"); - } - for (a, b) in &edges { - println!("t{} -> t{}", ids[a], ids[b]); - } - println!("}}"); - - Ok(()) -} - -fn is_primitive(s: &str) -> bool { - matches!( - s, - "Type*" - | "int" - | "unsigned int" - | "UInt8" - | "UInt16" - | "UInt32" - | "UInt64" - | "SInt8" - | "SInt16" - | "SInt32" - | "SInt64" - | "bool" - | "float" - | "string" - | "float3" - | "float4" - | "float2" - | "Vector2f" - | "Vector3f" - | "Vector4f" - | "Matrix4x4f" - | "ColorRGBA" - | "Rectf" - | "Quaternionf" - | "xform" - ) -} diff --git a/src/bin/yaml.rs b/src/bin/yaml.rs deleted file mode 100644 index 4ef8933..0000000 --- a/src/bin/yaml.rs +++ /dev/null @@ -1,50 +0,0 @@ -use serde_yml::Value; -use std::{ - env::args, - fs::File, - io::{BufReader, stdout}, -}; -use unity_tools::{classes::HValue, 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())?); - let mut fs = UnityFS::open(file)?; - let filter = args().nth(2); - - let node = fs.find_main_file().unwrap().to_owned(); - let mut cab = fs.read(&node)?; - - let mut file = SerializedFile::read(&mut cab)?; - for ob in file.objects.clone() { - if let Some(f) = &filter { - if file.get_object_type_tree(&ob)?.type_string != *f && ob.path_id.to_string() != *f { - continue; - } - } - let value = file.read_object(ob)?; - let hvalue = HValue::from_value(value)?; - - let mut hvalue = serde_yml::to_value(hvalue)?; - trim_large_arrays(&mut hvalue); - - serde_yml::to_writer(stdout(), &hvalue).unwrap(); - println!() - } - - Ok(()) -} - -fn trim_large_arrays(v: &mut Value) { - match v { - Value::Sequence(values) => { - values.iter_mut().for_each(trim_large_arrays); - while values.len() > 32 { - values.pop(); - } - } - Value::Mapping(mapping) => mapping.map.values_mut().for_each(trim_large_arrays), - Value::Tagged(tagged_value) => trim_large_arrays(&mut tagged_value.value), - _ => (), - } -} |