pub fn remove_hook(original: *const ()) -> Result<(), Error>
Expand description
Removes a previously added hook by disabling the trampoline and restoring the original function.
§Errors
This function returns a retour::Error
if:
- Disabling the hook fails.
§Example
use commonlibsse_ng::skse::trampoline::{add_hook, remove_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 ();
// Verify the original behavior
assert_eq!(add5(5), 10);
// Replace the original function with the new one
unsafe { add_hook(original, replacement) }.unwrap();
assert_eq!(add5(5), 15); // Initially, the behavior is to add5 to add10
// Remove the hook (if added previously)
remove_hook(original).unwrap();
assert_eq!(add5(5), 10);