mhgu-forge 1.4.0

Rust API for writing forge plugins for MHGU
Documentation
/// Installs a hook generated by `#[forge::hook]`.
///
/// The first argument is the base address (e.g. from `forge::mem::text_addr()`),
/// and the second is the hook module created by `#[forge::hook]`. The macro
/// adds the hook's `OFFSET` constant to the base to compute the final target.
///
/// An optional third argument passes a context pointer that can be retrieved
/// inside the hook body with `context!()` or `context!(T)`.
///
/// # Examples
/// ```ignore
/// // No context
/// forge::install_hook!(forge::mem::text_addr(), my_hook);
///
/// // With context
/// let mut num: u32 = 3;
/// forge::install_hook!(forge::mem::text_addr(), my_hook, &mut num);
/// ```
/// Note: `num` MUST outlive the hook
#[macro_export]
macro_rules! install_hook {
    ($base:expr, $hook:ident) => {
        unsafe { $hook::__install($base as u32) }
    };
    ($base:expr, $hook:ident, $ctx:expr) => {
        unsafe {
            let __ctx = $ctx;
            $hook::__install_with_ctx($base as u32, __ctx as *const _ as *const ::core::ffi::c_void)
        }
    };
}

/// Updates the context for an already-installed hook.
///
/// # Example
/// ```ignore
/// forge::update_hook_ctx!(my_hook, &mut new_value);
/// ```
#[macro_export]
macro_rules! update_hook_ctx {
    ($hook:ident, $ctx:expr) => {
        unsafe {
            let __ctx = $ctx;
            $hook::__update_ctx(__ctx as *const _ as *const ::core::ffi::c_void)
        }
    };
}