PokerStars Auto Reloader

By _dave_ at 2+2 forums. The corresponding thread on 2+2 is here.

This script automatically reloads your stack on PokerStars (both NL and Limit tables) when it falls below a certain amount.

Also creates a hotkey (F1 by default) for instant reloading on the table your mouse is over.

There are a few settings right at the start of the script - these will need changed depending on your local timezone, location of PokerStars installation, etc.

This script includes several extracts from Roland's Functions, from Roland and JukofYork, slightly modified by me for the purposes of this script.

Many thanks to all of the AHK peoples in the 2p2 software forum.

Enjoy!

dave.

Instructions

Download the attachment or copy/paste the script.

Edit the settings to taste, save.

Run the script.

Version History

0.01

0.2 (24-Jan-2007)

0.2a (18-Feb-2007)

0.2b (27-Mar-2007)

0.2c (31-Mar-2007)

0.2d (13-Sep-2007)

0.2e (15-Sep-2007)

0.2f (04-Apr-2008)

Download

StarsAutoReloader-v0.2f.ahk

Code - Version 0.2f


; PokerStars NL / Limit (Auto)Reloader, by _dave_at twoplustwo.com forums
; Improtant contributions by Roland.

; Automatically reloads chips on NL and Limit tables once they drop
; below a user defined amount. Will reload to the max for NL, or add
; on a multiple of BBs at limit tables.

; Also a manual reload hotkey is provided (F1 by defualt), since the auto-reload
; is always one hand behind the action (useful if getting stacked - Hit it!)

; TEST ON LOW STAKES!!! NO GUARANTEES !!! USE AT YOUR OWN RISK!!!

; SETTINGS BELOW, ADJUST AS REQUIRED


min_nl_bbs := 104

min_limit_bbs := 50
rebuy_limit_bbs := 4



filepath := A_ProgramFiles "\PokerStars\HandHistory\"

; END OF SETTINGS

#NoEnv
#SingleInstance, Force
SendMode Input
tables := ""
nltables := ""
SetTitleMatchMode 2
GroupAdd, StarsTables, Logged In as ,,, PokerStars Lobby
SetTimer, UpdateTables, 1000
timezone_difference_EST := "-5"

SetTimer, KillPopUps, 200
;SetTimer, KillPopUps, Off

F1::  ; <-------- Hotkey for manual reload, point mouse, press key.
id := getid()
IfWinExist, ahk_id%id% ahk_group StarsTables
{
  if (InStr(nltables, id))
  {
    RebuyStars(id, "max")
  }
  else if (InStr(tables, id))
  {
    RebuyStars(id, rebuy_limit_bbs)
  }
}
return

F14::  ; <-------- Hotkey for manual reload, point mouse, press key.
id := getid()
IfWinExist, ahk_id%id% ahk_group StarsTables
{
  if (InStr(nltables, id))
  {
    RebuyStars(id, "max")
  }
  else if (InStr(tables, id))
  {
    RebuyStars(id, rebuy_limit_bbs)
  }
}
return


getTables()
{
  global tables
  global nltables
  global screenname
  global hero
  tables := ""
  nltables := ""
  SetTitleMatchMode 2
  WinGet, id, id, PokerStars Lobby
  WinGetTitle, hero, ahk_id%id%
  StringTrimLeft, hero, hero, InStr(hero, "Logged in as ", true, 0)+12
  screenname := hero
  StringReplace, hero, hero,%A_SPACE%,, All
  StringReplace, hero, hero,|,, All
  ;Msgbox, %hero%
  WinGet, pid, PID, ahk_id%id%
  WinGet, list, list, Logged In as ahk_pid%pid% 
  Loop %list%
  {
    this_id := list%a_index%
    WinGetTitle, title, ahk_id%this_id%
    If (this_id != id)
    {
      if (InStr(title, "Tournament"))
      {
        continue
      }
      if(InStr(title, "No Limit") || InStr(title, "Pot Limit"))
      {
        ;Msgbox, got nl table`n`n%title%
        nltables = %nltables%,%this_id%
      }
      else if(InStr(title, "Limit"))
      {
        ;Msgbox, got limit table`n`n%title%
        tables = %tables%,%this_id%
      }
    }
  }
  StringTrimLeft, tables, tables, 1
  StringTrimLeft, nltables, nltables, 1
}



UpdateTables:
  getTables()
  Loop, Parse, nltables, `,
  {
    DetectHiddenWindows, On
    WinGet, alreadyopen, id, _StarsAutoRebuy_%A_LoopField%.ahk 
    if (alreadyopen)
    {
      ;WinGetTitle, title, ahk_id%alreadyopen%
      continue
    }
    else
    {
      str := "#NoTrayIcon`n"
      str := str . "table_id := """ . A_LoopField . """`n"
      str := str . "justdone := 0`n"
      str := str . "screenname := """ . screenname  . """`n"
      str := str . "Loop`n"
      str := str . "{`n"
      str := str . "  IfWinNotExist, ahk_id%table_id%`n"
      str := str . "  {`n"
      str := str . "    ExitApp`n"
      str := str . "  }`n"
      str := str . "  WinGetTitle, title, ahk_id%table_id%`n"
      str := str . "  StringMid, bb, title, InStr(title, ""/"") + 1, InStr(title, a_space,"""", InStr(title, ""/"")) - InStr(title, ""/"") - 1`n"
      str := str . "  bb := StrRep(bb, ""$"")`n"
      str := str . "  desired_chips := bb * " . min_nl_bbs . "`n"
      str := str . "  StringTrimRight, title, title, (StrLen(title) - InStr(title, "" - "", true, 0))+1`n"
      str := str . "  est := A_NowUTC`n"
      ;str := str . "  MsgBox, %est%`n"
      str := str . "  est += " . timezone_difference_EST . ", hours`n"
      str := str . "  FormatTime, est, %est%, yyyyMMdd`n"
      str := str . "  filename := """ . filepath . hero . "\HH"" . est . "" "" . title . "".txt""`n"
      str := str . "  StringReplace, filename, filename, /, -`n"
      ;str := str . "  MsgBox, %filename%`n"
      str := str . "  FileGetSize, fsize, %filename%`n"
      str := str . "  if (fsize)`n"
      str := str . "  {`n"
      str := str . "    FileGetTime, ftime, %filename%`n"
      str := str . "    if (ftime > oldftime)`n"
      str := str . "    {`n"
      str := str . "      Sleep, 40`n"
      str := str . "      oldftime := ftime`n"
      str := str . "      FileRead, hh, %filename%`n"
      str := str . "      StringTrimLeft, hh, hh, Instr(hh, ""PokerStars Game #"", true, 0)-1`n"
      str := str . "      StringTrimLeft, chips, hh, InStr(hh, screenname)`n"
      str := str . "      StringTrimLeft, chips, chips, InStr(chips, "" ("")+2`n"
      str := str . "      StringTrimRight, chips, chips, StrLen(chips) - InStr(chips, "" "")+1`n"
      str := str . "      if (justdone)`n"
      str := str . "      {`n"
      str := str . "        justdone := 0`n"
      str := str . "        continue`n"
      str := str . "      }`n"
      str := str . "      if (chips < desired_chips)`n"
      str := str . "      {`n"
      str := str . "        Sleep, 2000`n"
      str := str . "        RebuyStars(table_id, ""max"")`n"
      str := str . "        justdone := 1`n"
      str := str . "      }`n"
      str := str . "    }`n"
      str := str . "  }`n"
      str := str . "Sleep, 40`n"
      str := str . "}`n"
      FileRead, fns, %A_ScriptFullPath%
      StringTrimLeft, fns, fns, InStr(fns, ";-------------- CHOP --------------;", true, 0)
      StringTrimLeft, fns, fns, InStr(fns, "`n")
      str := str . "`n`n" . fns
      filename := "_StarsAutoRebuy_" . A_LoopField . ".ahk"
      FileDelete, %filename%
      FileAppend, %str%, %filename%
      Run "AutoHotkey.exe" "/f" %filename%, , , ahkpid
      WinWait, ahk_pid%ahkpid%
      FileDelete, %filename%
      
    }
    
  }
  
  Loop, Parse, tables, `,
  {
    DetectHiddenWindows, On
    WinGet, alreadyopen, id, _StarsAutoRebuy_%A_LoopField%.ahk 
    if (alreadyopen)
    {
      WinGetTitle, title, ahk_id%alreadyopen%
      continue
    }
    else
    {
      str := "#NoTrayIcon`n"
      str := str . "table_id := """ . A_LoopField . """`n"
      str := str . "justdone := 0`n"
      str := str . "screenname := """ . screenname  . """`n"
      str := str . "Loop`n"
      str := str . "{`n"
      str := str . "  IfWinNotExist, ahk_id%table_id%`n"
      str := str . "  {`n"
      str := str . "    ExitApp`n"
      str := str . "  }`n"
      str := str . "  WinGetTitle, title, ahk_id%table_id%`n"
      str := str . "  StringMid, bb, title, InStr(title, ""/"") + 1, InStr(title, a_space,"""", InStr(title, ""/"")) - InStr(title, ""/"") - 1`n"
      str := str . "  bb := StrRep(bb, ""$"")`n"
      str := str . "  desired_chips := bb * " . min_limit_bbs . "`n"
      str := str . "  StringTrimRight, title, title, (StrLen(title) - InStr(title, "" - "", true, 0))+1`n"
      str := str . "  est := A_NowUTC`n"
      str := str . "  est += " . timezone_difference_EST . ", hours`n"
      str := str . "  FormatTime, est, %est%, yyyyMMdd`n"
      str := str . "  filename := """ . filepath . hero . "\HH"" . est . "" "" . title . "".txt""`n"
      str := str . "  StringReplace, filename, filename, /, -`n"
      str := str . "  FileGetSize, fsize, %filename%`n"
      str := str . "  if (fsize)`n"
      str := str . "  {`n"
      str := str . "    FileGetTime, ftime, %filename%`n"
      str := str . "    if (ftime > oldftime)`n"
      str := str . "    {`n"
      str := str . "      Sleep, 40`n"
      str := str . "      oldftime := ftime`n"
      str := str . "      FileRead, hh, %filename%`n"
      str := str . "      StringTrimLeft, hh, hh, Instr(hh, ""PokerStars Game #"", true, 0)-1`n"
      str := str . "      StringTrimLeft, chips, hh, InStr(hh, screenname)`n"
      str := str . "      StringTrimLeft, chips, chips, InStr(chips, "" ("")+2`n"
      str := str . "      StringTrimRight, chips, chips, StrLen(chips) - InStr(chips, "" "")+1`n"
      str := str . "      if (justdone)`n"
      str := str . "      {`n"
      str := str . "        justdone := 0`n"
      str := str . "        continue`n"
      str := str . "      }`n"
      str := str . "      if (chips < desired_chips)`n"
      str := str . "      {`n"
      str := str . "        RebuyStars(table_id, " . rebuy_limit_bbs . ")`n"      
      str := str . "        justdone := 1`n"
      str := str . "      }`n"
      str := str . "    }`n"
      str := str . "  }`n"
      str := str . "Sleep, 40`n"
      str := str . "}`n"
      FileRead, fns, %A_ScriptFullPath%
      StringTrimLeft, fns, fns, InStr(fns, ";-------------- CHOP --------------;", true, 0)
      StringTrimLeft, fns, fns, InStr(fns, "`n")
      str := str . "`n`n" . fns
      filename := "_StarsAutoRebuy_" . A_LoopField . ".ahk"
      FileDelete, %filename%
      FileAppend, %str%, %filename%
      Run "AutoHotkey.exe" "/f" %filename%, , , ahkpid
      WinWait, ahk_pid%ahkpid%
      FileDelete, %filename%
      
    }
    
  }
return


getid()
{
  global act_only_on_active_table
  id := ""
  If (act_only_on_active_table = 1)
  {
    ;MsgBox, Active Table Mode
    WinGet,id,,A
  }
  Else
  {
    ;MsgBox, Table Under Cursor Mode
    MouseGetPos, , , id
  }
  return id
}

KillPopUps:
SetTitleMatchMode, 2
  
WinGet, id, id, PokerStars Lobby
WinGet, ps_pid, PID, ahk_id%id%

IfWinExist, PokerStars ahk_class #32770 ahk_pid%ps_pid%
{
  WinGet, idlist, list, PokerStars ahk_class #32770 ahk_pid%ps_pid%, , Lobby
  Loop, %idlist%
  {
    id := idlist%A_Index%
    WinGet, clist, ControlList, ahk_id%id%
    if (InStr(clist, "Button2"))
    {
      continue
    }
    else
    {
      ;WinGetText, wintxt, ahk_id%id%
      ;MsgBox, %wintxt%
      Loop, 20
      {
        ;MsgBox, hhdjsak
        ;WinActivate, ahk_id%id%
        ControlFocus, Button1, ahk_id%id%
        ControlSend, Button1, {SPACE}, ahk_id%id%
        Sleep, 100
        IfWinNotExist, ahk_id%id%
        {
          ;ControlClick, Button1, ahk_id%id%
          break
        }
      }
      Sleep, 20
    }
  }
}
return
; Below from RolandsFunctions.ahk - Slight alterations + added specify bb amount

;-------------- CHOP --------------;

RebuyStars(win, bbs)
{
  bb := 1
  PostStarsClick(400, 52, win)
  WinWait, % "Options ahk_class #32770",, 5
  If (errorLevel)
  {
    return
  }
  WinGet, id, id
  Sleep, 250
  SetTitleMatchMode 2
  If ( IsDisabledCtrl("Button4", id) )
  {
    WinClose, ahk_id%id%
    return
  }
  Loop, 5
  {  
    ControlFocus, Button4, ahk_id%id%
    ControlSend, Button4, {SPACE} ahk_id%id%
  } 
  Loop, 50
  {
    IfWinExist, Buy-in ahk_class #32770
    {
      WinGet, id2, id, Buy-in ahk_class #32770
      break
    }
    If WinExist("PokerStars", "Your rebuy cannot be processed")
    {
      WinClose
      return
    }
    Sleep, 100
  }
  If (!id2)
  {
    ;Msgbox, no id2
    return
  }
    
  if (bbs = "max")
  {
    /*
    amount := CtrlGetTxt("Allowed maximum", id2)
    StringTrimLeft, amount, amount, InStr(amount, ": ")+2
    amount := StrRep(amount, "$")
    */
    ControlSend, Button1, {SPACE}, ahk_id%id2%
    Loop, 100
    {
      c := 0
      ControlGet, c, Checked, ,Button1, ahk_id%id2%
      if (c)
      {
        break
      }
      ControlSend, Button1, {SPACE}, ahk_id%id2%
      Sleep, 20
    }
    ;ControlSend, Button3, {SPACE}, ahk_id%id2%
  }
  else
  {
    WinGetTitle, title, ahk_id%win%
    StringMid, bb, title, InStr(title, "/") + 1, InStr(title, a_space,"", InStr(title, "/")) - InStr(title, "/") - 1
    bb := StrRep(bb, "$")
    amount := bbs * bb
  }
  ;Msgbox, %amount%
  ControlSetText, Edit1, %amount%
  Loop, 10
  {
    ;ControlFocus, Button4, ahk_id%id2%
    ControlSend, Button3, {SPACE}, ahk_id%id2%
    Sleep, 20
  }
  
}


IsDisabledCtrl(ctrl,win,matchMode=1) {
mm = %a_titleMatchMode%
SetTitleMatchMode %matchMode%
ControlGet, enabled, Enabled,, %ctrl%, ahk_id%win%
SetTitleMatchMode %mm%
return !enabled
}

CtrlGetTxt(ctrl,win,matchMode=1) {
mm = %a_titleMatchMode%
SetTitleMatchMode %matchMode%
ControlGetText, text, %ctrl%, ahk_id%win%
SetTitleMatchMode %mm%
return text
}

StrRep(str,char,rep_char="",all=1) {
StringReplace,str,str,%char%,%rep_char%,%all%
return str
}

PostStarsClick(x, y, win) {
static border,caption
If ! border {
    SysGet, border, 32
    SysGet, caption, 4
    caption := border + caption
  }
WinGetPos,,,w,h,ahk_id%win%
x := x/792*(w-border*2)
y := y/546*(h-(caption+border))
PostLeftClick(x, y, win)
}

;Juks rocks
PostLeftClick(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, 0x201, 0x0001, ((y<<16)^x), , ahk_id%table_id%
PostMessage, 0x202 , 0, ((y<<16)^x), , ahk_id%table_id%
}






CategoryAutoHotKey

StarsAutoReloader (last edited 2008-08-17 02:17:39 by MogobuTheFool)