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(100); Point captureLocation = new Point(Config.CooldownTextLocation.X, Config.CooldownTextLocation.Y); Size captureSize = new Size(Config.CooldownTextSize.Width, Config.CooldownTextSize.Height); decimal currentCooldown = IMG.Capture(OverlayWindow.CurrentHandle, captureLocation, captureSize); while (c == Party.SelectedCharacter && currentCooldown == 0) { Thread.Sleep(100); currentCooldown = IMG.Capture(OverlayWindow.CurrentHandle, captureLocation, captureSize); } if (c != Party.SelectedCharacter) { Party.Characters[c].Cooldown = 0; Party.Characters[c].Max = 0; } else { if (Config.CooldownOverride[c] > 0) { if (currentCooldown < Config.CooldownMinimumOverride) { Party.Characters[c].Cooldown = Config.CooldownOverride[c]; Party.Characters[c].Max = Config.CooldownOverride[c]; } else { Party.Characters[c].Cooldown = currentCooldown; Party.Characters[c].Max = currentCooldown; } } else { Party.Characters[c].Cooldown = currentCooldown + Config.CooldownOffset; Party.Characters[c].Max = Party.Characters[c].Cooldown; } } Party.Characters[c].Processing = false; }).Start(); } }
private void DebugButton_Click(object sender, EventArgs e) { 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; } OverlayWindow.IsDebug = true; 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); decimal currentCooldown = IMG.Capture(proc.MainWindowHandle, captureLocation, captureSize, true); string debugOut = $"\nParty Size (1 to 4): {Party.PartySize}\n" + $"Selected Character (1 to 4): Slot#{sel + 1}\n" + $"OCR Text Detected: {IMG.Text}\n" + $"Assumed Cooldown: {currentCooldown}\n" + $"Confidence: {IMG.Confidence * 100}% Required: {Config.OCRMinimumConfidence * 100}%"; Clipboard.SetText(debugOut); MetroMessageBox.Show(this, debugOut + $"\nCheck the GenshinOverlay folder for OCR input/output images.", "OCR Debug", MessageBoxButtons.OK, Theme, MessageBoxDefaultButton.Button1, 240); OverlayWindow.IsDebug = false; }
public static int GetSelectedCharacter(IntPtr handle) { if (handle == IntPtr.Zero) { return(-1); } int c0, c1, c2, c3; c0 = IMG.GetColorAt(handle, Config.PartyNumLocations["4 #1"].X, Config.PartyNumLocations["4 #1"].Y) == Color.FromArgb(255, 255, 255, 255) ? 1 : 0; c1 = IMG.GetColorAt(handle, Config.PartyNumLocations["4 #2"].X, Config.PartyNumLocations["4 #2"].Y) == Color.FromArgb(255, 255, 255, 255) ? 1 : 0; c2 = IMG.GetColorAt(handle, Config.PartyNumLocations["4 #3"].X, Config.PartyNumLocations["4 #3"].Y) == Color.FromArgb(255, 255, 255, 255) ? 1 : 0; c3 = IMG.GetColorAt(handle, Config.PartyNumLocations["4 #4"].X, Config.PartyNumLocations["4 #4"].Y) == Color.FromArgb(255, 255, 255, 255) ? 1 : 0; if (c0 + c1 + c2 + c3 == 4) { return(-1); } else if (c0 + c1 + c2 + c3 == 3) { PartySize = 4; return(c0 == 0 ? 0 : c1 == 0 ? 1 : c2 == 0 ? 2 : 3); } else if (c0 + c1 + c2 + c3 == 2 && PartySize == 4) { return(SelectedCharacter); } else { c0 = IMG.GetColorAt(handle, Config.PartyNumLocations["3 #1"].X, Config.PartyNumLocations["3 #1"].Y) == Color.FromArgb(255, 255, 255, 255) ? 1 : 0; c1 = IMG.GetColorAt(handle, Config.PartyNumLocations["3 #2"].X, Config.PartyNumLocations["3 #2"].Y) == Color.FromArgb(255, 255, 255, 255) ? 1 : 0; c2 = IMG.GetColorAt(handle, Config.PartyNumLocations["3 #3"].X, Config.PartyNumLocations["3 #3"].Y) == Color.FromArgb(255, 255, 255, 255) ? 1 : 0; if (c0 + c1 + c2 == 2) { PartySize = 3; return(c0 == 0 ? 0 : c1 == 0 ? 1 : 2); } else if (c0 + c1 + c2 == 1 && PartySize == 3) { return(SelectedCharacter); } else { c0 = IMG.GetColorAt(handle, Config.PartyNumLocations["2 #1"].X, Config.PartyNumLocations["2 #1"].Y) == Color.FromArgb(255, 255, 255, 255) ? 1 : 0; c1 = IMG.GetColorAt(handle, Config.PartyNumLocations["2 #2"].X, Config.PartyNumLocations["2 #2"].Y) == Color.FromArgb(255, 255, 255, 255) ? 1 : 0; if (c0 + c1 == 1) { PartySize = 2; _p2PauseStep = 0; return(c0 == 0 ? 0 : 1); } else if (c0 + c1 == 0 && _p2PauseStep < 2) { _p2PauseStep++; return(SelectedCharacter); } } } return(-1); }
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(); }
private void ConfigureOverlayButton_Click(object sender, EventArgs e) { 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; } else { OverlayWindow.GenshinHandle = proc.MainWindowHandle; } User32.GetClientRect(OverlayWindow.GenshinHandle, out User32.RECT rect); if (rect.Empty()) { MetroMessageBox.Show(this, $"\nGenshin Impact client area could not be detected.\n> Please ensure Genshin Impact is not minimized.\n> Only windowed/fullscreen borderless are supported.", "Client Error", MessageBoxButtons.OK, Theme, MessageBoxDefaultButton.Button1, 180); return; } OverlayWindow.IsConfiguring = true; if (ConfigureOverlayMessage.Visible) { ConfigureOverlayMessage.Visible = false; ConfigureOverlayButton.Location = new Point(ConfigureOverlayButton.Location.X, ConfigureOverlayButton.Location.Y - 20); } MainPanel.Visible = false; ConfigPanel.Visible = true; CooldownBarsYOffsetText.ForeColor = Color.FromArgb(255, 255, 0, 0); CooldownTextXPosTrack.Maximum = rect.Width; CooldownTextYPosTrack.Maximum = rect.Height; CooldownText2XPosTrack.Maximum = rect.Width; PartyNumXPosTrack.Maximum = rect.Width; PartyNumYPosTrack.Maximum = rect.Height; CooldownBarsXPosTrack.Maximum = rect.Width; CooldownBarsYPosTrack.Maximum = rect.Height; CooldownTextXPosTrack.MouseWheelBarPartitions = CooldownTextXPosTrack.Maximum - CooldownTextXPosTrack.Minimum; CooldownTextYPosTrack.MouseWheelBarPartitions = CooldownTextYPosTrack.Maximum - CooldownTextYPosTrack.Minimum; CooldownText2XPosTrack.MouseWheelBarPartitions = CooldownText2XPosTrack.Maximum - CooldownText2XPosTrack.Minimum; PartyNumXPosTrack.MouseWheelBarPartitions = PartyNumXPosTrack.Maximum - PartyNumXPosTrack.Minimum; PartyNumYPosTrack.MouseWheelBarPartitions = PartyNumYPosTrack.Maximum - PartyNumYPosTrack.Minimum; CooldownBarsXPosTrack.MouseWheelBarPartitions = CooldownBarsXPosTrack.Maximum - CooldownBarsXPosTrack.Minimum; CooldownBarsYPosTrack.MouseWheelBarPartitions = CooldownBarsYPosTrack.Maximum - CooldownBarsYPosTrack.Minimum; Config.LoadTemplates(); IMG.GetDesktopScale(); if (Config.CooldownTextLocation == Point.Empty || Config.PartyNumLocations["4 #1"] == Point.Empty) { OverlayTemplateValues(rect.Size, (int)(IMG.DesktopScale * 100)); } UpdateControlValues(); }
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(); }