From e9f6b969b68d0920dd64665bd01f230c4a062abc Mon Sep 17 00:00:00 2001 From: EnderIce2 Date: Mon, 13 May 2024 02:39:19 +0300 Subject: [PATCH] Add --rpc command to manually specify the location of discord-ipc-0 --- bridge.c | 15 ++++++++++++++- main.c | 23 ++++++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/bridge.c b/bridge.c index aeb17a7..6aba668 100644 --- a/bridge.c +++ b/bridge.c @@ -164,13 +164,26 @@ static inline int sys_connect(int s, caddr_t name, socklen_t namelen) char *native_getenv(const char *name) { + static char lpBuffer[512]; + DWORD ret = GetEnvironmentVariable("BRIDGE_RPC_PATH", lpBuffer, sizeof(lpBuffer)); + if (ret != 0) + return lpBuffer; + if (!IsLinux) { char *value = getenv(name); if (value == NULL) { print("Failed to get environment variable: %s\n", name); - return NULL; + + /* Use GetEnvironmentVariable as a last resort */ + DWORD ret = GetEnvironmentVariable(name, lpBuffer, sizeof(lpBuffer)); + if (ret == 0) + { + print("GetEnvironmentVariable(\"%s\", ...) failed: %d\n", name, ret); + return NULL; + } + return lpBuffer; } return value; } diff --git a/main.c b/main.c index 34ce027..2fa40e9 100644 --- a/main.c +++ b/main.c @@ -259,6 +259,19 @@ void HandleArguments(int argc, char *argv[]) RemoveService(); ExitProcess(0); } + else if (strcmp(argv[1], "--rpc") == 0) + { + if (argc < 3) + { + print("No directory provided\n"); + ExitProcess(1); + } + + SetEnvironmentVariable("BRIDGE_RPC_PATH", argv[2]); + print("BRIDGE_RPC_PATH has been set to \"%s\"\n", argv[2]); + CreateBridge(); + ExitProcess(0); + } else if (strcmp(argv[1], "--help") == 0) { printf("Usage:\n"); @@ -269,17 +282,21 @@ void HandleArguments(int argc, char *argv[]) printf(" --install Install service\n"); printf(" This will copy the binary to C:\\windows\\bridge.exe and register it as a service\n\n"); - printf(" --uninstall Uninstall service\n"); + printf(" --uninstall Uninstall service\n"); printf(" This will remove the service and delete C:\\windows\\bridge.exe\n\n"); - printf(" --steam Reserved for Steam\n"); + printf(" --steam Reserved for Steam\n"); printf(" This will start the service and exit (used with bridge.sh)\n\n"); - printf(" --no-service Do not run as service\n"); + printf(" --no-service Do not run as service\n"); printf(" (only for --steam)\n\n"); + printf(" --service Reserved for service\n\n"); + printf(" --rpc Set RPC_PATH environment variable\n"); + printf(" This is used to specify the directory where 'discord-ipc-0' is located\n\n"); + printf("Note: If no arguments are provided, the GUI will be shown instead\n"); ExitProcess(0); }