Refactor SceneManager / Transform; fix a number of bugs in scene/game object traversal#133
Refactor SceneManager / Transform; fix a number of bugs in scene/game object traversal#133mitchell-merry wants to merge 7 commits into
Conversation
…t of SceneManager and Scene
…ncy - by just shelling out to the Mono/il2cpp class code
|
|
||
| impl Class { | ||
| pub(super) fn get_name<const N: usize>( | ||
| pub fn get_from_component( |
There was a problem hiding this comment.
"component" isn't accurate here, but there's something in between the component and the class. not exactly sure what it is.
| })) | ||
| } | ||
|
|
||
| // TODO it's really dumb i have to split this by mono/il2cpp |
There was a problem hiding this comment.
we really need to implement some sort of strategy pattern here. The amount of code duplication is getting ridiculous
| game_object_activeself: 0x5E, | ||
| game_object_activeinhierarchy: 0x5F, | ||
| klass: 0x28, | ||
| klass_name: 0x48, |
There was a problem hiding this comment.
this changes depending on the mono version, which, of course it does.
Code updated to use the mono/il2cpp class name offsets
| /// (and so on), as well as a list of `Component`s, which are classes (eg. | ||
| /// `MonoBehaviour`) containing data we might want to retrieve for the auto | ||
| /// splitter logic. | ||
| fn root_game_objects<'a>( |
There was a problem hiding this comment.
This makes more conceptual sense to live on the Scene rather than the SceneManager
|
|
||
| /// Tries to find the specified root [`Transform`] from the | ||
| /// `DontDestroyOnLoad` Unity scene. | ||
| pub fn get_game_object_from_dont_destroy_on_load( |
There was a problem hiding this comment.
no replacement for this - get the DDoL scene from SceneManager, then call get_root_game_object as with any other Scene
|
|
||
| iter::from_fn(move || { | ||
| // TODO check if this is correct on other games | ||
| let [_prev, next, current]: [Address; 3] = match scene_manager.pointer_size { |
There was a problem hiding this comment.
note: there's a change here, previously we were using [first, _, third] where first was our next element.
That's wrong: https://gist.github.com/just-ero/92457b51baf85bd1e5b8c87de8c9835e#file-list-hpp it actually causes us to go in the reverse order in the list. That caused me some issues in Cuphead
| } | ||
|
|
||
| /// Returns the full path to the [scene](Scene), as a [String](alloc::string::String). | ||
| pub fn path_as_string( |
There was a problem hiding this comment.
just realised this is already in #127, I'll take it out of this one when I get the chance
Another one of the changes I made to asr that I need to upstream...
Why?
I'm now more and more often traversing the gameobject tree in my autosplitters. This has culminated in being able to get a field on a component of a gameobject in a scene: https://github.com/mitchell-merry/autosplitters-wasm/blob/94fbcef38134317b3a5bd7e549a483f18bed17c4/cuphead/src/memory.rs#L170 which does wonders for what's possible.
I have been maintaining a fork with a bunch of tweaks to asr to make this possible, and it's about time I upstream some of it.
get_game_object_from_dont_destroy_on_loaddoesn't really make sense as a specific function, since we can already get the DDoL scene + game objects on arbitrary scenesWhat?
root_game_objects,get_root_game_objectget_game_object_from_dont_destroy_on_load(replacement is to get the DDoL scene then callget_root_game_object, like any other scene)Scene#root_game_objectsnow readsnextinstead ofprev, so the objects are read in the correct orderTransform#find_transformwhich traverses the game object tree for you via a path of game object namesTransformintoGameObject&TransformTransform#get_namelogic toGameObject#get_name, addTransform#get_game_objecttoTransformand makeTransform#get_nameuse the above twoTransform#classesandTransform#get_classtoGameObjectTransform#get_classsplit intoGameObject#get_class_monoandGameObject#get_class_il2cppsince the offset ofklass.namedepends on the mono version / il2cpp version, same way as it does in the regular path dereferencing codeGameObject#is_active_in_hierarchyandGameObject#is_active_self, which are self-explanatoryTesting
TODO: