Beispiel #1
0
        /// <summary>
        /// Initialize Worker
        /// </summary>
        public SeatingScript()
        {
            /*
             * What does the seating script need to start?
             * 1. Pointer to the table
             * 2. Positions of avatar rectangles since these are the spots to check on and click if open seat
             */

            worker = new BackgroundSeatingWorker();
            worker.WorkerReportsProgress      = true;
            worker.WorkerSupportsCancellation = true;
            worker.DoWork             += new DoWorkEventHandler(Worker_DoWork);
            worker.RunWorkerCompleted += Worker_RunWorkerCompleted;
        }
Beispiel #2
0
        /// <summary>
        /// Evaluation of seating success after worker completed/got cancelled
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            BackgroundSeatingWorker result = (BackgroundSeatingWorker)sender;

            if (e.Error != null)
            {
                //MessageBox.Show(e.Error.StackTrace.ToString()); // Debug
            }
            // Reset Buttons after worker got cancelled (either b/c we got a seat or something went wrong)
            else if (e.Cancelled)
            {
                // Adjust Click Delegates and Text after Seat was successfully found
                ScanButton scan = result.scanButton;
                scan.Text = GlobalSettings.ButtonSettings.ScanButtonLabel;

                // Clean up delegates and adjust accordingly
                // If seating script runs, clicking on ScanButton stops seating script
                // If seating script is off, clicking on ScanButton scans table
                RemoveClickEvent(scan);
                scan.Click += SessionHandler.ControlButton_Click;
                scan.Refresh();
                activeWorkers.Remove(scan.TableHandle);

                // Update ContextMenu for ScanButton (switch between "start seatingscript" and "stop seatingscript"
                foreach (ToolStripMenuItem tsmi in scan.ContextMenuStrip.Items)
                {
                    if (tsmi.Text.Contains("SeatingScript"))
                    {
                        tsmi.Text = GlobalSettings.SeatingScript.StartSeatingScriptLabel;
                        break;
                    }
                }
            }
            else
            {
                // No exception in DoWork.
                try
                {
                    // Seat was found!
                    success.Play();
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.ToString());
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Try to seat every pre-set interval if seat opened up
        /// </summary>
        /// <param name="handle">Pointer of table which gets scanned</param>
        /// <param name="ava">List of avatar positions which need to get checked and eventually clicked on</param>
        /// <returns></returns>
        private bool attemptSeating(IntPtr handle, List <Rectangle> ava)
        {
            // Get new Screenshot every interval
            Bitmap asd = Screenshot.CaptureApplication(handle);

            // Check for each Avatar Position
            foreach (Rectangle r in ava)
            {
                // Crop Image to specific avatar size/position in order to check if seat is open or not
                using (Bitmap tmp = Screenshot.CropImage(Screenshot.CaptureApplication(handle), r))
                {
                    bool escape = false;
                    int  count  = 0;

                    for (int x = 0; x < r.Width; x++)
                    {
                        for (int y = 0; y < r.Height; y++)
                        {
                            // Check every pixel from cropped image if it fits the range of color an open seat usually has
                            if (Helper.colorIsInRange(GlobalSettings.SeatingScript.OpenSeatColor, tmp.GetPixel(x, y), 10))
                            {
                                // Keep track of how many pixels matched the open seat color
                                count++;

                                // If count exceeds threshold of open seat pixels we can assume the seat is open
                                if (count > GlobalSettings.SeatingScript.SeatOpenCounts) // Seat is open
                                {
                                    escape = true;

                                    /*
                                     * Problem: If we are using the betslider on a table while a seat pops open,
                                     *          clicking on the open seat will often move us all-in on the other table
                                     *          (yes, it cost me some money figuring that out xD -.-)
                                     * Solution: Before clicking on the seat, Check if Left MouseButton is pressed
                                     */
                                    if (WinAPI.GetAsyncKeyState(WinAPI.VK_LBUTTON) != -32767) // Left Mouse Button is NOT pressed
                                    {
                                        // click on open seat
                                        clickSeat(handle, r);

                                        // Cancel Background Worker
                                        BackgroundSeatingWorker bgWorker = activeWorkers[handle];
                                        ScanButton sb = bgWorker.scanButton;
                                        worker.CancelAsync();

                                        // Play success-Sound
                                        success.Play();
                                        return(true);
                                    }
                                    break;
                                }
                                if (escape)
                                {
                                    break;
                                }
                            }
                            if (escape)
                            {
                                break;
                            }
                        }
                        if (escape)
                        {
                            break;
                        }
                    }
                    if (escape)
                    {
                        break;
                    }
                }
            }
            return(false);
        }