Lachee / discord-rpc-csharp

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

Only works until ConnectionEstablished #74

Open Bluscream opened 5 years ago

Bluscream commented 5 years ago
[15:56:49.635] <EFTDiscordPresence> Info - Mod..ctor: Plugin Initialized
[15:56:49.669] <JustEmuTarkov> Error - Logger.Init: Unable to initialize LogWriter: Sharing violation on path G:\Escape from Tarkov\Logs\Plugins.log
[15:56:49.671] <JustEmuTarkov> Info - Mod..ctor: Plugin Initialized
[15:56:50.085] <JustEmuTarkov> Warn - SSL.Disable: Disabling SSL verification!
[15:56:50.187] <JustEmuTarkov> Warn - SSL.Disable: Disabled SSL verification!
[15:56:50.191] <Test Plugin> Error - Logger.Init: Unable to initialize LogWriter: Sharing violation on path G:\Escape from Tarkov\Logs\Plugins.log
[15:56:50.192] <Test Plugin> Info - Main..ctor: Plugin Initialized
Running on Unity 5.6.6f2
-----------------------------
Loading plugins from G:\Escape from Tarkov\Plugins and found 3
-----------------------------
 Discord Rich Presence: 1.0
 JustEmuTarkov: 1.0
 Test Plugin: 1.0
-----------------------------
[15:56:50.217] <EFTDiscordPresence> Info - Mod.InitRPC: [Discord] RichPresence Initialised
[15:56:50.218] <JustEmuTarkov> Info - Mod.OnApplicationStart: OnApplicationStart
[15:56:50.234] <Test Plugin> Debug - ExternalConsole.InitConsole: Console already present, not allocating second time
[15:56:50.235] <Test Plugin> Info - Main.OnApplicationStart: OnApplicationStart
[15:56:50.254] <EFTDiscordPresence> Info - <>c.<InitRPC>b__11_6: OnRpcMessage ConnectionEstablished
[15:56:50.258] <EFTDiscordPresence> Info - <>c__DisplayClass11_0.<InitRPC>b__4: OnConnectionEstablished 0: ConnectionEstablished
[15:56:51.570] <EFTDiscordPresence> Info - Mod.OnLevelWasLoaded: OnLevelWasLoaded 0
[15:56:51.571] <JustEmuTarkov> Info - Mod.OnLevelWasLoaded: OnLevelWasLoaded 0
[15:56:51.571] <Test Plugin> Info - Main.OnLevelWasLoaded: OnLevelWasLoaded 0
[15:56:51.645] <EFTDiscordPresence> Info - Mod.OnGameInitialized: OnGameInitialized
[15:56:51.653] <EFTDiscordPresence> Info - Mod.OnGameInitialized: Loaded assemblies: System.Runtime.Serialization, System.ServiceModel, ?, System.Data, TestPlugin, System.Xml, System.Configuration, HarmonySharedState, JustEmuTarkov, EFTDiscordPresence, DiscordRPC, 0Harmony, IllusionPlugin, IllusionInjector, System, System.Core, TextMeshPro-5.6-Runtime, Poly2Tri, pb_Stl, KdTreeLib, ProBuilderMeshOps-Unity5, ProBuilderCore-Unity5, NLog, Newtonsoft.Json, Comfort.Unity, Comfort, zlib.net, DynamicLoadingKit, DecalSystem.Runtime, AmplifyMotion, UnityEngine.Networking, UnityEngine.UI, Assembly-UnityScript, Assembly-UnityScript-firstpass, Assembly-CSharp, Assembly-CSharp-firstpass, UnityEngine, mscorlib
[15:56:51.655] <EFTDiscordPresence> Info - Mod.OnLevelWasInitialized: OnLevelWasInitialized 0
[15:56:51.658] <JustEmuTarkov> Info - Mod.OnLevelWasInitialized: OnLevelWasInitialized 0
[15:56:51.658] <JustEmuTarkov> Info - Mod.OnGameInitialized: OnGameInitialized
[15:56:51.659] <Test Plugin> Info - Main.OnLevelWasInitialized: OnLevelWasInitialized 0
[15:59:23.742] <EFTDiscordPresence> Info - Mod.OnLevelWasLoaded: OnLevelWasLoaded 44
[15:59:23.742] <JustEmuTarkov> Info - Mod.OnLevelWasLoaded: OnLevelWasLoaded 44
[15:59:23.742] <Test Plugin> Info - Main.OnLevelWasLoaded: OnLevelWasLoaded 44
[15:59:23.812] <EFTDiscordPresence> Info - Mod.OnLevelWasInitialized: OnLevelWasInitialized 44
[15:59:23.812] <JustEmuTarkov> Info - Mod.OnLevelWasInitialized: OnLevelWasInitialized 44
[15:59:23.812] <Test Plugin> Info - Main.OnLevelWasInitialized: OnLevelWasInitialized 44
Lachee commented 5 years ago

Can you please make sure the client has a logger that is writing to your logs and is in TRACE. Additionally, I see you are using Unity 5.6.6f2... This version can be a bit picky on how it loads libraries.

Please make sure you include the native pipe wrapper that the unity example has as Unity by itself doesn't actually support pipes.

Bluscream commented 5 years ago

After setting the level to trace i got some more atleast

INFO: Attempting a new connection
INFO: RPC Connection StartedINFO: RPC Connection Started
[16:31:00.245] <EFTDiscordPresence> Info - Mod.InitRPC: [Discord] RichPresence Initialised
ERR : Cannot Invoke client when AutomaticallyInvokeEvents has been set.

R : Cannot Invoke client when AutomaticallyInvokeEvents has beeTRACE: ============================
TRACE: Assembly:             DiscordRPC, Version=1.0.132.0, Culture=neutral, PublicKeyToken=null
TRACE: Pipe:                 DiscordRPC.IO.ManagedNamedPipeClient
TRACE: Platform:             Microsoft Windows NT 10.0.18362.0
TRACE: applicationID:        628201599025545226
TRACE: targetPipe:           1
TRACE: POLL_RATE:            1000
TRACE: _maxRtQueueSize:      512
TRACE: _maxRxQueueSize:      0
TRACE: ============================
TRACE: Connecting to the pipe through the DiscordRPC.IO.ManagedNamedPipeClient
TRACE: ManagedNamedPipeClient.Connection(1)
TRACE: Connection Attempt 1 ()
INFO: Attempting to connect to discord-ipc-1
ERR : Failed connection to discord-ipc-1. The operation completed successfully.

WARN: Tried to close a already closed pipe.
TRACE: Done. Result: True
TRACE: Skipping sandbox connection.
ERR : Failed to connect for some reason.
[16:31:00.302] <EFTDiscordPresence> Info - <>c.<InitRPC>b__11_6: OnRpcMessage ConnectionFailed
[16:31:00.312] <EFTDiscordPresence> Info - <>c.<InitRPC>b__11_5: OnConnectionFailed 1: ConnectionFailed
TRACE: Enqueued Message, but queue size is 0.
TRACE: Creating Windows Scheme CreatorTRACE: Creating Windows Scheme Creator

ACE: Waiting 1095ms before attempting to connect again
TRACE: Enqueue Command: DiscordRPC.RPC.Commands.SubscribeCommand
TRACE: Enqueue Command: DiscordRPC.RPC.Commands.SubscribeCommand
TRACE: Enqueue Command: DiscordRPC.RPC.Commands.SubscribeCommand
[16:31:00.344] <JustEmuTarkov> Info - Mod.OnApplicationStart: OnApplicationStart
[16:31:00.381] <Test Plugin> Debug - ExternalConsole.InitConsole: Console already present, not allocating second time
[16:31:00.383] <Test Plugin> Info - Main.OnApplicationStart: OnApplicationStart
TRACE: Setting the connection state to DISCONNECTED
TRACE: Connecting to the pipe through the DiscordRPC.IO.ManagedNamedPipeClient
TRACE: ManagedNamedPipeClient.Connection(1)
TRACE: Connection Attempt 1 ()
INFO: Attempting to connect to discord-ipc-1
ERR : Failed connection to discord-ipc-1. The operation completed successfully.

WARN: Tried to close a already closed pipe.
Lachee commented 5 years ago

Okay, since you are using Unity, you are required to use the NativeNamedPipe, not the Managed. Please look at the Unity example as a sample.

Bluscream commented 5 years ago

Is it right that i have put discord-rpc.dll (dynamic x64) in <game>/Data/Plugins?

Bluscream commented 5 years ago

Also i can not set AutoEvents as described in the readme because it's private. image

Lachee commented 5 years ago

AutoEvents is part of the constructor: https://github.com/Lachee/discord-rpc-csharp/blob/master/DiscordRPC/DiscordRpcClient.cs#L217

so you will want to do client = new DiscordRpcClient(discordAppId, autoEvents: false);

Bluscream commented 5 years ago

Ill get to it in a few hours and try again. Btw does it need to be in a monobehavior or does it also work in a plain IPA plugin?

Lachee commented 5 years ago

¯_(ツ)_/¯

Don't forget that you are required to use the NativeNamedPipeClient, not the managed. Like I mentioned before, examples on how it works can be found in the Unity project included in this repository.

Bluscream commented 5 years ago

You can't import unitypackages into a game by someone else :'D anyway, i already imported your pipeclient from your ci into my plugin

Bluscream commented 5 years ago

I made sure but it definitly is loaded:

[16:40:28.468] <EFTDiscordPresence> Info - Mod.OnGameInitialized: Loaded assemblies:
?, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
0Harmony, Version=1.2.0.1, Culture=neutral, PublicKeyToken=null
AmplifyMotion, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Assembly-UnityScript, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Assembly-UnityScript-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Comfort, Version=1.0.0.4, Culture=neutral, PublicKeyToken=null
Comfort.Unity, Version=1.0.0.4, Culture=neutral, PublicKeyToken=null
DecalSystem.Runtime, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null
+ DiscordRPC, Version=1.0.121.0, Culture=neutral, PublicKeyToken=null
DynamicLoadingKit, Version=1.0.5640.17315, Culture=neutral, PublicKeyToken=null
+ EFTDiscordPresence, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
HarmonySharedState, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
IllusionInjector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
IllusionPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
JustEmuTarkov, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
KdTreeLib, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c
pb_Stl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Poly2Tri, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
ProBuilderCore-Unity5, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
ProBuilderMeshOps-Unity5, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
TestPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
TextMeshPro-5.6-Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
UnityEngine.Networking, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
+ UnityNamedPipe, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
zlib.net, Version=1.0.3.0, Culture=neutral, PublicKeyToken=null