Coder Social home page Coder Social logo

lachee / discord-rpc-csharp Goto Github PK

View Code? Open in Web Editor NEW
569.0 20.0 93.0 17.88 MB

C# custom implementation for Discord Rich Presence. Not deprecated and still available!

License: MIT License

C# 86.25% Rich Text Format 11.29% CSS 2.19% JavaScript 0.28%
discord-rpc discord csharp library unity3d rich-presence discord-net discord-rich-presence unity

discord-rpc-csharp's Introduction

Discord Rich Presence

Release ๐Ÿ“ฆ Codacy Badge Nuget GitHub package.json version

This is a C# implementation of the Discord RPC library which was originally written in C++. This avoids having to use the official C++ and instead provides a managed way of using the Rich Presence within the .NET environment*.

While the official C++ library has been deprecated, this library has continued support and development for all your Rich Presence need, without requiring the Game SDK.

Here are some key features of this library:

  • Message Queuing
  • Threaded Reads
  • Managed Pipes*
  • Error Handling & Error Checking with automatic reconnects
  • Events from Discord (such as presence update and join requests)
  • Full Rich Presence Implementation (including Join / Spectate)
  • Inline Documented (for all your IntelliSense needs)
  • Helper Functionality (eg: AvatarURL generator from Join Requests)
  • Ghost Prevention (Tells Discord to clear the RP on disposal)
  • Full Unity3D Editor (Contains all the tools, inspectors and helpers for a Unity3D game all in one package).

Documentation

All the documentation can be found lachee.github.io/discord-rpc-csharp/docs/

Installation

Dependencies:

  • Newtonsoft.Json
  • .NET Standard 2.0

.NET Project

For projects that target either .NET Core or .NETFX, you can get the package on nuget:

PM> Install-Package DiscordRichPresence

You can also Download or Build your own version of the library if you have more specific requirements.

Unity3D Game Engine

Unity Package is being moved to Lachee/Discord-RPC-Unity. Please check the releases / documentation there.

Usage

The Discord.Example project within the solution contains example code, showing how to use all available features. For Unity Specific examples, check out the example project included. There are 3 important stages of usage, Initialization, Invoking and Deinitialization. It's important you follow all 3 stages to ensure proper behaviour of the library.

Initialization

This stage will setup the connection to Discord and establish the events. Once you have done the initialization you can call SetPresence and other variants as many times as you wish throughout your code. Please note that ideally this should only run once, otherwise conflicts may occur with them trying to access the same Discord client at the same time.

public DiscordRpcClient client;

//Called when your application first starts.
//For example, just before your main loop, on OnEnable for unity.
void Initialize() 
{
	/*
	Create a Discord client
	NOTE: 	If you are using Unity3D, you must use the full constructor and define
			 the pipe connection.
	*/
	client = new DiscordRpcClient("my_client_id");			
	
	//Set the logger
	client.Logger = new ConsoleLogger() { Level = LogLevel.Warning };

	//Subscribe to events
	client.OnReady += (sender, e) =>
	{
		Console.WriteLine("Received Ready from user {0}", e.User.Username);
	};
		
	client.OnPresenceUpdate += (sender, e) =>
	{
		Console.WriteLine("Received Update! {0}", e.Presence);
	};
	
	//Connect to the RPC
	client.Initialize();

	//Set the rich presence
	//Call this as many times as you want and anywhere in your code.
	client.SetPresence(new RichPresence()
	{
		Details = "Example Project",
		State = "csharp example",
		Assets = new Assets()
		{
			LargeImageKey = "image_large",
			LargeImageText = "Lachee's Discord IPC Library",
			SmallImageKey = "image_small"
		}
	});	
}

Invoking

Invoking is optional. Use this when thread safety is paramount.

The client will store messages from the pipe and won't invoke them until you call Invoke() or DequeueMessages(). It does this because the pipe is working on another thread, and manually invoking ensures proper thread safety and order of operations (especially important in Unity3D applications).

In order to enable this method of event calling, you need to set it in the constructor of the DiscordRpcClient under autoEvents.

//The main loop of your application, or some sort of timer. Literally the Update function in Unity3D
void Update() 
{
	//Invoke all the events, such as OnPresenceUpdate
	client.Invoke();
};

Here is an example on how a Timer could be used to invoke the events for a WinForm

var timer = new System.Timers.Timer(150);
timer.Elapsed += (sender, args) => { client.Invoke(); };
timer.Start();

Deinitialization

It's important that you dispose your client before your application terminates. This will stop the threads, abort the pipe reads, and tell Discord to clear the presence. Failure to do so may result in a memory leak!

//Called when your application terminates.
//For example, just after your main loop, on OnDisable for unity.
void Deinitialize() 
{
	client.Dispose();
}

Building

Release ๐Ÿ“ฆ Documentation ๐Ÿ“š

DiscordRPC Library

dotnet build -c Release

Unity3D

If you wish to have barebones Unity3D implementation, you need to build the DiscordRPC.dll, the Unity Named Pipes Library and the UnityNamedPipe.cs. Put these in your own Unity Project and the .dlls in a folder called Plugins.

UWP / .NET MAUI / WIN UI 3

For now, the library doesn't work on UWP applications until we find the issue and fix it.

In order to make this library work with the WIN UI 3 related applications such as .NET MAUI, you need to define runFullTrust Capability inside Package.appxmanifest.

Here is an example of how to add runFullTrust to your WIN UI 3 application:

Package.appxmanifest:

<?xml version="1.0" encoding="utf-8"?>

<Package
  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
  xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
  IgnorableNamespaces="uap rescap">
  ...
    <Capabilities>
	    <rescap:Capability Name="runFullTrust" />
    </Capabilities>
</Package>

If you use .NET MAUI or WIN UI 3 template for C#, it automatically puts runFullTrust capability.

discord-rpc-csharp's People

Contributors

abnersquared avatar almighty-shogun avatar azyyyyyy avatar canadahonk avatar codacy-badger avatar ijre avatar j0nathan550 avatar jonashouben avatar kakusaoao avatar kianakaslana avatar kotx avatar lachee avatar letsdank avatar maximmax42 avatar peppy avatar pjb3005 avatar recklessboon avatar regorforgot avatar ruintd avatar s1rcheese avatar sll552 avatar smaltin avatar still34 avatar teredokot avatar whouishere avatar youknowedo avatar yousucklol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

discord-rpc-csharp's Issues

I Can't update. help me plz

` private void button1_Click(object sender, EventArgs e)
{
client = new DiscordRpcClient(ClientID, true, DiscordPipe);

        client.OnPresenceUpdate += (sender2, e2) =>
        {
            richTextBox1.Text += e2.Presence;
        };

        if (button1.Text == "Connect")
        {
            presence.Details = textBox1.Text;

            presence.Timestamps = new Timestamps()
            {
                Start = DateTime.UtcNow
            };

            presence.Party = new Party()
            {
                ID = Secrets.CreateFriendlySecret(new Random()),
                Size = 1,
                Max = 4
            };

            client.SetPresence(presence);

            client.Initialize();

            Properties.Settings.Default.Details = textBox1.Text;
            Properties.Settings.Default.Stats = textBox2.Text;
            Properties.Settings.Default.LImageText = textBox5.Text;
            Properties.Settings.Default.SImageText = textBox6.Text;

            Properties.Settings.Default.LImageKey = comboBox1.SelectedIndex;
            Properties.Settings.Default.SImageKey = comboBox2.SelectedIndex;
            Properties.Settings.Default.Save();

            button1.Text = "Update";
        }
        else
        {
            presence.Details =  textBox1.Text;

            client.SetPresence(presence);
        }
    }`

TypeLoadException

Hello I have this error when I press play button:

(I put DiscordRPC.dll on Assets/Plugins/ and DiscordRPC.Native.dll on ProjectFolder/ with Unity 5.6.6f2)

TypeLoadException: Could not load type 'DiscordRPC.RPC.Payload.EventPayload' from assembly 'DiscordRPC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
System.Reflection.MonoMethodInfo.GetMethodInfo (IntPtr handle) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:59)
System.Reflection.MonoMethodInfo.GetAttributes (IntPtr handle) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:75)
System.Reflection.MonoMethod.get_Attributes () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:245)
System.Reflection.MethodBase.get_IsSpecialName () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:184)
UnityEditor.Build.BuildPipelineInterfaces.InitializeBuildCallbacks (Boolean findBuildProcessors, Boolean findSceneProcessors) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:150)

No parties/join request stuff/etc

I attempted to use this library without creating parties, subscriptions, or anything that involves actual interaction in discord (basically, I set up a client that updates Details and State, nothing else). However, nothing happened. Is there a way to get around it? I donโ€™t want โ€œJoinโ€ and โ€œSpecateโ€ buttons, etc.

Events are not being triggered.

I've subscribed to said events but nothing is being triggered :(

            //Create RPC client.
            rpc = new DiscordRpcClient(clientID, true);
            rpc.Subscribe(EventType.JoinRequest);
            rpc.Subscribe(EventType.Join);
            api.Logger.LogInfo("Starting rich presence ... ");

            //Subscribe to events.
            rpc.OnConnectionFailed += (sender, e) => api.Logger.LogError("There was an error while trying to connect to the rich presence.");
            rpc.OnConnectionEstablished += (sender, e) => api.Logger.LogInfo("Rich presence connected.");
            rpc.OnError += (sender, e) => api.Logger.LogError("Rich presence error: " + e.Message);
            rpc.OnReady += (sender, e) => api.Logger.LogInfo("Rich presence ready.");

            //Start the RPC.
            rpc.Initialize();

Unity 2018.3+ Deprecates WWW

The WWW class found in DiscordUser.cs is throwing obsolete warnings. The WWW that is used to get the users avatar needs to be changed to UnityWebRequest instead.

Annoyingly since I wish to keep support for Unity 5 (because I am a masochist apparently) I will probably need to add #defines for older versions of unity to keep using the old WWW.

(yay! This code base is going to get messy)

Asynchronous Pipes

Hey guys, I would love to help you with testing, on my current Linux setup the log produces some errors:

INFO: Attempting a new connection
INFO: Attempting to connect to /run/user/1000/discord-ipc-0
ERR : Failed connection to /run/user/1000/discord-ipc-0. Asynchronous pipe mode is not supported
WARN: Tried to close a already closed pipe.
INFO: Attempting to connect to /run/user/1000/discord-ipc-1
ERR : Failed connection to /run/user/1000/discord-ipc-1. Asynchronous pipe mode is not supported
WARN: Tried to close a already closed pipe.

And etc, all pipes fail.

Originally posted by @egordorichev in #53 (comment)

Remove ThreadAbort

Thread abort seems to be causing issues with Unity, causing it to freeze forever due to how mono handles the exception. After some research I discovered that the pipe read will just return a 0 instantly if .Close() is called and Asynchronous mode is set on the pipe (which it is).

Timestamps adds 4 hours?

using the code

Timestamps = new Timestamps()
{
        Start = DateTime.Now,
        End = null
}

produces results like:
Image showing 4 hours

It's adding on an extra four hours to this? Is this a timezone issue or something? Do I need to do

DateTime.Now.AddHours to compensate on every client or something? Just started using RPC, so I might be missing something.

Program.cs

error
DiscordRPC.dll'. Cannot find or open the PDB file.

i have the pdb file within the output folder

this is my program.cs file

`class Program
{
public static DiscordRpcClient client;

    static void Main(string[] args)
    {
        client = new DiscordRpcClient("id", true, 1);

        //Subscribe to events
        client.OnPresenceUpdate += (sender, e) =>
        {
            Console.WriteLine("Received Update! {0}", e.Presence);
        };

        //Connect to the RPC
        client.Initialize();

        //Set the rich presence
        client.SetPresence(new RichPresence()
        {
            Details = "csharp example",
            State = "csharp example",
            Assets = new Assets()
            {
                LargeImageKey = "removed",
                LargeImageText = "removed",
                SmallImageKey = ""
            }
        });
        Console.ReadLine();
    }
}`

i dont have any idea what the problem is

Kind regards,
Phil

Doesn't connect.

Hey, this is my first day experimenting with this library.. I've messed around with my code multiple ways and It keeps failing to connect or I really don't know what's going on, they're no errors or anything showing me what the problem is.

Here is my code
https://hastebin.com/ulexifutuq.cs

Thanks :D

[Unity] Doesn't work on player

Discord RPC doesn't work if I build the application, only on the editor.

Using Unity 2018.3.12f1 Personal and lastest package

[Critical!] Discord Presence can't find library once compiled.

The libraries are included with the Windows build, so there shouldn't be a reason this error appears.


TRCE: Creating Windows Scheme Creator
WARN: Client has not yet initialized, but events are being subscribed too. Storing them as state instead.
WARN: The client is not yet initialized, storing the presence as a state instead.
TRCE: Enqueue Command: DiscordRPC.RPC.Commands.PresenceCommand
INFO: Attempting a new connection
TRCE: Initializing Thread. Creating pipe object.
TRCE: Connecting to the pipe through the DiscordRPC.Unity.UnityNamedPipe
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-0 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-1 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-2 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-3 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-4 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-5 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-6 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-7 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-8 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-9 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
ERR : Failed to connect for some reason.
TRCE: Enqueue Message: ConnectionFailed
TRCE: Waiting 1095ms before attempting to connect again
TRCE: Setting the connection state to DISCONNECTED
TRCE: Connecting to the pipe through the DiscordRPC.Unity.UnityNamedPipe
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-0 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-1 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-2 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-3 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-4 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-5 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-6 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-7 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-8 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-9 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
ERR : Failed to connect for some reason.
TRCE: Enqueue Message: ConnectionFailed
TRCE: Waiting 2285ms before attempting to connect again
TRCE: Setting the connection state to DISCONNECTED
TRCE: Connecting to the pipe through the DiscordRPC.Unity.UnityNamedPipe
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-0 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-1 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-2 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-3 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-4 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-5 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-6 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-7 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-8 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-9 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
ERR : Failed to connect for some reason.
TRCE: Enqueue Message: ConnectionFailed
TRCE: Waiting 3475ms before attempting to connect again
TRCE: Setting the connection state to DISCONNECTED
TRCE: Connecting to the pipe through the DiscordRPC.Unity.UnityNamedPipe
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-0 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-1 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-2 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-3 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-4 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-5 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-6 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-7 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-8 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-9 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
ERR : Failed to connect for some reason.
TRCE: Enqueue Message: ConnectionFailed
TRCE: Waiting 4665ms before attempting to connect again
TRCE: Enqueue Command: DiscordRPC.RPC.Commands.PresenceCommand
TRCE: Setting the connection state to DISCONNECTED
TRCE: Connecting to the pipe through the DiscordRPC.Unity.UnityNamedPipe
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-0 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-1 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-2 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-3 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-4 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-5 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-6 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-7 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-8 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-9 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
ERR : Failed to connect for some reason.
TRCE: Enqueue Message: ConnectionFailed
TRCE: Waiting 5855ms before attempting to connect again
TRCE: Setting the connection state to DISCONNECTED
TRCE: Connecting to the pipe through the DiscordRPC.Unity.UnityNamedPipe
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-0 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-1 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-2 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-3 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-4 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-5 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-6 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-7 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-8 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-9 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
ERR : Failed to connect for some reason.
TRCE: Enqueue Message: ConnectionFailed
TRCE: Waiting 7045ms before attempting to connect again
TRCE: Setting the connection state to DISCONNECTED
TRCE: Connecting to the pipe through the DiscordRPC.Unity.UnityNamedPipe
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-0 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-1 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-2 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-3 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-4 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-5 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-6 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-7 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-8 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-9 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
ERR : Failed to connect for some reason.
TRCE: Enqueue Message: ConnectionFailed
TRCE: Waiting 8235ms before attempting to connect again
TRCE: Setting the connection state to DISCONNECTED
TRCE: Connecting to the pipe through the DiscordRPC.Unity.UnityNamedPipe
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-0 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-1 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-2 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-3 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-4 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-5 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-6 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-7 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-8 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-9 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
ERR : Failed to connect for some reason.
TRCE: Enqueue Message: ConnectionFailed
TRCE: Waiting 9425ms before attempting to connect again
TRCE: Setting the connection state to DISCONNECTED
TRCE: Connecting to the pipe through the DiscordRPC.Unity.UnityNamedPipe
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-0 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-1 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-2 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-3 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-4 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-5 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-6 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-7 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-8 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-9 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
ERR : Failed to connect for some reason.
TRCE: Enqueue Message: ConnectionFailed
TRCE: Waiting 10615ms before attempting to connect again
TRCE: Setting the connection state to DISCONNECTED
TRCE: Connecting to the pipe through the DiscordRPC.Unity.UnityNamedPipe
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-0 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-1 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-2 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-3 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-4 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-5 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-6 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-7 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-8 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-9 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
ERR : Failed to connect for some reason.
TRCE: Enqueue Message: ConnectionFailed
TRCE: Waiting 11805ms before attempting to connect again
TRCE: Setting the connection state to DISCONNECTED
TRCE: Connecting to the pipe through the DiscordRPC.Unity.UnityNamedPipe
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-0 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-1 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-2 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-3 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-4 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-5 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-6 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-7 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-8 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-9 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
ERR : Failed to connect for some reason.
TRCE: Enqueue Message: ConnectionFailed
TRCE: Waiting 12995ms before attempting to connect again
TRCE: Setting the connection state to DISCONNECTED
TRCE: Connecting to the pipe through the DiscordRPC.Unity.UnityNamedPipe
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-0 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-1 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-2 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-3 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-4 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-5 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-6 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-7 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-8 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
TRCE: PIPE WIN
INFO: Connecting to discord-ipc-9 ()
ERR : Failed: System.DllNotFoundException, NativeNamedPipe
TRCE: Skipping sandbox because this platform does not support it.
ERR : Failed to connect for some reason.
TRCE: Enqueue Message: ConnectionFailed
TRCE: Waiting 14185ms before attempting to connect again
TRCE: Initiated shutdown procedure
ERR : Unhandled Exception: System.Threading.ThreadAbortException
ERR : 
ERR :   at (wrapper managed-to-native) System.Threading.Thread.SleepInternal(int)
  at System.Threading.Thread.Sleep (System.Int32 millisecondsTimeout) [0x00019] in <c6bd535f6ab848b4a13f34d01b756eef>:0 
  at DiscordRPC.RPC.RpcConnection.MainLoop () [0x003bf] in <5f0b8a0591e64a36a1937aa82979578c>:0 
TRCE: Setting the connection state to DISCONNECTED

Create NativeNamedPipeClient

In the latest commit, I have added support for custom Named Pipe Clients. The main purpose of this is part of a solution with a unity limitation. There is absolutely no way to abort a Read for a NamedPipeClientStream.Read or EndRead within Unity. Calling WaitHandle.Close(); does nothing and closing the stream hangs until the read is finish. It ignores thread.Abort(); and there is a bug with unity's NamedPipeClientStream that it isn't actually asynchronous in the sense that it cannot write while reading (non-duplex) (so I cannot send a close signal to the server).

My latest commit allows me to now create a native unmanaged client in C++ and use DLLImports into the library. This isn't the best solution and actually makes this library useless (avoiding dll imports and a fully managed solution), but for unity it is the only thing that is viable.

This is current under help wanted as I am fairly new in writing C++ and I feel writing a pipe client is a bit out of my depth. Looking for advice and possibly even a solution.

Tutorial Projects for Non-Unity3D

There needs to be some tutorial projects and examples that do not use the Unity3D. Proper documentation and a step by step guide of helping people use the library.

Migrate Unity 5.5 Fixes

Unity has a really weird set of rules. It is using .NET 2.0, but it basically acting as .NET 3.5..... but has the feature set of C# 5. I fixed a bunch of import errors within the Unity branch, such as removing the somevalue?.Invoke() as C# 5 does not support it. Requires merging.

SetPresence doesn't work

Hello, I don't know if I'm doing it wrong but I can't get the SetPresence function working on Unity 2017.1.3p3.

I only get this :
2018-07-22_17h18_01

Here is my code :

 public DiscordRpcClient client;

    void Initialize()
    {
        client = new DiscordRpcClient(TheClientID, null, true, -1, new DiscordRPC.IO.NativeNamedPipeClient()); //Create a discord client
        client.Logger = new ConsoleLogger() { Level = LogLevel.Warning }; //Set the logger

        //Subscribe to events
        client.OnPresenceUpdate += (sender, e) =>
        {
            Debug.LogFormat("Received Update! {0}", e.Presence);
        };

        client.Initialize(); //Connect to the RPC

        //Set the rich presence
        client.SetPresence(new RichPresence()
        {
            Details = "Example Project",
            State = "csharp example",
            Assets = new Assets()
            {
                LargeImageKey = "default"
            }
        });
    }

    void OnEnable()
    {
        DontDestroyOnLoad(gameObject);
        Initialize();
    }

    void Update()
    {
        client.Invoke(); //Invoke all the events, such as OnPresenceUpdate
    }

    void OnDisable()
    {
        client.Dispose();
    }

crashes

Added discord-rpc-csharp to our project, some users get following errors:

Either the IAsyncResult object did not come from the corresponding async method on this type, or EndRead was called multiple times with the same IAsyncResult.
   at System.IO.Stream.EndRead(IAsyncResult asyncResult)
   at System.IO.Pipes.PipeStream.EndRead(IAsyncResult asyncResult)
   at DiscordRPC.IO.ManagedNamedPipeClient.EndRead(IAsyncResult callback)
   at System.IO.Pipes.PipeStream.AsyncPSCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
mscorlib
System.ArgumentException: Either the IAsyncResult object did not come from the corresponding async method on this type, or EndRead was called multiple times with the same IAsyncResult.
   at System.IO.Stream.EndRead(IAsyncResult asyncResult)
   at System.IO.Pipes.PipeStream.EndRead(IAsyncResult asyncResult)
   at DiscordRPC.IO.ManagedNamedPipeClient.EndRead(IAsyncResult callback)
   at System.IO.Pipes.PipeStream.AsyncPSCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
System.Collections.ListDictionaryInternal

Int32 EndRead(System.IAsyncResult)

and

Arithmetic operation resulted in an overflow.
   at DiscordRPC.IO.PipeFrame.ReadStream(Stream stream)
   at DiscordRPC.IO.ManagedNamedPipeClient.EndRead(IAsyncResult callback)
   at System.IO.Pipes.PipeStream.AsyncPSCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
Discord RPC
System.OverflowException: Arithmetic operation resulted in an overflow.
   at DiscordRPC.IO.PipeFrame.ReadStream(Stream stream)
   at DiscordRPC.IO.ManagedNamedPipeClient.EndRead(IAsyncResult callback)
   at System.IO.Pipes.PipeStream.AsyncPSCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
System.Collections.ListDictionaryInternal

Boolean ReadStream(System.IO.Stream)

Not sure what they do to get it...

DiscordRPC NewtonSoft.Json not loading

When i try to open my application using DiscordRPC it loops this in the console

ERR : Unhandled Exception: System.IO.FileLoadException ERR : Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I included both DiscordRPC and DiscordRPC.Native in the executable directory. I also tried using the DLL from the compiled example but that also dint work.

Query about DotNetCore Compatibility

Tried to send an email but couldn't find any working contact methods.

Just wondering what level of Core compatibility there is with this project.
There are specific instructions for targeting Core, but when doing a dotnet restore it warns that it restores with target .NETFramework instead of .NETCoreApp.

Is it compatible in the sense that you can use it from Core as long as you've also got Framework, or is it truly compatible (can run on Linux/Mac just fine) and it just restored to Framework because reasons?

Update Readme

The readme is significantly out of date. This library is no longer async (instead using threads for IO operations and unity support) and has a bunch of new features. The new readme should include:

  • Updated Preqs
  • How to connect with Initialize
  • A simple example showing the flow of sending presence
  • A simple example showing the flow of a join request

Extras that could be included or made into a wiki page:

  • How to assign loggers, and create new loggers
  • The solution to the unity bug with NativeNamedPipeClient (TODO)
  • Events and the different ways of receiving them
  • Avoiding ghosting with ClearPresence

Validate Register Uri Scheme Works on All Platforms

The RegisterUriScheme function needs to be tested and validated on all platforms. So far only Windows has been tested, but both Unix and MacOSX also need to be tested, especially mac since it has been disabled up until now.

  • Windows
  • Linux
  • MaxOSX

TypeLoadException thrown on deserializing json response

TypeLoadException is thrown by frame.GetObject<EventPayload>(); RpcConnection#L29 while trying to parse JSON response data to a EventPayload

Json data:

{
	"cmd": "DISPATCH",
	"data": {
		"v": 1,
		"config": {
			"cdn_host": "cdn.discordapp.com",
			"api_endpoint": "//discordapp.com/api",
			"environment": "production"
		},
		"user": {
			"id": "155357872413212672",
			"username": "Senpai",
			"discriminator": "7297",
			"avatar": "0bd63b57da6e6119d54560a6f2c6165f",
			"bot": false
		}
	},
	"evt": "READY",
	"nonce": null
}

It seems that the TypeLoadException is caused by the EventPayload.Data. Changing the type of the field fixes the problem.

I'm targeting .NET Framework 3.5 and editing an Assembly-CSharp from a unity game.

Output Log:

INFO: Attempting a new connection
INFO: Initializing Thread. Creating pipe object.
INFO: Connecting to the pipe through the Mod.Discord.IO.NativeNamedPipeClient
INFO: Attempting to connect to \\?\pipe\discord-ipc-0
INFO: Succesfully connected to \\?\pipe\discord-ipc-0
INFO: Connected to the pipe. Attempting to establish handshake...
INFO: Attempting to establish a handshake...
INFO: Sending Handshake...
INFO: Setting the connection state to CONNECTING
INFO: Connection Established. Starting reading loop...
INFO: Read Payload: Frame
ERR : Failed to parse event! Could not load type 'DiscordRPC.RPC.Payload.EventPayload' from assembly 'DiscordRPC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
ERR : Data: {"cmd":"DISPATCH","data":{"v":1,"config":{"cdn_host":"cdn.discordapp.com","api_endpoint":"//discordapp.com/api","environment":"production"},"user":{"id":"155357872413212672","username":"Senpai","discriminator":"7297","avatar":"0bd63b57da6e6119d54560a6f2c6165f","bot":false}},"evt":"READY","nonce":null}

(Out of topic: RpcConnection#301 throws a FormatException too, as the json data contains { } and the message is then passed to a string.Format even tho the args are empty)

Setting Timestamp end time results in a crash.

Here's my code.

DiscordManager.Presence.Timestamps = new Timestamps()
{
     End = DateTime.UtcNow.AddSeconds(100)
};

DiscordManager.Client.SetPresence(DiscordManager.Presence);

Here's the exception being thrown when doing so.

ERR : Unhandled Exception: Newtonsoft.Json.JsonSerializationException
ERR : Error getting value from 'epochEnd' on 'DiscordRPC.Timestamps'.
ERR :    at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.Linq.JToken.FromObjectInternal(Object o, JsonSerializer jsonSerializer)
   at Newtonsoft.Json.Linq.JObject.FromObject(Object o, JsonSerializer jsonSerializer)
   at Newtonsoft.Json.Linq.JObject.FromObject(Object o)
   at DiscordRPC.RPC.Payload.ArgumentPayload.SetObject(Object obj)
   at DiscordRPC.RPC.Payload.ArgumentPayload..ctor(Object args, Int64 nonce)
   at DiscordRPC.RPC.Commands.PresenceCommand.PreparePayload(Int64 nonce)
   at DiscordRPC.RPC.RpcConnection.ProcessCommandQueue()
   at DiscordRPC.RPC.RpcConnection.MainLoop()

Found conflicts between different versions of "Newtonsoft.Json"

I'm using Newtonsoft v1.11 in my project, installed via NuGet, when I build I get the warning:

Found conflicts between different versions of "Newtonsoft.Json that could not be resolved"
When I build, the RPC client then says that it cannot find v1.11 of Newtonsoft.Json even though I have the DLL in the same directory as my program

Fails to connect to pipe on macOS

while it works perfect on windows and linux, i fail to connect on macos.
It spams the following:

ERR : Failed connection to /var/folders/xc/wbs6jsyx4dq8_nd06b2zjg600000gr/T//snap.discord/discord-ipc--1. Error on creating named pipe: error code -1
WARN: Tried to close a already closed pipe.
ERR : Failed to connect for some reason.

Pipe EndRead being called multiple times possibly.

I don't know if this is the correct way to post this but i got this error and have no idea how to fix it.

System.ArgumentException: 'Either the IAsyncResult object did not come from the corresponding async method on this type, or EndRead was called multiple times with the same IAsyncResult.'

What i am doing is:
` public static DiscordRpcClient customRPClient = null;

    public static void SetCustomRPC(string details, string state)
    {
        customRPClient = new DiscordRpcClient("506120925280993305");
        customRPClient.Initialize();

        customRPClient.SetPresence(new RichPresence()
        {
            Details = details,
            State = state,
        });
    }`

Then calling it from a other class..

Add PipeEstablished and PipeConnectionFailure messages

There is a issue on the Offical Discord Implementation that it is not possible to know if discord is currently running or not.

Adding a PipeEstablishedand a PipeConnectionFailure message will allow for them to listen to those callbacks and abort the connection if necessary. The PipeEstablished should be called when the AttemptConnection succeeds. The PipeConnectionFailure should occur everytime we try to connect to a pipe and it times out or fails for some other reason. Might be better design however to just stick it as the inverse of PipeEstablished and put it next to AttemptConnection

How to set the End timestamp correctly?

Hi!
I know this isn`t really an issue, anyways ive been trying to set the "Time Left" ( 00:00 Left) Thingy and it always says 00:00 Left when i try it.
Defining the time when its over:
DateTime timeover = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, DateTime.UtcNow.Hour + Hours, DateTime.UtcNow.Minute + Minutes, DateTime.UtcNow.Second + 10);
Setting Timestamps:

Timestamps = new DiscordRPC.Timestamps() { Start = DateTime.UtcNow, End = timeover }

Hours and Minutes are an Int defined by a NumericUpDown

System.NullReferenceException - _stream was null

Hi, i've recently been looking at some libraries to add Discord Rich Presence support for C#, and I came across your library as the most complete one. I've downloaded your master branch and built the .dll, copied into the program of choice (I'm trying to make a plugin for a sim racing program called SimHub), referenced in VS.

I've looked at the DiscordRPC.Example code and copied what's relevant into my .CS file. Now when I run the code, it opens up the program, then shortly after, breaks with an unhandled exception

System.NullReferenceException: 'Object reference not set to an instance of an object.'

_stream was null.

I have re-written everything a few times, but this error is one I cannot get past.

System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Discord RPC
StackTrace:
at DiscordRPC.IO.ManagedNamedPipeClient.Close() in C:\Users\morga\Downloads\discord-rpc-csharp-master\Discord RPC\IO\ManagedNamedPipeClient.cs:line 218
at DiscordRPC.IO.ManagedNamedPipeClient.Dispose() in C:\Users\morga\Downloads\discord-rpc-csharp-master\Discord RPC\IO\ManagedNamedPipeClient.cs:line 233
at DiscordRPC.RPC.RpcConnection.MainLoop() in C:\Users\morga\Downloads\discord-rpc-csharp-master\Discord RPC\RPC\RpcConnection.cs:line 369
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Any help would be greatly appreciated.

Cheers,
Morgan

Add Linux / Mac Support

The library currently only supports Windows machines. This is mostly due to the Uri Scheme registration working with only Windows registry (I am unsure how it translates between OS) and the native pipe recently created uses only the windows api (this is only for Unity projects, the standard pipe client uses C# managed system which should be cross platform).

.NET Core Support?

I would like to add Discord Rich Presence to my application which targets Windows and macOS via netcoreapp2.2. Does this project support .NET Core for cross-platform? If not, are there plans to bring support?

Rich presence becomes intermittent.

Unsure if this is a issue on your end, or how I am setting the presence.

After a few hours my rich presence with time elapsed starts becoming intermittent (Appears and disappears about half a second later (Unsure Of Exact Timing) on loop in discord) and has for my users too.

Here is my code:

        //Define Client Used To Set/Send Rich Presence Updates
        private DiscordRpcClient client;

        //Fix For Time Resetting To 00:00 Each Update
        private Timestamps Time;

        //Set Client ID And Connect To The Discord App's Rich Presence API
        private void InitializeRPC()
        {
            //Client ID For Images Via Names, Client ID Name (Name Of Tool/Program At Top Of Rich Presence - Clickable
            client = new DiscordRpcClient("57428998320108****");

            //Connect To The Discord App's Rich Presence API
            client.Initialize();
        }

        private void UpdatePresence()
        {
            //Last Two Version Numbers
            string CurrentVersionNumber = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Build + "." + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Revision;

            //If Program Does Not Have Focus
            if (!ApplicationIsActivated())
            {
                //Define New RichPresence And Set/Update It
                client.SetPresence(new RichPresence()
                {
                    Details = "Idle",
                    Assets = new Assets()
                    {
                        LargeImageKey = "main_logo",
                        LargeImageText = "Poppy's FF Editor v" + CurrentVersionNumber + Environment.NewLine + "Created By OFWModz"
                    }
                });

                Time = null;
            }
            //Else, If Program Is Focused.
            else
            {
                //If Current Project Name And Selected RawFile Is Not Null
                if (filename != null && treeView1.SelectedNode != null)
                {
                    if (Time == null)
                    {
                        //Only Define Timestamp Once - Fix For Time Resetting To 00:00 Each Update - Only Done Once Project Is Opened And File Is Selected
                        Time = Timestamps.Now;
                    }

                    //If Current Project Is A .CFG File
                    if (HasOpenedCFGFile == true)
                    {
                        //Define New RichPresence And Set/Update It
                        client.SetPresence(new RichPresence()
                        {
                            State = "File: " + filename,
                            Timestamps = Time,
                            Assets = new Assets()
                            {
                                LargeImageKey = "main_logo",
                                LargeImageText = "Poppy's FF Editor v" + CurrentVersionNumber + Environment.NewLine + "Created By OFWModz",
                                SmallImageKey = "cfg_file",
                                SmallImageText = "File: " + filename,
                            }
                        });
                    }
                    //Else, If Current Project Is A FastFile
                    else
                    {
                        //Define New RichPresence And Set/Update It
                        client.SetPresence(new RichPresence()
                        {
                            Details = "Project: " + filename,
                            State = "File: " + treeView1.SelectedNode.Text,
                            Timestamps = Time,
                            Assets = new Assets()
                            {
                                LargeImageKey = "main_logo",
                                LargeImageText = "Poppy's FF Editor v" + CurrentVersionNumber + Environment.NewLine + "Project: " + filename + Environment.NewLine + "Created By OFWModz",
                                SmallImageKey = "cfg_file",
                                SmallImageText = "File: " + treeView1.SelectedNode.Text,
                            }
                        });
                    }
                }
                //Else, If Nothing Is Opened / Program Just Started
                else
                {
                    //Define New RichPresence And Set/Update It
                    client.SetPresence(new RichPresence()
                    {
                        Details = "Idle",
                        Assets = new Assets()
                        {
                            LargeImageKey = "main_logo",
                            LargeImageText = "Poppy's FF Editor v" + CurrentVersionNumber + Environment.NewLine + "Created By OFWModz"
                        }
                    });
                }
            }
        }

The UpdatePresence is called every 25ms, have tried various timings, all come out with the same issue.

I know that this is not due to another app clashing trying to set rich presence. This issue occurs with no apparent cause.

Unable to load file or composition Discord RPC

Unmanaged exception: System.IO.FileNotFoundException: Unable to load file or composition Discord RPC, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null, or one of its dependencies. The file can not be found.
ย ย ย  at DiscordRPCTest.Program.Main (String [] args)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DiscordRPC;

namespace DiscordRPCTest
{
    class Program
    {
        public static DiscordRpcClient client;

        static void Main(string[] args)
        {
            client = new DiscordRpcClient("458202823641792512", true, 1);

            //Subscribe to events
            client.OnPresenceUpdate += (sender, e) =>
            {
                Console.WriteLine("Received Update! {0}", e.Presence);
            };

            //Connect to the RPC
            client.Initialize();

            //Set the rich presence
            client.SetPresence(new RichPresence()
            {
                Details = "CrunchyHub",
                State = "csharp example",
                Assets = new Assets()
                {
                    LargeImageKey = "image_large",
                    LargeImageText = "Lachee's Discord IPC Library",
                    SmallImageKey = "image_small"
                }
            });
            Console.ReadLine();
        }
    }
}

64bit support?

Does this repository support 64bit? And when mono is supported, do you think, in theory, that mono 64bit will be supported as well? Not really necessary, but it's something a friend is interested in for the 64bit version he built.

Changing status from "Playing [name]" to "Listening to [name]"

It feels like I've seen people's bots do this before, but I believe the majority of them are written in Python. I might be being stupid here and missing something, but is there a way we can do something like this? I apologize if this question has been asked before, couldn't find it when I tried.

Spotify's real presence is also an example of doing this, albeit they also have a custom UI for their real presence, but I'm assuming that's just a result of their agreement with Discord.

Change primary name

Hello, so I'm programming in C #, I was interested in showing information in discord but did not know where to start. Then I found the files you published, everything worked, but I would like to know where I change the name that appears in the discord. "DISCORD APC .NET" - I searched the code and did not find ...

  • Remember, I do not know if it's a problem. Sorry if I posted in the wrong place for that matter.

Congratulations and I await your response!

DllNotFoundException

Using Unity 5.6.6f2 (32-bits), I manually copied DiscordRPC.Native.dll in my project root folder:

Log1: Unhandled Exception: System.DllNotFoundException
UnityEngine.Debug:LogError(Object)
UnityLogger:Error(String, Object[]) (at Assets/Scripts/Discord/Control/UnityLogger.cs:28)
DiscordRPC.RPC.RpcConnection:MainLoop()

Log2: DiscordRPC.Native.dll
UnityEngine.Debug:LogError(Object)
UnityLogger:Error(String, Object[]) (at Assets/Scripts/Discord/Control/UnityLogger.cs:28)
DiscordRPC.RPC.RpcConnection:MainLoop()

Could not load file or assembly 'Newtonsoft.Json

#34 reopen, I have the same problem.

Newtonsoft.Json.dll is present in the netcoreapp2.0 folder (I use .NET Core).

Console output:
Running...
INFO: Attempting a new connection
INFO: Initializing Thread. Creating pipe object.
INFO: Connecting to the pipe through the DiscordRPC.IO.ManagedNamedPipeClient
INFO: Attempting to connect to discord-ipc-0
INFO: Waiting for connection...
INFO: Connected to discord-ipc-0
INFO: Begining Read of 16384 bytes
INFO: Connected to the pipe. Attempting to establish handshake...
INFO: Attempting to establish a handshake...
INFO: Sending Handshake...
ERR : Unhandled Exception: System.IO.FileNotFoundException
ERR : Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. Het systeem kan het opgegeven bestand niet vinden.
ERR : at DiscordRPC.IO.PipeFrame.SetObject(Object obj) at DiscordRPC.IO.PipeFrame..ctor(Opcode opcode, Object data) in C:\Users\hugow\Documents\discord-rpc-csharp-master\Discord RPC\IO\PipeFrame.cs:line 49 at DiscordRPC.RPC.RpcConnection.EstablishHandshake() in C:\Users\hugow\Documents\discord-rpc-csharp-master\Discord RPC\RPC\RpcConnection.cs:line 633 at DiscordRPC.RPC.RpcConnection.MainLoop() in C:\Users\hugow\Documents\discord-rpc-csharp-master\Discord RPC\RPC\RpcConnection.cs:line 238

Adding events on runtime

Just a question. Am I able to add events to the Discord client events during runtime? Or forced to add the events via the editor. Here are some code to get an idea.

Discord.client.OnJoin += Client_OnJoin;
Discord.client.OnJoinRequested += Client_OnJoinRequested;

Updating presence

Hello,
client.invoke() invokes
client.OnPresenceUpdate() but i dont know how i update the actual presence, it says Received update DiscordRpc.Richpresence but it does not actually update and i dont know how to do it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.