From 45c46596bad5598446a4a5f003e0da2d6a1a01ca Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Sat, 6 Jul 2024 02:20:33 +0200 Subject: [PATCH] Bump rrplug to `4.0.0` (#24) from tracking specific git commit and update logic accordingly where necessary Co-authored-by: cat_or_not <41955154+catornot@users.noreply.github.com> --- Cargo.lock | 6 ++++-- Cargo.toml | 2 +- src/lib.rs | 8 ++++---- src/presence.rs | 40 +++++++++++++--------------------------- 4 files changed, 22 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d43c8c4..56e720e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -399,7 +399,8 @@ dependencies = [ [[package]] name = "rrplug" version = "4.0.0" -source = "git+https://github.com/R2NorthstarTools/rrplug.git?rev=209a8b4b478ab095e3186dd32a3ed29dc9dbffee#209a8b4b478ab095e3186dd32a3ed29dc9dbffee" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4beccc264275850d6526bc531934bbcb254b2350bb4a5723964ad6d95b4abd" dependencies = [ "bitflags 2.4.2", "log", @@ -413,7 +414,8 @@ dependencies = [ [[package]] name = "rrplug_proc" version = "4.0.0" -source = "git+https://github.com/R2NorthstarTools/rrplug.git?rev=209a8b4b478ab095e3186dd32a3ed29dc9dbffee#209a8b4b478ab095e3186dd32a3ed29dc9dbffee" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb023a15963bb3d031369610b680dc23c1bac985a3a352cacdd4cb9df9e038d0" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 1c60c48..07afdde 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rrplug = { git = "https://github.com/R2NorthstarTools/rrplug.git", rev = "209a8b4b478ab095e3186dd32a3ed29dc9dbffee" } +rrplug = "4.0.0" discord-sdk = "0.3.2" tokio = "1.26.0" parking_lot = "0.12.1" diff --git a/src/lib.rs b/src/lib.rs index fce812f..1ad92da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,9 +41,9 @@ pub struct DiscordRpcPlugin { #[deny(non_snake_case)] impl Plugin for DiscordRpcPlugin { const PLUGIN_INFO: PluginInfo = PluginInfo::new( - "DISCORDRPC\0", - "DSCRD-RPC\0", - "DISCORDRPC\0", + c"DISCORDRPC", + c"DSCRD-RPC", + c"DISCORDRPC", PluginContext::CLIENT, ); @@ -72,7 +72,7 @@ impl Plugin for DiscordRpcPlugin { fn on_sqvm_created(&self, sqvm_handle: &CSquirrelVMHandle, _: EngineToken) { match sqvm_handle.get_context() { ScriptContext::CLIENT | ScriptContext::UI => { - run_presence_updates(unsafe { sqvm_handle.get_sqvm() }) + run_presence_updates(unsafe { sqvm_handle.get_sqvm().take() }) } _ => {} } diff --git a/src/presence.rs b/src/presence.rs index de77d0f..0cda83d 100644 --- a/src/presence.rs +++ b/src/presence.rs @@ -1,11 +1,11 @@ #![deny(non_snake_case)] +use rrplug::mid::squirrel::sqvm_to_context; use rrplug::prelude::*; use rrplug::{ - bindings::squirrelclasstypes::ScriptContext, - call_sq_function, - high::{squirrel::compile_string, UnsafeHandle}, + bindings::squirrelclasstypes::ScriptContext, call_sq_function, high::squirrel::compile_string, }; +use std::ptr::NonNull; use std::{ ops::DerefMut, time::{SystemTime, UNIX_EPOCH}, @@ -14,8 +14,7 @@ use std::{ use crate::presense_bindings::{GameState, GameStateStruct, UIPresenceStruct}; // heartbeat for pulling presence -pub fn run_presence_updates(sqvm: UnsafeHandle<*mut HSquirrelVM>) { - let sqvm = *sqvm.get(); +pub fn run_presence_updates(sqvm: NonNull) { let sq_functions = SQFUNCTIONS.client.wait(); if let Err(err) = compile_string( @@ -42,18 +41,7 @@ pub fn fetch_presence() -> Result<(), String> { let plugin = crate::PLUGIN.wait(); let mut presence_lock = plugin.presence_data.lock(); let (cl_presence, ui_presence) = presence_lock.deref_mut(); - let sqvm = unsafe { sqvm.as_mut().ok_or_else(|| "None sqvm".to_string())? }; - let context = unsafe { - std::mem::transmute::<_, ScriptContext>( - sqvm.sharedState - .as_ref() - .ok_or_else(|| "None shared state".to_string())? - .cSquirrelVM - .as_ref() - .ok_or_else(|| "None csqvm".to_string())? - .vmContext, - ) - }; + let context = unsafe { sqvm_to_context(sqvm) }; match context { ScriptContext::CLIENT => { @@ -68,11 +56,10 @@ pub fn fetch_presence() -> Result<(), String> { #[cfg(not(debug_assertions))] drop(err); } else { - *cl_presence = GameStateStruct::get_from_sqvm( - sqvm, - SQFUNCTIONS.client.wait(), - sqvm._stackbase, - ); + *cl_presence = + GameStateStruct::get_from_sqvm(sqvm, SQFUNCTIONS.client.wait(), unsafe { + sqvm.as_ref()._stackbase + }); } } ScriptContext::UI => { @@ -89,11 +76,10 @@ pub fn fetch_presence() -> Result<(), String> { drop(err); } Ok(_) => { - *ui_presence = UIPresenceStruct::get_from_sqvm( - sqvm, - SQFUNCTIONS.client.wait(), - sqvm._stackbase, - ); + *ui_presence = + UIPresenceStruct::get_from_sqvm(sqvm, SQFUNCTIONS.client.wait(), unsafe { + sqvm.as_ref()._stackbase + }); } } }