Expand description
§ghook-sdk
Core SDK for the ghook modding framework.
This crate provides the runtime infrastructure for native Rust modding:
- Hook Manager – dispatches prefix, postfix, and replace hooks with panic isolation
- Mod Loader – scans directories, resolves dependencies, loads mods in correct order
- Dependency Resolver – topological sorting, cycle detection, conflict checking
- Host API – extensible interface between game and mods via extension registry
- Safety – segfault handler, panic catching, safe FFI boundaries
§Overview
ghook implements an Inversion of Control (IoC) and Aspect-Oriented Programming (AOP)
system for Rust games. The game marks functions as hookable with #[hookable], and
mods intercept them with #[prefix], #[postfix], or #[replace].
§Quick Start
use ghook_sdk::*;
fn main() {
let host_api = create_host_api();
let mut loader = ModLoader::new();
loader.load_all_mods("./mods", &host_api).unwrap();
}§Feature Flags
This crate has no feature flags. All functionality is included by default.
§Safety
This crate uses unsafe internally for FFI operations. All unsafe blocks are
documented and justified. Public APIs are safe to call.
§License
Licensed under the Mozilla Public License 2.0.
§Author
Semyon Tsarev
Macros§
- declare_
args - Declares FFI-compatible argument structures for hooks.
- use_
game_ hooks - Reads a game binary and auto-generates hook argument/result types.
Structs§
- Dependency
Resolver - Resolves mod load order based on dependency metadata.
- Extension
Registry - Registry for game-provided API extensions.
- Hook
Context - Context passed to every hook callback via FFI.
- Hook
Info - Information about a hookable function, extracted from a game binary.
- Hook
Manager - Manages hook registrations and dispatch.
- HostApi
- The interface provided by the game to mods.
- Loaded
Mod - A loaded mod with its manifest and library handle.
- ModInfo
- Metadata about a mod, stored in a dedicated binary section.
- ModLoader
- Full-featured mod loader with dependency resolution and lifecycle management.
- ModManifest
- Parsed manifest of a mod, derived from
ModInfo.
Enums§
- Dependency
Error - Errors that can occur during dependency resolution.
- Hook
Control - Control flow signal returned by prefix and postfix hooks.
Functions§
- create_
host_ api - Creates the host API that is passed to mods during initialization.
- get_
hook_ manager - Returns a reference to the global hook manager.
- hash_
string - Computes an FNV-1a hash of a string at runtime.
- hash_
string_ const - Computes an FNV-1a hash of a string at compile time.
- install_
segfault_ handler - Installs a SIGSEGV/SIGBUS handler that prints a diagnostic and aborts.
- read_
hooks_ info - Reads hook metadata from a game binary’s
.hooks_info.*sections. - register_
extension - Registers a game-provided API extension.
- validate_
game_ binary - Validates a game binary and returns the list of available hook names.
Attribute Macros§
- hookable
- Marks a function as hookable by mods.
- mod_
info - Embeds mod metadata into a dedicated binary section.
- mod_
init - Marks a function as the mod’s initialization entry point.
- postfix
- Defines a postfix hook that runs after the original function.
- prefix
- Defines a prefix hook that runs before the original function.
- replace
- Defines a replace hook that completely substitutes the original function.