From 1f07882b4922cb621829d984fc2b435adf57182e Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Mon, 24 May 2021 15:09:19 +0000 Subject: [PATCH] Added discord rpc timestamps --- src/moon/texts/moon-loader.cpp | 2 +- src/pc/discord/discordrpc.cpp | 22 +++++++++++++++++----- src/pc/discord/discordrpc.h | 5 +++-- src/pc/pc_main.c | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/moon/texts/moon-loader.cpp b/src/moon/texts/moon-loader.cpp index f8387874..d3549f8e 100644 --- a/src/moon/texts/moon-loader.cpp +++ b/src/moon/texts/moon-loader.cpp @@ -169,7 +169,7 @@ namespace Moon { seg2_act_name_table = current->acts.data(); seg2_course_name_table = current->courses.data(); #ifdef DISCORDRPC - DiscordUpdatePresence(true); + DiscordReloadPresence(); #endif } diff --git a/src/pc/discord/discordrpc.cpp b/src/pc/discord/discordrpc.cpp index c4546247..d7c4736b 100644 --- a/src/pc/discord/discordrpc.cpp +++ b/src/pc/discord/discordrpc.cpp @@ -62,6 +62,7 @@ Discord_UpdatePresence discordUpdatePresence; static s16 lastCourseNum = -1; static s16 lastActNum = -1; +static int64_t timestamp; bool reloadRPC = false; static char stage[188]; @@ -156,6 +157,14 @@ static void init_discord(void) { initd = true; } +static void set_time(void){ + if (lastCourseNum != gCurrCourseNum) { + timestamp = 0; + discordRichPresence.startTimestamp = time(0); + lastCourseNum = gCurrCourseNum; + } +} + static void set_details(void) { if (lastCourseNum != gCurrCourseNum || reloadRPC) { // If we are in in Course 0 we are in the castle which doesn't have a string @@ -201,13 +210,16 @@ void set_logo(void) { discordRichPresence.largeImageKey = largeImageKey; } -void DiscordUpdatePresence(bool force){ - if(force) - reloadRPC = true; +void DiscordReloadPresence() { + reloadRPC = true; +} + +void DiscordUpdatePresence(){ if (!configDiscordRPC || !initd) return; if (time(NULL) < lastUpdatedTime + DISCORD_UPDATE_RATE) return; lastUpdatedTime = time(NULL); + set_time(); set_state(); set_details(); set_logo(); @@ -216,8 +228,8 @@ void DiscordUpdatePresence(bool force){ } extern "C" { -void discord_update_rich_presence(bool force) { - DiscordUpdatePresence(force); +void discord_update_rich_presence() { + DiscordUpdatePresence(); } void discord_shutdown(void) { diff --git a/src/pc/discord/discordrpc.h b/src/pc/discord/discordrpc.h index 2969e0ee..57a76e6a 100644 --- a/src/pc/discord/discordrpc.h +++ b/src/pc/discord/discordrpc.h @@ -43,11 +43,12 @@ typedef struct DiscordEventHandlers { void discord_reset(void); #ifndef __cplusplus -void discord_update_rich_presence(bool force); +void discord_update_rich_presence(); void discord_shutdown(void); void discord_init(void); #else -void DiscordUpdatePresence(bool force); +void DiscordReloadPresence(); +void DiscordUpdatePresence(); #endif #endif // DISCORDRPC_H diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index e10d0611..7e8b08d9 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -266,7 +266,7 @@ void main_func(char *argv[]) { while (true) { wm_api->main_loop(produce_one_frame); #ifdef DISCORDRPC - discord_update_rich_presence(0); + discord_update_rich_presence(); #endif } #endif