Compare commits

...

6 Commits

Author SHA1 Message Date
EnderIce2
9f1a9de3d7
Update actions/checkout and actions/upload-artifact to v4 2024-06-01 19:57:30 +03:00
EnderIce2
ccf09806c9
Print version on program start 2024-06-01 19:39:39 +03:00
EnderIce2
7363ee64d5
Update bridge.manifest with correct assembly name 2024-06-01 19:35:01 +03:00
EnderIce2
a3023e349e
Update gui.png 2024-06-01 02:56:12 +03:00
EnderIce2
39966d7149
Update Discord socket search
* Test multiple instances
* Add support for Discord Canary (Snap)
* Add support for Vesktop (Flatpak)
2024-06-01 01:37:40 +03:00
EnderIce2
a8904bf3f1
Update version 2024-06-01 00:57:06 +03:00
10 changed files with 89 additions and 67 deletions

View File

@ -13,13 +13,13 @@ jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: dependencies - name: dependencies
run: sudo apt-get update && sudo apt-get install gcc-mingw-w64 make run: sudo apt-get update && sudo apt-get install gcc-mingw-w64 make
- name: make - name: make
run: make run: make
- name: artifact - name: artifact
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: bridge name: bridge
path: build path: build

View File

@ -5,7 +5,10 @@
"includePath": [ "includePath": [
"${workspaceFolder}/**" "${workspaceFolder}/**"
], ],
"defines": [], "defines": [
"GIT_COMMIT",
"GIT_BRANCH"
],
"cStandard": "c17", "cStandard": "c17",
"cppStandard": "gnu++17", "cppStandard": "gnu++17",
"intelliSenseMode": "windows-gcc-x64" "intelliSenseMode": "windows-gcc-x64"

View File

@ -1,7 +1,10 @@
C_SOURCES = $(shell find ./ -type f -name '*.c') C_SOURCES = $(shell find ./ -type f -name '*.c')
C_OBJECTS = $(C_SOURCES:.c=.o) C_OBJECTS = $(C_SOURCES:.c=.o)
CFLAGS = -std=c17 -Wno-int-conversion GIT_COMMIT = $(shell git rev-parse --short HEAD)
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
CFLAGS = -std=c17 -Wno-int-conversion -DGIT_COMMIT='"$(GIT_COMMIT)"' -DGIT_BRANCH='"$(GIT_BRANCH)"'
LFLAGS = -lgdi32 LFLAGS = -lgdi32
# DBGFLAGS = -Wl,--export-all-symbols -g -O0 -ggdb3 -Wall # DBGFLAGS = -Wl,--export-all-symbols -g -O0 -ggdb3 -Wall

View File

@ -282,41 +282,53 @@ void ConnectToSocket(int fd)
print("IPC directory: %s\n", runtime); print("IPC directory: %s\n", runtime);
/* TODO: check for multiple discord instances and create a pipe for each */ /* TODO: check for multiple discord instances and create a pipe for each */
const char *discordUnixPipes[] = { const char *discordUnixSockets[] = {
"/discord-ipc-0", "%s/discord-ipc-%d",
"/snap.discord/discord-ipc-0", "%s/app/com.discordapp.Discord/discord-ipc-%d",
"/app/com.discordapp.Discord/discord-ipc-0", "%s/.flatpak/dev.vencord.Vesktop/xdg-run/discord-ipc-%d",
"%s/snap.discord/discord-ipc-%d",
"%s/snap.discord-canary/discord-ipc-%d",
}; };
struct sockaddr_un socketAddr; struct sockaddr_un socketAddr;
socketAddr.sun_family = AF_UNIX; socketAddr.sun_family = AF_UNIX;
char *pipePath = NULL;
int sockRet = -1;
for (int i = 0; i < sizeof(discordUnixPipes) / sizeof(discordUnixPipes[0]); i++) int sockRet = 0;
for (int i = 0; i < sizeof(discordUnixSockets) / sizeof(discordUnixSockets[0]); i++)
{ {
pipePath = malloc(strlen(runtime) + strlen(discordUnixPipes[i]) + 1); size_t pipePathLen = strlen(runtime) + strlen(discordUnixSockets[i]) + 1;
strcpy(pipePath, runtime); char *pipePath = malloc(pipePathLen);
strcat(pipePath, discordUnixPipes[i]);
strcpy_s(socketAddr.sun_path, sizeof(socketAddr.sun_path), pipePath);
print("Connecting to %s\n", pipePath); for (int j = 0; j < 16; j++)
if (IsLinux)
{ {
unsigned long socketArgs[] = { snprintf(pipePath, pipePathLen, discordUnixSockets[i], runtime, j);
(unsigned long)fd, strcpy_s(socketAddr.sun_path, sizeof(socketAddr.sun_path), pipePath);
(unsigned long)(intptr_t)&socketAddr, print("Probing %s\n", pipePath);
sizeof(socketAddr)};
sockRet = sys_socketcall(SYS_CONNECT, socketArgs); if (IsLinux)
{
unsigned long socketArgs[] = {
(unsigned long)fd,
(unsigned long)(intptr_t)&socketAddr,
sizeof(socketAddr)};
sockRet = sys_socketcall(SYS_CONNECT, socketArgs);
}
else
sockRet = sys_connect(fd, (caddr_t)&socketAddr, sizeof(socketAddr));
print(" error: %d\n", sockRet);
if (sockRet >= 0)
break;
} }
else
sockRet = sys_connect(fd, (caddr_t)&socketAddr, sizeof(socketAddr));
free(pipePath);
if (sockRet >= 0) if (sockRet >= 0)
{
print("Connecting to %s\n", pipePath);
free(pipePath);
break; break;
}
free(pipePath);
} }
if (sockRet < 0) if (sockRet < 0)

View File

@ -3,7 +3,7 @@
<assemblyIdentity <assemblyIdentity
version="1.0.0.0" version="1.0.0.0"
processorArchitecture="amd64" processorArchitecture="amd64"
name="EnderIce2.rpc-bridge" name="com.enderice2.rpc-bridge"
type="win32" type="win32"
/> />
<description>Simple bridge that allows you to use Discord Rich Presence with Wine games/software.</description> <description>Simple bridge that allows you to use Discord Rich Presence with Wine games/software.</description>

View File

@ -21,10 +21,10 @@ TEMP_PATH="$XDG_RUNTIME_DIR"
TEMP_PATH=${TEMP_PATH:-"$TMPDIR"} TEMP_PATH=${TEMP_PATH:-"$TMPDIR"}
VESSEL_PATH="$BRIDGE_PATH" VESSEL_PATH="$BRIDGE_PATH"
IPC_PATHS="$TEMP_PATH /run/user/$UID $TEMP_PATH/snap.discord $TEMP_PATH/app/com.discordapp.Discord" IPC_PATHS="$TEMP_PATH /run/user/$UID $TEMP_PATH/app/com.discordapp.Discord $TEMP_PATH/.flatpak/dev.vencord.Vesktop/xdg-run $TEMP_PATH/snap.discord $TEMP_PATH/snap.discord-canary"
for discord_ipc in $IPC_PATHS; do for discord_ipc in $IPC_PATHS; do
if [ -S "$discord_ipc"/discord-ipc-0 ]; then if [ -S "$discord_ipc"/discord-ipc-? ]; then
VESSEL_PATH="$BRIDGE_PATH:$(echo "$discord_ipc"/discord-ipc-0)" VESSEL_PATH="$BRIDGE_PATH:$(echo "$discord_ipc"/discord-ipc-?)"
break break
fi fi
done done

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 11 KiB

13
gui.c
View File

@ -191,11 +191,14 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case IDM_HELP_ABOUT: case IDM_HELP_ABOUT:
{ {
char msg[256]; char msg[256];
sprintf(msg, "rpc-bridge v%s\n\n" snprintf(msg, sizeof(msg),
"Simple bridge that allows you to use Discord Rich Presence with Wine games/software.\n\n" "rpc-bridge v%s\n"
"Created by EnderIce2\n\n" " branch: %s\n"
"Licensed under the MIT License", " commit: %s\n\n"
VER_VERSION_STR); "Simple bridge that allows you to use Discord Rich Presence with Wine games/software.\n\n"
"Created by EnderIce2\n\n"
"Licensed under the MIT License",
VER_VERSION_STR, GIT_BRANCH, GIT_COMMIT);
MessageBox(NULL, msg, "About", MB_OK); MessageBox(NULL, msg, "About", MB_OK);
break; break;
} }

61
main.c
View File

@ -273,38 +273,38 @@ void HandleArguments(int argc, char *argv[])
} }
else if (strcmp(argv[1], "--version") == 0) else if (strcmp(argv[1], "--version") == 0)
{ {
printf("%s\n", VER_VERSION_STR); /* Already shows the version */
ExitProcess(0); ExitProcess(0);
} }
else if (strcmp(argv[1], "--help") == 0) else if (strcmp(argv[1], "--help") == 0)
{ {
printf("Usage:\n" print("Usage:\n"
" %s [args]\n" " %s [args]\n"
"\n" "\n"
"Arguments:\n" "Arguments:\n"
" --help Show this help\n" " --help Show this help\n"
"\n" "\n"
" --version Show version\n" " --version Show version\n"
"\n" "\n"
" --install Install service\n" " --install Install service\n"
" This will copy the binary to C:\\windows\\bridge.exe and register it as a service\n" " This will copy the binary to C:\\windows\\bridge.exe and register it as a service\n"
"\n" "\n"
" --uninstall Uninstall service\n" " --uninstall Uninstall service\n"
" This will remove the service and delete C:\\windows\\bridge.exe\n" " This will remove the service and delete C:\\windows\\bridge.exe\n"
"\n" "\n"
" --steam Reserved for Steam\n" " --steam Reserved for Steam\n"
" This will start the service and exit (used with bridge.sh)\n" " This will start the service and exit (used with bridge.sh)\n"
"\n" "\n"
" --no-service Do not run as service\n" " --no-service Do not run as service\n"
" (only for --steam)\n" " (only for --steam)\n"
"\n" "\n"
" --service Reserved for service\n" " --service Reserved for service\n"
"\n" "\n"
" --rpc <dir> Set RPC_PATH environment variable\n" " --rpc <dir> Set RPC_PATH environment variable\n"
" This is used to specify the directory where 'discord-ipc-0' is located\n" " This is used to specify the directory where 'discord-ipc-0' is located\n"
"\n" "\n"
"Note: If no arguments are provided, the GUI will be shown instead\n", "Note: If no arguments are provided, the GUI will be shown instead\n",
argv[0]); argv[0]);
ExitProcess(0); ExitProcess(0);
} }
} }
@ -316,11 +316,12 @@ int main(int argc, char *argv[])
g_logFile = fopen(logFilePath, "w"); g_logFile = fopen(logFilePath, "w");
if (g_logFile == NULL) if (g_logFile == NULL)
{ {
printf("Failed to open logs file: %ld\n", MessageBox(NULL, "Failed to open logs file", "Error", MB_OK | MB_ICONERROR);
GetLastError()); printf("Failed to open logs file: %ld\n", GetLastError());
ExitProcess(1); ExitProcess(1);
} }
print("rpc-bridge v%s %s-%s\n", VER_VERSION_STR, GIT_BRANCH, GIT_COMMIT);
if (argc > 1) if (argc > 1)
HandleArguments(argc, argv); HandleArguments(argc, argv);
else else

View File

@ -5,5 +5,5 @@
#define IDM_HELP_ABOUT 40003 #define IDM_HELP_ABOUT 40003
#define IDM_VIEW_LOG 40004 #define IDM_VIEW_LOG 40004
#define VER_VERSION 1, 2, 0, 0 #define VER_VERSION 1, 3, 0, 0
#define VER_VERSION_STR "1.2\0" #define VER_VERSION_STR "1.3\0"