The Mod trait¶
A Rust mod is a type that implements oxidizer_api::Mod, registered with oxidizer_mod!:
use oxidizer_api::Mod;
struct MyMod { /* your state */ }
impl Mod for MyMod {
fn init() -> Self { MyMod {} } // once, before the game's Main: nothing loaded yet
fn loaded(&mut self) {} // once the game has loaded its content and mods (0.5+)
fn frame(&mut self, player_time: f64, dt: f64) {} // every frame
fn gui(&mut self, dt: f64) {} // every frame, inside the ImGui frame: draw windows
fn menu(&mut self) {} // while the game's Mods menu is open
fn unload(&mut self) {} // when the game closes
}
oxidizer_api::oxidizer_mod!(MyMod);
Only init is required. init runs before the game's Main, so the game hasn't loaded any data yet: do setup that needs the game's parts, systems or mods in loaded (oxidizer_api 0.5, Oxidizer 0.8). No flight exists at loaded either; the controlled vehicle comes later, so check for it in frame. Your state lives in the struct; every callback gets &mut self.
oxidizer_mod! exports the functions Oxidizer looks for in the library. It also catches panics: a panic in a callback is logged ("mod panicked in gui") instead of taking the game down, and the next callback runs as usual.
State that hooks need¶
Hooks run inside the game's own calls, not in your callbacks, so they don't get &mut self. Keep what they need in statics, such as atomics or a Mutex, and update it from frame. Flight Panel's warp_guard.rs is a complete example.