51 Commits

Author SHA1 Message Date
77a2a748ad Fix macos version
Some checks failed
Build Project / build (push) Has been cancelled
2025-04-09 10:03:54 +03:00
0d4f46e536 Fix build error #14 2025-04-09 06:38:25 +03:00
d065019137 Fix formatting in documentation
Some checks failed
Build Project / build (push) Has been cancelled
Deploy Documentation / deploy (push) Has been cancelled
2025-04-08 12:11:52 +03:00
e03dce1a7c Improve formatting of installation instructions in documentation 2025-04-08 12:09:38 +03:00
7c806779d2 Add link to latest pre-release in documentation 2025-04-08 12:05:58 +03:00
885cf775f9 Remove link to latest pre-release in documentation 2025-04-08 12:05:04 +03:00
7c07952df1 Add paths-ignore to GitHub Actions for build workflow 2025-04-08 12:04:16 +03:00
ea566cfdeb Update documentation links in index.md 2025-04-08 12:00:56 +03:00
d56de21e74 Refactor GitHub Actions workflows 2025-04-08 11:58:50 +03:00
26a016cb26 Bump version 2025-04-08 11:51:50 +03:00
edfcce2ae9 Update copyright year in bridge.rc to 2025
[no ci]
2025-04-08 11:51:02 +03:00
9bec33c358 Update bug_report.md 2025-04-08 11:36:51 +03:00
3e6b5dbb43 Merge branch 'master' of https://github.com/EnderIce2/rpc-bridge 2025-04-08 11:14:41 +03:00
4c432a0e50 Fix #12, socket -14 (EFAULT) 2025-04-08 11:14:32 +03:00
65b5625a57 Update error message for Wine compatibility check 2025-04-08 08:21:03 +03:00
9d2440f616 Update LICENSE
Some checks failed
Build and Deploy docs / deploy (push) Failing after 12m12s
Build and Deploy docs / build (push) Failing after 6m5s
2025-01-04 06:55:43 +02:00
51cbb666f9 Update build-deploy.yml
Some checks failed
Build and Deploy docs / build (push) Failing after 4m46s
Build and Deploy docs / deploy (push) Failing after 48s
2024-12-30 00:27:21 +02:00
1deccc5a63 Update CODE_OF_CONDUCT.md
Some checks failed
Build and Deploy docs / build (push) Failing after 28s
Build and Deploy docs / deploy (push) Failing after 34s
2024-12-11 05:54:45 +02:00
3412c3c011 Update issue templates
Some checks failed
Build and Deploy docs / build (push) Has been cancelled
Build and Deploy docs / deploy (push) Has been cancelled
2024-10-30 16:52:46 +02:00
c15c4df29e Create CODE_OF_CONDUCT.md 2024-10-30 16:39:46 +02:00
3a0b9ddb2a Ensure log file is properly closed
Some checks are pending
Build and Deploy docs / build (push) Waiting to run
Build and Deploy docs / deploy (push) Waiting to run
* Closing the log before service starts prevents log file to be corrupted (like in #7)
2024-10-30 01:08:12 +02:00
8786efd144 Fix formatting and add game links 2024-06-02 17:52:52 +03:00
2024de9408 Add "Known Issues" section
* Using Vesktop may cause issues with some games #4
2024-06-02 17:45:48 +03:00
e8926edb41 Add more screenshots
* Content Warning
* Hades
* Lethal Company
* vivid/stasis
2024-06-02 17:41:16 +03:00
9f1a9de3d7 Update actions/checkout and actions/upload-artifact to v4 2024-06-01 19:57:30 +03:00
ccf09806c9 Print version on program start 2024-06-01 19:39:39 +03:00
7363ee64d5 Update bridge.manifest with correct assembly name 2024-06-01 19:35:01 +03:00
a3023e349e Update gui.png 2024-06-01 02:56:12 +03:00
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
a8904bf3f1 Update version 2024-06-01 00:57:06 +03:00
08feef776b Update version 2024-05-31 01:18:38 +03:00
8545467a85 Add .elf file to .gitignore 2024-05-30 05:33:28 +03:00
20728818d2 Update pipe creation parameters 2024-05-30 04:19:19 +03:00
751d9ab3b7 Add menu bar and tab navigation for GUI, --version command 2024-05-30 03:28:18 +03:00
b906c009f4 Update docs 2024-05-29 23:18:53 +03:00
38e620836e Update shebang to use bash instead of sh
"function" is a bash builtin
2024-05-29 23:11:14 +03:00
a640dd5af1 Remove unnecessary code for starting the bridge service 2024-05-29 23:06:16 +03:00
8fbe00b555 Display installation guide prompt for missing temp directory 2024-05-29 23:02:48 +03:00
bf98b8784c Fix formatting and remove unnecessary recursive rm's 2024-05-29 22:55:02 +03:00
3021f8e4ad Update installation instructions for MacOS 2024-05-29 21:01:05 +03:00
655caa2934 Update README.md 2024-05-29 20:35:52 +03:00
da2a006ffb Merge pull request #3 from OrigamingWasTaken/master
Add support for the windows service on MacOS
2024-05-29 20:32:54 +03:00
e61fbf556e Added github markdown link 2024-05-29 17:04:26 +02:00
2dce976038 Clearer instructions (pt1) 2024-05-29 17:02:13 +02:00
2fe1dd5ece Update README.md 2024-05-27 22:13:16 +02:00
c23af8300c Increase pipe buffer 2024-05-23 06:00:45 +03:00
14226489d7 Modified readme and script 2024-05-22 16:41:15 +02:00
66f3bc53f1 readme 2024-05-21 23:48:12 +02:00
dcd9cf520e Modified README and added warning in bridge.c 2024-05-21 23:46:19 +02:00
8dd5952a64 MacOS Fix 2024-05-21 23:39:51 +02:00
81aa5d8d18 Remove unused macro 2024-05-13 08:42:23 +03:00
27 changed files with 707 additions and 225 deletions

31
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@ -0,0 +1,31 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: EnderIce2
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Log File**
Located in `/path/to/prefix/drive_c/windows/logs/bridge.log` or a screenshot with the terminal should suffice.
**System Info (please complete the following information):**
- OS: [e.g. SteamOS 3.0, Ubuntu 22.04, macOS 15, or output from command `uname -srm`]
- Wine: [e.g. 10.5]
**Additional context**
Add any other context about the problem here.

View File

@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: EnderIce2
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

35
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,35 @@
name: Build Project
on:
push:
branches: [ "master" ]
paths-ignore:
- 'ISSUE_TEMPLATE/**'
- 'workflows/**'
- '.vsocde/**'
- 'docs/**'
pull_request:
branches: [ "master" ]
paths-ignore:
- 'ISSUE_TEMPLATE/**'
- 'workflows/**'
- '.vsocde/**'
- 'docs/**'
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: dependencies
run: sudo apt update && sudo apt -y install gcc-mingw-w64 make
- name: make
run: make
- name: artifact
uses: actions/upload-artifact@v4
with:
name: bridge
path: build

View File

@ -1,29 +1,21 @@
name: Build and Deploy docs
name: Deploy Documentation
on:
push:
branches: [ "master" ]
branches: [ master ]
paths:
- docs/**
- mkdocs.yml
pull_request:
branches: [ "master" ]
paths:
- docs/**
- mkdocs.yml
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: dependencies
run: sudo apt-get update && sudo apt-get install gcc-mingw-w64 make
- name: make
run: make
- name: artifact
uses: actions/upload-artifact@v3
with:
name: bridge
path: build
deploy:
runs-on: ubuntu-latest
steps:

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.o
*.exe
*.res
*.elf

View File

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

128
CODE_OF_CONDUCT.md Normal file
View File

@ -0,0 +1,128 @@
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
enderice2@protonmail.com.
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series
of actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within
the community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.

View File

@ -1,4 +1,4 @@
Copyright (c) 2024 EnderIce2
Copyright (c) 2025 EnderIce2
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,8 +1,13 @@
C_SOURCES = $(shell find ./ -type f -name '*.c')
C_OBJECTS = $(C_SOURCES:.c=.o)
CFLAGS = -std=c17 -Wno-int-conversion
LFLAGS = -lgdi32
GIT_COMMIT = $(shell git rev-parse --short HEAD)
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
CWARNFLAGS = -Wno-int-conversion -Wno-incompatible-pointer-types
CFLAGS = -std=c17 -DGIT_COMMIT='"$(GIT_COMMIT)"' -DGIT_BRANCH='"$(GIT_BRANCH)"'
LFLAGS = -lgdi32 -lws2_32
# DBGFLAGS = -Wl,--export-all-symbols -g -O0 -ggdb3 -Wall
@ -15,7 +20,7 @@ build: $(C_OBJECTS)
%.o: %.c
$(info Compiling $<)
x86_64-w64-mingw32-gcc $(CFLAGS) $(DBGFLAGS) -c $< -o $@
x86_64-w64-mingw32-gcc $(CFLAGS) $(CWARNFLAGS) $(DBGFLAGS) -c $< -o $@
clean:
rm -f $(C_OBJECTS) build/bridge.exe bridge.res

View File

@ -25,6 +25,8 @@ Logs are stored in `C:\windows\logs\bridge.log`.
- ![gui](docs/assets/gui.png)
- To remove, the same process can be followed, but click `Remove` instead.
*Note, an [extra step](https://github.com/EnderIce2/rpc-bridge?tab=readme-ov-file#macos) is needed on MacOS*
##### Lutris
- Click on a game and select `Run EXE inside Wine prefix`.
@ -50,9 +52,17 @@ Logs are stored in `C:\windows\logs\bridge.log`.
- Globally
- `flatpak override --user --filesystem=xdg-run/discord-ipc-0`
## macOS
##### MacOS
On macOS, follow [these instructions](https://enderice2.github.io/rpc-bridge/installation.html#macos).
The steps for MacOS are almost the same, but due to the way `$TMPDIR` works, you will have to install a **LaunchAgent**.
- Download the latest build from the [releases](https://github.com/EnderIce2/rpc-bridge/releases)
- Open the archive and make the `launchd.sh` script executable by doing: `chmod +x launchd.sh`
- To **install** the LaunchAgent, run `./launchd install` and to **remove** it simply run `./launchd remove`.
The script will add a LaunchAgent to your user, that will symlink the `$TMPDIR` directory to `/tmp/rpc-bridge/tmpdir`.
*Note: You will need to launch the `bridge.exe` file manually in Wine at least once for it to register and launch automatically the next time.*
## Compiling from source

232
bridge.c
View File

@ -20,11 +20,13 @@
#define __darwin_close 0x2000006
#define __darwin_socket 0x2000061
#define __darwin_connect 0x2000062
#define __darwin_mmap 0x20000C5
#define __darwin_fcntl 0x200005C
#define __darwin_sysctl 0x20000CA
#define O_RDONLY 00
/* macos & linux are the same for PROT_READ, PROT_WRITE, MAP_FIXED & MAP_PRIVATE */
#define PROT_READ 1
#define PROT_WRITE 2
#define MAP_PRIVATE 0x02
@ -32,6 +34,8 @@
#define MAP_ANON 0x20
#define MAP_FAILED ((void *)-1)
#define __darwin_MAP_ANON 0x1000
#define SYS_SOCKET 1
#define SYS_CONNECT 3
@ -43,6 +47,8 @@
__attribute__((__always_inline__, __gnu_inline__))
#define naked __attribute__((naked))
#define BUFFER_LENGTH 2048
typedef unsigned short sa_family_t;
typedef char *caddr_t;
typedef unsigned socklen_t;
@ -132,8 +138,17 @@ static inline int sys_close(int fd)
static inline unsigned int *sys_mmap(unsigned int *addr, size_t length, int prot, int flags, int fd, off_t offset)
{
assert(IsLinux);
return linux_syscall(__linux_mmap2, addr, length, prot, flags, fd, offset);
if (IsLinux)
return linux_syscall(__linux_mmap2, addr, length, prot, flags, fd, offset);
else
{
if (flags & MAP_ANON)
{
flags &= ~MAP_ANON;
flags |= __darwin_MAP_ANON;
}
return darwin_syscall(__darwin_mmap, addr, length, prot, flags, fd, offset);
}
}
static inline int sys_munmap(unsigned int *addr, size_t length)
@ -193,11 +208,7 @@ char *native_getenv(const char *name)
/* I hope the 0x20000 is okay */
if (environStr == NULL)
{
environStr = sys_mmap(0x20000, 4096, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
print("Allocated 4096 bytes at %#lx\n", environStr);
}
environStr = sys_mmap(0x20000, 0x1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
if ((uintptr_t)environStr > 0x7effffff)
print("Warning: environStr %#lx is above 2GB\n", environStr);
@ -207,18 +218,17 @@ char *native_getenv(const char *name)
int fd = sys_open(environStr, O_RDONLY, 0);
// sys_munmap(environStr, 4096);
if (fd < 0)
{
print("Failed to open /proc/self/environ: %d\n", fd);
return NULL;
}
char buffer[4096];
char *buffer = sys_mmap(0x22000, 0x1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
char *result = NULL;
int bytesRead;
while ((bytesRead = sys_read(fd, buffer, sizeof(buffer) - 1)) > 0)
while ((bytesRead = sys_read(fd, buffer, 0x1000 - 1)) > 0)
{
buffer[bytesRead] = '\0';
char *env = buffer;
@ -252,55 +262,96 @@ void ConnectToSocket(int fd)
if (IsLinux)
runtime = native_getenv("XDG_RUNTIME_DIR");
else
runtime = native_getenv("TMPDIR");
if (runtime == NULL)
{
print("IPC directory not set\n");
if (!RunningAsService)
MessageBox(NULL, "IPC directory not set",
"Environment variable not set",
MB_OK | MB_ICONSTOP);
ExitProcess(1);
runtime = native_getenv("TMPDIR");
if (runtime == NULL)
{
runtime = "/tmp/rpc-bridge/tmpdir";
print("IPC directory not set, fallback to /tmp/rpc-bridge/tmpdir\n");
// Check if the directory exists
DWORD dwAttrib = GetFileAttributes(runtime);
if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY))
{
print("IPC directory does not exist: %s. If you're on MacOS, see the github guide on how to install the launchd service.\n", runtime);
// Handle the case where the directory doesn't exist
// For example, create the directory
int result = MessageBox(NULL, "IPC directory does not exist\nDo you want to open the installation guide?",
"Directory not found",
MB_YESNO | MB_ICONSTOP);
if (result == IDYES)
ShellExecute(NULL, "open", "https://enderice2.github.io/rpc-bridge/installation.html#macos", NULL, NULL, SW_SHOWNORMAL);
ExitProcess(1);
}
}
}
print("IPC directory: %s\n", runtime);
/* TODO: check for multiple discord instances and create a pipe for each */
const char *discordUnixPipes[] = {
"/discord-ipc-0",
"/snap.discord/discord-ipc-0",
"/app/com.discordapp.Discord/discord-ipc-0",
const char *discordUnixSockets[] = {
"%s/discord-ipc-%d",
"%s/app/com.discordapp.Discord/discord-ipc-%d",
"%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;
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);
strcpy(pipePath, runtime);
strcat(pipePath, discordUnixPipes[i]);
strcpy_s(socketAddr.sun_path, sizeof(socketAddr.sun_path), pipePath);
size_t pipePathLen = strlen(runtime) + strlen(discordUnixSockets[i]) + 1;
char *pipePath = malloc(pipePathLen);
print("Connecting to %s\n", pipePath);
if (IsLinux)
for (int j = 0; j < 16; j++)
{
unsigned long socketArgs[] = {
(unsigned long)fd,
(unsigned long)(intptr_t)&socketAddr,
sizeof(socketAddr)};
if (IsLinux)
{
struct sockaddr_un *socketAddr = sys_mmap(0x23000, 0x1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
print("Socket address allocated at %#lx\n", socketAddr);
socketAddr->sun_family = AF_UNIX;
sockRet = sys_socketcall(SYS_CONNECT, socketArgs);
snprintf(pipePath, pipePathLen, discordUnixSockets[i], runtime, j);
strcpy_s(socketAddr->sun_path, sizeof(socketAddr->sun_path), pipePath);
print("Probing %s\n", pipePath);
// unsigned long socketArgs[] = {
// (unsigned long)fd,
// (unsigned long)(intptr_t)&socketAddr,
// sizeof(socketAddr)};
unsigned long *socketArgs = sys_mmap(0x24000, 0x1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
socketArgs[0] = (unsigned long)fd;
socketArgs[1] = (unsigned long)(intptr_t)socketAddr;
socketArgs[2] = sizeof(struct sockaddr_un);
socketArgs[3] = 0;
sockRet = sys_socketcall(SYS_CONNECT, socketArgs);
}
else
{
struct sockaddr_un socketAddr;
socketAddr.sun_family = AF_UNIX;
snprintf(pipePath, pipePathLen, discordUnixSockets[i], runtime, j);
strcpy_s(socketAddr.sun_path, sizeof(socketAddr.sun_path), pipePath);
print("Probing %s\n", pipePath);
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)
{
print("Connecting to %s\n", pipePath);
free(pipePath);
break;
}
free(pipePath);
}
if (sockRet < 0)
@ -317,18 +368,22 @@ void ConnectToSocket(int fd)
void PipeBufferInThread(LPVOID lpParam)
{
bridge_thread *bt = (bridge_thread *)lpParam;
print("In thread started using fd %d and pipe %#x\n",
bt->fd, bt->hPipe);
print("In thread started using fd %d and pipe %#x\n", bt->fd, bt->hPipe);
int EOFCount = 0;
char *l_buffer;
if (IsLinux)
l_buffer = sys_mmap(0x25000, 0x1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
else
l_buffer = malloc(BUFFER_LENGTH);
print("Buffer in thread allocated at %#lx\n", l_buffer);
while (TRUE)
{
char buffer[1024];
int read = sys_read(bt->fd, buffer, sizeof(buffer));
char buffer[BUFFER_LENGTH];
int read = sys_read(bt->fd, l_buffer, BUFFER_LENGTH);
if (unlikely(read < 0))
{
print("Failed to read from unix pipe: %d\n",
GetErrorMessage());
print("Failed to read from unix pipe: %d\n", read);
Sleep(1000);
continue;
}
@ -350,14 +405,16 @@ void PipeBufferInThread(LPVOID lpParam)
}
EOFCount = 0;
memcpy(buffer, l_buffer, read);
print("Reading %d bytes from unix pipe: \"", read);
for (int i = 0; i < read; i++)
print("%c", buffer[i]);
print("\"\n");
DWORD dwWritten;
if (unlikely(!WriteFile(bt->hPipe, buffer, read,
&dwWritten, NULL)))
WINBOOL bResult = WriteFile(bt->hPipe, buffer, read, &dwWritten, NULL);
if (unlikely(bResult == FALSE))
{
if (GetLastError() == ERROR_BROKEN_PIPE)
{
@ -366,16 +423,14 @@ void PipeBufferInThread(LPVOID lpParam)
break;
}
print("Failed to read from pipe: %d\n",
GetErrorMessage());
print("Failed to read from pipe: %s\n", GetErrorMessage());
Sleep(1000);
continue;
}
if (unlikely(dwWritten < 0))
{
print("Failed to write to pipe: %d\n",
GetErrorMessage());
print("Failed to write to pipe: %s\n", GetErrorMessage());
Sleep(1000);
continue;
}
@ -383,8 +438,8 @@ void PipeBufferInThread(LPVOID lpParam)
while (dwWritten < read)
{
int last_written = dwWritten;
if (unlikely(!WriteFile(bt->hPipe, buffer + dwWritten,
read - dwWritten, &dwWritten, NULL)))
WINBOOL bResult = WriteFile(bt->hPipe, buffer + dwWritten, read - dwWritten, &dwWritten, NULL);
if (unlikely(bResult == FALSE))
{
if (GetLastError() == ERROR_BROKEN_PIPE)
{
@ -393,16 +448,14 @@ void PipeBufferInThread(LPVOID lpParam)
break;
}
print("Failed to read from pipe: %d\n",
GetErrorMessage());
print("Failed to read from pipe: %s\n", GetErrorMessage());
Sleep(1000);
continue;
}
if (unlikely(last_written == dwWritten))
{
print("Failed to write to pipe: %d\n",
GetErrorMessage());
print("Failed to write to pipe: %s\n", GetErrorMessage());
Sleep(1000);
continue;
}
@ -413,15 +466,19 @@ void PipeBufferInThread(LPVOID lpParam)
void PipeBufferOutThread(LPVOID lpParam)
{
bridge_thread *bt = (bridge_thread *)lpParam;
print("Out thread started using fd %d and pipe %#x\n",
bt->fd, bt->hPipe);
print("Out thread started using fd %d and pipe %#x\n", bt->fd, bt->hPipe);
char *l_buffer;
if (IsLinux)
l_buffer = sys_mmap(0x26000, 0x1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
else
l_buffer = malloc(BUFFER_LENGTH);
print("Buffer out thread allocated at %#lx\n", l_buffer);
while (TRUE)
{
char buffer[1024];
char buffer[BUFFER_LENGTH];
DWORD dwRead;
if (unlikely(!ReadFile(bt->hPipe, buffer, sizeof(buffer),
&dwRead, NULL)))
WINBOOL bResult = ReadFile(bt->hPipe, buffer, BUFFER_LENGTH, &dwRead, NULL);
if (unlikely(bResult == FALSE))
{
if (GetLastError() == ERROR_BROKEN_PIPE)
{
@ -430,8 +487,7 @@ void PipeBufferOutThread(LPVOID lpParam)
break;
}
print("Failed to read from pipe: %d\n",
GetErrorMessage());
print("Failed to read from pipe: %s\n", GetErrorMessage());
Sleep(1000);
continue;
}
@ -441,11 +497,11 @@ void PipeBufferOutThread(LPVOID lpParam)
print("%c", buffer[i]);
print("\"\n");
int written = sys_write(bt->fd, buffer, dwRead);
memcpy(l_buffer, buffer, dwRead);
int written = sys_write(bt->fd, l_buffer, dwRead);
if (unlikely(written < 0))
{
print("Failed to write to socket: %d\n",
written);
print("Failed to write to socket: %d\n", written);
continue;
}
@ -455,8 +511,7 @@ void PipeBufferOutThread(LPVOID lpParam)
written += sys_write(bt->fd, buffer + written, dwRead - written);
if (unlikely(last_written == written))
{
print("Failed to write to socket: %d\n",
GetErrorMessage());
print("Failed to write to socket: %s\n", GetErrorMessage());
Sleep(1000);
continue;
}
@ -488,7 +543,7 @@ NewConnection:
CreateNamedPipe("\\\\.\\pipe\\discord-ipc-0",
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
1, 1024, 1024, 0, NULL);
PIPE_UNLIMITED_INSTANCES, BUFFER_LENGTH, BUFFER_LENGTH, 0, NULL);
if (hPipe == INVALID_HANDLE_VALUE)
{
@ -519,16 +574,31 @@ NewConnection:
int fd;
if (IsLinux)
{
unsigned long socketArgs[] = {
(unsigned long)AF_UNIX,
(unsigned long)SOCK_STREAM,
0};
// unsigned long socketArgs[] = {
// (unsigned long)AF_UNIX,
// (unsigned long)SOCK_STREAM,
// 0};
unsigned long *socketArgs = sys_mmap(0x21000, 0x1000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
socketArgs[0] = (unsigned long)AF_UNIX;
socketArgs[1] = (unsigned long)SOCK_STREAM;
socketArgs[2] = 0;
fd = sys_socketcall(SYS_SOCKET, socketArgs);
/* FIXME: WSAEAFNOSUPPORT: https://gitlab.winehq.org/wine/wine/-/merge_requests/2786 */
// WSADATA wsaData;
// int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
// if (iResult != 0)
// printf("WSAStartup failed: %d\n", iResult);
// fd = socket(AF_UNIX, SOCK_STREAM, 0);
}
else
fd = sys_socket(AF_UNIX, SOCK_STREAM, 0);
print("Socket %d created\n", fd);
if (fd == INVALID_SOCKET)
{
print("invalid socket: %d %d\n", fd, WSAGetLastError());
ExitProcess(1);
}
if (fd < 0)
{
@ -539,6 +609,8 @@ NewConnection:
ExitProcess(1);
}
print("Socket %d created\n", fd);
ConnectToSocket(fd);
print("Connected to Discord\n");

View File

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

View File

@ -2,14 +2,7 @@
#include <winuser.h>
#include <winresrc.h>
#define VER_VERSION 1,1,0,0
#define VER_VERSION_STR "1.1\0"
#ifndef DEBUG
#define VER_DEBUG 0
#else
#define VER_DEBUG VS_FF_DEBUG
#endif
#include "resource.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_VERSION
@ -26,7 +19,7 @@ BEGIN
VALUE "FileDescription", "Simple bridge that allows you to use Discord Rich Presence with Wine games/software."
VALUE "FileVersion", VER_VERSION_STR
VALUE "InternalName", "bridge"
VALUE "LegalCopyright", "Copyright (c) 2024 EnderIce2"
VALUE "LegalCopyright", "Copyright (c) 2025 EnderIce2"
VALUE "OriginalFilename", "bridge.exe"
VALUE "ProductName", "rpc-bridge"
VALUE "ProductVersion", VER_VERSION_STR
@ -39,6 +32,22 @@ BEGIN
END
END
IDR_MAINMENU MENU
BEGIN
POPUP "&View"
BEGIN
MENUITEM "&Log", IDM_VIEW_LOG
END
POPUP "&Help"
BEGIN
MENUITEM "&Documentation", IDM_HELP_DOCUMENTATION
MENUITEM "&License", IDM_HELP_LICENSE
MENUITEM "&About", IDM_HELP_ABOUT
END
END
IDR_LICENSE_TXT RCDATA "LICENSE"
IDI_ICON_128 ICON "bridge.ico"
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST bridge.manifest

View File

@ -21,10 +21,10 @@ TEMP_PATH="$XDG_RUNTIME_DIR"
TEMP_PATH=${TEMP_PATH:-"$TMPDIR"}
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
if [ -S "$discord_ipc"/discord-ipc-0 ]; then
VESSEL_PATH="$BRIDGE_PATH:$(echo "$discord_ipc"/discord-ipc-0)"
if [ -S "$discord_ipc"/discord-ipc-? ]; then
VESSEL_PATH="$BRIDGE_PATH:$(echo "$discord_ipc"/discord-ipc-?)"
break
fi
done

83
build/launchd.sh Executable file
View File

@ -0,0 +1,83 @@
#!/bin/bash
# This script is used to create a LaunchAgent on MacOS, to support the service functionality.
# Usage: ./launchd.sh (install|remove)
SYMLINK=/tmp/rpc-bridge/tmpdir
LOCATION=~/Library/Application\ Support/rpc-bridge
SCRIPT=$LOCATION/rpc-bridge
AGENT=~/Library/LaunchAgents/com.enderice2.rpc-bridge.plist
function install() {
# Directories
if [ ! -d "$SYMLINK" ]; then
mkdir -p "$SYMLINK"
fi
if [ ! -d "$LOCATION" ]; then
mkdir -p "$LOCATION"
fi
# Link script
if [ -f "$SCRIPT" ]; then
rm -f "$SCRIPT"
fi
echo "#!/bin/bash
TARGET_DIR=/tmp/rpc-bridge/tmpdir
if [ ! -d "\$TARGET_DIR" ]; then
mkdir -p "\$TARGET_DIR"
fi
rm -rf "\$TARGET_DIR"
ln -s "\$TMPDIR" "\$TARGET_DIR"" > "$SCRIPT"
chmod +x "$SCRIPT"
# LaunchAgent
if [ -f "$AGENT" ]; then
rm -f "$AGENT"
fi
echo "<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST File Format//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.enderice2.rpc-bridge</string>
<key>ProgramArguments</key>
<array>
<string>$SCRIPT</string>
</array>
<key>RunAtLoad</key>
<true />
</dict>
</plist>" > "$AGENT"
launchctl load "$AGENT"
echo "LaunchAgent has been installed."
}
function remove() {
rm -f "$SYMLINK"
rm -f "$SCRIPT"
rmdir "$LOCATION"
if [ -f "$AGENT" ]; then
launchctl unload "$AGENT"
fi
rm -f "$AGENT"
echo "LaunchAgent has been removed."
}
# CLI
if [ $# -eq 0 ]; then
echo "Usage: $0 (install|remove)"
exit 1
fi
case $1 in
install)
install
;;
remove)
remove
;;
*)
echo "Invalid argument. Please use 'install' or 'remove'."
exit 1
;;
esac

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 11 KiB

BIN
docs/assets/hades.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 551 KiB

BIN
docs/assets/vividstasis.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 945 KiB

View File

@ -9,7 +9,7 @@ Simple bridge that allows you to use Discord Rich Presence with Wine games/softw
[Download latest release](https://github.com/EnderIce2/rpc-bridge/releases/latest/download/bridge.zip "Recommended"){ .md-button .md-button--primary }
[Download latest pre-release](https://github.com/EnderIce2/rpc-bridge/releases "Unstable builds with experimental features"){ .md-button }
<!-- [Download latest build](https://github.com/EnderIce2/rpc-bridge/actions "Builds from the latest commits, here be dragons!"){ .md-button } -->
[Download latest build](https://github.com/EnderIce2/rpc-bridge/actions/workflows/build.yml "Builds from the latest commits, here be dragons!"){ .md-button }
Works by running a small program in the background that creates a [named pipe](https://learn.microsoft.com/en-us/windows/win32/ipc/named-pipes) `\\.\pipe\discord-ipc-0` inside the prefix and forwards all data to the pipe `/run/user/1000/discord-ipc-0`.
@ -20,11 +20,32 @@ For v1.0, see [the original README](https://github.com/EnderIce2/rpc-bridge/blob
---
## Known Issues
- If you use **Vesktop**
Some games may not show up in Discord. This is because Vesktop uses arRPC, which it doesn't work with some games [#4](https://github.com/EnderIce2/rpc-bridge/issues/4#issuecomment-2143549407). This is not an issue with the bridge.
---
## Examples
![lol](assets/lutris_lol.png "League Of Legends running under Wine using Lutris"){ width="600" }
[**League Of Legends**](https://www.leagueoflegends.com/en-us/) running under Wine using Lutris
![image](assets/lutris_lol.png){ width="600" }
![among us](assets/steam_amongus.png "Among Us on Steam"){ width="600" }
[**Among Us**](https://store.steampowered.com/app/945360/Among_Us/) on Steam
![image](assets/steam_amongus.png){ width="600" }
[**Content Warning**](https://store.steampowered.com/app/2881650/Content_Warning/) on Steam
![image](assets/contentwarning.png){ width="600" }
[**Hades**](https://store.steampowered.com/app/1145360/Hades/) on Steam
![image](assets/hades.png){ width="600" }
[**Lethal Company**](https://store.steampowered.com/app/1966720/Lethal_Company/) ([modded](https://thunderstore.io/c/lethal-company/p/mrov/LethalRichPresence/)) on Steam
![image](assets/lethalcompany.png){ width="600" }
[**vivid/stasis**](https://store.steampowered.com/app/2093940/vividstasis/) on Steam
![image](assets/vividstasis.png){ width="600" }
## Credits

View File

@ -64,14 +64,16 @@ This method is recommended because it's easier to manage.
## macOS
If using the default Wine prefix (`~/.wine`), you can follow the same steps as in Wine.
The steps for MacOS are almost the same, but due to the way `$TMPDIR` works, you will have to install a **LaunchAgent**.
Registering as a service [is not supported](https://github.com/EnderIce2/rpc-bridge/issues/1#issuecomment-2103423242 "Bridge can't get $TMPDIR unless is set with --rpc. See note below").
- Download the latest build from the [releases](https://github.com/EnderIce2/rpc-bridge/releases)
- Open the archive and make the `launchd.sh` script executable by doing: `chmod +x launchd.sh`
- To **install** the LaunchAgent, run `./launchd install` and to **remove** it simply run `./launchd remove`.
The script will add a LaunchAgent to your user, that will symlink the `$TMPDIR` directory to `/tmp/rpc-bridge/tmpdir`.
!!! info "Note"
Since macOS doesn't have `/proc/self/environ` and `$TMPDIR` is neither always set nor the same after reboots, so you will need to [add `--rpc "$TMPDIR"` to the `bridge.exe` arguments](https://github.com/EnderIce2/rpc-bridge/issues/1#issuecomment-2104797235).
If you don't encounter any issues, you can ignore this step.
You will need to launch the `bridge.exe` file manually in Wine at least once for it to register and launch automatically the next time.
## Run without installing the service
@ -82,21 +84,17 @@ In Lutris, you can achieve this by adding the path to `bridge.exe` in the `Execu
=== "Without bridge"
```
Executable
/mnt/games/lutris/league-of-legends/drive_c/Riot Games/League of Legends/LeagueClient.exe
Arguments
--locale=en_US --launch-product=league_of_legends --launch-patchline=live
```
- Executable
- `/mnt/games/lutris/league-of-legends/drive_c/Riot Games/League of Legends/LeagueClient.exe`
- Arguments
- `--locale=en_US --launch-product=league_of_legends --launch-patchline=live`
=== "With bridge"
```
Executable
/mnt/games/lutris/league-of-legends/drive_c/bridge.exe
Arguments
"C:\Riot Games\League of Legends\LeagueClient.exe" --locale=en_US --launch-product=league_of_legends --launch-patchline=live
```
- Executable
- `/mnt/games/lutris/league-of-legends/drive_c/bridge.exe`
- Arguments
- `"C:\Riot Games\League of Legends\LeagueClient.exe" --locale=en_US --launch-product=league_of_legends --launch-patchline=live`
In Wine, all you need to do is run `bridge.exe` and select `Start`.

View File

@ -11,7 +11,10 @@
## Commands
- `--help` Show help message
- This will show the help message
- This will show the help message
- `--version` Show version
- This will show the version of the program
- `--install` Install the service
- This will copy the binary to `C:\windows\bridge.exe` and register it as a service

118
gui.c
View File

@ -4,6 +4,8 @@
#include <assert.h>
#include <stdio.h>
#include "resource.h"
/**
* The entire code could be better written, but at least it works.
*
@ -31,7 +33,7 @@ VOID HandleStartButton(BOOL Silent)
SetWindowText(item, "Do you want to start, install or remove the bridge?");
RedrawWindow(item, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
item = GetDlgItem(hwnd, /* Start Button */ 1);
Button_SetText(item, "Start");
Button_SetText(item, "&Start");
EnableWindow(item, FALSE);
RedrawWindow(item, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
@ -47,20 +49,6 @@ VOID HandleStartButton(BOOL Silent)
return;
}
if (!IsLinux)
{
hBridge = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CreateBridge,
NULL, 0, NULL);
HWND item = GetDlgItem(hwnd, /* Start Button */ 1);
Button_SetText(item, "Stop");
item = GetDlgItem(hwnd, 4);
SetWindowText(item, "Bridge is running...");
IsAlreadyRunning = TRUE;
ShowWindow(hwnd, SW_MINIMIZE);
return;
}
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hSCManager == NULL)
{
@ -72,7 +60,7 @@ VOID HandleStartButton(BOOL Silent)
SERVICE_QUERY_CONFIG | SERVICE_CHANGE_CONFIG | SERVICE_START);
if (schService == NULL)
{
// print("OpenService failed: %s\n", GetErrorMessage());
print("Service doesn't exist: %s\n", GetErrorMessage());
/* Service doesn't exist; running without any service */
@ -80,7 +68,7 @@ VOID HandleStartButton(BOOL Silent)
NULL, 0, NULL);
HWND item = GetDlgItem(hwnd, /* Start Button */ 1);
Button_SetText(item, "Stop");
Button_SetText(item, "&Stop");
item = GetDlgItem(hwnd, 4);
SetWindowText(item, "Bridge is running...");
IsAlreadyRunning = TRUE;
@ -115,6 +103,7 @@ VOID HandleStartButton(BOOL Silent)
CloseServiceHandle(hSCManager);
if (Silent == FALSE)
MessageBox(NULL, "Bridge service started successfully", "Info", MB_OK);
print("Bridge service started successfully\n");
}
VOID HandleInstallButton()
@ -135,6 +124,44 @@ VOID HandleRemoveButton()
ExitProcess(0);
}
void ShowLicenseDialog()
{
HMODULE hModule = GetModuleHandle(NULL);
HRSRC hRes = FindResource(hModule, MAKEINTRESOURCE(IDR_LICENSE_TXT), RT_RCDATA);
if (!hRes)
{
MessageBox(NULL, "Resource not found", "Error", MB_OK | MB_ICONERROR);
return;
}
HGLOBAL hResData = LoadResource(NULL, hRes);
if (!hResData)
{
MessageBox(NULL, "Resource failed to load", "Error", MB_OK | MB_ICONERROR);
return;
}
DWORD resSize = SizeofResource(NULL, hRes);
void *pRes = LockResource(hResData);
if (!pRes)
{
MessageBox(NULL, "Resource failed to lock", "Error", MB_OK | MB_ICONERROR);
return;
}
char *licenseText = (char *)malloc(resSize + 1);
if (!licenseText)
{
MessageBox(NULL, "Memory allocation failed", "Error", MB_OK | MB_ICONERROR);
return;
}
memcpy(licenseText, pRes, resSize);
licenseText[resSize] = '\0';
MessageBoxA(hwnd, licenseText, "About", MB_OK);
free(licenseText);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
@ -152,6 +179,29 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case 3:
HandleRemoveButton();
break;
case IDM_VIEW_LOG:
ShellExecute(NULL, "open", "C:\\windows\\notepad.exe", "C:\\windows\\logs\\bridge.log", NULL, SW_SHOW);
break;
case IDM_HELP_DOCUMENTATION:
ShellExecute(NULL, "open", "https://enderice2.github.io/rpc-bridge/index.html", NULL, NULL, SW_SHOWNORMAL);
break;
case IDM_HELP_LICENSE:
ShowLicenseDialog();
break;
case IDM_HELP_ABOUT:
{
char msg[256];
snprintf(msg, sizeof(msg),
"rpc-bridge v%s\n"
" branch: %s\n"
" commit: %s\n\n"
"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);
break;
}
default:
break;
}
@ -178,16 +228,16 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
VOID SetButtonStyles(INT *btnStartStyle, INT *btnRemoveStyle, INT *btnInstallStyle)
{
*btnStartStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON;
*btnRemoveStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON;
*btnInstallStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON;
*btnStartStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP;
*btnRemoveStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP;
*btnInstallStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP;
if (!IsLinux)
{
*btnInstallStyle |= WS_DISABLED;
*btnRemoveStyle |= WS_DISABLED;
return;
}
// if (!IsLinux)
// {
// *btnInstallStyle |= WS_DISABLED;
// *btnRemoveStyle |= WS_DISABLED;
// return;
// }
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
SC_HANDLE schService = OpenService(hSCManager, "rpc-bridge", SERVICE_START | SERVICE_QUERY_STATUS);
@ -254,21 +304,24 @@ int WINAPI __WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
0, 15, 400, 25,
hwnd, (HMENU)4, hInstance, NULL);
HWND hbtn1 = CreateWindow("BUTTON", "Start",
HWND hbtn1 = CreateWindow("BUTTON", "&Start",
btnStartStyle,
40, 60, 100, 30,
hwnd, (HMENU)1, hInstance, NULL);
HWND hbtn2 = CreateWindow("BUTTON", "Install",
HWND hbtn2 = CreateWindow("BUTTON", "&Install",
btnInstallStyle,
150, 60, 100, 30,
hwnd, (HMENU)2, hInstance, NULL);
HWND hbtn3 = CreateWindow("BUTTON", "Remove",
HWND hbtn3 = CreateWindow("BUTTON", "&Remove",
btnRemoveStyle,
260, 60, 100, 30,
hwnd, (HMENU)3, hInstance, NULL);
HMENU hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MAINMENU));
SetMenu(hwnd, hMenu);
HDC hDC = GetDC(hwnd);
int nHeight = -MulDiv(11, GetDeviceCaps(hDC, LOGPIXELSY), 72);
@ -289,8 +342,11 @@ int WINAPI __WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if (!IsDialogMessage(hwnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}

106
main.c
View File

@ -3,6 +3,8 @@
#include <assert.h>
#include <stdio.h>
#include "resource.h"
FILE *g_logFile = NULL;
BOOL RunningAsService = FALSE;
@ -57,7 +59,7 @@ void DetectWine()
if (!GetProcAddress(hNTdll, "wine_get_version"))
{
MessageBox(NULL, "This program is only intended to run under Wine.",
GetErrorMessage(), MB_OK | MB_ICONINFORMATION);
"Error", MB_OK | MB_ICONINFORMATION);
ExitProcess(1);
}
@ -72,14 +74,11 @@ void DetectWine()
{
int result = MessageBox(NULL, "This program is designed for Linux and macOS only!\nDo you want to proceed?",
NULL, MB_YESNO | MB_ICONQUESTION);
if (result == IDYES)
return;
else if (result == IDNO)
if (result == IDNO)
ExitProcess(1);
}
IsLinux = strcmp(__sysname, "Linux") == 0;
printf("Running on %s\n", __sysname);
}
void print(char const *fmt, ...)
@ -222,28 +221,26 @@ void HandleArguments(int argc, char *argv[])
HeapFree(GetProcessHeap(), 0, asciiPath);
}
print("(Steam) Starting service...\n");
if (StartService(schService, 0, NULL) == FALSE)
{
if (GetLastError() == ERROR_SERVICE_ALREADY_RUNNING)
{
print("(Steam) Service is already running\n");
CloseServiceHandle(schService);
CloseServiceHandle(hSCManager);
ExitProcess(0);
}
print("(Steam) Starting service and then exiting...\n");
fclose(g_logFile);
print("StartService: %s\n", GetErrorMessage());
MessageBox(NULL, GetErrorMessage(),
"StartService",
MB_OK | MB_ICONSTOP);
ExitProcess(1);
if (StartService(schService, 0, NULL) != FALSE)
{
CloseServiceHandle(schService);
CloseServiceHandle(hSCManager);
ExitProcess(0);
}
else if (GetLastError() == ERROR_SERVICE_ALREADY_RUNNING)
{
CloseServiceHandle(schService);
CloseServiceHandle(hSCManager);
ExitProcess(0);
}
print("(Steam) Service started successfully, exiting...\n");
CloseServiceHandle(schService);
CloseServiceHandle(hSCManager);
ExitProcess(0);
MessageBox(NULL, GetErrorMessage(),
"StartService",
MB_OK | MB_ICONSTOP);
ExitProcess(1);
}
else if (strcmp(argv[1], "--install") == 0)
{
@ -272,32 +269,40 @@ void HandleArguments(int argc, char *argv[])
CreateBridge();
ExitProcess(0);
}
else if (strcmp(argv[1], "--version") == 0)
{
/* Already shows the version */
ExitProcess(0);
}
else if (strcmp(argv[1], "--help") == 0)
{
printf("Usage:\n");
printf(" %s [args]\n\n", argv[0]);
printf("Arguments:\n");
printf(" --help Show this help\n\n");
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(" This will remove the service and delete C:\\windows\\bridge.exe\n\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(" (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");
print("Usage:\n"
" %s [args]\n"
"\n"
"Arguments:\n"
" --help Show this help\n"
"\n"
" --version Show version\n"
"\n"
" --install Install service\n"
" This will copy the binary to C:\\windows\\bridge.exe and register it as a service\n"
"\n"
" --uninstall Uninstall service\n"
" This will remove the service and delete C:\\windows\\bridge.exe\n"
"\n"
" --steam Reserved for Steam\n"
" This will start the service and exit (used with bridge.sh)\n"
"\n"
" --no-service Do not run as service\n"
" (only for --steam)\n"
"\n"
" --service Reserved for service\n"
"\n"
" --rpc <dir> Set RPC_PATH environment variable\n"
" This is used to specify the directory where 'discord-ipc-0' is located\n"
"\n"
"Note: If no arguments are provided, the GUI will be shown instead\n",
argv[0]);
ExitProcess(0);
}
}
@ -309,11 +314,12 @@ int main(int argc, char *argv[])
g_logFile = fopen(logFilePath, "w");
if (g_logFile == NULL)
{
printf("Failed to open logs file: %ld\n",
GetLastError());
MessageBox(NULL, "Failed to open logs file", "Error", MB_OK | MB_ICONERROR);
printf("Failed to open logs file: %ld\n", GetLastError());
ExitProcess(1);
}
print("rpc-bridge v%s %s-%s\n", VER_VERSION_STR, GIT_BRANCH, GIT_COMMIT);
if (argc > 1)
HandleArguments(argc, argv);
else

9
resource.h Normal file
View File

@ -0,0 +1,9 @@
#define IDR_MAINMENU 101
#define IDR_LICENSE_TXT 102
#define IDM_HELP_DOCUMENTATION 40001
#define IDM_HELP_LICENSE 40002
#define IDM_HELP_ABOUT 40003
#define IDM_VIEW_LOG 40004
#define VER_VERSION 1, 4, 0, 0
#define VER_VERSION_STR "1.4.0.0\0"

View File

@ -88,13 +88,13 @@ void InstallService(int ServiceStartType, LPCSTR Path)
{
print("Registering service\n");
if (IsLinux == FALSE)
{
/* FIXME: I don't know how to get the TMPDIR without getenv */
MessageBox(NULL, "Registering as a service is not supported on macOS at the moment.",
"Unsupported", MB_OK | MB_ICONINFORMATION);
ExitProcess(1);
}
// if (IsLinux == FALSE)
// {
// /* FIXME: I don't know how to get the TMPDIR without getenv */
// MessageBox(NULL, "Registering as a service is not supported on macOS at the moment.",
// "Unsupported", MB_OK | MB_ICONINFORMATION);
// ExitProcess(1);
// }
SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
if (schSCManager == NULL)