Skip to content

Commit

Permalink
Unity fixes + decrunching (#744)
Browse files Browse the repository at this point in the history
* Fix typo

* unity: Add some missing texture types

* unity: add ScriptMapper and Shader

ScriptMappers contain shader names, so we can actually sort materials by the shaders they use

* Add Outer Wilds stub

* Remove some cruft

* fix use of shaderName

* nicer message on metadata parse error

* fix bug in concatBufs

* use texture2ddecoder for decrunching

* fix Outer Wilds shader error

* fix wasm-bindgen version

* rm log
  • Loading branch information
wgreenberg authored Jan 20, 2025
1 parent a001264 commit 1da3428
Show file tree
Hide file tree
Showing 11 changed files with 778 additions and 122 deletions.
78 changes: 44 additions & 34 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ lz4_flex = { version = "0.10.0", default-features = false, features = ["safe-dec
lzma-rs = { version = "0.3.0", features = ["raw_decoder"] }
naga = { git = "https://github.com/magcius/wgpu", branch = "issue-4349", features = ["glsl-in", "wgsl-out"] }
num_enum = "0.5.7"
wasm-bindgen = "0.2.95"
wasm-bindgen = "=0.2.95"
web-sys = { version = "0.3.48", features = ["console"] }
nalgebra-glm = "0.19.0"
rand = "0.8.5"
getrandom = { version = "0.2.15", features = ["js"] }
noclip-macros = { version = "*", path = "./noclip-macros" }
texture2ddecoder = { git = "https://github.com/wgreenberg/texture2ddecoder" }
24 changes: 24 additions & 0 deletions rust/src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,27 @@ pub fn deflate_raw_decompress(src: &[u8]) -> Vec<u8> {
inflate::inflate_bytes(src).unwrap()
}

#[wasm_bindgen(js_name = "CrunchTexture")]
pub struct CrunchTexture {
handle: texture2ddecoder::CrunchHandle,
}

#[wasm_bindgen(js_class = "CrunchTexture")]
impl CrunchTexture {
pub fn new(data: &[u8]) -> Result<Self, String> {
let handle = texture2ddecoder::CrunchHandle::new(data)
.map_err(|err| format!("{:?}", err))?;
Ok(Self {
handle,
})
}

pub fn get_num_levels(&self) -> u32 {
self.handle.get_num_levels()
}

pub fn decode_level(&self, data: &[u8], level_index: u32) -> Result<Vec<u8>, String> {
self.handle.unpack_level(data, level_index)
.map_err(|err| err.into())
}
}
5 changes: 3 additions & 2 deletions rust/src/unity/asset_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ impl AssetFile {
pub fn append_metadata_chunk(&mut self, data: &[u8]) -> Result<(), String> {
// data will be the file from bytes 0..data_offset, so skip to where the metadata starts
let bitslice = BitSlice::from_slice(data);
let (rest, _) = SerializedFileHeader::read(&bitslice, ()).unwrap();
let (rest, _) = SerializedFileHeader::read(&bitslice, ())
.map_err(|err| format!("failed to parse metadata file header: {:?}", err))?;
match SerializedFileMetadata::read(rest, self.header.version) {
Ok((_, metadata)) => self.metadata = Some(metadata),
Err(err) => return Err(format!("failed to parse metadata: {:?}", err)),
Expand Down Expand Up @@ -77,7 +78,7 @@ impl AssetFile {
ClassID::MonoBehavior
};
result.push(AssetFileObject {
file_id:obj.file_id,
file_id: obj.file_id,
byte_start,
byte_size: obj.byte_size as usize,
class_id,
Expand Down
Loading

0 comments on commit 1da3428

Please sign in to comment.