Skip to content

Commit

Permalink
removes old todos and add reinstating
Browse files Browse the repository at this point in the history
  • Loading branch information
catornot committed Mar 30, 2024
1 parent c904fb7 commit 9225a49
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "wrappers and functions for R2Northstar plugins"
repository = "https://github.com/catornot/rrplug"
license = "Apache-2.0 OR MIT"
keywords = ["plugin", "northstar", "titanfall"]
exclude = ["/rrplug_template", ".gitignore"]
exclude = [".gitignore"]
edition = "2021"
rust-version = "1.77"

Expand Down
1 change: 0 additions & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ pub enum InterfaceGetterError<'a> {
InterfaceNotFound(&'a str),
}

// TODO: make a macro for this
impl InterfaceGetterError<'_> {
/// logs the error with the builtin logger
pub fn log(&self) {
Expand Down
3 changes: 2 additions & 1 deletion src/high/engine/convars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ impl ConVarRegister {
}
}

// TODO: rewrite convars with thread_local!
// so the convars have to init at mod scope with a macro
// sync and send must be removed from ConVarStruct to forbid unsafe access with race condition
// altought a unsafe way of initing the ConVarStruct should be given
Expand Down Expand Up @@ -406,6 +405,8 @@ impl ConVarStruct {
}

// TODO: add exclusive access set_value s aka &mut self
// this might not be needed acutally since this acts like a Cell where you can't get a reference to internal parts
// well the string can be referenced but eh ub is fine ig XD
// this really should not be a &self

/// set the int value of the convar
Expand Down
2 changes: 1 addition & 1 deletion src/high/engine_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub unsafe fn run_async_routine() {
let result = unsafe {
(sqfunctions.sq_getfunction)(
sqvm.as_ptr(),
to_cstring(&function_name).as_ptr(), // TODO: safe or not?
to_cstring(&function_name).as_ptr(),
function_obj.as_mut_ptr(),
std::ptr::null(),
)
Expand Down
1 change: 0 additions & 1 deletion src/high/squirrel_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ impl<T: PushToSquirrelVm + Send + Sync + 'static> IntoSquirrelArgs for T {
}
}

// TODO: format this
// TODO: check for correctness
macro_rules! into_squirrel_args_impl{
( $( ($($ty_name: ident : $tuple_index:tt),*) );*; ) => { $(
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod test {
use crate::rrplug;
use rrplug_proc::as_interface;

#[allow(dead_code)] // TODO: fix later
#[allow(dead_code)]
#[repr(C)]
struct TestInterface {
the_line: &'static str,
Expand Down
27 changes: 25 additions & 2 deletions src/macros/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ macro_rules! entry {

use high::engine::EngineData;
use mid::squirrel::SQFUNCTIONS;
use std::ffi::{CStr, CString};
use $crate::bindings::{plugin_abi, squirrelclasstypes, squirreldatatypes};
use $crate::exports::log;
use $crate::exports::windows::{
core::PCSTR, Win32::System::LibraryLoader::GetModuleHandleA,
};
use $crate::interfaces::external::SourceInterface;
use $crate::plugin::Plugin;
use $crate::rrplug;
use $crate::{high, mid};

use std::ffi::CString;

pub static PLUGIN: $crate::exports::OnceCell<$plugin> =
$crate::exports::OnceCell::new();

Expand Down Expand Up @@ -111,6 +113,27 @@ macro_rules! entry {
if PLUGIN.set(plugin).is_err() {
panic!("PLUGIN failed initialization")
}

if reloaded {
const ENGINE: &CStr = c"engine.dll";
const SERVER: &CStr = c"server.dll";
const CLIENT: &CStr = c"client.dll";
unsafe {
_ = self.OnLibraryLoaded(
GetModuleHandleA(PCSTR(ENGINE.as_ptr().cast()))
.expect("engine.dll should exists if called for reload"),
ENGINE.as_ptr(),
);
if let Ok(handle) = GetModuleHandleA(PCSTR(CLIENT.as_ptr().cast())) {
self.OnLibraryLoaded(handle, CLIENT.as_ptr());
} // client gets loaded before server
self.OnLibraryLoaded(
GetModuleHandleA(PCSTR(SERVER.as_ptr().cast()))
.expect("server.dll should exists if called for reload"),
SERVER.as_ptr(),
);
}
}
}
fn Finalize(&self) {
PLUGIN
Expand Down
32 changes: 0 additions & 32 deletions src/macros/sq_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,38 +122,6 @@ macro_rules! call_sq_object_function {
)
}

// TODO: remove this
/*
/// calls any function defined on the sqvm
/// the call will happen on the next engine frame
///
/// macro version of [`crate::high::squirrel::async_call_sq_function`], used to call a function with args
///
/// ## example
/// ```no_run
/// # use rrplug::prelude::*;
///
/// rrplug::async_call_sq_function!(ScriptVmType::Client, "SomeSQFunc", 9347, "Test".to_string());
/// ```
#[macro_export]
macro_rules! async_call_sq_function {
($context:expr, $function_name:expr, $( $arg:expr ),* ) => (
$crate::high::squirrel::async_call_sq_function(
$context,
$function_name,
Some( Box::new( move |sqvm,sqfunctions| {
use $crate::high::squirrel_traits::PushToSquirrelVm;
$(
$arg.push_to_sqvm(sqvm, sqfunctions);
)*
$crate::macros::sq_utils::__arg_count_helper([$($crate::__replace_expr!($arg)),*]) as i32
} )),
)
);
}
*/

/// internal macro used in counting args in some macros
#[doc(hidden)]
#[macro_export]
Expand Down
1 change: 0 additions & 1 deletion src/mid/engine/concommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ impl RegisterConCommands {
help_string: &str,
flags: i32,
) -> Result<*mut ConCommand, RegisterError> {
// TODO: use IMemAlloc here
let name = try_cstring(name)?.into_bytes_with_nul();
let name_ptr =
unsafe {
Expand Down
11 changes: 9 additions & 2 deletions src/mid/reloading.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
//! rrplug's prototype of a plugin reloading system
/// the reponse to a unload event
///
/// # Difficulties
/// the main issue arises from dangling pointers since the moment a plugin is reloaded callbacks, sqfunctions, etc will start calling into uninit memory.
/// which may be hard to handle at times.
///
/// the other issue is reinstating the plugin. rrplug will get back up by getting handles to engine, client and server in order
/// but squirrel cannot be fully restorted so it's best to reset all vms.
pub struct ReloadResponse {
should_reload: bool,
}
Expand All @@ -22,9 +29,9 @@ impl ReloadResponse {
///
/// # Safety
///
/// this will create ub!
/// **this will create ub!**
///
/// **unless** before calling this everything will cleaned up!
/// **unless** before calling this everything will be cleaned up!
///
/// ex: convars, concommands, sqfunctions (sqvm reload), hooks, etc
pub const unsafe fn allow_reload() -> Self {
Expand Down

0 comments on commit 9225a49

Please sign in to comment.