aboutsummaryrefslogtreecommitdiff
path: root/src/bin/typegraph.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-03-14 14:58:38 +0100
committermetamuffin <metamuffin@disroot.org>2025-03-14 14:58:38 +0100
commit7ff78cff53eba1da60b8beb851732e2f8197c221 (patch)
treefa6d914270ba1acdeddbc3aa1ce1cf7cf0824a7b /src/bin/typegraph.rs
parent6debd2c0a230d623c06869ca4c4f13519f53eb5d (diff)
downloadunity-tools-7ff78cff53eba1da60b8beb851732e2f8197c221.tar
unity-tools-7ff78cff53eba1da60b8beb851732e2f8197c221.tar.bz2
unity-tools-7ff78cff53eba1da60b8beb851732e2f8197c221.tar.zst
move files around
Diffstat (limited to 'src/bin/typegraph.rs')
-rw-r--r--src/bin/typegraph.rs124
1 files changed, 0 insertions, 124 deletions
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"
- )
-}