use once_cell::sync::OnceCell;
use std::ffi::c_void;
use self::{concommands::RegisterConCommands, convars::CvarGlobals};
use crate::{bindings::cvar::RawCVar, high::engine::EngineData};
pub mod concommands;
pub mod convars;
pub static ENGINE_DATA: OnceCell<EngineData> = OnceCell::new();
impl EngineData {
pub const fn get_convar_ptrs(&self) -> &CvarGlobals {
self.convar
}
pub const fn get_concommand_func(&self) -> &RegisterConCommands {
self.concommands
}
pub const fn get_cvar(&self) -> &RawCVar {
self.cvar
}
}
pub fn get_engine_data() -> Option<&'static EngineData> {
ENGINE_DATA.get()
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum WhichDll<'a> {
Engine,
Client,
Server,
Other(&'a str),
}
pub struct DLLPointer<'a> {
dll: WhichDll<'a>,
ptr: *const c_void,
}
impl<'a> DLLPointer<'a> {
#[doc(hidden)]
pub fn new(dll_str: &'a str, ptr: *const c_void) -> DLLPointer<'a> {
let which_dll = match dll_str {
"engine.dll" => WhichDll::Engine,
"client.dll" => WhichDll::Client,
"server.dll" => WhichDll::Server,
dll => WhichDll::Other(dll),
};
Self {
dll: which_dll,
ptr,
}
}
pub const fn get_dll_ptr(&self) -> *const c_void {
self.ptr
}
pub const fn which_dll(&'_ self) -> &'_ WhichDll<'_> {
&self.dll
}
pub const unsafe fn offset(&self, offset: isize) -> *const c_void {
unsafe { self.ptr.offset(offset) }
}
}