Skip to content

Commit

Permalink
Fix SceneManager base_address vs address
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKnauth committed Oct 17, 2023
1 parent 80cc89a commit 0856aa7
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/game_engine/unity/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::<Address64>(base_address).ok()?.into(),
false => process.read::<Address32>(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.
Expand Down

0 comments on commit 0856aa7

Please sign in to comment.