Skip to content

Commit

Permalink
Bump rrplug to 4.0.0 (#24)
Browse files Browse the repository at this point in the history
from tracking specific git commit
and update logic accordingly where necessary


Co-authored-by: cat_or_not <[email protected]>
  • Loading branch information
GeckoEidechse and catornot authored Jul 6, 2024
1 parent 9fb9f7d commit 45c4659
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 34 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down Expand Up @@ -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() })
}
_ => {}
}
Expand Down
40 changes: 13 additions & 27 deletions src/presence.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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<HSquirrelVM>) {
let sq_functions = SQFUNCTIONS.client.wait();

if let Err(err) = compile_string(
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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
});
}
}
}
Expand Down

0 comments on commit 45c4659

Please sign in to comment.