Skip to content

Commit 0856aa7

Browse files
committed
Fix SceneManager base_address vs address
1 parent 80cc89a commit 0856aa7

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/game_engine/unity/scene.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl SceneManager {
9191
let is_64_bit = macho::is_64_bit(process, macho::scan_macho_page(process, unity_player)?)?;
9292
let is_il2cpp = false;
9393

94-
let address = if is_64_bit {
94+
let base_address: Address = if is_64_bit {
9595
// RIP-relative addressing
9696
// 7 is the offset to the ???????? question marks in the signature
9797
let addr = SIG_64_BIT_DYLIB.scan_process_range(process, unity_player)? + 7;
@@ -103,12 +103,23 @@ impl SceneManager {
103103

104104
let offsets = Offsets::new(is_64_bit);
105105

106-
Some(Self {
107-
is_64_bit,
108-
is_il2cpp,
109-
address,
110-
offsets,
111-
})
106+
// Dereferencing one level because this pointer never changes as long as the game is open.
107+
// It might not seem a lot, but it helps make things a bit faster when querying for scene stuff.
108+
let address: Address = match is_64_bit {
109+
true => process.read::<Address64>(base_address).ok()?.into(),
110+
false => process.read::<Address32>(base_address).ok()?.into(),
111+
};
112+
113+
if address.is_null() {
114+
None
115+
} else {
116+
Some(Self {
117+
is_64_bit,
118+
is_il2cpp,
119+
address,
120+
offsets,
121+
})
122+
}
112123
}
113124

114125
/// Attaches to the scene manager in the given process.

0 commit comments

Comments
 (0)