PartySNGHelper v1.18e

By jukofyork at 2+2 forums (reusing alot of code from Dave's and Roland's scripts - thanks to them!).

Improvements added in v1.11b thanks to fenixguy (FenixOnTilt).

The corresponding thread on 2+2 is here.

Video demonstration on DonkraftPoker.com.


PartySNGHelper currently works on "classic" tables only. Do not try to use it on the "new" tables yet...

Features

Instructions

Simply start the script and all the features will be available while you play SNGs.

Mouse Controls

Keyboard Controls

Speed SNG List

Options

Version History

1.01 (19-Jan-2007)

  1. Original Release

1.02 (24-Jan-2007)

  1. Have tried to make the finished SNG closer work more stably by trying for 5 times over 2.5 seconds and testing if each time agrees.

1.03 (29-Jan-2007)

  1. Have removed the code which closed the finished SNGs - wasn't working properly and was unsafe...

1.04 (4-Feb-2007)

  1. Fixed the problem where when using half size BB increments I was rounding the value to 1dp (no need to do this, as always gonna be whole number if only ever playing SNGs...).

1.05 (6-Mar-2007)

  1. Added a nice GUI to make setting the settings much easier.

  2. Merged the code with the old beta "Empire-Lobby-Filter" AHK script as is also useful on Party.

  3. Have tried to further bullet-proof the table opening code, but still not 100% sure it will work.

  4. Have added a button to hide the lobby and another to show the lobby. This is useful when we just want to use our own listview and/or the F10/F11 hotkeys for joining SNGs and the lobby is not needed.

1.06 (14-Mar-2007)

  1. Now have two different versions of Open Table(). One works fine on Empire and is fast but won't work always on Party. The other works fine on Party, but is very slow to open tables if the list isn't filtered (Both seem to work fine now even if the lobby is hidden using the hide button).

  2. Have made it so that the fold and push commands will only be send when the mouse button is released. This give you a chance to cancel by moving the mouse off the tables (like you can with the button clicks).

1.07 (19-Mar-2007)

  1. Have removed all critical section in the code as they seem to cause an unexplained deadlock occationally. Re-checked the code and there should be no reason for this as all code paths release them... Seems that the sections like Open Tables, etc seem to work fine anyway (better than a deadlock anyway...).

  2. Have made it so that you have to uncomment a line to use "act on mouse release" now, as it can be unsafe at times of high CPU usage and cause folds/pushes on other tables by accident (default = off now).

1.08 (22-Mar-2007)

  1. Have added 3 pixels to the list-box width to correct for change after update.

  2. Have fixed the problem where autobet and increment_half_bb were not being set properly from the GUI.

  3. Have fixed the problem from the latest update which caused numbers with commas in to mess up (eg: "1,000").

1.09 (8-May-2007)

  1. Have set the priority for the Push and Check/Fold hotkeys to be higher and have gone back to using "action on release" as should be safe with higher priority now.

  2. Have made it so that the timer bank clicker thread is higher priority than all but the important hotkeys.

  3. Have made it so "Auto-Request summary" also gets rid of the "You are the champion..." popup.

1.10 (8-May-2007)

  1. Changed the string to match the "would you like to join another SNG..." pop-up so it now closes ones where you didn't win also.

1.11 (19-Aug-2007)

  1. Have fixed the "Would you like to play in another Sit & Go" dialog closer.

  2. Have made it so that if we press push and there is no raise button, we now will click on "All-In" instead.

1.11b (21-Aug-2007) - imrovements by fenixguy (FenixOnTilt)

  1. Changed the string to match the "would you like to join another SNG..." pop-up once more, because the ampersand caused some problems.

  2. Reworked the "Auto-Request Summary" Checkbox so that it now actually does what it says and clicks YES or NO depending on your choice. Works only if "Auto-Close Bustout Popups" is activated.

  3. Added an "Auto-Close Bustout Popups" Checkbox to take over the function the Summary Button did before.

  4. Added an "Auto-Close Finished SNGs" Checkbox which actually closes every active Party Poker table you don't sit at. (Yet to be tested on Empire)

1.12 (21-Aug-2007)

  1. Have made it so that the scroll wheel should also work for european style decimal seperators (eg: 1,000 and 1.000).

  2. Have made it so that we no longer open tables with 9 players allready seated as they are usually just filling as we sit and we have to close them.

  3. Have fixed problem with setting the "Request Summary" checkbox (should work now).

1.13 (22-Sep-2007)

  1. Have made it so that we no longer open tables with 9 players allready seated as they are usually just filling as we sit and we have to close them. (redone).

  2. Have made it so we deafult to using the table closer now (seems 100% safe).

  3. Have made it so that we deafult to not having summaries sent by email now.

  4. Have added in a thread to press the "I am Back" button whenever it sees it (useful for crash recovery and time-outs).

  5. Have added a special "Kill and restart" hotkey: use control+alt+F11 for Empire and control+alt+F12 for Party

  6. Have made it so that we can now use the scroll wheel in MTTs too.

  7. Have added an option to enable/disable the use of mouse hotkeys (MMB push, scrollwheel inc/dec and RMB fold).

  8. Have made it so that "Auto Bet" and "Increment 1/2 BB" option get shosted if mouse hotkets disabled.

  9. Have added the ability to reset the lobby to (0,0) to fix the "mini-lobby bug" from within this script too.

1.14 (8-Nov-2007)

  1. Fixed the bug where the scroll wheel would stop working because of the "value added" popup.

1.15 (20-Nov-2007)

  1. Have added an option to get rid of the chat-realted stuff.

  2. Have added an option to get rid of the 3 pointless buttons from the bottom right corner.

  3. Have fixed a tiny slowdown bug in the automatic pressing of "I am Back" button where we kept returning uneccessarily.

  4. Have altered the UI to work look slightly better and work better with non-Win98 style windows.

1.15a (27-Jan-2008) - imrovements by chris228:

  1. Have added an option in the UI to switch between european and us style decimal seperators.

  2. Have added SingleInstance, Force to the script

1.15b (27-Jan-2008) - imrovements by chris228:

  1. Fixed a problem, if amounts contains a space (e.g. used to seperate thousends in Norway)

1.16 (28-Mar-2008)

  1. Have tidied up the code a bit to make it easier for people to see where to change the default settings and timings.

  2. Have added the ability to auto-change to 16bit colour when using the script.

  3. Have fixed some problems introduced in the 28/03/08 update: Static control for reading the blinds is now Static5 (was Static6 before) and Editbox for entering bet amounts is now Edit2 (was Edit3 before).

  4. Have merged the code to remove spaces in a number.

1.16b (28-Mar-2008)

  1. Have fixed the problem with the auto-timebank clicker not working after 28/03/08 update.

  2. Have fixed a bug introduced in v1.16 where we wern't removing spaces from numbers properly.

  3. Have re-written the ato-close finished SNGs function to use a loop so it can close all windows at the same time now.

1.17 (01-Sep-2008)

  1. Have reverted the "Auto Close Finished" procedure to use the old code as it seemed to work much more safely.

  2. Have increased the priority of the press "I am back" code so as to sit back ASAP now.

  3. Have increased the priority of the scroll wheel handler as sometimes could "stall" while busy with other stuff.

  4. Have re-arrange the controls on the GUI to accomodate the "Auto-Hide MTT Popups" option and seperate "Auto-Update Speed SNG List".

1.18 (23-Sep-2008)

  1. Have merged the table opener code so we now use the old Empire opener for both now. The old Party-specific method would be far too slow and error prone now that we have so many things in the list... To open tables from the filtered list you *MUST* have exactly the same column headers in as the classic list view.

  2. Have added some rudamentary filtering capabilty to allow us to filter the listbox to display certain limits only. Very hacky and required editing of the code atm - add somthing to the GUI later...

  3. Had to replace all "Buy-in." with "Buy-in" - this fixed most problems (timebank, chatbox hider, buttons hider, etc).

  4. Had to change "This Hand" to "This hand" and "Auto Post Blind" to "Auto-post blind" to get the table closer function to work.

1.18b (23-Sep-2008)

  1. Have fixed the Hide/Show/Reset buttons to now resize the lobby to the correct dimmensions (the new lobby is not the same as the old).

  2. Have made it so that "Auto-Hide 'Pointless' Buttons" option also hides the "New table" button displayed at the top of each table.

1.18c (24-Sep-2008)

  1. Fixed a small problem whereby "Auto-Buyin" and "Auto-Close-Non-NL-SpeedSNGs" would not work properly together.

1.18d (05-Jan-2009)

  1. Fixed the "deadlock" problem when opening tables with F11 by adding a 3 second timeout to all WinWaitActive calls.

1.18e (05-Jan-2009)

  1. Have removed the ghosted "remove MTT popups" option, as it looks like we will never find an AHK method round these.

  2. Have added a "Quick-Leave Non-Started SNGs" option that saves you from pressing OK on the dialog box when you want to exit a SNG that hasn't started yet. This should be used carefully, especially if there are allready 9 players seated...

  3. Have made it so that the push() fucntion now double checks that the bet-amount edit box has actaully been changed and if it hasn't then it's redoes it (this is done to fix the occational times it min-raises instead of pushes all-in...).

  4. We now make sure that the "raise" button gets the focus before it gets clicked (2p2er "sence" reported that sometimes it would fail to click the button for him - this may have been the reason...).

  5. Have improved the FocusLooby() procedure so as to make sure the table list get focus before we do anything else.

  6. Have increased the priority of the middle mouse button hotkey to try to fix the "minraise bug".

Download

PartySNGHelper_1_18e.ahk

Code

;-----------------------------------------------------------
;----------------- Party SNG Helper v1.18e -----------------
;-----------------------------------------------------------
; AutoHotkey Version: 1.x
; Language:         English
; Platform:         Win9x/NT
; Original Author:  jukofyork (reused code and thanks to: _dave_, Roland and HighSteaks!)
; Improvements:     fenixguy (FenixOnTilt) added v1.11b improvements.

; Features:
; =========
; 1. Push with/without AutoBet using middle mouse mutton.
; 2. Check or fold (ie: check if we can, else fold) using right mouse button.
; 3. Scroll wheel moved bet amount up/down in big bets.
; 4. Auto-confirm and check the buying box so all that will be needed is to click on an empty seat to join a SNG.
; 5. Auto-timebank clicker.
; 6. Auto-confirm the "Would you like a summary sent" box after being knocked out of a SNG.

; New for v1.01:
; ==============
; 1. Now will click Check/Fold checkbox if visible.
; 2. Pressing F12 over a player's name will simulate a right mouse click so we can takes notes, etc.
; 3. Have made it so that AlterAmount amount can take another argument to increment in 0.5BB amounts.
; 4. Have made it so we will close finished SNGs.
; 5. Have changed the timings to be 1000ms rather than 500ms to try to save on CPU time.

; New for v1.02:
; ==============
; 1. Have tried to make the finished SNG closer work more stably by trying for 5 times over 2.5 seconds
;    and testing if each time agrees.

; New for v1.03:
; ==============
; 1. Have removed the code which closed the finished SNGs - wasn't working properly and was unsafe...

; New for v1.04:
; ==============
; 1. Fixed the problem where when using half size BB increments I was rounding the value to 1dp (no
;    need to do this, as always gonna be whole number if only ever playing SNGs...).

; New for v1.05:
; ==============
; 1. Added a nice GUI to make setting the settings much easier.
; 2. Merged the code with the old EmpireLobbyFilter AHK script as is also useful on Party.
; 3. Have tried to further bullet-proof the table opening code, but still not 100% sure it will work.
; 4. Have added a button to hide the lobby and another to show the lobby. This is useful when we just want
;    to use our own listview and/or the F10/F11 hotkeys for joining SNGs and the lobby is not needed.

; New for v1.06:
; ==============
; 1. Now have two different versions of OpenTable(). One works fine on Empire and is fast but won't work always on
;    Party. The other works fine on Party, but is very slow to open tables if the list isn't filtered.
;    - Both seem to work fine now even if the lobby is hidden using the hide button.
; 2. Have made it so that the fold and push commands will only be send when the mouse button is released. This
;    give you a chance to cancel by moving the mouse off the tables (like you can with the button clicks).

; New for v1.07:
; ==============
; 1. Have removed all critical section in the code as they seem to cause an unexplained deadlock occationally.
;    - Re-checked the code and there should be no reason for this as all code paths release them...
;    - Seems that the sections like OpenTables, etc seem to work fine anyway (better than a deadlock anyway...).
; 2. Have made it so that you have to uncomment a line to use "act on mouse release" now, as it can be unsafe
;    at times of high CPU usage and cause folds/pushes on other tables by accident (default = off now).

; New for v1.08:
; ==============
; 1. Have added 3 pixels to the list-box width to correct for change after update.
; 2. Have fixed the problem where AutoBet and IncrementHalfBigBet were not being set properly from the GUI.
; 3. Have fixed the problem from the latest update which caused numbers with commas in to mess up (eg: "1,000").

; New for v1.09:
; ==============
; 1. Have set the priority for the Push and Check/Fold hotkeys to be higher and have gone back to using
;    "action on release" as should be safe with higher priority now.
; 2. Have made it so that the timer bank clicker thread is higher priority than all but the important hotkeys.
; 3. Have made it so "Auto-Request summary" also gets rid of the "You are the champion..." popup.

; New for v1.10:
; ==============
; 1. Changed the string to match the "would you like to join another SNG..." pop-up so it now closes ones where
;    you didn't win also.

; New for v1.11:
; ==============
; 1. Have fixed the "Would you like to play in another Sit & Go" dialog closer.
; 2. Have made it so that if we press push and there is no raise button, we now will click on "All-In" instead.

; New for v1.11b - imrovements by fenixguy (FenixOnTilt):
; =======================================================
; 1. Changed the string to match the "would you like to join another SNG..." pop-up once more, because the ampersand caused some problems.
; 2. Reworked the "Auto-Request Summary" Checkbox so that it now actually does what it says and clicks YES or NO depending on your choice
;    Works only if "Auto-Close Bustout Popups" is activated.
; 3. Added an "Auto-Close Bustout Popups" Checkbox to take over the function the Summary Button did before.
; 4. Added an "Auto-Close Finished SNGs" Checkbox which actually closes every active PartyPoker table you don't sit at. (Yet to be tested on Empire)

; New for 1.12:
; =============
; 1. Have made it so that the scroll wheel should also work for european style decimal seperators (eg: 1,000 and 1.000).
; 2. Have made it so that we no longer open tables with 9 players allready seated as they are usually just filling as we sit and we have to close them.
; 3. Have fixed problem with setting the RequestSummary checkbox (should work now).

; New for 1.13:
; =============
; 1. Have made it so that we no longer open tables with 9 players allready seated as they are usually just filling as we sit and we have to close them. (redone).
; 2. Have made it so we deafult to using the table closer now (seems 100% safe).
; 3. Have made it so that we deafult to not having summaries sent by email now.
; 4. Have added in a thread to press the "I am Back" button whenever it sees it (useful for crash recovery and time-outs).
; 5. Have added a special "Kill and restart" hotkey: use control+alt+F11 for Empire and control+alt+F12 for Party
; 6. Have made it so that we can now use the scroll wheel in MTTs too.
; 7. Have added an option to enable/disable the use of mouse hotkeys (MMB push, scrollwheel inc/dec and RMB fold).
; 8. Have made it so that "AutoBet" and "Increment 1/2 BB" option get shosted if mouse hotkets disabled.
; 9. Have added the ability to reset the lobby to (0,0) to fix the "mini-lobby bug" from within this script too.

; New for 1.14:
; =============
; 1. Fixed the bug where the scroll wheel would stop working because of the "value added" popup.


; New for 1.15:
; =============
; 1. Have added an option to get rid of the chat-realted stuff.
; 2. Have added an option to get rid of the 3 pointless buttons from the bottom right corner.
; 3. Have fixed a tiny slowdown bug in the automatic pressing of "I am Back" button where we kept
;    returning uneccessarily.
; 4. Have altered the UI to work look slightly better and work better with non-Win98 style windows by
;    putting the listbox below the other options.

; New for 1.16:
; =============
; 1. Have tidied up the code a bit to make it easier for people to see where to change the default settings and timings.
; 2. Have added the ability to auto-change to 16bit colour when using the script.
; 3. Have fixed some problems introduced in the 28/03/08 update:
;    - Static control for reading the blinds is now Static5 (was Static6 before).
;    - Editbox for entering bet amounts is now Edit2 (was Edit3 before).
; 4. Have merged the code to remove spaces in a number.

; New for 1.16b:
; ==============
; 1. Have fixed the problem with the auto-timebank clicker not working after 28/03/08 update.
; 2. Have fixed a bug introduced in v1.16 where we wern't removing spaces from numbers properly.
; 3. Have re-written the ato-close finished SNGs function to use a loop so it can close all windows at the same time now.

; New for 1.17:
; =============
; 1. Have reverted the AutoCloseFinished procedure to use the old code as it seemed to work much more safely.
; 2. Have increased the priority of the press "I am back" code so as to sit back ASAP now.
; 3. Have increased the priority of the scroll wheel handler as sometimes could "stall" while busy with other stuff.
; 4. Have re-arrange the controls on the GUI to accomodate the "Auto-Hide MTT Popups" option and seperate "Auto-Update Speed SNG List".

; New for 1.18:
; =============
; 1. Have merged the table opener code so we now use the old Empire opener for both now.
;    - The old Party-specific method would be far too slow and error prone now that we have so many things in the list...
;    - To open tables from the filtered list you *MUST* have exactly the same column headers in as the classic list view.
; 2. Have added some rudamentary filtering capabilty to allow us to filter the listbox to display certain limits only.
;    - Very hacky and required editing of the code atm - add somthing to the GUI later...
; 3. Had to replace all "Buy-in." with "Buy-in" - this fixed most problems (timebank, chatboc hider, buttons hider, etc).
; 4. Had to change "This Hand" to "This hand" and "Auto Post Blind" to "Auto-post blind" to get the table closer function to work.
; 

; New for 1.18b:
; ==============
; 1. Have fixed the Hide/Show/Reset buttons to now resize the lobby to the correct dimmensions (the new lobby is not the same as the old).
; 2. Have made it so that "Auto-Hide 'Pointless' Buttons" option also hides the "New table" button displayed at the top of each table.

; New for 1.18c:
; ==============
; 1. Fixed a small problem whereby "Auto-Buyin" and "Auto-Close-Non-NL-SpeedSNGs" would not work properly together.

; New for 1.18d:
; ==============
; 1. Fixed the "deadlock" problem when opening tables with F11 by adding a 3 second timeout to all WinWaitActive calls.

; New for 1.18e:
; ==============
; 1. Have removed the ghosted "remove MTT popups" option, as it looks like we will never find an AHK method round these.
; 2. Have added a "Quick-Leave Non-Started SNGs" option that saves you from pressing OK on the dialog box when you want to exit
;    a SNG that hasn't started yet. This should be used carefully, especially if there are allready 9 players seated...
; 3. Have made it so that the push() fucntion now double checks that the bet-amount edit box has actaully been changed and if
;    it hasn't then it's redoes it (this is done to fix the occational times it min-raises instead of pushes all-in...).
; 4. We now make sure that the "raise" button gets the focus before it gets clicked (2p2er "sence" reported that sometimes it would
;    fail to click the button for him - this may have been the reason...).
; 5. Have improved the FocusLooby() procedure so as to make sure the table list get focus before we do anything else.
; 6. Have increased the priority of the middle mouse button hotkey to try to fix the "minraise bug".

#Persistent
#SingleInstance, Force
#NoEnv

SendMode Input

DetectHiddenText, off

SetTitleMatchMode 2

; For BPP reset purposes.
OnExit, ExitSub

; Add the first group of controls.
Gui, Add, GroupBox, x10 y-2 w358 h52
Gui, Add, Checkbox, vEnableMouseShortcuts gEnableMouseShortcuts x15 y10, Enable Mouse Shortcuts
Gui, Add, Button, vHideLobbyBtn gHideLobbyBtn x15 y27 w44 h17, Hide
Gui, Add, Button, vShowLobbyBtn gShowLobbyBtn x63 y27 w44 h17, Show
Gui, Add, Button, vResetLobbyBtn gResetLobbyBtn x111 y27 w44 h17, Reset
Gui, Add, Checkbox, vAutoBet gAutoBet x163 y10, Auto-Bet
Gui, Add, Checkbox, vBuyin gBuyin x163 y30, Auto-Buyin
Gui, Add, Checkbox, vIncrementHalfBigBet gIncrementHalfBigBet x241 y10, Increment Half BBs 
Gui, Add, Checkbox, vClickTimeBank gClickTimeBank x241 y30, Auto-Click Time Bank

; Add the second group of controls.
Gui, Add, GroupBox, x10 y48 w358 h90
Gui, Add, Checkbox, vCloseFinished gCloseFinished x15 y60, Auto-Close Finished SNGs
Gui, Add, Checkbox, vCloseNonNLSpeeds gCloseNonNLSpeeds x183 y60, Auto-Close Non-NL-Speed SNGs
Gui, Add, Checkbox, vQuickLeaveTable gQuickLeaveTable x183 y80, Quick-Leave Non-Started SNGs
Gui, Add, Checkbox, vPressIAmBack gPressIAmBack x15 y80, Auto-Click "I am Back" Button
Gui, Add, Checkbox, vClosePopups gClosePopups x15 y100, Auto-Close Bustout Popups
Gui, Add, Checkbox, vRequestSummary gRequestSummary x183 y100, Auto-Request Summary (via email)
Gui, Add, Checkbox, vHideChat gHideChat x15 y120, Auto-Hide Chat Boxes
Gui, Add, Checkbox, vHideButtons gHideButtons x183 y120, Auto-Hide "Pointless" Buttons

; Add the second group of controls.
Gui, Add, GroupBox, x10 y136 w358 h29
Gui, Add, Checkbox, vUpadteSNGList gUpadteSNGList x15 y147, Auto-Update Speed SNG List  (can cause slowdowns - use with care)

; Add the Speed-SNG-specific listbox.
Gui, Add, ListView, r4 w359 x10 y169 gMyListView, ID|Name|Game|Buy-in|Plrs/Sts|Status

; Set to "always on top" and change the title to include the version number.
Gui +AlwaysOnTop
Gui, Show, , PartySNGHelper v1.18e

;Get this script's PID and set our own priority (thanks to _dave_ for this!).
pid := DllCall("GetCurrentProcessId")
Process, Priority, %pid%, AboveNormal

; ####################################################################################################################
; ############ CHANGE THESE VALUES TO MAKE THE SCRIPT START UP WITH DIFFERENT DEFAULT/START-UP SETTINGS! #############
; ####################################################################################################################
GuiControl, , AutoBet,              1 ; Do we want to actually hit raise after we set the edit box to all-in?        #
GuiControl, , IncrementHalfBigBet,  1 ; Set this to use 0.5BB increments with the scroll wheel, rather than 1BB.     #
GuiControl, , ClickTimeBank,        1 ; This will auto-click the timebank button for you when it sees it.            #
GuiControl, , Buyin,                1 ; This will let you just click on a empty seat to join a SNG.                  #
GuiControl, , RequestSummary,       0 ; This will auto-request a summary when it see the dialog at the end of a SNG. #
GuiControl, , UpadteSNGList,        0 ; This will auto-update the SNG list (lots of CPU used - F10/F11 better...).   #
GuiControl, , CloseNonNLSpeeds,     0 ; This will close any non-NL/non-Speed SNG opened by accident.                 #
GuiControl, , CloseFinished,        1 ; This will auto-close every running SNG you are not sitting in                #
GuiControl, , ClosePopups,          1 ; This will auto-close the "Play another" and "Summary" Popups                 #
GuiControl, , PressIAmBack,         1 ; This will auto-click the "I am Back" button.                                 #
GuiControl, , EnableMouseShortcuts, 1 ; This will turn on the mouse shortcuts.                                       #
GuiControl, , HideChat,             0 ; This will turn off chat hiding.                                              #
GuiControl, , HideButtons,          0 ; This will turn off pointless button hiding.                                  #
GuiControl, , QuickLeaveTable,      0 ; This will let you quickly get upo from a SNG that hasn't started yet.
; ------------------------------------------------------------------------------------------------------------------ #
AutoSwitch16bitColour :=            0 ; Set this to 1 to have the client automatically switch to using 16bit colour. #
; ####################################################################################################################

; Set the BPP to 16bit colour, as Party seems to work better using it.
if (AutoSwitch16bitColour = 1)
  SetBPP(16)

; Start the timers (depends on the default checkbox setting as to if they start or not).
GoSub, AutoBet
GoSub, IncrementHalfBigBet
SetTimer, AutoClickTimeBank,     1000, ,1 ; Higher priority so as not to lag and miss the timebank...
GoSub, ClickTimeBank
SetTimer, AutoBuyin,             500
GoSub, Buyin
SetTimer, AutoUpdateSNGList,     5000
GoSub, UpadteSNGList
SetTimer, AutoCloseNonNLSpeeds,  1000
GoSub, CloseNonNLSpeeds
SetTimer, AutoCloseFinished,     1000
GoSub, CloseFinished
SetTimer, AutoClosePopups,       500
GoSub, ClosePopups
SetTimer, AutoSitBackIn,         500, ,1 ; Higher priority so as to sit back ASAP.
GoSub, PressIAmBack
SetTimer, AutoHideChat,          1000
GoSub, HideChat
SetTimer, AutoHideButtons,       1000
GoSub, HideButtons
SetTimer, AutoQuickLeaveTable,   500
GoSub, QuickLeaveTable


; Set the priority of the important hotkeys.
Hotkey, ~RButton, , P2
Hotkey, ~MButton, , P3          ; This should be higher than the wheel priorities.
Hotkey, ~WheelUp, , P2
Hotkey, ~WheelDown, , P2

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Pressing F10 will manually update the SNG list.
F10::
  gosub, FocusLooby
  gosub, AutoUpdateSNGList
return

; ---------------------------------------------------------------------------------------------------------------

; Pressing F11 will manually update the SNG list *AND* open the first SNG in the list.
F11::
  gosub, FocusLooby
  gosub, AutoUpdateSNGList
  Sleep, 500                 ; v1.18e: To give the list time to update.
  LV_GetText(TableName,1,1)
  if (TableName <> "")
  {
    OpenTable(TableName)
  }
return

; ---------------------------------------------------------------------------------------------------------------

; Pressing F12 simulates a right mouse click over a player's name (so we can take notes and still use RMB for check/fold).
F12::
id := ""
MouseGetPos, x, y, id
if (id <> "")
  PostRightClick(x, y, id)
return

; ---------------------------------------------------------------------------------------------------------------

; Pressing control+alt+F11 will make the Empire client restart.
^!F11::
  Process, Close, EmpirePokerMaster.exe
  Process, WaitClose, EmpirePokerMaster.exe
  Sleep, 1
  Process, WaitClose, EmpirePokerMaster.exe
  Sleep, 1
  run, C:\Program Files\EmpirePokerMaster\EmpirePoker\RunEPoker.exe
return

; ---------------------------------------------------------------------------------------------------------------

; Pressing control+alt+F12 will make the Party client restart.
^!F12::
  Process, Close, partygaming.exe
  Process, WaitClose, partygaming.exe
  Sleep, 1
  Process, WaitClose, partygaming.exe
  Sleep, 1
  run, C:\Program Files\PartyGaming\PartyPoker\RunApp.exe
return

; ---------------------------------------------------------------------------------------------------------------

; Right mouse click = check/fold.
~RButton::
if (EnableMouseShortcuts)
  CheckFold(getid())
return

; ---------------------------------------------------------------------------------------------------------------

; Middle mouse click = push all-in.
~MButton::
if (EnableMouseShortcuts)
  Push(getid(),AutoBet)
return

; ---------------------------------------------------------------------------------------------------------------

; Mouse-wheel up = Increment bet amount.
~WheelUp::
if (EnableMouseShortcuts)
  AlterAmount(getid(),"up",IncrementHalfBigBet)
return

; ---------------------------------------------------------------------------------------------------------------

; Mouse-wheel down = Decrement bet amount.
~WheelDown::
if (EnableMouseShortcuts)
  AlterAmount(getid(),"down",IncrementHalfBigBet)
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

AutoBet:
  Gui, Submit, NoHide
return

; ---------------------------------------------------------------------------------------------------------------

IncrementHalfBigBet:
  Gui, Submit, NoHide
return

; ---------------------------------------------------------------------------------------------------------------

RequestSummary:
  Gui, Submit, NoHide
return

; ---------------------------------------------------------------------------------------------------------------

UpadteSNGList:
  Gui, Submit, NoHide
  if (UpadteSNGList)
    SetTimer, AutoUpdateSNGList, On
  else
    SetTimer, AutoUpdateSNGList, Off
return

; ---------------------------------------------------------------------------------------------------------------

CloseNonNLSpeeds:
  Gui, Submit, NoHide
  if (CloseNonNLSpeeds)
    SetTimer, AutoCloseNonNLSpeeds, On
  else
    SetTimer, AutoCloseNonNLSpeeds, Off
return


; ---------------------------------------------------------------------------------------------------------------

ClickTimeBank:
  Gui, Submit, NoHide
  if (ClickTimeBank)
    SetTimer, AutoClickTimeBank, On
  else
    SetTimer, AutoClickTimeBank, Off
return


; ---------------------------------------------------------------------------------------------------------------

Buyin:
  Gui, Submit, NoHide
  if (Buyin)
    SetTimer, AutoBuyin, On
  else
    SetTimer, AutoBuyin, Off
return


; ---------------------------------------------------------------------------------------------------------------

CloseFinished:
  Gui, Submit, NoHide
  if (CloseFinished)
    SetTimer, AutoCloseFinished, On
  else
    SetTimer, AutoCloseFinished, Off
return

; ---------------------------------------------------------------------------------------------------------------

HideChat:
  Gui, Submit, NoHide
  if (HideChat)
    SetTimer, AutoHideChat, On
  else
    SetTimer, AutoHideChat, Off
return

; ---------------------------------------------------------------------------------------------------------------

HideButtons:
  Gui, Submit, NoHide
  if (HideButtons)
    SetTimer, AutoHideButtons, On
  else
    SetTimer, AutoHideButtons, Off
return

; ---------------------------------------------------------------------------------------------------------------

QuickLeaveTable:
  Gui, Submit, NoHide
  if (QuickLeaveTable)
    SetTimer, AutoQuickLeaveTable, On
  else
    SetTimer, AutoQuickLeaveTable, Off
return

; ---------------------------------------------------------------------------------------------------------------

ClosePopups:
  Gui, Submit, NoHide
  if (ClosePopups)
  {
    SetTimer, AutoClosePopups, On
    GuiControl, Enable, RequestSummary
  }
  else
  {
    SetTimer, AutoClosePopups, Off
    GuiControl, Disable, RequestSummary
  }
return

; ---------------------------------------------------------------------------------------------------------------

PressIAmBack:
  Gui, Submit, NoHide
  if (PressIAmBack)
    SetTimer, AutoSitBackIn, On
  else
    SetTimer, AutoSitBackIn, Off
return

; ---------------------------------------------------------------------------------------------------------------

EnableMouseShortcuts:
  Gui, Submit, NoHide
  if (EnableMouseShortcuts)
  {
    GuiControl, Enable, AutoBet
    GuiControl, Enable, IncrementHalfBigBet
  }
  else
  {
    GuiControl, Disable, AutoBet
    GuiControl, Disable, IncrementHalfBigBet
  }

return

; ---------------------------------------------------------------------------------------------------------------

HideLobbyBtn:
  SetTitleMatchMode, 2
  WinMove, Poker Lobby, , , , 1, 1
return

; ---------------------------------------------------------------------------------------------------------------

ShowLobbyBtn:
  SetTitleMatchMode, 2
  WinMove, Poker Lobby, , , , 791, 558
return

; ---------------------------------------------------------------------------------------------------------------

; Reset the Party lobby to top left and correct dimentions.
ResetLobbyBtn:
  SetTitleMatchMode, 2
  WinMove, Poker Lobby, , 0, 0, 791, 558
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


AutoClickTimeBank:

  checkfield = AfxWnd42u34 ; AfxWnd42u34 is timebank control
  LobbyWindowTitle = Poker Lobby ; identify poker lobby substring
  TableWindowTitle = Buy-in ; identify pokertable substring

  WinGet, lobbyID, ID, %LobbyWindowTitle%

  WinGet, pid, PID, ahk_id%lobbyID%
  WinGet, rlist, LIST, %TableWindowTitle% ahk_pid%pid%
  Loop %rlist%
  {
    this_id := rlist%a_index%
    If this_id != %lobbyID%
    {
      WinGetTitle, name, ahk_id%this_id%
      ControlGet, result, Visible, , %checkfield%, ahk_id%this_id%
      if (result)
      {
        ControlClick %checkfield%, ahk_id%this_id% ;Click timebank
      }
    }
  }

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

AutoBuyin:

  IfWinExist, ahk_class #32770, Tournament Buy-in
  {
    WinGet, idList, List, ahk_class #32770, Tournament Buy-in
    Loop, %idList%
    {
      winID := idList%a_index%
      ControlSend, Button2, {SPACE}, ahk_id%winID%
      Sleep, 40
      ControlSend, Button5, {SPACE}, ahk_id%winID%
    }
  }

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

AutoClosePopups:
  
  IfWinExist, ahk_class #32770, Would you like a tournament summary
  {
    WinGet, idList, List, ahk_class #32770, Would you like a tournament summary 
    Loop, %idList%
    {
      winID := idList%a_index%
      if (RequestSummary)                                    ; Request Summary if activated
        ControlSend, Button1, {ENTER}, ahk_id%winID%
      else
        ControlSend, Button2, {ESC}, ahk_id%winID%
    }
  }

  ; Lets get rid of the champion of the tournament window.
  IfWinExist, ahk_class #32770, Would you like to play in another Sit
  {
    WinGet, idList, List, ahk_class #32770, Would you like to play in another Sit
     Loop, %idList%
     {
      winID := idList%a_index%
      ControlSend, Button2, {ESC}, ahk_id%winID% ; Click NO always.
     }
   }

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

MyListView:
if A_GuiEvent = DoubleClick
{
  ;___ A_EventInfo contains the focused row number; insert the correct comlumn number 
  LV_GetText(TableName, A_EventInfo, 1)
  if (TableName <> "")
    OpenTable(TableName)
}
return

GuiClose:  ; Indicate that the script should exit automatically when the window is closed.
ExitApp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

getid()
{
  id := ""
  MouseGetPos, , , id
  return id
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

PostRightClick(x, y, table_id, activate=1) {
; ### JUK: Send the down left click, then the mouse-up messages.
; NOTE: This is relative to the top left of the client area and NOT the top left of the
;       window (ie: It *doesn't* include the title-bar like AHK's MouseClick does!!!).
If activate
 WinActivate, ahk_id%table_id%
PostMessage, 0x204, 0x0001, ((y<<16)^x), , ahk_id%table_id%
PostMessage, 0x205 , 0, ((y<<16)^x), , ahk_id%table_id%
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; This will set the edit box to the maximum amount.
; - v1.18e: Have tried to make this fucntion more relyable, as the recent update seems to have made it occationally
;           make min-raises and also 2p2er "sense" reported that it would occationally not press the raise button for him.
Push(id, AutoBet=0)
{
    ; v1.18e: Lets get the current value that is stored in the box (see below).
    ControlGetText, BeforeText, Edit2, ahk_id%id%

    ; Lets set the box to a really big "all-in" value.
    ControlSetText, Edit2, 10000000, ahk_id%id%
    Sleep -1
    Sleep 50
    WinSet, Redraw,, ahk_id%id%

    ; v1.18e: Has the value actaully changed (this is done to try to avoid the strange min-raises we sometimes get)?
    ControlGetText, AfterText, Edit2, ahk_id%id%
    if (BeforeText = AfterText)
    {
      Sleep 100
      ControlSetText, Edit2, 10000000, ahk_id%id%
      Sleep -1
      Sleep 50
      WinSet, Redraw,, ahk_id%id%
    }

    ; Do we want to press the raise button too?
    If(AutoBet)
    {

      ; Lets see if we can see the "All-In" button.
      ControlGet, v, Visible, , AfxWnd42u18, ahk_id%id%
      if (v)
      {
        ControlGetText, text, AfxWnd42u18, ahk_id%id%
        IfInString, text, All-In
        {
          ControlFocus, AfxWnd42u18, ahk_id%id%
          Sleep, -1
          ControlClick, AfxWnd42u18, ahk_id%id%
          return
        }
      }

      ; Click raise instead then.
      ControlFocus, AfxWnd42u19, ahk_id%id%
      Sleep, -1
      ControlClick, AfxWnd42u19, ahk_id%id% ; Raise.

    }
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Clicks Check/Fold-in-turn or fold-in-turn button if sees it, else clicks check if sees 
; it, else clicks fold.
CheckFold(id)
{

  ; Check/Fold checkbox.
  ControlGet, v, Visible, , AfxWnd42u23, ahk_id%id%
  if (v)
  {
    ControlFocus, AfxWnd42u23, ahk_id%id%
    Sleep, -1
    ControlClick, AfxWnd42u23, ahk_id%id%
    return
  }

  ; Fold checkbox.
  ControlGet, v, Visible, , AfxWnd42u22, ahk_id%id%
  if (v)
  {
    ControlFocus, AfxWnd42u22, ahk_id%id%
    Sleep, -1
    ControlClick, AfxWnd42u22, ahk_id%id%
    return
  }

  ; Lets see if we can see the check button.
  ControlGet, v, Visible, , AfxWnd42u18, ahk_id%id%
  if (v)
  {
    ControlGetText, text, AfxWnd42u18, ahk_id%id%
    IfInString, text, Check
    {
      ControlFocus, AfxWnd42u18, ahk_id%id%
      Sleep, -1
      ControlClick, AfxWnd42u18, ahk_id%id%
      return
    }
  }

  ; Lets try for fold then.
  ControlGet, v, Visible, , AfxWnd42u17, ahk_id%id%
  if (v)
  {
    ControlFocus, AfxWnd42u17, ahk_id%id%
    Sleep, -1
    ControlClick, AfxWnd42u17, ahk_id%id%
  }

}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Removes any comma in number and returns the result.
; ### JUK: Now tries to remove any european style decimal seperators too.
RemoveCommaInNumber(n)
{
  ; This should remove any spaces in the number.
  StringReplace, n, n, %A_Space%,, All

  If (InStr(n, ".") <> 0)
  {
    n := n*1000
  }
  If (InStr(n, ",") <> 0)
  {
    StringReplace, n, n, `,, .
    n := n*1000
  }
  return n
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

AlterAmount(id, dir="",IncrementHalfBigBet=1)
{
  WinGetTitle, title, ahk_id%id%
  amount := 0

  ; Get the current BB amount.
  if (InStr(title, "NL") <> 0 AND (InStr(title, "Buy-in") <> 0 OR InStr(title, "Table #") <> 0))
  {

    ; ### Fixed the problem where empire stopped working sometimes. ###
    ControlGetText, text, Static5, ahk_id%id%
    IfNotInString, text, Blinds
      ControlGetText, text, Static6, ahk_id%id%
    IfNotInString, text, Blinds
      ControlGetText, text, Static7, ahk_id%id%
    ; msgbox, %text%

    IfNotInString, text, Blinds-Antes
    {
      StringMid, bb, text, InStr(text, "/") + 1, InStr(text, ")") - InStr(text, "/") - 1
    }
    else
    {
      StringMid, bb, text, InStr(text, "/") + 1, InStr(text, "-","",InStr(text, "/")) - InStr(text, "/") - 1
    }
    bb := RemoveCommaInNumber(bb)
    ; msgbox, %bb%
  }

  ; Do we want to increment by a whole or a half BB?
  if (IncrementHalfBigBet = 1)
    amount := bb / 2
  else
    amount := bb

  if (dir="down")
  {
    amount := amount - (2*amount)
  }

  ; Get the text and turn back into a number without commas (eg: 1,000 -> 1000).
  ControlGetText, t, Edit2, ahk_id%id%
  t := RemoveCommaInNumber(t)
  ;msgbox, %t%

  t := t + amount
  if (t < 0)
  {
    t := 0
  }

  ; Lets round to 0dp.
  t := Round(t, 0)
  
  ; Alter the edit-box.
  ControlSetText, Edit2, %t%, ahk_id%id%
  ;WinSet, Redraw,, ahk_id%id%

}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

OpenTable(TableName)
{
  ; Lets see if the Party lobby is up?
  WinGet, lobby_id, ID, PartyPoker.com: Poker Lobby

  ; Lets try and get the Empire lobby then.
  if (not lobby_id)
    WinGet, lobby_id, ID, EmpirePoker.com: Poker Lobby


  ; We now use the same method for both Party and Empire.
  if (lobby_id)
  {

    ;___ Now we want to focus that table in the PartyListView
    WinActivate, ahk_id%lobby_id%
    WinwaitActive, ahk_id%lobby_id%, , 3 ; @@@ v1.18d: Now exits after 3 seconds to prevent deadlock! @@@

    ; Lets give it some time to update.
    Sleep, 500

    Loop ;__ see below... 
    { 

      ; Lets makes sure we have the correct listview in focus.
      ControlFocus, SysListView321, ahk_id%lobby_id% 
      ControlClick, SysListView321, ahk_id%lobby_id% ;___ I've had ControlFocus fail here, but this always works

      ; ### Using ControlSendraw was causing the Party problems: use ControlSend instead.
      ControlSend, SysListView321, %TableName%, ahk_id%lobby_id% ;___ this wasn't so hard, huh?  FPRIVATE "TYPE=PICT;ALT=" Just send the name, that should focus the table 

      ;___ now I'm guessing you'll want to open it; since the above method sometimes fails, we double-check: 
      ControlGet, row, List, Fosused, SysListView321, ahk_id%lobby_id% 
      IfInString, row, %TableName% 
        break ;__ terminate the loop; else we'd send the name all over again

      ;__ but maybe there's some other problem, so it's better we only try, say, three times 
      If a_index = 3
        return

    }

    ; ### v1.18d: Do this twice as it doesn't always work.
    Sleep, 500
    ControlSend, SysListView321, {Enter}, ahk_id%lobby_id% ;___open the table
    Sleep, 500
    ControlSend, SysListView321, {Enter}, ahk_id%lobby_id% ;___open the table

  }

}


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

FocusLooby:

  WinGet, lobby_id, ID, PartyPoker.com: Poker Lobby
  if (lobby_id)
  {
    WinActivate, ahk_id%lobby_id%
    WinwaitActive, ahk_id%lobby_id%, , 3 ; @@@ v1.18d: Now exits after 3 seconds to prevent deadlock! @@@
    ControlFocus, SysListView321, ahk_id%lobby_id%
    Sleep, -1
    ControlClick, SysListView321, ahk_id%lobby_id%
    return
  }

  WinGet, lobby_id, ID, EmpirePoker.com: Poker Lobby
  if (lobby_id)
  {
    WinActivate, ahk_id%lobby_id%
    WinwaitActive, ahk_id%lobby_id%, , 3 ; @@@ v1.18d: Now exits after 3 seconds to prevent deadlock! @@@
    ControlFocus, SysListView321, ahk_id%lobby_id%
    Sleep, -1
    ControlClick, SysListView321, ahk_id%lobby_id%
  }

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; This function will update the integrated list of SNGs.
AutoUpdateSNGList:

  ; Depends on if we have Party or empire loaded.
  WinGet, id, ID, EmpirePoker.com: Poker Lobby
  if (id)
    ControlGet, List, List, , SysListView321, EmpirePoker.com: Poker Lobby
  else
    ControlGet, List, List, , SysListView321, PartyPoker.com: Poker Lobby

  ; Clear it ready to start again.
  LV_Delete()

  RowNumber := 1
  Loop, Parse, List, `n  ; Rows are delimited by linefeeds (`n).
  {

    ; See if we find what we are looking for.
    Found := 0
    Loop, Parse, A_LoopField, %A_Tab%
    {

       ; Now check it's the correct type.
       if (A_Index = 2)
       {
         if (InStr(A_LoopField, "Speed") <> 0)
             Found := Found + 1
         else
             break
       }  
       if (A_Index = 3)
       {
         if (A_LoopField = "NL Hold'em")
           Found := Found + 1
         else
             break
       }  
       if (A_Index = 5)
       {
         if (A_LoopField <> "10/10")
           Found := Found + 1
         else
             break
         if (A_LoopField <> "9/10") ; Ignore 9/10 tables as they usually just fill as we open them...
           Found := Found + 1
         else
             break
       }  
       if (A_Index = 6)
       {
         if (A_LoopField = "Registering")
           Found := Found + 1
         else
             break
       }  
    }
    if (Found <> 5)
      continue

    ; See if the table is open allready.
    Found := 0
    Loop, Parse, A_LoopField, %A_Tab%
    {

       ; Now check it's the correct type.
       if (A_Index = 2)
       {
         if (InStr(A_LoopField, "Speed") <> 0)
           IfWinNotExist, %A_LoopField%
           {
             Found := 1
             break
           }
       }  
    }
    if (Found <> 1)
      continue

    LV_Add(RowNumber)
    Loop, Parse, A_LoopField, %A_Tab%   ; Fields (columns) in each row are delimited by tabs (A_Tab).
    {
      LV_Modify(RowNumber, "Col"A_Index , A_LoopField)
    }

    RowNumber := RowNumber + 1
  }

  if (RowNumber > 1)
    LV_ModifyCol()  ; Auto-size each column to fit its contents.

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Call this to make sure we never open a non-speed NL table by accident.
AutoCloseNonNLSpeeds:

  LobbyWindowTitle = Poker Lobby ; identify poker lobby substring
  TableWindowTitle = Buy-in ; identify pokertable substring

  WinGet, lobbyID, ID, %LobbyWindowTitle%

  WinGet, pid, PID, ahk_id%lobbyID%
  WinGet, rlist, LIST, %TableWindowTitle% ahk_pid%pid%
  Loop %rlist%
  {
    this_id := rlist%a_index%
    If this_id != %lobbyID%
    {
      WinGetTitle, name, ahk_id%this_id%
      if (InStr(name, "Tournament Buy-in") = 0)
      {
        if (InStr(name, "Speed") = 0 OR InStr(name, "NL") = 0 OR InStr(name, "Hold'em") = 0)
          WinClose, ahk_id%this_id%
      }
    }
  }

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Call this to close all the running SNGs we are not sitting in.
; ### v1.17: Have reverted to the old code as the new code didn't work 100% and sometimes tried to close wrong table.
; ### v1.18: Had to change "This Hand" to "This hand" and "Auto Post Blind" to "Auto-post blind" to get working after the 23/09/08 update.
AutoCloseFinished:

  WinClose, ahk_class #32770, This hand, , , Auto-post blind
  IfWinExist, ahk_class #32770, will not be refunded and your blinds will continue to be posted
  {
    WinGet, idList, List, ahk_class #32770, will not be refunded and your blinds will continue to be posted
    Loop, %idList%
    {
      winID := idList%a_index%
      ControlSend, Button2, {ESC}, ahk_id%winID% ; Click Cancel always.
    }
  }

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Call this to make sure we never end up sitting out.
AutoSitBackIn:

  LobbyWindowTitle = Poker Lobby ; identify poker lobby substring
  TableWindowTitle = Buy-in ; identify pokertable substring

  WinGet, lobbyID, ID, %LobbyWindowTitle%

  WinGet, pid, PID, ahk_id%lobbyID%
  WinGet, rlist, LIST, %TableWindowTitle% ahk_pid%pid%
  Loop %rlist%
  {
    this_id := rlist%a_index%
    If this_id != %lobbyID%
    {
      ; Lets see if we can see the check button.
      ControlGet, v, Visible, , AfxWnd42u17, ahk_id%this_id%
      if (v)
      {
        ControlGetText, text, AfxWnd42u17, ahk_id%this_id%
        IfInString, text, I am Back
        {
          ControlFocus, AfxWnd42u17, ahk_id%this_id%
          Sleep, -1
          ControlClick, AfxWnd42u17, ahk_id%this_id%
        }
      }

    }
  }

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Call this to make sure all chat boxes are hidden.
AutoHideChat:

  LobbyWindowTitle = Poker Lobby ; identify poker lobby substring
  TableWindowTitle = Buy-in ; identify pokertable substring

  WinGet, lobbyID, ID, %LobbyWindowTitle%

  WinGet, pid, PID, ahk_id%lobbyID%
  WinGet, rlist, LIST, %TableWindowTitle% ahk_pid%pid%
  Loop %rlist%
  {
    this_id := rlist%a_index%
    If this_id != %lobbyID%
    {
      ; Lets see if we can see the chat box.
      ControlGet, v, Visible, , RichEdit20W1, ahk_id%this_id%
      if (v)
        Control, Hide, , RichEdit20W1, ahk_id%this_id%

      ; Lets see if we can see the combo box.
      ControlGet, v, Visible, , ComboBox1, ahk_id%this_id%
      if (v)
        Control, Hide, , ComboBox1, ahk_id%this_id%

      ; Lets see if we can see the Edit box.
      ControlGet, v, Visible, , Edit1, ahk_id%this_id%
      if (v)
        Control, Hide, , Edit1, ahk_id%this_id%      
    }
  }

return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;