private async Task AutoWorker() { while (true) { try { if (!contextMenu.AutoAccept.Checked && !contextMenu.AutoLock.Checked) { continue; } if (Process.GetProcessesByName("League of Legends").Any()) { await Sleep(true); continue; } var lolLuncherProcesses = Process.GetProcessesByName("LeagueClientUx") .FirstOrDefault(p => p.MainWindowHandle != IntPtr.Zero); if (lolLuncherProcesses == null) { await Sleep(true); continue; } notifyIcon.Icon = SystemIcons.Shield; var windowRect = (Rectangle)Rect.FromWindowHandleWindowRect(lolLuncherProcesses.MainWindowHandle); if (bmpScreenshot == null || patterns == null || bmpScreenshot.Size != windowRect.Size) { championSelectSession = null; if (!Patterns.SupportedResolutions.Contains(windowRect.Size)) { await Sleep(false); continue; } //Create a new bitmap. bmpScreenshot = new Bitmap(windowRect.Width, windowRect.Height, PixelFormat.Format32bppArgb); patterns = new Patterns(windowRect.Size); } // Create a graphics object from the bitmap. using (var gfxScreenshot = Graphics.FromImage(bmpScreenshot)) { // Take the screenshot from the upper left corner to the right bottom corner. gfxScreenshot.CopyFromScreen(windowRect.Location, Point.Empty, bmpScreenshot.Size, CopyPixelOperation.SourceCopy); } patternCaptureForm?.AddBitmap(bmpScreenshot); await ProcessScreenshot(patterns, new CachedBitmapPixels(bmpScreenshot), windowRect); } catch (Exception exception) { await ShowBallonTip(exception.Message, ToolTipIcon.Error); } await Task.Delay(500); } }
private async Task ProcessScreenshot(Patterns patterns, CachedBitmapPixels screenshot, Rectangle windowRect) { if ((contextMenu.AutoLock.Checked || autoPickForm != null) && patterns.IsChampionSelect(screenshot)) { if (autoPickForm != null && autoPickForm.Enabled) //TODO { championSelectSession = championSelectSession ?? new ChampionSelectSession(screenshot, patterns); if (patterns.HasBanLockButtonDisabled(screenshot) && patterns.IsChampionSearch(screenshot)) { var isBanPhase = patterns.IsFirstSelectBan(screenshot); var state = isBanPhase ? championSelectSession.BanState : championSelectSession.PickState; switch (state.Phase) { case ChampionSelectSession.BanPickPhase.Initial: LeftMouseClick(windowRect, 0.7203125, 0.1); state = new ChampionSelectSession.BanPickState( ChampionSelectSession.BanPickPhase.ClearSearchPressed, state.ChampionIndex); break; case ChampionSelectSession.BanPickPhase.ClearSearchPressed: break; case ChampionSelectSession.BanPickPhase.ChampionEntered: break; case ChampionSelectSession.BanPickPhase.ChampionSelected: break; default: throw new ArgumentOutOfRangeException(); } if (isBanPhase) { championSelectSession.BanState = state; } else { championSelectSession.PickState = state; } } else if (patterns.IsBanButton(screenshot)) { } else if (patterns.IsLockButton(screenshot)) { } } else if (patterns.IsLockButton(screenshot)) { LeftMouseClick(windowRect, 0.5, 0.81); await ShowBallonTip("Auto locked!", ToolTipIcon.Info); } return; } else if (contextMenu.AutoAccept.Checked && patterns.IsAcceptMatchButton(screenshot)) { LeftMouseClick(windowRect, 0.5, 0.775); await ShowBallonTip("Auto accepted!", ToolTipIcon.Info); } championSelectSession = null; }
public ChampionSelectSession(CachedBitmapPixels bitmap, Patterns patterns) { OurPickPosition = new Lazy <int>(() => patterns.DetectOurPickPosition(bitmap), false); }