Skip to main content

Crate oxidizer_api

Crate oxidizer_api 

Source
Expand description

API for KSA Rust mods. Game objects are opaque .NET GC handles wrapped in Obj; members are reached by name through reflection in the C# bridge.

ⓘ
struct MyMod;
impl oxidizer_api::Mod for MyMod { fn init() -> Self { oxidizer_api::log("hi"); MyMod } }
oxidizer_api::oxidizer_mod!(MyMod);

Modules§

bind
Runtime for typed bindings generated by oxidizer --bindgen ksa.rs.
imgui
Direct calls into KSA’s own ImGui library (its plain C exports, the ones the game itself calls), so mods share the game’s ImGui context. Only valid inside Mod::gui (and the menu functions inside Mod::menu). Like Dear ImGui: always call end after begin, and end_child after begin_child.

Macros§

oxidizer_mod
Exports the C entry points the loader looks for.

Structs§

Api
Function table shared by loader, bridge and mods. Field order must match bridge/Bridge.cs.
ModStatus
One Oxidizer mod, as Mods > Oxidizer shows it.
Obj
Owned reference to a .NET object (freed on drop).

Constants§

API_VERSION
ABI version of Api and the mod exports. Bump when the table grows or changes; the loader runs mods built for its version or an older one, and refuses newer ones. Version 2 added hook results, keys, typed-binding calls and 64-bit integers. Version 3 added reading the log and mod status, and running Rhai code. Version 4 added Mod::loaded.

Traits§

Mod
Implement and register with oxidizer_mod!.

Functions§

api
config_path
Where a mod keeps its settings: <game documents>/oxidizer/<mod_id>.toml (its folder is created). It lives outside the mod folder so updating the mod doesn’t lose it; read and write it with your own TOML code.
hook
Patch with a plain fn(instance, args) -> run_original. Return value is ignored for postfixes.
hook_result
Inside a hook: the hooked method’s return value (null for void methods or outside a hook). In a prefix it is the default until something sets it.
key_down
True while key is held down.
key_pressed
True on the frame key was pressed. Key names are the game’s (GLFW) names, e.g. “F5”, “K”, “Space”. Keys typed into text fields or the console don’t count.
log
log_lines
Oxidizer’s log (what Mods > Oxidizer shows) from line number from on. Only the last few hundred lines are kept, so older ones are gone.
log_next
Number the next line of Oxidizer’s log will get. Lines are numbered from 0 as they are logged; keep this to read only what is new with log_lines.
mod_statuses
mods_dir
The game’s mods folder, <game documents>/mods, where every mod has its folder.
patch
Harmony-patch ty.method with a raw callback. See HookFn.
read_string
Read a UTF-8 string out of a bridge “fill buffer, return length” call.
rhai_eval
Runs Rhai code in Oxidizer’s script engine, with the game access Rhai mods have, and returns its value as text (empty for ()), or the error. Variables persist between calls, like a console.
set_hook_result
Inside a hook: replace the hooked method’s return value (converted to its return type). From a prefix, combine with returning false to skip the original and return this value.

Type Aliases§

Handle
.NET GCHandle. 0 = null.
HookFn
Hook callback: (user data, instance or 0 for static methods, object[] of args) -> 0 to skip the original (prefix only). The callback owns both handles (wrap with Obj::from_handle).