mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 10:09:43 +01:00
Patch potential crash scenarios and remove warnings.
This commit is contained in:
parent
0a1244bd2a
commit
7975b27e7c
2 changed files with 40 additions and 28 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <SDL.h>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#else
|
#else
|
||||||
|
@ -12,9 +13,11 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "Vlogging.h"
|
||||||
|
|
||||||
// Library includes
|
// Library includes
|
||||||
#include "discord_game_sdk.h"
|
#include "discord_game_sdk.h"
|
||||||
#include <SDL.h>
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#define DISCORD_LIBRARY "discord_game_sdk.dll"
|
#define DISCORD_LIBRARY "discord_game_sdk.dll"
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
|
@ -25,18 +28,19 @@
|
||||||
#error DISCORD_LIBRARY: Unrecognized platform!
|
#error DISCORD_LIBRARY: Unrecognized platform!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Vlogging.h"
|
|
||||||
|
#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_REQUIRE(x) assert(x == DiscordResult_Ok)
|
struct DISCORD_application {
|
||||||
|
|
||||||
struct Application {
|
|
||||||
struct IDiscordCore* core;
|
struct IDiscordCore* core;
|
||||||
struct IDiscordActivityManager* activityMan;
|
struct IDiscordActivityManager* activityMan;
|
||||||
};
|
} app;
|
||||||
|
|
||||||
struct DiscordActivity activity;
|
struct DiscordActivity activity;
|
||||||
struct Application app;
|
|
||||||
|
int discordCrashes = 0; // This is here to ensure we do not get stuck in a theoratical softlock of opening and crashing Discord instances.
|
||||||
|
|
||||||
static void* libHandle = NULL;
|
static void* libHandle = NULL;
|
||||||
|
|
||||||
|
@ -59,6 +63,13 @@ static void ClearPointers(void)
|
||||||
#undef FOREACH_FUNC
|
#undef FOREACH_FUNC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DISCORD_shutdown(void)
|
||||||
|
{
|
||||||
|
if (libHandle)
|
||||||
|
{
|
||||||
|
ClearPointers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int32_t DISCORD_init(void)
|
int32_t DISCORD_init(void)
|
||||||
{
|
{
|
||||||
|
@ -86,7 +97,7 @@ int32_t DISCORD_init(void)
|
||||||
memset(&app, 0, sizeof(app));
|
memset(&app, 0, sizeof(app));
|
||||||
|
|
||||||
struct DiscordCreateParams params;
|
struct DiscordCreateParams params;
|
||||||
params.client_id = 1315544357532729447;
|
params.client_id = DISCORD_CLIENT_ID;
|
||||||
params.flags = DiscordCreateFlags_Default;
|
params.flags = DiscordCreateFlags_Default;
|
||||||
|
|
||||||
if(!DiscordCreate(DISCORD_VERSION, ¶ms, &app.core))
|
if(!DiscordCreate(DISCORD_VERSION, ¶ms, &app.core))
|
||||||
|
@ -108,8 +119,27 @@ int32_t DISCORD_init(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DISCORD_REQUIRE(int x) {
|
||||||
|
if(discordCrashes > DISCORD_CRASH_LIMIT)
|
||||||
|
{
|
||||||
|
DISCORD_shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(x != DiscordResult_Ok)
|
||||||
|
{
|
||||||
|
++discordCrashes;
|
||||||
|
DISCORD_shutdown();
|
||||||
|
DISCORD_init();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
discordCrashes = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void DISCORD_update(const char *level, const char *name)
|
void DISCORD_update(const char *level, const char *name)
|
||||||
{
|
{
|
||||||
|
if(discordCrashes > DISCORD_CRASH_LIMIT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(app.activityMan == NULL)
|
if(app.activityMan == NULL)
|
||||||
{
|
{
|
||||||
app.activityMan = app.core->get_activity_manager(app.core);
|
app.activityMan = app.core->get_activity_manager(app.core);
|
||||||
|
@ -130,9 +160,6 @@ void DISCORD_unlockAchievement(const char *name)
|
||||||
// No "achivements" in Discord
|
// No "achivements" in Discord
|
||||||
}
|
}
|
||||||
|
|
||||||
void DISCORD_shutdown(void)
|
|
||||||
{
|
|
||||||
// ???
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // MakeAndPlay
|
#endif // MakeAndPlay
|
||||||
|
|
|
@ -703,22 +703,7 @@ inline
|
||||||
#else
|
#else
|
||||||
static
|
static
|
||||||
#endif
|
#endif
|
||||||
void DiscordCreateParamsSetDefault(struct DiscordCreateParams* params)
|
|
||||||
{
|
|
||||||
memset(params, 0, sizeof(struct DiscordCreateParams));
|
|
||||||
params->application_version = DISCORD_APPLICATION_MANAGER_VERSION;
|
|
||||||
params->user_version = DISCORD_USER_MANAGER_VERSION;
|
|
||||||
params->image_version = DISCORD_IMAGE_MANAGER_VERSION;
|
|
||||||
params->activity_version = DISCORD_ACTIVITY_MANAGER_VERSION;
|
|
||||||
params->relationship_version = DISCORD_RELATIONSHIP_MANAGER_VERSION;
|
|
||||||
params->lobby_version = DISCORD_LOBBY_MANAGER_VERSION;
|
|
||||||
params->network_version = DISCORD_NETWORK_MANAGER_VERSION;
|
|
||||||
params->overlay_version = DISCORD_OVERLAY_MANAGER_VERSION;
|
|
||||||
params->storage_version = DISCORD_STORAGE_MANAGER_VERSION;
|
|
||||||
params->store_version = DISCORD_STORE_MANAGER_VERSION;
|
|
||||||
params->voice_version = DISCORD_VOICE_MANAGER_VERSION;
|
|
||||||
params->achievement_version = DISCORD_ACHIEVEMENT_MANAGER_VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Reference in a new issue