Lachee / discord-rpc-csharp

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

[BUG] Instead of setting presence it opens Discord and crashes the program #161

Closed Nanolocity closed 2 years ago

Nanolocity commented 2 years ago

Describe the bug As soon as my application launches it just opens Discord(for some reason?) and it crashes. I tried to see if it throws any errors in VS 2019 but all it said was The program '[4744] FPremium.exe' has exited with code 1 (0x1). and also tons of exceptions when the client.setPresence ran(and client.RegisterUrIScheme, etc) which leads me to believe that some API changes happened and that it broke the package itself.

To Reproduce Steps to reproduce the behavior:

  1. Launch program
  2. Program opens Discord(it shouldn't)
  3. See the program crash

Expected behavior It should launch the program, set the presence to "playing FPremium", etc with all the set parameters(this has worked before).

Desktop (please complete the following information):

Additional context When trying to do client.setSubscription, client.RegisterUriScheme, client.OnJoinRequested it throws this same exact exception for every one of them

Exception thrown: 'System.TimeoutException' in System.IO.Pipes.dll

Logs

'FPremium.exe' (CoreCLR: DefaultDomain): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Private.CoreLib.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'D:\biggering\fuckyt\fuckyt\bin\Release\net5.0-windows\FPremium.dll'. Symbols loaded.
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\5.0.11\PresentationFramework.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\5.0.11\WindowsBase.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Runtime.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\5.0.11\System.Xaml.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\5.0.11\System.IO.Packaging.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\netstandard.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Private.Uri.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\5.0.11\PresentationCore.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\mscorlib.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\5.0.11\DirectWriteForwarder.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Runtime.Extensions.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Runtime.InteropServices.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Runtime.CompilerServices.VisualC.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Diagnostics.Debug.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Threading.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\Microsoft.Win32.Primitives.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Collections.NonGeneric.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Linq.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Collections.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\Microsoft.Win32.Registry.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Diagnostics.TraceSource.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Collections.Specialized.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.ComponentModel.Primitives.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Threading.Thread.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\5.0.11\System.Configuration.ConfigurationManager.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Xml.ReaderWriter.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Private.Xml.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.IO.FileSystem.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Net.WebClient.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Memory.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Security.Cryptography.Algorithms.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Text.Encoding.Extensions.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Threading.ThreadPool.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.ComponentModel.TypeConverter.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\5.0.11\System.Windows.Extensions.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.ComponentModel.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Collections.Concurrent.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.ObjectModel.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Net.Requests.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Net.Primitives.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Net.WebHeaderCollection.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Diagnostics.Process.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\5.0.11\PresentationFramework.Aero2.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'D:\biggering\fuckyt\fuckyt\bin\Release\net5.0-windows\DiscordRPC.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'D:\biggering\fuckyt\fuckyt\bin\Release\net5.0-windows\H.Hooks.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'D:\biggering\fuckyt\fuckyt\bin\Release\net5.0-windows\Newtonsoft.Json.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.IO.Pipes.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\5.0.11\UIAutomationTypes.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\5.0.11\UIAutomationProvider.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Console.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\5.0.11\PresentationFramework-SystemXml.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\xamldiagnostics\Core\x64\Microsoft.VisualStudio.DesignTools.WpfTap.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Diagnostics.Tracing.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Text.RegularExpressions.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Threading.Tasks.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Runtime.Serialization.Json.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Private.DataContractSerialization.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Runtime.Serialization.Xml.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Runtime.Serialization.Primitives.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Resources.ResourceManager.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Reflection.Emit.ILGeneration.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Reflection.Emit.Lightweight.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Reflection.Primitives.dll'. 
'FPremium.exe' (CoreCLR: clrhost): Loaded 'D:\biggering\fuckyt\fuckyt\bin\Release\net5.0-windows\NAudio.Core.dll'. 
100
'FPremium.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Runtime.Serialization.Formatters.dll'. 
The program '[11872] FPremium.exe' has exited with code 1 (0x1).
HAHOOS commented 2 years ago

I see in logs that program is loading files and exiting program. Something in your code is timeouted EDIT: You did something that pipe.dll is timeouting

HAHOOS commented 2 years ago

Can you send code?

Nanolocity commented 2 years ago

This is a smaller portion of the code(It might include some weird names for variables and it's not optimized at all)

    {

        bool playing = false;
        public static string path = "undefined";
        public static bool savemp4 = false;
        public string detail = "Home";
        public string state = "Not listening to anything";
        DiscordRpcClient client = new DiscordRpcClient("900034624133144596");
        public string currentimage = "small_red";
        public string currentsong = "";
        public string currenttext = "";
        MediaElement mediaElement = new MediaElement();
        public static string nastyname= "100";
        LowLevelKeyboardHook keyboardHok = new LowLevelKeyboardHook();
        Stopwatch songtimer = new Stopwatch();
        public bool songsstart = false;
        public MainWindow()
        {
            InitializeComponent();
            System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
            dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
            dispatcherTimer.Start();

            client.Logger = new ConsoleLogger() { Level = DiscordRPC.Logging.LogLevel.Info };

            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);
            };
            client.Initialize();
            mediaElement.LoadedBehavior = MediaState.Manual;
            mediaElement.UnloadedBehavior = MediaState.Manual;

            string partyid = "n2dnfkfnhadsfb";
            Party ohno = new Party();
            ohno.ID = partyid;
            ohno.Max = 2;
            ohno.Size = 1;
            ohno.Privacy = Party.PrivacySetting.Public;
            client.UpdateStartTime();
            songtimer.Start();
        }

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

        MediaState GetMediaState(MediaElement myMedia)
        {
            FieldInfo hlp = typeof(MediaElement).GetField("_helper", BindingFlags.NonPublic | BindingFlags.Instance);
            object helperObject = hlp.GetValue(myMedia);
            FieldInfo stateField = helperObject.GetType().GetField("_currentState", BindingFlags.NonPublic | BindingFlags.Instance);
            MediaState state = (MediaState)stateField.GetValue(helperObject);
            return state;
        }

        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            if (File.Exists($"{Directory.GetCurrentDirectory()}/userSettings.txt"))
            {
                path = File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").First();
                savemp4 = bool.Parse(File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").Last());
            }
            else
            {
                File.WriteAllText($"{Directory.GetCurrentDirectory()}/userSettings.txt", $"{Directory.GetCurrentDirectory()}/{Environment.NewLine}False{Environment.NewLine}100{Environment.NewLine}False");
            }
            gayness();
            if (GetMediaState(mediaElement) == MediaState.Close)
            {
                state = "Not listening to anything";
                currentimage = "small_red";
            }
                if (GetMediaState(mediaElement) == MediaState.Play)
            {
                currentimage = "small_green";
                playButton.Content = "II";
            }
            else
            {
                currentimage = "small_red";
                playButton.Content = "";
            }
            Party gaynessh = new Party();
            gaynessh.ID = "random169";
            gaynessh.Max = 2;
            gaynessh.Privacy = Party.PrivacySetting.Public;
            gaynessh.Size = 1;

            DiscordRPC.Button[] ga = new DiscordRPC.Button[1];
            var Url = "https://www.youtube.com/watch?v=7Do70nztRNE";
            var Label = "Listen in";
            ga[0] = JsonConvert.DeserializeObject<DiscordRPC.Button>("{\"Url\":\"" + Url + "\", \"Label\":\"" + Label + "\"}");

            client.SetPresence(new RichPresence()
            {
                Details = detail,
                State = state,
                Assets = new Assets()
                {
                    LargeImageKey = "image_large",
                    LargeImageText = "FPremium - YouTube without ads & Offline",
                    SmallImageKey = currentimage
                },
                Buttons = ga
    });
            client.RegisterUriScheme("440", "");
            client.SetSubscription(EventType.JoinRequest);

            void gn(object sender, JoinRequestMessage args)
            {
                Trace.WriteLine("button pressed");
            }

            client.OnJoinRequested += gn;

            if (mediaElement.Source != null) { songNameText.Content = mediaElement.Source.ToString().Substring(8 + Directory.GetCurrentDirectory().Length + 8).Replace(".wav", "").Replace("_", " "); }

            string pos = null;
            if (File.Exists(Directory.GetCurrentDirectory()+ "/audiopos.txt"))
            {
                pos = File.ReadLines($"{Directory.GetCurrentDirectory()}/audiopos.txt").First();
            }

            if (songsstart == true) { timeTracker.Value = songtimer.Elapsed.TotalSeconds; }
            else if(pos != null) { timeTracker.Value = songtimer.Elapsed.TotalSeconds + Double.Parse(TimeSpan.Parse(pos).TotalSeconds.ToString()); }

            if (mediaElement.Source != null)
            {
                WaveFileReader wf = new WaveFileReader(mediaElement.Source.AbsolutePath.ToString());

                timeTracker.Maximum = wf.TotalTime.TotalSeconds;
            }

            if(timeTracker.Value == timeTracker.Maximum)
            {
                mediaElement.Pause();
                var rand = new Random();
                var files = Directory.GetFiles(Directory.GetCurrentDirectory() + "/videos/", "*.wav");
                var penis = files[rand.Next(files.Length)];

                    mediaElement.Source = new Uri(penis);

                    mediaElement.Play();
                    if (bool.Parse(File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").Skip(1).First()) == true) { state = "Listening to a song..."; } else { state = $"Listening to {penis.Substring(Directory.GetCurrentDirectory().Length + 8).Replace("_", " ").Replace(".wav", "")}"; }
                    currentimage = "small_green";
                    currentsong = $"{mediaElement.Source.ToString().Substring(8 + Directory.GetCurrentDirectory().Length + 8).Replace(".wav", "").Replace("_", " ")}...";
                    songtimer.Restart();
                WaveFileReader wf = new WaveFileReader(mediaElement.Source.AbsolutePath.ToString());

                timeTracker.Maximum = wf.TotalTime.TotalSeconds;
                timeTracker.Value = 0;
                File.WriteAllText($"{Directory.GetCurrentDirectory()}/audiopos.txt", $"00:00:00{Environment.NewLine}{mediaElement.Source.AbsolutePath.ToString()}");
            }
        }
        private void Grid_Loaded(object sender, RoutedEventArgs e)
        {
            if (File.Exists($"{Directory.GetCurrentDirectory()}/audiopos.txt"))
            {
                string pos = File.ReadLines($"{Directory.GetCurrentDirectory()}/audiopos.txt").First();
                string filename = File.ReadLines($"{Directory.GetCurrentDirectory()}/audiopos.txt").Last();
                mediaElement.Position = TimeSpan.Parse(pos);
                mediaElement.Source = new Uri(filename);
                mediaElement.Play();
                timeTracker.Value = Double.Parse(TimeSpan.Parse(pos).TotalSeconds.ToString());
                if (bool.Parse(File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").Skip(1).First()) == false)
                {
                    state = $"Listening to { mediaElement.Source.ToString().Substring(8 + Directory.GetCurrentDirectory().Length + 8).Replace(".wav", "").Replace("_", " ")}...";
                }
                else
                {
                    state = "Listening to a song...";
                }
            }
            switchto("Grid");
            if (File.Exists($"{Directory.GetCurrentDirectory()}/userSettings.txt"))
            {
                path = File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").First();
                savemp4 = bool.Parse(File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").Last());
                Trace.WriteLine(File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").Skip(2).First());
                volume.Value = double.Parse(File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").Skip(2).First());
                mediaElement.Volume = float.Parse(File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").Skip(2).First())/100;
                if (mediaElement.Source != null)
                {
                    WaveFileReader wf = new WaveFileReader(mediaElement.Source.AbsolutePath.ToString());

                    timeTracker.Maximum = wf.TotalTime.TotalSeconds;
                }
            }
            else
            {
                File.WriteAllText($"{Directory.GetCurrentDirectory()}/userSettings.txt", $"{Directory.GetCurrentDirectory().Replace("\\","/")}/videos/{Environment.NewLine}False{Environment.NewLine}100{Environment.NewLine}False");
            }

            keyboardHok.Up += (_, args) => cokc(args);
            keyboardHok.Down += (_, args) => cokc(args);

            keyboardHok.Start();

        }
Nanolocity commented 2 years ago

So I did remove some random stuff and now it launches and works fine but I still get the exceptions and the richpresence doesn't show.

HAHOOS commented 2 years ago

It's hard to see error with richpresence, because for me all looks fine

Nanolocity commented 2 years ago

Yeah it seems fine

HAHOOS commented 2 years ago

How is class named?

HAHOOS commented 2 years ago

I think:

>>> ga[0] = JsonConvert.DeserializeObject<DiscordRPC.Button>("{\"Url\":\"" + Url + "\", \"Label\":\"" + Label + "\"}");

            client.SetPresence(new RichPresence()
            {
                Details = detail,
                State = state,
                Assets = new Assets()
                {
                    LargeImageKey = "image_large",
                    LargeImageText = "FPremium - YouTube without ads & Offline",
                    SmallImageKey = currentimage
                },
                >>>> Buttons = ga

Change to:

client.SetPresence(new RichPresence()
            {
                Details = detail,
                State = state,
                Assets = new Assets()
                {
                    LargeImageKey = "image_large",
                    LargeImageText = "FPremium - YouTube without ads & Offline",
                    SmallImageKey = currentimage
                },
               Buttons = new DiscordRPC.Button[]
                        {
                            new DiscordRPC.Button() { Label = Label, Url = Url },
                        }
Nanolocity commented 2 years ago

the project? If you're asking that, it's named "fuckyt" the file is called MainWindow.xaml.cs

HAHOOS commented 2 years ago

"fuckyt" interesting

Nanolocity commented 2 years ago

I thought it sounded pretty straight forward so I just named it that, btw the error is still there. I feel like I'm losing my mind

HAHOOS commented 2 years ago

@Nanolocity i was losing my mind with YAML, so i know how it feels

HAHOOS commented 2 years ago

can you see what line is doing it?

Nanolocity commented 2 years ago

I added breaking points and I'm pretty sure trying to do anything with client does it. Now i think the servers might have some issues or something?

Nanolocity commented 2 years ago

I'm gonna be back in a second

HAHOOS commented 2 years ago

ok

HAHOOS commented 2 years ago

I am losing mind with it rn

HAHOOS commented 2 years ago

71

HAHOOS commented 2 years ago

check it

Nanolocity commented 2 years ago

I'm thankful for you directing me but I have no idea what I'm supposed to do(me dumb)

HAHOOS commented 2 years ago

https://github.com/Lachee/discord-rpc-csharp/commit/df0e8f256a34060b2cb5ad8b63e14234c413b1c7

Nanolocity commented 2 years ago

I still don't know what I'm supposed to do, I'm sorry

HAHOOS commented 2 years ago

If the SetPresence was called within a few milliseconds (less than 100ms) repeatedly, the pipe would not have enough time to process the messages and will throw errors.

HAHOOS commented 2 years ago

Somehow as i think it is changing >100ms repeatedly

Nanolocity commented 2 years ago

And how can I fix it?(I'm really dumb, please help)

Lachee commented 2 years ago

I think:

>>> ga[0] = JsonConvert.DeserializeObject<DiscordRPC.Button>("{\"Url\":\"" + Url + "\", \"Label\":\"" + Label + "\"}");

            client.SetPresence(new RichPresence()
            {
                Details = detail,
                State = state,
                Assets = new Assets()
                {
                    LargeImageKey = "image_large",
                    LargeImageText = "FPremium - YouTube without ads & Offline",
                    SmallImageKey = currentimage
                },
                >>>> Buttons = ga

Change to:

client.SetPresence(new RichPresence()
            {
                Details = detail,
                State = state,
                Assets = new Assets()
                {
                    LargeImageKey = "image_large",
                    LargeImageText = "FPremium - YouTube without ads & Offline",
                    SmallImageKey = currentimage
                },
               Buttons = new DiscordRPC.Button[]
                        {
                            new DiscordRPC.Button() { Label = Label, Url = Url },
                        }

Yes, HAHOOS is 100% correct. What you are doing with JSON is just... questionable at best.

Nanolocity commented 2 years ago

I don't know why I have sent that code snippet since I already have it set to

Buttons = new DiscordRPC.Button[]
                        {
                            new DiscordRPC.Button() { Label = Label, Url = Url },
                        }
``` I'm really sorry but it still gives me an error. Also I did remove the party thing, the subscription and the urischeme and it still gives me it. The current code is this : 

public partial class MainWindow : Window {

    bool playing = false;
    public static string path = "undefined";
    public static bool savemp4 = false;
    public string detail = "Home";
    public string state = "Not listening to anything";
    DiscordRpcClient client = new DiscordRpcClient("900034624133144596");
    public string currentimage = "small_red";
    public string currentsong = "";
    public string currenttext = "";
    MediaElement mediaElement = new MediaElement();
    public static string cock = "100";
    LowLevelKeyboardHook keyboardHok = new LowLevelKeyboardHook();
    Stopwatch songtimer = new Stopwatch();
    public bool songsstart = false;
    public MainWindow()
    {
        InitializeComponent();
        System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
        dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
        dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
        client.SkipIdenticalPresence = false;
        dispatcherTimer.Start();

        client.Logger = new ConsoleLogger() { Level = DiscordRPC.Logging.LogLevel.Info };

        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);
        };
        client.Initialize();

        mediaElement.LoadedBehavior = MediaState.Manual;
        mediaElement.UnloadedBehavior = MediaState.Manual;

        string partyid = "n2dnfkfnhadsfb";
        Party ohno = new Party();
        ohno.ID = partyid;
        ohno.Max = 2;
        ohno.Size = 1;
        ohno.Privacy = Party.PrivacySetting.Public;
        client.UpdateStartTime();
        songtimer.Start();
    }

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

    [DllImport("winmm.dll")]
    static extern Int32 mciSendString(string command, StringBuilder buffer, int bufferSize, IntPtr hwndCallback);

    private void TextBlock_Scroll(object sender, System.Windows.Controls.Primitives.ScrollEventArgs e)
    {

    }

    MediaState GetMediaState(MediaElement myMedia)
    {
        FieldInfo hlp = typeof(MediaElement).GetField("_helper", BindingFlags.NonPublic | BindingFlags.Instance);
        object helperObject = hlp.GetValue(myMedia);
        FieldInfo stateField = helperObject.GetType().GetField("_currentState", BindingFlags.NonPublic | BindingFlags.Instance);
        MediaState state = (MediaState)stateField.GetValue(helperObject);
        return state;
    }

    private void dispatcherTimer_Tick(object sender, EventArgs e)
    {
        if (File.Exists($"{Directory.GetCurrentDirectory()}/userSettings.txt"))
        {
            path = File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").First();
            savemp4 = bool.Parse(File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").Last());
        }
        else
        {
            File.WriteAllText($"{Directory.GetCurrentDirectory()}/userSettings.txt", $"{Directory.GetCurrentDirectory()}/{Environment.NewLine}False{Environment.NewLine}100{Environment.NewLine}False");
        }
        gayness();
        if (GetMediaState(mediaElement) == MediaState.Close)
        {
            state = "Not listening to anything";
            currentimage = "small_red";
        }
            if (GetMediaState(mediaElement) == MediaState.Play)
        {
            currentimage = "small_green";
            playButton.Content = "II";
        }
        else
        {
            currentimage = "small_red";
            playButton.Content = "";
        }

        DiscordRPC.Button[] ga = new DiscordRPC.Button[1];
        var Url = "https://www.youtube.com/watch?v=7Do70nztRNE";
        var Label = "Listen in";

        client.SetPresence(new RichPresence()
        {
            Details = detail,
            State = state,
            Assets = new Assets()
            {
                LargeImageKey = "image_large",
                LargeImageText = "FPremium - YouTube without ads & Offline",
                SmallImageKey = currentimage
            },
            Buttons = new DiscordRPC.Button[]
                    {
                        new DiscordRPC.Button() { Label = Label, Url = Url },
                    }
        });

        if (mediaElement.Source != null) { songNameText.Content = mediaElement.Source.ToString().Substring(8 + Directory.GetCurrentDirectory().Length + 8).Replace(".wav", "").Replace("_", " "); }

        string pos = null;
        if (File.Exists(Directory.GetCurrentDirectory()+ "/audiopos.txt"))
        {
            pos = File.ReadLines($"{Directory.GetCurrentDirectory()}/audiopos.txt").First();
        }

        if (songsstart == true) { timeTracker.Value = songtimer.Elapsed.TotalSeconds; }
        else if(pos != null) { timeTracker.Value = songtimer.Elapsed.TotalSeconds + Double.Parse(TimeSpan.Parse(pos).TotalSeconds.ToString()); }

        if (mediaElement.Source != null)
        {
            WaveFileReader wf = new WaveFileReader(mediaElement.Source.AbsolutePath.ToString());

            timeTracker.Maximum = wf.TotalTime.TotalSeconds;
        }

        if(timeTracker.Value == timeTracker.Maximum)
        {
            mediaElement.Pause();
            var rand = new Random();
            var files = Directory.GetFiles(Directory.GetCurrentDirectory() + "/videos/", "*.wav");
            var penis = files[rand.Next(files.Length)];

                mediaElement.Source = new Uri(penis);

                mediaElement.Play();
                if (bool.Parse(File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").Skip(1).First()) == true) { state = "Listening to a song..."; } else { state = $"Listening to {penis.Substring(Directory.GetCurrentDirectory().Length + 8).Replace("_", " ").Replace(".wav", "")}"; }
                currentimage = "small_green";
                currentsong = $"{mediaElement.Source.ToString().Substring(8 + Directory.GetCurrentDirectory().Length + 8).Replace(".wav", "").Replace("_", " ")}...";
                songtimer.Restart();
            WaveFileReader wf = new WaveFileReader(mediaElement.Source.AbsolutePath.ToString());

            timeTracker.Maximum = wf.TotalTime.TotalSeconds;
            timeTracker.Value = 0;
            File.WriteAllText($"{Directory.GetCurrentDirectory()}/audiopos.txt", $"00:00:00{Environment.NewLine}{mediaElement.Source.AbsolutePath.ToString()}");
        }
    }
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        switchto("Home");
    }

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        switchto("Refresh");
    }

    private void Grid_Loaded(object sender, RoutedEventArgs e)
    {
        if (File.Exists($"{Directory.GetCurrentDirectory()}/audiopos.txt"))
        {
            string pos = File.ReadLines($"{Directory.GetCurrentDirectory()}/audiopos.txt").First();
            string filename = File.ReadLines($"{Directory.GetCurrentDirectory()}/audiopos.txt").Last();
            mediaElement.Position = TimeSpan.Parse(pos);
            mediaElement.Source = new Uri(filename);
            mediaElement.Play();
            timeTracker.Value = Double.Parse(TimeSpan.Parse(pos).TotalSeconds.ToString());
            if (bool.Parse(File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").Skip(1).First()) == false)
            {
                state = $"Listening to { mediaElement.Source.ToString().Substring(8 + Directory.GetCurrentDirectory().Length + 8).Replace(".wav", "").Replace("_", " ")}...";
            }
            else
            {
                state = "Listening to a song...";
            }
        }
        switchto("Grid");
        if (File.Exists($"{Directory.GetCurrentDirectory()}/userSettings.txt"))
        {
            path = File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").First();
            savemp4 = bool.Parse(File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").Last());
            Trace.WriteLine(File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").Skip(2).First());
            volume.Value = double.Parse(File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").Skip(2).First());
            mediaElement.Volume = float.Parse(File.ReadLines($"{Directory.GetCurrentDirectory()}/userSettings.txt").Skip(2).First())/100;
            if (mediaElement.Source != null)
            {
                WaveFileReader wf = new WaveFileReader(mediaElement.Source.AbsolutePath.ToString());

                timeTracker.Maximum = wf.TotalTime.TotalSeconds;
            }
        }
        else
        {
            File.WriteAllText($"{Directory.GetCurrentDirectory()}/userSettings.txt", $"{Directory.GetCurrentDirectory().Replace("\\","/")}/videos/{Environment.NewLine}False{Environment.NewLine}100{Environment.NewLine}False");
        }

        keyboardHok.Up += (_, args) => cokc(args);
        keyboardHok.Down += (_, args) => cokc(args);

        keyboardHok.Start();

    }
Nanolocity commented 2 years ago

Alright, I just now realized that this error occurs when Discord isn't launched, I'm sorry for causing all this trouble