Guest User

Untitled

a guest
Jul 1st, 2015
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VBScript 13.87 KB | None | 0 0
  1. #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  2. #AutoIt3Wrapper_Icon=D:\GetThis\get-this\GetThis_Client\GetThis_Client\icon.ico
  3. #AutoIt3Wrapper_Outfile_x64=C:\Program Files (x86)\Glyph\Games\Archebuddy\EnhancedArcheBuddy.exe
  4. #AutoIt3Wrapper_Res_Comment=Should be run as admin
  5. #AutoIt3Wrapper_Res_Description=Ehance Archebuddy
  6. #AutoIt3Wrapper_Res_Fileversion=1.0.0.15
  7. #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
  8. #AutoIt3Wrapper_Res_LegalCopyright=Raigar Amarthalion ©
  9. #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
  10. #AutoIt3Wrapper_Run_Tidy=y
  11. #AutoIt3Wrapper_Run_Au3Stripper=y
  12. #Au3Stripper_Parameters=/soi
  13. #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
  14. ; *** Start added by AutoIt3Wrapper ***
  15. #include <MsgBoxConstants.au3>
  16. ; *** End added by AutoIt3Wrapper ***
  17. #include <GuiEdit.au3>
  18. #include <EditConstants.au3>
  19. #include <GUIConstantsEx.au3>
  20. #include <WindowsConstants.au3>
  21. #include <WinAPI.au3>
  22. #include "UIAWrappers.au3"
  23. #include <Misc.au3>
  24.  
  25. Opt('WinWaitDelay', 100)
  26. Opt('WinDetectHiddenText', 1)
  27. Opt('MouseCoordMode', 1)
  28.  
  29. Global Const $False = 0
  30. Global Const $True = 1
  31. Global $bExitOnError = $False
  32. Global $UIA_oUIAutomation ;The main library core CUI automation reference
  33. Global $UIA_oDesktop, $UIA_pDesktop ;Desktop will be frequently the starting point
  34. Global $UIA_oTRUECondition ;TRUE condition easy to be available for treewalking
  35. 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
  36. Global $oArcheBuddy, $oAccountsManager, $launchAccountButton, $pluginsToRun, $checkConnection, $waitAfterClick
  37.  
  38. Func LoadConfiguration()
  39.     $pluginsToRun = IniReadSection("EnhancedArcheBuddy.ini", "PluginsToRun")
  40.     If @error Then
  41.         MsgBox($MB_SYSTEMMODAL, '', 'Error while trying to read EnhancedArcheBuddy.ini... Did you create it ?')
  42.         Exit
  43.     EndIf
  44.     $checkConnection = Int(IniRead("EnhancedArcheBuddy.ini", "Timings", "CheckConnection", "10000"))
  45.     $UIA_DefaultWaitTime = Int(IniRead("EnhancedArcheBuddy.ini", "Timings", "WaitAfterClick", "500"))
  46.     If @error Then
  47.         MsgBox($MB_SYSTEMMODAL, '', 'Error while trying to read EnhancedArcheBuddy.ini... Did you create it ?')
  48.         Exit
  49.     EndIf
  50. EndFunc   ;==>LoadConfiguration
  51.  
  52. Func LogError($message)
  53.     FileWriteLine(@ScriptDir & '\EnhancedArcheBuddy.log', @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & " --> " & $message)
  54.     If $bExitOnError = $True Then
  55.         MsgBox($MB_SYSTEMMODAL, "Critical error", $message, 20)
  56.         Exit
  57.     EndIf
  58.     Return SetError(1)
  59. EndFunc   ;==>LogError
  60.  
  61. Func _debugTreeItem($itemDebuged, $level = 0, $index = 0)
  62.     Local $t = StringSplit(_UIA_getPropertyValue($itemDebuged, $UIA_BoundingRectanglePropertyId), ";")
  63.     For $i = 0 To $level - 1
  64.         ConsoleWrite(">>> ")
  65.     Next
  66.     For $i = $level To 3
  67.         ConsoleWrite("    ")
  68.     Next
  69.     ConsoleWrite("X " & $t[1] & "; Y " & $t[2] & " / X " & $t[3] & "; Y" & $t[4] & @TAB _
  70.              & "[L" & $level & "/I" & $index & "] :" & @TAB & "Title := <" & _UIA_getPropertyValue($itemDebuged, $UIA_NamePropertyId) & ">" & @TAB _
  71.              & "Class   := <" & _UIA_getPropertyValue($itemDebuged, $uia_classnamepropertyid) & ">" & @TAB _
  72.              & "controltype:= " _
  73.              & "<" & _UIA_getControlName(_UIA_getPropertyValue($itemDebuged, $UIA_ControlTypePropertyId)) & ">" & @TAB _
  74.              & ",<" & _UIA_getPropertyValue($itemDebuged, $UIA_ControlTypePropertyId) & ">" & @TAB _
  75.              & ", (" & Hex(_UIA_getPropertyValue($itemDebuged, $UIA_ControlTypePropertyId)) & ")" & @TAB & @CRLF)
  76. EndFunc   ;==>_debugTreeItem
  77.  
  78. Func _debugTree($root, $level = 0, $index = 0)
  79.     _debugTreeItem($root, $level, $index)
  80.     Dim $pLevel, $pLevelArray, $levelLength, $pLevelElement, $oLevelElement
  81.  
  82.     $root.FindAll($TreeScope_Children, $UIA_oTRUECondition, $pLevel)
  83.     $pLevelArray = ObjCreateInterface($pLevel, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray)
  84.     If Not IsObj($pLevelArray) Then Return
  85.  
  86.     $pLevelArray.Length($levelLength)
  87.     If $levelLength = 0 Then Return
  88.     For $i = 0 To $levelLength - 1; it's zero based
  89.         $pLevelArray.GetElement($i, $pLevelElement)
  90.         $oLevelElement = ObjCreateInterface($pLevelElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  91.         _debugTree($oLevelElement, $level + 1, $i)
  92.     Next
  93.  
  94. EndFunc   ;==>_debugTree
  95.  
  96. Func _debugItem($itemDebuged)
  97.     Local $t = StringSplit(_UIA_getPropertyValue($itemDebuged, $UIA_BoundingRectanglePropertyId), ";")
  98.     ConsoleWrite("X " & $t[1] & "; Y " & $t[2] & " / X " & $t[3] & "; Y" & $t[4] & @TAB _
  99.              & "Title := <" & _UIA_getPropertyValue($itemDebuged, $UIA_NamePropertyId) & ">" & @TAB _
  100.              & "Class   := <" & _UIA_getPropertyValue($itemDebuged, $uia_classnamepropertyid) & ">" & @TAB _
  101.              & "controltype:= " _
  102.              & "<" & _UIA_getControlName(_UIA_getPropertyValue($itemDebuged, $UIA_ControlTypePropertyId)) & ">" & @TAB _
  103.              & ",<" & _UIA_getPropertyValue($itemDebuged, $UIA_ControlTypePropertyId) & ">" & @TAB _
  104.              & ", (" & Hex(_UIA_getPropertyValue($itemDebuged, $UIA_ControlTypePropertyId)) & ")" & @TAB & @CRLF)
  105. EndFunc   ;==>_debugItem
  106.  
  107.  
  108. Func _WinWaitActivate($title, $text, $timeout = 0)
  109.     WinWait($title, $text, $timeout)
  110.     If Not WinActive($title, $text) Then WinActivate($title, $text)
  111.     WinWaitActive($title, $text, $timeout)
  112. EndFunc   ;==>_WinWaitActivate
  113.  
  114. Func _WinWaitActivateThenClose($title, $text, $timeout = 0)
  115.     _WinWaitActivate($title, $text, $timeout)
  116.     WinWaitNotActive($title, $text, $timeout)
  117. EndFunc   ;==>_WinWaitActivateThenClose
  118.  
  119. Func GetFirstChild($oElement, $sCondition, $sErrorMessage)
  120.     Local $oResult = _UIA_getFirstObjectOfElement($oElement, $sCondition, $TreeScope_Children)
  121.  
  122.     If Not IsObj($oResult) Then Return LogError($sErrorMessage)
  123.     Return $oResult
  124. EndFunc   ;==>GetFirstChild
  125.  
  126. Func GetChild($oElement, $index, $sErrorMessage, $oCondition = $UIA_oTRUECondition)
  127.     Dim $pElement
  128.  
  129.     Local $oElements = GetChilds($oElement, $sErrorMessage, $oCondition)
  130.     If @error Then Return
  131.  
  132.     $oElements.GetElement($index, $pElement)
  133.     Return ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  134. EndFunc   ;==>GetChild
  135.  
  136. Func GetChilds($oElement, $sErrorMessage, $oCondition = $UIA_oTRUECondition)
  137.     Dim $pElements, $pElement, $oElements
  138.  
  139.     $oElement.FindAll($TreeScope_Children, $oCondition, $pElements)
  140.     $oElements = ObjCreateInterface($pElements, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray)
  141.  
  142.     If Not IsObj($oElements) Then Return LogError($sErrorMessage)
  143.     Return $oElements
  144. EndFunc   ;==>GetChilds
  145.  
  146. Func GetArcheBuddy()
  147.     If Not WinExists("ArcheBuddy") Then
  148.         Run('C:\Program Files (x86)\Glyph\Games\Archebuddy\Updater.exe')
  149.         _WinWaitActivateThenClose("ArcheBuddy", "")
  150.         _WinWaitActivate("ArcheBuddy", "")
  151.     EndIf
  152.     If Not WinActive("ArcheBuddy", "") Then WinActivate("ArcheBuddy", "")
  153.  
  154.     $oArcheBuddy = GetFirstChild($UIA_oDesktop, "title:=ArcheBuddy", "ArcheBuddy window could not be found")
  155. EndFunc   ;==>GetArcheBuddy
  156.  
  157. Func GetMenuPopup()
  158.     If Not WinActive("ArcheBuddy", "") Then WinActivate("ArcheBuddy", "")
  159.  
  160.     Local $oMenu = GetFirstChild($oArcheBuddy, "classname:=Menu", "Archebuddy menu could not be found")
  161.     If @error Then Return
  162.     _UIA_action($oMenu, "leftclick")
  163.  
  164.     Return GetFirstChild($oArcheBuddy, "classname:=Popup", "Archebuddy menu popup could not be found")
  165. EndFunc   ;==>GetMenuPopup
  166.  
  167. Func OpenAccountsManager()
  168.     If Not WinExists("Accounts manager") Then
  169.         Local $oPopUp = GetMenuPopup()
  170.         If @error Then Return
  171.         Local $oAccountManagerMenuItem = GetFirstChild($oPopUp, "name:=Account manager", "Archebuddy Account manager menu item could not be found")
  172.         If @error Then Return
  173.  
  174.         _UIA_action($oAccountManagerMenuItem, "leftclick")
  175.         _WinWaitActivate("Accounts manager", "")
  176.     Else
  177.         If Not WinActive("Accounts manager", "") Then WinActivate("Accounts manager", "")
  178.     EndIf
  179. EndFunc   ;==>OpenAccountsManager
  180.  
  181. Func GetAccounts()
  182.     Dim $oDictionary, $oCondition, $iLength, $pAccounts, $pAccount
  183.  
  184.     OpenAccountsManager()
  185.  
  186.     $oDictionary = ObjCreate("Scripting.Dictionary")
  187.     If @error Then Return LogError('Error creating the dictionary object')
  188.  
  189.     $oAccountsManager = GetFirstChild($UIA_oDesktop, "title:=Accounts manager", "Accounts manager window could not be found")
  190.     Local $toolBar = GetFirstChild($oAccountsManager, "classname:=ToolBar", "Accounts manager toolbar could not be found")
  191.     Local $oDataGrid = GetFirstChild($oAccountsManager, "classname:=DataGrid", "Accounts datagrid could not be found")
  192.  
  193.     $UIA_oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "Button", $oCondition)
  194.     $launchAccountButton = GetChild($toolBar, 1, "Accounts manager launch account button could not be found", $oCondition)
  195.  
  196.     $UIA_oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "DataGridRow", $oCondition)
  197.     Local $oAccounts = GetChilds($oDataGrid, "Accounts data could not be found", $oCondition)
  198.  
  199.     $oAccounts.Length($iLength)
  200.     For $i = 0 To $iLength - 1
  201.         Dim $table[2]
  202.         $oAccounts.GetElement($i, $pAccount)
  203.         Local $oAccount = ObjCreateInterface($pAccount, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  204.  
  205.         $table[0] = GetChild($oAccount, 2, "Account data could not be found")
  206.         Local $accountInformations = GetChild($oAccount, 3, "Account informations could not be found")
  207.         $table[1] = GetChild($accountInformations, 3, "Account status could not be found")
  208.         $oDictionary.Add(_UIA_getPropertyValue($table[0], $UIA_NamePropertyId), $table)
  209.         ;ConsoleWrite("Account <" & _UIA_getPropertyValue($table[0], $UIA_NamePropertyId) & "> status <" & _UIA_getPropertyValue($table[1], $UIA_NamePropertyId) & ">" & @CRLF)
  210.     Next
  211.  
  212.     Return $oDictionary
  213. EndFunc   ;==>GetAccounts
  214.  
  215. Func OpenPluginsManager()
  216.     If Not WinExists("Plugins Manager") Then
  217.         Local $oPopUp = GetMenuPopup()
  218.         If @error Then Return
  219.         Local $oPluginManagerMenuItem = GetFirstChild($oPopUp, "name:=Plugin manager", "Archebuddy Plugin manager menu item could not be found")
  220.         If @error Then Return
  221.  
  222.         _UIA_action($oPluginManagerMenuItem, "leftclick")
  223.         _WinWaitActivate("Plugins Manager", "")
  224.     Else
  225.         If Not WinActive("Plugins Manager", "") Then WinActivate("Plugins Manager", "")
  226.     EndIf
  227. EndFunc   ;==>OpenPluginsManager
  228.  
  229. Func TryGetPlugins()
  230.     Dim $oDictionary, $oCondition, $iLength, $pPlugins, $oPlugins, $pPlugin, $oPlugin
  231.  
  232.     OpenPluginsManager()
  233.     If @error Then Return
  234.  
  235.     $oDictionary = ObjCreate("Scripting.Dictionary")
  236.     If @error Then Return LogError('Error creating the dictionary object')
  237.  
  238.     Local $oPluginsManager = GetFirstChild($UIA_oDesktop, "title:=Plugins Manager", "Plugins Manager window could not be found")
  239.     If @error Then Return
  240.     Local $oDataGrid = GetFirstChild($oPluginsManager, "classname:=DataGrid", "Plugins datagrid could not be found")
  241.     If @error Then Return
  242.  
  243.     $UIA_oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "DataGridRow", $oCondition)
  244.     Local $oPlugins = GetChilds($oDataGrid, "Plugins data could not be found", $oCondition)
  245.     If @error Then Return
  246.  
  247.     $oPlugins.Length($iLength)
  248.     For $i = 0 To $iLength - 1
  249.         $oPlugins.GetElement($i, $pPlugin)
  250.         $oPlugin = ObjCreateInterface($pPlugin, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  251.  
  252.         Dim $table[2]
  253.         $table[0] = GetChild($oPlugin, 2, "Plugin data could not be found")
  254.         If @error Then Return
  255.         Local $pluginInformations = GetChild($oPlugin, 1, "Plugin informations could not be found")
  256.         If @error Then Return
  257.         $table[1] = GetFirstChild($pluginInformations, "classname:=Image", "Plugin launch button could not be found")
  258.         If @error Then Return
  259.         $oDictionary.Add(_UIA_getPropertyValue($table[0], $UIA_NamePropertyId), $table)
  260.         ;ConsoleWrite("Plugin <" & _UIA_getPropertyValue($table[0], $UIA_NamePropertyId) & "> start button <" & _UIA_getPropertyValue($table[1], $UIA_ClassNamePropertyId) & ">" & @CRLF)
  261.     Next
  262.  
  263.     Return $oDictionary
  264. EndFunc   ;==>TryGetPlugins
  265.  
  266. Func IsAccountLaunched($oState)
  267.     If _UIA_getPropertyValue($oState, $UIA_NamePropertyId) <> "Disabled" And _UIA_getPropertyValue($oState, $UIA_NamePropertyId) <> "NotLogged" And _UIA_getPropertyValue($oState, $UIA_NamePropertyId) <> "ServerSelect" Then Return $True
  268.     Return $False
  269. EndFunc   ;==>IsAccountLaunched
  270.  
  271. Func TryLaunchAccount($oAccount, $oState)
  272.     Local $errors = 0
  273.  
  274.     While $errors < 3
  275.         OpenAccountsManager()
  276.         If @error Then
  277.             $errors = $errors + 1
  278.             Sleep(5000)
  279.             ContinueLoop
  280.         EndIf
  281.  
  282.         If IsAccountLaunched($oState) = $False Then
  283.             Local $slept = 0
  284.             _UIA_action($oAccount, "leftclick")
  285.             _UIA_action($launchAccountButton, "leftclick")
  286.             Do
  287.                 $slept = $slept + 1000
  288.                 If $slept > 120000 Then
  289.                     $errors = $errors + 1
  290.                     Break
  291.                 EndIf
  292.                 Sleep(1000)
  293.             Until IsAccountLaunched($oState) = $True
  294.         Else
  295.             Return $True
  296.         EndIf
  297.     WEnd
  298.     Return $False
  299. EndFunc   ;==>TryLaunchAccount
  300.  
  301. Func TryLaunchPlugin($pluginName)
  302.     Local $errors = 0
  303.  
  304.     While $errors < 3
  305.         Local $oPlugins = TryGetPlugins()
  306.         If @error Then
  307.             $errors = $errors + 1
  308.             Sleep(5000)
  309.             ContinueLoop
  310.         EndIf
  311.  
  312.         If $oPlugins.Exists($pluginName) Then
  313.             Local $launchPluginButton = $oPlugins.Item($pluginName)[1]
  314.             _UIA_action($launchPluginButton, "leftclick")
  315.             Return $True
  316.         Else
  317.             $errors = $errors + 1
  318.             Sleep(5000)
  319.         EndIf
  320.     WEnd
  321.     Return $False
  322. EndFunc   ;==>TryLaunchPlugin
  323.  
  324. $bExitOnError = $True
  325. _UIA_Init()
  326. LoadConfiguration()
  327. GetArcheBuddy()
  328. Local $oAccounts = GetAccounts()
  329.  
  330. $bExitOnError = $False
  331. ; Enumerate through the array displaying the keys and their respective values.
  332. For $i = 1 To $pluginsToRun[0][0]
  333.     Local $accountName = $pluginsToRun[$i][0]
  334.     If ($oAccounts.Exists($accountName)) Then
  335.         Local $item = $oAccounts.Item($accountName)
  336.  
  337.         TryLaunchAccount($item[0], $item[1])
  338.         If @error Then
  339.             SetError(0)
  340.             ContinueLoop
  341.         EndIf
  342.         TryLaunchPlugin($pluginsToRun[$i][1])
  343.         If @error Then
  344.             SetError(0)
  345.             ContinueLoop
  346.         EndIf
  347.         OpenAccountsManager()
  348.         If @error Then
  349.             SetError(0)
  350.             ContinueLoop
  351.         EndIf
  352.  
  353.         Do
  354.             Sleep($checkConnection)
  355.         Until _UIA_getPropertyValue($item[1], $UIA_NamePropertyId) = "Disabled"
  356.     EndIf
  357. Next
Advertisement
Add Comment
Please, Sign In to add comment