Lachee / discord-rpc-csharp

C# custom implementation for Discord Rich Presence. Not deprecated and still available!
MIT License
579 stars 96 forks source link

[BUG] Presence Will Not Set - Very Specific And Complicated Issue #135

Closed MistressPlague closed 3 years ago

MistressPlague commented 3 years ago

Describe the bug Presence will not set when this is being used in a melonloader mod for a IL2CPP game. Could you add me on discord at Plague#6278 so we can get to the bottom of this, as I feel it is not simple?

To Reproduce Steps to reproduce the behavior: Create A MelonLoader Mod For VRChat & Try To Use This Library, It Will Not Work, But Using DllImport On The OG Discord-RPC (C++) Works. - Yes, I embedded your code instead of using a external DLL, which fixes the reference not existing issue.

Expected behavior It working lul

Desktop (please complete the following information):

Additional context It would be beyond more efficient to find the cause of this on discord than here.

EDIT: Yes, I have made a seperate simple winforms project and tested, my code works fine there and the presence works. It does not when in a MelonLoader mod for VRChat however.

MistressPlague commented 3 years ago

Here is a test mod for MelonLoader (Latest): discord-rpc-csharp Test Mod.zip (You can view the source with DnSpy if you'd like, it is not obfuscated at all)

Lachee commented 3 years ago

If you are using Unity3D, you need to use the Native Named Pipe instead of the default Managed Named Pipe. This is a limitation of mono and how it handles pipes (it doesn't, so I wrote my own implementation).

If you want more information from the pipe to see what is causing the issues, I recommend writing a logger to use your MelonLogger.Msg and setting it to Verbose (or just using the Console Logger )

MistressPlague commented 3 years ago

I'll look into it and update you if I find anything.

MistressPlague commented 3 years ago

This is all I got:

INFO: Attempting a new connection INFO: RPC Connection Started TRCE: ============================ TRCE: Enqueue Command: DiscordRPC.RPC.Commands.PresenceCommand TRCE: Assembly: discord-rpc-csharp Test Mod, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null TRCE: Pipe: DiscordRPC.IO.ManagedNamedPipeClient TRCE: Platform: Microsoft Windows NT 10.0.18362.0 TRCE: applicationID: 812162424068898836 TRCE: targetPipe: -1 TRCE: POLL_RATE: 1000 TRCE: _maxRtQueueSize: 512 TRCE: _maxRxQueueSize: 0 TRCE: ============================ TRCE: Connecting to the pipe through the DiscordRPC.IO.ManagedNamedPipeClient TRCE: ManagedNamedPipeClient.Connection(-1) TRCE: Connection Attempt 0 () INFO: Attempting to connect to discord-ipc-0 TRCE: Waiting for connection... INFO: Connected to discord-ipc-0 TRCE: Done. Result: False TRCE: Begining Read of 16384 bytes TRCE: Connected to the pipe. Attempting to establish handshake... TRCE: Enqueued Message, but queue size is 0. TRCE: Attempting to establish a handshake... TRCE: Sending Handshake...

I'm not sure what is failing here. For context, this is a MelonLoader mod, VRChat is a Unity3D IL2CPP game, but my assembly is loaded into it.

Latest Build: discord-rpc-csharp Test Mod.zip

Any ideas? I really want this working.

Lachee commented 3 years ago

If you are using Unity3D, you need to use the Native Named Pipe instead of the default Managed Named Pipe

probably why it isn't working.

This is a limitation of mono and how it handles pipes (it doesn't, so I wrote my own implementation).

this is why that wouldn't work.

MistressPlague commented 3 years ago

Except that native named pipe released is not made really usable for standalone unity3d injected dlls. I never made VRChat, thus have no editor access. How would I use it in a standalone MelonLoader mod dll?

And from the standalone repo it looks painful to use at best, not helped by no docs.

I'll manage. Thanks!

I will release a repo in time making this easy for people to do.