-
Notifications
You must be signed in to change notification settings - Fork 558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Discord Game SDK support #1217
Open
Buggem
wants to merge
19
commits into
TerryCavanagh:master
Choose a base branch
from
Buggem:discordrpc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
eb21260
Add Discord Network support.
Buggem 0a1244b
Dynamically load Discord Game SDK with `SDL_LoadObject()` to avoid CM…
Buggem 7975b27
Patch potential crash scenarios and remove warnings.
Buggem 76d5738
Replace `strncpy` with `SDL_strncpy`
Buggem 76d4368
Remove unneeded headerfiles, .vscode folder, and move comment
Buggem ce111cf
Make Discord not required to exist - thanks @Daaaav
Buggem 7d3e7db
Avoid segfault if Discord is not detected, remove useless headerfiles
Buggem 17fea40
Remove localisation features from the RPC, as people on English Disco…
Buggem 459437c
Remove placeholder
Buggem 7fcba85
Add @Daaaav's changes (full changelog below)
Buggem 5cbf03d
Fix bad implementation of inversion of discordDetected
Buggem 132c504
finish off naming convention = type*
Buggem 29708db
Finish @Daaaav's requests :D
Buggem 3b5108e
More requests (see full changelog below)
Buggem bef03b6
consistancy
Buggem d35fb29
maybe remove console spam (seperate commit to consider reverts)
Buggem 9c05ffe
Finish formatting
Buggem 731f2ce
Merge branch 'TerryCavanagh:master' into discordrpc
Buggem 6e5fed0
Add more names for different areas of the game IG
Buggem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
#include "MakeAndPlay.h" | ||
|
||
#ifndef MAKEANDPLAY | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include <SDL.h> | ||
|
||
#include "Vlogging.h" | ||
|
||
// Library includes | ||
#include "discord_game_sdk.h" | ||
|
||
#if defined(_WIN32) | ||
#define DISCORD_LIBRARY "discord_game_sdk.dll" | ||
#elif defined(__APPLE__) | ||
#define DISCORD_LIBRARY "libdiscord_game_sdk.dylib" | ||
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__) || defined(__DragonFly__) | ||
#define DISCORD_LIBRARY "libdiscord_game_sdk.so" | ||
#else | ||
#error DISCORD_LIBRARY: Unrecognized platform! | ||
#endif | ||
|
||
|
||
#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 { | ||
struct IDiscordCore* core; | ||
struct IDiscordActivityManager* activityMan; | ||
} app; | ||
|
||
struct DiscordActivity activity; | ||
|
||
bool discordDetected = false; | ||
bool discordPostInit = false; | ||
|
||
|
||
static void* libHandle = NULL; | ||
|
||
|
||
|
||
#define FUNC_LIST \ | ||
FOREACH_FUNC(enum EDiscordResult, DiscordCreate, (DiscordVersion, struct DiscordCreateParams*, struct IDiscordCore**)) | ||
|
||
|
||
|
||
#define FOREACH_FUNC(rettype, name, params) static rettype (*name) params = NULL; | ||
FUNC_LIST | ||
#undef FOREACH_FUNC | ||
|
||
bool DISCORD_REQUIRE(int x) | ||
{ | ||
if (!discordDetected && discordPostInit) | ||
{ | ||
return false; | ||
} | ||
if (x != DiscordResult_Ok) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
|
||
|
||
static void ClearPointers(void) | ||
{ | ||
SDL_UnloadObject(libHandle); | ||
libHandle = NULL; | ||
#define FOREACH_FUNC(rettype, name, params) name = NULL; | ||
FUNC_LIST | ||
#undef FOREACH_FUNC | ||
} | ||
|
||
void DISCORD_shutdown(void) | ||
{ | ||
if (libHandle != NULL) | ||
{ | ||
app.core->destroy(app.core); | ||
ClearPointers(); | ||
} | ||
} | ||
|
||
int32_t DISCORD_init(void) | ||
{ | ||
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__) || defined(__DragonFly__) | ||
return 0; | ||
#endif | ||
libHandle = SDL_LoadObject(DISCORD_LIBRARY); | ||
if (libHandle == NULL) | ||
{ | ||
vlog_info(DISCORD_LIBRARY " not found!"); | ||
vlog_debug("Can't load object %s : %s\n", DISCORD_LIBRARY, SDL_GetError()); | ||
return 0; | ||
} | ||
|
||
#define FOREACH_FUNC(rettype, name, params) \ | ||
name = (rettype (*) params) (intptr_t) SDL_LoadFunction(libHandle, #name); \ | ||
if (!name) \ | ||
{ \ | ||
vlog_error(DISCORD_LIBRARY " symbol " #name " not found!"); \ | ||
ClearPointers(); \ | ||
return 0; \ | ||
} | ||
FUNC_LIST | ||
#undef FOREACH_FUNC | ||
SDL_memset(&app, 0, sizeof(app)); | ||
|
||
struct DiscordCreateParams params; | ||
params.client_id = DISCORD_CLIENT_ID; | ||
params.flags = DiscordCreateFlags_NoRequireDiscord; | ||
|
||
if (!DISCORD_REQUIRE(DiscordCreate(DISCORD_VERSION, ¶ms, &app.core))) | ||
{ // Discord's API couldn't initialise, so just ignore it | ||
discordPostInit = true; // even if it fails, set post init to true. | ||
vlog_debug("Discord API failed to initialise!"); | ||
discordDetected = false; | ||
return 0; | ||
} | ||
|
||
if (app.core == NULL) | ||
{ | ||
discordPostInit = true; | ||
vlog_debug("app.core == null. DiscordCreate failed with a positive result?\nCheck DISCORD_REQUIRE for bugs."); | ||
discordDetected = false; | ||
return 0; | ||
} | ||
discordPostInit = true; | ||
|
||
// Placeholder, is this really nesaccary | ||
SDL_strlcpy(activity.assets.large_image, "vvvvvv", sizeof(activity.assets.large_image)); | ||
SDL_strlcpy(activity.assets.large_text, "Outside Dimension VVVVVV", sizeof(activity.assets.large_text)); | ||
|
||
app.activityMan = app.core->get_activity_manager(app.core); | ||
app.activityMan->update_activity(app.activityMan, &activity, NULL, NULL); | ||
|
||
|
||
discordDetected = true; | ||
return 1; | ||
} | ||
|
||
void DISCORD_update(const char* area, const char* roomname) | ||
{ | ||
if (libHandle == NULL) | ||
{ | ||
// no discord or just shutdown | ||
return; | ||
} | ||
if (app.core == NULL || !discordDetected) | ||
{ | ||
// No Discord | ||
return; | ||
} | ||
if (!DISCORD_REQUIRE(app.core->run_callbacks(app.core))) | ||
{ | ||
// Something or other is wrong, but do we care? | ||
return; | ||
} | ||
if (app.activityMan == NULL) | ||
{ | ||
vlog_debug("No activityMan! - it\'s fine, we can recreate this" ); | ||
app.activityMan = app.core->get_activity_manager(app.core); | ||
} | ||
if (SDL_strcmp(activity.state, roomname) != 0 || SDL_strcmp(activity.assets.large_text, area) != 0) | ||
{ | ||
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, area, sizeof(activity.assets.large_text)); | ||
|
||
app.activityMan->update_activity(app.activityMan, &activity, NULL, NULL); | ||
} | ||
} | ||
void DISCORD_unlockAchievement(const char *name) | ||
{ | ||
// No "achievements" in Discord | ||
} | ||
|
||
|
||
|
||
#endif // MakeAndPlay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TerryCavanagh, does this already exist...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference, the Discord docs do say this:
I wonder whether the reasons to use the ID they already have are good enough reasons to bother lol (maybe so it smoothly takes over the "Playing VVVVVV", "last played 2 days ago", etc that was already showing without rich presence?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Daaaav @flibitijibibo I have sent a message to Discord Support to see if this is true for VVVVVV. Hopefully I get a response before the 15th anniversary of VVVVVV. (I'm hoping this will be released then)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure an application already exists for VVVVVV, as it existed on the Discord Game Store back when that existed.