pub struct FunctionHook<F: FnPtr> { /* private fields */ }Expand description
A function hook, call redirect or import replacement, and the rest of its
chain. It lives in a static, so the detour (a plain function the game
calls) reaches next, and Anvil can write next into it before the change
is enabled:
ⓘ
static SPEED_OBJECT: anvil::FunctionHook<sym::SpeedObjectFn> = anvil::FunctionHook::new();
unsafe extern "C" fn on_speed_object(session: *mut c_void) -> *mut c_void {
let Some(next) = SPEED_OBJECT.next() else { return std::ptr::null_mut() };
// SAFETY: the game's own function, called as it declares.
unsafe { next(session) }
}A detour is called by the game directly, with no adapter between: it must
not panic (a panic out of an extern "C" function aborts the process).
Wrap fallible work in catch_panic.
Implementations§
Source§impl<F: FnPtr> FunctionHook<F>
impl<F: FnPtr> FunctionHook<F>
Sourcepub fn next(&self) -> Option<F>
pub fn next(&self) -> Option<F>
The rest of the chain: the next plugin’s detour or the game’s code;
None before Anvil wrote it. It stays valid after the change is
removed, for a thread still inside the detour.
Trait Implementations§
Source§impl<F: FnPtr> Debug for FunctionHook<F>
impl<F: FnPtr> Debug for FunctionHook<F>
Auto Trait Implementations§
impl<F> !Freeze for FunctionHook<F>
impl<F> Forget for FunctionHook<F>
impl<F> Move for FunctionHook<F>
impl<F> RefUnwindSafe for FunctionHook<F>where
PhantomData<F>: RefUnwindSafe,
impl<F> Send for FunctionHook<F>where
PhantomData<F>: Send,
impl<F> Sync for FunctionHook<F>where
PhantomData<F>: Sync,
impl<F> Unpin for FunctionHook<F>where
PhantomData<F>: Unpin,
impl<F> UnsafeUnpin for FunctionHook<F>where
PhantomData<F>: UnsafeUnpin,
impl<F> UnwindSafe for FunctionHook<F>where
PhantomData<F>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more