Lachee / discord-rpc-csharp

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

[BUG] Does not work on Godot 3 unless UnityNamedPipe is used #94

Closed sitiom closed 1 year ago

sitiom commented 3 years ago

Describe the bug DiscordRpcClient fails to connect in Godot normally without using UnityNamedPipe

Log output:

INFO: Attempting a new connection
INFO: RPC Connection Started
TRCE: ============================
TRCE: Assembly:             DiscordRPC, Version=1.0.150.0, Culture=neutral, PublicKeyToken=null
TRCE: Enqueue Command: DiscordRPC.RPC.Commands.PresenceCommand
TRCE: Pipe:                 DiscordRPC.IO.ManagedNamedPipeClient
TRCE: Platform:             Microsoft Windows NT 6.2.9200.0
TRCE: applicationID:        752376874339926187
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
ERR : Failed connection to discord-ipc-0. The operation has timed out.
WARN: Tried to close a already closed pipe.
TRCE: Done. Result: True
TRCE: Skipping sandbox connection.
TRCE: Connection Attempt 1 ()
INFO: Attempting to connect to discord-ipc-1
ERR : Failed connection to discord-ipc-1. The operation has timed out.
WARN: Tried to close a already closed pipe.
TRCE: Done. Result: True
TRCE: Skipping sandbox connection.
TRCE: Connection Attempt 2 ()
INFO: Attempting to connect to discord-ipc-2
ERR : Failed connection to discord-ipc-2. The operation has timed out.
WARN: Tried to close a already closed pipe.
TRCE: Done. Result: True
TRCE: Skipping sandbox connection.
TRCE: Connection Attempt 3 ()
INFO: Attempting to connect to discord-ipc-3
ERR : Failed connection to discord-ipc-3. The operation has timed out.
WARN: Tried to close a already closed pipe.
TRCE: Done. Result: True
TRCE: Skipping sandbox connection.
TRCE: Connection Attempt 4 ()
INFO: Attempting to connect to discord-ipc-4
ERR : Failed connection to discord-ipc-4. The operation has timed out.
WARN: Tried to close a already closed pipe.
TRCE: Done. Result: True
TRCE: Skipping sandbox connection.
TRCE: Connection Attempt 5 ()
INFO: Attempting to connect to discord-ipc-5
ERR : Failed connection to discord-ipc-5. The operation has timed out.
WARN: Tried to close a already closed pipe.
TRCE: Done. Result: True
TRCE: Skipping sandbox connection.
TRCE: Connection Attempt 6 ()
INFO: Attempting to connect to discord-ipc-6
ERR : Failed connection to discord-ipc-6. The operation has timed out.
WARN: Tried to close a already closed pipe.
TRCE: Done. Result: True
TRCE: Skipping sandbox connection.
TRCE: Connection Attempt 7 ()
INFO: Attempting to connect to discord-ipc-7
ERR : Failed connection to discord-ipc-7. The operation has timed out.
WARN: Tried to close a already closed pipe.
TRCE: Done. Result: True
TRCE: Skipping sandbox connection.
TRCE: Connection Attempt 8 ()
INFO: Attempting to connect to discord-ipc-8
ERR : Failed connection to discord-ipc-8. Thread was being aborted.
WARN: Tried to close a already closed pipe.
ERR : Unhandled Exception: System.Threading.ThreadAbortException
ERR : Thread was being aborted.
ERR :   at DiscordRPC.IO.ManagedNamedPipeClient.AttemptConnection (System.Int32 pipe, System.Boolean isSandbox) [0x00168] in <be27f5d1995a470d9db1a68b5833f77c>:0 
  at DiscordRPC.IO.ManagedNamedPipeClient.Connect (System.Int32 pipe) [0x00059] in <be27f5d1995a470d9db1a68b5833f77c>:0 
  at DiscordRPC.RPC.RpcConnection.MainLoop () [0x001ee] in <be27f5d1995a470d9db1a68b5833f77c>:0

To Reproduce Steps to reproduce the behavior:

  1. Create an empty Node2D Scene
  2. Attach a C# script
  3. Initialize DiscordRpcClient somewhere in the script

Desktop (please complete the following information):

Additional context Godot 3.2.3 Mono RC; Haven't tried in 3.2.2 but I think its the same case.

Lachee commented 3 years ago

Hmm this might be a Mono Bug. So it works fine when using the UnityNamedPipe and the native dll with it? If so, then it might be wise to rename that class to MonoNamedPipe instead.

sitiom commented 3 years ago

Hmm this might be a Mono Bug. So it works fine when using the UnityNamedPipe and the native dll with it?

Yep

If so, then it might be wise to rename that class to MonoNamedPipe instead.

Might also make it a nuget package as well.

Edit: Tried Monogame, same case.

Lachee commented 3 years ago

Awesome thanks, ill look into updating it!

GitMuslim commented 3 years ago

I want to put a quick update on this, this DOES work on Godot Linux executable for some reason and I tried using 'UnityNamedPipe' as in the issue's name but I didn't know how to use it, I also tried seeing if this could be a Build Tool bug but no, I tried building it on windows and put it on Linux and it did work, but building it on Linux and puting it on windows doesn't work no matter what the Build Tool type is, either it's dotnet or VS BuildTools or Mono, But one thing is MSBuild (Mono) does work for me on Linux but not on windows, it prints (The SDK resolver type "DotNetMSBuildSdkResolver" failed to load) so that's the only thing I'm unsure about, so if you can help I would gladly appreciate it. :)

sitiom commented 1 year ago

Related issue: https://github.com/godotengine/godot/issues/36958

I'm back after 2 years, Godot 4 now uses .NET 6 which fixes this issue. Continued in #201

GitMuslim commented 1 year ago

lol nice

GitMuslim commented 1 year ago

lol nice

Tbh I don't even remember when I commented this

Anyhow cool that the issue is fixed, it took long but late better than never