private void PingFilterTimer_Tick(object sender, EventArgs e)
        {
            double sumPing = 0;  int n = 0;
            bool   absPingRespected = true;

            foreach (Player p in Player.ActivePlayers())
            {
                if (p.Ping != -1)
                {
                    absPingRespected &= p.Ping < Settings.Default.MaxAbsPing;
                    sumPing          += p.Ping;
                    n++;
                }
            }
            if (n == 0)
            {   // Wait until at least one player has a ping
                pingFilterTimer.Interval = TimeSpan.FromSeconds(0.5);
                return;
            }
            if ((!absPingRespected || sumPing / n > Settings.Default.MaxAvgPing) && !DS3Interop.InLoadingScreen())
            {
                var joinMethod = DS3Interop.GetJoinMethod();
                DS3Interop.LeaveSession();
                if (joinMethod == DS3Interop.JoinMethod.RedEyeOrb)
                {
                    hadInvaded = true;
                }
                else if (joinMethod == DS3Interop.JoinMethod.RedSign)
                {
                    DS3Interop.ApplyEffect(10);
                }
                else if (joinMethod == DS3Interop.JoinMethod.WhiteSign)
                {
                    DS3Interop.ApplyEffect(4);
                }
            }
            else
            {
                reoSpamming = false;
            }
            pingFilterTimer.Stop();
        }
        private void GameStartTimer_Tick(object sender, EventArgs e)
        {   // Wait for both process attach & main window existing
            if (DS3Interop.TryAttach() && DS3Interop.FindWindow())
            {
                DS3Interop.Process.EnableRaisingEvents = true;
                DS3Interop.Process.Exited += DarkSouls_HasExited;
                labelGameState.Content     = "DS3: RUNNING";
                labelGameState.Foreground  = Brushes.LawnGreen;

                File.WriteAllText("steam_appid.txt", "374320");
                if (!SteamAPI.Init())
                {
                    MessageBox.Show("Could not initialize Steam API", "Steam API Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                }

                if (!HotkeyManager.Enable())
                {
                    MessageBox.Show("Could not initialize keyboard hook for hotkeys", "WINAPI Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                if (!overlay.InstallMsgHook())
                {
                    MessageBox.Show("Could not overlay message hook", "WINAPI Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                overlay.UpdateVisibility();
                if (swBorderless.IsOn ^ DS3Interop.Borderless)
                {
                    DS3Interop.MakeBorderless(swBorderless.IsOn);
                }

                HotkeyManager.AddHotkey(DS3Interop.WinHandle, () => Settings.Default.BorderlessHotkey, () => swBorderless.IsOn ^= true);
                HotkeyManager.AddHotkey(DS3Interop.WinHandle, () => Settings.Default.OverlayHotkey, () => swOverlay.IsOn       ^= true);
                HotkeyManager.AddHotkey(DS3Interop.WinHandle, () => Settings.Default.PingFilterHotkey, () => Settings.Default.UsePingFilter ^= true);
                HotkeyManager.AddHotkey(DS3Interop.WinHandle, () => Settings.Default.REOHotkey, () => OnlineHotkey(11));
                HotkeyManager.AddHotkey(DS3Interop.WinHandle, () => Settings.Default.RSDHotkey, () => OnlineHotkey(10));
                HotkeyManager.AddHotkey(DS3Interop.WinHandle, () => Settings.Default.WSDHotkey, () => OnlineHotkey(4));
                HotkeyManager.AddHotkey(DS3Interop.WinHandle, () => Settings.Default.LeaveSessionHotkey, () => DS3Interop.LeaveSession());

                ETWPingMonitor.Start();
                updateTimer.Start();
                gameStartTimer.Stop();
            }
        }