Struct red4ext_rs::SdkEnv
source · pub struct SdkEnv { /* private fields */ }
Expand description
A handle to the RED4ext SDK environment.
This struct enables access to the SDK’s functions and logging facilities.
It can be obtained statically using the PluginOps::env
method from any plugin
implementation.
Implementations§
source§impl SdkEnv
impl SdkEnv
sourcepub fn info(&self, txt: impl Display)
pub fn info(&self, txt: impl Display)
Logs a message at the info level.
You should generally use the info!
macro instead of calling this method directly.
sourcepub fn warn(&self, txt: impl Display)
pub fn warn(&self, txt: impl Display)
Logs a message at the warn level.
You should generally use the warn!
macro instead of calling this method directly.
sourcepub fn error(&self, txt: impl Display)
pub fn error(&self, txt: impl Display)
Logs a message at the error level.
You should generally use the error!
macro instead of calling this method directly.
sourcepub fn debug(&self, txt: impl Display)
pub fn debug(&self, txt: impl Display)
Logs a message at the debug level.
You should generally use the debug!
macro instead of calling this method directly.
sourcepub fn trace(&self, txt: impl Display)
pub fn trace(&self, txt: impl Display)
Logs a message at the trace level.
You should generally use the trace!
macro instead of calling this method directly.
sourcepub fn add_listener(&self, typ: StateType, listener: StateListener) -> bool
pub fn add_listener(&self, typ: StateType, listener: StateListener) -> bool
Adds a listener to a specific state type.
The listener will be called when the state is entered, updated, or exited.
See StateType
for the available state types.
§Example
use red4ext_rs::{GameApp, SdkEnv, StateListener, StateType};
fn add_state_listener(env: &SdkEnv) {
let listener = StateListener::default()
.with_on_enter(on_enter)
.with_on_exit(on_exit);
env.add_listener(StateType::Running, listener);
}
unsafe extern "C" fn on_enter(app: &GameApp) {
// do something here...
}
unsafe extern "C" fn on_exit(app: &GameApp) {
// do something here...
}
sourcepub unsafe fn attach_hook<F1, A1, R1, F2, A2, R2>(
&self,
hook: *mut Hook<F1, F2>,
target: F1,
detour: F2,
) -> bool
pub unsafe fn attach_hook<F1, A1, R1, F2, A2, R2>( &self, hook: *mut Hook<F1, F2>, target: F1, detour: F2, ) -> bool
Attaches a hook to a target function. The hook will be called instead of the target function. The hook must accept a callback function as its last argument, which should be called to execute the original function.
§Safety
The target and detour functions must both be valid and compatible function pointers.
§Example
use red4ext_rs::{hooks, SdkEnv};
hooks! {
static ADD_HOOK: fn(a: u32, b: u32) -> u32;
}
fn attach_my_hook(env: &SdkEnv, addr: unsafe extern "C" fn(u32, u32) -> u32) {
unsafe { env.attach_hook(ADD_HOOK, addr, detour) };
}
unsafe extern "C" fn detour(a: u32, b: u32, cb: unsafe extern "C" fn(u32, u32) -> u32) -> u32 {
// do something here...
cb(a, b)
}
sourcepub unsafe fn detach_hook<F, A, R>(&self, target: F) -> boolwhere
F: FnPtr<A, R>,
pub unsafe fn detach_hook<F, A, R>(&self, target: F) -> boolwhere
F: FnPtr<A, R>,
Detaches a hook from a target function.