From 539ef0044ab50c10a6d8ce320fd50e0a4c5cb36e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Wed, 4 Dec 2019 21:55:35 +0100 Subject: [PATCH] win_discord: configurability --- src/86box.h | 3 +++ src/config.c | 11 +++++++++ src/pc.c | 5 ++++- src/win/86Box.rc | 4 ++++ src/win/Makefile.mingw | 1 + src/win/Makefile_ndr.mingw | 1 + src/win/resource.h | 4 ++++ src/win/win_discord.c | 31 +++++++++++++++++-------- src/win/win_discord.h | 3 +++ src/win/win_ui.c | 46 +++++++++++++++++++++++++++++--------- 10 files changed, 89 insertions(+), 20 deletions(-) diff --git a/src/86box.h b/src/86box.h index 8baa0de37..2e1ee578a 100644 --- a/src/86box.h +++ b/src/86box.h @@ -115,6 +115,9 @@ extern int network_type; /* (C) net provider type */ extern int network_card; /* (C) net interface num */ extern char network_host[522]; /* (C) host network intf */ extern int hdd_format_type; /* (C) hard disk file format */ +#ifdef USE_DISCORD +extern int enable_discord; /* (C) enable Discord integration */ +#endif extern int is_pentium; /* TODO: Move back to cpu/cpu.h when it's figured out, how to remove that hack from the ET4000/W32p. */ diff --git a/src/config.c b/src/config.c index 51a5a70d6..9dc1bbf72 100644 --- a/src/config.c +++ b/src/config.c @@ -486,6 +486,10 @@ load_general(void) */ plat_langid = config_get_hex16(cat, "language", 0x0409); #endif + +#if USE_DISCORD + enable_discord = !!config_get_int(cat, "enable_discord", 0); +#endif } @@ -1387,6 +1391,13 @@ save_general(void) config_set_hex16(cat, "language", plat_langid); #endif +#if USE_DISCORD + if (enable_discord) + config_set_int(cat, "enable_discord", enable_discord); + else + config_delete_var(cat, "enable_discord"); +#endif + delete_section_if_empty(cat); } diff --git a/src/pc.c b/src/pc.c index 2882e211e..0f4eb8601 100644 --- a/src/pc.c +++ b/src/pc.c @@ -131,7 +131,10 @@ int cpu_manufacturer = 0, /* (C) cpu manufacturer */ cpu_use_dynarec = 0, /* (C) cpu uses/needs Dyna */ cpu = 3, /* (C) cpu type */ enable_external_fpu = 0; /* (C) enable external FPU */ -int time_sync = 0; /* (C) enable time sync */ +int time_sync = 0; /* (C) enable time sync */ +#ifdef USE_DISCORD +int enable_discord = 0; /* (C) enable Discord integration */ +#endif /* Statistics. */ extern int diff --git a/src/win/86Box.rc b/src/win/86Box.rc index d28c34767..738fb099b 100644 --- a/src/win/86Box.rc +++ b/src/win/86Box.rc @@ -120,6 +120,10 @@ BEGIN BEGIN MENUITEM "&Settings...", IDM_CONFIG MENUITEM "&Update status bar icons", IDM_UPDATE_ICONS +# ifdef USE_DISCORD + MENUITEM SEPARATOR + MENUITEM "Enable &Discord integration", IDM_DISCORD +# endif MENUITEM SEPARATOR MENUITEM "Take s&creenshot\tCtrl+F11", IDM_ACTION_SCREENSHOT END diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 986a2c209..b4ac19e33 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -428,6 +428,7 @@ endif ifeq ($(DISCORD), y) OPTS += -DUSE_DISCORD +RFLAGS += -DUSE_DISCORD DISCORDOBJ := win_discord.o endif diff --git a/src/win/Makefile_ndr.mingw b/src/win/Makefile_ndr.mingw index af495a9ff..273b428f1 100644 --- a/src/win/Makefile_ndr.mingw +++ b/src/win/Makefile_ndr.mingw @@ -434,6 +434,7 @@ endif ifeq ($(DISCORD), y) OPTS += -DUSE_DISCORD +RFLAGS += -DUSE_DISCORD DISCORDOBJ := win_discord.o endif diff --git a/src/win/resource.h b/src/win/resource.h index c2b58ed69..5f5474084 100644 --- a/src/win/resource.h +++ b/src/win/resource.h @@ -301,6 +301,10 @@ #define IDM_VID_GRAY_GREEN 40083 #define IDM_VID_GRAY_WHITE 40084 +#ifdef USE_DISCORD +#define IDM_DISCORD 40090 +#endif + #define IDM_LOG_BREAKPOINT 51201 #define IDM_DUMP_VRAM 51202 // should be an Action diff --git a/src/win/win_discord.c b/src/win/win_discord.c index fb9b5d001..74ec165da 100644 --- a/src/win/win_discord.c +++ b/src/win/win_discord.c @@ -36,6 +36,8 @@ #define PATH_DISCORD_DLL "discord_game_sdk.dll" +int discord_loaded = 0; + static void *discord_handle = NULL; static struct IDiscordCore *discord_core = NULL; static struct IDiscordActivityManager *discord_activities = NULL; @@ -114,25 +116,36 @@ discord_update_activity(int paused) discord_activities->update_activity(discord_activities, &activity, NULL, NULL); } -void -discord_init() +int +discord_load() { - enum EDiscordResult result; - struct DiscordCreateParams params; - - discord_log("win_discord: init\n"); + if (discord_handle != NULL) + return(1); // Try to load the DLL - if (discord_handle == NULL) - discord_handle = dynld_module(PATH_DISCORD_DLL, discord_imports); + discord_handle = dynld_module(PATH_DISCORD_DLL, discord_imports); if (discord_handle == NULL) { discord_log("win_discord: couldn't load " PATH_DISCORD_DLL "\n"); discord_close(); - return; + + return(0); } + discord_loaded = 1; + return(1); +} + +void +discord_init() +{ + enum EDiscordResult result; + struct DiscordCreateParams params; + + if(discord_handle == NULL) + return; + DiscordCreateParamsSetDefault(¶ms); params.client_id = 651478134352248832; params.flags = DiscordCreateFlags_NoRequireDiscord; diff --git a/src/win/win_discord.h b/src/win/win_discord.h index 142fdf40e..b7210fdc9 100644 --- a/src/win/win_discord.h +++ b/src/win/win_discord.h @@ -17,6 +17,9 @@ #ifndef WIN_DISCORD_H # define WIN_DISCORD_H +extern int discord_loaded; + +extern int discord_load(); extern void discord_init(); extern void discord_close(); extern void discord_update_activity(int paused); diff --git a/src/win/win_ui.c b/src/win/win_ui.c index d3c64b47d..a01394186 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -237,6 +237,13 @@ ResetAllMenus(void) CheckMenuItem(menuMain, IDM_VID_CGACON, vid_cga_contrast?MF_CHECKED:MF_UNCHECKED); CheckMenuItem(menuMain, IDM_VID_GRAYCT_601+video_graytype, MF_CHECKED); CheckMenuItem(menuMain, IDM_VID_GRAY_RGB+video_grayscale, MF_CHECKED); + +#ifdef USE_DISCORD + if (discord_loaded) + CheckMenuItem(menuMain, IDM_DISCORD, enable_discord ? MF_CHECKED : MF_UNCHECKED); + else + EnableMenuItem(menuMain, IDM_DISCORD, MF_DISABLED); +#endif } @@ -530,6 +537,19 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) config_save(); break; +#ifdef USE_DISCORD + case IDM_DISCORD: + if (! discord_loaded) break; + enable_discord ^= 1; + CheckMenuItem(hmenu, IDM_DISCORD, enable_discord ? MF_CHECKED : MF_UNCHECKED); + if(enable_discord) { + discord_init(); + discord_update_activity(dopause); + } else + discord_close(); + break; +#endif + #ifdef ENABLE_LOG_TOGGLES # ifdef ENABLE_BUSLOGIC_LOG case IDM_LOG_BUSLOGIC: @@ -845,6 +865,18 @@ ui_init(int nCmdShow) return(0); } +#ifdef USE_DISCORD + if(! discord_load()) { + enable_discord = 0; + } else if (enable_discord) { + /* Initialize the Discord API */ + discord_init(); + + /* Update Discord status */ + discord_update_activity(dopause); + } +#endif + /* Create our main window's class and register it. */ wincl.hInstance = hinstance; wincl.lpszClassName = CLASS_NAME; @@ -995,14 +1027,6 @@ ui_init(int nCmdShow) if (source_hwnd) PostMessage((HWND) (uintptr_t) source_hwnd, WM_SENDHWND, (WPARAM) unique_id, (LPARAM) hwndMain); -#ifdef USE_DISCORD - /* Initialize the Discord API */ - discord_init(); - - /* Update Discord status */ - discord_update_activity(dopause); -#endif - /* * Everything has been configured, and all seems to work, * so now it is time to start the main thread to do some @@ -1042,7 +1066,8 @@ ui_init(int nCmdShow) #ifdef USE_DISCORD /* Run Discord API callbacks */ - discord_run_callbacks(); + if (enable_discord) + discord_run_callbacks(); #endif } @@ -1124,7 +1149,8 @@ plat_pause(int p) #if USE_DISCORD /* Update Discord status */ - discord_update_activity(dopause); + if(enable_discord) + discord_update_activity(dopause); #endif /* Send the WM to a manager if needed. */