Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6c56fed
Separate the concept of Transform and GameObject; separate the concep…
mitchell-merry May 11, 2026
958fbd8
Add isSelf function, add / update more comments
mitchell-merry May 11, 2026
f575ae4
Create get_class_mono/il2cpp which should fix the klass_name discrepa…
mitchell-merry May 11, 2026
0152784
come on now
mitchell-merry May 11, 2026
25d397b
remove todo comments
mitchell-merry May 11, 2026
d078723
tweak
mitchell-merry May 11, 2026
c974ef2
Revert changes for scene name and path as string
mitchell-merry May 13, 2026
e964365
tmp
mitchell-merry May 14, 2026
5ab8c87
add new sig, add offsets
mitchell-merry May 15, 2026
135f371
update project settings
mitchell-merry May 15, 2026
305c1c5
add cheat table
mitchell-merry May 15, 2026
440ec35
add to todo
mitchell-merry May 15, 2026
25f596a
latest unity version etc
mitchell-merry May 16, 2026
5df5ac0
create mono::Object and clarify everything
mitchell-merry May 16, 2026
822dac3
comments
mitchell-merry May 16, 2026
1b3ed11
update todo
mitchell-merry May 16, 2026
50be285
Start cleaning
mitchell-merry Jun 27, 2026
1cb0786
remove more
mitchell-merry Jun 27, 2026
03646e0
more cleaning + formatting
mitchell-merry Jun 27, 2026
b54ef8e
Allow manually overriding the scene manager offsets
mitchell-merry Jun 27, 2026
8679e33
Merge branch 'master' into transform-refactor-tweaks
mitchell-merry Jun 27, 2026
a24f19e
Add another fixme
mitchell-merry Jun 27, 2026
63776b0
Revert changes to offsets, leave note
mitchell-merry Jun 27, 2026
972bb5e
Add get_component_mono_object to streamline
mitchell-merry Jun 27, 2026
1a29b00
Support older Unity versions by splitting on Mono version when readin…
mitchell-merry Jun 27, 2026
6657b25
Couple doc improvements
mitchell-merry Jun 27, 2026
f323316
Some more documentation
mitchell-merry Jun 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
/Cargo.lock
.idea
**/.DS_Store
15 changes: 14 additions & 1 deletion src/game_engine/unity/il2cpp/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@
}

impl Class {
pub(super) fn get_name<const N: usize>(
pub fn get_from_component(

Check warning on line 16 in src/game_engine/unity/il2cpp/class.rs

View workflow job for this annotation

GitHub Actions / Test (Host)

missing documentation for an associated function

Check warning on line 16 in src/game_engine/unity/il2cpp/class.rs

View workflow job for this annotation

GitHub Actions / build (wasm32-wasip1, stable)

missing documentation for an associated function

Check warning on line 16 in src/game_engine/unity/il2cpp/class.rs

View workflow job for this annotation

GitHub Actions / build (wasm32-unknown-unknown, stable)

missing documentation for an associated function

Check warning on line 16 in src/game_engine/unity/il2cpp/class.rs

View workflow job for this annotation

GitHub Actions / build (wasm32-unknown-unknown, nightly)

missing documentation for an associated function

Check warning on line 16 in src/game_engine/unity/il2cpp/class.rs

View workflow job for this annotation

GitHub Actions / build (wasm32-wasip1, nightly)

missing documentation for an associated function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"component" isn't accurate here, but there's something in between the component and the class. not exactly sure what it is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[ ] TODO: figure out what it is

process: &Process,
module: &Module,
component: Address,
) -> Result<Self, Error> {
process
.read_pointer(component, module.pointer_size)
.ok()
.filter(|val| !val.is_null())
.map(|class| Class { class })
.ok_or(Error {})
}

pub fn get_name<const N: usize>(

Check warning on line 29 in src/game_engine/unity/il2cpp/class.rs

View workflow job for this annotation

GitHub Actions / Test (Host)

missing documentation for a method

Check warning on line 29 in src/game_engine/unity/il2cpp/class.rs

View workflow job for this annotation

GitHub Actions / build (wasm32-wasip1, stable)

missing documentation for a method

Check warning on line 29 in src/game_engine/unity/il2cpp/class.rs

View workflow job for this annotation

GitHub Actions / build (wasm32-unknown-unknown, stable)

missing documentation for a method

Check warning on line 29 in src/game_engine/unity/il2cpp/class.rs

View workflow job for this annotation

GitHub Actions / build (wasm32-unknown-unknown, nightly)

missing documentation for a method

Check warning on line 29 in src/game_engine/unity/il2cpp/class.rs

View workflow job for this annotation

GitHub Actions / build (wasm32-wasip1, nightly)

missing documentation for a method
&self,
process: &Process,
module: &Module,
Expand Down
28 changes: 28 additions & 0 deletions src/game_engine/unity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
// https://github.com/Unity-Technologies/mono
// https://github.com/CryZe/lunistice-auto-splitter/blob/b8c01031991783f7b41044099ee69edd54514dba/asr-dotnet/src/lib.rs

use crate::file_format::{elf, macho, pe};
use crate::{Error, PointerSize, Process};

pub mod il2cpp;
pub mod mono;
pub mod scene_manager;
Expand All @@ -91,9 +94,15 @@ const CSTR: usize = 128;

#[derive(Copy, Clone, PartialEq, Hash, Debug)]
#[non_exhaustive]
/// The file format of a given executable / binary - different per operating system.
/// See https://en.wikipedia.org/wiki/Comparison_of_executable_file_formats
enum BinaryFormat {
/// [Portable Executable](https://en.wikipedia.org/wiki/Portable_Executable), for Windows.
PE,
/// [Executable and Linkable Format](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format),
/// for Linux.
ELF,
/// [Mach-O](https://en.wikipedia.org/wiki/Mach-O) (Mach object), for Mac.
MachO,
}

Expand All @@ -103,3 +112,22 @@ fn get_backing_name(name: &str) -> Option<&str> {
let end = name[start + 1..].find('>')?;
Some(&name[start + 1..start + 1 + end])
}

impl Process {
/// Get the [BinaryFormat](BinaryFormat) and pointer size of the main module of the Process
// FIXME: BinaryFormat and this function should probably be widely available (rather
// than gated by Unity)
fn get_format_and_pointer_size(&self) -> Result<(BinaryFormat, PointerSize), Error> {
let main_module = self.get_main_module_range()?;

if let Some(x) = pe::MachineType::read(self, main_module.0) {
Ok((BinaryFormat::PE, x.pointer_size().ok_or(Error {})?))
} else if let Some(pointer_size) = elf::pointer_size(self, main_module.0) {
Ok((BinaryFormat::ELF, pointer_size))
} else if let Some(pointer_size) = macho::pointer_size(self, main_module) {
Ok((BinaryFormat::MachO, pointer_size))
} else {
Err(Error {})
}
}
}
37 changes: 34 additions & 3 deletions src/game_engine/unity/mono/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ use crate::{future::retry, string::ArrayCString, Address, Error, Process};
pub use asr_derive::MonoClass as Class;

/// A .NET class that is part of an [`Image`](Image).
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub struct Class {
pub(super) class: Address,
/// The address of the class
pub class: Address,
}

impl Class {
pub(super) fn get_name<const N: usize>(
/// Get the name of the class
pub fn get_name<const N: usize>(
&self,
process: &Process,
module: &Module,
Expand Down Expand Up @@ -215,3 +217,32 @@ impl Class {
retry(|| self.get_parent(process, module)).await
}
}

/** Represents a MonoObject, which is an instantiation of a MonoVTable (and therefore MonoClass). It
* is where the actual fields of the class live.
*
* See https://github.com/mono/mono/blob/0f53e9e151d92944cacab3e24ac359410c606df6/mono/metadata/object.h#L31.
*/
#[derive(Debug, Clone)]
pub struct Object {
/// The address of the Mono object.
pub address: Address,
}

impl Object {
/** Get the Mono [class](Class) of this object. */
pub fn get_class(&self, process: &Process, module: &Module) -> Result<Class, Error> {
process
// MonoVTable *vtable
// See https://github.com/mono/mono/blob/0f53e9e151d92944cacab3e24ac359410c606df6/mono/metadata/object.h#L32
.read_pointer(self.address, module.pointer_size)
.ok()
.filter(|val| !val.is_null())
// MonoClass *klass
// See https://github.com/mono/mono/blob/0f53e9e151d92944cacab3e24ac359410c606df6/mono/metadata/class-internals.h#L360
.and_then(|addr| process.read_pointer(addr, module.pointer_size).ok())
.filter(|val| !val.is_null())
.map(|class| Class { class })
.ok_or(Error {})
}
}
6 changes: 3 additions & 3 deletions src/game_engine/unity/mono/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use assembly::Assembly;
mod image;
pub use image::Image;
mod class;
pub use class::Class;
pub use class::{Class, Object};
mod field;
use field::Field;
mod version;
Expand Down Expand Up @@ -193,12 +193,12 @@ impl Module {
}

/// Retrieve the [Mono version](Version) of the module.
pub fn get_version(&self) -> Version {
pub const fn get_version(&self) -> Version {
self.version
}

/// Retrieve the [pointer size](PointerSize) of the process/module.
pub fn get_pointer_size(&self) -> PointerSize {
pub const fn get_pointer_size(&self) -> PointerSize {
self.pointer_size
}

Expand Down
232 changes: 120 additions & 112 deletions src/game_engine/unity/mono/offsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,118 +241,126 @@ impl MonoOffsets {
},
v_table: MonoVTableOffsets { vtable: 0x28 },
}),
(BinaryFormat::ELF | BinaryFormat::MachO, Version::V3, PointerSize::Bit64) => Some(&Self {
assembly: AssemblyOffsets {
aname: 0x10,
image: 0x60,
},
image: ImageOffsets { class_cache: 0x4D0 },
hash_table: HashTableOffsets {
size: 0x18,
table: 0x20,
},
class: ClassOffsets {
parent: 0x28,
image: 0x38,
name: 0x40,
namespace: 0x48,
vtable_size: 0x54,
fields: 0x90,
runtime_info: 0xC8,
field_count: 0xF8,
next_class_cache: 0x100,
},
field: FieldInfoOffsets {
name: 0x8,
offset: 0x18,
alignment: 0x20,
},
v_table: MonoVTableOffsets { vtable: 0x48 },
}),
(BinaryFormat::ELF | BinaryFormat::MachO, Version::V2, PointerSize::Bit64) => Some(&Self {
assembly: AssemblyOffsets {
aname: 0x10,
image: 0x60,
},
image: ImageOffsets { class_cache: 0x4C0 },
hash_table: HashTableOffsets {
size: 0x18,
table: 0x20,
},
class: ClassOffsets {
parent: 0x28,
image: 0x38,
name: 0x40,
namespace: 0x48,
vtable_size: 0x54,
fields: 0x90,
runtime_info: 0xC8,
field_count: 0xF8,
next_class_cache: 0x100,
},
field: FieldInfoOffsets {
name: 0x8,
offset: 0x18,
alignment: 0x20,
},
v_table: MonoVTableOffsets { vtable: 0x40 },
}),
(BinaryFormat::ELF | BinaryFormat::MachO, Version::V1Cattrs, PointerSize::Bit64) => Some(&Self {
assembly: AssemblyOffsets {
aname: 0x10,
image: 0x58,
},
image: ImageOffsets { class_cache: 0x3D0 },
hash_table: HashTableOffsets {
size: 0x18,
table: 0x20,
},
class: ClassOffsets {
parent: 0x28,
image: 0x40,
name: 0x48,
namespace: 0x50,
vtable_size: 0x18,
fields: 0xA8,
runtime_info: 0xF8,
field_count: 0x94,
next_class_cache: 0x100,
},
field: FieldInfoOffsets {
name: 0x8,
offset: 0x18,
alignment: 0x20,
},
v_table: MonoVTableOffsets { vtable: 0x48 },
}),
(BinaryFormat::ELF | BinaryFormat::MachO, Version::V1, PointerSize::Bit64) => Some(&Self {
assembly: AssemblyOffsets {
aname: 0x10,
image: 0x58,
},
image: ImageOffsets { class_cache: 0x3D0 },
hash_table: HashTableOffsets {
size: 0x18,
table: 0x20,
},
class: ClassOffsets {
parent: 0x28,
image: 0x38,
name: 0x40,
namespace: 0x48,
vtable_size: 0x18,
fields: 0xA0,
runtime_info: 0xF0,
field_count: 0x8C,
next_class_cache: 0xF8,
},
field: FieldInfoOffsets {
name: 0x8,
offset: 0x18,
alignment: 0x20,
},
v_table: MonoVTableOffsets { vtable: 0x48 },
}),
(BinaryFormat::ELF | BinaryFormat::MachO, Version::V3, PointerSize::Bit64) => {
Some(&Self {

@mitchell-merry mitchell-merry Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this indented a level... I didn't change any offsets here.

assembly: AssemblyOffsets {
aname: 0x10,
image: 0x60,
},
image: ImageOffsets { class_cache: 0x4D0 },
hash_table: HashTableOffsets {
size: 0x18,
table: 0x20,
},
class: ClassOffsets {
parent: 0x28,
image: 0x38,
name: 0x40,
namespace: 0x48,
vtable_size: 0x54,
fields: 0x90,
runtime_info: 0xC8,
field_count: 0xF8,
next_class_cache: 0x100,
},
field: FieldInfoOffsets {
name: 0x8,
offset: 0x18,
alignment: 0x20,
},
v_table: MonoVTableOffsets { vtable: 0x48 },
})
}
(BinaryFormat::ELF | BinaryFormat::MachO, Version::V2, PointerSize::Bit64) => {
Some(&Self {
assembly: AssemblyOffsets {
aname: 0x10,
image: 0x60,
},
image: ImageOffsets { class_cache: 0x4C0 },
hash_table: HashTableOffsets {
size: 0x18,
table: 0x20,
},
class: ClassOffsets {
parent: 0x28,
image: 0x38,
name: 0x40,
namespace: 0x48,
vtable_size: 0x54,
fields: 0x90,
runtime_info: 0xC8,
field_count: 0xF8,
next_class_cache: 0x100,
},
field: FieldInfoOffsets {
name: 0x8,
offset: 0x18,
alignment: 0x20,
},
v_table: MonoVTableOffsets { vtable: 0x40 },
})
}
(BinaryFormat::ELF | BinaryFormat::MachO, Version::V1Cattrs, PointerSize::Bit64) => {
Some(&Self {
assembly: AssemblyOffsets {
aname: 0x10,
image: 0x58,
},
image: ImageOffsets { class_cache: 0x3D0 },
hash_table: HashTableOffsets {
size: 0x18,
table: 0x20,
},
class: ClassOffsets {
parent: 0x28,
image: 0x40,
name: 0x48,
namespace: 0x50,
vtable_size: 0x18,
fields: 0xA8,
runtime_info: 0xF8,
field_count: 0x94,
next_class_cache: 0x100,
},
field: FieldInfoOffsets {
name: 0x8,
offset: 0x18,
alignment: 0x20,
},
v_table: MonoVTableOffsets { vtable: 0x48 },
})
}
(BinaryFormat::ELF | BinaryFormat::MachO, Version::V1, PointerSize::Bit64) => {
Some(&Self {
assembly: AssemblyOffsets {
aname: 0x10,
image: 0x58,
},
image: ImageOffsets { class_cache: 0x3D0 },
hash_table: HashTableOffsets {
size: 0x18,
table: 0x20,
},
class: ClassOffsets {
parent: 0x28,
image: 0x38,
name: 0x40,
namespace: 0x48,
vtable_size: 0x18,
fields: 0xA0,
runtime_info: 0xF0,
field_count: 0x8C,
next_class_cache: 0xF8,
},
field: FieldInfoOffsets {
name: 0x8,
offset: 0x18,
alignment: 0x20,
},
v_table: MonoVTableOffsets { vtable: 0x48 },
})
}
_ => None,
}
}
Expand Down
Loading
Loading