aboutsummaryrefslogtreecommitdiff
path: root/exporter/src/bin/textures.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-03-15 21:31:40 +0100
committermetamuffin <metamuffin@disroot.org>2025-03-15 21:31:40 +0100
commited6ed7a62217369544f3e31ef9a886f459f0c21b (patch)
treec36f0e344e00b32c563494f77dd4191dc55f8c94 /exporter/src/bin/textures.rs
parentca02789996b94db87cd84571edb42bbcd9a3a18b (diff)
downloadunity-tools-ed6ed7a62217369544f3e31ef9a886f459f0c21b.tar
unity-tools-ed6ed7a62217369544f3e31ef9a886f459f0c21b.tar.bz2
unity-tools-ed6ed7a62217369544f3e31ef9a886f459f0c21b.tar.zst
assetbundle struct to abstract over unityfs and serializedfile
Diffstat (limited to 'exporter/src/bin/textures.rs')
-rw-r--r--exporter/src/bin/textures.rs28
1 files changed, 8 insertions, 20 deletions
diff --git a/exporter/src/bin/textures.rs b/exporter/src/bin/textures.rs
index a3b6cec..56cfc9b 100644
--- a/exporter/src/bin/textures.rs
+++ b/exporter/src/bin/textures.rs
@@ -1,38 +1,26 @@
-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,
-};
+use unity_tools::{assetbundle::AssetBundle, classes::texture2d::Texture2D};
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 bundle = AssetBundle::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)?;
+ for ob in bundle
+ .all_toplevel_of_class("Texture2D")
+ .collect::<Vec<_>>()
+ {
+ let mut texture = ob.load(&mut bundle)?.parse::<Texture2D>()?;
if texture.image_data.is_empty() {
- texture.image_data = texture.stream_data.read(&mut fs)?;
+ texture.image_data = texture.stream_data.read(&bundle.fs)?;
}
let path = format!(
"/tmp/a/{}_{i}.png",