Esempio n. 1
0
        /// <summary>
        /// Turn the bot on or off.
        /// </summary>
        public void ToggleBotStatus()
        {
            if (IsStopped())
            {
                PreferredAwakes = AwakeningParser.GetPreferredAwakes(Ui.lviAwakes);

                Thread panicThread = new Thread(() => PanicKeyThread());
                panicThread.Start();

                Thread awakeThread = new Thread((awakes) => AwakeningLoopThread(PreferredAwakes));
                awakeThread.Start(PreferredAwakes);

                CrossThreadChangeControlText(Ui.btnStartBot, "Stop");
            }
            else
            {
                CrossThreadChangeControlText(Ui.btnStartBot, "Start");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Executes the bot's awakening routine.
        /// </summary>
        /// <param name="preferredAwakes"></param>
        private void AwakeningLoopThread(List <Awake> preferredAwakes)
        {
            try
            {
                CrossThreadAppendLog("Bot has started\n");

                Win32API.SetForegroundWindow(Ui.Process.Handle);

                using (AwakeningResolver awakeResolver = new AwakeningResolver(ConfigManager, this))
                {
                    while (true)
                    {
                        Stopwatch stopWatch = new Stopwatch();
                        stopWatch.Start();

                        // Hover over the item to check the awake
                        BotHelper.SetCursorPosition(ItemPosition);

                        if (IsStopped())
                        {
                            break;
                        }

                        // Add specified delay to compensate for laggy server
                        int msValue = 0;

                        Ui.Invoke(new Action(() =>
                        {
                            msValue = Ui.trackBarMsDelay.Value;
                        }));

                        Thread.Sleep(msValue);

                        Bitmap bmp = awakeResolver.SnapshotRectangle(InventoryRectangle);

                        // bmp.Save("1.bmp");

                        Ui.Invoke(new Action(() =>
                        {
                            Ui.PictureBoxDebug1.Image = (Image)bmp.Clone();
                        }));

                        bmp = awakeResolver.DifferentiateAwakeText(bmp);
                        // bmp.Save("2.bmp");

                        Ui.Invoke(new Action(() =>
                        {
                            Ui.PictureBoxDebug2.Image = (Image)bmp.Clone();
                        }));

                        bmp = awakeResolver.CropBitmapSmart(bmp);
                        // bmp.Save("3.bmp");

                        Ui.Invoke(new Action(() =>
                        {
                            Ui.PictureBoxDebug3.Image = (Image)bmp.Clone();
                        }));

                        bmp = awakeResolver.IncreaseBitmapSize(bmp, 300);
                        // bmp.Save("4.bmp");

                        Ui.Invoke(new Action(() =>
                        {
                            Ui.PictureBoxDebug4.Image = (Image)bmp.Clone();
                        }));

                        string awakeText = awakeResolver.GetAwakening(bmp);

                        AwakeningParser awakeParser = new AwakeningParser(Ui, ConfigManager, awakeText);
                        List <Awake>    itemAwakes  = awakeParser.GetCompletedAwakes();

                        string awakeAchieved = "";

                        for (int i = 0; i < itemAwakes.Count; ++i)
                        {
                            awakeAchieved += itemAwakes[i].ToString() + (i == (itemAwakes.Count - 1) ? "" : " | ");
                        }

                        if (awakeAchieved.Length <= 0)
                        {
                            awakeAchieved = "No awake found\n";
                            CrossThreadAppendLog(awakeAchieved + "\n");
                        }

                        CrossThreadAppendLog(awakeAchieved + "\n");

                        // Check if awake meets the requirements
                        if (AwakeMeetsRequirements(itemAwakes, preferredAwakes))
                        {
                            CrossThreadAppendLog("Preferred awake was successfully achieved\n");

                            stopWatch.Stop();
                            CrossThreadChangeControlText(Ui.lblIterationTime, stopWatch.ElapsedMilliseconds.ToString() + " ms");
                            CrossThreadChangeControlText(Ui.lblTotalTries, (Convert.ToInt32(Ui.lblTotalTries.Text) + 1).ToString());

                            break;
                        }

                        CrossThreadAppendLog("Preferred awake was not achieved\n");

                        // Doubleclick reversion scroll
                        BotHelper.SimulateMouseClick(Ui.Process.Handle, ReversionPosition);
                        BotHelper.SimulateMouseClick(Ui.Process.Handle, ReversionPosition);

                        int ms = 200;

                        Thread.Sleep(ms);

                        // Click item with reversion
                        BotHelper.SimulateMouseClick(Ui.Process.Handle, ItemPosition);

                        // Wait until the reversion is done on the item
                        Thread.Sleep(ConfigManager.ScrollDelay);

                        // Doubleclick awake scroll
                        BotHelper.SimulateMouseClick(Ui.Process.Handle, AwakeScrollPosition);

                        if (!Ui.cbSupportAugmentation.Checked)
                        {
                            BotHelper.SimulateMouseClick(Ui.Process.Handle, AwakeScrollPosition);
                        }

                        Thread.Sleep(ms);

                        // Click item with awake scroll
                        BotHelper.SimulateMouseClick(Ui.Process.Handle, ItemPosition);

                        Thread.Sleep(ms);

                        BotHelper.SetCursorPosition(new Point(ItemPosition.X + 200, ItemPosition.Y + 200));
                        Thread.Sleep(ms);
                        BotHelper.SetCursorPosition(ItemPosition);

                        // Wait until the awake is done on the item
                        Thread.Sleep(ConfigManager.ScrollDelay);

                        bmp.Dispose();

                        if (IsStopped())
                        {
                            break;
                        }

                        stopWatch.Stop();
                        CrossThreadChangeControlText(Ui.lblIterationTime, stopWatch.ElapsedMilliseconds.ToString() + " ms");
                        CrossThreadChangeControlText(Ui.lblTotalTries, (Convert.ToInt32(Ui.lblTotalTries.Text) + 1).ToString());
                    }
                }

                CrossThreadChangeControlText(Ui.btnStartBot, "Start");

                CrossThreadAppendLog("Bot has finished\n");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }