Lachee / discord-rpc-csharp

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

BepInEx? #233

Closed StupidRepo closed 11 months ago

StupidRepo commented 1 year ago

When using this with BepInEx, I get this error: [Warning: Unity Log] The script '[hidden].Main' could not be instantiated!

Plugin.cs:

using System;
using System.Collections.Generic;
using BepInEx;
using DiscordRPC;
using DiscordRPC.Logging;
using HarmonyLib;
using SickDev.CommandSystem;
using UnityEngine;
using UnityEngine.SceneManagement;
using Objecto = UnityEngine.Object;

namespace WobbledOut
{
    ...
    public class Main : BaseUnityPlugin
    {
        private DiscordRpcClient client;

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

        private void OnEnable()
        {
            this.client = new DiscordRpcClient("[hidden]");

            // 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 = "dfdfsd",
                State = "dfdsfdf!",
                Assets = new DiscordRPC.Assets()
                {
                    LargeImageKey = "bep",
                    LargeImageText = "Uses BepInEx!"
                }
            }); 
        }

        ...

        private void Start()
        {
            SceneManager.sceneLoaded += OnSceneLoaded;
            this.harmonyPatch.PatchAll();
        }

        private void OnApplicationQuit()
        {
            this.harmonyPatch.UnpatchSelf();
        }

                ...

        private void Update()
        {
            client.Invoke();
            ...
        }

                ...
    }
}

How do I use this with BepInEx/how do I fix this issue?

StupidRepo commented 1 year ago

I installed it using dotnet add package DiscordRichPresence --version 1.1.3.18 btw

Scyye commented 1 year ago

you end up finding out how to fix this?

StupidRepo commented 11 months ago

Yeah! Sorry, I can't remember but I still have the source code for what I was using it for, so I'll take a look.