#![doc(html_logo_url = "https://github.com/SemyonTs/ghook/raw/main/logo.png")]
#![doc(html_favicon_url = "https://github.com/SemyonTs/ghook/raw/main/favicon.ico")]
use std::collections::HashMap;
use std::ffi::c_void;
use std::sync::{OnceLock, RwLock};
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::path::Path;
pub use ghook_macros::{hookable, mod_info, prefix, postfix, replace, mod_init};
pub use ghook_macros::use_game_hooks;
#[macro_export]
macro_rules! declare_args {
($($name:ident { $($field:ident: $ty:ty),* $(,)? }),* $(,)?) => {
$(
#[repr(C)]
pub struct $name {
$(pub $field: $ty,)*
}
)*
};
}
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HookControl {
Continue = 0,
SkipOriginal = 1,
Abort = 2,
}
#[repr(C)]
pub struct HookContext {
pub mod_id: *const u8,
pub mod_id_len: usize,
}
#[repr(C)]
pub struct ModInfo {
pub magic: [u8; 8],
pub api_version: u32,
pub id_ptr: *const u8,
pub id_len: usize,
pub version_ptr: *const u8,
pub version_len: usize,
pub requires_ptr: *const u8,
pub requires_len: usize,
pub load_after_ptr: *const u8,
pub load_after_len: usize,
pub load_before_ptr: *const u8,
pub load_before_len: usize,
pub incompatible_with_ptr: *const u8,
pub incompatible_with_len: usize,
}
unsafe impl Sync for ModInfo {}
unsafe impl Send for ModInfo {}
impl ModInfo {
fn read_str(ptr: *const u8, len: usize) -> String {
if ptr.is_null() || len == 0 {
return String::new();
}
unsafe {
let slice = std::slice::from_raw_parts(ptr, len);
std::str::from_utf8_unchecked(slice).to_string()
}
}
pub fn id(&self) -> String {
Self::read_str(self.id_ptr, self.id_len)
}
pub fn version(&self) -> String {
Self::read_str(self.version_ptr, self.version_len)
}
pub fn requires(&self) -> Vec<String> {
Self::read_str(self.requires_ptr, self.requires_len)
.split(',')
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.collect()
}
pub fn load_after(&self) -> Vec<String> {
Self::read_str(self.load_after_ptr, self.load_after_len)
.split(',')
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.collect()
}
pub fn load_before(&self) -> Vec<String> {
Self::read_str(self.load_before_ptr, self.load_before_len)
.split(',')
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.collect()
}
pub fn incompatible_with(&self) -> Vec<String> {
Self::read_str(self.incompatible_with_ptr, self.incompatible_with_len)
.split(',')
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.collect()
}
}
#[derive(Debug, Clone)]
pub struct ModManifest {
pub id: String,
pub version: String,
pub requires: Vec<String>,
pub load_after: Vec<String>,
pub load_before: Vec<String>,
pub incompatible_with: Vec<String>,
pub path: String,
}
impl From<&ModInfo> for ModManifest {
fn from(info: &ModInfo) -> Self {
Self {
id: info.id(),
version: info.version(),
requires: info.requires(),
load_after: info.load_after(),
load_before: info.load_before(),
incompatible_with: info.incompatible_with(),
path: String::new(),
}
}
}
#[repr(C)]
pub struct HostApi {
pub api_version: u32,
pub register_hook: extern "C" fn(
target_hash: u64,
kind: u8,
priority: i32,
callback: *const c_void,
) -> u64,
pub log: extern "C" fn(level: u8, msg_ptr: *const u8, msg_len: usize),
pub get_extension: extern "C" fn(name_ptr: *const u8, name_len: usize) -> *const c_void,
}
impl HostApi {
#[inline]
fn log_raw(&self, level: u8, msg: &str) {
(self.log)(level, msg.as_ptr(), msg.len());
}
pub fn log_info(&self, msg: &str) {
self.log_raw(0, msg);
}
pub fn log_warn(&self, msg: &str) {
self.log_raw(1, msg);
}
pub fn log_error(&self, msg: &str) {
self.log_raw(2, msg);
}
pub fn log_debug(&self, msg: &str) {
self.log_raw(3, msg);
}
pub fn get_extension_typed<T>(&self, name: &str) -> Option<&'static T> {
let ptr = (self.get_extension)(name.as_ptr(), name.len());
if ptr.is_null() {
None
} else {
Some(unsafe { &*(ptr as *const T) })
}
}
}
pub struct ExtensionRegistry {
extensions: HashMap<String, *const c_void>,
}
impl ExtensionRegistry {
pub fn new() -> Self {
Self {
extensions: HashMap::new(),
}
}
pub fn register<T: 'static>(&mut self, name: &str, api: &'static T) {
self.extensions
.insert(name.to_string(), api as *const T as *const c_void);
log::info!("Registered extension: '{}'", name);
}
pub fn get(&self, name: &str) -> *const c_void {
self.extensions
.get(name)
.copied()
.unwrap_or(std::ptr::null())
}
}
unsafe impl Send for ExtensionRegistry {}
unsafe impl Sync for ExtensionRegistry {}
#[derive(Debug, Clone)]
pub enum DependencyError {
MissingMod(String, String),
CycleDetected(Vec<String>),
IncompatibleMods(String, String),
}
impl std::fmt::Display for DependencyError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::MissingMod(mod_id, dep) => {
write!(f, "Mod '{}' requires '{}' which is not loaded", mod_id, dep)
}
Self::CycleDetected(cycle) => {
write!(f, "Circular dependency detected: {}", cycle.join(" -> "))
}
Self::IncompatibleMods(a, b) => {
write!(f, "Mods '{}' and '{}' are incompatible", a, b)
}
}
}
}
impl std::error::Error for DependencyError {}
pub struct DependencyResolver;
impl DependencyResolver {
pub fn resolve_load_order(manifests: &[ModManifest]) -> Result<Vec<String>, DependencyError> {
for manifest in manifests {
for conflict in &manifest.incompatible_with {
if manifests.iter().any(|m| &m.id == conflict) {
return Err(DependencyError::IncompatibleMods(
manifest.id.clone(),
conflict.clone(),
));
}
}
}
let ids: Vec<&str> = manifests.iter().map(|m| m.id.as_str()).collect();
for manifest in manifests {
for dep in &manifest.requires {
if !ids.contains(&dep.as_str()) {
return Err(DependencyError::MissingMod(
manifest.id.clone(),
dep.clone(),
));
}
}
}
let mut graph: HashMap<&str, Vec<&str>> = HashMap::new();
for manifest in manifests {
let entry = graph.entry(manifest.id.as_str()).or_default();
for dep in &manifest.requires {
entry.push(dep.as_str());
}
for after in &manifest.load_after {
entry.push(after.as_str());
}
for before in &manifest.load_before {
if let Some(other_deps) = graph.get_mut(before.as_str()) {
other_deps.push(manifest.id.as_str());
} else {
graph.insert(before.as_str(), vec![manifest.id.as_str()]);
}
}
}
let mut in_degree: HashMap<&str, usize> = HashMap::new();
for manifest in manifests {
in_degree.insert(manifest.id.as_str(), 0);
}
for deps in graph.values() {
for dep in deps {
*in_degree.entry(dep).or_insert(0) += 1;
}
}
let mut queue: Vec<&str> = in_degree
.iter()
.filter(|(_, °)| deg == 0)
.map(|(&id, _)| id)
.collect();
queue.sort();
let mut order = Vec::new();
while let Some(id) = queue.pop() {
order.push(id.to_string());
if let Some(deps) = graph.get(id) {
for dep in deps {
if let Some(deg) = in_degree.get_mut(dep) {
*deg -= 1;
if *deg == 0 {
queue.push(dep);
}
}
}
}
}
if order.len() != manifests.len() {
let cycle: Vec<String> = in_degree
.iter()
.filter(|(_, °)| deg > 0)
.map(|(&id, _)| id.to_string())
.collect();
return Err(DependencyError::CycleDetected(cycle));
}
Ok(order)
}
}
#[inline]
pub const fn hash_string_const(s: &str) -> u64 {
let bytes = s.as_bytes();
let mut hash: u64 = 0xcbf29ce484222325; let mut i = 0;
while i < bytes.len() {
hash ^= bytes[i] as u64;
hash = hash.wrapping_mul(0x100000001b3); i += 1;
}
hash
}
#[inline]
pub fn hash_string(s: &str) -> u64 {
hash_string_const(s)
}
static SEGFAULT_HANDLER_INSTALLED: OnceLock<()> = OnceLock::new();
extern "C" fn segfault_handler(
_sig: libc::c_int,
_info: *mut libc::siginfo_t,
_ctx: *mut libc::c_void,
) {
let msg = b"\n[SEGFAULT] A mod accessed invalid memory. Aborting.\n";
unsafe {
libc::write(libc::STDERR_FILENO, msg.as_ptr() as *const _, msg.len());
}
std::process::abort();
}
pub fn install_segfault_handler() {
SEGFAULT_HANDLER_INSTALLED.get_or_init(|| {
unsafe {
let mut sa: libc::sigaction = std::mem::zeroed();
sa.sa_sigaction = segfault_handler as *const () as usize;
sa.sa_flags = libc::SA_SIGINFO;
libc::sigemptyset(&mut sa.sa_mask);
libc::sigaction(libc::SIGSEGV, &sa, std::ptr::null_mut());
libc::sigaction(libc::SIGBUS, &sa, std::ptr::null_mut());
log::info!("Segfault handler installed");
}
});
}
type HookCallback =
extern "C" fn(ctx: *mut HookContext, args: *mut c_void, result: *mut c_void) -> u8;
struct HookRegistration {
mod_id: String,
kind: u8, priority: i32,
callback: HookCallback,
}
static HOOK_MANAGER: OnceLock<RwLock<HookManager>> = OnceLock::new();
pub struct HookManager {
hooks: HashMap<u64, Vec<HookRegistration>>,
}
impl HookManager {
pub fn new() -> Self {
Self {
hooks: HashMap::new(),
}
}
pub fn register_hook(
&mut self,
target_hash: u64,
kind: u8,
priority: i32,
callback: HookCallback,
mod_id: &str,
) -> u64 {
let reg = HookRegistration {
mod_id: mod_id.to_string(),
kind,
priority,
callback,
};
self.hooks.entry(target_hash).or_default().push(reg);
self.hooks
.get_mut(&target_hash)
.unwrap()
.sort_by_key(|h| h.priority);
1
}
pub fn unregister_mod(&mut self, mod_id: &str) {
for hooks in self.hooks.values_mut() {
hooks.retain(|h| h.mod_id != mod_id);
}
log::info!("Unregistered all hooks for mod '{}'", mod_id);
}
#[inline]
pub fn execute_prefix<A, R>(
&self,
target_hash: u64,
args: &mut A,
result: &mut R,
) -> HookControl {
let to_remove = if let Some(hooks) = self.hooks.get(&target_hash) {
let mut to_remove = Vec::new();
for (idx, hook) in hooks.iter().enumerate() {
if hook.kind != 0 {
continue;
}
let ctx = HookContext {
mod_id: hook.mod_id.as_ptr(),
mod_id_len: hook.mod_id.len(),
};
match catch_unwind(AssertUnwindSafe(|| {
(hook.callback)(
&ctx as *const _ as *mut _,
args as *mut A as *mut _,
result as *mut R as *mut _,
)
})) {
Ok(1) => return HookControl::SkipOriginal,
Ok(2) => return HookControl::Abort,
Err(_) => {
log::error!(
"Mod '{}' panicked in prefix! Disabling.",
hook.mod_id
);
to_remove.push(idx);
}
_ => {}
}
}
to_remove
} else {
Vec::new()
};
if !to_remove.is_empty() {
let mut manager = get_hook_manager().write().unwrap();
if let Some(hooks) = manager.hooks.get_mut(&target_hash) {
for idx in to_remove.into_iter().rev() {
hooks.remove(idx);
}
}
}
HookControl::Continue
}
#[inline]
pub fn execute_postfix<A, R>(
&self,
target_hash: u64,
args: &A,
result: &mut R,
) -> HookControl {
let to_remove = if let Some(hooks) = self.hooks.get(&target_hash) {
let mut to_remove = Vec::new();
for (idx, hook) in hooks.iter().enumerate() {
if hook.kind != 1 {
continue;
}
let ctx = HookContext {
mod_id: hook.mod_id.as_ptr(),
mod_id_len: hook.mod_id.len(),
};
match catch_unwind(AssertUnwindSafe(|| {
(hook.callback)(
&ctx as *const _ as *mut _,
args as *const A as *mut _,
result as *mut R as *mut _,
)
})) {
Ok(2) => return HookControl::Abort,
Err(_) => {
log::error!(
"Mod '{}' panicked in postfix! Disabling.",
hook.mod_id
);
to_remove.push(idx);
}
_ => {}
}
}
to_remove
} else {
Vec::new()
};
if !to_remove.is_empty() {
let mut manager = get_hook_manager().write().unwrap();
if let Some(hooks) = manager.hooks.get_mut(&target_hash) {
for idx in to_remove.into_iter().rev() {
hooks.remove(idx);
}
}
}
HookControl::Continue
}
#[inline]
pub fn execute_replace<A, R>(&self, target_hash: u64, args: &mut A, result: &mut R) -> bool {
let to_remove = if let Some(hooks) = self.hooks.get(&target_hash) {
let mut to_remove = Vec::new();
for (idx, hook) in hooks.iter().enumerate() {
if hook.kind != 2 {
continue;
}
let ctx = HookContext {
mod_id: hook.mod_id.as_ptr(),
mod_id_len: hook.mod_id.len(),
};
match catch_unwind(AssertUnwindSafe(|| {
(hook.callback)(
&ctx as *const _ as *mut _,
args as *mut A as *mut _,
result as *mut R as *mut _,
)
})) {
Ok(_) => return true,
Err(_) => {
log::error!(
"Mod '{}' panicked in replace! Disabling.",
hook.mod_id
);
to_remove.push(idx);
}
}
}
to_remove
} else {
Vec::new()
};
if !to_remove.is_empty() {
let mut manager = get_hook_manager().write().unwrap();
if let Some(hooks) = manager.hooks.get_mut(&target_hash) {
for idx in to_remove.into_iter().rev() {
hooks.remove(idx);
}
}
}
false
}
}
pub fn get_hook_manager() -> &'static RwLock<HookManager> {
HOOK_MANAGER.get_or_init(|| RwLock::new(HookManager::new()))
}
extern "C" fn host_register_hook(
target_hash: u64,
kind: u8,
priority: i32,
callback: *const c_void,
) -> u64 {
if callback.is_null() {
return 0;
}
let callback_fn: HookCallback = unsafe { std::mem::transmute(callback) };
get_hook_manager()
.write()
.unwrap()
.register_hook(target_hash, kind, priority, callback_fn, "dynamic_mod")
}
extern "C" fn host_log(level: u8, msg_ptr: *const u8, msg_len: usize) {
if msg_ptr.is_null() {
return;
}
let msg = unsafe { std::str::from_utf8_unchecked(std::slice::from_raw_parts(msg_ptr, msg_len)) };
match level {
0 => log::info!("[MOD] {}", msg),
1 => log::warn!("[MOD] {}", msg),
2 => log::error!("[MOD] {}", msg),
_ => log::debug!("[MOD] {}", msg),
}
}
static EXTENSION_REGISTRY: OnceLock<RwLock<ExtensionRegistry>> = OnceLock::new();
extern "C" fn host_get_extension(name_ptr: *const u8, name_len: usize) -> *const c_void {
if name_ptr.is_null() {
return std::ptr::null();
}
let name = unsafe { std::str::from_utf8_unchecked(std::slice::from_raw_parts(name_ptr, name_len)) };
let registry = EXTENSION_REGISTRY.get_or_init(|| RwLock::new(ExtensionRegistry::new()));
registry.read().unwrap().get(name)
}
pub fn create_host_api() -> HostApi {
install_segfault_handler();
HostApi {
api_version: 1,
register_hook: host_register_hook,
log: host_log,
get_extension: host_get_extension,
}
}
pub fn register_extension<T: 'static>(name: &str, api: &'static T) {
let registry = EXTENSION_REGISTRY.get_or_init(|| RwLock::new(ExtensionRegistry::new()));
registry.write().unwrap().register(name, api);
}
#[derive(Debug, Clone)]
pub struct HookInfo {
pub name: String,
pub hash: u64,
pub args: Vec<(String, String)>,
pub result_type: String,
}
pub fn read_hooks_info(binary_path: &str) -> Result<Vec<HookInfo>, String> {
let data =
std::fs::read(binary_path).map_err(|e| format!("Failed to read '{}': {}", binary_path, e))?;
let sections = read_elf_sections_runtime(&data, ".hooks_info.");
let mut hooks = Vec::new();
for (name, section_data) in sections {
let info_str = String::from_utf8_lossy(§ion_data);
let parts: Vec<&str> = info_str.split('|').collect();
if parts.len() != 2 {
continue;
}
let args: Vec<(String, String)> = if parts[0].is_empty() {
Vec::new()
} else {
parts[0]
.split(',')
.filter_map(|arg| {
let p: Vec<&str> = arg.splitn(2, ':').collect();
if p.len() == 2 {
Some((p[0].trim().to_string(), p[1].trim().to_string()))
} else {
None
}
})
.collect()
};
let hash = hash_string(&name);
hooks.push(HookInfo {
name,
hash,
args,
result_type: parts[1].trim().to_string(),
});
}
Ok(hooks)
}
pub fn validate_game_binary(binary_path: &str) -> Result<Vec<String>, String> {
let hooks = read_hooks_info(binary_path)?;
if hooks.is_empty() {
return Err("No hooks found in game binary".to_string());
}
Ok(hooks.iter().map(|h| h.name.clone()).collect())
}
fn read_elf_sections_runtime(data: &[u8], prefix: &str) -> Vec<(String, Vec<u8>)> {
let mut results = Vec::new();
if data.len() < 64 || &data[0..4] != b"\x7fELF" {
return results;
}
if data[4] != 2 {
return results;
}
let e_shoff = u64::from_le_bytes(data[40..48].try_into().unwrap_or([0; 8])) as usize;
let e_shentsize = u16::from_le_bytes(data[58..60].try_into().unwrap_or([0; 2])) as usize;
let e_shnum = u16::from_le_bytes(data[60..62].try_into().unwrap_or([0; 2])) as usize;
let e_shstrndx = u16::from_le_bytes(data[62..64].try_into().unwrap_or([0; 2])) as usize;
if e_shoff == 0 || e_shnum == 0 {
return results;
}
let shstr_offset = e_shoff + e_shstrndx * e_shentsize;
if shstr_offset + e_shentsize > data.len() {
return results;
}
let shstr_sh_offset = u64::from_le_bytes(
data[shstr_offset + 24..shstr_offset + 32]
.try_into()
.unwrap_or([0; 8]),
) as usize;
let shstr_sh_size = u64::from_le_bytes(
data[shstr_offset + 32..shstr_offset + 40]
.try_into()
.unwrap_or([0; 8]),
) as usize;
if shstr_sh_offset + shstr_sh_size > data.len() {
return results;
}
let shstrtab = &data[shstr_sh_offset..shstr_sh_offset + shstr_sh_size];
for i in 0..e_shnum {
let sh_offset = e_shoff + i * e_shentsize;
if sh_offset + e_shentsize > data.len() {
break;
}
let sh_name_idx = u32::from_le_bytes(
data[sh_offset..sh_offset + 4]
.try_into()
.unwrap_or([0; 4]),
) as usize;
if sh_name_idx >= shstrtab.len() {
continue;
}
let name_end = shstrtab[sh_name_idx..]
.iter()
.position(|&b| b == 0)
.unwrap_or(0);
let section_name =
std::str::from_utf8(&shstrtab[sh_name_idx..sh_name_idx + name_end]).unwrap_or("");
if section_name.starts_with(prefix) {
let sh_offset_val = u64::from_le_bytes(
data[sh_offset + 24..sh_offset + 32]
.try_into()
.unwrap_or([0; 8]),
) as usize;
let sh_size = u64::from_le_bytes(
data[sh_offset + 32..sh_offset + 40]
.try_into()
.unwrap_or([0; 8]),
) as usize;
if sh_offset_val + sh_size <= data.len() {
let hook_name = section_name.trim_start_matches(prefix).to_string();
let section_data = data[sh_offset_val..sh_offset_val + sh_size].to_vec();
results.push((hook_name, section_data));
}
}
}
results
}
pub struct LoadedMod {
pub manifest: ModManifest,
pub library: libloading::Library,
}
pub struct ModLoader {
mods: HashMap<String, LoadedMod>,
load_order: Vec<String>,
}
impl ModLoader {
pub fn new() -> Self {
Self {
mods: HashMap::new(),
load_order: Vec::new(),
}
}
pub fn load_all_mods(&mut self, mods_dir: &str, host_api: &HostApi) -> Result<(), String> {
log::info!("Scanning mods directory: {}", mods_dir);
let mods_path = Path::new(mods_dir);
if !mods_path.exists() {
return Err(format!("Mods directory not found: {}", mods_dir));
}
let mut manifests = Vec::new();
let ext = if cfg!(windows) {
"dll"
} else if cfg!(target_os = "macos") {
"dylib"
} else {
"so"
};
if let Ok(entries) = std::fs::read_dir(mods_path) {
for entry in entries.flatten() {
let path = entry.path();
if path.extension().map_or(false, |e| e == ext) {
let path_str = path.to_string_lossy().to_string();
unsafe {
if let Ok(lib) = libloading::Library::new(&path_str) {
if let Ok(info_ptr) =
lib.get::<*const ModInfo>(b"MOD_INFO_SECTION")
{
let info_ref = &**info_ptr;
let mut manifest = ModManifest::from(info_ref);
manifest.path = path_str.clone();
manifests.push(manifest);
}
}
}
}
}
}
log::info!(
"Found {} mods: {:?}",
manifests.len(),
manifests.iter().map(|m| m.id.clone()).collect::<Vec<_>>()
);
let order = DependencyResolver::resolve_load_order(&manifests)
.map_err(|e| format!("Dependency resolution failed: {}", e))?;
log::info!("Load order: {:?}", order);
for mod_id in &order {
let manifest = manifests.iter().find(|m| &m.id == mod_id).unwrap();
match self.load_mod_internal(&manifest.path, manifest.clone(), host_api) {
Ok(()) => {
log::info!(
"Loaded mod: {} (v{})",
manifest.id,
manifest.version
);
self.load_order.push(mod_id.clone());
}
Err(e) => {
log::error!("Failed to load mod '{}': {}", mod_id, e);
}
}
}
Ok(())
}
fn load_mod_internal(
&mut self,
path: &str,
manifest: ModManifest,
host_api: &HostApi,
) -> Result<(), String> {
unsafe {
let lib = libloading::Library::new(path)
.map_err(|e| format!("Failed to load library: {}", e))?;
let init_sym: libloading::Symbol<extern "C" fn(*const HostApi) -> i32> = lib
.get(b"mod_init")
.map_err(|e| format!("No 'mod_init' symbol: {}", e))?;
match catch_unwind(AssertUnwindSafe(|| init_sym(host_api as *const HostApi))) {
Ok(0) => {}
Ok(code) => return Err(format!("mod_init failed with code: {}", code)),
Err(_) => return Err("mod_init panicked".to_string()),
}
self.mods.insert(
manifest.id.clone(),
LoadedMod {
manifest,
library: lib,
},
);
Ok(())
}
}
pub fn unload_mod(&mut self, mod_id: &str) -> Result<(), String> {
for (id, loaded) in &self.mods {
if loaded.manifest.requires.contains(&mod_id.to_string()) {
return Err(format!(
"Cannot unload '{}': mod '{}' depends on it",
mod_id, id
));
}
}
if let Some(loaded) = self.mods.remove(mod_id) {
get_hook_manager()
.write()
.unwrap()
.unregister_mod(mod_id);
drop(loaded.library);
self.load_order.retain(|id| id != mod_id);
log::info!("Unloaded mod: {}", mod_id);
Ok(())
} else {
Err(format!("Mod '{}' not found", mod_id))
}
}
pub fn reload_mod(&mut self, mod_id: &str, host_api: &HostApi) -> Result<(), String> {
let manifest = self
.mods
.get(mod_id)
.map(|m| m.manifest.clone())
.ok_or_else(|| format!("Mod '{}' not found", mod_id))?;
let path = manifest.path.clone();
self.unload_mod(mod_id)?;
self.load_mod_internal(&path, manifest, host_api)?;
log::info!("Reloaded mod: {}", mod_id);
Ok(())
}
pub fn loaded_mods(&self) -> Vec<&str> {
self.mods.keys().map(|s| s.as_str()).collect()
}
pub fn get_manifest(&self, mod_id: &str) -> Option<&ModManifest> {
self.mods.get(mod_id).map(|m| &m.manifest)
}
}