static void Main(string[] args) { Logger.OnStartup(); Logger.Write("Loading LeagueBot..."); Configuration.LoadConfig(); PatternsManager.Initialize(); PixelCache.Initialize(); TextRecognition.Initialize(); try { LeagueManager.ApplySettings(); } catch { Logger.Write("Unable to set league of legends settings. (Probably due to permission restrictions.)", MessageState.WARNING); } HandleCommand(); Console.Read(); }
public static bool TextExists2(Rectangle rectangle, string phrase) { Stopwatch st = Stopwatch.StartNew(); Bitmap src = PixelCache.GetScreenshot(); Bitmap target = new Bitmap(rectangle.Width, rectangle.Height); using (Graphics g = Graphics.FromImage(target)) { g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), rectangle, GraphicsUnit.Pixel); } Page page = Engine.Process(target); string text = page.GetText(); src.Dispose(); target.Dispose(); page.Dispose(); return(text.ToLower().Contains(phrase.ToLower())); }
public ImageEngine(CancellationToken cancelToken, string outputPath) { _outputPath = outputPath; _cancelToken = cancelToken; DataContextFactory = new DataContextFactory(); PixelCache = new PixelCache("ImageSevice"); PixelCache.Initialize().Wait(); }
public void clickConfirmButton() { if (ImageRecognition.ImageExists("confirmNormal.png")) { Point coords = ImageRecognition.ImageCoords("confirmNormal.png"); Mouse.Move(coords.X + (PixelCache.GetWidth("confirmNormal.png") / 2), coords.Y + (PixelCache.GetHeight("confirmNormal.png") / 2)); Mouse.PressButton(Mouse.MouseKeys.Left, 150); } else if (ImageRecognition.ImageExists("confirmHover.png")) { Point coords = ImageRecognition.ImageCoords("confirmHover.png"); Mouse.Move(coords.X + (PixelCache.GetWidth("confirmHover.png") / 2), coords.Y + (PixelCache.GetHeight("confirmHover.png") / 2)); Mouse.PressButton(Mouse.MouseKeys.Left, 150); } }
void cacheDirections() { cacheNorth = getPixelNumbers(colors, lineWidth, lineHeight, 0, 1); cacheNorthEast = getPixelNumbers(colors, lineWidth, lineHeight, 1, 1); cacheEast = getPixelNumbers(colors, lineWidth, lineHeight, 1, 0); cacheSouthEast = getPixelNumbers(colors, lineWidth, lineHeight, 1, -1); cacheSouth = getPixelNumbers(colors, lineWidth, lineHeight, 0, -1); cacheSouthWest = getPixelNumbers(colors, lineWidth, lineHeight, -1, -1); cacheWest = getPixelNumbers(colors, lineWidth, lineHeight, -1, 0); cacheNorthWest = getPixelNumbers(colors, lineWidth, lineHeight, -1, 1); _fullCache = new PixelCache[3][][]; _fullCache[0] = new PixelCache[3][] { cacheSouthWest, cacheSouth, cacheSouthEast }; _fullCache[1] = new PixelCache[3][] { cacheWest, null, cacheEast }; _fullCache[2] = new PixelCache[3][] { cacheNorthWest, cacheNorth, cacheNorthEast }; }
public async Task <PixelResult> AddPixel(AddPixelRequest model) { var game = await GameCache.GetGame(model.GameId); if (game == null) { return(new PixelResult(false, "Game not found")); } if (game.Status != GameStatus.Started) { return(new PixelResult(false, "Game is not currently active")); } var pixel = await PixelCache.GetPixel(game.Id, model.X, model.Y); if (pixel != null) { if (pixel.Type == PixelType.Fixed) { return(new PixelResult(false, "Cannot overwrite gameboard pixel")); } if (pixel.Points > model.MaxPoints) { return(new PixelResult(false, "Pixel points are greater than Spend Limit")); } } var userId = Context.GetUserId(); var rateLimitResult = await CheckRateLimits(userId, game); if (!string.IsNullOrEmpty(rateLimitResult)) { return(new PixelResult(false, rateLimitResult)); } var result = await PixelWriter.AddPixel(userId, model); if (!result.Success) { return(new PixelResult(false, result.Message)); } return(new PixelResult(result)); }
private async Task ProcessLiveImages() { var start = DateTime.UtcNow; Log.Message(LogLevel.Info, "[ProcessLiveImages] - Processing Game Images"); using (var context = DataContextFactory.CreateReadOnlyContext()) { try { var pixelGames = await context.Games .Where(x => x.Status != Enums.GameStatus.Deleted && x.Status != Enums.GameStatus.Finished) .ToListAsync(); foreach (var pixelGame in pixelGames) { var gamePixels = (await PixelCache.GetPixels(pixelGame.Id)) .Select(x => new RenderPixelModel { X = x.X, Y = x.Y, Type = x.Type, Color = x.Color }).ToList(); var fixedPixels = gamePixels.Where(x => x.Type == PixelType.Fixed).ToList(); RenderPixels(pixelGame, gamePixels, "background"); RenderPixels(pixelGame, fixedPixels, "background-fixed", true); } Log.Message(LogLevel.Info, $"[ProcessLiveImages] - Processing Game Images complete, Elapsed: {DateTime.UtcNow - start}ms"); } catch (Exception ex) { Log.Exception("[ProcessLiveImages] - Exception Processing Game Images", ex); } } }
private static void Queue2TimerCallback(object state) // enter game queue { //Logger.Log("q2timer"); try { /*var process = GetProcessByName("League of Legends"); * if (process == null)*/ int port = GameSession.GetPort(); if (port == 0) { //Logger.Log("port"); if (LCU == null || LCU.SummonerID == 0) { LCU = new LCU(); } //Logger.Log("sumo"); Try++; int lb = LCU.LeaverBuster(); switch (Try) { case 1: LogAndInfo("Starting queue..."); LCU.StartQueue(); break; case 2: if (lb > 0) { GameSession.TimerTick = DateTime.Now.Ticks; LogAndInfo("Leaverbuster detected. Trying again in " + lb.ToString() + " seconds..."); Try = 1; if (lb > 4) { Thread.Sleep(4000); } LCU = new LCU(); } else { LCU.StartQueue(); Logger.Log("No Leaverbuster."); Try = 6; } break; default: if (Try > 90 && !LCU.InChampSelect() && port == 0) { for (int i = 0; i < 5; i++) { TryToContinue(); } LogAndInfo("Can't find match: Reached to max. number of tries. Restarting queue..."); Try = 0; sel = 0; } else if (port != 0) { LogAndInfo("Starting game (3) session... " + sel + " - p: " + port); State = ClientStates.InGame; Communication.SendMessageWithoutReply(Server.ClientID, "state", "ingame"); StartGameSession(sel); KillTimers(); } else if (Try > 5 && !LCU.InChampSelect()) { if (Try > 30 && Try % 5 == 0) { try { var bmp = PixelCache.GetScreenshot(); bmp.Bitmap.Save("gs5.bmp"); if (bmp.GetPixel(425, 362) == Color.FromArgb(205, 190, 145)) { ListProcesses(); GameSession.TimerTick = DateTime.Now.Ticks; Logger.Log("gamesession (5) restart..."); Logger.Log("Game crashed. Trying to continue..."); Server.SetInfoText("Game crashed. Trying to continue..."); Thread.Sleep(5000); TryToContinue(); } } catch (Exception x) { Logger.Log("gs5 error: " + x.Message); Logger.Log("Screenshot error. Trying to continue..."); Server.SetInfoText("Screenshot error. Trying to continue..."); TryToContinue(); } } LogAndInfo("Accepting match."); LCU.AcceptQueue(); //Logger.Log("acc macc: " + LCU?.auth?.ToString() + " kacc: " + port); } break; } if (LoginTimer != null) { GameSession.TimerTick = DateTime.Now.Ticks; if (LCU != null && !LCU.InChampSelect()) { TimerChange(LoginTimer, QueueTimerInterval); } else { sel = LCU.SelectedChamp(); int champ = Champions.RandomChamp(); try { LCU = new LCU(); if (sel == 0 && LCU.InChampSelect()) { LogAndInfo("Picking champion..."); LCU.PickChampion(champ); Thread.Sleep(500); while (LCU.SelectedChamp() == 0) { LCU.AcceptQueue(); LogAndInfo("Couldn't pick " + Champions.GetChampById(champ) + ". Trying again..."); LCU = new LCU(); Thread.Sleep(3000); champ = Champions.RandomChamp(); Logger.Log(LCU.PickChampion(champ)); } if (port == 0) { LogAndInfo("picked champion"); TimerChange(LoginTimer, QueueTimerInterval); } } else { sel = LCU.SelectedChamp(); if (sel != 0) { //LogAndInfo("p: " + port); Try = 6; champ = sel; LogAndInfo("Picked champion: " + Champions.GetChampById(champ)); Thread.Sleep(1000); if (port == 0) { TimerChange(LoginTimer, QueueTimerInterval); } else { LogAndInfo("Starting game (1) session..."); State = ClientStates.InGame; Communication.SendMessageWithoutReply(Server.ClientID, "state", "ingame"); StartGameSession(champ); KillTimers(); } } } } catch (Exception x) { Logger.Log("pick chmap exc: " + x.Message); } } } } else { LogAndInfo("Starting game (2) session..."); State = ClientStates.InGame; Communication.SendMessageWithoutReply(Server.ClientID, "state", "ingame"); StartGameSession((sel != 0) ? sel : 22); KillTimers(); } /* * else if(Try > 20) * { * LogAndInfo("game is f****d - restarting"); * var process = ClientApi.GetProcessByName("League of Legends"); * if (process != null) * { * var x = NativeMethods.GetAllTcpConnections(); * foreach (var a in x) * { * if (process.Id == a.owningPid) * { * process.Kill(); * } * } * } * TryToContinue(); * State = ClientStates.InGame; * Communication.SendMessageWithoutReply(Server.ClientID, "state", "ingame"); * StartGameSession(Champions.RandomChamp()); * KillTimers(); * }*/ } catch (Exception x) { Logger.Log("exc"); try { var bmp = PixelCache.GetScreenshot(); bmp.Bitmap.Save("q2.bmp"); bmp.Dispose(); } catch (Exception a) { Logger.Log("q2 login timer (1) image error..." + a.Message); } if (Try > 0) { Try--; } Server.SetInfoText("q2 Login timer error"); if (LoginTimer != null) { TimerChange(LoginTimer, QueueTimerInterval); } Logger.Log("restarting..."); Logger.Log("error: " + x.Message); Logger.Log(x.StackTrace); } }
private static void GameControlCallback(object state) { try { TimeSpan timeSpan = new TimeSpan(DateTime.Now.Ticks - GameSession.TimerTick); if (timeSpan.TotalSeconds > 260) { LCU = new LCU(); if (GameSession.GetPort() != 0) { try { var bmp = PixelCache.GetScreenshot(); bmp.Bitmap.Save("gs1.bmp"); if (bmp.GetPixel(485, 352) == Color.FromArgb(59, 45, 24)) // afk { Mouse.Move(485, 352); Thread.Sleep(600); Mouse.ButtonDown(Mouse.MouseKeys.Left); Thread.Sleep(50); Mouse.ButtonUp(Mouse.MouseKeys.Left); Thread.Sleep(300); Mouse.Move(490, 352); Thread.Sleep(100); Mouse.ButtonDown(Mouse.MouseKeys.Left); Thread.Sleep(50); Mouse.ButtonUp(Mouse.MouseKeys.Left); Thread.Sleep(1000); } if (bmp.GetPixel(798, 151) == Color.FromArgb(13, 26, 26)) // main menu { Mouse.Move(798, 151); Thread.Sleep(600); Mouse.ButtonDown(Mouse.MouseKeys.Left); Thread.Sleep(50); Mouse.ButtonUp(Mouse.MouseKeys.Left); Thread.Sleep(300); Mouse.Move(744, 596); // cancel button Thread.Sleep(100); Mouse.ButtonDown(Mouse.MouseKeys.Left); Thread.Sleep(50); Mouse.ButtonUp(Mouse.MouseKeys.Left); Thread.Sleep(3000); } if (bmp.GetPixel(495, 352) == Color.FromArgb(59, 45, 24) || bmp.GetPixel(507, 344) == Color.FromArgb(255, 255, 255)) { ListProcesses(); GameSession.TimerTick = DateTime.Now.Ticks; Logger.Log("gamesession (3) restart..." + timeSpan.ToString()); ClientApi.Stop(); Logger.Log("Connection lost. Trying to continue..."); Server.SetInfoText("Connection lost. Trying to continue..."); Thread.Sleep(5000); ClientApi.Restart = true; ClientApi.Start(); } else if (bmp.GetPixel(532, 765) != Color.FromArgb(78, 62, 29)) { ListProcesses(); GameSession.TimerTick = DateTime.Now.Ticks; Logger.Log("gamesession (1) restart..." + timeSpan.ToString()); GameSession.Start = 1; GameSession = null; GameSession = new GameSession(Server, Champions.RandomChamp()); } bmp.Dispose(); } catch (Exception x) { Logger.Log("gamesession (1) image error..." + x.Message); } } else //if(LCU != null && LCU.LeaverBuster() == 0) { bool flag = false; try { var bmp = PixelCache.GetScreenshot(); bmp.Bitmap.Save("kill1.bmp"); if (bmp.GetPixel(425, 362) == Color.FromArgb(205, 190, 145)) { GameSession.TimerTick = DateTime.Now.Ticks; ListProcesses(); flag = true; while (GameSession.GetPort() == 0) { GameSession.Control(); TryToContinue(); LogAndInfo("waiting for reconnect..."); } LogAndInfo("Reconnecting..."); State = ClientStates.InGame; Communication.SendMessageWithoutReply(Server.ClientID, "state", "ingame"); StartGameSession(Champions.RandomChamp()); KillTimers(); } else if (bmp.GetPixel(507, 344) == Color.FromArgb(255, 255, 255) || bmp.GetPixel(525, 125) == Color.FromArgb(17, 17, 17)) { ListProcesses(); GameSession.TimerTick = DateTime.Now.Ticks; Logger.Log("kill (3) restart..." + timeSpan.ToString()); ClientApi.Stop(); Logger.Log("Connection lost. Trying to continue..."); Server.SetInfoText("Connection lost. Trying to continue..."); Thread.Sleep(5000); ClientApi.Restart = true; ClientApi.Start(); } bmp.Dispose(); } catch (Exception x) { Logger.Log("kill (1) image error..." + x.Message); } if (!flag) { //425,362 = 205, 190, 145 GameSession.TimerTick = DateTime.Now.Ticks; Logger.Log("kill1 " + timeSpan.ToString()); Stop(); Logger.Log("Restarting bot..."); Server.SetInfoText("Restarting bot..."); Thread.Sleep(5000); if (Server.LoadedAccount != null) { Start(); } else { Logger.Log("no loaded account"); } } } } else { Logger.Log("check - OK: bot is working... (1)"); } } catch (Exception x) { Logger.Log("check - FAIL: gameControlTimer error: " + x.Message); } finally { TimerChange(gameControl, 60000); } }
private void SecondsTimerCallback(object state) { //Logger.Log("sec tim"); if (GameState.Started == true && !Player.Dead()) { /*Stopwatch all = new Stopwatch(); * all.Start();*/ // var bmp = ImageUtils.TakeSmallCapture(0, 0, 1024, 768); try { var bmp = PixelCache.GetScreenshot(); Color col = bmp.GetPixel(300, 300); if (col != LastScreenColor) { TimerTick = DateTime.Now.Ticks; } LastScreenColor = col; me = ImageValues.GetMyPosition(bmp); Point tower = ImageValues.EnemyTowerPosition(bmp); Point enemy = ImageValues.EnemyPosition(bmp); Point enemyCreep = ImageValues.EnemyCreepPosition(bmp); Point ally = ImageValues.AllyPosition(bmp); Point allyCreep = ImageValues.AllyCreepPosition(bmp); int hpercent = Player.GetHealthPercent(); int hpDiff = ImageValues.GetHPDifference(bmp); int creepHpDiff = ImageValues.GetCreepHPDifference(bmp); //int distanceEnemyCreep = ImageValues.GetDistanceFromOrigin(enemyCreep); var pressNothing = false; bool Attack = false; int baseX = 757; int baseY = 145; if (tower.Y > 5 || enemy.Y > 15 || enemyCreep.Y > 15) { baseX = 566; //allyCreep.X; baseY = 350; //allyCreep.Y;*/ } //Server.SetInfoText("Calculating..."); /* FORWARD * baseX = 757;//allyCreep.X; * baseY = 145;//allyCreep.Y;*/ /* MIDDLE * baseX = 566;//allyCreep.X; * baseY = 357;//allyCreep.Y;*/ /* BACK * baseX = 46; * baseY = 695;*/ if (hpDiff < -50 || creepHpDiff < -40) {/* * Server.SetInfoText("OK." + Environment.NewLine + (hpDiff < -50).ToString() + Environment.NewLine + (creepHpDiff < -40).ToString());*/ Attack = true; if (goB > 0) { goB = 20; } } if (Player.game.CurrentHealth < healthBefore || (goB < 1 && hpercent < 20) || tower.Y > 100 || hpDiff + (hpercent / 2) < -245 || (creepHpDiff < -150 && allyCreep.X == 0) || enemyCreep.Y > 380) { /*if (tower.Y > 110) * Logger.Log("tower.Y = " + tower.Y + " > 110"); * else if (Player.game.Level < 13 && creepHpDiff < -150 && allyCreep.X == 0) * Logger.Log("creepHpDiff = " + creepHpDiff + " < -150 && allyCreep.X = 0"); * else if (hpDiff + (hpercent / 2) < -260) * Logger.Log("hpDiff + (hpercent / 2) = " + (hpDiff + (hpercent / 2)).ToString() + " < -245"); * else if (enemyCreep.Y > 380) * Logger.Log("enemyCreep.Y = " + enemyCreep.Y + " > 380");*/ //Server.SetInfoText("Need to get back."); if (tower.Y > 110 || hpDiff < -700) { secondHP = 2; } else { secondHP = 1; } if (goB > 0) { goB = 20; } } if (secondHP > 0) { Attack = false; baseX = 46; baseY = 695; secondHP--; } else if (goB > 0) { if (hpercent > 90) { goB = 1; } if (goB == 20) { if (enemy.X > 0 || enemyCreep.X > 0 || tower.X > 0) { secondHP = 2; } else { Keyboard.KeyPress(System.Windows.Forms.Keys.B); goB--; pressNothing = true; } } else if (goB < 20) { goB--; pressNothing = true; } if (goB == 0) { if (hpercent < 95) { goB = 5; } else if (hpercent < 50) { goB = 20; } else { //-----buyitems Server.SetInfoText("Buying items..."); int gold = Player.GetGold(); foreach (var x in items) { if (x.got == false) { if (gold > x.cost) { if (!Shop.Opened) { Shop.Toggle(); Thread.Sleep(RandomTimeGenerator(500)); /*MouseOperations.SetCursorPosition(420 + RandomTimeGenerator(5), 80 + RandomTimeGenerator(4)); * Thread.Sleep(RandomTimeGenerator(200)); * MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftDown); * Thread.Sleep(RandomTimeGenerator(50)); * MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftUp);*/ Keyboard.ShortcutKeys(new System.Windows.Forms.Keys[] { System.Windows.Forms.Keys.ControlKey, System.Windows.Forms.Keys.L }, RandomTimeGenerator(40)); Thread.Sleep(RandomTimeGenerator(1000)); } Thread.Sleep(RandomTimeGenerator()); string str = x.phrase; foreach (char c in str) { Thread.Sleep(RandomTimeGenerator(150)); Keyboard.KeyPress((System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), c.ToString()), RandomTimeGenerator(50)); } Thread.Sleep(RandomTimeGenerator(500)); MouseOperations.SetCursorPosition(377 + RandomTimeGenerator(15), 146 + RandomTimeGenerator(8)); Thread.Sleep(RandomTimeGenerator(150)); MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.RightDown); Thread.Sleep(RandomTimeGenerator(40)); MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.RightUp); Thread.Sleep(RandomTimeGenerator(500)); Server.SetInfoText("Bought " + x.name); for (int i = 0; i < str.Length; i++) { Thread.Sleep(RandomTimeGenerator(100)); Keyboard.KeyPress(System.Windows.Forms.Keys.Back); } x.got = true; gold -= x.cost; } else { break; } } } Thread.Sleep(RandomTimeGenerator()); if (Shop.Opened) { Shop.Toggle(); } //-----buyitems pressNothing = true; /* baseX = 566;//allyCreep.X; * baseY = 357;//allyCreep.Y;*/ goB = -1; } } } else if (allyCreep.X == 0) { //Server.SetInfoText("No ally in sight."); if (enemyCreep.X != 0 || enemy.X != 0 || tower.X != 0) { secondHP = 2; } } else { baseX = allyCreep.X; baseY = allyCreep.Y; if (enemyCreep.X != 0) { Attack = true; Server.SetInfoText("Attacking creeps."); baseX = 566; //allyCreep.X; baseY = 350; //allyCreep.Y; } else if (tower.Y < 15 && enemy.X != 0 && (allyCreep.X != 0 || ally.X != 0) && hpDiff > -400) { Attack = true; Server.SetInfoText("Attacking enemy."); baseX = 566; //allyCreep.X; baseY = 350; //allyCreep.Y; } else if (tower.X != 0) { Attack = true; Server.SetInfoText("Attacking tower."); baseX = 566; //allyCreep.X; baseY = 350; //allyCreep.Y; } } //Server.SetInfoText("Calculated..."); if (!pressNothing) { Random rand = new Random(); int r1 = rand.Next(-15, 15); int r2 = rand.Next(-14, 14); if (hpercent > 10 && Attack && (ally.X != 0 || r1 > 8) && (enemyCreep.X > 0 || enemy.X > 0) && hpercent > 30 && Player.GetManaPercent() > 30) { new Thread(() => { if (enemy.X > 0) { MouseOperations.SetCursorPosition(enemy.X, enemy.Y + RandomTimeGenerator(10)); } else { MouseOperations.SetCursorPosition(enemyCreep.X, enemyCreep.Y + RandomTimeGenerator(10)); } MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.RightDown); Thread.Sleep(RandomTimeGenerator(30)); MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.RightUp); Thread.Sleep(RandomTimeGenerator(100)); int choice = rand.Next(1, 4); if (enemy.X > 0) { choice += 1; } DoRandomSkill(choice); //Server.SetInfoText("doskill: " + choice); }).Start(); } else { MouseOperations.SetCursorPosition(baseX + r1, baseY + r2); if (Attack && hpercent > 20) { Keyboard.KeyPress(System.Windows.Forms.Keys.A); } else if (!Attack) { MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.RightDown); Thread.Sleep(RandomTimeGenerator(12)); MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.RightUp); } } } bmp.Dispose(); //all.Stop(); healthBefore = Player.game.CurrentHealth; /* Logger.Log("ms: " + all.ElapsedMilliseconds.ToString()); * string ftr = "me:" + me.ToString() + Environment.NewLine + "tower:" + tower.ToString() + Environment.NewLine + "e:" + enemy.ToString() + Environment.NewLine + "ec:" + enemyCreep.ToString() + Environment.NewLine + "a:" + ally.ToString() + Environment.NewLine + "a:" + allyCreep.ToString() + Environment.NewLine + "hpDiff:" + hpDiff.ToString() + Environment.NewLine + "creepHpDiff:" + creepHpDiff.ToString() + Environment.NewLine; + Logger.Log(ftr);*/ //Logger.Log("me:" + me.ToString()); //Server.SetInfoText(ftr); } catch (Exception x) { Logger.Log("seconds timer error: " + x.Message); } } GameState.Started = (Player.GetGold() != 0); if (GameState.Started == false) { Logger.Log("seconds timer stopped - finish game..."); FinishGame(); } else { if (SecondsTimer != null) { ClientApi.TimerChange(SecondsTimer, RandomTimeGenerator()); } else { Logger.Log("seconds timer stopped - restarting..."); SecondsTimer = new Timer(SecondsTimerCallback, null, RandomTimeGenerator(), Timeout.Infinite); if (TenSecondsTimer == null) { Logger.Log("10sec timer stopped - restarting..."); TenSecondsTimer = new Timer(TenSecondsTimerCallback, null, RandomTimeGenerator(10000), Timeout.Infinite); } } } }
private void GameTimerCallback(object state) { try { //Logger.Log("game tim: " + GameState.Started); GameTimerTry++; TimerTick = DateTime.Now.Ticks; // waiting for game to start if (GameState.Started == false) { //Logger.Log("ee"); try { //Logger.Log("k1"); Player = new MainPlayer(((Port = GetPort()) != 0) ? Port : 2999); //Logger.Log("k3 p: " + Port); /*if (Player != null) * Logger.Log("gts p: " + Port + " currenthealth: " + Player.game.CurrentHealth + " money: " + Player.GetGold()); */ if (Player != null && Player?.game?.CurrentHealth != 1) { GameState.Started = Player.GetGold() != 0; //er.Log("k4 "+ GameState.Started); } } catch (Exception ex) { Logger.Log("Waiting for game to start... (err)"); Logger.Log("wait err: " + ex.Message); Server.SetInfoText("Waiting for game to start... (err)"); } if (GameTimerTry == 50) { Server.SetInfoText("Still waiting..."); Control(); } //Logger.Log("gtfalse2"); if (GameTimerTry > 55) { Control(); if (LCU.SummonerID == 0) { if (Server.LoadedAccount != null) { GameTimerTry = 0; ClientApi.Stop(); Logger.Log("Restarting bot..."); Server.SetInfoText("Restarting bot..."); Thread.Sleep(10000); ClientApi.Start(); } else { Logger.Log("Can't find the loaded account."); Server.SetInfoText("Can't find the loaded account."); } } else { var process = ClientApi.GetProcessByName("League of Legends"); if (process == null) { try { Logger.Log("Trying to continue..."); Server.SetInfoText("Trying to continue..."); var bmp = PixelCache.GetScreenshot(); bmp.Bitmap.Save("qr1.bmp"); bmp.Dispose(); ClientApi.TryToContinue(); Logger.Log("Restarting queue..."); Server.SetInfoText("Restarting queue..."); GameTimerTry = 0; ClientApi.StartNewGame(); } catch (Exception x) { Logger.Log("queuerestart1 (1) image error..." + x.Message); Thread.Sleep(5000); ClientApi.Stop(); Logger.Log("Can't take screenshots. Trying to continue..."); Server.SetInfoText("Can't take screenshots. Trying to continue..."); Control(false); ClientApi.Start(); } } else { bool flag = false; try { var bmp = PixelCache.GetScreenshot(); bmp.Bitmap.Save("copen.bmp"); if (bmp.GetPixel(495, 352) == Color.FromArgb(59, 45, 24) || bmp.GetPixel(507, 344) == Color.FromArgb(255, 255, 255)) { flag = true; } bmp.Dispose(); if (flag) { Logger.Log("connection lost"); } else { Logger.Log("copen ok"); } } catch (Exception x) { Logger.Log("copen (1) image error..." + x.Message); flag = true; } if (flag) { ClientApi.Stop(); Logger.Log("Connection lost. Trying to continue..."); Server.SetInfoText("Connection lost. Trying to continue..."); Thread.Sleep(5000); ClientApi.Restart = true; ClientApi.Start(); } } } } else if (GameTimer != null) { ClientApi.TimerChange(GameTimer, 8000); } //Logger.Log("gtfalse3"); } else { //Logger.Log("gttrue1"); if (LOLHandle != null) { NativeMethods.Focus(LOLHandle); } else { Logger.Log("LOLHandle = null (?)"); } ClientApi.SetState(ClientStates.InGame); Server.SetIndicator(IndicatorStates.On); TimerTick = DateTime.Now.Ticks; //Logger.Log("gttrue2"); if (Port != 0 && Player == null) { Player = new MainPlayer(Port); } Shop = new Shop(); if (Start == 0) { Logger.Log("Game started."); Server.SetInfoText("Game started."); try { int gold = Player.GetGold(); foreach (var x in items) { if (x.got == false) { if (gold > x.cost) { if (!Shop.Opened) { //Logger.Log("opening shop"); Shop.Toggle(); Thread.Sleep(RandomTimeGenerator(500));/* * MouseOperations.SetCursorPosition(420 + RandomTimeGenerator(5), 80 + RandomTimeGenerator(4)); * Thread.Sleep(RandomTimeGenerator(200)); * MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftDown); * Thread.Sleep(RandomTimeGenerator(50)); * MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftUp);*/ Keyboard.ShortcutKeys(new System.Windows.Forms.Keys[] { System.Windows.Forms.Keys.ControlKey, System.Windows.Forms.Keys.L }, 40); Thread.Sleep(RandomTimeGenerator(1000)); } Thread.Sleep(RandomTimeGenerator()); string str = x.phrase; //Logger.Log("buying: " + x.name); foreach (char c in str) { Thread.Sleep(RandomTimeGenerator(150)); Keyboard.KeyPress((System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), c.ToString()), RandomTimeGenerator(50)); } Thread.Sleep(RandomTimeGenerator(500)); MouseOperations.SetCursorPosition(377 + RandomTimeGenerator(15), 146 + RandomTimeGenerator(8)); Thread.Sleep(RandomTimeGenerator(150)); MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.RightDown); Thread.Sleep(RandomTimeGenerator(40)); MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.RightUp); Thread.Sleep(RandomTimeGenerator(500)); Server.SetInfoText("Bought " + x.name); //Logger.Log("bought: " + x.name); for (int i = 0; i < str.Length; i++) { Thread.Sleep(RandomTimeGenerator(100)); Keyboard.KeyPress(System.Windows.Forms.Keys.Back); } x.got = true; gold -= x.cost; } else { break; } } } Thread.Sleep(RandomTimeGenerator()); /*if (Shop.Opened) * Logger.Log("closing shop");*/ if (Shop.Opened) { Shop.Toggle(); } Thread.Sleep(RandomTimeGenerator()); Server.SetInfoText("Bought first items."); Thread.Sleep(RandomTimeGenerator(35000) + 7500); } catch (Exception x) { Logger.Log("gg: " + x.Message); } } else { Thread.Sleep(RandomTimeGenerator(10000)); Logger.Log("Game (re)started."); Server.SetInfoText("Game (re)started."); Start = 0; items[0].got = true; } //Logger.Log("gttrue3 - after start"); try { var bmp = PixelCache.GetScreenshot(); Color col = bmp.GetPixel(795, 756); if (col.R != 0 && col.R != 255 && col.R != 165 && col.G != 142 && col.B != 99) { Keyboard.KeyPress(System.Windows.Forms.Keys.Y, RandomTimeGenerator(50)); string str = "Fixed camera." /* + Environment.NewLine + "R:" + col.R + " G:" + col.G + " B:" + col.B*/; Server.SetInfoText(str); Logger.Log(str); } if (bmp != null) { bmp.Dispose(); } } catch (Exception x) { Logger.Log("getscreen problem: " + x.Message); } Logger.Log("starting timers"); MinuteTimer = new Timer(MinuteTimerCallback, null, MinuteTimerInterval, Timeout.Infinite); HalfMinuteTimer = new Timer(HalfMinuteTimerCallback, null, 30000, Timeout.Infinite); TenSecondsTimer = new Timer(TenSecondsTimerCallback, null, 10000, Timeout.Infinite); SecondsTimer = new Timer(SecondsTimerCallback, null, 1000, Timeout.Infinite); Logger.Log("started"); SkillUp(2); if (GameTimer != null) { GameTimer.Dispose(); GameTimer = null; } //Logger.Log("gtend"); } } catch (Exception e) { try { var bmp = PixelCache.GetScreenshot(); bmp.Bitmap.Save("fe1.bmp"); bmp.Dispose(); } catch (Exception x) { Logger.Log("fatal (1) image error..." + x.Message); } Logger.Log("fatal error: gametimer \r\n" + e.Message); /* * MinuteTimer = new Timer(MinuteTimerCallback, null, MinuteTimerInterval, Timeout.Infinite); * HalfMinuteTimer = new Timer(HalfMinuteTimerCallback, null, 30000, Timeout.Infinite); * TenSecondsTimer = new Timer(TenSecondsTimerCallback, null, 10000, Timeout.Infinite); * SecondsTimer = new Timer(SecondsTimerCallback, null, 1000, Timeout.Infinite); * SkillUp(2);*/ if (GameTimer != null) { GameTimer.Dispose(); GameTimer = null; } } }
private void InitializeCache(string nodeKey) { DependencyRegistrar.RegisterSingletonComponent <IQueueHubClient>(new QueueHubClient(ConfigurationManager.AppSettings["QueueService_Endpoint"])); DependencyRegistrar.RegisterSingletonComponent <IThrottleCache>(new ThrottleCache()); Task.WaitAll(new[] { Task.Run(async() => DependencyRegistrar.RegisterSingletonComponent <IGameCache>(await GameCache.BuildCache(nodeKey))), Task.Run(async() => DependencyRegistrar.RegisterSingletonComponent <IPixelCache>(await PixelCache.BuildCache(nodeKey))), }, TimeSpan.FromMinutes(10)); }
private void Test2Button_Click(object sender, EventArgs e) { Thread thr = new System.Threading.Thread(() => { for (int i = 0; i < 100; i++) { Logger.Log("log thread" + i); } }); thr.Start(); for (int i = 0; i < 100; i++) { Logger.Log("log" + i); } System.Threading.Thread.Sleep(3000); Stopwatch all = new Stopwatch(); Stopwatch bll = new Stopwatch(); Stopwatch cll = new Stopwatch(); Stopwatch dll = new Stopwatch(); Stopwatch ell = new Stopwatch(); Stopwatch fll = new Stopwatch(); Stopwatch gll = new Stopwatch(); all.Start(); var bmp = PixelCache.GetScreenshot(); bll.Start(); Point me = ImageValues.GetMyPosition(bmp); // 35ms bll.Stop(); cll.Start(); Point tower = ImageValues.EnemyTowerPosition(bmp); // 130ms cll.Stop(); dll.Start(); Point enemy = ImageValues.EnemyPosition(bmp); // 130ms dll.Stop(); ell.Start(); Point enemyCreep = ImageValues.EnemyCreepPosition(bmp); // 127ms ell.Stop(); Point ally = ImageValues.AllyPosition(bmp); // 129ms Point allyCreep = ImageValues.AllyCreepPosition(bmp); // 129ms //int hpercent = Player.GetHealthPercent(); fll.Start(); int hpDiff = ImageValues.GetHPDifference(bmp); fll.Stop(); gll.Start(); int creepHpDiff = ImageValues.GetCreepHPDifference(bmp); gll.Stop(); all.Stop(); bmp.Dispose(); SetInfoText(all.ElapsedMilliseconds + "ms total" + Environment.NewLine + bll.ElapsedMilliseconds + "ms" + Environment.NewLine + cll.ElapsedMilliseconds + "ms" + Environment.NewLine + dll.ElapsedMilliseconds + "ms" + Environment.NewLine + ell.ElapsedMilliseconds + "ms" + Environment.NewLine + fll.ElapsedMilliseconds + "ms" + Environment.NewLine + gll.ElapsedMilliseconds + "ms" + Environment.NewLine); }
public static void ReadText() { Console.WriteLine("Image Preprocessing..."); List <string> WLines = new List <string>(); List <Rectangle> WRects = new List <Rectangle>(); List <string> PLines = new List <string>(); List <Rectangle> PRects = new List <Rectangle>(); //Bitmap screenshot = PixelCache.GetScreenshot(); Bitmap screenshot = ImageUtils.InvertImage( ImageUtils.ContrastImage( ImageUtils.DesaturateImage( PixelCache.GetScreenshot() ) , 25)); Console.WriteLine("Engine Processing..."); var data = Engine.Process(screenshot, PageSegMode.SparseText ); WRects = data.GetSegmentedRegions(PageIteratorLevel.Word); PRects = data.GetSegmentedRegions(PageIteratorLevel.TextLine); //Clear text coords only after we've done engine work TextCache.Clear(); PhraseCache.Clear(); Console.WriteLine("Extracting Words..."); using (var iterator = data.GetIterator()) { string line = ""; iterator.Begin(); do { do { do { do { string word = iterator.GetText(PageIteratorLevel.Word).Trim(); if (word != "") { line = line + word + " "; WLines.Add(word.ToUpper().Trim()); } } while (iterator.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word)); if (line != "") { PLines.Add(line.ToUpper().Trim()); } line = ""; } while (iterator.Next(PageIteratorLevel.Para, PageIteratorLevel.TextLine)); } while (iterator.Next(PageIteratorLevel.Block, PageIteratorLevel.Para)); } while (iterator.Next(PageIteratorLevel.Block)); } data.Dispose(); screenshot.Dispose(); Console.WriteLine("Saving results..."); for (int i = 0; i < WLines.Count; ++i) { if (!TextCache.ContainsKey(WLines[i])) { TextCache.Add( WLines[i], new Point( Convert.ToInt32((WRects[i].X + (WRects[i].Width / 2)) * 1), Convert.ToInt32((WRects[i].Y + (WRects[i].Height / 2)) * 1) ) ); } } for (int i = 0; i < PLines.Count; ++i) { if (!PhraseCache.ContainsKey(PLines[i])) { PhraseCache.Add( PLines[i], new Point( Convert.ToInt32((PRects[i].X + (PRects[i].Width / 2)) * 1), Convert.ToInt32((PRects[i].Y + (PRects[i].Height / 2)) * 1) ) ); } } Console.WriteLine("Read Complete."); Console.WriteLine("-----------------------"); }
void cacheDirections() { cacheNorth = getPixelNumbers(colors, lineWidth, lineHeight, 0, 1); cacheNorthEast = getPixelNumbers(colors, lineWidth, lineHeight, 1, 1); cacheEast = getPixelNumbers(colors, lineWidth, lineHeight, 1, 0); cacheSouthEast = getPixelNumbers(colors, lineWidth, lineHeight, 1, -1); cacheSouth = getPixelNumbers(colors, lineWidth, lineHeight, 0, -1); cacheSouthWest = getPixelNumbers(colors, lineWidth, lineHeight, -1, -1); cacheWest = getPixelNumbers(colors, lineWidth, lineHeight, -1, 0); cacheNorthWest = getPixelNumbers(colors, lineWidth, lineHeight, -1, 1); _fullCache = new PixelCache[3][][]; _fullCache[0]=new PixelCache[3][]{cacheSouthWest, cacheSouth, cacheSouthEast}; _fullCache[1]=new PixelCache[3][]{cacheWest , null , cacheEast }; _fullCache[2]=new PixelCache[3][]{cacheNorthWest, cacheNorth, cacheNorthEast}; }
public void clickGameMode(string type) { if (type == "summoners rift") { if (ImageRecognition.ImageExists("summonersRiftNormal.png", 10)) { Point coords = ImageRecognition.ImageCoords("summonersRiftNormal.png", 10); Mouse.Move(coords.X + (PixelCache.GetWidth("summonersRiftNormal.png") / 2), coords.Y + (PixelCache.GetHeight("summonersRiftNormal.png") / 2)); Mouse.PressButton(Mouse.MouseKeys.Left, 150); } else { bool exists = ImageRecognition.ImageExists("summonersRiftHover.png", 10); while (!exists) { exists = ImageRecognition.ImageExists("summonersRiftHover.png", 10); Thread.Sleep(1000); } Point coords = ImageRecognition.ImageCoords("summonersRiftHover.png", 10); Mouse.Move(coords.X + (PixelCache.GetWidth("summonersRiftHover.png") / 2), coords.Y + (PixelCache.GetHeight("summonersRiftHover.png") / 2)); Mouse.PressButton(Mouse.MouseKeys.Left, 150); } } else if (type == "aram") { if (ImageRecognition.ImageExists("aramNormal.png", 10)) { Point coords = ImageRecognition.ImageCoords("aramNormal.png", 10); Mouse.Move(coords.X + (PixelCache.GetWidth("aramNormal.png") / 2), coords.Y + (PixelCache.GetHeight("aramNormal.png") / 2)); Mouse.PressButton(Mouse.MouseKeys.Left, 150); } else { bool exists = ImageRecognition.ImageExists("aramHover.png", 10); while (!exists) { exists = ImageRecognition.ImageExists("aramHover.png", 10); Thread.Sleep(1000); } Point coords = ImageRecognition.ImageCoords("aramHover.png", 10); Mouse.Move(coords.X + (PixelCache.GetWidth("aramHover.png") / 2), coords.Y + (PixelCache.GetHeight("aramHover.png") / 2)); Mouse.PressButton(Mouse.MouseKeys.Left, 150); } } else if (type == "one for all") { if (ImageRecognition.ImageExists("oneForAllNormal.png", 10)) { Point coords = ImageRecognition.ImageCoords("oneForAllNormal.png", 10); Mouse.Move(coords.X + (PixelCache.GetWidth("oneForAllNormal.png") / 2), coords.Y + (PixelCache.GetHeight("oneForAllNormal.png") / 2)); Mouse.PressButton(Mouse.MouseKeys.Left, 150); } else { bool exists = ImageRecognition.ImageExists("oneForAllHover.png", 10); while (!exists) { exists = ImageRecognition.ImageExists("oneForAllHover.png", 10); Thread.Sleep(1000); } Point coords = ImageRecognition.ImageCoords("oneForAllHover.png", 10); Mouse.Move(coords.X + (PixelCache.GetWidth("oneForAllHover.png") / 2), coords.Y + (PixelCache.GetHeight("oneForAllHover.png") / 2)); Mouse.PressButton(Mouse.MouseKeys.Left, 150); } } else if (type == "teamfight tactics") { if (ImageRecognition.ImageExists("teamfightTacticsNormal.png", 10)) { Point coords = ImageRecognition.ImageCoords("teamfightTacticsNormal.png", 10); Mouse.Move(coords.X + (PixelCache.GetWidth("teamfightTacticsNormal.png") / 2), coords.Y + (PixelCache.GetHeight("teamfightTacticsNormal.png") / 2)); Mouse.PressButton(Mouse.MouseKeys.Left, 150); } else { bool exists = ImageRecognition.ImageExists("teamfightTacticsHover.png", 10); while (!exists) { exists = ImageRecognition.ImageExists("teamfightTacticsHover.png", 10); Thread.Sleep(1000); } Point coords = ImageRecognition.ImageCoords("teamfightTacticsHover.png", 10); Mouse.Move(coords.X + (PixelCache.GetWidth("teamfightTacticsHover.png") / 2), coords.Y + (PixelCache.GetHeight("teamfightTacticsHover.png") / 2)); Mouse.PressButton(Mouse.MouseKeys.Left, 150); } } else { //Unknown game mode } }
private void ServerControlCallback(object state) { try { TimeSpan timeSpan = new TimeSpan(Math.Abs(DateTime.Now.Ticks - GameSession.TimerTick)); if (timeSpan.TotalMinutes > 10) { ClientApi.LCU = new LCU(); if (LCU.SummonerID == 0) { try { var bmp = PixelCache.GetScreenshot(); bmp.Bitmap.Save("kill2.bmp"); bmp.Dispose(); } catch (Exception x) { Logger.Log("kill (2) image error..." + x.Message); } Logger.Log("kill2 " + timeSpan.ToString()); ClientApi.Stop(); SetInfoText("Restarting bot..."); if (LoadedAccount != null) { ClientApi.Start(); } else { Logger.Log("no loaded account"); } } else { try { var bmp = PixelCache.GetScreenshot(); bmp.Bitmap.Save("gs2.bmp"); bmp.Dispose(); } catch (Exception x) { Logger.Log("gamesession (2) image error..." + x.Message); } Logger.Log("gamesession (2) restart..." + timeSpan.ToString()); GameSession.Start = 1; GameSession = new GameSession(this, Game.Champions.RandomChamp()); } } else { Logger.Log("check - OK: bot is working... (2)"); } } catch (Exception x) { Logger.Log("check - FAIL: serverControlTimer error: " + x.Message); } finally { ClientApi.TimerChange(serverControl, 30000); } }
public void pixelcache_flush(PixelCache cache) { throw new NotImplementedException(); }
internal static int GetTextValue(Rectangle rectangle) { Stopwatch st = Stopwatch.StartNew(); Bitmap src = PixelCache.GetScreenshot(); Bitmap target = new Bitmap(rectangle.Width, rectangle.Height); using (Graphics g = Graphics.FromImage(target)) { g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), rectangle, GraphicsUnit.Pixel); } Page page = Engine.Process(target); int text; string textReplacement; textReplacement = page.GetText(); if (textReplacement.Contains('I')) { textReplacement = textReplacement.Replace('I', '1'); } if (textReplacement.Contains(' ')) { textReplacement = textReplacement.Replace(" ", String.Empty); } if (textReplacement.Contains('Z')) { textReplacement = textReplacement.Replace('Z', '2'); } if (textReplacement.Contains('S')) { textReplacement = textReplacement.Replace('S', '5'); } if (textReplacement.Contains("\n")) { textReplacement = textReplacement.Replace("\n", String.Empty); } try { text = Convert.ToInt32(textReplacement); } catch { text = 0; } //Console.WriteLine($"DEBUG GOLD (actual value): {textReplacement}"); src.Dispose(); target.Dispose(); page.Dispose(); return(text); }