private void logic() { if (fpsLimitStopwatch.DurationInMilliseconds() < fpsLimit) { return; } fpsLimitStopwatch.Reset(); bool leagueOfLegendsOpen = false; Process[] pname = Process.GetProcessesByName("league of legends"); if (pname.Length != 0) { leagueOfLegendsOpen = true; } bool leagueOfLegendsClientOpen = false; pname = Process.GetProcessesByName("LolClient"); if (pname.Length != 0) { leagueOfLegendsClientOpen = true; } TaskScheduler aiContext = TaskScheduler.Current; //Measure timer performance double aiMilliseconds = timerPerformanceStopwatch.DurationInMilliseconds(); double aiFps = (1000.0 / aiMilliseconds); timerPerformanceCount++; timerPerformanceLength += aiMilliseconds; if (timerPerformanceLength >= 1000) { double averageMilliseconds = timerPerformanceLength / timerPerformanceCount; double averageFps = 1000.0 / averageMilliseconds; userInterface.setAIPerformanceLabel("" + Math.Round(averageFps, 4) + " fps (" + Math.Round(averageMilliseconds, 4) + " ms)"); timerPerformanceCount = 0; timerPerformanceLength = 0; } timerPerformanceStopwatch.Reset(); //Only grab the screen when it's done processing. //Do on separate task so we don't freeze the AI. if (grabbingScreen == false) { screenCapturePerformanceStopWatch.Reset(); grabbingScreen = true; Task t = Task.Run(() => { //visualCortex.runTest(); Bitmap screen = visualCortex.grabScreen2(leagueOfLegendsOpen); DetectionDataStruct data = visualCortex.getVisualDetectionData(); TaskHelper.RunTask(aiContext, () => { updateDetectionData(ref data, screen); }); }).ContinueWith(_ => { //Run on UI thread if (updateDisplayImage) { userInterface.setDisplayImage(visualCortex.getDisplayImage()); } grabbingScreen = false; double screenMilliseconds = screenCapturePerformanceStopWatch.DurationInMilliseconds(); double screenFps = (1000.0 / screenMilliseconds); userInterface.setScreenPerformanceLabel("" + Math.Round(screenFps, 4) + " fps (" + Math.Round(screenMilliseconds, 4) + " ms)"); }, aiContext); } if (leagueIsInGame == false && leagueOfLegendsOpen) { basicAI.resetAI(autoQueue.getPickedLane()); autoQueue.enteredLeagueOfLegends(); } if (leagueIsInGame == true && !leagueOfLegendsOpen) { autoQueue.exitedLeagueOfLegends(); } leagueIsInGame = leagueOfLegendsOpen; //Run basic AI algorithm if (leagueOfLegendsOpen) { lock (detectionDataLock) { basicAI.processAI(); } } else if ((leagueOfLegendsClientOpen || VisualCortex.IsTest) && currentScreen != null) { //Console.WriteLine("League of legends client open and scanning for auto queue"); //Run auto queue autoQueue.runAutoQueue(currentScreen); // userInterface.setDebugImage(new Bitmap(AutoQueueDetection.matchingBitmap)); } if (currentScreen != null) { autoQueue.runErrorCheck(currentScreen); } autoQueue.runSleepLogic(); }