use std::sync::LazyLock; use crate::hle::modules; #[derive(Debug, Clone, Copy)] pub struct HleExport { pub name: &'static str, pub address: usize, } #[derive(Debug)] pub struct HleModule { pub name: &'static str, pub dlls: &'static [&'static str], pub exports: Vec, } impl HleModule { pub fn serves(&self, dll: &str) -> bool { if !crate::hle::host::is_bare_dll_name(dll) { return false; } let dll = dll.to_ascii_lowercase(); self.dlls .iter() .any(|pattern| match pattern.strip_suffix('*') { Some(prefix) => dll.starts_with(prefix), None => dll == *pattern, }) } } #[macro_export] macro_rules! hle_export { ($f:ident) => { $crate::hle::HleExport { name: stringify!($f), address: $f as *const () as usize, } }; } static REGISTRY: LazyLock> = LazyLock::new(modules::all); pub fn registry() -> &'static [HleModule] { ®ISTRY } pub(crate) fn lookup(dll: &str, name: &str) -> Option { registry() .iter() .filter(|m| m.serves(dll)) .flat_map(|m| m.exports.iter()) .find(|e| e.name == name) .map(|e| e.address) }