Skip to content

Commit

Permalink
Added support for Mednafen (PS1 emu) (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jujstme committed Dec 1, 2023
1 parent b23ec61 commit af5f3a5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/emulator/ps1/mednafen.rs
Original file line number Diff line number Diff line change
@@ -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<Address> {
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::<Address32>(ptr).ok()?.into())
}

pub const fn keep_alive(&self) -> bool {
true
}
}
7 changes: 6 additions & 1 deletion src/emulator/ps1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use bytemuck::CheckedBitPattern;

mod duckstation;
mod epsxe;
mod mednafen;
mod pcsx_redux;
mod psxfin;
mod retroarch;
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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)),
(
Expand All @@ -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)),
];

0 comments on commit af5f3a5

Please sign in to comment.