Files
EonaCat.XSBox/crates/engine/src/hle/registry.rs
T
EonaCat 1b0d534e6c
Rust validation / Formatting (push) Failing after 27s
EonaCat/ci-workflows: SonarQube / sonar (push) Successful in 47s
Rust validation / Windows x64 build and tests (push) Canceled after 0s
Initial
2026-12-04 21:03:25 +01:00

62 lines
1.3 KiB
Rust

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<HleExport>,
}
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<Vec<HleModule>> = LazyLock::new(modules::all);
pub fn registry() -> &'static [HleModule] {
&REGISTRY
}
pub(crate) fn lookup(dll: &str, name: &str) -> Option<usize> {
registry()
.iter()
.filter(|m| m.serves(dll))
.flat_map(|m| m.exports.iter())
.find(|e| e.name == name)
.map(|e| e.address)
}