1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59:43 +01:00

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
This commit is contained in:
Buggem's Fedora PC 2024-12-15 19:40:42 +11:00
parent 459437cbac
commit 7fcba8510e
5 changed files with 29 additions and 33 deletions

View file

@ -3,7 +3,6 @@
#ifndef MAKEANDPLAY
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <SDL.h>
@ -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, &params, &app.core))
if(DiscordCreate(DISCORD_VERSION, &params, &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);

View file

@ -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)
{
}

View file

@ -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
}

View file

@ -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);

View file

@ -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)
{