Initial
This commit is contained in:
1 parent
2cff35f215
commit
1b0d534e6c
358 files changed
+253978
-74
No files matched your search
@@ -0,0 +1,61 @@
|
||||
|
||||
|
||||
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] {
|
||||
®ISTRY
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user