diff --git a/src/bindings/class_types/c_player.rs b/src/bindings/class_types/c_player.rs index 91689d5..5290259 100644 --- a/src/bindings/class_types/c_player.rs +++ b/src/bindings/class_types/c_player.rs @@ -13,4 +13,4 @@ impl_vmethods! { impl C_Player { pub fn get_origin() -> *const Vector3 where offset(8); } -} \ No newline at end of file +} diff --git a/src/bindings/class_types/globalvars.rs b/src/bindings/class_types/globalvars.rs index 567b08f..bfb6e55 100644 --- a/src/bindings/class_types/globalvars.rs +++ b/src/bindings/class_types/globalvars.rs @@ -1 +1 @@ -// todo: add CGlobalVars \ No newline at end of file +// todo: add CGlobalVars diff --git a/src/bindings/class_types/mod.rs b/src/bindings/class_types/mod.rs index 7785bd3..6eb412d 100644 --- a/src/bindings/class_types/mod.rs +++ b/src/bindings/class_types/mod.rs @@ -1,4 +1,4 @@ -pub mod cplayer; +pub mod c_player; pub mod client; +pub mod cplayer; pub mod globalvars; -pub mod c_player; \ No newline at end of file diff --git a/src/bindings/mod.rs b/src/bindings/mod.rs index 53b4615..eb90d06 100644 --- a/src/bindings/mod.rs +++ b/src/bindings/mod.rs @@ -2,12 +2,12 @@ use std::fmt::{Debug, Display}; +pub mod class_types; pub mod cvar; pub mod plugin_abi; pub mod squirrelclasstypes; pub mod squirreldatatypes; pub mod unwraped; -pub mod class_types; #[repr(C)] pub struct OffsetStructField { diff --git a/src/bindings/squirreldatatypes.rs b/src/bindings/squirreldatatypes.rs index 89ee229..d5b3126 100644 --- a/src/bindings/squirreldatatypes.rs +++ b/src/bindings/squirreldatatypes.rs @@ -78,7 +78,7 @@ impl std::fmt::Debug for SQObjectValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str("SQObjectValue: unk union field") } -} +} #[test] fn bindgen_test_layout_SQObjectValue() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); diff --git a/src/bindings/unwraped.rs b/src/bindings/unwraped.rs index fba3534..f106fe4 100644 --- a/src/bindings/unwraped.rs +++ b/src/bindings/unwraped.rs @@ -1,5 +1,6 @@ #![allow(non_camel_case_types)] // whar +use super::class_types::cplayer::CPlayer; use crate::bindings::{ plugin_abi::SquirrelFunctions, squirrelclasstypes::{ @@ -10,7 +11,6 @@ use crate::bindings::{ CSquirrelVM, HSquirrelVM, SQBool, SQChar, SQFloat, SQInteger, SQObject, SQStackInfos, }, }; -use super::class_types::cplayer::CPlayer; pub type sq_schedule_call_externalType_unwraped = unsafe extern "C" fn( context: ScriptContext, @@ -104,12 +104,11 @@ pub type sq_createuserdataType_unwraped = unsafe extern "C" fn(sqvm: *mut HSquirrelVM, iSize: SQInteger) -> *mut ::std::os::raw::c_void; pub type sq_setuserdatatypeidType_unwraped = unsafe extern "C" fn(sqvm: *mut HSquirrelVM, iStackpos: SQInteger, iTypeId: u64) -> SQRESULT; -pub type sq_getentityfrominstanceType_unwraped = - unsafe extern "C" fn( - sqvm: *mut CSquirrelVM, - pInstance: *mut SQObject, - ppEntityConstant: *mut *mut ::std::os::raw::c_char, - ) -> *mut CPlayer; +pub type sq_getentityfrominstanceType_unwraped = unsafe extern "C" fn( + sqvm: *mut CSquirrelVM, + pInstance: *mut SQObject, + ppEntityConstant: *mut *mut ::std::os::raw::c_char, +) -> *mut CPlayer; pub type sq_GetEntityConstantType_unwraped = unsafe extern "C" fn() -> *mut *mut ::std::os::raw::c_char; pub type sq_getfunctionType_unwraped = unsafe extern "C" fn( diff --git a/src/errors.rs b/src/errors.rs index afefc65..88a3c93 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -10,7 +10,7 @@ pub enum RegisterError { /// A function crutial to some systems was null (this is fatal I think) #[error("A core function from c++ is null")] NoneFunction, - + /// A function that creates objects returned a null pointer #[error("A builder function returned None")] NoneResult, @@ -29,9 +29,9 @@ pub enum CallError { /// the function that was called isn't on the sqvm #[error("{0} function wasn't found on the sqvm; is it global?")] FunctionNotFound(String), - + /// the execution of the function failed for some reason - /// + /// /// the reason is not exposed by the sqvm :( #[error("function failed to execute")] FunctionFailedToExecute, @@ -48,11 +48,11 @@ impl CallError { #[derive(Error, Debug)] pub enum SQCompileError { /// the buffer failed the compile - /// + /// /// the reason is only provided if the buffer is compiled to display it #[error("provided code failed to compile")] CompileError, - + /// buffer didn't execute corretly #[error("compiled buffer failed to execute")] BufferFailedToExecute, @@ -72,7 +72,7 @@ pub enum CStringPtrError { #[default] #[error("literally nothing like the pointer is null")] None, - + /// when the char pointer failed to be parsed as [`&str`] #[error("invalid string (0)")] Utf8Error(#[from] std::str::Utf8Error), diff --git a/src/high/engine.rs b/src/high/engine.rs index 79ca7cc..565b6f9 100644 --- a/src/high/engine.rs +++ b/src/high/engine.rs @@ -2,6 +2,8 @@ use parking_lot::Mutex; +#[cfg(doc)] +use crate::high::convars::ConVarStruct; use crate::{ bindings::{ cvar::{ @@ -13,8 +15,6 @@ use crate::{ errors::RegisterError, mid::{concommands::RegisterConCommands, convars::ConVarClasses, engine::PluginLoadDLL}, }; -#[cfg(doc)] -use crate::high::convars::ConVarStruct; /// internal vec to not call on_dll_load #[doc(hidden)] diff --git a/src/high/vector.rs b/src/high/vector.rs index d1d0870..20e1a8a 100644 --- a/src/high/vector.rs +++ b/src/high/vector.rs @@ -26,21 +26,21 @@ impl Vector3 { y: 0., z: 0., }; - + /// const for largest [`Vector3`] possible pub const MAX: Self = Self { x: f32::MAX, y: f32::MAX, z: f32::MAX, }; - + /// const for smallest [`Vector3`] possible pub const MIN: Self = Self { x: f32::MIN, y: f32::MIN, z: f32::MIN, }; - + /// creates a new [`Vector3`] from the 3 planes #[inline] pub fn new(x: f32, y: f32, z: f32) -> Self { @@ -201,7 +201,7 @@ impl QAngle { z: f32::MIN, w: f32::MIN, }; - + #[inline] pub fn new(x: f32, y: f32, z: f32, w: f32) -> Self { Self { x, y, z, w } diff --git a/src/lib.rs b/src/lib.rs index 8591d70..2bc9e42 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,19 @@ //! rrplug is a safe wrapper around the plugin system in [R2Northstar](https://northstar.tf/) //! -//! this version is for plugins v3 +//! rrplug uses compile time or sometimes runtime checks to guarantee safety in abstractions +//! +//! ## rrplug template +//! +//! install cargo-generate if you don't have it +//! ```bash +//! cargo install cargo-generate +//! ``` +//! +//! ```bash +//! cargo generate -g https://github.com/catornot/rrplug.git +//! ``` +//! +//! a git [template](https://github.com/catornot/rrplug-template) also exists but it may or not be maintained as well #![deny(unsafe_op_in_unsafe_fn)] #![warn(missing_docs)] @@ -8,7 +21,6 @@ #[cfg(doctest)] use crate as rrplug; - #[allow(missing_docs)] pub mod bindings; pub mod errors; diff --git a/src/low/mod.rs b/src/low/mod.rs index 3131bb9..d208066 100644 --- a/src/low/mod.rs +++ b/src/low/mod.rs @@ -1 +1 @@ -//! lowest access is at [`crate::bindings`] \ No newline at end of file +//! lowest access is at [`crate::bindings`] diff --git a/src/macros/mod.rs b/src/macros/mod.rs index 886d469..fafacda 100644 --- a/src/macros/mod.rs +++ b/src/macros/mod.rs @@ -3,4 +3,4 @@ pub mod entry; pub mod sq_return; pub mod sq_utils; -pub mod utils; \ No newline at end of file +pub mod utils; diff --git a/src/macros/sq_utils.rs b/src/macros/sq_utils.rs index a516257..492cdfa 100644 --- a/src/macros/sq_utils.rs +++ b/src/macros/sq_utils.rs @@ -1,5 +1,5 @@ //! various macros to help call squirrel functions -//! +//! //! for non async calls the args are not checked to be correct at compile time #[cfg(doc)] @@ -79,7 +79,7 @@ macro_rules! call_sq_function { /// ``` /// # use rrplug::prelude::*; /// # use rrplug::call_sq_object_function; -/// +/// /// #[rrplug::sqfunction(VM="Server")] /// fn test_call_funcs(mut func: fn(String)) { /// call_sq_object_function!(sqvm, sq_functions, func, "test".to_string()).map_err(|err| err.to_string())?; @@ -127,7 +127,7 @@ macro_rules! call_sq_object_function { /// ## example /// ```no_run /// # use rrplug::prelude::*; -/// +/// /// rrplug::async_call_sq_function!(ScriptVmType::Client, "SomeSQFunc", 9347, "Test".to_string()); /// ``` #[macro_export] diff --git a/src/mid/engine.rs b/src/mid/engine.rs index 56eb7df..3292069 100644 --- a/src/mid/engine.rs +++ b/src/mid/engine.rs @@ -11,7 +11,7 @@ use crate::{ use super::{concommands::RegisterConCommands, convars::ConVarClasses}; /// used to create to ConVars and ConComands -/// +/// /// also allows access to [`RawCVar`] if you need it but beter options are available in [`crate::high::convars`]/[`crate::mid::convars`] and [`crate::mid::concommands`] pub static ENGINE_DATA: OnceCell = OnceCell::new(); @@ -46,7 +46,7 @@ impl EngineData { } /// returns engine data [`EngineData`] -/// +/// /// refer to [`ENGINE_DATA`] for more docs:tm: pub fn get_engine_data() -> Option<&'static EngineData> { ENGINE_DATA.get() diff --git a/src/plugin.rs b/src/plugin.rs index 767f47f..477984d 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -1,5 +1,5 @@ //! the plugin trait module -//! +//! //! the plugin system will look for a exported function to pass stuff to //! //! this exported function and others are created by the `entry` macro @@ -12,7 +12,7 @@ use crate::{ northstar::{PluginData, ScriptVmType}, squirrel::CSquirrelVMHandle, }, - mid::engine::{DLLPointer,PluginLoadDLL}, + mid::engine::{DLLPointer, PluginLoadDLL}, }; /// Trait for defining the callbacks and entry point of the plugin @@ -22,26 +22,26 @@ use crate::{ /// it is unsafe to run any titanfall engine functions on it pub trait Plugin: Any + Sync { /// init function - /// + /// /// [`PluginData`] can be used to register sqfunctions and get the northstar version fn new(plugin_data: &PluginData) -> Self; - + /// provided separate thread fn main(&self); - + /// called when a dll is loaded with winapi functions by the game (full paths are not provided) - /// + /// /// only calls once for each unique dll fn on_dll_load(&self, _engine: &PluginLoadDLL, _dll_ptr: &DLLPointer) {} - + /// called when a sqvm is created - /// - /// can be used to store the sqvm for use on the titanfall 2 thread but it is unsafe since the sqvm can be invalided at any point + /// + /// can be used to store the sqvm for use on the titanfall 2 thread but it is unsafe since the sqvm can be invalided at any point fn on_sqvm_created(&self, _sqvm_handle: &CSquirrelVMHandle) {} - + /// called when a sqvm is dropped fn on_sqvm_destroyed(&self, _context: ScriptVmType) {} - + /// called on each engine frame (runs on the titanfall 2 thread ofc lol) fn runframe(&self) {} } diff --git a/src/prelude.rs b/src/prelude.rs index dc35e35..c229d1c 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -5,7 +5,7 @@ pub use crate::{ entry, high::{ concommands::CCommandResult, - convars::{ConVarStruct,ConVarRegister}, + convars::{ConVarRegister, ConVarStruct}, engine::EngineData, northstar::{PluginData, ScriptVmType}, squirrel::CSquirrelVMHandle,