wafel_api

Struct Emu

Source
pub struct Emu {
    pub layout: MemoryLayoutImpl<EmptySymbolLookup>,
    pub memory: EmuMemory,
}
Expand description

An SM64 API that attaches to a running emulator and can read/write to its memory.

§Example

use wafel_api::{Emu, SM64Version};

let pid = 4232;
let base_address = 0x0050B110;

let mut emu = Emu::attach(pid, base_address, SM64Version::US);

loop {
    let holding_l =
        (emu.read("gControllerPads[0].button").as_int() & emu.constant("L_TRIG").as_int()) != 0;

    if holding_l && emu.read("gMarioState.action") != emu.constant("ACT_FREEFALL") {
        emu.write("gMarioState.action", emu.constant("ACT_FREEFALL"));
        emu.write("gMarioState.vel[1]", 50.0.into());
    }
}

Fields§

§layout: MemoryLayoutImpl<EmptySymbolLookup>§memory: EmuMemory

Implementations§

Source§

impl Emu

Source

pub fn attach(pid: u32, base_address: usize, sm64_version: SM64Version) -> Self

Attach to a running emulator.

§Panics

Panics if attachment fails, probably because there is no running process with the given PID.

Source

pub fn try_attach( pid: u32, base_address: usize, sm64_version: SM64Version, ) -> Result<Self, Error>

Attach to a running emulator.

Returns an error if attachment fails, probably because there is no running process with the given PID.

Source

pub fn is_process_open(&self) -> bool

Return true if a process with the given pid is currently open.

If the process is closed, then reads and writes on this memory object will fail. Once this method returns false, you should avoid using this Emu again since a new process may eventually open with the same pid.

Note that a process may close immediately after calling this method, so failed reads/writes must be handled regardless.

Source

pub fn read(&self, path: &str) -> Value

Read a value from memory.

See the crate documentation for the path syntax.

§Panics

Panics if the path fails to compile or reading from memory fails.

Source

pub fn try_read(&self, path: &str) -> Result<Value, Error>

Read a value from memory.

See the crate documentation for the path syntax.

Returns an error if the path fails to compile or reading from memory fails.

Source

pub fn read_string_at(&self, address: Address) -> Vec<u8>

Read a null terminated string from memory at the given address.

§Panics

Panics if reading from memory fails.

Source

pub fn try_read_string_at(&self, address: Address) -> Result<Vec<u8>, Error>

Read a null terminated string from memory at the given address.

Returns an error if reading from memory fails.

Source

pub fn address(&self, path: &str) -> Option<Address>

Find the address of a path.

This method returns None if ? is used in the path and the expression before ? evaluates to a null pointer.

See the crate documentation for the path syntax.

§Panics

Panics if the path fails to compile or reading from memory fails.

Source

pub fn try_address(&self, path: &str) -> Result<Option<Address>, Error>

Find the address of a path.

This method returns None if ? is used in the path and the expression before ? evaluates to a null pointer.

See the crate documentation for the path syntax.

Returns an error if the path fails to compile or reading from memory fails.

Source

pub fn address_to_symbol(&self, address: Address) -> Option<String>

Return the name of the global variable at the given address.

Returns None if no global variable is at the address.

Source

pub fn data_type(&self, path: &str) -> DataType

Return a simplified description of the type of the given variable.

See the crate documentation for the path syntax.

§Panics

Panics if the path fails to compile or type resolution fails.

Source

pub fn try_data_type(&self, path: &str) -> Result<DataType, Error>

Return a simplified description of the type of the given variable.

See the crate documentation for the path syntax.

§Panics

Panics if the path fails to compile or type resolution fails.

Source

pub fn write(&mut self, path: &str, value: Value)

Write a value to memory.

See the crate documentation for the path syntax.

§Panics

Panics if the data path fails to compile or the write fails.

Source

pub fn try_write(&mut self, path: &str, value: Value) -> Result<(), Error>

Write a value to memory.

See the crate documentation for the path syntax.

Returns an error if the data path fails to compile or the write fails.

Source

pub fn constant(&self, name: &str) -> Value

Return the value of the macro constant or enum variant with the given name.

§Panics

Panics if the constant doesn’t exist. Unless the name has a typo, it is likely that either Wafel is out of date or it is just a limitation of how Wafel obtains constants from the source.

Source

pub fn try_constant(&self, name: &str) -> Result<Value, Error>

Return the value of the macro constant or enum variant with the given name.

Returns an error if the constant doesn’t exist. Unless the name has a typo, it is likely that either Wafel is out of date or it is just a limitation of how Wafel obtains constants from the source.

Source

pub fn render(&self, config: &VizConfig) -> VizScene

Render the game to a VizScene object, which can be displayed using [wafel_viz].

§Panics

Panics if rendering fails (most likely a bug in [wafel_viz]).

Source

pub fn try_render(&self, config: &VizConfig) -> Result<VizScene, Error>

Render the game to a VizScene object, which can be displayed using [wafel_viz].

Returns an error if rendering fails (most likely a bug in [wafel_viz]).

Source

pub fn mario_action_names(&self) -> HashMap<u32, String>

Return a mapping from Mario action values to their name (e.g. ACT_IDLE).

Source

pub fn surfaces(&self) -> Vec<Surface>

Read the currently loaded surfaces.

§Panics

Panics if the read fails.

Source

pub fn try_surfaces(&self) -> Result<Vec<Surface>, Error>

Read the currently loaded surfaces.

Returns an error if the read fails.

Source

pub fn object_hitboxes(&self) -> Vec<ObjectHitbox>

Read the hitboxes for active objects.

§Panics

Panics if the read fails.

Source

pub fn try_object_hitboxes(&self) -> Result<Vec<ObjectHitbox>, Error>

Read the hitboxes for active objects.

Returns an error if the read fails.

Trait Implementations§

Source§

impl Debug for Emu

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Emu

§

impl RefUnwindSafe for Emu

§

impl Send for Emu

§

impl Sync for Emu

§

impl Unpin for Emu

§

impl UnwindSafe for Emu

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,