diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/desktop_version/CMakeLists.txt b/desktop_version/CMakeLists.txt index 5ffc4117..cf764053 100644 --- a/desktop_version/CMakeLists.txt +++ b/desktop_version/CMakeLists.txt @@ -360,10 +360,6 @@ add_library(c-hashmap-static STATIC ${CHM_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 -DSB_CONFIG_UNITY ) diff --git a/desktop_version/src/DiscordNetwork.c b/desktop_version/src/DiscordNetwork.c index 93a05852..3b8e47cd 100644 --- a/desktop_version/src/DiscordNetwork.c +++ b/desktop_version/src/DiscordNetwork.c @@ -13,8 +13,20 @@ #endif // Library includes +#include "discord_game_sdk.h" #include -#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) @@ -26,10 +38,51 @@ struct Application { struct DiscordActivity activity; 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) { +#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)); struct DiscordCreateParams params; diff --git a/desktop_version/src/discord_game_sdk.h b/desktop_version/src/discord_game_sdk.h index 46187566..a7cc07b1 100644 --- a/desktop_version/src/discord_game_sdk.h +++ b/desktop_version/src/discord_game_sdk.h @@ -720,7 +720,6 @@ void DiscordCreateParamsSetDefault(struct DiscordCreateParams* params) params->achievement_version = DISCORD_ACHIEVEMENT_MANAGER_VERSION; } -enum EDiscordResult DISCORD_API DiscordCreate(DiscordVersion version, struct DiscordCreateParams* params, struct IDiscordCore** result); #ifdef __cplusplus } diff --git a/desktop_version/src/libdiscord_game_sdk.so b/desktop_version/src/libdiscord_game_sdk.so deleted file mode 100644 index 9dacf946..00000000 Binary files a/desktop_version/src/libdiscord_game_sdk.so and /dev/null differ