Closed Nanolocity closed 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
Can you send code?
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();
}
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.
It's hard to see error with richpresence, because for me all looks fine
Yeah it seems fine
How is class named?
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 },
}
the project? If you're asking that, it's named "fuckyt" the file is called MainWindow.xaml.cs
"fuckyt" interesting
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
@Nanolocity i was losing my mind with YAML, so i know how it feels
can you see what line is doing it?
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?
I'm gonna be back in a second
ok
I am losing mind with it rn
check it
I'm thankful for you directing me but I have no idea what I'm supposed to do(me dumb)
I still don't know what I'm supposed to do, I'm sorry
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.
Somehow as i think it is changing >100ms repeatedly
And how can I fix it?(I'm really dumb, please help)
The logs you provide do not look like actual logs that this library generates. If you cannot get the console logs to work properly, try using the File Logger
client.RegisterUriScheme("440", "");
This is not how you register URI schemes. Please read the documentation
You should be Registering URI before initialization
You should be only SetSubcription once, unless you need to change the current subscription
Are you actually trying to add a join feature? If not: you dont need RegisterUriScheme or SetSubscription at all.
JsonConvert.DeserializeObject<DiscordRPC.Button>("{\"Url\":\"" + Url + "\", \"Label\":\"" + Label + "\"}");
Dont do this... why?
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.
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();
}
Alright, I just now realized that this error occurs when Discord isn't launched, I'm sorry for causing all this trouble
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:
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
Logs