Skip to main content

Crate ghook_sdk

Crate ghook_sdk 

Source
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§

DependencyResolver
Resolves mod load order based on dependency metadata.
ExtensionRegistry
Registry for game-provided API extensions.
HookContext
Context passed to every hook callback via FFI.
HookInfo
Information about a hookable function, extracted from a game binary.
HookManager
Manages hook registrations and dispatch.
HostApi
The interface provided by the game to mods.
LoadedMod
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§

DependencyError
Errors that can occur during dependency resolution.
HookControl
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.