Skip to content
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

[BUGFIX] Added new sigscan for DuckStation (PS1 emu) #65

Merged
merged 4 commits into from
Oct 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/emulator/ps1/duckstation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{signature::Signature, Address, Address64, Process};
use crate::{file_format::pe, signature::Signature, Address, Address64, Process};

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct State {
Expand All @@ -14,12 +14,21 @@ impl State {
.filter(|(_, state)| matches!(state, super::State::Duckstation(_)))
.find_map(|(name, _)| game.get_module_range(name).ok())?;

let addr: Address = SIG.scan_process_range(game, main_module_range)? + 3;

self.addr = addr + 0x4 + game.read::<i32>(addr).ok()?;
// Recent Duckstation releases include a debug symbol that can be used to easily retrieve the address of the emulated RAM
// Info: https://github.com/stenzek/duckstation/commit/c98e0bd0969abdd82589bfc565aea52119fd0f19
if let Some(debug_symbol) = pe::symbols(game, main_module_range.0).find(|symbol| {
symbol
.get_name::<4>(game)
.is_ok_and(|name| name.matches(b"RAM"))
}) {
self.addr = debug_symbol.address;
} else {
// For older versions of Duckstation, we fall back to regular sigscanning
let addr = SIG.scan_process_range(game, main_module_range)? + 3;
self.addr = addr + 0x4 + game.read::<i32>(addr).ok()?;
}

let ram = game.read::<Address64>(self.addr).ok()?;
Some(ram.into())
Some(game.read::<Address64>(self.addr).ok()?.into())
}

pub fn keep_alive(&self, game: &Process, wram_base: &mut Option<Address>) -> bool {
Expand Down