diff --git a/src/game_engine/unity/scene.rs b/src/game_engine/unity/scene.rs index 4c2c6c9..405310e 100644 --- a/src/game_engine/unity/scene.rs +++ b/src/game_engine/unity/scene.rs @@ -91,7 +91,7 @@ impl SceneManager { let is_64_bit = macho::is_64_bit(process, macho::scan_macho_page(process, unity_player)?)?; let is_il2cpp = false; - let address = if is_64_bit { + let base_address: Address = if is_64_bit { // RIP-relative addressing // 7 is the offset to the ???????? question marks in the signature let addr = SIG_64_BIT_DYLIB.scan_process_range(process, unity_player)? + 7; @@ -103,12 +103,23 @@ impl SceneManager { let offsets = Offsets::new(is_64_bit); - Some(Self { - is_64_bit, - is_il2cpp, - address, - offsets, - }) + // Dereferencing one level because this pointer never changes as long as the game is open. + // It might not seem a lot, but it helps make things a bit faster when querying for scene stuff. + let address: Address = match is_64_bit { + true => process.read::(base_address).ok()?.into(), + false => process.read::(base_address).ok()?.into(), + }; + + if address.is_null() { + None + } else { + Some(Self { + is_64_bit, + is_il2cpp, + address, + offsets, + }) + } } /// Attaches to the scene manager in the given process.