From 325d85ed4bf5d4ec70e7f602a9c594323e6d6445 Mon Sep 17 00:00:00 2001 From: radius Date: Tue, 16 Oct 2018 22:53:42 -0500 Subject: [PATCH] [discord] nasty hack to register the application with the current runtime args basically saves the whole argv string to reuse it on game launch Not working due to: https://github.com/discordapp/discord-rpc/issues/240 https://github.com/discordapp/discord-rpc/issues/163 --- discord/discord.c | 9 +++++---- retroarch.c | 10 ++++++++++ retroarch.h | 3 +++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/discord/discord.c b/discord/discord.c index a51a77f1d4..0b00ec5bc9 100644 --- a/discord/discord.c +++ b/discord/discord.c @@ -227,12 +227,13 @@ void discord_init(void) handlers.spectateGame = handle_discord_spectate; handlers.joinRequest = handle_discord_join_request; - /* To-Do: Add the arguments RetroArch was started with to the register URI*/ - const char command[256] = "retroarch"; - Discord_Initialize(settings->arrays.discord_app_id, &handlers, 0, NULL); - Discord_Register(settings->arrays.discord_app_id, NULL); + char command[PATH_MAX_LENGTH]; + + strlcpy(command, _argv, sizeof(command)); + RARCH_LOG("[Discord] registering startup command: %s\n", command); + Discord_Register(settings->arrays.discord_app_id, command); discord_ready = true; } diff --git a/retroarch.c b/retroarch.c index 3e0dc5cb1a..3a3cf88daf 100644 --- a/retroarch.c +++ b/retroarch.c @@ -637,6 +637,16 @@ static void retroarch_parse_input_and_config(int argc, char *argv[]) bool explicit_menu = false; global_t *global = global_get_ptr(); + /* Nasty hack to copy the args into a global so discord can register the same arguments for launch */ + char buf[4096]; + for (unsigned i = 0; i < argc; i++) + { + snprintf(buf, sizeof(buf), "%s %s", _argv, argv[i]); + strlcpy(_argv, buf, sizeof(_argv)); + } + _argc = argc; + string_trim_whitespace_left(_argv); + const struct option opts[] = { #ifdef HAVE_DYNAMIC { "libretro", 1, NULL, 'L' }, diff --git a/retroarch.h b/retroarch.h index 50f481ea6c..ab4f62119d 100644 --- a/retroarch.h +++ b/retroarch.h @@ -305,6 +305,9 @@ typedef struct global #endif } global_t; +unsigned _argc; +char _argv[4096]; + bool rarch_ctl(enum rarch_ctl_state state, void *data); int retroarch_get_capabilities(enum rarch_capabilities type,