//only turned on if closed with pubg is checked
        //closes after pubg closes
        private void timer1_Tick(object sender, EventArgs e)
        {
            bool pubgClosed = true;

            Process[] proc = Process.GetProcesses();
            foreach (Process item in proc)
            {
                if (item.ProcessName.Equals("TslGame"))
                {
                    pubgStarted = true;
                    pubgClosed  = false;
                }
            }
            if (pubgStarted && pubgClosed)
            {
                updateSettings();
                if (!Properties.Settings.Default.profilePath.Equals(""))
                {
                    NoReciolScript.killLogiDriver();
                    NoReciolScript.resetProfileDefualt();
                    NoReciolScript.startLogiDriver();
                }
                Environment.Exit(0);
            }
        }
        //select button
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog FBD = new OpenFileDialog();

            FBD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Logitech\\Logitech Gaming Software\\profiles";
            if (FBD.ShowDialog() == DialogResult.OK)
            {
                Properties.Settings.Default.profilePath = FBD.FileName;
                Properties.Settings.Default.Save();
            }
            NoReciolScript.checkProfile();
            NoReciolScript.killLogiDriver();
            NoReciolScript.makeProfileDefualt();
            NoReciolScript.startLogiDriver();
        }
        //when the form close
        private async void Form1_FormClosingAsync(object sender, FormClosingEventArgs e)
        {
            if (firstClosingBlocked)
            {
                firstClosingBlocked = false;
                e.Cancel            = true;
                updateSettings();
                if (!Properties.Settings.Default.profilePath.Equals(""))
                {
                    NoReciolScript.killLogiDriver();
                    NoReciolScript.resetProfileDefualt();
                    NoReciolScript.startLogiDriver();
                }
                await PutTaskDelay(1000);

                Environment.Exit(0);
            }
        }
        //start button
        private void button2_Click(object sender, EventArgs e)
        {
            if (!Properties.Settings.Default.profilePath.Equals(""))
            {
                started = true;

                if (!Properties.Settings.Default.profilePath.Equals(""))
                {
                    NoReciolScript.killLogiDriver();
                    NoReciolScript.makeProfileDefualt();
                    NoReciolScript.startLogiDriver();
                }

                if (Properties.Settings.Default.openWithPUBG)
                {
                    Process.Start("steam://rungameid/578080");
                }

                //WindowState = FormWindowState.Minimized;
                weaponIndex = -1;
                switchGunRecoilAsync(null);
                button2.Text = "Running";
            }
        }
        //switch guns
        private async void switchGunRecoilAsync(String overide)
        {
            weaponIndex++;

            if (overide != null)
            {
                weaponIndex = gunNameToInt(overide);
            }

            int temp = weaponIndex;

GUNSWITCH:
            switch (weaponIndex)
            {
            case 0:
                if (checkBox4.Checked)
                {
                    currentGun    = "akm";
                    textBox7.Text = "akm";
                    NoReciolScript.selectGun(false, true, false, false, false, false, false, "akm");
                    audioStream = new SoundPlayer(Properties.Resources.akm);
                }
                else
                {
                    weaponIndex++;
                    goto GUNSWITCH;
                }
                break;

            case 1:
                if (checkBox5.Checked)
                {
                    currentGun    = "ump9";
                    textBox7.Text = "ump9";
                    NoReciolScript.selectGun(true, false, false, false, false, false, false, "ump9");
                    audioStream = new SoundPlayer(Properties.Resources.ump9);
                }
                else
                {
                    weaponIndex++;
                    goto GUNSWITCH;
                }
                break;

            case 2:
                if (checkBox6.Checked)
                {
                    currentGun    = "m416";
                    textBox7.Text = "m416";
                    NoReciolScript.selectGun(false, false, false, true, false, false, false, "m416");
                    audioStream = new SoundPlayer(Properties.Resources.m416);
                }
                else
                {
                    weaponIndex++;
                    goto GUNSWITCH;
                }

                break;

            case 3:
                if (checkBox8.Checked)
                {
                    currentGun    = "m16a4";
                    textBox7.Text = "m16a4";
                    NoReciolScript.selectGun(false, false, true, false, false, false, false, "m16a4");
                    audioStream = new SoundPlayer(Properties.Resources.m16a4);
                }
                else
                {
                    weaponIndex++;
                    goto GUNSWITCH;
                }

                break;

            case 4:
                if (checkBox7.Checked)
                {
                    currentGun    = "scarl";
                    textBox7.Text = "scarl";
                    NoReciolScript.selectGun(false, false, false, false, true, false, false, "scarl");
                    audioStream = new SoundPlayer(Properties.Resources.scarl);
                }
                else
                {
                    weaponIndex++;
                    goto GUNSWITCH;
                }

                break;

            case 5:
                if (checkBox3.Checked)
                {
                    currentGun    = "uzi";
                    textBox7.Text = "uzi";
                    NoReciolScript.selectGun(false, false, false, false, false, true, false, "uzi");
                    audioStream = new SoundPlayer(Properties.Resources.uzi);
                }
                else
                {
                    weaponIndex++;
                    goto GUNSWITCH;
                }

                break;

            case 6:
                if (checkBox9.Checked)
                {
                    currentGun    = "qbz";
                    textBox7.Text = "qbz";
                    NoReciolScript.selectGun(false, false, false, false, false, false, true, "qbz");
                    audioStream = new SoundPlayer(Properties.Resources.qbz);
                }
                else
                {
                    weaponIndex++;
                    goto GUNSWITCH;
                }

                break;

            case 7:
                weaponIndex = 0;
                atleastOneGunOn();
                goto GUNSWITCH;
            }
            audioStream.Play();
            await PutTaskDelay(3000);

            if (temp == weaponIndex)
            {
                NoReciolScript.killLogiDriver();
                NoReciolScript.updateProfile();
                NoReciolScript.startLogiDriver();

                await PutTaskDelay(3000);

                bool      procFound = false;
                Process[] proc      = Process.GetProcesses();
                do
                {
                    foreach (Process item in proc)
                    {
                        if (item.ProcessName.Equals("LCore"))
                        {
                            procFound = true;
                            InputSimulator inputSimulator = new InputSimulator();
                            if (!Control.IsKeyLocked(Keys.NumLock))
                            {
                                inputSimulator.Keyboard.KeyPress(VirtualKeyCode.NUMLOCK);
                            }
                            if (!Control.IsKeyLocked(Keys.Scroll))
                            {
                                inputSimulator.Keyboard.KeyPress(VirtualKeyCode.SCROLL);
                            }
                            synthesizer.SpeakAsync("ready");
                        }
                    }
                } while (!procFound);
            }
        }