From 7fcba8510e9726aa052cb888a54e0fcfbeef95cc Mon Sep 17 00:00:00 2001 From: Buggem's Fedora PC <66670928+Buggem@users.noreply.github.com> Date: Sun, 15 Dec 2024 19:40:42 +1100 Subject: [PATCH] Add @Daaaav's changes (full changelog below) - remove more useless headerfiles - rename [level, name] to [area, roomname] - remove 10 repeats fallback - do not update_activity if it is the same value as last DISCORD_update - fix bug with DiscordCreate failure handling - rename (and invert) discordNotDetected to discordDetected --- desktop_version/src/DiscordNetwork.c | 48 +++++++++++++--------------- desktop_version/src/GOGNetwork.c | 4 +-- desktop_version/src/Network.c | 6 ++-- desktop_version/src/Network.h | 2 +- desktop_version/src/SteamNetwork.c | 2 +- 5 files changed, 29 insertions(+), 33 deletions(-) diff --git a/desktop_version/src/DiscordNetwork.c b/desktop_version/src/DiscordNetwork.c index e9ec6baa..2ca16ba9 100644 --- a/desktop_version/src/DiscordNetwork.c +++ b/desktop_version/src/DiscordNetwork.c @@ -3,7 +3,6 @@ #ifndef MAKEANDPLAY #include -#include #include #include @@ -23,8 +22,9 @@ #endif -#define DISCORD_CRASH_LIMIT 10 -#define DISCORD_CLIENT_ID 1315544357532729447 // TO TERRY/FLIBIT: You can create your own Discord instance at the Discord Developer Portal. This ID belongs to me, so just be aware that if my account was to get hacked, VVVVVV RPC would too. Use your own! +#define DISCORD_CLIENT_ID 1315544357532729447 + +// TO TERRY/FLIBIT: You can create your own Discord instance at the Discord Developer Portal. This ID belongs to me, so just be aware that if my account was to get hacked, VVVVVV RPC would too. Use your own! struct DISCORD_application { @@ -34,8 +34,7 @@ struct DISCORD_application { struct DiscordActivity activity; -bool discordNotDetected = false; -int discordCrashes = 0; // This is here to ensure we do not get stuck in a theoratical softlock of opening and crashing Discord instances. +bool discordDetected = false; static void* libHandle = NULL; @@ -95,14 +94,14 @@ int32_t DISCORD_init(void) params.client_id = DISCORD_CLIENT_ID; params.flags = DiscordCreateFlags_NoRequireDiscord; - if(!DiscordCreate(DISCORD_VERSION, ¶ms, &app.core)) + if(DiscordCreate(DISCORD_VERSION, ¶ms, &app.core) != DiscordResult_Ok) { - return 1; + return 0; } if(app.core == NULL) { - discordNotDetected = true; + discordDetected = false; return 0; } @@ -115,41 +114,38 @@ int32_t DISCORD_init(void) - return 0; + return 1; } -void DISCORD_REQUIRE(int x) { - if(discordNotDetected) +bool DISCORD_REQUIRE(int x) { + if(!discordDetected) { - return; - } - if(discordCrashes > DISCORD_CRASH_LIMIT) - { - DISCORD_shutdown(); - return; + return false; } if(x != DiscordResult_Ok) { - ++discordCrashes; - DISCORD_shutdown(); - DISCORD_init(); - return; + return false; } - discordCrashes = 0; + return true; } -void DISCORD_update(const char *level, const char *name) +void DISCORD_update(const char* area, const char* roomname) { - if(discordCrashes > DISCORD_CRASH_LIMIT) { + if(app.core == NULL) { return; } if(app.activityMan == NULL) { app.activityMan = app.core->get_activity_manager(app.core); } - SDL_strlcpy(activity.state, name, sizeof(activity.state)); + if(activity.state == roomname || activity.assets.large_text == area) + { + DISCORD_REQUIRE(app.core->run_callbacks(app.core)); + return; + } + SDL_strlcpy(activity.state, roomname, sizeof(activity.state)); SDL_strlcpy(activity.assets.large_image, "vvvvvv", sizeof(activity.assets.large_image)); - SDL_strlcpy(activity.assets.large_text, level, sizeof(activity.assets.large_text)); + SDL_strlcpy(activity.assets.large_text, area, sizeof(activity.assets.large_text)); app.activityMan->update_activity(app.activityMan, &activity, NULL, NULL); diff --git a/desktop_version/src/GOGNetwork.c b/desktop_version/src/GOGNetwork.c index 74eaea74..bdd08bbe 100644 --- a/desktop_version/src/GOGNetwork.c +++ b/desktop_version/src/GOGNetwork.c @@ -15,11 +15,11 @@ void GOG_shutdown(void) { } -void GOG_update(const char *level, const char *name) +void GOG_update(const char* area, const char* roomname) { } -void GOG_unlockAchievement(const char *name) +void GOG_unlockAchievement(const char* name) { } diff --git a/desktop_version/src/Network.c b/desktop_version/src/Network.c index 62c8a6a6..7a52a7d5 100644 --- a/desktop_version/src/Network.c +++ b/desktop_version/src/Network.c @@ -36,7 +36,7 @@ #define DECLARE_BACKEND(name) \ int32_t name##_init(void); \ void name##_shutdown(void); \ - void name##_update(const char *level, const char *name); \ + void name##_update(const char *area, const char *roomname); \ void name##_unlockAchievement(const char *name); #ifdef STEAM_NETWORK DECLARE_BACKEND(STEAM) @@ -104,14 +104,14 @@ void NETWORK_shutdown(void) #endif } -void NETWORK_update(const char *level, const char *name) +void NETWORK_update(const char *area, const char *roomname) { #if NUM_BACKENDS > 0 int32_t i; for (i = 0; i < NUM_BACKENDS; i += 1) if (backends[i].IsInit) { - backends[i].Update(level, name); + backends[i].Update(area, roomname); } #endif } diff --git a/desktop_version/src/Network.h b/desktop_version/src/Network.h index 79b50e42..39ed5ce5 100644 --- a/desktop_version/src/Network.h +++ b/desktop_version/src/Network.h @@ -11,7 +11,7 @@ int32_t NETWORK_init(void); void NETWORK_shutdown(void); -void NETWORK_update(const char *level, const char *name); +void NETWORK_update(const char *area, const char *roomname); void NETWORK_unlockAchievement(const char *name); diff --git a/desktop_version/src/SteamNetwork.c b/desktop_version/src/SteamNetwork.c index fcf9cd08..1108bc5d 100644 --- a/desktop_version/src/SteamNetwork.c +++ b/desktop_version/src/SteamNetwork.c @@ -234,7 +234,7 @@ void STEAM_shutdown(void) } } -void STEAM_update(const char *level, const char *name) +void STEAM_update(const char* area, const char* roomname) { if (!libHandle) {