From af5f3a547f9f4a55dde35b1ce207f3ae50c9b7b6 Mon Sep 17 00:00:00 2001 From: Jujstme Date: Fri, 1 Dec 2023 17:28:38 +0100 Subject: [PATCH] Added support for Mednafen (PS1 emu) (#57) --- src/emulator/ps1/mednafen.rs | 30 ++++++++++++++++++++++++++++++ src/emulator/ps1/mod.rs | 7 ++++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/emulator/ps1/mednafen.rs diff --git a/src/emulator/ps1/mednafen.rs b/src/emulator/ps1/mednafen.rs new file mode 100644 index 0000000..9d351bb --- /dev/null +++ b/src/emulator/ps1/mednafen.rs @@ -0,0 +1,30 @@ +use crate::{file_format::pe, signature::Signature, Address, Address32, Process}; + +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +pub struct State; + +impl State { + pub fn find_ram(&self, game: &Process) -> Option
{ + const SIG_32: Signature<10> = Signature::new("89 01 0F B6 82 ?? ?? ?? ?? C3"); + const SIG_64: Signature<5> = Signature::new("89 01 0F B6 82"); + + let main_module_range = super::PROCESS_NAMES + .iter() + .filter(|(_, state)| matches!(state, super::State::Mednafen(_))) + .find_map(|(name, _)| game.get_module_range(name).ok())?; + + let is_64_bit = + pe::MachineType::read(game, main_module_range.0) == Some(pe::MachineType::X86_64); + + let ptr = match is_64_bit { + true => SIG_64.scan_process_range(game, main_module_range)?, + false => SIG_32.scan_process_range(game, main_module_range)?, + } + 0x5; + + Some(game.read::(ptr).ok()?.into()) + } + + pub const fn keep_alive(&self) -> bool { + true + } +} diff --git a/src/emulator/ps1/mod.rs b/src/emulator/ps1/mod.rs index 8a3f201..b63251d 100644 --- a/src/emulator/ps1/mod.rs +++ b/src/emulator/ps1/mod.rs @@ -5,6 +5,7 @@ use bytemuck::CheckedBitPattern; mod duckstation; mod epsxe; +mod mednafen; mod pcsx_redux; mod psxfin; mod retroarch; @@ -63,6 +64,7 @@ impl Emulator { State::Retroarch(x) => x.find_ram(&self.process), State::PcsxRedux(x) => x.find_ram(&self.process), State::Xebra(x) => x.find_ram(&self.process), + State::Mednafen(x) => x.find_ram(&self.process), } { None => return false, something => something, @@ -76,6 +78,7 @@ impl Emulator { State::Retroarch(x) => x.keep_alive(&self.process), State::PcsxRedux(x) => x.keep_alive(&self.process), State::Xebra(x) => x.keep_alive(), + State::Mednafen(x) => x.keep_alive(), }; if success { @@ -122,9 +125,10 @@ enum State { Retroarch(retroarch::State), PcsxRedux(pcsx_redux::State), Xebra(xebra::State), + Mednafen(mednafen::State), } -const PROCESS_NAMES: [(&str, State); 7] = [ +const PROCESS_NAMES: [(&str, State); 8] = [ ("ePSXe.exe", State::Epsxe(epsxe::State)), ("psxfin.exe", State::PsxFin(psxfin::State)), ( @@ -141,4 +145,5 @@ const PROCESS_NAMES: [(&str, State); 7] = [ State::PcsxRedux(pcsx_redux::State::new()), ), ("XEBRA.EXE", State::Xebra(xebra::State)), + ("mednafen.exe", State::Mednafen(mednafen::State)), ];