Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
- #AutoIt3Wrapper_Icon=D:\GetThis\get-this\GetThis_Client\GetThis_Client\icon.ico
- #AutoIt3Wrapper_Outfile_x64=C:\Program Files (x86)\Glyph\Games\Archebuddy\EnhancedArcheBuddy.exe
- #AutoIt3Wrapper_Res_Comment=Should be run as admin
- #AutoIt3Wrapper_Res_Description=Ehance Archebuddy
- #AutoIt3Wrapper_Res_Fileversion=1.0.0.15
- #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
- #AutoIt3Wrapper_Res_LegalCopyright=Raigar Amarthalion ©
- #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
- #AutoIt3Wrapper_Run_Tidy=y
- #AutoIt3Wrapper_Run_Au3Stripper=y
- #Au3Stripper_Parameters=/soi
- #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
- ; *** Start added by AutoIt3Wrapper ***
- #include <MsgBoxConstants.au3>
- ; *** End added by AutoIt3Wrapper ***
- #include <GuiEdit.au3>
- #include <EditConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <WindowsConstants.au3>
- #include <WinAPI.au3>
- #include "UIAWrappers.au3"
- #include <Misc.au3>
- Opt('WinWaitDelay', 100)
- Opt('WinDetectHiddenText', 1)
- Opt('MouseCoordMode', 1)
- Global Const $False = 0
- Global Const $True = 1
- Global $bExitOnError = $False
- Global $UIA_oUIAutomation ;The main library core CUI automation reference
- Global $UIA_oDesktop, $UIA_pDesktop ;Desktop will be frequently the starting point
- Global $UIA_oTRUECondition ;TRUE condition easy to be available for treewalking
- Global $UIA_DefaultWaitTime = 500 ;Frequently it makes sense to have a small waiting time to have windows rebuild, could be set to 0 if good synch is happening
- Global $oArcheBuddy, $oAccountsManager, $launchAccountButton, $pluginsToRun, $checkConnection, $waitAfterClick
- Func LoadConfiguration()
- $pluginsToRun = IniReadSection("EnhancedArcheBuddy.ini", "PluginsToRun")
- If @error Then
- MsgBox($MB_SYSTEMMODAL, '', 'Error while trying to read EnhancedArcheBuddy.ini... Did you create it ?')
- Exit
- EndIf
- $checkConnection = Int(IniRead("EnhancedArcheBuddy.ini", "Timings", "CheckConnection", "10000"))
- $UIA_DefaultWaitTime = Int(IniRead("EnhancedArcheBuddy.ini", "Timings", "WaitAfterClick", "500"))
- If @error Then
- MsgBox($MB_SYSTEMMODAL, '', 'Error while trying to read EnhancedArcheBuddy.ini... Did you create it ?')
- Exit
- EndIf
- EndFunc ;==>LoadConfiguration
- Func LogError($message)
- FileWriteLine(@ScriptDir & '\EnhancedArcheBuddy.log', @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & " --> " & $message)
- If $bExitOnError = $True Then
- MsgBox($MB_SYSTEMMODAL, "Critical error", $message, 20)
- Exit
- EndIf
- Return SetError(1)
- EndFunc ;==>LogError
- Func _debugTreeItem($itemDebuged, $level = 0, $index = 0)
- Local $t = StringSplit(_UIA_getPropertyValue($itemDebuged, $UIA_BoundingRectanglePropertyId), ";")
- For $i = 0 To $level - 1
- ConsoleWrite(">>> ")
- Next
- For $i = $level To 3
- ConsoleWrite(" ")
- Next
- ConsoleWrite("X " & $t[1] & "; Y " & $t[2] & " / X " & $t[3] & "; Y" & $t[4] & @TAB _
- & "[L" & $level & "/I" & $index & "] :" & @TAB & "Title := <" & _UIA_getPropertyValue($itemDebuged, $UIA_NamePropertyId) & ">" & @TAB _
- & "Class := <" & _UIA_getPropertyValue($itemDebuged, $uia_classnamepropertyid) & ">" & @TAB _
- & "controltype:= " _
- & "<" & _UIA_getControlName(_UIA_getPropertyValue($itemDebuged, $UIA_ControlTypePropertyId)) & ">" & @TAB _
- & ",<" & _UIA_getPropertyValue($itemDebuged, $UIA_ControlTypePropertyId) & ">" & @TAB _
- & ", (" & Hex(_UIA_getPropertyValue($itemDebuged, $UIA_ControlTypePropertyId)) & ")" & @TAB & @CRLF)
- EndFunc ;==>_debugTreeItem
- Func _debugTree($root, $level = 0, $index = 0)
- _debugTreeItem($root, $level, $index)
- Dim $pLevel, $pLevelArray, $levelLength, $pLevelElement, $oLevelElement
- $root.FindAll($TreeScope_Children, $UIA_oTRUECondition, $pLevel)
- $pLevelArray = ObjCreateInterface($pLevel, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray)
- If Not IsObj($pLevelArray) Then Return
- $pLevelArray.Length($levelLength)
- If $levelLength = 0 Then Return
- For $i = 0 To $levelLength - 1; it's zero based
- $pLevelArray.GetElement($i, $pLevelElement)
- $oLevelElement = ObjCreateInterface($pLevelElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
- _debugTree($oLevelElement, $level + 1, $i)
- Next
- EndFunc ;==>_debugTree
- Func _debugItem($itemDebuged)
- Local $t = StringSplit(_UIA_getPropertyValue($itemDebuged, $UIA_BoundingRectanglePropertyId), ";")
- ConsoleWrite("X " & $t[1] & "; Y " & $t[2] & " / X " & $t[3] & "; Y" & $t[4] & @TAB _
- & "Title := <" & _UIA_getPropertyValue($itemDebuged, $UIA_NamePropertyId) & ">" & @TAB _
- & "Class := <" & _UIA_getPropertyValue($itemDebuged, $uia_classnamepropertyid) & ">" & @TAB _
- & "controltype:= " _
- & "<" & _UIA_getControlName(_UIA_getPropertyValue($itemDebuged, $UIA_ControlTypePropertyId)) & ">" & @TAB _
- & ",<" & _UIA_getPropertyValue($itemDebuged, $UIA_ControlTypePropertyId) & ">" & @TAB _
- & ", (" & Hex(_UIA_getPropertyValue($itemDebuged, $UIA_ControlTypePropertyId)) & ")" & @TAB & @CRLF)
- EndFunc ;==>_debugItem
- Func _WinWaitActivate($title, $text, $timeout = 0)
- WinWait($title, $text, $timeout)
- If Not WinActive($title, $text) Then WinActivate($title, $text)
- WinWaitActive($title, $text, $timeout)
- EndFunc ;==>_WinWaitActivate
- Func _WinWaitActivateThenClose($title, $text, $timeout = 0)
- _WinWaitActivate($title, $text, $timeout)
- WinWaitNotActive($title, $text, $timeout)
- EndFunc ;==>_WinWaitActivateThenClose
- Func GetFirstChild($oElement, $sCondition, $sErrorMessage)
- Local $oResult = _UIA_getFirstObjectOfElement($oElement, $sCondition, $TreeScope_Children)
- If Not IsObj($oResult) Then Return LogError($sErrorMessage)
- Return $oResult
- EndFunc ;==>GetFirstChild
- Func GetChild($oElement, $index, $sErrorMessage, $oCondition = $UIA_oTRUECondition)
- Dim $pElement
- Local $oElements = GetChilds($oElement, $sErrorMessage, $oCondition)
- If @error Then Return
- $oElements.GetElement($index, $pElement)
- Return ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
- EndFunc ;==>GetChild
- Func GetChilds($oElement, $sErrorMessage, $oCondition = $UIA_oTRUECondition)
- Dim $pElements, $pElement, $oElements
- $oElement.FindAll($TreeScope_Children, $oCondition, $pElements)
- $oElements = ObjCreateInterface($pElements, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray)
- If Not IsObj($oElements) Then Return LogError($sErrorMessage)
- Return $oElements
- EndFunc ;==>GetChilds
- Func GetArcheBuddy()
- If Not WinExists("ArcheBuddy") Then
- Run('C:\Program Files (x86)\Glyph\Games\Archebuddy\Updater.exe')
- _WinWaitActivateThenClose("ArcheBuddy", "")
- _WinWaitActivate("ArcheBuddy", "")
- EndIf
- If Not WinActive("ArcheBuddy", "") Then WinActivate("ArcheBuddy", "")
- $oArcheBuddy = GetFirstChild($UIA_oDesktop, "title:=ArcheBuddy", "ArcheBuddy window could not be found")
- EndFunc ;==>GetArcheBuddy
- Func GetMenuPopup()
- If Not WinActive("ArcheBuddy", "") Then WinActivate("ArcheBuddy", "")
- Local $oMenu = GetFirstChild($oArcheBuddy, "classname:=Menu", "Archebuddy menu could not be found")
- If @error Then Return
- _UIA_action($oMenu, "leftclick")
- Return GetFirstChild($oArcheBuddy, "classname:=Popup", "Archebuddy menu popup could not be found")
- EndFunc ;==>GetMenuPopup
- Func OpenAccountsManager()
- If Not WinExists("Accounts manager") Then
- Local $oPopUp = GetMenuPopup()
- If @error Then Return
- Local $oAccountManagerMenuItem = GetFirstChild($oPopUp, "name:=Account manager", "Archebuddy Account manager menu item could not be found")
- If @error Then Return
- _UIA_action($oAccountManagerMenuItem, "leftclick")
- _WinWaitActivate("Accounts manager", "")
- Else
- If Not WinActive("Accounts manager", "") Then WinActivate("Accounts manager", "")
- EndIf
- EndFunc ;==>OpenAccountsManager
- Func GetAccounts()
- Dim $oDictionary, $oCondition, $iLength, $pAccounts, $pAccount
- OpenAccountsManager()
- $oDictionary = ObjCreate("Scripting.Dictionary")
- If @error Then Return LogError('Error creating the dictionary object')
- $oAccountsManager = GetFirstChild($UIA_oDesktop, "title:=Accounts manager", "Accounts manager window could not be found")
- Local $toolBar = GetFirstChild($oAccountsManager, "classname:=ToolBar", "Accounts manager toolbar could not be found")
- Local $oDataGrid = GetFirstChild($oAccountsManager, "classname:=DataGrid", "Accounts datagrid could not be found")
- $UIA_oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "Button", $oCondition)
- $launchAccountButton = GetChild($toolBar, 1, "Accounts manager launch account button could not be found", $oCondition)
- $UIA_oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "DataGridRow", $oCondition)
- Local $oAccounts = GetChilds($oDataGrid, "Accounts data could not be found", $oCondition)
- $oAccounts.Length($iLength)
- For $i = 0 To $iLength - 1
- Dim $table[2]
- $oAccounts.GetElement($i, $pAccount)
- Local $oAccount = ObjCreateInterface($pAccount, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
- $table[0] = GetChild($oAccount, 2, "Account data could not be found")
- Local $accountInformations = GetChild($oAccount, 3, "Account informations could not be found")
- $table[1] = GetChild($accountInformations, 3, "Account status could not be found")
- $oDictionary.Add(_UIA_getPropertyValue($table[0], $UIA_NamePropertyId), $table)
- ;ConsoleWrite("Account <" & _UIA_getPropertyValue($table[0], $UIA_NamePropertyId) & "> status <" & _UIA_getPropertyValue($table[1], $UIA_NamePropertyId) & ">" & @CRLF)
- Next
- Return $oDictionary
- EndFunc ;==>GetAccounts
- Func OpenPluginsManager()
- If Not WinExists("Plugins Manager") Then
- Local $oPopUp = GetMenuPopup()
- If @error Then Return
- Local $oPluginManagerMenuItem = GetFirstChild($oPopUp, "name:=Plugin manager", "Archebuddy Plugin manager menu item could not be found")
- If @error Then Return
- _UIA_action($oPluginManagerMenuItem, "leftclick")
- _WinWaitActivate("Plugins Manager", "")
- Else
- If Not WinActive("Plugins Manager", "") Then WinActivate("Plugins Manager", "")
- EndIf
- EndFunc ;==>OpenPluginsManager
- Func TryGetPlugins()
- Dim $oDictionary, $oCondition, $iLength, $pPlugins, $oPlugins, $pPlugin, $oPlugin
- OpenPluginsManager()
- If @error Then Return
- $oDictionary = ObjCreate("Scripting.Dictionary")
- If @error Then Return LogError('Error creating the dictionary object')
- Local $oPluginsManager = GetFirstChild($UIA_oDesktop, "title:=Plugins Manager", "Plugins Manager window could not be found")
- If @error Then Return
- Local $oDataGrid = GetFirstChild($oPluginsManager, "classname:=DataGrid", "Plugins datagrid could not be found")
- If @error Then Return
- $UIA_oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "DataGridRow", $oCondition)
- Local $oPlugins = GetChilds($oDataGrid, "Plugins data could not be found", $oCondition)
- If @error Then Return
- $oPlugins.Length($iLength)
- For $i = 0 To $iLength - 1
- $oPlugins.GetElement($i, $pPlugin)
- $oPlugin = ObjCreateInterface($pPlugin, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
- Dim $table[2]
- $table[0] = GetChild($oPlugin, 2, "Plugin data could not be found")
- If @error Then Return
- Local $pluginInformations = GetChild($oPlugin, 1, "Plugin informations could not be found")
- If @error Then Return
- $table[1] = GetFirstChild($pluginInformations, "classname:=Image", "Plugin launch button could not be found")
- If @error Then Return
- $oDictionary.Add(_UIA_getPropertyValue($table[0], $UIA_NamePropertyId), $table)
- ;ConsoleWrite("Plugin <" & _UIA_getPropertyValue($table[0], $UIA_NamePropertyId) & "> start button <" & _UIA_getPropertyValue($table[1], $UIA_ClassNamePropertyId) & ">" & @CRLF)
- Next
- Return $oDictionary
- EndFunc ;==>TryGetPlugins
- Func IsAccountLaunched($oState)
- If _UIA_getPropertyValue($oState, $UIA_NamePropertyId) <> "Disabled" And _UIA_getPropertyValue($oState, $UIA_NamePropertyId) <> "NotLogged" And _UIA_getPropertyValue($oState, $UIA_NamePropertyId) <> "ServerSelect" Then Return $True
- Return $False
- EndFunc ;==>IsAccountLaunched
- Func TryLaunchAccount($oAccount, $oState)
- Local $errors = 0
- While $errors < 3
- OpenAccountsManager()
- If @error Then
- $errors = $errors + 1
- Sleep(5000)
- ContinueLoop
- EndIf
- If IsAccountLaunched($oState) = $False Then
- Local $slept = 0
- _UIA_action($oAccount, "leftclick")
- _UIA_action($launchAccountButton, "leftclick")
- Do
- $slept = $slept + 1000
- If $slept > 120000 Then
- $errors = $errors + 1
- Break
- EndIf
- Sleep(1000)
- Until IsAccountLaunched($oState) = $True
- Else
- Return $True
- EndIf
- WEnd
- Return $False
- EndFunc ;==>TryLaunchAccount
- Func TryLaunchPlugin($pluginName)
- Local $errors = 0
- While $errors < 3
- Local $oPlugins = TryGetPlugins()
- If @error Then
- $errors = $errors + 1
- Sleep(5000)
- ContinueLoop
- EndIf
- If $oPlugins.Exists($pluginName) Then
- Local $launchPluginButton = $oPlugins.Item($pluginName)[1]
- _UIA_action($launchPluginButton, "leftclick")
- Return $True
- Else
- $errors = $errors + 1
- Sleep(5000)
- EndIf
- WEnd
- Return $False
- EndFunc ;==>TryLaunchPlugin
- $bExitOnError = $True
- _UIA_Init()
- LoadConfiguration()
- GetArcheBuddy()
- Local $oAccounts = GetAccounts()
- $bExitOnError = $False
- ; Enumerate through the array displaying the keys and their respective values.
- For $i = 1 To $pluginsToRun[0][0]
- Local $accountName = $pluginsToRun[$i][0]
- If ($oAccounts.Exists($accountName)) Then
- Local $item = $oAccounts.Item($accountName)
- TryLaunchAccount($item[0], $item[1])
- If @error Then
- SetError(0)
- ContinueLoop
- EndIf
- TryLaunchPlugin($pluginsToRun[$i][1])
- If @error Then
- SetError(0)
- ContinueLoop
- EndIf
- OpenAccountsManager()
- If @error Then
- SetError(0)
- ContinueLoop
- EndIf
- Do
- Sleep($checkConnection)
- Until _UIA_getPropertyValue($item[1], $UIA_NamePropertyId) = "Disabled"
- EndIf
- Next
Advertisement
Add Comment
Please, Sign In to add comment