Пример #1
0
 private bool NextPage()
 {
     WINAPI.click(int.Parse(reagentXBox.Text) + 633, int.Parse(reagentYBox.Text) + 510);
     Thread.Sleep(300);
     Cursor.Position = new Point(0, 0);
     if (Recognize.Contains(new Bitmap(Path.Combine(Directory.GetCurrentDirectory(), "BazaarUtils/nextpage.png"))))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #2
0
        private void BuySelected()
        {
            Log("Attempting to buy");
            WINAPI.click(int.Parse(reagentXBox.Text) + 106, int.Parse(reagentYBox.Text) + 550);
            Thread.Sleep(300);
            WINAPI.mDown(int.Parse(reagentXBox.Text) + 588, int.Parse(reagentYBox.Text) + 343);
            Thread.Sleep(300);
            WINAPI.mDragTo(int.Parse(reagentXBox.Text) + 643, int.Parse(reagentYBox.Text) + 343);
            Thread.Sleep(300);
            WINAPI.click(int.Parse(reagentXBox.Text) + 313, int.Parse(reagentYBox.Text) + 527);
            Cursor.Position = new Point(0, 0);
            Thread.Sleep(500);
            Log("Clicked buy");
            WINAPI.click(int.Parse(reagentXBox.Text) + 313, int.Parse(reagentYBox.Text) + 527);
            Cursor.Position = new Point(0, 0);
            Recognize.makeScreen().Save(Path.Combine(Directory.GetCurrentDirectory(), $"Purchases/{DateTime.Now.ToBinary()}.png"));
            Image <Bgr, byte> source   = new Image <Bgr, byte>(Recognize.makeScreen());                                                          // Image B
            Image <Bgr, byte> template = new Image <Bgr, byte>(new Bitmap(Path.Combine(Directory.GetCurrentDirectory(), "BazaarUtils/ok.png"))); // Image A

            using (Image <Gray, float> result = source.MatchTemplate(template, TemplateMatchingType.CcoeffNormed))
            {
                double[] minValues, maxValues;
                Point[]  minLocations, maxLocations;
                result.MinMax(out minValues, out maxValues, out minLocations, out maxLocations);

                // You can try different values of the threshold. I guess somewhere between 0.75 and 0.95 would be good.
                if (maxValues[0] > 0.85)
                {
                    DebugLog("Found ok button at X: " + maxLocations[0].X + " Y: " + maxLocations[0].Y);
                    // This is a match. Do something with it, for example draw a rectangle around it.
                    Rectangle match = new Rectangle(maxLocations[0], template.Size);
                    WINAPI.click(match.X, match.Y);
                    Thread.Sleep(50);
                    DebugLog("Clicked ok button");
                }
                else
                {
                    Log("I couldn't find the ok button!");
                }
            }

            WINAPI.click(1250, 780);
            Cursor.Position = new Point(0, 0);
            Thread.Sleep(50);
            WINAPI.click(1140, 620);
            Cursor.Position = new Point(0, 0);
            Thread.Sleep(50);
            source.Dispose();
            template.Dispose();
        }
Пример #3
0
        private void Main()
        {
            /*Image<Bgr, byte> Image1 = new Image<Bgr, byte>(Recognize.makeScreen(true)); //Your first image
             * Image<Bgr, byte> Image2 = new Image<Bgr, byte>(new Bitmap(Path.Combine(Directory.GetCurrentDirectory(), "BazaarItems/titanium.png")).ConvertToFormat(System.Drawing.Imaging.PixelFormat.Format24bppRgb)); //Your second image
             *
             * double Threshold = 0.9; //set it to a decimal value between 0 and 1.00, 1.00 meaning that the images must be identical
             *
             * Image<Gray, float> Matches = Image1.MatchTemplate(Image2, TemplateMatchingType.CcoeffNormed);
             *
             * for (int y = 0; y < Matches.Data.GetLength(0); y++)
             * {
             *  for (int x = 0; x < Matches.Data.GetLength(1); x++)
             *  {
             *      if (Matches.Data[y, x, 0] >= Threshold) //Check if its a valid match
             *      {
             *
             *          Log("Hey I found titanium!");
             *      }
             *  }
             * }*/
            Log("Main Logic Initialized");
            while (true)//Main loop
            {
                int counter = 1;
                //Refresh layer
                DebugLog("Trying to refresh Reagents (clicking X: " + int.Parse(reagentXBox.Text) + " Y: " + int.Parse(reagentYBox.Text) + ")");
                WINAPI.click(int.Parse(reagentXBox.Text), int.Parse(reagentYBox.Text));
                Cursor.Position = new Point(0, 0);
                Thread.Sleep(50);
                DebugLog("Clicked refresh, waiting for loading to finish");
                while (ContainsLoading(new Bitmap(Path.Combine(Directory.GetCurrentDirectory(), "BazaarUtils/isloading.png"))))
                {
                    Thread.Sleep(1);
                }
                DebugLog("Load finished");
                bool runAgain = true;
                while (runAgain)
                {
                    DebugLog("Scanning page " + counter);
                    counter++;
                    foreach (var item in selectedBox.Items)
                    {
                        DebugLog("Looking for " + item);
                        Image <Bgr, byte> source   = new Image <Bgr, byte>(Recognize.makeScreen(true));                                                                                                                                   // Image B
                        Image <Bgr, byte> template = new Image <Bgr, byte>(new Bitmap(Path.Combine(Directory.GetCurrentDirectory(), "BazaarItems/" + item + ".png")).ConvertToFormat(System.Drawing.Imaging.PixelFormat.Format24bppRgb)); // Image A

                        using (Image <Gray, float> result = source.MatchTemplate(template, TemplateMatchingType.CcoeffNormed))
                        {
                            double[] minValues, maxValues;
                            Point[]  minLocations, maxLocations;
                            result.MinMax(out minValues, out maxValues, out minLocations, out maxLocations);

                            if (maxValues[0] > 0.9)
                            {
                                // This is a match. Do something with it, for example draw a rectangle around it.
                                Rectangle match = new Rectangle(maxLocations[0], template.Size);
                                Log("Found " + item);
                                WINAPI.click(match.X + 800, match.Y + 380);
                                DebugLog("Clicked on Item");
                                Thread.Sleep(50);
                                BuySelected();
                            }
                            else
                            {
                                DebugLog("Not found");
                            }
                        }

                        source.Dispose();
                        template.Dispose();
                    }
                    Thread.Sleep(100);
                    DebugLog("Checking if there are more pages");
                    if (ContainsNext(new Bitmap(Path.Combine(Directory.GetCurrentDirectory(), "BazaarUtils/nextpagegray.png"))))
                    {
                        DebugLog("This was the last page");
                        runAgain = false;
                    }
                    else
                    {
                        DebugLog("Found another page, clicking to hardcoded Position");
                        WINAPI.click(1250, 780);
                        Cursor.Position = new Point(0, 0);
                        Thread.Sleep(50);
                    }
                }
            }
        }