Ejemplo n.º 1
0
        private void TestButton_Click(object sender, EventArgs e)
        {
            GameSession.Start = 1;
            LCU LCU = new LCU();

            GameSession = new GameSession(this, Convert.ToInt32(testBox1.Text));
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        private static void QueueTimerCallback(object state) // check main screen
        {
            if (LOLProcess != null && !LOLProcess.HasExited)
            {
                Try++;
                if (Try > MAX_TRIES)
                {
                    State = ClientStates.Idle;

                    LogAndInfo("Can't get in queue: Reached to max. number of tries.");
                    KillTimers();
                }
                else
                {
                    LogAndInfo("Waiting for the main screen..."); //);
                    TimerChange(LoginTimer, QueueTimerInterval);
                }
            }
            else
            {
                /*if (LOLProcess != null)
                 * {
                 *  LOLProcess.Dispose();
                 *  LOLProcess = null;
                 * }*/
                GameSession.TimerTick = DateTime.Now.Ticks;
                KillTimers();
                Logger.Log("Killed timers (q1)");
                LogAndInfo("Preparing...");
                Try = 0;
                sel = 0;

                Thread.Sleep(GameSession.RandomTimeGenerator(5000));
                try
                {
                    LCU = new LCU();
                    while (LCU.SummonerID == 0)
                    {
                        KillEdge();
                        Thread.Sleep(GameSession.RandomTimeGenerator(15000));
                        if (GameSession.GetPort() != 0)
                        {
                            GameSession.TimerTick = DateTime.Now.Ticks;
                            LogAndInfo("reconnecting");
                            Restart = true;
                            break;
                        }
                        LogAndInfo("Can't set summonerID");
                        Try = -1;
                        LCU = new LCU();
                    }
                    Thread.Sleep(GameSession.RandomTimeGenerator(15000));
                    while (LCU.IsInLoginQueue())
                    {
                        GameSession.TimerTick = DateTime.Now.Ticks;
                        KillEdge();
                        LogAndInfo("Still in login queue.");
                        Thread.Sleep(GameSession.RandomTimeGenerator(15000));
                    }
                }
                catch (Exception x)
                {
                    LogAndInfo("qu error: " + x.Message);
                }
                KillEdge();
                if (!Restart)
                {
                    try
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            TryToContinue();
                        }
                        //ok-ok-ok
                        Thread.Sleep(GameSession.RandomTimeGenerator(15000));
                        LogAndInfo("Creating lobby...");
                        string re = LCU.CreateLobby("intro");
                        while (re != "OK" && re != "423")
                        {
                            LCU = new LCU();
                            Thread.Sleep(GameSession.RandomTimeGenerator(5000));
                            re = LCU.CreateLobby("intro");
                        }
                        Server.SetIndicator(IndicatorStates.Wait);

                        LoginTimer = new Timer(Queue2TimerCallback, null, Queue2TimerInterval, Timeout.Infinite);
                    }
                    catch (Exception x)
                    {
                        Logger.Log("!res err: " + x.Message);
                    }
                }
                else
                {
                    while (GameSession.GetPort() == 0)
                    {
                        TryToContinue();
                        LogAndInfo("waiting for reconnect...");
                    }
                    LogAndInfo("Reconnecting...");
                    State = ClientStates.InGame;
                    Communication.SendMessageWithoutReply(Server.ClientID, "state", "ingame");
                    StartGameSession(Champions.RandomChamp());
                    KillTimers();
                    Restart = false;
                }
            }
        }
Ejemplo n.º 4
0
        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);
            }
        }