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

Added support for Mednafen (PS1 emu) #57

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
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
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)),
];
Loading