; vim: set foldmethod=marker:
; autoreg.ahk
; a simple poker stars auto register script by castor_ades7
; based on/inspired by SFSO_4.01b.ahk
; Thaks go to: Everlong@2p2, _dave_, chris228, finnisher, Max1mums
; ================================================== ======================
; Log in before starting the script
; In Lobby, activate "Show registering/upcoming only"
; In Lobby, use "Games View"
; Choose the "Classic" Table Theme
; Do not minimize PokerStars Lobby, just move it out of the way
; Enable option: Allow registration(s) without showing Buy-In dialog
; It is suggested that:
; PokerStars hotkeys are used and Go to 'First Action' Table = SPACE
; Tested with PokerStars 6 and Classic Theme for SnG tournaments
; For PS7, enable option: Settings > Lobby > Lobby_Display > Show_Guide_Bar
; ================================================== ======================
; init {{{
#NoEnv
#SingleInstance, Force
#WinActivateForce
SendMode Input
SetWorkingDir %A_ScriptDir%
SetBatchLines, -1
SetTitleMatchMode, 2
StringTrimRight, thisahk, A_ScriptName, 4
regButton_PS6 := "PokerStarsButtonClass10"
unregButton_PS6 := "PokerStarsButtonClass8"
regButton_PS7 := "PokerStarsButtonClass135"
unregButton_PS7 := "PokerStarsButtonClass133"
regList_PS6 := "PokerStarsListClass3"
regList_PS7 := "PokerStarsListClass13"
unregAll_selBtn_PS6 := "Button1"
unregAll_unregBtn_PS6 := "PokerStarsButtonClass2"
unregAll_selBtn_PS7 := "PokerStarsButtonClass1"
unregAll_unregBtn_PS7 := "PokerStarsButtonClass3"
regButton := regButton_PS6
unregButton := unregButton_PS6
regList := regList_PS6
unregAll_selBtn := unregAll_selBtn_PS6
unregAll_unregBtn := unregAll_unregBtn_PS6
PS_ver := 6
AutoRegister := 0
AutoAutoClose := 0
AutoInfoTab := 0
AutoSittingOut := 0
AutoSittingOut_hh := 0
AutoWindowMaximize := 0
AutoActivateTableWin := 0
ct_Tables_Now := 0 ; number of open tables currently
ct_Tables_SoFar := 0 ; number of tables so far, since start of script
window_position_to_move := "Center"
ScriptStarted := 0
LogFile := "autoreg_" A_Now ".log"
Hero_Name := "noname" ; set in StartScript from lobby title
so_tables_already_clicked_count := 0 ; sitting out
it_tables_already_clicked_count := 0 ; info tab
ct_tables_already_counted_count := 0 ; count tables
; ----------------------
; User defined variables
; ----------------------
MaxTablesInit:=16 ; Maximum number of Tables to keep open, Initial value
AutoCloseInterval:=50 ; Check if any and close "confirm" windows every X msec
RegisterInterval:=30*1000 ; Register every X millisec
SittingOut:=10 ; Check active table window if Sitting Out every X millisec
SittingOut_hh:=5*1000 ; Check if Sitting Out every X millisec via hh
WindowMaximize:=2*1000 ; Check and Maximize all table Windows every X millisec
ActivateTableWinTime:=10*1000 ; Activate a Table Window every X millisec
InfoTab:=200 ; Check active table win if InfoTab was clicked, every X millisec
CountTables:=3*1000 ; Count physical tables every X millisec
IdleTime:=10*60*1000 ; PauseScript and UnRegisterAll, if Idle for X millisec
MaxTablesSoFar:=700 ; Maximum number of total registered tables so far
SafeguardInterval:=1*60*1000 ; Do safeguard checks every X millisec
Path_to_HH:="C:\Program Files\PokerStars\HandHistory\"
alt_Path_to_HH := "C:\HandHistory\"
; Path_to_HH is combined with Hero_Name in StartScript
; Hand histories are used to check if hero is sitting out
; ----------------------
; ----------------------
ifExist, %alt_Path_to_HH%
Path_to_HH := alt_Path_to_HH
if (SafeguardInterval>0)
Sleep, 37
SetTimer, Safeguard, %SafeguardInterval%
Gosub, BuildGui
Return
; }}}
QuitScript: ; {{{
ExitApp
Return ; }}}
BuildGui: ; {{{
Gui, Color, White
Gui, Font, cOlive
Gui, Add, Text, x10 y12, Max Number of Open Tables:
Gui, Add, Edit, x155 y10 w42
Gui, Add, UpDown, vMaxTables, %MaxTablesInit%
Gui, Add, GroupBox, x5 y30 w92 h130,
Gui, Add, Button, x10 y40 w80 gStartScript
, &[S]tart
Gui, Add, Text, x100 y45, Submit and start/continue script
Gui, Add, Button, x10 y70 w80 gUnRegisterAll
, &S[T]op
Gui, Add, Text, x100 y75, Un-register all and stop registering
Gui, Add, Button, x10 y100 w80 gPauseScript
, &[P]ause
Gui, Add, Text, x100 y105, Cancel all automated functions
Gui, Add, Button, x10 y130 w80 gQuitScript
, &[Q]uit
Gui, Add, Text, x100 y135, Exit script and close window
Gui, Add, Checkbox, x10 y160 vSpaceG2FAT Checked
, &PokerStars hotkeys are used and`nSPACE goes to "First Action" Table
Gui, Add, Button, x10 y190 w190 gSittingOut_via_button
, &Check all if Sitting [O]ut and Go Back
Gui, Add, Checkbox, x205 y190 vAutoSittingOut Checked, &Auto
Gui, Add, Checkbox, x205 y202 vAutoSittingOut_hh Checked, &Auto_hh
Gui, Add, Button, x10 y220 w190 gInfoTab_via_button
, &Check all if [I]nfo Tab is selected
Gui, Add, Checkbox, x205 y225 vAutoInfoTab Checked, &Auto
Gui, Add, Button, x10 y250 w190 gInfoTab_via_button_active
, &Click In[F]o Tab on active table
Gui, Add, Button, x10 y280 w190 gWindowMaximize
, &Maximize all Table [W]indows
Gui, Add, Checkbox, x205 y285 vAutoWindowMaximize Checked, &Auto
Gui, Add, Button, x10 y310 w190 gActivateTableWin
, &[A]ctivate a Table Window
Gui, Add, Checkbox, x205 y315 vAutoActivateTableWin, &Auto
Gui, Add, Button, x10 y340 w190 gAutoClose
, &Close small confirmation windows
Gui, Add, Checkbox, x205 y345 vAutoAutoClose Checked, &Auto
Gui, Add, Text, x10 w255 cBlue
, hotkeys: Ctl + Alt + letter_in_brackets
Gui, Add, Text, w255 cGreen vStatus, Status: Idle
Gui, Add, Text, w255 cBlack vInfo1, n/a
Gui, Add, Text, w255 cBlack vInfo2, n/a
Gui, Add, Text, w255 cBlack vInfo3, n/a
Gui, Add, Text, w255 cBlack vInfo4, n/a
Gui, Add, Text, w255 cRed vInfo_Reg
, Registered now/total: %ct_Tables_Now%/%ct_Tables_SoFar%
Gui, Show, w265, %thisahk%
Gui, Show, x0 y0, %thisahk%
Sleep, -1
Gosub, Wait
Return ; }}}
Safeguard: ; {{{
if (A_TimeIdle > IdleTime OR ct_Tables_SoFar > MaxTablesSoFar)
{
Gosub, UnRegisterAll
GuiControl,, Status, Status: Stop registering due to safeguard
FileAppend, %A_Now% Stop registering due to safeguard `n, %LogFile%
}
Return ; }}}
Wait: ; {{{
GuiControl,, Status, Status: Waiting
Return ; }}}
PauseScript: ; {{{
AutoRegister:=0
AutoAutoClose:=0
AutoInfoTab:=0
AutoSittingOut:=0
AutoSittingOut_hh:=0
AutoWindowMaximize:=0
AutoActivateTableWin:=0
GuiControl,, Status, Status: Script Paused
FileAppend, %A_Now% Script Paused `n, %LogFile%
Return ; }}}
StartScript: ; {{{
GuiControl,, Status, Status: Started/Continued on %A_Hour%:%A_Min%:%A_Sec%
Gui, Submit, NoHide ; update all AutoX switches
AutoRegister := 1
WinGet, LobbyId, Id, PokerStars Lobby ahk_class #32770
if !LobbyId {
GuiControl,, Status, Status: PokerStars Lobby not found
Return
}
WinActivate, ahk_id%LobbyId%
WinGetText, Lobby_Txt, ahk_id%LobbyId%
StringMid, Lobby_Txt_short, Lobby_Txt, 1, 256
IfInString, Lobby_Txt_short, Revert
{
PS_ver := 7
StringSplit, Lobby_Txt_split, Lobby_Txt_short, `n, `r
Hero_Name := Lobby_Txt_split1
regButton := regButton_PS7
unregButton := unregButton_PS7
regList := regList_PS7
unregAll_selBtn := unregAll_selBtn_PS7
unregAll_unregBtn := unregAll_unregBtn_PS7
}
else
{
PS_ver := 6
WinGetTitle, Lobby_Title, ahk_id%LobbyId%
StringSplit, Lobby_Title_split, Lobby_Title, %A_Space%'%A_Tab%
Hero_Name := Lobby_Title_split7
regButton := regButton_PS6
unregButton := unregButton_PS6
regList := regList_PS6
unregAll_selBtn := unregAll_selBtn_PS6
unregAll_unregBtn := unregAll_unregBtn_PS6
}
Path_to_hero_HH := Path_to_HH Hero_Name "\*.txt"
GuiControl,, Info1, %A_Hour%:%A_Min%:%A_Sec% PS%PS_ver% Hero_Name: %Hero_Name%
if !ScriptStarted
{
if (CountTables>0)
SetTimer, CountTables, %CountTables%
Sleep, 37
if (AutoCloseInterval>0)
SetTimer, AutoClose, %AutoCloseInterval%
Sleep, 37
if (InfoTab>0)
SetTimer, InfoTab, %InfoTab%
Sleep, 37
if (SittingOut>0)
SetTimer, SittingOut, %SittingOut%
Sleep, 37
if (SittingOut_hh>0)
SetTimer, SittingOut_hh, %SittingOut_hh%
Sleep, 37
if (WindowMaximize>0)
SetTimer, WindowMaximize, %WindowMaximize%
Sleep, 37
if (ActivateTableWinTime>0)
SetTimer, ActivateTableWin, %ActivateTableWinTime%
Sleep, 37
if (RegisterInterval>0) {
Gosub, Register
SetTimer, Register, %RegisterInterval%
}
FileAppend, %A_Now% Script Initial Start `n, %LogFile%
ScriptStarted := 1
Sleep, -1
}
Sleep, -1
Return ; }}}
ActivateTableWin: ; {{{
if AutoActivateTableWin
ActivateTableWin()
Return
ActivateTableWin() {
Global SpaceG2FAT
SetTitleMatchMode, 2
if !SpaceG2FAT {
WinActivate, Table ahk_class PokerStarsTableFrameClass
Return
}
WinGetTitle, active_win_title, A
IfInString, active_win_title, Table
SendInput, {Space} ; Go to 'First Action' Table
else {
WinActivate, Table ahk_class PokerStarsTableFrameClass
WinGetTitle, active_win_title, A
IfInString, active_win_title, Table
SendInput, {Space} ; Go to 'First Action' Table
}
}
Return ; }}}
Register: ; {{{
if AutoRegister
Register()
Return
Register()
{
Global ; all variables of this function will be globals
SetTitleMatchMode, 2
WinGet, rg_LobbyId, Id, PokerStars Lobby ahk_class #32770
if !rg_LobbyId {
GuiControl,, Status, Status: PokerStars Lobby not found
Return
}
if (ct_Tables_Now >= MaxTables)
{
GuiControl,, Status, Status: Set Full at %ct_Tables_Now% tables_Waiting
Return
}
ControlSend, %regList%, {NumpadUp 20}, ahk_id%rg_LobbyId%
rg_TimesToReg := MaxTables - ct_Tables_Now
Loop %rg_TimesToReg% {
GuiControl,, Status, Status: Registering %rg_TimesToReg% times
ControlGet, rg_regBtnVis, Visible,, %regButton%, ahk_id%rg_LobbyId%
if (rg_regBtnVis = 1) {
ControlSend, %regButton%, {Space}, ahk_id%rg_LobbyId%
ControlSend, %regButton%, {Space}, ahk_id%rg_LobbyId%
ControlSend, %regList%, {NumpadDown}, ahk_id%rg_LobbyId%
GuiControl,, Status
, Status: Waiting _ register %A_Index% of %rg_TimesToReg%
} else {
ControlGet, rg_unregBtnVis
, Visible,, %unregButton%, ahk_id%rg_LobbyId%
if (rg_unregBtnVis = 1) {
GuiControl,, Status
, Status: Already registered game found _ Waiting
ControlSend, %regList%
, {NumpadDown}, ahk_id%rg_LobbyId%
} else
GuiControl,, Status, Status: No games found _ Waiting
}
Sleep, 30
Sleep, -1
}
ActivateTableWin()
Sleep, -1
}
Return ; }}}
UnRegisterAll: ; {{{
AutoRegister:=0
GuiControl,, Status, Status: Stop Registering
if ScriptStarted
UnRegisterAll()
else
GuiControl,, Status, Status: Need to press Submit first
Return
UnRegisterAll() {
Global regList
Global unregAll_selBtn
Global unregAll_unregBtn
SetTitleMatchMode,2
WinGet, LobbyId, id, PokerStars Lobby ahk_class #32770
if !LobbyId
{
GuiControl,, Status, Status: PokerStars Lobby not found
Return
}
ControlSend, %regList%, ^r, ahk_id%lobbyid%
WinWait, Registered In Tournaments ahk_class #32770,, 1
{
WinGet, regid, Id, Registered In Tournaments ahk_class #32770
ControlGet, vis, Visible,, %unregAll_selBtn%, ahk_id%regid%
if vis {
ControlSend, %unregAll_selBtn%, {Space}, ahk_id%regid%
Sleep, 30
ControlSend, %unregAll_unregBtn%, {Space}, ahk_id%regid%
Sleep, 30
}
WinClose, ahk_id%regid%
}
ActivateTableWin()
}
Return ; }}}
AutoClose: ; {{{
if AutoAutoClose
AutoClose()
Return
AutoClose()
{
Global AutoRegister
Global LogFile
a_win_was_closed:=0
SetTitleMatchMode,2
ifWinExist, Tournament Registration ahk_class #32770
{
WinGet, id1, id, ; Automatically uses the window found above
ControlGetText, btn_text, PokerStarsButtonClass1, ahk_id%id1%
if !(btn_text = "OK")
{
AutoRegister := 0
FileAppend
, %A_Now% Registration not OK _ Stop Registering `n, %LogFile%
GuiControl,, Info3
, %A_Hour%:%A_Min%:%A_Sec% Registration not OK _ Stop Registering
}
WinGetTitle, title_id1, ahk_id%id1%
WinClose, ahk_id%id1%
GuiControl,, Info2, %A_Hour%:%A_Min%:%A_Sec% closed: %title_id1%
a_win_was_closed:=1
}
ifWinExist, PokerStars ahk_class #32770,, Lobby
{
; closes any PokerStars window that pops up, except Lobby
WinGet, id2, id,
WinMove, ahk_id%id2%,, A_ScreenWidth, 0
WinGetTitle, title_id2, ahk_id%id2%
GuiControl,, Info3, %A_Hour%:%A_Min%:%A_Sec% closed: %title_id2%
FileAppend, %A_Now% closed_win %title_id2% `n, %LogFile%
a_win_was_closed:=2
}
if a_win_was_closed
ActivateTableWin()
if a_win_was_closed = 2
{
; saves the image of the non-tournament-registration closed window
; to a file, in order to check later
image_file_name := "ahk_closed_window_" A_Now ".bmp"
; www.autohotkey.com/forum/viewtopic.php?t=35242
WinGetPos,,, w, h, ahk_id%id2%
hDC := Dllcall( "GetDC"
, UInt, id2 )
hCDC := Dllcall( "CreateCompatibleDC"
, UInt, hDC )
hCBMP := Dllcall( "CreateCompatibleBitmap"
, UInt, hDC
, Int, w
, Int, h )
DllCall( "SelectObject"
, UInt, hCDC
, UInt, hCBMP )
DllCall( "PrintWindow"
, UInt, id2
, UInt, hCDC
, UInt, 0 )
DllCall( "BitBlt"
, Int, hCDC
, Int, 0
, Int, 0
, Int, w
, Int, h
, Int, hDC
, Int, 0
, Int, 0
, Int, 0xCC0020 )
hBM := DllCall( "CopyImage"
, UInt, hCBMP
, UInt, 0
, Int, 0
, Int, 0
, UInt, 0x2000 )
DllCall( "GetObject"
, Int, hBM
, Int, VarSetCapacity($,84)
, UInt, NumPut(0,$,40,"Short") - 42 )
Numput( VarSetCapacity( BFH, 14, 0) + 40
, Numput( (NumGet($, 44) + 54)
, Numput(0x4D42, BFH) - 2) + 4 )
hF := DllCall( "CreateFile"
, Str, image_file_name
, UInt, 2**30
, UInt, 2
, Int, 0
, UInt, 2
, Int64, 0 )
If hF > 0
{
; BITMAPFILEHEADER
DllCall( "WriteFile"
, UInt, hF
, UInt, &BFH
, UInt, 14
, IntP, 0
, Int, 0 )
; BITMAPINFOHEADER
DllCall( "WriteFile"
, UInt, hF
, UInt, &$ + 24
, UInt, 40
, IntP, 0
, Int, 0 )
DllCall( "WriteFile"
, UInt, hF
, UInt,NumGet($, 20)
, UInt, NumGet($, 44)
, UIntP, BW
, Int, 0 )
DllCall( "CloseHandle"
, UInt, hF )
}
DllCall( "DeleteObject"
, Int, hCBMP )
DllCall( "ReleaseDC"
, Int, id2
, Int, hDC )
DllCall( "DeleteDC"
, Int, hCDC )
WinClose, ahk_id%id2%
}
}
Return ; }}}
InfoTab: ; {{{
; looks at every active table on screen if info tab is selected, once
if AutoInfoTab
InfoTab()
Return
InfoTab()
{
Global ; all variables of this function will be globals
it_found := 0
SetTitleMatchMode, 2
it_id := WinExist("A")
WinGetTitle, it_active_win_title, ahk_id%it_id%
IfNotInString, it_active_win_title, Table
Return
Loop %it_tables_already_clicked_count% {
it_id_already_clicked := it_tables_already_clicked%A_Index%
if (it_id = it_id_already_clicked) {
it_found := 1
Break
}
}
if it_found
Return
WinGetPos,,, it_w, it_h, ahk_id%it_id%
VarSetCapacity(it_rc, 16)
DllCall("GetClientRect", "UInt", it_id, "UInt", &it_rc)
it_client_w := NumGet(it_rc, 8, "Int")
it_client_h := NumGet(it_rc, 12, "Int")
VarSetCapacity(it_rc, 0)
it_win_frame_sides := (it_w - it_client_w) / 2
it_win_frame_top := it_h - it_client_h - it_win_frame_sides
it_x := Round(0.244 * it_client_w) + it_win_frame_sides
it_y := Round(0.77 * it_client_h) + it_win_frame_top
MouseGetPos, it_mouse_x_init, it_mouse_y_init
Click %it_x%, %it_y%
MouseMove, it_mouse_x_init, it_mouse_y_init, 0
Sleep, -1
ActivateTableWin()
it_tables_already_clicked_count += 1
it_tables_already_clicked%it_tables_already_clicke d_count% := it_id
Sleep, -1
}
Return ; }}}
InfoTab_via_button: ; {{{
; looks at every table if info tab is selected
InfoTab_via_button()
Return
InfoTab_via_button()
{
activated := 0
SetTitleMatchMode, 2
WinGet, TableWindows, List, Table ahk_class PokerStarsTableFrameClass
if TableWindows = 0
Return
Loop %TableWindows% {
id := TableWindows%A_Index%
WinGetPos,,, w, h, ahk_id%id%
VarSetCapacity(rc, 16)
DllCall("GetClientRect", "UInt", id, "UInt", &rc)
client_w := NumGet(rc, 8, "Int")
client_h := NumGet(rc, 12, "Int")
VarSetCapacity(rc, 0)
win_frame_sides := (w - client_w) / 2
win_frame_top := h - client_h - win_frame_sides
x := Round(0.243 * client_w)
y := Round(0.77 * client_h)
x := x + win_frame_sides
y := y + win_frame_top
ColorID:=0x003386
WinActivate, ahk_id%id%
activated := 1
PixelSearch,,, x, y, x+1, y+1, ColorID, 20, ahk_id%id%, Fast
if (ErrorLevel=0) {
MouseGetPos, mouse_x_init, mouse_y_init
Click %x%, %y%
MouseMove, mouse_x_init, mouse_y_init, 0
Sleep, -1
activeid := WinExist("A")
if (id != activeid) {
; another window might have poped, press key again
WinActivate, ahk_id%id%
MouseGetPos, mouse_x_init, mouse_y_init
Click %x%, %y%
MouseMove, mouse_x_init, mouse_y_init, 0
Sleep, -1
}
}
}
if activated
ActivateTableWin()
Sleep, -1
}
Return ; }}}
InfoTab_via_button_active: ; {{{
; presses info tab of currently active table window
InfoTab_via_button_active()
Return
InfoTab_via_button_active()
{
SetTitleMatchMode, 2
id := WinExist("A")
WinGetTitle, win_title, ahk_id%id%
IfNotInString, win_title, Table
{
WinActivate, Table ahk_class PokerStarsTableFrameClass
WinGetTitle, active_win_title, A
IfInString, active_win_title, Table
id := WinExist("A")
else
Return
}
WinGetPos,,, w, h, ahk_id%id%
VarSetCapacity(rc, 16)
DllCall("GetClientRect", "UInt", id, "UInt", &rc)
client_w := NumGet(rc, 8, "Int")
client_h := NumGet(rc, 12, "Int")
VarSetCapacity(rc, 0)
win_frame_sides := (w - client_w) / 2
win_frame_top := h - client_h - win_frame_sides
x := Round(0.243 * client_w) + win_frame_sides
y := Round(0.77 * client_h) + win_frame_top
MouseGetPos, mouse_x_init, mouse_y_init
Click %x%, %y%
MouseMove, mouse_x_init, mouse_y_init, 0
Sleep, -1
ActivateTableWin()
Sleep, -1
}
Return ; }}}
SittingOut: ; {{{
; looks at every active table on screen if hero is sitting out
if AutoSittingOut
SittingOut()
Return
SittingOut()
{
activated := 0
SetTitleMatchMode, 2
id := WinExist("A")
WinGetTitle, active_win_title, ahk_id%id%
IfNotInString, active_win_title, Table
Return
WinGetPos,,, w, h, ahk_id%id%
VarSetCapacity(rc, 16)
DllCall("GetClientRect", "UInt", id, "UInt", &rc)
client_w := NumGet(rc, 8, "Int")
client_h := NumGet(rc, 12, "Int")
VarSetCapacity(rc, 0)
win_frame_sides := (w - client_w) / 2
win_frame_top := h - client_h - win_frame_sides
x := Round(0.015748 * client_w) + win_frame_sides
y := Round(0.7042857 * client_h) + win_frame_top
ColorID:=0x000000
PixelSearch,,, x, y, x+1, y+1, ColorID, 0, ahk_id%id%, Fast
if (ErrorLevel = 0) {
x := Round(0.71 * client_w) + win_frame_sides
y := Round(0.85 * client_h) + win_frame_top
PixelSearch,,, x, y, x+1, y+1, ColorID, 0, ahk_id%id%, Fast
if (ErrorLevel = 0) {
MouseGetPos, mouse_x_init, mouse_y_init
Click %x%, %y%
MouseMove, mouse_x_init, mouse_y_init, 0
GuiControl,, Info4, %A_Hour%:%A_Min%:%A_Sec% pressed i_am_back
activated := 1
Sleep, -1
}
}
if activated
ActivateTableWin()
Sleep, -1
}
Return ; }}}
SittingOut_hh: ; {{{
; looks at hh files if hero is sitting out
if AutoSittingOut_hh
SittingOut_hh()
Return
SittingOut_hh()
{
Global ; all variables of this function will be globals
so_iamback_clicked := 0
so_tables_to_be_clicked_count := 0
Loop, %Path_to_hero_HH%, 0 ; {{{
{
; look into recent hand history files if hero is sitting out
so_modification_interval := 5 ;check hh files modified in last X minutes
so_CharCount := 4000 ; characters to read, starting at end of hh file
so_time_var := A_Now
EnvSub, so_time_var, %A_LoopFileTimeModified%, Minutes
if (so_time_var > so_modification_interval)
Continue
if (A_LoopFileSize < so_CharCount)
so_CharCount := A_LoopFileSize - 1
so_BytesToRead := VarSetCapacity(so_HH_String, so_CharCount)
so_FileName = %A_LoopFileLongPath%
so_GENERIC_READ = 0x80000000
so_OPEN_EXISTING = 3
so_FILE_SHARE_READ = 0x1
so_FILE_SHARE_WRITE = 0x2
so_hFile := DllCall("CreateFile"
, str, so_FileName
, UInt, so_GENERIC_READ
, UInt, so_FILE_SHARE_WRITE
, UInt, 0
, UInt, so_OPEN_EXISTING
, Uint, 0, UInt, 0)
if not so_hFile {
GuiControl,, Info1, Can't open "%so_FileName%" for reading
Return
}
so_ret_val := DllCall("SetFilePointerEx"
, "Uint", so_hFile
, "Int64", -so_CharCount
, "UInt *", "NULL"
, "Int", 2)
if not so_ret_val {
GuiControl,, Info1, Can't create new file pointer
Return
}
DllCall("ReadFile"
, UInt, so_hFile
, str, so_HH_String
, UInt, so_BytesToRead
, UIntP, so_BytesActuallyRead
, UInt, 0)
DllCall("CloseHandle", UInt, so_hFile)
StringGetPos, so_table_pos, so_HH_String, Table ', R
if (so_table_pos < 0)
Continue
so_FoundPos := RegExMatch(so_HH_String, Hero_Name ".*is sitting out"
, so_outvar, StartingPosition = %so_table_pos%)
if (so_FoundPos = 0)
Continue
; get tournament/window id and click on "I am back" button
StringMid, so_tournament_id_string, so_HH_String, %so_table_pos%, 32
StringSplit, so_tournament_id_split, so_tournament_id_string
, %A_Space%'%A_Tab%
so_tournament_id := so_tournament_id_split3
FileAppend, %A_Now% %so_tournament_id% %so_outvar% `n, %LogFile%
SetTitleMatchMode,2
WinGet, so_id, Id,%so_tournament_id% ahk_class PokerStarsTableFrameClass
if so_id is not Number
Continue
so_tables_to_be_clicked_count += 1
so_tables_to_be_clicked%so_tables_to_be_clicked_co unt%_id := so_id
so_tables_to_be_clicked%so_tables_to_be_clicked_co unt%_trn := so_tournament_id
} ; }}}
Loop %so_tables_to_be_clicked_count% { ; {{{
so_id := so_tables_to_be_clicked%A_Index%_id
so_trn := so_tables_to_be_clicked%A_Index%_trn
so_already_clicked := 0
Loop %so_tables_already_clicked_count% {
so_stored_id := so_tables_already_clicked%A_Index%_id
so_stored_time := so_tables_already_clicked%A_Index%_time
if ((so_stored_id = so_id) && (A_Now - so_stored_time < 100)) {
so_already_clicked:= 1
Break
}
}
if so_already_clicked
Continue
WinGetPos,,, so_w, so_h, ahk_id%so_id%
VarSetCapacity(so_rc, 16)
DllCall("GetClientRect", "UInt", so_id, "UInt", &so_rc)
so_client_w := NumGet(so_rc, 8, "Int")
so_client_h := NumGet(so_rc, 12, "Int")
VarSetCapacity(so_rc, 0)
so_win_frame_sides := (so_w - so_client_w) / 2
so_win_frame_top := so_h - so_client_h - so_win_frame_sides
so_x := Round(0.71 * so_client_w) + so_win_frame_sides
so_y := Round(0.85 * so_client_h) + so_win_frame_top
ControlClick, x%so_x% y%so_y%, ahk_id%so_id%,,,, Pos
so_iamback_clicked := 1
GuiControl,, Info4
, %A_Hour%:%A_Min%:%A_Sec% i_am_back on %so_trn%
FileAppend, %A_Now% %so_trn% i_am_back `n, %LogFile%
so_tables_already_clicked_count += 1
so_tables_already_clicked%so_tables_already_clicke d_count%_id := so_id
so_tables_already_clicked%so_tables_already_clicke d_count%_time := A_Now
Sleep, -1
}
if so_iamback_clicked {
ActivateTableWin()
} ; }}}
Sleep, -1
}
Return ; }}}
SittingOut_via_button: ; {{{
; looks at every table if hero is sitting out
SittingOut_via_button()
Return
SittingOut_via_button()
{
activated := 0
SetTitleMatchMode, 2
WinGet, TableWindows, List, Table ahk_class PokerStarsTableFrameClass
if TableWindows = 0
Return
Loop %TableWindows% {
id := TableWindows%A_Index%
WinGetPos,,, w, h, ahk_id%id%
VarSetCapacity(rc, 16)
DllCall("GetClientRect", "UInt", id, "UInt", &rc)
client_w := NumGet(rc, 8, "Int")
client_h := NumGet(rc, 12, "Int")
VarSetCapacity(rc, 0)
win_frame_sides := (w - client_w) / 2
win_frame_top := h - client_h - win_frame_sides
x := Round(0.015748 * client_w) + win_frame_sides
y := Round(0.7042857 * client_h) + win_frame_top
ColorID:=0x000000
WinActivate, ahk_id%id%
activated := 1
PixelSearch,,, x, y, x+1, y+1, ColorID, 0, ahk_id%id%, Fast
if (ErrorLevel = 0) {
x := Round(0.71 * client_w) + win_frame_sides
y := Round(0.85 * client_h) + win_frame_top
PixelSearch,,, x, y, x+1, y+1, ColorID, 0, ahk_id%id%, Fast
if (ErrorLevel = 0) {
MouseGetPos, mouse_x_init, mouse_y_init
Click %x%, %y%
MouseMove, mouse_x_init, mouse_y_init, 0
Sleep, -1
GuiControl,, Info4, %A_Hour%:%A_Min%:%A_Sec% pressed i_am_back
activeid := WinExist("A")
if (id != activeid) {
; another window might have poped, press key again
WinActivate, ahk_id%id%
MouseGetPos, mouse_x_init, mouse_y_init
Click %x%, %y%
MouseMove, mouse_x_init, mouse_y_init, 0
Sleep, -1
GuiControl,, Info4
, %A_Hour%:%A_Min%:%A_Sec% pressed i_am_back2
}
}
}
}
if activated
ActivateTableWin()
Sleep, -1
}
Return ; }}}
WindowMaximize: ; {{{
if AutoWindowMaximize
WindowMaximize()
Return
WindowMaximize()
{
; maximizes all table windows, useful for "Stack Tables" multitabling
wmax:=0
SetTitleMatchMode,2
WinGet, TableWindows, List, Table ahk_class PokerStarsTableFrameClass
if TableWindows=0
Return
activeid := WinExist("A")
WinGetPos,,,, taskbar_h, ahk_class Shell_TrayWnd
Loop %TableWindows% {
id:=TableWindows%A_Index%
WinGetPos,,, w, h, ahk_id%id%
if (w<A_ScreenWidth AND w<1328 AND h<A_ScreenHeight-taskbar_h) {
PostMessage, 0x112, 0xF030,,, ahk_id%id%
wmax:=1
}
Sleep, -1
}
if wmax
ActivateTableWin()
}
Return ; }}}
CountTables: ; {{{
CountTables()
Return
CountTables()
{
Global ; all variables of this function will be globals
ct_found := 0
SetTitleMatchMode,2
WinGet, ct_Tables_Now, List, Logged ahk_class PokerStarsTableFrameClass
if (ct_Tables_Now = 0) {
GuiControl,, Info_Reg
, Registered now/total: %ct_Tables_Now%/%ct_Tables_SoFar%
Return
}
Loop %ct_Tables_Now% {
ct_id := ct_Tables_Now%A_Index%
Loop %ct_tables_already_counted_count% {
ct_id_already_counted := ct_tables_already_counted%A_Index%
if (ct_id = ct_id_already_counted) {
ct_found := 1
Break
}
}
if ct_found {
ct_found := 0
Continue
}
ct_tables_already_counted_count += 1
ct_tables_already_counted%ct_tables_already_counte d_count% := ct_id
}
ct_Tables_SoFar := ct_tables_already_counted_count
GuiControl,, Info_Reg
, Registered now/total: %ct_Tables_Now%/%ct_Tables_SoFar%
}
Return ; }}}
WindowMove: ; {{{
WindowMove()
Return
WindowMove()
{
Global window_position_to_move
SetTitleMatchMode,2
activeid := WinExist("A")
WinGetTitle, active_win_title, ahk_id%activeid%
IfInString, active_win_title, Table
{
WinGetPos, X, Y, Width, Height, ahk_id%activeid%
if (window_position_to_move == "Top_Right")
WinMove, ahk_id%activeid%,, (A_ScreenWidth - Width), 0
else if (window_position_to_move == "Bottom_Right")
WinMove, ahk_id%activeid%,, (A_ScreenWidth - Width)
, (A_ScreenHeight - Height)
else if (window_position_to_move == "Top_Left")
WinMove, ahk_id%activeid%,, 0, 0
else if (window_position_to_move == "Bottom_Left")
WinMove, ahk_id%activeid%,, 0, (A_ScreenHeight - Height)
else if (window_position_to_move == "Center") {
WinMove, ahk_id%activeid%,, X, Y, 0.8 * Width, 0.8 * Height
PostMessage, 0x112, 0xF030,,, ahk_id%activeid%
}
ActivateTableWin()
}
}
Return ; }}}
LobbyRestore: ; {{{
WinGet, LobbyId, id, PokerStars Lobby ahk_class #32770
if !LobbyId
{
GuiControl,, Status, Status: PokerStars Lobby not found
Return
}
WinShow, ahk_id%LobbyId%
WinMove, ahk_id%LobbyId%,, 0, 0
Return ; }}}
; hotkeys {{{
; ^ = Ctrl
; ! = Alt
^!s::
Gosub, StartScript
Return
^!t::
Gosub, UnRegisterAll
Return
^!p::
Gosub, PauseScript
Return
^!o::
Gosub, SittingOut_via_button
Return
^!i::
Gosub, InfoTab_via_button
Return
^!f::
Gosub, InfoTab_via_button_active
Return
^!w::
Gosub, WindowMaximize
Return
^!a::
Gosub, ActivateTableWin
Return
NumpadHome::
window_position_to_move := "Top_Right"
Gosub, WindowMove
Return
NumpadEnd::
window_position_to_move := "Bottom_Right"
Gosub, WindowMove
Return
Insert::
window_position_to_move := "Top_Left"
Gosub, WindowMove
Return
Delete::
window_position_to_move := "Bottom_Left"
Gosub, WindowMove
Return
Home::
window_position_to_move := "Center"
Gosub, WindowMove
Return
PgUp::
ControlSend, Edit1, {Up}, %thisahk%
Gui, Submit, NoHide
Return
PgDn::
ControlSend, Edit1, {Down}, %thisahk%
Gui, Submit, NoHide
Return
^!h::
WinHide, %thisahk%
Return
^!r::
WinShow, %thisahk%
Return
^!l::
Gosub, LobbyRestore
Return
~^!q::
ExitApp
; }}}