Skip to content

Commit

Permalink
unity debug
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Jan 24, 2025
1 parent 30e11c0 commit 23261e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions rust/src/unity/asset_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ mod tests {
}

for obj in asset_file.get_objects() {
if obj.file_id != 107 {
continue;
}

let data = &data[obj.byte_start as usize..obj.byte_start as usize + obj.byte_size];
match obj.class_id {
ClassID::Transform => {
Expand Down
7 changes: 7 additions & 0 deletions rust/src/unity/types/binary.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

use deku::prelude::*;
use crate::unity::util::deku_peek;

// https://github.com/AssetRipper/TypeTreeDumps/blob/main/StructsDump/release/2019.4.39f1.dump
// e.g. Outer Wilds
Expand Down Expand Up @@ -123,6 +124,7 @@ pub struct MeshRenderer {
#[derive(DekuRead, Clone, Debug)]
#[deku(ctx = "version: UnityVersion")]
pub struct Mesh {
#[deku(reader = "deku_peek(deku::reader, \"name\")")]
pub name: CharArray,
pub submeshes: UnityArray<SubMesh>,
pub shapes: BlendShapeData,
Expand All @@ -131,6 +133,7 @@ pub struct Mesh {
pub root_bone_name_hash: u32,
pub bones_aabb: UnityArray<AABB>,
pub variable_bone_count_weights: UnityArray<u32>,
#[deku(reader = "deku_peek(deku::reader, \"mesh_compression\")")]
pub mesh_compression: MeshCompression,
pub is_readable: u8,
pub keep_vertices: u8,
Expand All @@ -142,10 +145,14 @@ pub struct Mesh {
pub vertex_data: VertexData,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment3: Vec<u8>,
pub compressed_mesh: CompressedMesh,
#[deku(reader = "deku_peek(deku::reader, \"local_aabb\")")]
pub local_aabb: AABB,
#[deku(reader = "deku_peek(deku::reader, \"mesh_usage_flags\")")]
pub mesh_usage_flags: i32,
#[deku(reader = "deku_peek(deku::reader, \"baked_convex_collision_mesh\")")]
pub baked_convex_collision_mesh: ByteArray,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment4: Vec<u8>,
#[deku(reader = "deku_peek(deku::reader, \"baked_triangle_collision_mesh\")")]
pub baked_triangle_collision_mesh: ByteArray,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment5: Vec<u8>,
pub mesh_metrics: [f32; 2],
Expand Down
2 changes: 1 addition & 1 deletion rust/src/unity/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn deku_peek<'a, T, R: deku::no_std_io::Read + deku::no_std_io::Seek>(reader
where for<'b> T: DekuReader<'b, ()> + Debug
{
println!("deku_peek - {}", msg);
println!(" offset: {}", reader.bits_read);
println!(" offset: {} / {}", reader.bits_read >> 3, reader.bits_read);
match T::from_reader_with_ctx(reader, ()) {
Ok(value) => {
println!(" value: {:?}", value);
Expand Down

0 comments on commit 23261e5

Please sign in to comment.