-
Notifications
You must be signed in to change notification settings - Fork 12
Refactor SceneManager / Transform; fix a number of bugs in scene/game object traversal #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mitchell-merry
wants to merge
7
commits into
LiveSplit:master
Choose a base branch
from
mitchell-merry:transform-refactor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6c56fed
Separate the concept of Transform and GameObject; separate the concep…
mitchell-merry 958fbd8
Add isSelf function, add / update more comments
mitchell-merry f575ae4
Create get_class_mono/il2cpp which should fix the klass_name discrepa…
mitchell-merry 0152784
come on now
mitchell-merry 25d397b
remove todo comments
mitchell-merry d078723
tweak
mitchell-merry c974ef2
Revert changes for scene name and path as string
mitchell-merry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| 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()) | ||
| })) | ||
| } | ||
|
|
||
| /// 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_self( | ||
| &self, | ||
| process: &Process, | ||
| scene_manager: &SceneManager, | ||
| ) -> Result<bool, Error> { | ||
| process.read::<bool>(self.address + scene_manager.offsets.game_object_activeself) | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
| } | ||
|
|
||
|
|
@@ -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, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this changes depending on the mono version, which, of course it does. Code updated to use the mono/il2cpp class name offsets |
||
| children_pointer: 0x70, | ||
| }), | ||
| PointerSize::Bit32 => Some(&Self { | ||
|
|
@@ -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, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.