Exemple #1
0
        /// <summary>
        /// Get TableSize from ScanButton
        /// </summary>
        /// <param name="button">ScanButton</param>
        /// <returns>TableSize</returns>
        private int getTableSize(ScanButton button)
        {
            int selectedIndex = button.scanComboBox.SelectedIndex;
            int numberOfSeats = int.Parse(button.scanComboBox.Items[selectedIndex].ToString());

            return(numberOfSeats);
        }
Exemple #2
0
        /// <summary>
        /// Stop SeatingScript - Accessible from rest of toolbox, handles stop-requests
        /// </summary>
        /// <param name="b">ScanButton of table which seatingscript will stop</param>
        public void stopSeating(ScanButton b)
        {
            // Get Worker-Object from active workerlist
            BackgroundWorker finishHim = activeWorkers[b.TableHandle];

            try
            {
                if (finishHim.WorkerSupportsCancellation)
                {
                    // Send Cancel-Command to
                    finishHim.CancelAsync();

                    // Reset Text in ScanButton Context Menu from "Stop SeatingScript" to "Start SeatingScript"
                    foreach (ToolStripMenuItem tsmi in b.ContextMenuStrip.Items)
                    {
                        if (tsmi.Text.Contains("SeatingScript"))
                        {
                            tsmi.Text = GlobalSettings.SeatingScript.StartSeatingScriptLabel;
                        }
                    }
                    // Play Abort-Sound
                    stop.Play();
                }
                else
                {
                    throw new Exception("Cancellation not Supported");
                }
            } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); }
        }
Exemple #3
0
        /// <summary>
        /// Start SeatingScript
        /// </summary>
        /// <param name="button">ScanButton from table where scripts will start running (necessary to update GUI)</param>
        public void startSeating(ScanButton button)
        {
            // Init
            int              tableSize = getTableSize(button);
            IntPtr           pointer   = button.TableHandle;
            GraphicPositions graphics  = new GraphicPositions();

            // Chefk if emulator has preset size, if not => Resize
            SessionHandler.checkEmulatorSize(pointer);

            // Retrieve avatar rectangles for specific tablesize (avatar positions are seating buttons if nobody sits)
            Dictionary <string, Rectangle>[] positions       = graphics.getGraphicPositions(tableSize);
            Dictionary <string, Rectangle>   avatarPositions = positions[1];
            List <Rectangle> avaPosi = avatarPositions.Values.ToList();

            // BackgroundWorker needs Pointer of Table and positions of avatar rectangles to check
            // Construct parameters passed to Worker-Thread
            object[] parameters = new object[2];
            parameters[0] = pointer;
            parameters[1] = avaPosi;

            activeWorkers[pointer] = worker;
            worker.RunWorkerAsync(parameters);
            worker.scanButton = button;

            // Update ScanButton text
            button.Text = GlobalSettings.SeatingScript.StopSeatingScriptLabel;

            // Remove Click Events from ScanButton, otherwise it Scans the table before stopping the seating script
            RemoveClickEvent(button);

            // Set EventHandler on Click to Stopping SeatingScript instead of Scanning Table
            button.Click += ButtonStopSeatingScript_Click;
        }
        /// <summary>
        /// Start TableModule ==> Scan Button Was clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void ControlButton_Click(object sender, EventArgs e)
        {
            ScanButton sb = new ScanButton();

            // Get ScanButton instance depending on where the request came from
            if (sender is ToolStripMenuItem) // From Context Menu
            {
                ToolStripMenuItem          tsi   = (ToolStripMenuItem)sender;
                ScanButtonContextMenuStrip pbcms = (ScanButtonContextMenuStrip)tsi.GetCurrentParent();
                sb = pbcms.parentButton;
            }
            else if (sender is ScanButton) // From LeftClick on ScanButton
            {
                sb = (ScanButton)sender;
            }
            else
            {
                throw new Exception("ControlButton_Click: Unknown Sender");
            }

            // Check Again for Size of the table
            checkEmulatorSize(sb.TableHandle);

            // Scan the table
            TableHandler.scan(sb);
        }
        public static void SeatingScript_Click(object sender, EventArgs e)
        {
            if (sender is ToolStripMenuItem)
            {
                SeatingScript ss = new SeatingScript();

                ToolStripMenuItem          tsi   = (ToolStripMenuItem)sender;
                ScanButtonContextMenuStrip pbcms = (ScanButtonContextMenuStrip)tsi.GetCurrentParent();
                ScanButton scanButton            = pbcms.parentButton;

                if (tsi.Text.Equals(GlobalSettings.SeatingScript.StartSeatingScriptLabel))
                {
                    ss.startSeating(scanButton);
                    tsi.Text = GlobalSettings.SeatingScript.StopSeatingScriptLabel;
                }
                else if (tsi.Text.Equals(GlobalSettings.SeatingScript.StopSeatingScriptLabel))
                {
                    ss.stopSeating(scanButton);
                    tsi.Text        = GlobalSettings.SeatingScript.StartSeatingScriptLabel;
                    scanButton.Text = GlobalSettings.ButtonSettings.ScanButtonLabel;
                }
                else
                {
                    throw new Exception("Labeling of SeatingScript Buttons is wrong!");
                }
            }
            else
            {
                throw new Exception("Sender is no ToolStripMenuItem!");
            }
        }
Exemple #6
0
        /// <summary>
        /// StopSeating Script Button
        /// </summary>
        /// <param name="sender">ScanButton</param>
        /// <param name="e"></param>
        private void ButtonStopSeatingScript_Click(object sender, EventArgs e)
        {
            // Stop Seating Script
            ScanButton scan = (ScanButton)sender;

            stopSeating(scan);

            // Reset ScanButton Text & Update EventHandlers (Scan Table on ScanButton.Click)
            scan.Text = GlobalSettings.ButtonSettings.ScanButtonLabel;
            RemoveClickEvent(scan);
            scan.Click += SessionHandler.ControlButton_Click;
            scan.Refresh();

            // Remove worker from active worker list
            activeWorkers.Remove(scan.TableHandle);
        }
Exemple #7
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());
                }
            }
        }
        /// <summary>
        /// Remove ScanButton from single Instance
        /// </summary>
        /// <param name="sb"></param>
        public static void removeScanButton(ScanButton sb)
        {
            scanButtonList.Remove(sb.TableHandle);
            // bug if table hasnt been scanned
            if (!TableHandler.tableSessions.ContainsKey(sb.TableHandle))
            {
                //MessageBox.Show("Table was not scanned yet!");    // Debug
            }
            else
            {
                // Clear TableData and Button Inventory
                string tablename = TableHandler.tableSessions[sb.TableHandle].tablename;
                TableHandler.Dispose(sb.TableHandle);
                TableHandler.buttonInventory[tablename].Dispose();
            }

            // Dispose components
            sb.Dispose();
            sb.scanComboBox.Dispose();
            sb.checkBox.Dispose();
        }
        /// <summary>
        /// Attach ScanButton to Emulator instances
        /// </summary>
        public void attachScanControls()
        {
            updateSession(); // check for new emulator instances
            foreach (IntPtr emulator in emulatorList)
            {
                if (scanButtonList == null)
                {
                    scanButtonList = new Dictionary <IntPtr, ScanButton>();
                }

                // check if ScanButton for this emulator is already getting tracked
                if (scanButtonList.ContainsKey(emulator))
                {
                    continue;
                }
                //else Console.WriteLine("new emulator found");     // Debug

                // Check & Set Emulator Window Size
                checkEmulatorSize(emulator);

                // Init ScanButton with all necessary components (ComboBox for chosing tablesize, custom context menu, etc)
                ScanButton    scanButton         = new ScanButton();
                ScanComboBox  scanButtonComboBox = new ScanComboBox();
                AlertCheckBox box = new AlertCheckBox();
                ScanButtonContextMenuStrip scanButtonCMS = new ScanButtonContextMenuStrip();

                scanButton.ContextMenuStrip = scanButtonCMS;
                scanButton.scanComboBox     = scanButtonComboBox;
                scanButton.checkBox         = box;
                scanButton.TableName        = WinAPI.GetWindowTitle((int)emulator);
                scanButton.Click           += ControlButton_Click;

                scanButton.SetParent(emulator);
                scanButtonComboBox.SetParent(emulator);
                box.SetParent(emulator);

                // Add Emulator/Button to tracking
                scanButtonList[emulator] = scanButton;
            }
        }
Exemple #10
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);
        }
Exemple #11
0
        /// <summary>
        /// Triggers Tablescan where all info will be gathered and retrieve information will get separated into Data and GUI Parts
        /// </summary>
        /// <param name="button">ScanButton of table in focus</param>
        public static void scan(ScanButton button)
        {
            IntPtr handle = button.TableHandle;

            if (handle.Equals(IntPtr.Zero))
            {
                throw new Exception("Can't scan Zero Pointer");
            }

            // Get TableSize and check if supported by toolbox
            int tableSize = int.Parse(button.scanComboBox.SelectedItem.ToString());

            if (!GlobalSettings.General.SupportedTableSizes.Contains(tableSize))
            {
                throw new Exception("Unsupported Tablesize: " + tableSize);
            }

            // Init TableData with tablesize
            TableData table = new TableData(tableSize);

            // Retrieve Screenshot for table
            Bitmap screenshot = Screenshot.CaptureApplication(handle);

            // Checks if tablesize between scans has changed
            // If changed, means that we have to perform a completely new table (and get rid of locked seats and stuff)
            bool tableHasSameNumberOfSeats = true;

            // Table was scanned before
            if (tableSessions.ContainsKey(handle))
            {
                table = tableSessions[handle];

                // if tableSize from sessions is different than new one => start over with a new table since selection has changed (we sit on a new table)
                if (!table.getTableSize().Equals(tableSize))
                {
                    table                     = new TableData(tableSize);
                    table.tablename           = button.TableName;
                    table.tablePointer        = handle;
                    tableSessions[handle]     = table;
                    table.scanButton          = button;
                    tableHasSameNumberOfSeats = false;
                }
            }
            else // New Table aka First Scan of a table
            {
                table.tablename       = button.TableName;
                table.tablePointer    = handle;
                tableSessions[handle] = table;
                table.scanButton      = button;
            }

            // Get all unlocked Seats, as they are the only ones that should be scanned/updated from scratch
            Stack <string> scanTheseSeats = table.getUnlockedSeats();

            // Analyze those seats from screenshot
            ScreenshotAnalyzer scAnalyze = new ScreenshotAnalyzer(engine, screenshot, scanTheseSeats, tableSize);

            // Retrieve usable (aka string) information from the scan
            Dictionary <string, RawSeatInfo> unlockedSeatsInformation = scAnalyze.getRawSeatInfo();

            // Update/Set Retrieved info in TableData
            foreach (KeyValuePair <string, RawSeatInfo> kvp in unlockedSeatsInformation)
            {
                string      seat = kvp.Key;
                RawSeatInfo rsi  = kvp.Value;
                table.setNickname(seat, rsi.nicknameSTRING);
                table.setAvatar(seat, rsi.avatar);
            }

            // Run Button Creation at this point
            if (buttonInventory.ContainsKey(table.tablename))
            {
                if (tableHasSameNumberOfSeats) // Same table as before (probably)
                {
                    buttonInventory[table.tablename].removeUnlockedButtons(scanTheseSeats);
                    buttonInventory[table.tablename].updateButtons(table, false);
                }
                else // if there is a new table size than scan before => new table/remove all old buttons from display
                {
                    buttonInventory[table.tablename].removeAllButtons();
                    tableHasSameNumberOfSeats        = true;
                    buttonInventory[table.tablename] = new PlayerButtonHandler(table);
                }
            }
            else
            {
                buttonInventory[table.tablename] = new PlayerButtonHandler(table);
            }
        }