From 3f1252ee5889f0a74ae94e13c1e3ed57cbeaa561 Mon Sep 17 00:00:00 2001 From: cat_or_not <41955154+catornot@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:34:14 -0500 Subject: [PATCH] fix clippy stuff --- rrplug_proc/src/lib.rs | 6 +- src/bindings/mod.rs | 5 +- src/bindings/squirrelfunctions.rs | 152 +++++++++++++++--------------- src/errors.rs | 13 +++ src/high/class_types.rs | 2 +- src/high/concommands.rs | 7 +- src/high/convars.rs | 2 +- src/high/engine.rs | 14 ++- src/high/mod.rs | 8 +- src/high/squirrel.rs | 10 +- src/interfaces/external.rs | 4 +- src/interfaces/interface.rs | 4 +- src/interfaces/manager.rs | 3 +- src/interfaces/mod.rs | 2 +- src/lib.rs | 1 + src/macros/entry.rs | 19 ++-- src/mid/concommands.rs | 4 +- src/mid/convars.rs | 2 +- src/mid/engine.rs | 16 ++-- src/mid/northstar.rs | 4 +- src/mid/squirrel.rs | 2 +- src/nslog/mod.rs | 2 +- src/plugin.rs | 2 + 23 files changed, 157 insertions(+), 127 deletions(-) diff --git a/rrplug_proc/src/lib.rs b/rrplug_proc/src/lib.rs index 1e926b4..86765bb 100644 --- a/rrplug_proc/src/lib.rs +++ b/rrplug_proc/src/lib.rs @@ -489,7 +489,7 @@ pub fn as_interface(_attr: TokenStream, item: TokenStream) -> TokenStream { #(#attrs)* #vis #defaultness #sig { use rrplug::interfaces::interface::AsInterface; - Self::as_interface({ + Self::to_interface({ #(#stmts)* }) } @@ -568,14 +568,14 @@ pub fn as_interface(_attr: TokenStream, item: TokenStream) -> TokenStream { #(#attrs)* impl #generics rrplug::interfaces::interface::AsInterface for #self_ty { - fn as_interface(self) -> rrplug::interfaces::interface::Interface { + fn to_interface(self) -> rrplug::interfaces::interface::Interface { // make these extern c wrapped and offset the self since it will have the vtable // TODO: make generic functions work (big headache) #( #[allow(unsafe_op_in_unsafe_fn)] unsafe extern "C" fn #function_idents #generics(self_: *const std::ffi::c_void, #extern_inputs) #extern_outputs { // transmute because I want to be lazy here - #self_ty_ident::#generics_bracked #function_idents(std::mem::transmute(self_.offset(std::mem::size_of::() as isize)), #extern_inputs_idents ) + #self_ty_ident::#generics_bracked #function_idents(self_.cast::().add(1).cast::<#self_ty_ident>().as_ref().expect("how!"), #extern_inputs_idents ) } )* diff --git a/src/bindings/mod.rs b/src/bindings/mod.rs index cc0e4c7..16aa8ed 100644 --- a/src/bindings/mod.rs +++ b/src/bindings/mod.rs @@ -30,7 +30,7 @@ impl std::ops::DerefMut for OffsetStructField { } impl OffsetStructField { - pub fn get_inner(&self) -> &T { + pub const fn get_inner(&self) -> &T { &self.value } @@ -40,7 +40,8 @@ impl OffsetStructField { } impl OffsetStructField { - pub fn copy_inner(&self) -> T { + /// Returns the copy inner of this [`OffsetStructField`]. + pub const fn copy_inner(&self) -> T { self.value } } diff --git a/src/bindings/squirrelfunctions.rs b/src/bindings/squirrelfunctions.rs index 70f66c2..cda0a78 100644 --- a/src/bindings/squirrelfunctions.rs +++ b/src/bindings/squirrelfunctions.rs @@ -148,88 +148,88 @@ pub struct SquirrelFunctions { pub sq_sealstructslot: sq_sealstructslotType, } -impl Into for ClientSQFunctions { - fn into(self) -> SquirrelFunctions { +impl From for SquirrelFunctions { + fn from(val: ClientSQFunctions) -> Self { SquirrelFunctions { - register_squirrel_func: self.register_squirrel_func, - sq_defconst: self.sq_defconst, - sq_compilebuffer: self.sq_compilebuffer, - sq_call: self.sq_call, - sq_raiseerror: self.sq_raiseerror, - sq_compilefile: self.sq_compilefile, - sq_newarray: self.sq_newarray, - sq_arrayappend: self.sq_arrayappend, - sq_newtable: self.sq_newtable, - sq_newslot: self.sq_newslot, - sq_pushroottable: self.sq_pushroottable, - sq_pushstring: self.sq_pushstring, - sq_pushinteger: self.sq_pushinteger, - sq_pushfloat: self.sq_pushfloat, - sq_pushbool: self.sq_pushbool, - sq_pushasset: self.sq_pushasset, - sq_pushvector: self.sq_pushvector, - sq_pushobject: self.sq_pushobject, - sq_getstring: self.sq_getstring, - sq_getinteger: self.sq_getinteger, - sq_getfloat: self.sq_getfloat, - sq_getbool: self.sq_getbool, - sq_get: self.sq_get, - sq_getasset: self.sq_getasset, - sq_getuserdata: self.sq_getuserdata, - sq_getvector: self.sq_getvector, - sq_getthisentity: self.sq_getthisentity, - sq_getobject: self.sq_getobject, - sq_stackinfos: self.sq_stackinfos, - sq_createuserdata: self.sq_createuserdata, - sq_setuserdatatypeid: self.sq_setuserdatatypeid, - sq_getfunction: self.sq_getfunction, - sq_getentityfrominstance: self.sq_getentityfrominstance, - sq_get_entity_constant_cbase_entity: self.sq_get_entity_constant_cbase_entity, - sq_pushnewstructinstance: self.sq_pushnewstructinstance, - sq_sealstructslot: self.sq_sealstructslot, + register_squirrel_func: val.register_squirrel_func, + sq_defconst: val.sq_defconst, + sq_compilebuffer: val.sq_compilebuffer, + sq_call: val.sq_call, + sq_raiseerror: val.sq_raiseerror, + sq_compilefile: val.sq_compilefile, + sq_newarray: val.sq_newarray, + sq_arrayappend: val.sq_arrayappend, + sq_newtable: val.sq_newtable, + sq_newslot: val.sq_newslot, + sq_pushroottable: val.sq_pushroottable, + sq_pushstring: val.sq_pushstring, + sq_pushinteger: val.sq_pushinteger, + sq_pushfloat: val.sq_pushfloat, + sq_pushbool: val.sq_pushbool, + sq_pushasset: val.sq_pushasset, + sq_pushvector: val.sq_pushvector, + sq_pushobject: val.sq_pushobject, + sq_getstring: val.sq_getstring, + sq_getinteger: val.sq_getinteger, + sq_getfloat: val.sq_getfloat, + sq_getbool: val.sq_getbool, + sq_get: val.sq_get, + sq_getasset: val.sq_getasset, + sq_getuserdata: val.sq_getuserdata, + sq_getvector: val.sq_getvector, + sq_getthisentity: val.sq_getthisentity, + sq_getobject: val.sq_getobject, + sq_stackinfos: val.sq_stackinfos, + sq_createuserdata: val.sq_createuserdata, + sq_setuserdatatypeid: val.sq_setuserdatatypeid, + sq_getfunction: val.sq_getfunction, + sq_getentityfrominstance: val.sq_getentityfrominstance, + sq_get_entity_constant_cbase_entity: val.sq_get_entity_constant_cbase_entity, + sq_pushnewstructinstance: val.sq_pushnewstructinstance, + sq_sealstructslot: val.sq_sealstructslot, } } } -impl Into for ServerSQFunctions { - fn into(self) -> SquirrelFunctions { +impl From for SquirrelFunctions { + fn from(val: ServerSQFunctions) -> Self { SquirrelFunctions { - register_squirrel_func: self.register_squirrel_func, - sq_defconst: self.sq_defconst, - sq_compilebuffer: self.sq_compilebuffer, - sq_call: self.sq_call, - sq_raiseerror: self.sq_raiseerror, - sq_compilefile: self.sq_compilefile, - sq_newarray: self.sq_newarray, - sq_arrayappend: self.sq_arrayappend, - sq_newtable: self.sq_newtable, - sq_newslot: self.sq_newslot, - sq_pushroottable: self.sq_pushroottable, - sq_pushstring: self.sq_pushstring, - sq_pushinteger: self.sq_pushinteger, - sq_pushfloat: self.sq_pushfloat, - sq_pushbool: self.sq_pushbool, - sq_pushasset: self.sq_pushasset, - sq_pushvector: self.sq_pushvector, - sq_pushobject: self.sq_pushobject, - sq_getstring: self.sq_getstring, - sq_getinteger: self.sq_getinteger, - sq_getfloat: self.sq_getfloat, - sq_getbool: self.sq_getbool, - sq_get: self.sq_get, - sq_getasset: self.sq_getasset, - sq_getuserdata: self.sq_getuserdata, - sq_getvector: self.sq_getvector, - sq_getthisentity: self.sq_getthisentity, - sq_getobject: self.sq_getobject, - sq_stackinfos: self.sq_stackinfos, - sq_createuserdata: self.sq_createuserdata, - sq_setuserdatatypeid: self.sq_setuserdatatypeid, - sq_getfunction: self.sq_getfunction, - sq_getentityfrominstance: self.sq_getentityfrominstance, - sq_get_entity_constant_cbase_entity: self.sq_get_entity_constant_cbase_entity, - sq_pushnewstructinstance: self.sq_pushnewstructinstance, - sq_sealstructslot: self.sq_sealstructslot, + register_squirrel_func: val.register_squirrel_func, + sq_defconst: val.sq_defconst, + sq_compilebuffer: val.sq_compilebuffer, + sq_call: val.sq_call, + sq_raiseerror: val.sq_raiseerror, + sq_compilefile: val.sq_compilefile, + sq_newarray: val.sq_newarray, + sq_arrayappend: val.sq_arrayappend, + sq_newtable: val.sq_newtable, + sq_newslot: val.sq_newslot, + sq_pushroottable: val.sq_pushroottable, + sq_pushstring: val.sq_pushstring, + sq_pushinteger: val.sq_pushinteger, + sq_pushfloat: val.sq_pushfloat, + sq_pushbool: val.sq_pushbool, + sq_pushasset: val.sq_pushasset, + sq_pushvector: val.sq_pushvector, + sq_pushobject: val.sq_pushobject, + sq_getstring: val.sq_getstring, + sq_getinteger: val.sq_getinteger, + sq_getfloat: val.sq_getfloat, + sq_getbool: val.sq_getbool, + sq_get: val.sq_get, + sq_getasset: val.sq_getasset, + sq_getuserdata: val.sq_getuserdata, + sq_getvector: val.sq_getvector, + sq_getthisentity: val.sq_getthisentity, + sq_getobject: val.sq_getobject, + sq_stackinfos: val.sq_stackinfos, + sq_createuserdata: val.sq_createuserdata, + sq_setuserdatatypeid: val.sq_setuserdatatypeid, + sq_getfunction: val.sq_getfunction, + sq_getentityfrominstance: val.sq_getentityfrominstance, + sq_get_entity_constant_cbase_entity: val.sq_get_entity_constant_cbase_entity, + sq_pushnewstructinstance: val.sq_pushnewstructinstance, + sq_sealstructslot: val.sq_sealstructslot, } } } diff --git a/src/errors.rs b/src/errors.rs index 5bb94e9..14884e4 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -115,3 +115,16 @@ impl CStringPtrError { log::error!("{}", self) } } + +#[derive(Error, Debug)] +pub enum CompletionError { + #[error("no more completion slots remain")] + NoCompletionSlotsLeft, +} + +impl CompletionError { + /// logs the error with the builtin logger + pub fn log(&self) { + log::error!("{}", self) + } +} diff --git a/src/high/class_types.rs b/src/high/class_types.rs index 725829a..6fbcfda 100644 --- a/src/high/class_types.rs +++ b/src/high/class_types.rs @@ -20,7 +20,7 @@ impl Iterator for PointerIterator { impl PointerIterator { /// # Safety /// the pointer must be an array of pointers to `T` terminated by a null pointer - pub unsafe fn new(ptr: *mut T) -> Self { + pub const unsafe fn new(ptr: *mut T) -> Self { Self { ptr } } } diff --git a/src/high/concommands.rs b/src/high/concommands.rs index 4b2f4d3..bd145b3 100644 --- a/src/high/concommands.rs +++ b/src/high/concommands.rs @@ -43,6 +43,7 @@ use crate::{ bindings::cvar::command::{ CCommand, COMMAND_COMPLETION_ITEM_LENGTH, COMMAND_COMPLETION_MAXITEMS, }, + errors::CompletionError, mid::utils::set_c_char_array, }; @@ -122,9 +123,9 @@ impl<'a> From<*mut [c_char; COMMAND_COMPLETION_ITEM_LENGTH as usize]> for Comman } } impl CommandCompletion<'_> { - pub fn push<'b>(&mut self, new: &'b str) -> Result<(), ()> { + pub fn push(&mut self, new: &str) -> Result<(), CompletionError> { if self.suggestions_left == 0 { - return Err(()); + return Err(CompletionError::NoCompletionSlotsLeft); } unsafe { @@ -139,7 +140,7 @@ impl CommandCompletion<'_> { Ok(()) } - pub fn commands_used(&self) -> i32 { + pub const fn commands_used(&self) -> i32 { (COMMAND_COMPLETION_MAXITEMS - self.suggestions_left) as i32 } } diff --git a/src/high/convars.rs b/src/high/convars.rs index 729038f..017a52b 100644 --- a/src/high/convars.rs +++ b/src/high/convars.rs @@ -263,7 +263,7 @@ impl ConVarStruct { default_value_ptr.copy_from_nonoverlapping(default_value.as_ptr(), default_value.len()) }; - let help_string = try_cstring(®ister_info.help_string)?.into_bytes_with_nul(); + let help_string = try_cstring(register_info.help_string)?.into_bytes_with_nul(); let help_string_ptr = unsafe { SOURCE_ALLOC.alloc(Layout::for_value(&help_string)) }; unsafe { help_string_ptr.copy_from_nonoverlapping(help_string.as_ptr(), help_string.len()) diff --git a/src/high/engine.rs b/src/high/engine.rs index 763976d..53b3630 100644 --- a/src/high/engine.rs +++ b/src/high/engine.rs @@ -34,7 +34,15 @@ impl EngineToken { todo!() } - pub unsafe fn new_unchecked() -> Self { + /// allows you to call engine restricted functions without checking if it's the right thread + /// + /// # Safety + /// please only use this if you are sure that it is the engine thread + /// + /// can lead to crashes or ub since most functions are not thread safe + /// + /// this is usually the most sensible solution altought it does at least require you to think from where you call stuff + pub const unsafe fn new_unchecked() -> Self { Self(PhantomData) } } @@ -46,7 +54,7 @@ impl EngineGlobal { Self(UnsafeHandle { inner: data }) } - pub fn get(&self, _: EngineToken) -> &T { + pub const fn get(&self, _: EngineToken) -> &T { self.0.get() } @@ -60,7 +68,7 @@ impl EngineGlobal { } impl EngineGlobal { - pub fn copy(&self, _: EngineToken) -> T { + pub const fn copy(&self, _: EngineToken) -> T { self.0.copy() } } diff --git a/src/high/mod.rs b/src/high/mod.rs index ebd714c..ac7b581 100644 --- a/src/high/mod.rs +++ b/src/high/mod.rs @@ -18,11 +18,11 @@ pub mod engine_sync; pub mod engine_sync { #[doc(hidden)] #[inline(always)] - pub fn init_async_routine() {} + pub const fn init_async_routine() {} #[doc(hidden)] #[inline(always)] - pub unsafe fn run_async_routine() {} + pub const unsafe fn run_async_routine() {} } /// allows some tf2 types to be send and sync @@ -51,7 +51,7 @@ impl UnsafeHandle { } /// returns a ref to the underlying value - pub fn get(&self) -> &T { + pub const fn get(&self) -> &T { &self.inner } @@ -68,7 +68,7 @@ impl UnsafeHandle { impl UnsafeHandle { /// copies the underlying value if it has [`Copy`] - pub fn copy(&self) -> T { + pub const fn copy(&self) -> T { self.inner } } diff --git a/src/high/squirrel.rs b/src/high/squirrel.rs index 085512a..4723d6c 100644 --- a/src/high/squirrel.rs +++ b/src/high/squirrel.rs @@ -102,12 +102,12 @@ impl CSquirrelVMHandle { /// [`UnsafeHandle`] : when used outside of engine thread can cause race conditions or ub /// /// [`UnsafeHandle`] should only be used to transfer the pointers to other places in the engine thread like sqfunctions or runframe - pub unsafe fn get_cs_sqvm(&self) -> UnsafeHandle<*mut CSquirrelVM> { + pub const unsafe fn get_cs_sqvm(&self) -> UnsafeHandle<*mut CSquirrelVM> { UnsafeHandle::internal_new(self.handle) } /// gets the type of the sqvm :D - pub fn get_context(&self) -> ScriptContext { + pub const fn get_context(&self) -> ScriptContext { self.vm_type } } @@ -136,7 +136,7 @@ impl SQHandle { /// # Safety /// /// this breaks the type guarantees provided by this struct - pub unsafe fn new_unchecked(value: SQObject) -> Self { + pub const unsafe fn new_unchecked(value: SQObject) -> Self { Self { inner: value, marker: PhantomData, @@ -144,7 +144,7 @@ impl SQHandle { } /// a getter - pub fn get(&self) -> &SQObject { + pub const fn get(&self) -> &SQObject { &self.inner } @@ -154,7 +154,7 @@ impl SQHandle { } /// consumes itself and returns the [`SQObject`] - pub fn take(self) -> SQObject { + pub const fn take(self) -> SQObject { self.inner } } diff --git a/src/interfaces/external.rs b/src/interfaces/external.rs index 719b1d6..61c5cac 100644 --- a/src/interfaces/external.rs +++ b/src/interfaces/external.rs @@ -64,7 +64,7 @@ pub trait SourceInterface { unsafe { let create_interface = std::mem::transmute::<_, CreateInterface>(GetProcAddress( dll_ptr, - PCSTR("CreateInterface\0".as_ptr().into()), + PCSTR("CreateInterface\0".as_ptr()), )?); let interface_name = try_cstring(interface_name).ok()?; @@ -80,7 +80,7 @@ pub trait SourceInterface { let dll_name = try_cstring(dll_name).ok()?; let create_interface = std::mem::transmute::<_, CreateInterface>(GetProcAddress( GetModuleHandleA(PCSTR(dll_name.as_ptr() as *const u8)).ok()?, - PCSTR("CreateInterface\0".as_ptr().into()), + PCSTR("CreateInterface\0".as_ptr()), )?); let interface_name = try_cstring(interface_name).ok()?; diff --git a/src/interfaces/interface.rs b/src/interfaces/interface.rs index 1803e7f..ce66e9f 100644 --- a/src/interfaces/interface.rs +++ b/src/interfaces/interface.rs @@ -9,7 +9,7 @@ pub struct Interface { } impl Interface { - pub fn new(vtable: NonNull<*const c_void>, interface_data: T) -> Self { + pub const fn new(vtable: NonNull<*const c_void>, interface_data: T) -> Self { Self { vtable, data: interface_data, @@ -19,5 +19,5 @@ impl Interface { } pub trait AsInterface: Sized + Sync + Send { - fn as_interface(self) -> Interface; + fn to_interface(self) -> Interface; } diff --git a/src/interfaces/manager.rs b/src/interfaces/manager.rs index 2c0c42e..2c86e7c 100644 --- a/src/interfaces/manager.rs +++ b/src/interfaces/manager.rs @@ -24,8 +24,7 @@ unsafe extern "C" fn create_interface( unsafe { CStr::from_ptr(interface_name) } .to_str() .ok() - .map(|name| interfaces.get(name)) - .flatten() + .and_then(|name| interfaces.get(name)) .map(|interface| interface.copy()) .unwrap_or_else(|| { unsafe { *error = 1 }; diff --git a/src/interfaces/mod.rs b/src/interfaces/mod.rs index 433b4d2..9f7d6d7 100644 --- a/src/interfaces/mod.rs +++ b/src/interfaces/mod.rs @@ -19,7 +19,7 @@ mod test { Self { the_line: "line" } } - pub fn get_line(&self) -> &'static str { + pub const fn get_line(&self) -> &'static str { self.the_line } } diff --git a/src/lib.rs b/src/lib.rs index 89618ad..07e15d9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,7 @@ clippy::missing_const_for_fn )] // #![warn(missing_docs)] +#![allow(clippy::missing_safety_doc)] // TODO: remove before release #[allow(missing_docs)] pub mod bindings; diff --git a/src/macros/entry.rs b/src/macros/entry.rs index 9485f4b..40fc71a 100644 --- a/src/macros/entry.rs +++ b/src/macros/entry.rs @@ -13,7 +13,7 @@ /// /// impl Plugin for BasicPlugin { /// const PLUGIN_INFO: PluginInfo = -/// PluginInfo::new("test", "Testtttt", "test", PluginContext::all()); +/// PluginInfo::new("test", "Testttttt", "test", PluginContext::all()); /// /// fn new(reloaded: bool) -> Self { /// Self {} @@ -58,7 +58,10 @@ macro_rules! entry { Self } - fn GetString(&self, prop: plugin_abi::PluginString) -> *const std::ffi::c_char { + const fn GetString( + &self, + prop: plugin_abi::PluginString, + ) -> *const std::ffi::c_char { match prop { plugin_abi::PluginString::Name => { $plugin::PLUGIN_INFO.get_name().as_ptr() as *const i8 @@ -72,7 +75,7 @@ macro_rules! entry { } } - fn GetField(&self, prop: plugin_abi::PluginField) -> i64 { + const fn GetField(&self, prop: plugin_abi::PluginField) -> i64 { match prop { plugin_abi::PluginField::Context => { $plugin::PLUGIN_INFO.get_context().bits() as i64 @@ -108,8 +111,10 @@ macro_rules! entry { panic!("PLUGIN failed initialization") } } - fn Finalize(&self) {} - fn Unload(&self) -> bool { + fn Finalize(&self) { + PLUGIN.wait().plugins_loaded() + } + const fn Unload(&self) -> bool { false // TODO: add this to Plugin } fn OnSqvmCreated(&self, sqvm: *mut squirreldatatypes::CSquirrelVM) { @@ -292,7 +297,7 @@ mod test_entry { impl Plugin for Test { const PLUGIN_INFO: PluginInfo = - PluginInfo::new("test", "Test ", "test", PluginContext::all()); + PluginInfo::new("test", "Testttttt", "test", PluginContext::all()); fn new(_reloaded: bool) -> Self { Self {} @@ -302,7 +307,7 @@ mod test_entry { entry!(Test); #[test] - fn test_init() { + const fn test_init() { // todo: somehow test all the functions } } diff --git a/src/mid/concommands.rs b/src/mid/concommands.rs index a87d5cc..eeb30a8 100644 --- a/src/mid/concommands.rs +++ b/src/mid/concommands.rs @@ -125,7 +125,7 @@ pub fn find_concommand_with_cvar( pub fn find_concommand(name: &str) -> Result<&'static mut ConCommand, CVarQueryError> { find_concommand_with_cvar( name, - &get_engine_data() + get_engine_data() .ok_or(CVarQueryError::NoCVarInterface)? .cvar, ) @@ -167,7 +167,7 @@ pub fn find_concommand_base_with_cvar( pub fn find_concommand_base(name: &str) -> Result<&'static mut ConCommandBase, CVarQueryError> { find_concommand_base_with_cvar( name, - &get_engine_data() + get_engine_data() .ok_or(CVarQueryError::NoCVarInterface)? .cvar, ) diff --git a/src/mid/convars.rs b/src/mid/convars.rs index 4decaf8..38dd2c9 100644 --- a/src/mid/convars.rs +++ b/src/mid/convars.rs @@ -60,7 +60,7 @@ pub fn find_convar_with_cvar( pub fn find_convar(name: &str) -> Result<&'static mut ConVar, CVarQueryError> { find_convar_with_cvar( name, - &get_engine_data() + get_engine_data() .ok_or(CVarQueryError::NoCVarInterface)? .cvar, ) diff --git a/src/mid/engine.rs b/src/mid/engine.rs index ce5fd6d..d9274b2 100644 --- a/src/mid/engine.rs +++ b/src/mid/engine.rs @@ -17,15 +17,15 @@ impl EngineData { /// returns the functions and statics needed to register ConVars /// /// if you need to use it for some reason you can refer to rrplug code in [`crate::high::convars`] - pub fn get_convar_ptrs(&self) -> &CvarGlobals { + pub const fn get_convar_ptrs(&self) -> &CvarGlobals { self.convar } /// returns the function to register concommands /// /// if you need to use it for some reason you can refer to rrplug code in [`crate::mid::concommands`] - pub fn get_concommand_func(&self) -> &RegisterConCommands { - &self.concommands + pub const fn get_concommand_func(&self) -> &RegisterConCommands { + self.concommands } /// # major notes about [`RawCVar`] @@ -33,8 +33,8 @@ impl EngineData { /// [`RawCVar`] has many many unsafe functions /// but the `iterator` function should not be invoked /// since the returned `iterator` cannot be dropped by rust's default `allocator` which may produce ub. - pub fn get_cvar(&self) -> &RawCVar { - &self.cvar + pub const fn get_cvar(&self) -> &RawCVar { + self.cvar } } @@ -84,12 +84,12 @@ impl<'a> DLLPointer<'a> { } /// return the address of the dll - pub fn get_dll_ptr(&self) -> *const c_void { + pub const fn get_dll_ptr(&self) -> *const c_void { self.ptr } /// return the name of the dll - pub fn which_dll(&self) -> &WhichDll { + pub const fn which_dll(&self) -> &WhichDll { &self.dll } @@ -99,7 +99,7 @@ impl<'a> DLLPointer<'a> { /// /// a really bad idea if you have a bad offset or if you don't know what you are doing. /// this is mainly here to give access to the engines functions without having the crate be the provider of them. - pub unsafe fn offset(&self, offset: isize) -> *const c_void { + pub const unsafe fn offset(&self, offset: isize) -> *const c_void { unsafe { self.ptr.offset(offset) } } } diff --git a/src/mid/northstar.rs b/src/mid/northstar.rs index a7f8f2b..9073984 100644 --- a/src/mid/northstar.rs +++ b/src/mid/northstar.rs @@ -26,11 +26,11 @@ impl std::fmt::Debug for NorthstarData { } impl NorthstarData { - pub fn sys(&self) -> &'static NorthstarSys { + pub const fn sys(&self) -> &'static NorthstarSys { self.sys.copy() } - pub fn handle(&self) -> HMODULE { + pub const fn handle(&self) -> HMODULE { self.handle } } diff --git a/src/mid/squirrel.rs b/src/mid/squirrel.rs index 401166b..b20e2b9 100644 --- a/src/mid/squirrel.rs +++ b/src/mid/squirrel.rs @@ -113,7 +113,7 @@ bitflags::bitflags! { } impl SQFunctionContext { - pub fn contains_context(&self, context: ScriptContext) -> bool { + pub const fn contains_context(&self, context: ScriptContext) -> bool { match context { ScriptContext::SERVER => self.contains(Self::SERVER), ScriptContext::CLIENT => self.contains(Self::CLIENT), diff --git a/src/nslog/mod.rs b/src/nslog/mod.rs index 5bb4318..1c12311 100644 --- a/src/nslog/mod.rs +++ b/src/nslog/mod.rs @@ -87,7 +87,7 @@ where } /// this is needed because [`Level`] doesn't have the same order -fn level_to_log(level: Level) -> Option { +const fn level_to_log(level: Level) -> Option { match level { Level::Error => Some(LogLevel::LogErr), Level::Warn => Some(LogLevel::LogWarn), diff --git a/src/plugin.rs b/src/plugin.rs index 28eb946..a56761b 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -53,6 +53,8 @@ pub trait Plugin: Any + Sync { /// using this may be a bad idea since rrplug may not be done initializing everything. fn on_module_load() {} + fn plugins_loaded(&self) {} + /// called on each engine frame (runs on the titanfall 2 thread ofc lol) fn runframe(&self, _engine_token: EngineToken) {} }