Skip to content

Commit

Permalink
additional formating
Browse files Browse the repository at this point in the history
  • Loading branch information
catornot committed Sep 23, 2023
1 parent 0795573 commit cd27cf1
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/bindings/class_types/c_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ impl_vmethods! {
impl C_Player {
pub fn get_origin() -> *const Vector3 where offset(8);
}
}
}
2 changes: 1 addition & 1 deletion src/bindings/class_types/globalvars.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// todo: add CGlobalVars
// todo: add CGlobalVars
4 changes: 2 additions & 2 deletions src/bindings/class_types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod cplayer;
pub mod c_player;
pub mod client;
pub mod cplayer;
pub mod globalvars;
pub mod c_player;
2 changes: 1 addition & 1 deletion src/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, const U: usize> {
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/squirreldatatypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SQObjectValue> = ::std::mem::MaybeUninit::uninit();
Expand Down
13 changes: 6 additions & 7 deletions src/bindings/unwraped.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(non_camel_case_types)] // whar

use super::class_types::cplayer::CPlayer;
use crate::bindings::{
plugin_abi::SquirrelFunctions,
squirrelclasstypes::{
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/high/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
use parking_lot::Mutex;

#[cfg(doc)]
use crate::high::convars::ConVarStruct;
use crate::{
bindings::{
cvar::{
Expand All @@ -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)]
Expand Down
8 changes: 4 additions & 4 deletions src/high/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 }
Expand Down
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
//! 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)]

#[cfg(doctest)]
use crate as rrplug;


#[allow(missing_docs)]
pub mod bindings;
pub mod errors;
Expand Down
2 changes: 1 addition & 1 deletion src/low/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
//! lowest access is at [`crate::bindings`]
//! lowest access is at [`crate::bindings`]
2 changes: 1 addition & 1 deletion src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
pub mod entry;
pub mod sq_return;
pub mod sq_utils;
pub mod utils;
pub mod utils;
6 changes: 3 additions & 3 deletions src/macros/sq_utils.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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())?;
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions src/mid/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EngineData> = OnceCell::new();

Expand Down Expand Up @@ -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()
Expand Down
22 changes: 11 additions & 11 deletions src/plugin.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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) {}
}
2 changes: 1 addition & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub use crate::{
entry,
high::{
concommands::CCommandResult,
convars::{ConVarStruct,ConVarRegister},
convars::{ConVarRegister, ConVarStruct},
engine::EngineData,
northstar::{PluginData, ScriptVmType},
squirrel::CSquirrelVMHandle,
Expand Down

0 comments on commit cd27cf1

Please sign in to comment.