Advertisement
HawkenX

Crash Recovery

May 22nd, 2015
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Written by LemonFrosting
  2. ;With the help from OiJkN
  3. ;all comments refer to lines below
  4. #SingleInstance, Force
  5. #Persistent
  6. #InstallKeybdHook
  7. #UseHook, On
  8. #Include ./Ranger Recovery/FindClick.ahk
  9. ;http://www.autohotkey.com/board/topic/89592-findclick-2nd-edition/
  10. ;#NoTrayIcon
  11.  
  12.  
  13. ;run as admin and get vars from ini file sets mouse speed to fastest.
  14. RunAsAdmin()
  15.  
  16. ExeName()               ;<== call the function to rename the app // ADDED
  17. Menu, Tray, Icon , %A_WorkingDir%/Ranger Recovery/Icon.ico, 1, 1
  18.  
  19. sysget,PriMon,Monitorprimary
  20. sysget,PriMon,Monitor,,
  21. ;;Default Vars if no ini file present.
  22. gui1in = 0
  23. gui2in = 10
  24. gui3in = 1
  25. gui4in = 15
  26. gui5in = 5
  27. gui6in = 10
  28. gui7in = C:\Program Files (x86)\Battle.net\Battle.net.exe
  29. gui8in = HearthRanger.exe
  30. gui9in =
  31. gui10in = ExternBot\silverfish\Silver.exe
  32. gui11in = 1
  33. gui12in = 1
  34. gui13in = 1
  35. gui14in = 1
  36. gui15in = 1
  37. gui16in := 100
  38. gui17in := 100
  39.  
  40. ;version number var
  41. versionnum = 1.5
  42. ;mousemove Coordinate mode.
  43. coordmode,mouse,screen
  44. ;Global starting vars
  45. SetDefaultMouseSpeed,0
  46. readvarsfromfile()
  47. UserConfig_a = o20,TransBlack
  48. ClickContinue = 1
  49. BotStarted = 0
  50. PausedBot = 0
  51. Pausex := 249
  52. Controlsy := 150
  53. Playx := 210
  54. AutoStopAfter = 1
  55. AppName .= ExeName()    ;<== set the name of the app // ADDED
  56. CrashCounterInt = -1    ;<== set the counter // ADDED
  57.  
  58. ;GUI self explanotory
  59. GUIsub:
  60. Gui, Show ,W530 H400 x%gui16in% y%gui17in%,%AppName%    ; <== %AppName% // ADDED
  61. Gui, Color, dddddd
  62. Gui, Font, s14 c212121,Arial
  63. Gui, Add, Text,x16 y16,Ranger Crash Recovery
  64. Gui, Font, s10
  65. Gui, Add, Text,x405 y10 ,Bot Status:
  66. Gui, Add, Text, x405 y25 h12 vBotStatusGui cRed, Script not running
  67. Gui, Add, Text,x255 y10 ,Number of Crashes:                         ; <== Text Number of Crashes // ADDED
  68. Gui, Add, Text, x375 y10 h12 cRed vCrachCounter, %CrashCounterInt%  ; <== Value of crashes // ADDED
  69. GuiControl,Hide,%CrashCounterInt%                                   ; <== Hide the negative counter value // ADDED
  70. Gui, Add, Button, x320 y11 h30 w80 vSkipBreakBtn gskipBreak, Skip Break
  71. guicontrol,hide,SkipBreakBtn
  72. Gui, Add, Button, x376 y59 w140 h40 default vStartBtnBtn gStartBot, Start
  73. Gui, Add, Button, x376 y99 w140 h40 vPauseBot gExecFunc, Pause
  74. GuiControl,Disable,PauseBot
  75. Gui, Add, Checkbox, Checked%gui12in% vgui12out x378 y139,Pause bot too?
  76. Gui, Add, Button, c323232 x376 y159 w140 h40 vRestartBtn gExecFunc, Restart
  77. Gui, Add, Button, x376 y199 w140 h40 gSaveVars, Save Settings
  78. gui, add, text, x16 y45 w502 0x10
  79. Gui, Add, Checkbox,checked%gui11in% x376 y250 w140 vgui11out ,Close Battle net after Hearthstone launch?
  80. Gui, Add, Checkbox,checked%gui1in% x376 y310 w140 vgui1out ,Start Hearthstone Deck Tracker?
  81. Gui, Add, Checkbox,checked%gui2in% x376 y350 w140 vgui2out ,Check this if you use Silver.exe
  82. Gui, Add, Text, x14 y380,Ver %versionnum%
  83. Gui, Add, Tab2,x10 y64 h310, Settings|Paths|About
  84.  
  85. Gui, Tab, 1
  86. Gui, Font, s8
  87. Gui, Add, CheckBox,checked%gui13in% x45 y100 vgui13out, Close the Bot when auto stop condition met
  88. Gui, Add, CheckBox,checked%gui14in% x45 y120 vgui14out, Close the Game when auto stop condition met
  89. Gui, Add, CheckBox,checked%gui15in% x45 y140 vgui15out, Close Recovery when auto stop condition met
  90. Gui, Add, CheckBox,checked%gui3in% vgui3out x45 y170,Take breaks between games?
  91. Gui, Add, Edit, x16 y190 w45 h20,Percent Chance
  92. Gui, Add, UpDown,vgui4out, %gui4in%
  93. Gui, Add, Text,x66 y193,Percent chance to take a break after each game
  94. Gui, Add, Edit, x16 y220 w45 h20, Min break time
  95. Gui, Add, UpDown, vMinTime vgui5out, %gui5in%
  96. Gui, Add, Edit, x16 y240 w45 h20, Max break time
  97. Gui, Add, UpDown, vMaxTime vgui6out, %gui6in%
  98. Gui, Add, Text, x66 y230,Range in minutes for breaks
  99.  
  100. Gui, Tab, 2
  101. Gui, Add, Text, x20 y100,Location of Battle.net.exe:
  102. Gui, Add, Edit, x20 y120 w330 h20 vBattleLauncher,%gui7in%
  103. Gui, Add, Text, x20 y150,Location of HearthRanger.exe:
  104. Gui, Add, Edit, x20 y170 w330 h20 vHearthRangerPath,%gui8in%
  105. Gui, Add, Text, x20 y200,Location of Deck/Stat Tracker.exe:
  106. Gui, Add, Edit, x20 y220 w330 h20 vDeckTracker,%gui9in%
  107. Gui, Add, Text, x20 y250,Location of Silver.exe:
  108. Gui, Add, Edit, x20 y270 w330 h20 vSilverLoc,%gui10in%
  109. Gui, Add, Text, x20 y300 w330,Note: Please put the full path including the EXE files into the text box.`nIt will automatically strip quote marks so use copy as path in windows explorer (Shift right click a file and press copy as path).
  110.  
  111. Gui, Tab, 3
  112. Gui, Font, s12
  113. Gui, Add, Text, x20 y100,Ranger Crash Recovery ver %versionnum%
  114. Gui, Add, Text, x20 y130,Written by Lemon Frosting(Jammo2k5) with `nhelp from OiJkN.
  115. Gui, Font,s10
  116. Gui, Add, Text, x20 y180, Intructions for use:`n1. Set your settings in the settings tab.`n2. Set your paths to the programs you want to launch `nin the paths tab.`n3. Press the start button and let it do it's thing.
  117. ;pulls in command line arguments and checks for -r only
  118. loop %0%
  119. {
  120.     If %A_Index% = -r
  121.     {
  122.         gosub,StartBot
  123.     }
  124. }
  125. Return
  126.  
  127. ;emergencey restart sub routine.
  128. ^F10::
  129. gosub,SaveVars
  130. Reload
  131. return
  132.  
  133. skipBreak:
  134. SkipSleep = 1
  135. return
  136.  
  137.  
  138. ;Start button sub routine
  139. StartBot:
  140. gosub,SaveVars
  141. MainFunc()
  142. return
  143.  
  144. ;Saves all variables to the ini file. reads them back to filter "" and such other nonsence and resaves them.
  145. SaveVars:
  146. gui,submit,nohide
  147. rememberposition()
  148. SaveVars()
  149. return
  150.  
  151. ;this saves all vars on closing of the GUI.
  152. GuiClose:
  153. gosub,SaveVars
  154. ExitApp
  155.  
  156. ;Subroutine to launch functions from buttons vValue.
  157. ExecFunc:
  158. gosub,SaveVars
  159. %A_GuiControl%()
  160. return
  161.  
  162. ;Main loop function ########Needs to be cleaned up##########
  163. MainFunc()
  164. {
  165.     global
  166.     readvarsfromfile()
  167.     PausedBot = 0
  168.     GuiControl,Disable,StartBtnBtn
  169.     GuiControl,Enable,PauseBot
  170.     LogLast := ReadLog(20)
  171.     ;Resumes bot if paused
  172.     while PausedBot = 0
  173.     {  
  174.         LogLast := ReadLog(20)
  175.         ifinstring,LogLast,Bot paused
  176.         {  
  177.             sleep 2000
  178.             ;msgbox, botpaused found
  179.             LogLast2 := ReadLog(20)
  180.             ;If (InStr(LogLast,Bot paused,false,0) > InStr(LogLast,Bot is running,false,0))
  181.             if (LogLast2 = LogLast)
  182.             {
  183.                 StartRanger(Pausex,Controlsy)
  184.                 BotStatusMod("Running","Green")
  185.                 ;msgbox, Ranger should be running ID1
  186.             }
  187.         }
  188.         DelLogs()
  189.         BotStatusMod("Starting Game","Blue")
  190.         CheckIfExist(BattleLauncher,"Battle.net")
  191.         CheckIfExist(HearthRangerPath,"Ranger")
  192.         If PausedBot = 1
  193.         {
  194.             BotStatusMod("Script paused","Yellow")
  195.             If gui12in = 1
  196.             {
  197.                 BotStatusMod("Bot user paused","Yellow")
  198.             }
  199.             exit
  200.         }
  201.         If gui1in = 1
  202.         {
  203.             CheckIfExist(DeckTracker,"Tracker")
  204.         }
  205.         if gui2in = 1
  206.         {
  207.             CheckIfExist(SilverLoc,"Silver.exe")
  208.         }
  209.         GuiControl,Enable,PauseBtn
  210.         process,exist,Hearthstone.exe
  211.         if (ErrorLevel = 0)
  212.         {
  213.             StartGame()
  214.         }
  215.         If PausedBot = 1
  216.         {
  217.             BotStatusMod("Script paused","Yellow")
  218.             If gui12in = 1
  219.             {
  220.                 BotStatusMod("Bot user paused","Yellow")
  221.             }
  222.             exit
  223.         }
  224.         If gui1out = 1
  225.         {
  226.             BotStatusMod("Starting Tracker","Blue")
  227.             Ifexist %DeckTracker%
  228.             {
  229.                 Run, %DeckTracker%,%Trackerpath%,,DeckTrackerPID
  230.             }
  231.         }
  232.         If PausedBot = 1
  233.         {
  234.             BotStatusMod("Script paused","Yellow")
  235.             If gui12in = 1
  236.             {
  237.                 BotStatusMod("Bot user paused","Yellow")
  238.             }
  239.             exit
  240.         }
  241.         If gui2in = 1
  242.         {
  243.             BotStatusMod("Starting Silver.exe","Blue")
  244.             IfExist,%SilverLoc%
  245.             {
  246.                 process,Exist,Silver.exe
  247.                 If (ErrorLevel = 0)
  248.                 {
  249.                     Run,%SilverLoc%,%Silverpath%
  250.                 }
  251.             }
  252.         }
  253.         if pausedbot = 1
  254.         {
  255.             BotStatusMod("Script paused","Yellow")
  256.             If gui12in = 1
  257.             {
  258.                 BotStatusMod("Bot user paused","Yellow")
  259.             }
  260.             exit
  261.         }
  262.         process,exist,HearthRanger.exe
  263.         if (ErrorLevel = 0)
  264.         {
  265.             DelLogs()
  266.             BotStatusMod("Starting Bot","Blue")
  267.             Run, %HearthRangerPath%,%Rangerpath%
  268.         }
  269.         if pausedbot = 1
  270.         {
  271.             BotStatusMod("Script paused","Yellow")
  272.             If gui12in = 1
  273.             {
  274.                 BotStatusMod("Bot user paused","Yellow")
  275.             }
  276.             exit
  277.         }
  278.         if pausedbot = 1
  279.         {
  280.             BotStatusMod("Script paused","Yellow")
  281.             If gui12in = 1
  282.             {
  283.                 BotStatusMod("Bot user paused","Yellow")
  284.             }
  285.             exit
  286.         }
  287. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;second loop
  288.         while PausedBot = 0
  289.         {
  290.             BotStatusMod("Running","Green")
  291.             readvarsfromfile()
  292.             If gui11out = 1
  293.             {
  294.                 process,close,Battle.net.exe
  295.             }
  296.             If LogLast = `n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n
  297.             {
  298.                 process,exist,HearthRanger.exe
  299.                 if (ErrorLevel = 0)
  300.                 {                  
  301.                     BotStatusMod("Restarting bot","Blue")
  302.                     DelLogs()
  303.                     Run, %HearthRangerPath%,%Rangerpath%
  304.                 }
  305.                 StartRanger(Playx,Controlsy)
  306.                 ;msgbox, Ranger should be running ID4
  307.                 BotStatusMod("Running","Green")
  308.             }
  309.             LogLast := ReadLog(1)
  310.            
  311.                
  312.                 IfInString, LogLast,Please start game
  313.                 {
  314.                     IfWinNotExist Hearthstone
  315.                     {
  316.                     StartGame()
  317.                     }
  318.                 }
  319.                
  320.            
  321.             LogLast := ReadLog(20)
  322. ;;;
  323.            
  324.             If gui3in = 1
  325.             {
  326.                 IfNotInString, LogLast, Click to continue ret=True
  327.                 {
  328.                     ClickContinue = 0
  329.                 }      
  330.                 IfInString, LogLast, Click to continue ret=True
  331.                 {
  332.                     If ClickContinue = 0
  333.                     {
  334.                         Random,BreakRand,1,100
  335.                         If (BreakRand <= gui4in)
  336.                         {  
  337.                             BotStatusMod("Pausing","Blue")
  338.                             process,close,Hearthranger.exe
  339.                             ;msgbox, Ranger should be paused ID5
  340.                             SleepFunc(gui5in,gui6in)
  341.                             BotStatusMod("Un Pausing","Blue")
  342.                             DelLogs()
  343.                             Run, %HearthRangerPath%,%Rangerpath%
  344.                             StartRanger(Playx,Controlsy)
  345.                             LogLast := ReadLog(2)
  346.                             LogLastCompare := ReadLog(2)
  347.                             while LogLast = LogLastCompare
  348.                             {
  349.                                 StartRanger(Playx,Controlsy)
  350.                                 sleep 1000
  351.                                 LogLastCompare := LogLast
  352.                                 LogLast := ReadLog(2)
  353.                             }
  354.                             ;msgbox, Ranger should be running ID6
  355.                             BotStatusMod("Running","Green")
  356.                         }
  357.                     }
  358.                     ClickContinue = 1
  359.                 }
  360.             }
  361.             process,exist,HearthRanger.exe
  362.             if (ErrorLevel = 0)
  363.             {
  364.                 BotStatusMod("Restarting Bot","Blue")
  365.                 DelLogs()
  366.                 Run, %HearthRangerPath%,%Rangerpath%
  367.             }
  368.             process,exist,Hearthstone.exe
  369.             if (ErrorLevel = 0)
  370.             {
  371.                 BotStatusMod("Restarting Game","Blue")
  372.                 StartGame()
  373.             }
  374.             LogLast := ReadLog(20)
  375.             IfInString, LogLast ,Bot stopped
  376.             {
  377.                 sleep 500
  378.                 LogLast := ReadLog(2)
  379.                 IfInString, LogLast ,auto stop
  380.                 {
  381.                     if StartedRanger = 1
  382.                     {
  383.                         Ifinstring,LogLast,auto stop bot - stop bot after current game
  384.                         {
  385.                             BotStatusMod("Script not running","Red")
  386.                             GuiControl,Enable,StartBtnBtn
  387.                             GuiControl,Disable,PauseBot
  388.                             AutoStopAfter = 1
  389.                             exit
  390.                         }
  391.                         else
  392.                         {
  393.                             CloseDown(gui15out)
  394.                         }
  395.                         StartedRanger = 0
  396.                     }
  397.                     Else
  398.                     {  
  399.                         StartRanger(Playx,Controlsy)
  400.                     }
  401.                 }
  402.                 else
  403.                 {
  404.                     ;Restartbot()
  405.                     break      
  406.                 }
  407.             }
  408.             LogLast2 := ReadLog(20)
  409.             sleep 2000
  410.             LogLast := ReadLog(20)
  411.             emptyLog = `n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n
  412.             /*
  413.             If (LogLast != emptyLog)
  414.             {
  415.                 if (LogLast2 = LogLast)
  416.                 {
  417.                     sleep 300000
  418.                     LogLast2 := ReadLog(20)
  419.                     if (LogLast2 = LogLast)
  420.                     {
  421.                         process,close,Hearthstone.exe
  422.                     }
  423.                 }
  424.             }
  425.             */
  426.         }
  427.         if pausedbot = 1
  428.         {
  429.             BotStatusMod("Script paused","Yellow")
  430.             If gui12in = 1
  431.             {
  432.                 BotStatusMod("Bot user paused","Yellow")
  433.             }
  434.             exit
  435.         }
  436.         controlclick,,Hearthstone,,Left
  437.     }
  438. }
  439.  
  440. ;Start battle launcher and launch the game ########currently relies on
  441. ;hearthstone being the selected game want to add selecting hearthstone in the future
  442. StartGame()
  443. {
  444.  
  445.     global
  446.     CountCrash()            ; <== Call the function to count number of crashes // ADDED
  447.     attempts:=0
  448.     IfWinExist Hearthstone
  449.     {
  450.     return 
  451.     }
  452.     process,exist,Battle.net.exe
  453.     if (ErrorLevel = 0) ; if Battle.net isnt open
  454.     {
  455.     Run %BattleLauncher%
  456.     }
  457.     process,exist,Battle.net.exe
  458.     if (ErrorLevel > 0) ; if Battle.net exists
  459.     {
  460.         process,exist,Hearthstone.exe
  461.         While (ErrorLevel = 0) ;while Hearthstone does not exist, keep trying to open it
  462.         {
  463.            
  464.             process,exist,Battle.net.exe
  465.             if (ErrorLevel > 0)
  466.             {
  467.                
  468.                 FindClick("./Ranger Recovery/play.png","!a rBattle.net Silent1")
  469.                 ;MsgBox ,Trying to open game
  470.                 process,exist,Hearthstone.exe
  471.                 if (ErrorLevel > 0)
  472.                 {
  473.                     Break
  474.                 }
  475.                 WinGetTitle, title, A
  476.                 WinMove,Battle.net,,0,0,1,1
  477.                 Wingetpos,Bx,By,BattleWidth,,Battle.net
  478.                 DPIScaleMod := BattleWidth/720
  479.                 Winactivate,Battle.net
  480.                 MouseGetPos, xpos, ypos
  481.                 Mouseclick,left,Bx+(290*DPIScaleMod),By+(477*DPIScaleMod)
  482.                 MouseMove, xpos, ypos , 1
  483.                 winactivate,% title
  484.                 Sleep 100
  485.                 attempts++
  486.                 if (attempts>30) ;if battle.net is frozen or something's wrong
  487.                 {
  488.                     process,close,Battle.net.exe
  489.                     Run %BattleLauncher%
  490.                     Sleep,5000
  491.                     StartGame()
  492.                 }
  493.             }
  494.            
  495.         }   ;Hearthstone is opened
  496.        
  497.         if pausedbot = 1
  498.         {
  499.             exit
  500.         }
  501.         sleep 1000
  502.        
  503.         StartRanger(Playx,Controlsy)
  504.     }
  505.    
  506.     ;process,close,Battle.net.exe
  507.    
  508. }
  509.  
  510. ;Pauses the bot
  511. PauseBot()
  512. {
  513.     global
  514.     readvarsfromfile()
  515.     BotStatusMod("Script paused","Yellow")
  516.     GuiControl,Enable,StartBtnBtn
  517.     GuiControl,Disable,PauseBot
  518.     If gui12in = 1
  519.     {
  520.         Loop
  521.         {
  522.             LogLast := ReadLog(20)
  523.             if StartedRanger = 1
  524.             {
  525.                 If LogLast = `n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n
  526.                 {
  527.                     BotStatusMod("Pausing ASAP","Blue")
  528.                     sleep 10000
  529.                 }
  530.                 else ifinstring,LogLast,Please wait, checking
  531.                 {
  532.                     BotStatusMod("Pausing ASAP","Blue")
  533.                     LogLast := ReadLog(20)
  534.                     ifinstring,LogLast,Login success
  535.                     {
  536.                         sleep 1000
  537.                         StartRanger(Pausex,Controlsy)
  538.                         BotStatusMod("Paused","Yellow")
  539.                         ;msgbox, Ranger should be paused ID9
  540.                         break
  541.                     }
  542.                     sleep 1000
  543.                 }
  544.                 else
  545.                 {
  546.                     StartRanger(Pausex,Controlsy)
  547.                     ;msgbox, Ranger should be paused ID10
  548.                     BotStatusMod("Paused","Yellow")
  549.                     break
  550.                 }
  551.             }          
  552.         }
  553.     }
  554.     PausedBot = 1
  555.    
  556. }
  557.  
  558. ;checks if ranger is working if not checks if it is running and if not it will launch it.
  559. CheckIfRangerRunning()
  560. {
  561.     LogLast := ReadLog(20)
  562.     If LogLast = `n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n
  563.     {
  564.         process,exist,HearthRanger.exe
  565.         if (ErrorLevel = 0)
  566.         {
  567.             DelLogs()
  568.             Run, %HearthRangerPath%,%Rangerpath%
  569.         }
  570.     }
  571. }
  572.  
  573. ;log cleaning ########### Change code to make deleting logs obselete and chose last created log and open that instead.########
  574. DelLogs()
  575. {
  576.     FileRemoveDir,%Rangerpath%task_log,1
  577.     FileCreateDir,%Rangerpath%task_log
  578. }
  579.  
  580. ; clicks the play button on Ranger
  581. StartRanger(Bx,By)
  582. {  
  583.     global
  584.     StartedRanger = 1
  585.     WinGetTitle, title, A
  586.     Process Exist,HearthRanger.exe
  587.     RangerPID := ErrorLevel
  588.    
  589.     WinGetPos,Rx,Ry,Rangerwidth,Rangerheight,ahk_pid %RangerPID%
  590.     winactivate,ahk_pid %RangerPID%
  591.     rangerscalemod := Rangerwidth/500
  592.     ;msgbox % rangerscalemod
  593.     MouseGetPos, xpos, ypos
  594.     Mouseclick,left,Rx+(Bx*rangerscalemod),Ry+(By*rangerscalemod)
  595.     ;MouseMove, xpos, ypos , 1
  596.     Winactivate,% title
  597. }
  598.  
  599. ;Shuts down everything on bot auto stop########add check for autostop after current game.
  600. CloseDown(fullclose)
  601. {
  602.     global
  603.     BotStatusMod("Stopping","Blue")
  604.     if gui14out = 1
  605.     {
  606.         process,close,Battle.net.exe
  607.         process,close,Hearthstone.exe
  608.         FileAppend, gui4, D:\Downloads\Hearthranger_v.3.2.0\HearthRanger\output.txt
  609.     }
  610.     if gui13out = 1
  611.     {
  612.         process,close,Hearthranger.exe
  613.         Process,close,silver.exe
  614.         Process,Close,%TrackerProcess%
  615.         FileAppend, gui3, D:\Downloads\Hearthranger_v.3.2.0\HearthRanger\output.txt
  616.         }
  617.     If fullclose = 1
  618.     {
  619.         exitapp
  620.     }
  621.     BotStatusMod("Not Running","Red")
  622.     GuiControl,Enable,StartBtnBtn
  623.     GuiControl,Disable,PauseBot
  624.     exit
  625. }
  626.  
  627. ; Reads the last K lines of the Hearthranher%date%.log and returns it
  628. ReadLog(k)
  629. {
  630.     loop,%A_WorkingDir%/task_log/HearthRanger*.log
  631.     {
  632.         Loop Read,%A_WorkingDir%/task_log/%A_LoopFileName%
  633.         {
  634.             i := Mod(A_Index,k)
  635.             L%i% = %A_LoopReadLine%
  636.         }
  637.         L := L%i%
  638.         Loop % k-1
  639.         {
  640.             IfLess i,1, SetEnv i,%k%
  641.             i--      
  642.             L := L%i% "`n" L
  643.         }
  644.         Return L
  645.     }
  646. }
  647.  
  648. ;This is the bot status updater
  649. BotStatusMod(status,color)
  650. {
  651.     Gui,Font,c%color% s10
  652.     GuiControl,Font,BotStatusGui
  653.     GuiControl,text,BotStatusGui,%Status%
  654.  
  655. }
  656.  
  657. ;checks if a program exists if not it will send a message and status notif
  658. CheckIfExist(path,name)
  659. {  
  660.     Ifnotexist %path%
  661.     {  
  662.         GuiControl,Enable,StartBtnBtn
  663.         GuiControl,Disable,PauseBot
  664.         BotStatusMod("Check "name,"Red")
  665.         msgbox,Please make sure the %name% path is correct in the Path tab.
  666.         exit
  667.     }
  668. }
  669.  
  670. ;this saves all the GUI vars to an INI file.
  671. SaveVars()
  672. {
  673.     global
  674.     FileDelete,%A_WorkingDir%\Ranger Recovery\RangerRecovery.ini
  675.     FileAppend,%gui1out%`n%gui2out%`n%gui3out%`n%gui4out%`n%gui5out%`n%gui6out%`n%BattleLauncher%`n%HearthRangerPath%`n%DeckTracker%`n%SilverLoc%`n%gui11out%`n%gui12out%`n%gui13out%`n%gui14out%`n%gui15out%`n%gui16out%`n%gui17out%`n      ,%A_WorkingDir%\Ranger Recovery\RangerRecovery.ini
  676.    
  677. }
  678.  
  679. ;this reads all vars from the INI file and trims the "fat"
  680. readvarsfromfile()
  681. {
  682.     global
  683.     i = 0
  684.     loop 17
  685.     {
  686.     i++
  687.     FileReadLine, gui%i%in, %A_WorkingDir%\Ranger Recovery\RangerRecovery.ini,%i%
  688.     }
  689.     StringReplace,BattleLauncher,gui7in,",,All
  690.     StringReplace,HearthRangerPath,gui8in,",,All
  691.     StringReplace,DeckTracker,gui9in,",,All
  692.     StringReplace,SilverLoc,gui10in,",,All
  693.     SplitPath,HearthRangerPath,,Rangerpath
  694.     SplitPath,DeckTracker,TrackerProcess,Trackerpath
  695.     SplitPath,SilverLoc,,Silverpath
  696. }
  697.  
  698. ;This restarts the bot, game and all supporting programs
  699. RestartBot()
  700. {
  701.     global
  702.     SaveVars()
  703.     process,close,Hearthranger.exe
  704.     process,close,Hearthstone.exe
  705.     process,close,Battle.net.exe
  706.     Process,close,silver.exe
  707.     Process,Close,%TrackerProcess%
  708. }
  709.  
  710. ;This is the random sleep function
  711. SleepFunc(x,y)
  712. {  
  713.     global
  714.     GuiControl,Enable,StartBtnBtn
  715.     GuiControl,Disable,PauseBot
  716.     Random,BreakTime,%x%,%y%
  717.     TimeLeft := BreakTime*60
  718.     guicontrol,Show,SkipBreakBtn
  719.     loop %TimeLeft%
  720.     {
  721.         BotStatus := % "Paused for " FormatSeconds(TimeLeft-1)
  722.         BotStatusMod(BotStatus,"Yellow")
  723.         sleep 1000
  724.         TimeLeft--
  725.         if Skipsleep = 1
  726.         {
  727.             Break
  728.         }
  729.     }
  730.     skipsleep = 0
  731.     guicontrol,hide,SkipBreakBtn
  732.     GuiControl,disable,StartBtnBtn
  733.     GuiControl,enable,PauseBot
  734. }
  735.  
  736. ; Formats the time into mm:ss for the status
  737. FormatSeconds(NumberOfSeconds)
  738. {
  739.     time = 19990101  ; *Midnight* of an arbitrary date.
  740.     time += %NumberOfSeconds%, seconds
  741.     FormatTime, mmss, %time%, mm:ss
  742.     return mmss  ; This method is used to support more than 24 hours worth of sections.
  743. }
  744.  
  745. ;this is the restart button func
  746. RestartBtn()
  747. {
  748.     global
  749.     rememberposition()
  750.     gosub,savevars
  751.     msgbox,3,Kill Bot and Game?,Do you want to Restart HearthRanger and Hearthstone too?`nThey can be restarted automatically by starting recoery when it reloads.
  752.     Ifmsgbox yes
  753.     {
  754.         SaveVars()
  755.         process,close,Battle.net.exe
  756.         process,close,Hearthstone.exe
  757.         process,close,Hearthranger.exe
  758.         Process,close,silver.exe
  759.         Process,Close,%TrackerProcess%
  760.         Reload
  761.     }
  762.     ifmsgbox no
  763.     {
  764.         Reload
  765.     }
  766. }
  767.  
  768. ;More comprehensive argument check.
  769. getParams:
  770.     Loop, %0% ; for each parameter
  771.     {
  772.         param := %A_Index%
  773.         ; check for switches
  774.         StringLeft, paramType, param, 1
  775.         If (paramType = - or paramType = /)
  776.         {
  777.             ; determine type of switch
  778.             StringMid, switch, param, 2, 1
  779.             ; settings file switch
  780.             If switch = s
  781.             {
  782.                 ; access value (= next parameter)
  783.                 param = % A_Index + 1
  784.                 file_settings := %param%
  785.                 MsgBox, settings file:`n%file_settings%
  786.             }
  787.         }
  788.     }
  789. Return
  790.  
  791. rememberposition()
  792. {
  793.     global
  794.     wingetpos,gui16out,gui17out,,,%AppNAme%,,-
  795. }
  796.  
  797. ;Run program as admin.
  798. RunAsAdmin()
  799. {
  800. global
  801.   Loop, %0%  ; For each parameter:
  802.     {
  803.       param := %A_Index%  ; Fetch the contents of the variable whose name is contained in A_Index.
  804.       params .= A_Space . param
  805.     }
  806.   ShellExecute := A_IsUnicode ? "shell32\ShellExecute":"shell32\ShellExecuteA"
  807.        
  808.   if not A_IsAdmin
  809.   {
  810.       If A_IsCompiled
  811.          DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_ScriptFullPath, str, params , str, A_WorkingDir, int, 1)
  812.       Else
  813.          DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_AhkPath, str, """" . A_ScriptFullPath . """" . A_Space . params, str, A_WorkingDir, int, 1)
  814.       exitapp
  815.   }
  816. }
  817.  
  818. ExeName()                                                               ;<== Function to return a random name for the app //ADDED
  819. {
  820.     var_Types := "alnum"
  821.  
  822.     Loop, Parse, var_Types, `,
  823.     {
  824.       var_result := ""
  825.         var_result .= RandomVar(6,12,A_LoopField)
  826.     }
  827.     return var_result
  828. }
  829.  
  830. RandomVar(p_MinLength,p_MaxLength,p_Type="",p_MinAsc=32,p_MaxAsc=126)   ;<== Function to randomize // ADDED
  831. {
  832.   StringReplace,p_Type,p_Type,!,,All
  833.   l_Neg := !ErrorLevel
  834.   StringReplace,p_Type,p_Type,#,@,All
  835.   l_Cse := !ErrorLevel
  836.   StringReplace,p_Type,p_Type,@,,All
  837.   l_Rep := !ErrorLevel
  838.   Random, l_Aux, %p_MinLength%, %p_MaxLength%
  839.   Loop, %l_Aux% {
  840.     Loop {
  841.       Random, l_Aux, %p_MinAsc%, %p_MaxAsc%
  842.       l_Aux := Chr(l_Aux)
  843.       If ( !l_Rep ) OR ( l_Rep AND !InStr(l_Output,l_Aux,l_Cse) ) {
  844.         If p_Type not in integer,number,digit,xdigit,alpha,upper,lower,alnum,space
  845.           break
  846.         Else
  847.           If l_Neg {
  848.             If l_Aux is not %p_Type%
  849.               break
  850.           }
  851.           Else
  852.             If l_Aux is %p_Type%
  853.               break
  854.       }
  855.     }
  856.     l_Output .= l_Aux
  857.   }
  858.   return l_Output
  859. }
  860.  
  861. CountCrash()                                                        ; <== Function to count // ADDED
  862. {  
  863.     Global
  864.     CrashCounterInt++    ;this increases Counter value by 1
  865.     GuiControl,Show,CrachCounter
  866.     GuiControl,,CrachCounter,%CrashCounterInt%
  867. }
  868. F9::pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement