aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-03-12 13:20:44 +0100
committermetamuffin <metamuffin@disroot.org>2025-03-12 13:20:44 +0100
commit4906844cbfd2717a29b434fb7d8f90c5117fddd5 (patch)
treebf0e744dbe861b6e5688986eadfc555f3f2b2570
parent8bea7b0838ca83af9abf2ec64b679b98c92d472e (diff)
downloadunity-tools-4906844cbfd2717a29b434fb7d8f90c5117fddd5.tar
unity-tools-4906844cbfd2717a29b434fb7d8f90c5117fddd5.tar.bz2
unity-tools-4906844cbfd2717a29b434fb7d8f90c5117fddd5.tar.zst
streaming large files
-rw-r--r--src/bin/textures.rs8
-rw-r--r--src/classes/streaminginfo.rs4
-rw-r--r--src/object.rs7
3 files changed, 14 insertions, 5 deletions
diff --git a/src/bin/textures.rs b/src/bin/textures.rs
index 4a35de7..5db888e 100644
--- a/src/bin/textures.rs
+++ b/src/bin/textures.rs
@@ -51,7 +51,7 @@ fn main() -> anyhow::Result<()> {
let mut texture = Texture2D::from_value(value).unwrap();
if texture.image_data.len() == 0 {
let ress = ress.as_mut().unwrap();
- ress.seek(SeekFrom::Start(texture.stream_data.offset as u64))?;
+ ress.seek(SeekFrom::Start(texture.stream_data.offset))?;
ress.by_ref()
.take(texture.stream_data.size as u64)
.read_to_end(&mut texture.image_data)?;
@@ -62,8 +62,10 @@ fn main() -> anyhow::Result<()> {
);
match texture.to_image() {
Ok(im) => {
- im.save(&path).unwrap();
- println!("{path}");
+ if !im.as_rgba32f().is_some() {
+ im.save(&path).unwrap();
+ println!("{path}");
+ }
}
Err(e) => warn!("{e}"),
}
diff --git a/src/classes/streaminginfo.rs b/src/classes/streaminginfo.rs
index 3ab271d..1f8cadb 100644
--- a/src/classes/streaminginfo.rs
+++ b/src/classes/streaminginfo.rs
@@ -6,7 +6,7 @@ use super::FromValue;
#[derive(Debug, Serialize)]
pub struct StreamingInfo {
- pub offset: u32,
+ pub offset: u64,
pub path: String,
pub size: u32,
}
@@ -14,7 +14,7 @@ impl FromValue for StreamingInfo {
fn from_value(v: Value) -> Result<Self> {
let fields = v.as_class("StreamingInfo").unwrap();
Ok(StreamingInfo {
- offset: fields["offset"].as_u32().unwrap(),
+ offset: fields["offset"].as_u64().unwrap(),
size: fields["size"].as_u32().unwrap(),
path: fields["path"].to_owned().as_string().unwrap(),
})
diff --git a/src/object.rs b/src/object.rs
index ef677d1..92415e1 100644
--- a/src/object.rs
+++ b/src/object.rs
@@ -164,6 +164,13 @@ impl Value {
None
}
}
+ pub fn as_u64(&self) -> Option<u64> {
+ match self {
+ Self::U64(x) => Some(*x),
+ Self::U32(x) => Some(*x as u64),
+ _ => None,
+ }
+ }
pub fn as_f32(&self) -> Option<f32> {
if let Value::F32(s) = self {
Some(*s)