private void SkillKeyPressed()
        {
            if (Party.SelectedCharacter == -1 || Party.Characters[Party.SelectedCharacter].Cooldown > Config.CooldownMinimumReapply || Party.Characters[Party.SelectedCharacter].Processing)
            {
                return;
            }
            int c = Party.SelectedCharacter;

            Party.Characters[c].Processing = true;

            new Thread(() => {
                Thread.Sleep(Config.CooldownOCRRateInMs);
                Point captureLocation  = new Point(Config.CooldownTextLocation.X, Config.CooldownTextLocation.Y);
                Size captureSize       = new Size(Config.CooldownTextSize.Width, Config.CooldownTextSize.Height);
                Point captureLocation2 = new Point(Config.CooldownText2LocationX, Config.CooldownTextLocation.Y);

                IMG.OCRCapture ocr = new IMG.OCRCapture();
                IMG.Capture(OverlayWindow.CurrentHandle, captureLocation, captureSize, ref ocr);
                while (c == Party.SelectedCharacter && ocr.Cooldown == 0)
                {
                    Thread.Sleep(Config.CooldownOCRRateInMs);
                    IMG.Capture(OverlayWindow.CurrentHandle, captureLocation, captureSize, ref ocr);
                    if (ocr.Cooldown == 0 && Config.CooldownText2LocationX != 0)
                    {
                        IMG.Capture(OverlayWindow.CurrentHandle, captureLocation2, captureSize, ref ocr);
                    }
                }
                if (c != Party.SelectedCharacter)
                {
                    Party.Characters[c].Cooldown = 0;
                    Party.Characters[c].Max      = 0;
                }
                else
                {
                    if (Config.CooldownOverride[c] > 0)
                    {
                        if (ocr.Cooldown < Config.CooldownMinimumOverride)
                        {
                            Party.Characters[c].Cooldown = Config.CooldownOverride[c];
                            Party.Characters[c].Max      = Config.CooldownOverride[c];
                        }
                        else
                        {
                            Party.Characters[c].Cooldown = ocr.Cooldown;
                            Party.Characters[c].Max      = ocr.Cooldown;
                        }
                    }
                    else
                    {
                        Party.Characters[c].Cooldown = ocr.Cooldown + Config.CooldownOffset;
                        Party.Characters[c].Max      = Party.Characters[c].Cooldown;
                    }
                }
                Party.Characters[c].Processing = false;
            }).Start();
        }
Exemple #2
0
        private void KeyHook_KeyUp(object sender, KeyHookEventArgs e)
        {
            if (OverlayWindow.GenshinHandle == IntPtr.Zero)
            {
                return;
            }
            if (Config.CooldownTextLocation == Point.Empty || Config.PartyNumLocations["4 #1"] == Point.Empty)
            {
                return;
            }
            if (e.Key == Keys.E)
            {
                if (Party.SelectedCharacter == -1 || Party.Characters[Party.SelectedCharacter].Cooldown > Config.CooldownMinimumReapply || Party.Characters[Party.SelectedCharacter].Processing)
                {
                    return;
                }
                int c = Party.SelectedCharacter;
                Party.Characters[c].Processing = true;

                new Thread(() => {
                    Thread.Sleep(Config.CooldownOCRRateInMs);
                    Point captureLocation = new Point(Config.CooldownTextLocation.X, Config.CooldownTextLocation.Y);
                    Size captureSize      = new Size(Config.CooldownTextSize.Width, Config.CooldownTextSize.Height);

                    IMG.OCRCapture ocr = new IMG.OCRCapture();
                    IMG.Capture(OverlayWindow.CurrentHandle, captureLocation, captureSize, ref ocr);
                    while (c == Party.SelectedCharacter && ocr.Cooldown == 0)
                    {
                        Thread.Sleep(Config.CooldownOCRRateInMs);
                        IMG.Capture(OverlayWindow.CurrentHandle, captureLocation, captureSize, ref ocr);
                    }
                    if (c != Party.SelectedCharacter)
                    {
                        Party.Characters[c].Cooldown = 0;
                        Party.Characters[c].Max      = 0;
                    }
                    else
                    {
                        if (Config.CooldownOverride[c] > 0)
                        {
                            if (ocr.Cooldown < Config.CooldownMinimumOverride)
                            {
                                Party.Characters[c].Cooldown = Config.CooldownOverride[c];
                                Party.Characters[c].Max      = Config.CooldownOverride[c];
                            }
                            else
                            {
                                Party.Characters[c].Cooldown = ocr.Cooldown;
                                Party.Characters[c].Max      = ocr.Cooldown;
                            }
                        }
                        else
                        {
                            Party.Characters[c].Cooldown = ocr.Cooldown + Config.CooldownOffset;
                            Party.Characters[c].Max      = Party.Characters[c].Cooldown;
                        }
                    }
                    Party.Characters[c].Processing = false;
                }).Start();
            }
        }
Exemple #3
0
        private void OCRDebug(bool isMulti)
        {
            if (OverlayWindow.IsDebug)
            {
                OverlayWindow.IsDebug = false;
                return;
            }
            Process proc = Process.GetProcesses().Where(x => x.ProcessName == Config.ProcessName).FirstOrDefault();

            if (proc == null)
            {
                MetroMessageBox.Show(this, $"\nGenshin Impact must be running first.", "Process Error", MessageBoxButtons.OK, Theme, MessageBoxDefaultButton.Button1, 135);
                return;
            }

            if (Config.CooldownTextLocation == Point.Empty || Config.PartyNumLocations["4 #1"] == Point.Empty)
            {
                MetroMessageBox.Show(this, $"\nMust first setup cooldown text/party location before debugging.", "Overlay Error", MessageBoxButtons.OK, Theme, MessageBoxDefaultButton.Button1, 135);
                return;
            }

            new Thread(() => {
                OverlayWindow.IsDebug = true;
                Stopwatch sw          = new Stopwatch();
                sw.Start();
                int sel = Party.GetSelectedCharacter(proc.MainWindowHandle);
                Point captureLocation = new Point(Config.CooldownTextLocation.X, Config.CooldownTextLocation.Y);
                Size captureSize      = new Size(Config.CooldownTextSize.Width, Config.CooldownTextSize.Height);

                IMG.OCRCapture ocr = new IMG.OCRCapture();
                IMG.Capture(proc.MainWindowHandle, captureLocation, captureSize, ref ocr, true);
                long time = sw.ElapsedMilliseconds;
                if (!isMulti || (isMulti && ocr.Cooldown > 0))
                {
                    this.UI(() => {
                        DebugText.Text = $"Party Size (1 to 4): {Party.PartySize}\r\n" +
                                         $"Selected Character (1 to 4): Slot#{sel + 1}\r\n" +
                                         $"OCR Text Detected: {ocr.Text}\r\n" +
                                         $"Parsed Cooldown: {ocr.Cooldown}\r\n" +
                                         $"Confidence: {ocr.Confidence * 100}% Required: {Config.OCRMinimumConfidence * 100}%\r\n" +
                                         $"Iteration #{ocr.Iterations} ({time}ms @ {Config.CooldownOCRRateInMs}ms rate)";
                    });
                }
                else
                {
                    while (ocr.Cooldown == 0 && ocr.Iterations < 1000 && OverlayWindow.IsDebug)
                    {
                        Thread.Sleep(Config.CooldownOCRRateInMs);
                        IMG.Capture(proc.MainWindowHandle, captureLocation, captureSize, ref ocr, false);

                        this.UI(() => {
                            DebugText.Text = $"Party Size (1 to 4): {Party.PartySize}\r\n" +
                                             $"Selected Character (1 to 4): Slot#{sel + 1}\r\n" +
                                             $"OCR Text Detected: {ocr.Text}\r\n" +
                                             $"Parsed Cooldown: {ocr.Cooldown}\r\n" +
                                             $"Confidence: {ocr.Confidence * 100}% Required: {Config.OCRMinimumConfidence * 100}%\r\n" +
                                             $"Iteration #{ocr.Iterations} ({sw.ElapsedMilliseconds}ms @ {Config.CooldownOCRRateInMs}ms rate)";
                        });
                    }
                }
                sw.Stop();

                OverlayWindow.IsDebug = false;
            }).Start();
        }