Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #RequireAdmin
- #include <file.au3>
- #include <Constants.au3>
- #include <WinAPI.au3>
- _DeclareMsgBoxVars()
- #region ;ScriptSettings
- #region ;UserSetSettings
- Global $Answer, $Character, $District, $Faction, $BorderWidth = _WinAPI_GetSystemMetrics(7), $BorderHeight = _WinAPI_GetSystemMetrics(8) + _WinAPI_GetSystemMetrics(4), $WindowedMode, $WinPos, $Size, $login
- _MsgBox_SetButtonText(3, "Steam", "G1", "None")
- Global $Answer = _MsgBox(3, "Login System", '"Would you like to use the automatic login system? If yes choose the method you will be using. (Steam options requires steam to be running as well as the account already tied)', 0)
- If $Answer = 6 Or $Answer = 7 Then
- If $Answer = 7 Then
- Global $login = _GUICreateLogin("G1 Login", "", False)
- If @error Then Exit
- EndIf
- Do
- _MsgBox_SetButtonText(4, "Criminal", "Enforcer")
- $Faction = _MsgBox(4, "Faction Selection", "Choose the faction of the character to be botted", 0)
- Until $Faction = 6 Or $Faction = 7
- $Character = InputBox("Character Selection", "Which character slot should be botted?" & @LF & @LF & "Must match faction selected previously", "1")
- Do
- _MsgBox_SetButtonText(4, "Financial", "Waterfront")
- $District = _MsgBox(4, "District Select", "Choose the district to spawn in.", 0)
- Until $District = 6 Or $District = 7
- EndIf
- Global $PauseKey = InputBox("Pause key", "What key should pause the bot?", "`")
- Global $PhrasesFile = "Phrases.txt"
- #endregion ;UserSetSettings
- #region ;InternalSettings
- Global $Sleep[3][2] = [[5, 15],[0, 10],[5, 15]]
- ;Controls the sleep timers, with the timers being seperated by rows and actual sleep time is between the first number and the second number, in seconds
- Global $RandomAddition[2] = [1, 3]
- ;Controls the adder that adds to the "ForceRandomPhrase" variable. It adds a random number between the two values to the $ForceRandomPhrase var.
- Global $TriggerNumber = 6
- ;When the adder makes the "ForceRandomPhrase" variable greater than this number, a random phrase is typed in game.
- #endregion ;InternalSettings
- #endregion ;ScriptSettings
- #region ;Internal Vars
- ;Login Page
- Global $SteamLogin[2] = [0.5, 0.4759259259259259]
- Global $LoginEmail[2] = [0.5213541666666667, 0.5759259259259259]
- Global $LoginPass[2] = [0.5213541666666667, 0.6305555555555556]
- Global $LoginButton[2] = [0.5744791666666667, 0.6759259259259259]
- ;Character Page
- Global $CharacterSlots[2] = [0.0963541666666667, 0.25]
- Global $CharacterSpacing = 0.0407407407407407
- Global $SelectCharacter[2] = [0.9395833333333333, 0.9768518518518519]
- ;District Page
- Global $FinanDistrict[2] = [0.3416666666666667, 0.4592592592592593]
- Global $WFDistrict[2] = [0.4979166666666667, 0.4592592592592593]
- Global $JoinDistrict[2] = [0.9411458333333333, 0.9768518518518519]
- ;Criminals
- Global $DoubleB[2] = [0.5182291666666667, 0.5027777777777778]
- Global $PaganBloodrose[2] = [0.4270833333333333, 0.5842592592592593]
- ;Enforcers
- Global $TyDurrent[2] = [0.5765625, 0.4046296296296296]
- Global $SimonTran[2] = [0.1958333333333333, 0.8111111111111111]
- Global $PremiumMsg[2] = [0.398958333333333, 0.699074074074074]
- Global $Paused
- Global $Phrases[1]
- Global $Hwnd
- #endregion ;Internal Vars
- Global $ForceRandomPhrase
- #region ;Main
- HotKeySet($PauseKey, "_TogglePause")
- _GetSize()
- AdlibRegister("_GetSize", 15000)
- If $Answer = 6 Or $Answer = 7 Then _LoginSystem($Answer)
- If FileExists($PhrasesFile) Then _FileReadToArray($PhrasesFile, $Phrases)
- While 1
- While WinActive($Hwnd)
- Sleep(Number(Random($Sleep[0][0], $Sleep[0][1], 1) * 1000))
- Send("k")
- Send("b")
- Sleep(Number(Random($Sleep[1][0], $Sleep[1][1], 1) * 1000))
- Send("{Enter}")
- Sleep(2000)
- Send("/AbandonMission")
- Sleep(2000)
- Send("{Enter}")
- Sleep(Number(Random($Sleep[2][0], $Sleep[2][1], 1) * 1000))
- Switch Number(Random(1, 4, 1))
- Case 1
- Send("w down")
- Sleep(5000)
- Case 2
- Send("a down")
- Case 3
- Send("s down")
- Case 4
- Send("d down")
- EndSwitch
- If FileExists($PhrasesFile) Then _RandomPhrase()
- WEnd
- WEnd
- #endregion ;Main
- #region ;Functions
- Func _ProcessGetWindow($aPId)
- $aPId = ProcessExists($aPId)
- If $aPId = 0 Then
- Return SetError(1, 0, False)
- Else
- Local $aWinList = WinList()
- For $i = 1 To $aWinList[0][0]
- If WinGetProcess($aWinList[$i][1], "") = $aPId And $aWinList[$i][0] <> "" And $aWinList[$i][0] <> "DIEmWin" Then Return WinGetHandle($aWinList[$i][1])
- Next
- Return SetError(2, 0, False)
- EndIf
- EndFunc ;==>_ProcessGetWindow
- Func _GetSize()
- $Hwnd = _ProcessGetWindow("APB.exe")
- If Not $Paused Then
- Local $aTimeout = TimerInit()
- Do
- WinActivate($Hwnd)
- $Size = WinGetClientSize($Hwnd) ; 0=w, 1=h
- If TimerDiff($aTimeout) > 10000 Then
- MsgBox(0, "Failure", "Bot could not get size of APB")
- Exit
- EndIf
- Until IsArray($Size) And $Size[0] > 640 And $Size[1] > 480
- Sleep(5000)
- $WindowedMode = _WindowedMode()
- $WinPos = WinGetPos($Hwnd)
- EndIf
- EndFunc ;==>_GetSize
- Func _LoginSystem($A)
- WinActivate($Hwnd)
- Sleep(10000)
- If $A = 6 Then
- _Click($SteamLogin)
- ElseIf $A = 7 Then
- _Click($LoginEmail)
- Send("^a" & $login[0])
- _Click($LoginPass)
- Send("^a" & $login[1])
- _Click($LoginButton)
- EndIf
- Sleep(15000)
- _CharacterSelect($CharacterSlots, $CharacterSpacing, $Character)
- Sleep(10000)
- _Click($SelectCharacter)
- Sleep(10000)
- If $District = 6 Then
- _Click($FinanDistrict)
- ElseIf $District = 7 Then
- _Click($WFDistrict)
- Else
- MsgBox(0,"Error", "Invalid District Detected")
- Exit
- EndIf
- _Click($JoinDistrict)
- If $District = 6 Then
- _Click($FinanDistrict)
- _Click($JoinDistrict)
- Sleep(60000)
- If $Faction = 6 Then
- _Click($DoubleB)
- ElseIf $Faction = 7 Then
- _Click($TyDurrent)
- Else
- MsgBox(0,"Error", "Invalid Faction Detected")
- Exit
- EndIf
- ElseIf $District = 7 Then
- _Click($WFDistrict)
- _Click($JoinDistrict)
- Sleep(60000)
- If $Faction = 6 Then
- _Click($PaganBloodrose)
- ElseIf $Faction = 7 Then
- _Click($SimonTran)
- Else
- MsgBox(0,"Error", "Invalid Faction Detected")
- Exit
- EndIf
- Else
- MsgBox(0,"Error", "Invalid District Detected")
- Exit
- EndIf
- EndFunc ;==>_LoginSystem
- ;_Click($LoginButton)
- Func _Click(ByRef $ClickLocation, $Clicks = 1)
- MouseMove(($WindowedMode * ($BorderWidth + $WinPos[0])) + $ClickLocation[0] * $Size[0], ($WindowedMode * ($BorderHeight + $WinPos[1])) + ($ClickLocation[1] * $Size[1]), 10)
- MouseClick("Left", ($WindowedMode * ($BorderWidth + $WinPos[0])) + $ClickLocation[0] * $Size[0], ($WindowedMode * ($BorderHeight + $WinPos[1])) + ($ClickLocation[1] * $Size[1]), $Clicks, 0)
- EndFunc ;==>_Click
- ;_CharacterSelect($CharacterSlots, $CharacterSpacing, 1)
- Func _CharacterSelect(ByRef $ClickLocation, $aS, $Character)
- MouseMove(($WindowedMode * ($BorderWidth + $WinPos[0])) + $ClickLocation[0] * $Size[0], ($WindowedMode * ($BorderHeight + $WinPos[1])) + ($ClickLocation[1] * $Size[1]), 10)
- MouseClick("Left", ($WindowedMode * ($BorderWidth + $WinPos[0])) + $ClickLocation[0] * $Size[0], ($WindowedMode * ($BorderHeight + $WinPos[1])) + (($ClickLocation[1] + ($aS * ($Character - 1))) * $Size[1]), 1, 0)
- EndFunc ;==>_CharacterSelect
- Func _RandomPhrase()
- $ForceRandomPhrase += Number(Random($RandomAddition[0], $RandomAddition[1]))
- If $ForceRandomPhrase > Number($TriggerNumber) Then
- Send("{Enter}")
- Sleep(2000)
- Send("/d " & $Phrases[Random(1, $Phrases[0], 1)])
- Sleep(2000)
- Send("{Enter}")
- $ForceRandomPhrase = 0
- EndIf
- EndFunc ;==>_RandomPhrase
- Func _TogglePause()
- $Paused = Not $Paused
- While $Paused
- Sleep(100)
- ToolTip('AFK Bot is paused', 0, 0)
- WEnd
- ToolTip("")
- EndFunc ;==>_TogglePause
- Func _WindowedMode()
- If ProcessExists("APB.exe") And IniRead(StringReplace(_ProcessGetPath("APB.exe"), "\binaries\apb.exe", "") & "\APBGame\Config\APBMachineOptions.ini", "SystemSettings", "Fullscreen", "TRUE") = "False" Then Return SetExtended(1, True)
- EndFunc ;==>_WindowedMode
- Func _ProcessGetPath($vProcess)
- Local $i_PID, $hKernel32, $hPsapi, $aProcessHandle, $tDLLStruct, $iError, $sProcessPath
- $i_PID = ProcessExists($vProcess)
- If Not $i_PID Then Return SetError(1, 0, "");process doesn't exist?
- $hKernel32 = DllOpen("Kernel32.dll")
- $iError = @error
- If $iError Then
- DllClose($hKernel32)
- Return SetError(2, $iError, ""); dllopen kernell32.dll failed
- EndIf
- $aProcessHandle = DllCall($hKernel32, "int", "OpenProcess", "int", 0x0400 + 0x0010, "int", 0, "int", $i_PID)
- $iError = @error
- If $iError Or $aProcessHandle[0] = 0 Then
- DllClose($hKernel32)
- Return SetError(2, $iError, "");openprocess failed
- EndIf
- $hPsapi = DllOpen("PSAPI.dll")
- $iError = @error
- If $iError Then
- DllClose($hKernel32)
- DllClose($hPsapi)
- Return SetError(3, $iError, ""); dllopen psapi.dll failed
- EndIf
- $tDLLStruct = DllStructCreate("char[1000]")
- DllCall($hPsapi, "long", "GetModuleFileNameEx", "int", $aProcessHandle[0], "int", 0, "ptr", DllStructGetPtr($tDLLStruct), "long", DllStructGetSize($tDLLStruct))
- $iError = @error
- DllCall($hKernel32, "int", "CloseHandle", "int", $aProcessHandle[0])
- DllClose($hKernel32)
- DllClose($hPsapi)
- If $iError Then
- $tDLLStruct = 0
- Return SetError(4, $iError, "");getmodulefilenamex failed
- EndIf
- $sProcessPath = DllStructGetData($tDLLStruct, 1)
- $tDLLStruct = 0
- ;format the output
- If StringLen($sProcessPath) < 2 Then Return SetError(5, 0, "");is empty or non readable
- If StringLeft($sProcessPath, 4) = "\??\" Then $sProcessPath = StringReplace($sProcessPath, "\??\", "")
- If StringLeft($sProcessPath, 20) = "\SystemRoot\System32" Then $sProcessPath = StringReplace($sProcessPath, "\SystemRoot\System32", @SystemDir)
- Return SetError(0, 0, $sProcessPath)
- EndFunc ;==>_ProcessGetPath
- Func _WinAPI_ShellQueryUserNotificationState()
- Local $Ret = DllCall('shell32.dll', 'uint', 'SHQueryUserNotificationState', 'uint*', 0)
- If @error Then
- Return SetError(1, 0, 0)
- Else
- If $Ret[0] Then
- Return SetError(1, $Ret[0], 0)
- EndIf
- EndIf
- Return $Ret[1]
- EndFunc ;==>_WinAPI_ShellQueryUserNotificationState
- #endregion ;Functions
- Func _DeclareMsgBoxVars()
- Global Const $__MsgBox_HCBT_MOVESIZE = 0
- Global Const $__MsgBox_HCBT_MINMAX = 1
- Global Const $__MsgBox_HCBT_QS = 2
- Global Const $__MsgBox_HCBT_CREATEWND = 3
- Global Const $__MsgBox_HCBT_DESTROYWND = 4
- Global Const $__MsgBox_HCBT_ACTIVATE = 5
- Global Const $__MsgBox_HCBT_CLICKSKIPPED = 6
- Global Const $__MsgBox_HCBT_KEYSKIPPED = 7
- Global Const $__MsgBox_HCBT_SYSCOMMAND = 8
- Global Const $__MsgBox_HCBT_SETFOCUS = 9
- Global Enum $__iMsgBox_IDOK = 1, _
- $__iMsgBox_IDCANCEL, _
- $__iMsgBox_IDABORT, _
- $__iMsgBox_IDRETRY, _
- $__iMsgBox_IDIGNORE, _
- $__iMsgBox_IDYES, _
- $__iMsgBox_IDNO, _
- $__iMsgBox_IDCLOSE, _
- $__iMsgBox_IDHELP, _
- $__iMsgBox_IDTRYAGAIN, _
- $__iMsgBox_IDCONTINUE, _
- $__iMsgBox_IDLASTITEM
- Global $__aMsgBoxTextDefault[$__iMsgBox_IDLASTITEM] = [$__iMsgBox_IDLASTITEM - 1, _
- "OK", "Cancel", "&Abort", "&Retry", "&Ignore", "Yes", "No", "", "Help", _
- "&Continue", "&Try Again"]
- Global $__iMsgBox_Flag = -1
- Global $__fMsgBox_Move = False
- Global $__hMsgBox_Parent = 0
- Global $__iMsgBox_XPos = -1
- Global $__iMsgBox_YPos = -1
- Global $__aMsgBoxText = $__aMsgBoxTextDefault
- Global $__hMsgBoxHook = 0
- EndFunc ;==>_DeclareMsgBoxVars
- ;===================================================================================================
- ;
- ; Function Name....: _CBT_MsgBoxProc()
- ; Description......: Message Box Callback Function
- ; Parameter(s).....:
- ; $i_code: N/A
- ; $w_param: N/A
- ; $l_param: N/A
- ; Return Value(s)..:
- ; Success...: N/A
- ; Failure...: N/A
- ; Error.....: N/A
- ; Extended..: N/A
- ; Requirement(s)...:
- ; Author(s)........: SmOke_N (Ron Nielsen)
- ; Modified.........:
- ; Comment(s).......: Tested with AutoIt 3.3.6.1
- ; Example(s).......: N/A - Internal Use Only
- ;
- ;===================================================================================================
- Func _CBT_MsgBoxProc($i_code, $w_param, $l_param)
- #forceref $l_param
- Local $h_msgbox = HWnd($w_param)
- Local $t_rect_msg = 0, $t_rect_hwnd
- Local $i_hwnd_left, $i_hwnd_top, $i_hwnd_right, $i_hwnd_bottom
- Local $i_msg_left, $i_msg_top, $i_msg_right, $i_msg_bottom
- #forceref $h_msgbox, $t_rect_msg, $t_rect_hwnd
- #forceref $i_hwnd_left, $i_hwnd_top, $i_hwnd_right, $i_hwnd_bottom
- #forceref $i_msg_left, $i_msg_top, $i_msg_right, $i_msg_bottom
- Switch $i_code
- Case $__MsgBox_HCBT_ACTIVATE
- If $__fMsgBox_Move Then
- If $__iMsgBox_XPos = -1 Or $__iMsgBox_YPos = -1 Then
- If $__hMsgBox_Parent Then
- $t_rect_hwnd = _WinAPI_GetWindowRect($__hMsgBox_Parent)
- Else
- $t_rect_hwnd = _WinAPI_GetWindowRect(_WinAPI_GetDesktopWindow())
- EndIf
- $i_hwnd_left = DllStructGetData($t_rect_hwnd, "left")
- $i_hwnd_top = DllStructGetData($t_rect_hwnd, "top")
- $i_hwnd_right = DllStructGetData($t_rect_hwnd, "right")
- $i_hwnd_bottom = DllStructGetData($t_rect_hwnd, "bottom")
- $t_rect_msg = _WinAPI_GetWindowRect($h_msgbox)
- $i_msg_left = DllStructGetData($t_rect_msg, "left")
- $i_msg_top = DllStructGetData($t_rect_msg, "top")
- $i_msg_right = DllStructGetData($t_rect_msg, "right")
- $i_msg_bottom = DllStructGetData($t_rect_msg, "bottom")
- EndIf
- If $__iMsgBox_XPos = -1 Then
- $__iMsgBox_XPos = ($i_hwnd_left + ($i_hwnd_right - $i_hwnd_left) / 2) - _
- (($i_msg_right - $i_msg_left) / 2)
- EndIf
- If $__iMsgBox_YPos = -1 Then
- $__iMsgBox_YPos = ($i_hwnd_top + ($i_hwnd_bottom - $i_hwnd_top) / 2) - _
- (($i_msg_bottom - $i_msg_top) / 2)
- EndIf
- _WinAPI_SetWindowPos($h_msgbox, 0, $__iMsgBox_XPos, $__iMsgBox_YPos, _
- - 1, -1, BitOR($SWP_NOSIZE, $SWP_NOZORDER, $SWP_NOACTIVATE))
- EndIf
- If $__iMsgBox_Flag <> -1 Then
- For $iid = $__iMsgBox_IDOK To $__iMsgBox_IDLASTITEM - 1
- If $iid = $__iMsgBox_IDCLOSE Then ContinueLoop
- If _WinAPI_GetDlgItem($h_msgbox, $iid) Then
- DllCall("User32.dll", "int", "SetDlgItemText", "hwnd", $h_msgbox, _
- "int", $iid, "str", $__aMsgBoxText[$iid])
- EndIf
- Next
- EndIf
- _WinAPI_UnhookWindowsHookEx($__hMsgBoxHook)
- $__hMsgBoxHook = 0
- Return 0
- EndSwitch
- Return _WinAPI_CallNextHookEx($__hMsgBoxHook, $i_code, $w_param, $l_param)
- EndFunc ;==>_CBT_MsgBoxProc
- ;===================================================================================================
- ;
- ; Function Name....: _MsgBox()
- ; Description......: Message box
- ; Parameter(s).....:
- ; $i_flag: Button(s) flag
- ; $s_title: Text of title
- ; $s_text: Text of body
- ; $i_timeout: ( Optional -1 or Default ) Timeout of message box
- ; $h_wnd: ( Optional -1 or Default ) Parent Window
- ; Return Value(s)..:
- ; Success...: Button code that was selected
- ; Failure...: N/A
- ; Error.....: N/A
- ; Extended..: N/A
- ; Requirement(s)...:
- ; Author(s)........: SmOke_N (Ron Nielsen)
- ; Modified.........:
- ; Comment(s).......: Tested with AutoIt 3.3.6.1
- ; Example(s).......: _MsgBox(64 + 4 + 262144, "Title", "Body Of Text")
- ;
- ;===================================================================================================
- Func _MsgBox($i_flag, $s_title, $s_text, $i_timeout = 0, $h_wnd = 0)
- If Not $__fMsgBox_Move Then
- ; If everything is default we don't need the flag
- If $__iMsgBox_Flag = -1 Then Return MsgBox($i_flag, $s_title, $s_text, $i_timeout, $h_wnd)
- ; If flags are different than just set off normal msgbox rather than work through possible conflicts
- If Not (BitAND($i_flag, $__iMsgBox_Flag) = $__iMsgBox_Flag) Then _MsgBox_SetButtonText(-1)
- EndIf
- Local $h_cb = DllCallbackRegister("_CBT_MsgBoxProc", "lresult", "int;wparam;lparam")
- Local $p_cb = DllCallbackGetPtr($h_cb)
- $__hMsgBoxHook = _WinAPI_SetWindowsHookEx($WH_CBT, $p_cb, 0, _WinAPI_GetCurrentThreadId())
- Local $i_ret = MsgBox($i_flag, $s_title, $s_text, $i_timeout, $h_wnd)
- If $__hMsgBoxHook Then _WinAPI_UnhookWindowsHookEx($__hMsgBoxHook)
- DllCallbackFree($h_cb)
- $__hMsgBoxHook = 0
- ; Reset Globals
- _MsgBox_SetButtonText(-1)
- _MsgBox_SetWindowPos()
- Return $i_ret
- EndFunc ;==>_MsgBox
- ;===================================================================================================
- ;
- ; Function Name....: _MsgBox_SetWindowPos()
- ; Description......: Move the window to a specific position or center to a window
- ; Parameter(s).....:
- ; $i_pos_x: ( Optional -1 or Default ) X position of messagebox
- ; ( reverts to default (center) if $h_parent param is used )
- ; $i_pos_y: ( Optional -1 or Default ) Y position of messagebox
- ; ( reverts to default (center) if $h_parent param is used )
- ; $h_parent: ( Optional -1 or Default ) Window to center messagbox on
- ; Return Value(s)..:
- ; Success...: N/A
- ; Failure...: N/A
- ; Error.....: N/A
- ; Extended..: N/A
- ; Requirement(s)...:
- ; Author(s)........: SmOke_N (Ron Nielsen)
- ; Modified.........:
- ; Comment(s).......: This must be called before _MsgBox(); Tested with AutoIt 3.3.6.1
- ; Example(s).......: _MsgBox_SetWindowPos(100, 200)
- ;
- ;===================================================================================================
- Func _MsgBox_SetWindowPos($i_pos_x = -1, $i_pos_y = -1, $h_parent = -1)
- If $h_parent = Default Or $h_parent = -1 Then $h_parent = 0
- If $i_pos_x = Default Or $h_parent Then $i_pos_x = -1
- If $i_pos_y = Default Or $h_parent Then $i_pos_y = -1
- $__iMsgBox_XPos = $i_pos_x
- $__iMsgBox_YPos = $i_pos_y
- $__hMsgBox_Parent = $h_parent
- If $i_pos_x = -1 And $i_pos_y = -1 And $h_parent = 0 Then
- $__fMsgBox_Move = False
- Return True
- EndIf
- $__fMsgBox_Move = True
- Return True
- EndFunc ;==>_MsgBox_SetWindowPos
- ;===================================================================================================
- ;
- ; Function Name....: _MsgBox_SetButtonText()
- ; Description......: Change the text of buttons
- ; Parameter(s).....:
- ; $i_flag: Flag for button(s) ( See helpfile )
- ; $s_button1: ( Optional -1 or Default ) Text for first button
- ; $s_button2: ( Optional -1 or Default ) Text for second button
- ; $s_button3: ( Optional -1 or Default ) Text for third button
- ; Return Value(s)..:
- ; Success...: N/A
- ; Failure...: N/A
- ; Error.....: N/A
- ; Extended..: N/A
- ; Requirement(s)...:
- ; Author(s)........: SmOke_N (Ron Nielsen)
- ; Modified.........:
- ; Comment(s).......: This must be called before _MsgBox(); Tested with AutoIt 3.3.6.1
- ; Example(s).......: _MsgBox_SetButtonText(4, "Button 1", "Button 2")
- ;
- ;===================================================================================================
- Func _MsgBox_SetButtonText($i_flag, $s_button1 = -1, $s_button2 = -1, $s_button3 = -1)
- If ((IsInt($i_flag) And ($i_flag < 0 Or $i_flag > 6)) Or _
- Not StringIsInt($i_flag) Or $i_flag = Default) Then
- $__aMsgBoxText = $__aMsgBoxTextDefault
- $__iMsgBox_Flag = -1
- Return True
- EndIf
- $__iMsgBox_Flag = Int($i_flag)
- Switch $__iMsgBox_Flag
- Case 0
- If (IsInt($s_button1) And $s_button1 = -1) Or $s_button1 = Default Then $s_button1 = "OK"
- $__aMsgBoxText[$__iMsgBox_IDOK] = $s_button1
- Case 1
- If (IsInt($s_button1) And $s_button1 = -1) Or $s_button1 = Default Then $s_button1 = "OK"
- If (IsInt($s_button2) And $s_button2 = -1) Or $s_button2 = Default Then $s_button2 = "Cancel"
- $__aMsgBoxText[$__iMsgBox_IDOK] = $s_button1
- $__aMsgBoxText[$__iMsgBox_IDCANCEL] = $s_button2
- Case 2
- If (IsInt($s_button1) And $s_button1 = -1) Or $s_button1 = Default Then $s_button1 = "&Abort"
- If (IsInt($s_button2) And $s_button2 = -1) Or $s_button2 = Default Then $s_button2 = "&Retry"
- If (IsInt($s_button3) And $s_button3 = -1) Or $s_button3 = Default Then $s_button3 = "&Ignore"
- $__aMsgBoxText[$__iMsgBox_IDABORT] = $s_button1
- $__aMsgBoxText[$__iMsgBox_IDRETRY] = $s_button2
- $__aMsgBoxText[$__iMsgBox_IDIGNORE] = $s_button3
- Case 3
- If (IsInt($s_button1) And $s_button1 = -1) Or $s_button1 = Default Then $s_button1 = "Yes"
- If (IsInt($s_button2) And $s_button2 = -1) Or $s_button2 = Default Then $s_button2 = "No"
- If (IsInt($s_button3) And $s_button3 = -1) Or $s_button3 = Default Then $s_button3 = "Cancel"
- $__aMsgBoxText[$__iMsgBox_IDYES] = $s_button1
- $__aMsgBoxText[$__iMsgBox_IDNO] = $s_button2
- $__aMsgBoxText[$__iMsgBox_IDCANCEL] = $s_button3
- Case 4
- If (IsInt($s_button1) And $s_button1 = -1) Or $s_button1 = Default Then $s_button1 = "Yes"
- If (IsInt($s_button2) And $s_button2 = -1) Or $s_button2 = Default Then $s_button2 = "No"
- $__aMsgBoxText[$__iMsgBox_IDYES] = $s_button1
- $__aMsgBoxText[$__iMsgBox_IDNO] = $s_button2
- Case 5
- If (IsInt($s_button1) And $s_button1 = -1) Or $s_button1 = Default Then $s_button1 = "&Retry"
- If (IsInt($s_button2) And $s_button2 = -1) Or $s_button2 = Default Then $s_button2 = "Cancel"
- $__aMsgBoxText[$__iMsgBox_IDRETRY] = $s_button1
- $__aMsgBoxText[$__iMsgBox_IDCANCEL] = $s_button2
- Case 6
- If (IsInt($s_button1) And $s_button1 = -1) Or $s_button1 = Default Then $s_button1 = "Cancel"
- If (IsInt($s_button2) And $s_button2 = -1) Or $s_button2 = Default Then $s_button2 = "&Try Again"
- If (IsInt($s_button3) And $s_button3 = -1) Or $s_button3 = Default Then $s_button3 = "&Continue"
- $__aMsgBoxText[$__iMsgBox_IDCANCEL] = $s_button1
- $__aMsgBoxText[$__iMsgBox_IDTRYAGAIN] = $s_button2
- $__aMsgBoxText[$__iMsgBox_IDCONTINUE] = $s_button3
- EndSwitch
- Return True
- EndFunc ;==>_MsgBox_SetButtonText
- ;===============================================================================
- ; Function Name: _GUICreateLogin()
- ; Description: Create a basic login box with Username, Password, and a prompt.
- ; Syntax:
- ; Parameter(s): $hTitle - The title of the Form
- ; $hPrompt - The text prompt for the user [Optional] (maximum of 2 lines)
- ; $bBlank - The password or username can be blank. [optional]
- ; Default = False (Blanks are not allowed)
- ; $hWidth - Width of the form [optional] - default = 250
- ; $hHeight - Height of the form [optional] - default = 130
- ; $hLeft - X position [optional] - default = centered
- ; $hTop - Y position [optional] - default = centered
- ; $Timeout - The timeout of the form [optional - default = 0 (no timeout)
- ; $ShowError - Prompts are displayed to the user with timeout [optional]
- ; Requirement(s): None
- ; Return Value(s): Success - Returns an array of 2 elements where
- ; [0] = UserName
- ; [1] = Password
- ; Failure - Sets @Error to 1 and
- ; @Extended - 1 = Cancel/Exit Button Pressed
- ; - 2 = Timed out
- ; Author(s): Brett Francis ([email protected])
- ; Modification(s): GeoSoft
- ; Note(s): If $hPrompt is blank then the GUI height will be reduced by 30
- ; Example(s):
- ;===============================================================================
- Func _GUICreateLogin($hTitle, $hPrompt = "", $bBlank = False, $hWidth = -1, $hHeight = -1, $hLeft = -1, $hTop = -1, $timeout = 0, $ShowError = 0)
- If Not $hTitle Then $hTitle = "Login"
- Local $Msg, $Status, $err, $ext, $iGCM = Opt("GUICoordMode", 2);; Get the current value of GUICoordMode and set it to 2
- If StringRegExp($bBlank, "(?i)\s|default|-1") Then $bBlank = False
- If StringRegExp($hWidth, "(?i)\s|default|-1") Then $hWidth = 250
- If StringRegExp($hHeight, "(?i)\s|default|-1") Then $hHeight = 130
- If StringRegExp($hLeft, "(?i)\s|default|-1") Then $hLeft = (@DesktopWidth / 2) - ($hWidth / 2)
- If StringRegExp($hTop, "(?i)\s|default|-1") Then $hTop = (@DesktopHeight / 2) - ($hHeight / 2)
- If Not $hPrompt Then $hHeight -= 30;If $hPrompt is blank then resize the GUI.
- Local $retarr[2] = ["", ""], $Time = 0
- Local $gui = GUICreate($hTitle, $hWidth, $hHeight, $hLeft, $hTop)
- GUISetCoord(4, 0)
- If $hPrompt Then Local $Lbl_Prompt = GUICtrlCreateLabel($hPrompt, -1, 4, 201, 30)
- Local $Lbl_User = GUICtrlCreateLabel("Username:", -1, 4, 64, 17);44, 64, 17)
- GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
- Local $username = GUICtrlCreateInput('', 8, -1, $hWidth - 81, 21)
- GUICtrlCreateLabel("Password:", -($hWidth - 8), 4, 65, 17)
- GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
- Local $password = GUICtrlCreateInput('', 8, -1, $hWidth - 81, 21, 32);, $ES_PASSWORD)
- GUISetCoord(($hWidth / 2) - 85, $hHeight - 34)
- Local $Btn_OK = GUICtrlCreateButton("&OK", -1, -1, 75, 25)
- Local $Btn_Cancel = GUICtrlCreateButton("&Cancel", 20, -1, 75, 25)
- GUICtrlSetState($Btn_OK, 512)
- GUISetState()
- If $timeout Then $Time = TimerInit()
- While 1
- $Msg = GUIGetMsg()
- Local $sUser = GUICtrlRead($username)
- Local $sPass = GUICtrlRead($password)
- If ($Time And TimerDiff($Time) >= $timeout) And ($sUser = "" And $sPass = "") Then
- $Status = 2
- ExitLoop
- EndIf
- Select
- Case $Msg = -3
- $Status = 0
- ExitLoop
- Case $Msg = $Btn_OK
- If $bBlank And ($sUser = "" Or $sPass = "") Then
- $Status = 1
- ExitLoop
- Else
- If $sUser <> "" And $sPass <> "" Then
- $Status = 1
- ExitLoop
- Else
- Select
- Case $sUser = "" And $sPass = ""
- If $ShowError = 1 Then MsgBox(16, "Error!", "Username and Password cannot be blank!")
- Case $sPass = ""
- If $ShowError = 1 Then MsgBox(16, "Error!", "Password cannot be blank!")
- GUICtrlSetState($password, 256)
- Case $sUser = ""
- If $ShowError = 1 Then MsgBox(16, "Error!", "Username cannot be blank!")
- GUICtrlSetState($username, 256)
- EndSelect
- EndIf
- EndIf
- Case $Msg = $Btn_Cancel
- $Status = 0
- ExitLoop
- Case $timeout And TimerDiff($Time) >= $timeout; And $timeout
- If $bBlank And ($sUser = "" Or $sPass = "") Then
- $Status = 2
- ExitLoop
- Else
- ;$time = TimerInit()
- Select
- Case $sUser = "" And $sPass = ""
- If $timeout Then $Time = TimerInit()
- If $ShowError = 1 Then MsgBox(16, "Error!", "Username and Password cannot be blank!")
- Case $sPass = ""
- If $timeout Then $Time = TimerInit()
- If $ShowError = 1 Then
- MsgBox(16, "Error!", "Password cannot be blank!")
- GUICtrlSetState($password, 256)
- EndIf
- Case $sUser = ""
- $Time = TimerInit()
- If $ShowError = 1 Then
- MsgBox(16, "Error!", "Username cannot be blank!")
- GUICtrlSetState($username, 256)
- EndIf
- ;Case ($Timeout AND TimerDiff($time) >= $timeout) AND ($sUser = "" OR $sPass = "")
- ;$status = 2
- ;ExitLoop
- Case Else
- If $sUser <> "" And $sPass <> "" Then
- $Status = 3
- ;If $Timeout AND TimerDiff($time) >= $timeout Then $Status = 2
- ExitLoop
- EndIf
- EndSelect
- EndIf
- EndSelect
- WEnd
- Local $eMsg = ""
- Switch $Status
- Case 0, 2
- $err = 1;0
- $ext = 1;Cancel/Exit Button Pressed
- $eMsg = "Cancel/Exit Button Pressed"
- If $Status = 2 Then $ext = 2;Timed Out
- If $ext = 2 Then $eMsg = "Timed Out"
- Case Else;1, 3
- $retarr[0] = $sUser
- $retarr[1] = $sPass
- $err = 0;1
- $ext = 0
- If $Status = 3 Then $ext = 1;Username Fields Not Blank, Timeout reached
- EndSwitch
- GUIDelete($gui)
- Opt("GUICoordMode", $iGCM);Reset the GUICoordMode to what it started as.
- If $eMsg Then Return SetError($err, $ext, $eMsg)
- Return $retarr
- EndFunc ;==>_GUICreateLogin
Add Comment
Please, Sign In to add comment