Skip to content

Commit

Permalink
Check that lastID exists to prevent crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared K committed Nov 2, 2022
1 parent 4801edd commit cdb76a0
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions AFB.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
/*
constants
*/
ONE_MIN := 1000 * 60
ONE_MIN := 60 * 1000
THREE_MINS := 3 * ONE_MIN
FIVE_MINS := 5 * ONE_MIN
SIXTEEN_MINS := 15 * ONE_MIN
DATA_DIR := A_WorkingDir . "\data"
RECONNECT_BUTTON_IMG := DATA_DIR . "\reconnect-button.png"
RECONNECT_TEXT_IMG := DATA_DIR . "\reconnect-text.png"
FIFTEEN_MINS := 15 * ONE_MIN

DATA_DIR := A_WorkingDir . "\data"
RECONNECT_BUTTON_IMG := DATA_DIR . "\reconnect-button.png"
RECONNECT_TEXT_IMG := DATA_DIR . "\reconnect-text.png"
RECONNECT_IMG_SEARCH_ARRAY := [RECONNECT_BUTTON_IMG, RECONNECT_TEXT_IMG]

DirCreate(DATA_DIR)
Expand All @@ -20,50 +21,55 @@ FileInstall("data\reconnect-text.png", RECONNECT_TEXT_IMG, 1)
globals
*/
IsRunning := false
TrayTip("Script is ready for input. AntiKick is disabled.", "AwayFromBlox")
SetTrayTip("Script is ready for input. Anti-kick is disabled.")

#MaxThreadsPerHotkey 2
F1:: {
global IsRunning := !IsRunning
If (IsRunning) {
TrayTip("AntiKick is enabled.", "AwayFromBlox")
SetTrayTip("Anti-kick is enabled.")
} Else {
Reload()
}

While (IsRunning) {
lastID := WinGetID("A")
robloxID := WinExist("Roblox")
if (robloxID) {
; BEGIN WORK
BlockInput(True)
lastID := WinGetID("A")
robloxID := WinExist("Roblox")
if (robloxID) {
; BEGIN WORK - any automation must be done between the BlockInputs
BlockInput(True)

WinActivate(robloxID)
WinGetPos(&winX, &winY, &winWidth, &winHeight, robloxID)
WinActivate(robloxID)
WinGetPos(&winX, &winY, &winWidth, &winHeight, robloxID)

Reconnect(winWidth, winHeight)
Reconnect(winWidth, winHeight)

BreakAFK()
BreakAFK()

if (lastID) {
WinActivate(lastID)
BlockInput(False)
; END OF WORK

antiKickInterval := GetIntervalMins()
sleep(antiKickInterval)
} else {
sleep(FIVE_MINS)
}
BlockInput(False)
; END OF WORK

antiKickInterval := GetIntervalMins()
sleep(antiKickInterval)
} else {
sleep(FIVE_MINS)
}
}

/*
Core logic for "breaking" afk idle timer
*/
BreakAFK() {
sleep(300)
; TODO allow action to be defined by user upon startup and/or config
send("{Space down}")
sleep(100)
sleep(50)
send("{Space up}")
sleep(500)
send("{Space down}")
sleep(50)
send("{Space up}")
}

Expand All @@ -78,8 +84,8 @@ Reconnect(winWidth, winHeight) {
return 1
}
}
} catch as exc {
MsgBox "Something went wrong when trying to check for reconnect button:`n" exc.Message
} catch as err {
MsgBox "Something went wrong when trying to check for reconnect button:`n" err.Message
Reload
}
return 0
Expand All @@ -90,7 +96,7 @@ Reconnect(winWidth, winHeight) {
(avg 9mins: 1/2 AFK timer - 1 (this is for redundancy))
*/
GetIntervalMins() {
randomMins := Random(THREE_MINS, SIXTEEN_MINS)
randomMins := Random(THREE_MINS, FIFTEEN_MINS)
return randomMins
}

Expand Down Expand Up @@ -119,4 +125,8 @@ ClickImageMidPoint(imageFile, xOffset, yOffset){
Click(clickX, clickY)
sleep(350)
Click(clickX, clickY)
}

SetTrayTip(str, title := "AwayFromBlox") {
TrayTip(str, title)
}

0 comments on commit cdb76a0

Please sign in to comment.