macro_rules! generate_offset_getter {
(
$( $fn_name:ident : $ret_ty:ty = $read_fn:ident ( $offset:expr , $get_base:ident ); )*
) => { ... };
}Expand description
Generates offset-based getter functions for memory access.
This macro creates functions that read data from specific memory offsets using a base address getter function.
§Syntax
generate_offset_getter! {
function_name: return_type = read_method(offset, base_getter);
another_function: another_type = another_read_method(another_offset, another_base);
}§Arguments
Each getter definition consists of:
function_name- Name of the generated functionreturn_type- Rust type to returnread_method- Memory reading method to useoffset- Memory offset from base addressbase_getter- Function that returns the base address (most of the time from generate_reader_fn)
§Examples
generate_offset_getter! {
score: i32 = read_i32(0x10, score_base),
combo: i16 = read_i16(0x14, score_base),
username: String = read_string(0x20, score_base),
hp: f64 = read_f64(0x30, hp_base),
}
// Generates functions like:
// pub fn score(p: &Process, state: &mut State) -> Result<i32, Error> {
// Ok(<i32>::from(read_i32(p, state, 0x10, score_base)?))
// }§Generated Functions
Each definition generates a function with signature:
pub fn function_name(p: &Process, state: &mut State) -> Result<return_type, Error>§Memory Safety
The generated functions assume the offsets are valid and the base address getter returns a valid memory address.