asr/emulator/sms/
blastem.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::{runtime::MemoryRangeFlags, 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: Signature<15> = Signature::new("66 81 E1 FF 1F 0F B7 C9 8A 89 ?? ?? ?? ?? C3");

        let scanned_address = game
            .memory_ranges()
            .filter(|m| {
                m.flags()
                    .unwrap_or_default()
                    .contains(MemoryRangeFlags::WRITE)
                    && m.size().unwrap_or_default() == 0x101000
            })
            .find_map(|m| SIG.scan_process_range(game, m.range().ok()?))?
            + 10;

        let wram: Address = game.read::<Address32>(scanned_address).ok()?.into();

        if wram.is_null() {
            None
        } else {
            Some(wram)
        }
    }

    pub const fn keep_alive(&self) -> bool {
        true
    }
}