/// <summary> /// Keyboard event handler. Fires when the hotkey is pressed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Event_Keyboard(object sender, EventArgs e) { Log("[KEY] Captured hotkey", -1); if (Settings.saveKey) { Settings.saveKey = false; Button_SetHotkey.IsEnabled = true; Log("Assigned TCP disconnect to key: " + (System.Windows.Forms.Keys)Settings.logOutHotKey, 0); return; } // Don't send disconnect if game is minimized and checkbox is not ticked if (Settings.workMinimized && !Win32.IsTopmost()) { return; } // Send disconnect signal Log("Closing TCP connections...", 0); long delay = KillTCP.KillTCPConnectionForProcess(); Log("Closed connections (took " + delay + " ms)", 0); }
/// <summary> /// Main loop of sorts /// </summary> public void PollHealth_Task() { bool lastNotBelowLimit = true; double health, lastHealth = 0; // Wait until program has found PoE process while (Settings.captureTop < 1 || gfx == null) { System.Threading.Thread.Sleep(10); } while (true) { try { // Run x times a second System.Threading.Thread.Sleep(Settings.healthPollRateMS); // Don't do any calculations until health tracking has been enabled in settings if (!Settings.trackHealth) { continue; } // Don't track while game client is being moved if (Settings.dontTrackImMoving) { continue; } // Take screenshot of health bar gfx.CopyFromScreen(Settings.captureLeft, Settings.captureTop, 0, 0, size, CopyPixelOperation.SourceCopy); ParseHealth(); health = GetEHPAsPercentage(); // Do nothing if state has not changed if (health == lastHealth) { continue; } else { lastHealth = health; } // Manage errorcodes if (health == -1) { MainWindow.Log("[WARN] Too many unreadable pixels", -1); img.Save("Screenshot_2_many_unreadable.png", System.Drawing.Imaging.ImageFormat.Png); continue; } else if (health < 1) { MainWindow.Log(" Health bar not visible", -1); continue; } // If topmost window is not PoE if (!Win32.IsTopmost()) { continue; } // Update health window if (Settings.healthBarEnabled) { System.Windows.Application.Current.Dispatcher.Invoke(() => MainWindow.healthBar.SetPercentage(health)); } // Debugging, I guess? if (health > Settings.healthLimitPercent) { MainWindow.Log("[Health] Found change: " + health, -1); } // Do action when health is below limit if (health < Settings.healthLimitPercent) { if (lastNotBelowLimit) { // Raise flag so this is not spammed lastNotBelowLimit = false; MainWindow.Log("[Health] Health below limit (" + health + ")", 0); // Quit game if event is enabled in settings if (Settings.doLogout) { MainWindow.Log("[Health] Sending disconnect signal", 0); long delay = KillTCP.KillTCPConnectionForProcess(); MainWindow.Log("[Health] Disconnected (took " + delay + "ms)", 0); } } } else { lastNotBelowLimit = true; } } catch (Exception ex) { Console.WriteLine(ex); } } }