pub fn enable_hook(original: *const ()) -> Result<(), Error>
Expand description
Enables a previously added hook, replacing the original function with the new one.
§Errors
This function returns a retour::Error
if:
- Enabling the hook fails.
§Example
use commonlibsse_ng::skse::trampoline::{add_hook, remove_hook, enable_hook};
use retour::Error;
fn add5(val: i32) -> i32 {
val + 5
}
fn add10(val: i32) -> i32 {
val + 10
}
let original = add5 as *const ();
let replacement = add10 as *const ();
// Initially, the behavior is to add 5
assert_eq!(add5(5), 10);
// Add a hook to replace `add5` with `add10`
unsafe { add_hook(original, replacement) }.unwrap();
assert_eq!(add5(5), 15);
assert!(enable_hook(original).is_ok());
assert_eq!(add5(5), 15);