Skip to content

Commit

Permalink
update to v4
Browse files Browse the repository at this point in the history
  • Loading branch information
catornot committed Jan 20, 2024
1 parent 9a64853 commit 6fcd114
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 247 deletions.
275 changes: 165 additions & 110 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rrplug = "=3.0.0"
rrplug = { git = "https://github.com/R2NorthstarTools/rrplug.git", rev = "3a31f4a9173d2e82f8d4b2a30bafa3faf57a5158" }
discord-sdk = "0.3.2"
tokio = "1.26.0"
parking_lot = "0.12.1"

[build-dependencies]
windres = "0.2.2"
uuid = { version = "1.7.0", features = ["v4"] }

[lib]
name = "DiscordRPC"
Expand Down
8 changes: 0 additions & 8 deletions build.rs

This file was deleted.

95 changes: 0 additions & 95 deletions manifest/Resource.rc

This file was deleted.

10 changes: 0 additions & 10 deletions manifest/manifest.json

This file was deleted.

11 changes: 0 additions & 11 deletions manifest/resource.h

This file was deleted.

6 changes: 4 additions & 2 deletions src/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use rrplug::prelude::*;
use crate::exports::PLUGIN;

/// the discord app's id, taken from older v1 discord rpc
const APP_ID: i64 = 941428101429231617;
// const APP_ID: i64 = 941428101429231617;
const APP_ID: i64 = 1198009103516180500;

/// struct to hold everything required to run discord rpc
pub struct Client {
Expand Down Expand Up @@ -59,7 +60,8 @@ pub async fn async_main() {
large_text: data.large_text,
small_image: data.small_image,
small_text: data.small_text,
});
})
.secrets(data.secrets);

if let Some(start) = data.start {
activity_builder = activity_builder.start_timestamp(if start == 0 { 1 } else { start });
Expand Down
49 changes: 44 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#![allow(non_snake_case)]

use discord_sdk::activity::Secrets;
use parking_lot::Mutex;
use rrplug::prelude::*;
use rrplug::{bindings::cvar::convar::FCVAR_CLIENTDLL, prelude::*};
use tokio::runtime::Runtime;
use uuid::Uuid;

use crate::{
discord::async_main,
Expand All @@ -28,6 +30,7 @@ pub struct ActivityData {
end: Option<i64>,
start: Option<i64>,
last_state: GameState,
secrets: Secrets,
}

#[deny(non_snake_case)]
Expand All @@ -38,8 +41,15 @@ pub struct DiscordRpcPlugin {

#[deny(non_snake_case)]
impl Plugin for DiscordRpcPlugin {
fn new(plugin_data: &PluginData) -> Self {
plugin_data.register_sq_functions(presence::fetch_presence);
const PLUGIN_INFO: PluginInfo = PluginInfo::new(
"DISCORDRPC\0",
"DISCORDXD\0",
"DISCORDRPC\0",
PluginContext::CLIENT,
);

fn new(_: bool) -> Self {
register_sq_functions(presence::fetch_presence);

let activity = Mutex::new(ActivityData {
large_image: Some("northstar".to_string()),
Expand All @@ -61,14 +71,43 @@ impl Plugin for DiscordRpcPlugin {
}
}

fn on_sqvm_created(&self, sqvm_handle: &CSquirrelVMHandle) {
fn on_sqvm_created(&self, sqvm_handle: &CSquirrelVMHandle, _: EngineToken) {
match sqvm_handle.get_context() {
ScriptVmType::Client | ScriptVmType::Ui => {
ScriptContext::CLIENT | ScriptContext::UI => {
run_presence_updates(unsafe { sqvm_handle.get_sqvm() })
}
_ => {}
}
}

fn on_dll_load(
&self,
engine_data: Option<&EngineData>,
_dll_ptr: &DLLPointer,
_engine_token: EngineToken,
) {
let Some(engine_data) = engine_data else {
return;
};

engine_data
.register_concommand(
"discord_rpc_reload_secrets",
reload_secrets,
"reloads the secrets for joining games",
FCVAR_CLIENTDLL as i32,
)
.expect("couldn't register reload secrets");
}
}

#[rrplug::concommand]
fn reload_secrets() {
PLUGIN.wait().activity.lock().secrets = Secrets {
r#match: Uuid::new_v4().to_string().into(),
join: Uuid::new_v4().to_string().into(),
spectate: None,
};
}

entry!(DiscordRpcPlugin);
4 changes: 2 additions & 2 deletions src/presence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ pub fn run_presence_updates(sqvm: UnsafeHandle<*mut HSquirrelVM>) {
"#,
) {
err.log()
}
};
}

/// function to pull presence from the sqvm since in runframe it's impossibke to get the output of a function back
#[rrplug::sqfunction(VM = "UiClient", ExportName = "FetchPresence")]
#[rrplug::sqfunction(VM = "UI | CLIENT", ExportName = "FetchPresence")]
pub fn fetch_presence() -> Result<(), String> {
let plugin = crate::PLUGIN.wait();
let mut presence_lock = plugin.presence_data.lock();
Expand Down

0 comments on commit 6fcd114

Please sign in to comment.