Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Written by LemonFrosting
- ;With the help from OiJkN
- ;all comments refer to lines below
- #SingleInstance, Force
- #Persistent
- #InstallKeybdHook
- #UseHook, On
- #Include ./Ranger Recovery/FindClick.ahk
- ;http://www.autohotkey.com/board/topic/89592-findclick-2nd-edition/
- ;#NoTrayIcon
- ;run as admin and get vars from ini file sets mouse speed to fastest.
- RunAsAdmin()
- ExeName() ;<== call the function to rename the app // ADDED
- Menu, Tray, Icon , %A_WorkingDir%/Ranger Recovery/Icon.ico, 1, 1
- sysget,PriMon,Monitorprimary
- sysget,PriMon,Monitor,,
- ;;Default Vars if no ini file present.
- gui1in = 0
- gui2in = 10
- gui3in = 1
- gui4in = 15
- gui5in = 5
- gui6in = 10
- gui7in = C:\Program Files (x86)\Battle.net\Battle.net.exe
- gui8in = HearthRanger.exe
- gui9in =
- gui10in = ExternBot\silverfish\Silver.exe
- gui11in = 1
- gui12in = 1
- gui13in = 1
- gui14in = 1
- gui15in = 1
- gui16in := 100
- gui17in := 100
- ;version number var
- versionnum = 1.5
- ;mousemove Coordinate mode.
- coordmode,mouse,screen
- ;Global starting vars
- SetDefaultMouseSpeed,0
- readvarsfromfile()
- UserConfig_a = o20,TransBlack
- ClickContinue = 1
- BotStarted = 0
- PausedBot = 0
- Pausex := 249
- Controlsy := 150
- Playx := 210
- AutoStopAfter = 1
- AppName .= ExeName() ;<== set the name of the app // ADDED
- CrashCounterInt = -1 ;<== set the counter // ADDED
- ;GUI self explanotory
- GUIsub:
- Gui, Show ,W530 H400 x%gui16in% y%gui17in%,%AppName% ; <== %AppName% // ADDED
- Gui, Color, dddddd
- Gui, Font, s14 c212121,Arial
- Gui, Add, Text,x16 y16,Ranger Crash Recovery
- Gui, Font, s10
- Gui, Add, Text,x405 y10 ,Bot Status:
- Gui, Add, Text, x405 y25 h12 vBotStatusGui cRed, Script not running
- Gui, Add, Text,x255 y10 ,Number of Crashes: ; <== Text Number of Crashes // ADDED
- Gui, Add, Text, x375 y10 h12 cRed vCrachCounter, %CrashCounterInt% ; <== Value of crashes // ADDED
- GuiControl,Hide,%CrashCounterInt% ; <== Hide the negative counter value // ADDED
- Gui, Add, Button, x320 y11 h30 w80 vSkipBreakBtn gskipBreak, Skip Break
- guicontrol,hide,SkipBreakBtn
- Gui, Add, Button, x376 y59 w140 h40 default vStartBtnBtn gStartBot, Start
- Gui, Add, Button, x376 y99 w140 h40 vPauseBot gExecFunc, Pause
- GuiControl,Disable,PauseBot
- Gui, Add, Checkbox, Checked%gui12in% vgui12out x378 y139,Pause bot too?
- Gui, Add, Button, c323232 x376 y159 w140 h40 vRestartBtn gExecFunc, Restart
- Gui, Add, Button, x376 y199 w140 h40 gSaveVars, Save Settings
- gui, add, text, x16 y45 w502 0x10
- Gui, Add, Checkbox,checked%gui11in% x376 y250 w140 vgui11out ,Close Battle net after Hearthstone launch?
- Gui, Add, Checkbox,checked%gui1in% x376 y310 w140 vgui1out ,Start Hearthstone Deck Tracker?
- Gui, Add, Checkbox,checked%gui2in% x376 y350 w140 vgui2out ,Check this if you use Silver.exe
- Gui, Add, Text, x14 y380,Ver %versionnum%
- Gui, Add, Tab2,x10 y64 h310, Settings|Paths|About
- Gui, Tab, 1
- Gui, Font, s8
- Gui, Add, CheckBox,checked%gui13in% x45 y100 vgui13out, Close the Bot when auto stop condition met
- Gui, Add, CheckBox,checked%gui14in% x45 y120 vgui14out, Close the Game when auto stop condition met
- Gui, Add, CheckBox,checked%gui15in% x45 y140 vgui15out, Close Recovery when auto stop condition met
- Gui, Add, CheckBox,checked%gui3in% vgui3out x45 y170,Take breaks between games?
- Gui, Add, Edit, x16 y190 w45 h20,Percent Chance
- Gui, Add, UpDown,vgui4out, %gui4in%
- Gui, Add, Text,x66 y193,Percent chance to take a break after each game
- Gui, Add, Edit, x16 y220 w45 h20, Min break time
- Gui, Add, UpDown, vMinTime vgui5out, %gui5in%
- Gui, Add, Edit, x16 y240 w45 h20, Max break time
- Gui, Add, UpDown, vMaxTime vgui6out, %gui6in%
- Gui, Add, Text, x66 y230,Range in minutes for breaks
- Gui, Tab, 2
- Gui, Add, Text, x20 y100,Location of Battle.net.exe:
- Gui, Add, Edit, x20 y120 w330 h20 vBattleLauncher,%gui7in%
- Gui, Add, Text, x20 y150,Location of HearthRanger.exe:
- Gui, Add, Edit, x20 y170 w330 h20 vHearthRangerPath,%gui8in%
- Gui, Add, Text, x20 y200,Location of Deck/Stat Tracker.exe:
- Gui, Add, Edit, x20 y220 w330 h20 vDeckTracker,%gui9in%
- Gui, Add, Text, x20 y250,Location of Silver.exe:
- Gui, Add, Edit, x20 y270 w330 h20 vSilverLoc,%gui10in%
- 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).
- Gui, Tab, 3
- Gui, Font, s12
- Gui, Add, Text, x20 y100,Ranger Crash Recovery ver %versionnum%
- Gui, Add, Text, x20 y130,Written by Lemon Frosting(Jammo2k5) with `nhelp from OiJkN.
- Gui, Font,s10
- 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.
- ;pulls in command line arguments and checks for -r only
- loop %0%
- {
- If %A_Index% = -r
- {
- gosub,StartBot
- }
- }
- Return
- ;emergencey restart sub routine.
- ^F10::
- gosub,SaveVars
- Reload
- return
- skipBreak:
- SkipSleep = 1
- return
- ;Start button sub routine
- StartBot:
- gosub,SaveVars
- MainFunc()
- return
- ;Saves all variables to the ini file. reads them back to filter "" and such other nonsence and resaves them.
- SaveVars:
- gui,submit,nohide
- rememberposition()
- SaveVars()
- return
- ;this saves all vars on closing of the GUI.
- GuiClose:
- gosub,SaveVars
- ExitApp
- ;Subroutine to launch functions from buttons vValue.
- ExecFunc:
- gosub,SaveVars
- %A_GuiControl%()
- return
- ;Main loop function ########Needs to be cleaned up##########
- MainFunc()
- {
- global
- readvarsfromfile()
- PausedBot = 0
- GuiControl,Disable,StartBtnBtn
- GuiControl,Enable,PauseBot
- LogLast := ReadLog(20)
- ;Resumes bot if paused
- while PausedBot = 0
- {
- LogLast := ReadLog(20)
- ifinstring,LogLast,Bot paused
- {
- sleep 2000
- ;msgbox, botpaused found
- LogLast2 := ReadLog(20)
- ;If (InStr(LogLast,Bot paused,false,0) > InStr(LogLast,Bot is running,false,0))
- if (LogLast2 = LogLast)
- {
- StartRanger(Pausex,Controlsy)
- BotStatusMod("Running","Green")
- ;msgbox, Ranger should be running ID1
- }
- }
- DelLogs()
- BotStatusMod("Starting Game","Blue")
- CheckIfExist(BattleLauncher,"Battle.net")
- CheckIfExist(HearthRangerPath,"Ranger")
- If PausedBot = 1
- {
- BotStatusMod("Script paused","Yellow")
- If gui12in = 1
- {
- BotStatusMod("Bot user paused","Yellow")
- }
- exit
- }
- If gui1in = 1
- {
- CheckIfExist(DeckTracker,"Tracker")
- }
- if gui2in = 1
- {
- CheckIfExist(SilverLoc,"Silver.exe")
- }
- GuiControl,Enable,PauseBtn
- process,exist,Hearthstone.exe
- if (ErrorLevel = 0)
- {
- StartGame()
- }
- If PausedBot = 1
- {
- BotStatusMod("Script paused","Yellow")
- If gui12in = 1
- {
- BotStatusMod("Bot user paused","Yellow")
- }
- exit
- }
- If gui1out = 1
- {
- BotStatusMod("Starting Tracker","Blue")
- Ifexist %DeckTracker%
- {
- Run, %DeckTracker%,%Trackerpath%,,DeckTrackerPID
- }
- }
- If PausedBot = 1
- {
- BotStatusMod("Script paused","Yellow")
- If gui12in = 1
- {
- BotStatusMod("Bot user paused","Yellow")
- }
- exit
- }
- If gui2in = 1
- {
- BotStatusMod("Starting Silver.exe","Blue")
- IfExist,%SilverLoc%
- {
- process,Exist,Silver.exe
- If (ErrorLevel = 0)
- {
- Run,%SilverLoc%,%Silverpath%
- }
- }
- }
- if pausedbot = 1
- {
- BotStatusMod("Script paused","Yellow")
- If gui12in = 1
- {
- BotStatusMod("Bot user paused","Yellow")
- }
- exit
- }
- process,exist,HearthRanger.exe
- if (ErrorLevel = 0)
- {
- DelLogs()
- BotStatusMod("Starting Bot","Blue")
- Run, %HearthRangerPath%,%Rangerpath%
- }
- if pausedbot = 1
- {
- BotStatusMod("Script paused","Yellow")
- If gui12in = 1
- {
- BotStatusMod("Bot user paused","Yellow")
- }
- exit
- }
- if pausedbot = 1
- {
- BotStatusMod("Script paused","Yellow")
- If gui12in = 1
- {
- BotStatusMod("Bot user paused","Yellow")
- }
- exit
- }
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;second loop
- while PausedBot = 0
- {
- BotStatusMod("Running","Green")
- readvarsfromfile()
- If gui11out = 1
- {
- process,close,Battle.net.exe
- }
- If LogLast = `n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n
- {
- process,exist,HearthRanger.exe
- if (ErrorLevel = 0)
- {
- BotStatusMod("Restarting bot","Blue")
- DelLogs()
- Run, %HearthRangerPath%,%Rangerpath%
- }
- StartRanger(Playx,Controlsy)
- ;msgbox, Ranger should be running ID4
- BotStatusMod("Running","Green")
- }
- LogLast := ReadLog(1)
- IfInString, LogLast,Please start game
- {
- IfWinNotExist Hearthstone
- {
- StartGame()
- }
- }
- LogLast := ReadLog(20)
- ;;;
- If gui3in = 1
- {
- IfNotInString, LogLast, Click to continue ret=True
- {
- ClickContinue = 0
- }
- IfInString, LogLast, Click to continue ret=True
- {
- If ClickContinue = 0
- {
- Random,BreakRand,1,100
- If (BreakRand <= gui4in)
- {
- BotStatusMod("Pausing","Blue")
- process,close,Hearthranger.exe
- ;msgbox, Ranger should be paused ID5
- SleepFunc(gui5in,gui6in)
- BotStatusMod("Un Pausing","Blue")
- DelLogs()
- Run, %HearthRangerPath%,%Rangerpath%
- StartRanger(Playx,Controlsy)
- LogLast := ReadLog(2)
- LogLastCompare := ReadLog(2)
- while LogLast = LogLastCompare
- {
- StartRanger(Playx,Controlsy)
- sleep 1000
- LogLastCompare := LogLast
- LogLast := ReadLog(2)
- }
- ;msgbox, Ranger should be running ID6
- BotStatusMod("Running","Green")
- }
- }
- ClickContinue = 1
- }
- }
- process,exist,HearthRanger.exe
- if (ErrorLevel = 0)
- {
- BotStatusMod("Restarting Bot","Blue")
- DelLogs()
- Run, %HearthRangerPath%,%Rangerpath%
- }
- process,exist,Hearthstone.exe
- if (ErrorLevel = 0)
- {
- BotStatusMod("Restarting Game","Blue")
- StartGame()
- }
- LogLast := ReadLog(20)
- IfInString, LogLast ,Bot stopped
- {
- sleep 500
- LogLast := ReadLog(2)
- IfInString, LogLast ,auto stop
- {
- if StartedRanger = 1
- {
- Ifinstring,LogLast,auto stop bot - stop bot after current game
- {
- BotStatusMod("Script not running","Red")
- GuiControl,Enable,StartBtnBtn
- GuiControl,Disable,PauseBot
- AutoStopAfter = 1
- exit
- }
- else
- {
- CloseDown(gui15out)
- }
- StartedRanger = 0
- }
- Else
- {
- StartRanger(Playx,Controlsy)
- }
- }
- else
- {
- ;Restartbot()
- break
- }
- }
- LogLast2 := ReadLog(20)
- sleep 2000
- LogLast := ReadLog(20)
- emptyLog = `n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n
- /*
- If (LogLast != emptyLog)
- {
- if (LogLast2 = LogLast)
- {
- sleep 300000
- LogLast2 := ReadLog(20)
- if (LogLast2 = LogLast)
- {
- process,close,Hearthstone.exe
- }
- }
- }
- */
- }
- if pausedbot = 1
- {
- BotStatusMod("Script paused","Yellow")
- If gui12in = 1
- {
- BotStatusMod("Bot user paused","Yellow")
- }
- exit
- }
- controlclick,,Hearthstone,,Left
- }
- }
- ;Start battle launcher and launch the game ########currently relies on
- ;hearthstone being the selected game want to add selecting hearthstone in the future
- StartGame()
- {
- global
- CountCrash() ; <== Call the function to count number of crashes // ADDED
- attempts:=0
- IfWinExist Hearthstone
- {
- return
- }
- process,exist,Battle.net.exe
- if (ErrorLevel = 0) ; if Battle.net isnt open
- {
- Run %BattleLauncher%
- }
- process,exist,Battle.net.exe
- if (ErrorLevel > 0) ; if Battle.net exists
- {
- process,exist,Hearthstone.exe
- While (ErrorLevel = 0) ;while Hearthstone does not exist, keep trying to open it
- {
- process,exist,Battle.net.exe
- if (ErrorLevel > 0)
- {
- FindClick("./Ranger Recovery/play.png","!a rBattle.net Silent1")
- ;MsgBox ,Trying to open game
- process,exist,Hearthstone.exe
- if (ErrorLevel > 0)
- {
- Break
- }
- WinGetTitle, title, A
- WinMove,Battle.net,,0,0,1,1
- Wingetpos,Bx,By,BattleWidth,,Battle.net
- DPIScaleMod := BattleWidth/720
- Winactivate,Battle.net
- MouseGetPos, xpos, ypos
- Mouseclick,left,Bx+(290*DPIScaleMod),By+(477*DPIScaleMod)
- MouseMove, xpos, ypos , 1
- winactivate,% title
- Sleep 100
- attempts++
- if (attempts>30) ;if battle.net is frozen or something's wrong
- {
- process,close,Battle.net.exe
- Run %BattleLauncher%
- Sleep,5000
- StartGame()
- }
- }
- } ;Hearthstone is opened
- if pausedbot = 1
- {
- exit
- }
- sleep 1000
- StartRanger(Playx,Controlsy)
- }
- ;process,close,Battle.net.exe
- }
- ;Pauses the bot
- PauseBot()
- {
- global
- readvarsfromfile()
- BotStatusMod("Script paused","Yellow")
- GuiControl,Enable,StartBtnBtn
- GuiControl,Disable,PauseBot
- If gui12in = 1
- {
- Loop
- {
- LogLast := ReadLog(20)
- if StartedRanger = 1
- {
- If LogLast = `n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n
- {
- BotStatusMod("Pausing ASAP","Blue")
- sleep 10000
- }
- else ifinstring,LogLast,Please wait, checking
- {
- BotStatusMod("Pausing ASAP","Blue")
- LogLast := ReadLog(20)
- ifinstring,LogLast,Login success
- {
- sleep 1000
- StartRanger(Pausex,Controlsy)
- BotStatusMod("Paused","Yellow")
- ;msgbox, Ranger should be paused ID9
- break
- }
- sleep 1000
- }
- else
- {
- StartRanger(Pausex,Controlsy)
- ;msgbox, Ranger should be paused ID10
- BotStatusMod("Paused","Yellow")
- break
- }
- }
- }
- }
- PausedBot = 1
- }
- ;checks if ranger is working if not checks if it is running and if not it will launch it.
- CheckIfRangerRunning()
- {
- LogLast := ReadLog(20)
- If LogLast = `n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n`n
- {
- process,exist,HearthRanger.exe
- if (ErrorLevel = 0)
- {
- DelLogs()
- Run, %HearthRangerPath%,%Rangerpath%
- }
- }
- }
- ;log cleaning ########### Change code to make deleting logs obselete and chose last created log and open that instead.########
- DelLogs()
- {
- FileRemoveDir,%Rangerpath%task_log,1
- FileCreateDir,%Rangerpath%task_log
- }
- ; clicks the play button on Ranger
- StartRanger(Bx,By)
- {
- global
- StartedRanger = 1
- WinGetTitle, title, A
- Process Exist,HearthRanger.exe
- RangerPID := ErrorLevel
- WinGetPos,Rx,Ry,Rangerwidth,Rangerheight,ahk_pid %RangerPID%
- winactivate,ahk_pid %RangerPID%
- rangerscalemod := Rangerwidth/500
- ;msgbox % rangerscalemod
- MouseGetPos, xpos, ypos
- Mouseclick,left,Rx+(Bx*rangerscalemod),Ry+(By*rangerscalemod)
- ;MouseMove, xpos, ypos , 1
- Winactivate,% title
- }
- ;Shuts down everything on bot auto stop########add check for autostop after current game.
- CloseDown(fullclose)
- {
- global
- BotStatusMod("Stopping","Blue")
- if gui14out = 1
- {
- process,close,Battle.net.exe
- process,close,Hearthstone.exe
- FileAppend, gui4, D:\Downloads\Hearthranger_v.3.2.0\HearthRanger\output.txt
- }
- if gui13out = 1
- {
- process,close,Hearthranger.exe
- Process,close,silver.exe
- Process,Close,%TrackerProcess%
- FileAppend, gui3, D:\Downloads\Hearthranger_v.3.2.0\HearthRanger\output.txt
- }
- If fullclose = 1
- {
- exitapp
- }
- BotStatusMod("Not Running","Red")
- GuiControl,Enable,StartBtnBtn
- GuiControl,Disable,PauseBot
- exit
- }
- ; Reads the last K lines of the Hearthranher%date%.log and returns it
- ReadLog(k)
- {
- loop,%A_WorkingDir%/task_log/HearthRanger*.log
- {
- Loop Read,%A_WorkingDir%/task_log/%A_LoopFileName%
- {
- i := Mod(A_Index,k)
- L%i% = %A_LoopReadLine%
- }
- L := L%i%
- Loop % k-1
- {
- IfLess i,1, SetEnv i,%k%
- i--
- L := L%i% "`n" L
- }
- Return L
- }
- }
- ;This is the bot status updater
- BotStatusMod(status,color)
- {
- Gui,Font,c%color% s10
- GuiControl,Font,BotStatusGui
- GuiControl,text,BotStatusGui,%Status%
- }
- ;checks if a program exists if not it will send a message and status notif
- CheckIfExist(path,name)
- {
- Ifnotexist %path%
- {
- GuiControl,Enable,StartBtnBtn
- GuiControl,Disable,PauseBot
- BotStatusMod("Check "name,"Red")
- msgbox,Please make sure the %name% path is correct in the Path tab.
- exit
- }
- }
- ;this saves all the GUI vars to an INI file.
- SaveVars()
- {
- global
- FileDelete,%A_WorkingDir%\Ranger Recovery\RangerRecovery.ini
- 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
- }
- ;this reads all vars from the INI file and trims the "fat"
- readvarsfromfile()
- {
- global
- i = 0
- loop 17
- {
- i++
- FileReadLine, gui%i%in, %A_WorkingDir%\Ranger Recovery\RangerRecovery.ini,%i%
- }
- StringReplace,BattleLauncher,gui7in,",,All
- StringReplace,HearthRangerPath,gui8in,",,All
- StringReplace,DeckTracker,gui9in,",,All
- StringReplace,SilverLoc,gui10in,",,All
- SplitPath,HearthRangerPath,,Rangerpath
- SplitPath,DeckTracker,TrackerProcess,Trackerpath
- SplitPath,SilverLoc,,Silverpath
- }
- ;This restarts the bot, game and all supporting programs
- RestartBot()
- {
- global
- SaveVars()
- process,close,Hearthranger.exe
- process,close,Hearthstone.exe
- process,close,Battle.net.exe
- Process,close,silver.exe
- Process,Close,%TrackerProcess%
- }
- ;This is the random sleep function
- SleepFunc(x,y)
- {
- global
- GuiControl,Enable,StartBtnBtn
- GuiControl,Disable,PauseBot
- Random,BreakTime,%x%,%y%
- TimeLeft := BreakTime*60
- guicontrol,Show,SkipBreakBtn
- loop %TimeLeft%
- {
- BotStatus := % "Paused for " FormatSeconds(TimeLeft-1)
- BotStatusMod(BotStatus,"Yellow")
- sleep 1000
- TimeLeft--
- if Skipsleep = 1
- {
- Break
- }
- }
- skipsleep = 0
- guicontrol,hide,SkipBreakBtn
- GuiControl,disable,StartBtnBtn
- GuiControl,enable,PauseBot
- }
- ; Formats the time into mm:ss for the status
- FormatSeconds(NumberOfSeconds)
- {
- time = 19990101 ; *Midnight* of an arbitrary date.
- time += %NumberOfSeconds%, seconds
- FormatTime, mmss, %time%, mm:ss
- return mmss ; This method is used to support more than 24 hours worth of sections.
- }
- ;this is the restart button func
- RestartBtn()
- {
- global
- rememberposition()
- gosub,savevars
- 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.
- Ifmsgbox yes
- {
- SaveVars()
- process,close,Battle.net.exe
- process,close,Hearthstone.exe
- process,close,Hearthranger.exe
- Process,close,silver.exe
- Process,Close,%TrackerProcess%
- Reload
- }
- ifmsgbox no
- {
- Reload
- }
- }
- ;More comprehensive argument check.
- getParams:
- Loop, %0% ; for each parameter
- {
- param := %A_Index%
- ; check for switches
- StringLeft, paramType, param, 1
- If (paramType = - or paramType = /)
- {
- ; determine type of switch
- StringMid, switch, param, 2, 1
- ; settings file switch
- If switch = s
- {
- ; access value (= next parameter)
- param = % A_Index + 1
- file_settings := %param%
- MsgBox, settings file:`n%file_settings%
- }
- }
- }
- Return
- rememberposition()
- {
- global
- wingetpos,gui16out,gui17out,,,%AppNAme%,,-
- }
- ;Run program as admin.
- RunAsAdmin()
- {
- global
- Loop, %0% ; For each parameter:
- {
- param := %A_Index% ; Fetch the contents of the variable whose name is contained in A_Index.
- params .= A_Space . param
- }
- ShellExecute := A_IsUnicode ? "shell32\ShellExecute":"shell32\ShellExecuteA"
- if not A_IsAdmin
- {
- If A_IsCompiled
- DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_ScriptFullPath, str, params , str, A_WorkingDir, int, 1)
- Else
- DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_AhkPath, str, """" . A_ScriptFullPath . """" . A_Space . params, str, A_WorkingDir, int, 1)
- exitapp
- }
- }
- ExeName() ;<== Function to return a random name for the app //ADDED
- {
- var_Types := "alnum"
- Loop, Parse, var_Types, `,
- {
- var_result := ""
- var_result .= RandomVar(6,12,A_LoopField)
- }
- return var_result
- }
- RandomVar(p_MinLength,p_MaxLength,p_Type="",p_MinAsc=32,p_MaxAsc=126) ;<== Function to randomize // ADDED
- {
- StringReplace,p_Type,p_Type,!,,All
- l_Neg := !ErrorLevel
- StringReplace,p_Type,p_Type,#,@,All
- l_Cse := !ErrorLevel
- StringReplace,p_Type,p_Type,@,,All
- l_Rep := !ErrorLevel
- Random, l_Aux, %p_MinLength%, %p_MaxLength%
- Loop, %l_Aux% {
- Loop {
- Random, l_Aux, %p_MinAsc%, %p_MaxAsc%
- l_Aux := Chr(l_Aux)
- If ( !l_Rep ) OR ( l_Rep AND !InStr(l_Output,l_Aux,l_Cse) ) {
- If p_Type not in integer,number,digit,xdigit,alpha,upper,lower,alnum,space
- break
- Else
- If l_Neg {
- If l_Aux is not %p_Type%
- break
- }
- Else
- If l_Aux is %p_Type%
- break
- }
- }
- l_Output .= l_Aux
- }
- return l_Output
- }
- CountCrash() ; <== Function to count // ADDED
- {
- Global
- CrashCounterInt++ ;this increases Counter value by 1
- GuiControl,Show,CrachCounter
- GuiControl,,CrachCounter,%CrashCounterInt%
- }
- F9::pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement