Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 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
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
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 / 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, 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 / 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, 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 / 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, 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 / 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, nightly)

missing documentation for a method
&self,
process: &Process,
module: &Module,
Expand Down
17 changes: 16 additions & 1 deletion src/game_engine/unity/mono/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,22 @@
}

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/mono/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/mono/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/mono/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/mono/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/mono/class.rs

View workflow job for this annotation

GitHub Actions / build (wasm32-wasip1, nightly)

missing documentation for an associated function
process: &Process,
module: &Module,
component: Address,
) -> Result<Self, Error> {
process
.read_pointer(component, module.pointer_size)
.ok()
.filter(|val| !val.is_null())
.and_then(|addr| process.read_pointer(addr, 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 31 in src/game_engine/unity/mono/class.rs

View workflow job for this annotation

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

missing documentation for a method

Check warning on line 31 in src/game_engine/unity/mono/class.rs

View workflow job for this annotation

GitHub Actions / build (wasm32-wasip1, stable)

missing documentation for a method

Check warning on line 31 in src/game_engine/unity/mono/class.rs

View workflow job for this annotation

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

missing documentation for a method

Check warning on line 31 in src/game_engine/unity/mono/class.rs

View workflow job for this annotation

GitHub Actions / Test (Host)

missing documentation for a method

Check warning on line 31 in src/game_engine/unity/mono/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
166 changes: 166 additions & 0 deletions src/game_engine/unity/scene_manager/game_object.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
use super::{SceneManager, CSTR};
use crate::game_engine::unity::{il2cpp, mono};
use crate::string::ArrayCString;
use crate::{Address, Address32, Address64, Error, PointerSize, Process};
use core::array;
use core::mem::MaybeUninit;

/// Representing a GameObject. From a GameObject, you can get the attached components (includes the
/// C# scripts).
#[derive(Clone, Debug)]
pub struct GameObject {
pub(super) address: Address,
}

impl GameObject {
/// Get the name of the GameObject.
pub fn get_name<const N: usize>(
&self,
process: &Process,
scene_manager: &SceneManager,
) -> Result<ArrayCString<N>, Error> {
process.read_pointer_path(
self.address,
scene_manager.pointer_size,
&[scene_manager.offsets.game_object_name as u64, 0x0],
)
}

/// Traverse the classes associated with the Components attached to this game object.
pub fn classes<'a>(
&'a self,
process: &'a Process,
scene_manager: &'a SceneManager,
) -> Result<impl Iterator<Item = Address> + 'a, Error> {
let (number_of_components, component_pair_array): (usize, Address) =
match scene_manager.pointer_size {
PointerSize::Bit64 => {
let array = process
.read::<[Address64; 3]>(self.address + scene_manager.offsets.game_object)?;
(array[2].value() as usize, array[0].into())
}
_ => {
let array = process
.read::<[Address32; 3]>(self.address + scene_manager.offsets.game_object)?;
(array[2].value() as usize, array[0].into())
}
};

if number_of_components == 0 {
return Err(Error {});
}

const ARRAY_SIZE: usize = 128;

let components: [Address; ARRAY_SIZE] = match scene_manager.pointer_size {
PointerSize::Bit64 => {
let mut buf = [MaybeUninit::<[Address64; 2]>::uninit(); ARRAY_SIZE];
let slice = process.read_into_uninit_slice(
component_pair_array,
&mut buf[..number_of_components],
)?;

let mut iter = slice.iter_mut();
array::from_fn(|_| {
iter.next()
.map(|&mut [_, second]| second.into())
.unwrap_or_default()
})
}
_ => {
let mut buf = [MaybeUninit::<[Address32; 2]>::uninit(); ARRAY_SIZE];
let slice = process.read_into_uninit_slice(
component_pair_array,
&mut buf[..number_of_components],
)?;

let mut iter = slice.iter_mut();
array::from_fn(|_| {
iter.next()
.map(|&mut [_, second]| second.into())
.unwrap_or_default()
})
}
};

Ok((1..number_of_components).filter_map(move |m| {
process
.read_pointer(
components[m] + scene_manager.offsets.klass,
scene_manager.pointer_size,
)
.ok()
.filter(|val| !val.is_null())
}))
}

// TODO it's really dumb i have to split this by mono/il2cpp

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.

we really need to implement some sort of strategy pattern here. The amount of code duplication is getting ridiculous


/// Tries to find the base address of a class in the current `GameObject` by name.
///
/// Mono only.
pub fn get_class_mono(
&self,
process: &Process,
scene_manager: &SceneManager,
module: &mono::Module,
name: &str,
) -> Result<Address, Error> {
if scene_manager.is_il2cpp {
return Err(Error {});
}

self.classes(process, scene_manager)?
.find(|&addr| {
let val = mono::Class::get_from_component(process, module, addr)
.and_then(|c| c.get_name::<CSTR>(process, module));

val.is_ok_and(|class_name| class_name.matches(name))
})
.ok_or(Error {})
}

/// Tries to find the base address of a class in the current `GameObject` by name.
///
/// IL2CPP only.
pub fn get_class_il2cpp(
&self,
process: &Process,
scene_manager: &SceneManager,
module: &il2cpp::Module,
name: &str,
) -> Result<Address, Error> {
if !scene_manager.is_il2cpp {
return Err(Error {});
}

self.classes(process, scene_manager)?
.find(|&addr| {
let val = il2cpp::Class::get_from_component(process, module, addr)
.and_then(|c| c.get_name::<CSTR>(process, module));

val.is_ok_and(|class_name| class_name.matches(name))
})
.ok_or(Error {})
}

/// Returns whether the game object is considered "active" by the scene (if it or any of its
/// parents are inactive, then the game object is inactive)
pub fn is_active_in_hierarchy(
&self,
process: &Process,
scene_manager: &SceneManager,
) -> Result<bool, Error> {
process.read::<bool>(self.address + scene_manager.offsets.game_object_activeinhierarchy)
}

/// Returns whether the game object is considered "active" by itself (irrespective of any of its
/// parents)
pub fn is_active_in_self(
&self,
process: &Process,
scene_manager: &SceneManager,
) -> Result<bool, Error> {
process.read::<bool>(self.address + scene_manager.offsets.game_object_activeself)
}
}
80 changes: 0 additions & 80 deletions src/game_engine/unity/scene_manager/game_objects.rs

This file was deleted.

6 changes: 4 additions & 2 deletions src/game_engine/unity/scene_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ use crate::{
Address, Address32, Error, PointerSize, Process,
};

mod game_objects;

mod offsets;

mod transform;
pub use transform::Transform;

use offsets::Offsets;

mod game_object;
pub use game_object::GameObject;

mod scene;

pub use scene::Scene;

use super::{BinaryFormat, CSTR};
Expand Down
9 changes: 6 additions & 3 deletions src/game_engine/unity/scene_manager/offsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ pub(super) struct Offsets {
pub(super) root_storage_container: u8,
pub(super) game_object: u8,
pub(super) game_object_name: u8,
pub(super) game_object_activeself: u8,
pub(super) game_object_activeinhierarchy: u8,
pub(super) klass: u8,
pub(super) klass_name: u8,
pub(super) children_pointer: u8,
}

Expand All @@ -26,8 +27,9 @@ impl Offsets {
root_storage_container: 0xB0,
game_object: 0x30,
game_object_name: 0x60,
game_object_activeself: 0x5E,
game_object_activeinhierarchy: 0x5F,
klass: 0x28,
klass_name: 0x48,

@mitchell-merry mitchell-merry May 11, 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.

this changes depending on the mono version, which, of course it does.

Now we just store the offset to the object handle, and you have to use mono/il2cpp specific code to get the component

children_pointer: 0x70,
}),
PointerSize::Bit32 => Some(&Self {
Expand All @@ -39,8 +41,9 @@ impl Offsets {
root_storage_container: 0x88,
game_object: 0x1C,
game_object_name: 0x3C,
game_object_activeself: 0x32,
game_object_activeinhierarchy: 0x33,
klass: 0x18,
klass_name: 0x2C,
children_pointer: 0x50,
}),
_ => None,
Expand Down
Loading
Loading