Skip to content

Commit

Permalink
Add --rpc command to manually specify the location of discord-ipc-0
Browse files Browse the repository at this point in the history
  • Loading branch information
EnderIce2 committed May 12, 2024
1 parent 5d0e6c4 commit e9f6b96
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
15 changes: 14 additions & 1 deletion bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
23 changes: 20 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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 <dir> 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);
}
Expand Down

0 comments on commit e9f6b96

Please sign in to comment.