mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2025-01-08 09:59:45 +01:00
Dynamically load Discord Game SDK with SDL_LoadObject()
to avoid CMake issues.
This commit is contained in:
parent
eb21260221
commit
0a1244bd2a
5 changed files with 55 additions and 6 deletions
1
.vscode/settings.json
vendored
Normal file
1
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{}
|
|
@ -360,10 +360,6 @@ add_library(c-hashmap-static STATIC ${CHM_SRC})
|
||||||
|
|
||||||
add_library(sheenbidi-static STATIC ${SBIDI_SRC})
|
add_library(sheenbidi-static STATIC ${SBIDI_SRC})
|
||||||
|
|
||||||
# Link after we did all of the other initialisation
|
|
||||||
if(DISCORD)
|
|
||||||
target_link_options(VVVVVV PRIVATE ../../third_party/libdiscord_game_sdk.so)
|
|
||||||
endif()
|
|
||||||
target_compile_definitions(sheenbidi-static PRIVATE
|
target_compile_definitions(sheenbidi-static PRIVATE
|
||||||
-DSB_CONFIG_UNITY
|
-DSB_CONFIG_UNITY
|
||||||
)
|
)
|
||||||
|
|
|
@ -13,8 +13,20 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Library includes
|
// Library includes
|
||||||
|
#include "discord_game_sdk.h"
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include "discord_game_sdk.h" // DISCORD HEADERS REQUIRE LINKING AT RUNTIME!!!!!
|
#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
|
||||||
|
|
||||||
|
#include "Vlogging.h"
|
||||||
|
|
||||||
|
|
||||||
#define DISCORD_REQUIRE(x) assert(x == DiscordResult_Ok)
|
#define DISCORD_REQUIRE(x) assert(x == DiscordResult_Ok)
|
||||||
|
|
||||||
|
@ -26,10 +38,51 @@ struct Application {
|
||||||
struct DiscordActivity activity;
|
struct DiscordActivity activity;
|
||||||
struct Application app;
|
struct Application app;
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
static void ClearPointers(void)
|
||||||
|
{
|
||||||
|
SDL_UnloadObject(libHandle);
|
||||||
|
libHandle = NULL;
|
||||||
|
#define FOREACH_FUNC(rettype, name, params) name = NULL;
|
||||||
|
FUNC_LIST
|
||||||
|
#undef FOREACH_FUNC
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t DISCORD_init(void)
|
int32_t DISCORD_init(void)
|
||||||
{
|
{
|
||||||
|
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__) || defined(__DragonFly__)
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
libHandle = SDL_LoadObject(DISCORD_LIBRARY);
|
||||||
|
if (!libHandle)
|
||||||
|
{
|
||||||
|
vlog_info(DISCORD_LIBRARY " not found!");
|
||||||
|
printf("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
|
||||||
memset(&app, 0, sizeof(app));
|
memset(&app, 0, sizeof(app));
|
||||||
|
|
||||||
struct DiscordCreateParams params;
|
struct DiscordCreateParams params;
|
||||||
|
|
|
@ -720,7 +720,6 @@ void DiscordCreateParamsSetDefault(struct DiscordCreateParams* params)
|
||||||
params->achievement_version = DISCORD_ACHIEVEMENT_MANAGER_VERSION;
|
params->achievement_version = DISCORD_ACHIEVEMENT_MANAGER_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum EDiscordResult DISCORD_API DiscordCreate(DiscordVersion version, struct DiscordCreateParams* params, struct IDiscordCore** result);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue