Advertisement
zEEneXx

farming_sarkoth_dank_cellar_wd_1.3d_zeenexx

Jul 3rd, 2012
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 75.00 KB | None | 0 0
  1. #include <WindowsConstants.au3>
  2. #include <Misc.au3>
  3. #include <WinAPI.au3>
  4. #include <StaticConstants.au3>
  5. #include <GuiListBox.au3>
  6. #include <ScrollBarConstants.au3>
  7. #include <Array.au3>
  8. #include <GUIConstantsEx.au3>
  9. #include <File.au3>
  10. #include <ScreenCapture.au3>
  11. #include <String.au3>
  12.  
  13. Initialize()
  14.  
  15. #cs
  16.  
  17.    [Gold/Itemfarming] [AutoIt] Sarkoth Act I Dank Cellar [WD] [Stash, Sell, Repair, +++]
  18.                                     by zEEneXx
  19.                                  
  20.                                   Version: 1.3d
  21.                                
  22.                                 www.ownedcore.com
  23.                  
  24. #ce
  25.  
  26. ;///////////////////////////////////////--CONFIG--////////////////////////////////////////////////////////////////////////////////////
  27. ;                                                                                                                                   //
  28. ;                                       Important                                                                                   //
  29. $ComputerLag            = 0                                                 ;Increases time (ms) before and after casting spells    //
  30. $MoveDelay              = 0                                                 ;Increases time (ms) between movements                  //
  31. $LootDelay              = 0                                                 ;Increases time (ms) between looting                    //
  32. $SellDelay              = 0                                                 ;Increases time (ms) between selling                    //
  33. $SalvageDelay           = 0                                                 ;Increases time (ms) between salvaging                  //
  34. $StashDelay             = 0                                                 ;Increases time (ms) between stashing                   //
  35. $ReqFiles               = "C:\Program Files (x86)\AutoIt3\required files\"  ;Location of the required files folder                  //
  36. ;                                                                                                                                   //
  37. ;                                       Functions                                                                                   //
  38. $Repair                 = True                                              ;Orders the bot to repair                               //
  39. $Sell                   = True                                              ;Orders the bot to sell magic items                     //
  40. $Salvage                = True                                              ;Orders the bot to salvage magic items                  //
  41. $KeepHighLevel          = False                                             ;Orders the bot to keep items above $KeepLevel          //
  42. $KeepLevel              = 63                                                ;Possible values: 60, 61, 62, 63                        //
  43. $UseStash               = True                                              ;Orders the bot to stash items                          //
  44. $HighGoldRadius         = False                                             ;Orders the bot to use a shorter gold loot route        //
  45. ;                                                                                                                                   //
  46. ;                                     Miscellaneous                                                                                 //
  47. $Sounds                 = True                                              ;Enable pickup sounds                                   //
  48. $ShowLootArea           = True                                              ;Shows lootarea                                         //
  49. $ShowLog                = True                                              ;Shows log window                                       //
  50. $SaveStats              = True                                              ;Saves statistics per run to a text file                //
  51. $SaveLogsPath           = "C:\Program Files (x86)\AutoIt3\logs\"            ;Folder to save the logs and statistics in              //
  52. $InstantLeave           = False                                             ;Leaves the game instead of teleporting to town         //
  53. ;                                                                                                                                   //
  54. ;                                       Relogging                                                                                   //                                 
  55. $UseRelogging           = False                                             ;Orders the bot to relog on disconnect                  //
  56. $Password               = "XXXXXXXXXXX"                                     ;Your password                                          //
  57. ;                                                                                                                                   //
  58. ;                                        Looting                                                                                    //
  59. $LootSets               = True                                              ;Orders the bot to loot set items                       //
  60. $LootLegendaries        = True                                              ;Orders the bot to loot legendary items                 //
  61. $LootRares              = True                                              ;Orders the bot to loot rare items                      //
  62. $LootMagics             = True                                              ;Orders the bot to loot magic items (includes tomes)    //
  63. $LootTomes              = False                                             ;Orders the bot to loot tomes                           //
  64. $LootGems               = True                                              ;Orders the bot to loot gems                            //
  65. $FlawlessOnly           = False                                             ;Orders the bot to loot only flawless gems              //
  66. ;                                                                                                                                   //
  67. $SetLootAmount          = 1                                                 ;Amount of set items to loot                            //
  68. $LegendaryLootAmount    = 1                                                 ;Amount of legendary items to loot                      //
  69. $RareLootAmount         = 2                                                 ;Amount of rare items to loot                           //
  70. $MagicLootAmount        = 4                                                 ;Amount of magic items to loot (including tomes)        //
  71. $TomeLootAmount         = 1                                                 ;Amount of tomes to loot (if $LootMagics = False)       //
  72. $GemLootAmount          = 2                                                 ;Amount of gems to loot                                 //
  73. ;                                                                                                                                   //
  74. $LootingArea[0]         = 570                                               ;Left   (lower -> bigger)                               //
  75. $LootingArea[1]         = 185                                               ;Top    (lower -> bigger)                               //
  76. $LootingArea[2]         = 1375                                              ;Right  (higher -> bigger)                              //
  77. $LootingArea[3]         = 720                                               ;Bot    (higher -> bigger)                              //
  78. ;                                                                                                                                   //
  79. ;                                        TimeOuts                                                                                   //
  80. $GameLobbyTimeOut       = 25                                                ;Time (s) to wait for entering the gamelobby            //
  81. $GameplayScreenTimeOut  = 14                                                ;Time (s) to wait for entering the gameplay screen      //
  82. $CellarTimeOut          = 8                                                 ;Time (s) to wait for entering the cellar               //
  83. $TownTimeOut            = 8                                                 ;Time (s) to wait for entering the town                 //
  84. $MerchantTimeOut        = 8                                                 ;Time (s) to wait for reaching the merchant             //
  85. $ArtisanTimeOut         = 8                                                 ;Time (s) to wait for reaching the artisan              //
  86. $StashTimeOut           = 8                                                 ;Time (s) to wait for reaching the stash                //
  87. ;                                                                                                                                   //
  88. ;/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  89.  
  90. ScriptStarted()
  91.  
  92. While 1
  93.    While WinActive('Diablo III')
  94.       Randomize()
  95.  
  96.       Switch ResumeGame()
  97.          Case "LeftGame"
  98.             ExitLoop
  99.          Case "Network connection lost"
  100.             ExitLoop
  101.          Case "Relogged"
  102.             ExitLoop
  103.       EndSwitch
  104.        
  105.       MoveToCellar()
  106.        
  107.       Switch EnterCellar()
  108.          Case "LeftGame"
  109.             ExitLoop
  110.          Case "Network connection lost"
  111.             ExitLoop
  112.          Case "Relogged"
  113.             ExitLoop
  114.       EndSwitch
  115.        
  116.       MoveInCellar()
  117.       UseSkills()
  118.       KillSarkoth()
  119.       LootGold()
  120.        
  121.       Switch LootItems()
  122.          Case "LeftGame"
  123.             ExitLoop
  124.          Case "Network connection lost"
  125.             ExitLoop
  126.          Case "Relogged"
  127.             ExitLoop
  128.       EndSwitch
  129.        
  130.       If $InstantLeave = False Then
  131.          Switch TeleportToTown()
  132.             Case "LeftGame"
  133.                ExitLoop
  134.             Case "Network connection lost"
  135.                ExitLoop
  136.             Case "Relogged"
  137.                ExitLoop
  138.          EndSwitch
  139.       EndIf
  140.        
  141.       LeaveGame()
  142.     WEnd
  143. WEnd
  144.  
  145.  
  146. ;Routine
  147. Func ResumeGame()
  148.    If $UseRelogging = True Then
  149.       $Array = StringSplit($ImageFiles[7][4], "|")
  150.       $File = $Array[1]
  151.       $Accuracy = $Array[2]
  152.  
  153.       $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $LoginButtonSearchArea[0], $LoginButtonSearchArea[1], $LoginButtonSearchArea[2], $LoginButtonSearchArea[3], $ISx, $ISy, $Accuracy)
  154.       If $Target = 1 Then
  155.          Relog()
  156.          Return "Relogged"
  157.       EndIf
  158.    EndIf
  159.    
  160.    Switch InGameLobby()
  161.       Case "InGameLobby"
  162.          ToLog("Resuming game...")
  163.          MouseClick('LEFT', $ResumeButton[0], $ResumeButton[1], 1, 2)
  164.       Case "LeftGame"
  165.          Return "LeftGame"
  166.       Case "Relogged"
  167.          Return "Relogged"
  168.    EndSwitch
  169.  
  170.    Switch InGameplayScreen()
  171.       Case "LeftGame"
  172.          Return "LeftGame"
  173.       Case "InGamePlayScreen"
  174.          Return "InGamePlayScreen"
  175.       Case "Network connection lost"
  176.          Return "Network connection lost"
  177.       Case "Relogged"
  178.          Return "Relogged"
  179.    EndSwitch
  180. EndFunc
  181.  
  182. Func MoveToCellar()
  183.    If $StartGold = 0 Then
  184.       Sleep(1500)
  185.       GetGold()
  186.    EndIf
  187.    
  188.    $Sek = Floor(TimerDiff($RunTimer) / 1000)
  189.    If $Runs > 0 Then
  190.       ToLog("Last run took: " & $Sek & "s")
  191.    EndIf
  192.      
  193.    $RunTimer = TimerInit()
  194.  
  195.    ToLog("Starting run...")
  196.    $Runs += 1
  197.    RefreshStats()
  198.  
  199.    Sleep(375 + $ComputerLag)
  200.  
  201.    Send("{4}")
  202.    Sleep(30 + ($ComputerLag / 2))
  203.  
  204.    ToLog("Moving to cellar - 1")
  205.    Move($MoveToCellar1[0], $MoveToCellar1[1])
  206.    Sleep(1175 + $MoveDelay)
  207.  
  208.    ToLog("Moving to cellar - 2")
  209.    Move($MoveToCellar2[0], $MoveToCellar2[1])
  210.    Sleep(2075 + $MoveDelay)
  211.  
  212.    ToLog("Moving to cellar - 3")
  213.    Move($MoveToCellar3[0], $MoveToCellar3[1])
  214.    Sleep(1550 + $MoveDelay)
  215.  
  216.    Send("{2}")
  217.    Sleep(200 + $ComputerLag)
  218. EndFunc
  219.  
  220. Func EnterCellar()
  221.    MouseMove($CellarLocation[0], $CellarLocation[1], 2)
  222.    Sleep(100 + ($ComputerLag / 2))
  223.  
  224.    For $i = 0 To 2
  225.       $CellarPixel = PixelSearch($CellarSearchArea[0], $CellarSearchArea[1], $CellarSearchArea[2], $CellarSearchArea[3], 0x334FB7, 8)
  226.       If @error Then
  227.          ToLog("Cellar is closed")
  228.          $Closed += 1
  229.          RefreshStats()
  230.          If $InstantLeave = False Then
  231.             Switch TeleportToTown()
  232.                Case "LeftGame"
  233.                   Return "LeftGame"
  234.                Case "Network connection lost"
  235.                   Return "Network connection lost"
  236.                Case "Relogged"
  237.                   Return "Relogged"
  238.             EndSwitch
  239.          EndIf
  240.          LeaveGame()
  241.          Return "LeftGame"
  242.       Else
  243.          ToLog("Entering cellar...")
  244.          MouseClick('LEFT', $CellarLocation[0], $CellarLocation[1], 1, 2)
  245.          Switch InCellar()
  246.             Case "InCellar"
  247.                Return "InCellar"
  248.             Case "LeftGame"
  249.                Return "LeftGame"
  250.             Case "Network connection lost"
  251.                Return "Network connection lost"
  252.             Case "Relogged"
  253.                Return "Relogged"
  254.          EndSwitch
  255.       EndIf
  256.       Sleep(Random(20, 30, 1))
  257.    Next
  258. EndFunc
  259.  
  260. Func MoveInCellar()
  261.    ToLog("Moving in cellar - 1")
  262.    Move($MoveInCellar1[0], $MoveInCellar1[1])
  263.    Sleep(2050 + $MoveDelay)
  264.  
  265.    ToLog("Moving in cellar - 2")
  266.    Move($MoveInCellar2[0], $MoveInCellar2[1])
  267.    Sleep(1050 + $MoveDelay)
  268.  
  269.    MouseMove($MonsterLocation[0], $MonsterLocation[1], 2)
  270.    Sleep(50 + ($ComputerLag / 2))
  271. EndFunc
  272.  
  273. Func UseSkills()
  274.    ToLog("Using skills...")
  275.    Send("{1}")
  276.    Sleep(400 + $ComputerLag)
  277.  
  278.    Send("{3}")
  279.    Sleep(400 + $ComputerLag)
  280.  
  281.    MouseClick('RIGHT')
  282.    Sleep(250 + $ComputerLag)
  283. EndFunc
  284.  
  285. Func KillSarkoth()
  286.    ToLog("Killing Sarkoth...")
  287.    While 1
  288.       $MonsterBar = PixelSearch($MonsterSearchArea[0], $MonsterSearchArea[1], $MonsterSearchArea[2], $MonsterSearchArea[3], 0xEE0000, 10)
  289.       If @error Then
  290.          Attack($MonsterLocation[0], $MonsterLocation[1])
  291.          Sleep(600)
  292.            
  293.          $MonsterBar = PixelSearch($MonsterSearchArea[0], $MonsterSearchArea[1], $MonsterSearchArea[2], $MonsterSearchArea[3], 0xEE0000, 10)
  294.          If @error Then
  295.             ExitLoop
  296.          EndIf
  297.       EndIf
  298.        
  299.       Attack($MonsterBar[0], $MonsterBar[1])
  300.       Sleep(100)
  301.    WEnd
  302.    ToLog("All monsters are dead")
  303.  
  304.    Send("{4}")
  305.    Sleep(30 + ($ComputerLag / 2))
  306. EndFunc
  307.  
  308. Func LootGold()
  309.    If $ShowLootArea = True Then
  310.       DrawLootArea()
  311.    EndIf
  312.  
  313.    ToLog("Looting gold...")
  314.    If $HighGoldRadius = False Then
  315.       Move($MoveToGoldLoot1a[0], $MoveToGoldLoot1a[1])
  316.       Sleep(850 + $MoveDelay)
  317.       AttackNearbyMonsters()
  318.        
  319.       Move($MoveToGoldLoot2[0], $MoveToGoldLoot2[1])
  320.       Sleep(550 + $MoveDelay)
  321.       AttackNearbyMonsters()
  322.        
  323.       Move($MoveToGoldLoot3[0], $MoveToGoldLoot3[1])
  324.       Sleep(400 + $MoveDelay)
  325.       AttackNearbyMonsters()
  326.    Else
  327.       Move($MoveToGoldLoot1b[0], $MoveToGoldLoot1b[1])
  328.       Sleep(800 + $MoveDelay)
  329.       AttackNearbyMonsters()
  330.    EndIf
  331.  
  332.    MouseMove(Random(100, 140, 1), Random(100, 140, 1), 2)
  333.    Sleep(50)
  334. EndFunc
  335.  
  336. Func LootItems()
  337.    If $LootSets Then
  338.       Send("{ALT}")
  339.       Switch LootSets()
  340.          Case "LeftGame"
  341.             Return "LeftGame"
  342.          Case "Network connection lost"
  343.             Return "Network connection lost"
  344.          Case "Relogged"
  345.             Return "Relogged"
  346.       EndSwitch
  347.    EndIf
  348.  
  349.    If $LootLegendaries Then
  350.       Send("{ALT}")
  351.       Switch LootLegendaries()
  352.          Case "LeftGame"
  353.             Return "LeftGame"
  354.          Case "Network connection lost"
  355.             Return "Network connection lost"
  356.          Case "Relogged"
  357.             Return "Relogged"
  358.       EndSwitch
  359.    EndIf
  360.  
  361.    If $LootRares Then
  362.       Send("{ALT}")
  363.       Switch LootRares()
  364.          Case "LeftGame"
  365.             Return "LeftGame"
  366.          Case "Network connection lost"
  367.             Return "Network connection lost"
  368.          Case "Relogged"
  369.             Return "Relogged"
  370.       EndSwitch
  371.       $RareLootAttempts = 0
  372.    EndIf
  373.  
  374.    If $LootMagics Then
  375.       Send("{ALT}")
  376.       Switch LootMagics()
  377.          Case "LeftGame"
  378.             Return "LeftGame"
  379.          Case "Network connection lost"
  380.             Return "Network connection lost"
  381.          Case "Relogged"
  382.             Return "Relogged"
  383.       EndSwitch
  384.       $MagicLootAttempts = 0
  385.    Else
  386.       If $LootTomes Then
  387.          Send("{ALT}")
  388.          Switch LootTomes()
  389.             Case "LeftGame"
  390.                Return "LeftGame"
  391.             Case "Network connection lost"
  392.                Return "Network connection lost"
  393.             Case "Relogged"
  394.                Return "Relogged"
  395.          EndSwitch
  396.          $TomeLootAttempts = 0
  397.       EndIf
  398.    EndIf
  399.  
  400.    If $LootGems Then
  401.       Send("{ALT}")
  402.       Switch LootGems()
  403.          Case "LeftGame"
  404.             Return "LeftGame"
  405.          Case "Network connection lost"
  406.             Return "Network connection lost"
  407.          Case "Relogged"
  408.             Return "Relogged"
  409.       EndSwitch
  410.       $GemLootAttempts = 0
  411.    EndIf
  412.  
  413.    If $ShowLootArea = True Then
  414.       GUIDelete($LootAreaGUI)
  415.    EndIf
  416.  
  417.    Return "Looted"
  418. EndFunc
  419.  
  420. Func TeleportToTown()
  421.    ToLog("Teleporting to town...")
  422.    Sleep(50 + ($ComputerLag / 2))
  423.    Send("{t}")
  424.    
  425.    If $FullBag = False Then
  426.       If $CellarPixel = 0 Then
  427.          If $GoldDifference = 0 Then
  428.             GUICtrlSetData($DifferenceGoldLabel, "0")
  429.          EndIf
  430.          $Sek = Floor(TimerDiff($RuntimeTimer) / 1000)
  431.          $GPH = Floor(($CurrentGold - $StartGold) / ($Sek / 3600))
  432.          GUICtrlSetData($GPHLabel, _StringAddThousandsSep($GPH))
  433.          GUICtrlSetData($LastDifferenceGoldLabel, "0")
  434.       Else
  435.          GetGold()
  436.       EndIf
  437.    EndIf
  438.    
  439.    Switch InTown()
  440.       Case "InTown"
  441.          Return "InTown"
  442.       Case "LeftGame"
  443.          Return "LeftGame"
  444.       Case "Network connection lost"
  445.          Return "Network connection lost"
  446.       Case "Relogged"
  447.          Return "Relogged"
  448.    EndSwitch
  449. EndFunc
  450.  
  451.  
  452. ;Loot
  453. Func LootSets()
  454.    While $SetLootAttempts < $SetLootAmount
  455.       ToLog("Searching for sets... " & $SetLootAttempts + 1)
  456.       For $gI = 0 To 4
  457.          $Array = StringSplit($ImageFiles[1][$gI], "|")
  458.          $File = $Array[1]
  459.          $Accuracy = $Array[2]
  460.            
  461.          $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $LootingArea[0], $LootingArea[1], $LootingArea[2], $LootingArea[3], $ISx, $ISy, $Accuracy)
  462.          If $Target = 1 Then
  463.             ToLog("Set found")
  464.                
  465.             If $Sounds = True Then
  466.                SoundPlay($ReqFiles & "\sounds\" & $SoundFiles[1], 0)
  467.             EndIf
  468.                
  469.             MouseClick("LEFT", $ISx, $ISy, 1, 2)
  470.             Sleep(550 + $LootDelay)
  471.                
  472.             MouseMove(Random(100, 140, 1), Random(100, 140, 1), 2)
  473.             Sleep(50)
  474.                
  475.             If $Salvage = True Or $Sell = True Or $UseStash = True Then
  476.                Switch CheckBagFull()
  477.                   Case "LeftGame"
  478.                      Return "LeftGame"
  479.                   Case "Network connection lost"
  480.                      Return "Network connection lost"
  481.                   Case "Relogged"
  482.                      Return "Relogged"
  483.                EndSwitch
  484.                If $FullBag = True Then
  485.                   $FullBag = False
  486.                Else
  487.                   $SetLootAttempts += 1
  488.                   $Sets += 1
  489.                   RefreshStats()
  490.                EndIf
  491.             EndIf
  492.             ExitLoop
  493.          EndIf
  494.       Next
  495.       If $Target = 0 Then ExitLoop
  496.    WEnd
  497.    Return "Looted"
  498. EndFunc
  499.  
  500. Func LootLegendaries()
  501.    While $LegendaryLootAttempts < $LegendaryLootAmount
  502.       ToLog("Searching for legendaries... " & $LegendaryLootAttempts + 1)
  503.       For $gI = 0 To 4
  504.          $Array = StringSplit($ImageFiles[0][$gI], "|")
  505.          $File = $Array[1]
  506.          $Accuracy = $Array[2]
  507.            
  508.          $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $LootingArea[0], $LootingArea[1], $LootingArea[2], $LootingArea[3], $ISx, $ISy, $Accuracy)
  509.          If $Target = 1 Then
  510.             ToLog("Legendary found")
  511.                
  512.             If $Sounds = True Then
  513.                SoundPlay($ReqFiles & "\sounds\" & $SoundFiles[0], 0)
  514.             EndIf
  515.                
  516.             MouseClick("LEFT", $ISx, $ISy, 1, 2)
  517.             Sleep(550 + $LootDelay)
  518.                
  519.             MouseMove(Random(100, 140, 1), Random(100, 140, 1), 2)
  520.             Sleep(50)
  521.                
  522.             If $Salvage = True Or $Sell = True Or $UseStash = True Then
  523.                Switch CheckBagFull()
  524.                   Case "LeftGame"
  525.                      Return "LeftGame"
  526.                   Case "Network connection lost"
  527.                      Return "Network connection lost"
  528.                   Case "Relogged"
  529.                      Return "Relogged"
  530.                EndSwitch
  531.                If $FullBag = True Then
  532.                   $FullBag = False
  533.                Else
  534.                   $LegendaryLootAttempts += 1
  535.                   $Legendaries += 1
  536.                   RefreshStats()
  537.                EndIf
  538.             EndIf
  539.             ExitLoop
  540.          EndIf
  541.       Next
  542.       If $Target = 0 Then ExitLoop
  543.    WEnd
  544.    Return "Looted"
  545. EndFunc
  546.  
  547. Func LootRares()
  548.    While $RareLootAttempts < $RareLootAmount
  549.       ToLog("Searching for rares... " & $RareLootAttempts + 1)
  550.       For $gI = 0 To 4
  551.          $Array = StringSplit($ImageFiles[2][$gI], "|")
  552.          $File = $Array[1]
  553.          $Accuracy = $Array[2]
  554.            
  555.          $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $LootingArea[0], $LootingArea[1], $LootingArea[2], $LootingArea[3], $ISx, $ISy, $Accuracy)
  556.          If $Target = 1 Then
  557.             ToLog("Rare found")
  558.                
  559.             If $Sounds = True Then
  560.                SoundPlay($ReqFiles & "\sounds\" & $SoundFiles[2], 0)
  561.             EndIf
  562.                
  563.             MouseClick("LEFT", $ISx, $ISy, 1, 2)
  564.             Sleep(550 + $LootDelay)
  565.                
  566.             MouseMove(Random(100, 140, 1), Random(100, 140, 1), 2)
  567.             Sleep(50)
  568.                
  569.             If $Salvage = True Or $Sell = True Or $UseStash = True Then
  570.                Switch CheckBagFull()
  571.                   Case "LeftGame"
  572.                      Return "LeftGame"
  573.                   Case "Network connection lost"
  574.                      Return "Network connection lost"
  575.                   Case "Relogged"
  576.                      Return "Relogged"
  577.                EndSwitch
  578.                If $FullBag = True Then
  579.                   $FullBag = False
  580.                Else
  581.                   $RareLootAttempts += 1
  582.                   $Rares += 1
  583.                   RefreshStats()
  584.                EndIf
  585.             EndIf
  586.             ExitLoop
  587.          EndIf
  588.       Next
  589.       If $Target = 0 Then ExitLoop
  590.    WEnd
  591.    Return "Looted"
  592. EndFunc
  593.  
  594. Func LootMagics()
  595.    While $MagicLootAttempts < $MagicLootAmount
  596.       ToLog("Searching for magics... " & $MagicLootAttempts + 1)
  597.       For $gI = 0 To 4
  598.          $Array = StringSplit($ImageFiles[3][$gI], "|")
  599.          $File = $Array[1]
  600.          $Accuracy = $Array[2]
  601.            
  602.          $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $LootingArea[0], $LootingArea[1], $LootingArea[2], $LootingArea[3], $ISx, $ISy, $Accuracy)
  603.          If $Target = 1 Then
  604.             ToLog("Magic found")
  605.                
  606.             If $Sounds = True Then
  607.                SoundPlay($ReqFiles & "\sounds\" & $SoundFiles[3], 0)
  608.             EndIf
  609.                
  610.             MouseClick("LEFT", $ISx, $ISy, 1, 2)
  611.             Sleep(550 + $LootDelay)
  612.                
  613.             MouseMove(Random(100, 140, 1), Random(100, 140, 1), 2)
  614.             Sleep(50)
  615.                
  616.             If $Salvage = True Or $Sell = True Or $UseStash = True Then
  617.                Switch CheckBagFull()
  618.                   Case "LeftGame"
  619.                      Return "LeftGame"
  620.                   Case "Network connection lost"
  621.                      Return "Network connection lost"
  622.                   Case "Relogged"
  623.                      Return "Relogged"
  624.                EndSwitch
  625.                If $FullBag = True Then
  626.                   $FullBag = False
  627.                Else
  628.                   $MagicLootAttempts += 1
  629.                   $Magics += 1
  630.                   RefreshStats()
  631.                EndIf
  632.             EndIf
  633.             ExitLoop
  634.          EndIf
  635.       Next
  636.       If $Target = 0 Then ExitLoop
  637.    WEnd
  638.    Return "Looted"
  639. EndFunc
  640.  
  641. Func LootTomes()
  642.    While $TomeLootAttempts < $TomeLootAmount
  643.       ToLog("Searching for Tomes of Secrets... " & $TomeLootAttempts + 1)
  644.       $Array = StringSplit($ImageFiles[4][0], "|")
  645.       $File = $Array[1]
  646.       $Accuracy = $Array[2]
  647.        
  648.       $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $LootingArea[0], $LootingArea[1], $LootingArea[2], $LootingArea[3], $ISx, $ISy, $Accuracy)
  649.       If $Target = 1 Then
  650.          ToLog("Tome of Secrets found")
  651.            
  652.          If $Sounds = True Then
  653.             SoundPlay($ReqFiles & "\sounds\" & $SoundFiles[4], 0)
  654.          EndIf
  655.            
  656.          MouseClick("LEFT", $ISx, $ISy, 1, 2)
  657.          Sleep(550 + $LootDelay)
  658.            
  659.          MouseMove(Random(100, 140, 1), Random(100, 140, 1), 2)
  660.          Sleep(50)
  661.            
  662.          If $Salvage = True Or $Sell = True Or $UseStash = True Then
  663.             Switch CheckBagFull()
  664.                Case "LeftGame"
  665.                   Return "LeftGame"
  666.                Case "Network connection lost"
  667.                   Return "Network connection lost"
  668.                Case "Relogged"
  669.                   Return "Relogged"
  670.             EndSwitch
  671.             If $FullBag = True Then
  672.                $FullBag = False
  673.             Else
  674.                $TomeLootAttempts += 1
  675.                $Tomes += 1
  676.                RefreshStats()
  677.             EndIf
  678.          EndIf
  679.       EndIf
  680.       If $Target = 0 Then ExitLoop
  681.    WEnd
  682.    Return "Looted"
  683. EndFunc
  684.  
  685. Func LootGems()
  686.    While $GemLootAttempts < $GemLootAmount
  687.       ToLog("Searching for Gems... " & $GemLootAttempts + 1)
  688.        
  689.       If $FlawlessOnly = True Then
  690.          $Array = StringSplit($ImageFiles[4][6], "|")
  691.       Else
  692.          $Array = StringSplit($ImageFiles[4][5], "|")
  693.       EndIf
  694.      
  695.       $File = $Array[1]
  696.       $Accuracy = $Array[2]
  697.          
  698.       $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $LootingArea[0], $LootingArea[1], $LootingArea[2], $LootingArea[3], $ISx, $ISy, $Accuracy)
  699.       If $Target = 1 Then
  700.          ToLog("Gem found")
  701.            
  702.          If $Sounds = True Then
  703.             SoundPlay($ReqFiles & "\sounds\" & $SoundFiles[5], 0)
  704.          EndIf
  705.            
  706.          MouseClick("LEFT", $ISx, $ISy, 1, 2)
  707.          Sleep(550 + $LootDelay)
  708.            
  709.          MouseMove(Random(100, 140, 1), Random(100, 140, 1), 2)
  710.          Sleep(50)
  711.            
  712.          If $Salvage = True Or $Sell = True Or $UseStash = True Then
  713.             Switch CheckBagFull()
  714.                Case "LeftGame"
  715.                   Return "LeftGame"
  716.                Case "Network connection lost"
  717.                   Return "Network connection lost"
  718.                Case "Relogged"
  719.                   Return "Relogged"
  720.             EndSwitch
  721.             If $FullBag = True Then
  722.                $FullBag = False
  723.             Else
  724.                $GemLootAttempts += 1
  725.                $Gems += 1
  726.                RefreshStats()
  727.             EndIf
  728.          EndIf
  729.       EndIf
  730.       If $Target = 0 Then ExitLoop
  731.    WEnd
  732.    Return "Looted"
  733. EndFunc
  734.  
  735.  
  736. ;Sell, salvage, store and repair
  737. Func CheckBagFull()
  738.    $Array = StringSplit($ImageFiles[6][4], "|")
  739.    $File = $Array[1]
  740.    $Accuracy = $Array[2]
  741.  
  742.    $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $FullBagSearchArea[0], $FullBagSearchArea[1], $FullBagSearchArea[2], $FullBagSearchArea[3], $ISx, $ISy, $Accuracy)
  743.    If $Target = 1 Then
  744.       ToLog("Our bag is full")
  745.       $FullBag = True
  746.       Switch SellItems()
  747.          Case "LeftGame"
  748.             Return "LeftGame"
  749.          Case "Network connection lost"
  750.             Return "Network connection lost"
  751.          Case "Relogged"
  752.             Return "Relogged"
  753.       EndSwitch
  754.    EndIf
  755.    Return "BagNotFull"
  756. EndFunc
  757.  
  758. Func SellItems()
  759.    If $Salvage = True Then
  760.       If $KeepLevel >= 62 Then
  761.          $SellCheck = 61
  762.       Else
  763.          $SellCheck = $KeepLevel
  764.       EndIf
  765.    Else
  766.       $SellCheck = $KeepLevel
  767.    EndIf
  768.  
  769.    If $ShowLootArea = True Then
  770.       GUIDelete($LootAreaGUI)
  771.    EndIf
  772.  
  773.    Switch TeleportToTown()
  774.       Case "LeftGame"
  775.          Return "LeftGame"
  776.       Case "Network connection lost"
  777.          Return "Network connection lost"
  778.       Case "Relogged"
  779.          Return "Relogged"
  780.    EndSwitch
  781.  
  782.    If $Sell = True Then
  783.       Switch MoveToMerchant()
  784.          Case "LeftGame"
  785.             Return "LeftGame"
  786.          Case "Network connection lost"
  787.             Return "Network connection lost"
  788.          Case "Relogged"
  789.             Return "Relogged"
  790.       EndSwitch
  791.  
  792.       ToLog("Selling...")
  793.  
  794.       $Count = 0
  795.  
  796.       RandomizeInventory()
  797.  
  798.       While UBound($Stash) > 0
  799.          $r = Random(0, UBound($Stash) - 1, 1)
  800.            
  801.          $Array = StringSplit($ImageFiles[5][0], "|")
  802.          $File = $Array[1]
  803.          $Accuracy = $Array[2]
  804.          $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $Stash[$r][0] - 35, $Stash[$r][1] - 35, $Stash[$r][0] + 35, $Stash[$r][1] + 35, 0, 0, $Accuracy)
  805.          If Not $Target = 1 Then
  806.             MouseMove($Stash[$r][0], $Stash[$r][1], 0)
  807.             Sleep(150 + $SellDelay)
  808.             $Array = StringSplit($ImageFiles[5][1], "|")
  809.             $File = $Array[1]
  810.             $Accuracy = $Array[2]
  811.                
  812.             $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 0, $SellItemsArea[0], $SellItemsArea[1], $SellItemsArea[2], $SellItemsArea[3], $ISx, $ISy, $Accuracy)
  813.             If $Target = 1 Then
  814.                For $gI = 2 To 6
  815.                   $Array = StringSplit($ImageFiles[5][$gI], "|")
  816.                   $File = $Array[1]
  817.                   $Accuracy = $Array[2]
  818.                        
  819.                   $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $ISx, $ISy, $ISx + 450, $ISy + 90, 0, 0, $Accuracy)
  820.                        
  821.                   If $Target = 1 Then
  822.                      If $KeepHighLevel = True Then
  823.                         Switch $SellCheck
  824.                            Case 60
  825.                               For $gI = 1 To 4
  826.                                  $Array = StringSplit($ImageFiles[4][$gI], "|")
  827.                                  $File = $Array[1]
  828.                                  $Accuracy = $Array[2]
  829.                                            
  830.                                  $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $ISx, $ISy + 210, $ISx + 140, $ISy + 420, 0, 0, $Accuracy)
  831.                                            
  832.                                  If $Target = 1 Then
  833.                                     ExitLoop 2
  834.                                  EndIf
  835.                               Next
  836.                                        
  837.                            Case 61
  838.                               For $gI = 2 To 4
  839.                                  $Array = StringSplit($ImageFiles[4][$gI], "|")
  840.                                  $File = $Array[1]
  841.                                  $Accuracy = $Array[2]
  842.                                            
  843.                                  $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $ISx, $ISy + 210, $ISx + 140, $ISy + 420, 0, 0, $Accuracy)
  844.                                            
  845.                                  If $Target = 1 Then
  846.                                     ExitLoop 2
  847.                                  EndIf
  848.                               Next
  849.                                        
  850.                            Case 62
  851.                               For $gI = 3 To 4
  852.                                  $Array = StringSplit($ImageFiles[4][$gI], "|")
  853.                                  $File = $Array[1]
  854.                                  $Accuracy = $Array[2]
  855.                                            
  856.                                  $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $ISx, $ISy + 210, $ISx + 140, $ISy + 420, 0, 0, $Accuracy)
  857.                                            
  858.                                  If $Target = 1 Then
  859.                                     ExitLoop 2
  860.                                  EndIf
  861.                               Next
  862.                                        
  863.                            Case 63
  864.                               $Array = StringSplit($ImageFiles[4][4], "|")
  865.                               $File = $Array[1]
  866.                               $Accuracy = $Array[2]
  867.                                        
  868.                               $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $ISx, $ISy + 210, $ISx + 140, $ISy + 420, 0, 0, $Accuracy)
  869.                                        
  870.                               If $Target = 1 Then
  871.                                  ExitLoop
  872.                               EndIf
  873.                         EndSwitch
  874.                         MouseClick("RIGHT")
  875.                         $Count += 1
  876.                         $Sold += 1
  877.                         ExitLoop
  878.                      Else
  879.                         If $Salvage = True Then
  880.                            For $gI = 2 To 4
  881.                               $Array = StringSplit($ImageFiles[4][$gI], "|")
  882.                               $File = $Array[1]
  883.                               $Accuracy = $Array[2]
  884.                                        
  885.                               $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $ISx, $ISy + 210, $ISx + 140, $ISy + 420, 0, 0, $Accuracy)
  886.                                        
  887.                               If $Target = 1 Then
  888.                                  ExitLoop 2
  889.                               EndIf
  890.                            Next
  891.                         EndIf
  892.                         MouseClick("RIGHT")
  893.                         $Count += 1
  894.                         $Sold += 1
  895.                         ExitLoop
  896.                      EndIf
  897.                   EndIf
  898.                Next
  899.                MouseMove(Random(1710, 1770, 1), Random(970, 1030, 1), 0)
  900.                Sleep(150 + $SellDelay)
  901.             EndIf
  902.          EndIf
  903.          _ArrayDelete($Stash, $r)
  904.       WEnd
  905.  
  906.       ToLog("Selling... done - Sold " & $Count & " items")
  907.    EndIf
  908.    
  909.    Sleep(100 + ($ComputerLag / 2))
  910.    Send("{ESC}")
  911.  
  912.    $RareLootAttempts = 0
  913.    $MagicLootAttempts = 0
  914.    $TomeLootAttempts = 0
  915.    $GemLootAttempts = 0
  916.  
  917.    If $Salvage = True Then
  918.       Switch MoveToSalvage()
  919.          Case "LeftGame"
  920.             Return "LeftGame"
  921.          Case "Network connection lost"
  922.             Return "Network connection lost"
  923.          Case "Relogged"
  924.             Return "Relogged"
  925.       EndSwitch
  926.    EndIf
  927.  
  928.    Switch MoveToStash()
  929.       Case "LeftGame"
  930.          Return "LeftGame"
  931.       Case "Network connection lost"
  932.          Return "Network connection lost"
  933.       Case "Relogged"
  934.          Return "Relogged"
  935.    EndSwitch
  936.  
  937.    Sleep(150 + $ComputerLag)
  938.  
  939.    MouseClick("LEFT", $PortalLocation[0], $PortalLocation[1], 1, 2)
  940.  
  941.    Switch InCellar()
  942.       Case "InCellar"
  943.          If $ShowLootArea = True Then
  944.             DrawLootArea()
  945.          EndIf
  946.          Sleep(500 + ($ComputerLag / 2))
  947.          Return "InCellar"
  948.       Case "LeftGame"
  949.          Return "LeftGame"
  950.       Case "Network connection lost"
  951.          Return "Network connection lost"
  952.       Case "Relogged"
  953.          Return "Relogged"
  954.    EndSwitch
  955. EndFunc
  956.  
  957. Func SalvageItems()
  958.    ToLog("Salvaging...")
  959.  
  960.    $Count = 0
  961.  
  962.    RandomizeInventory()
  963.    While UBound($Stash) > 0
  964.       $r = Random(0, UBound($Stash) - 1, 1)
  965.        
  966.       $Array = StringSplit($ImageFiles[5][0], "|")
  967.       $File = $Array[1]
  968.       $Accuracy = $Array[2]
  969.        
  970.       $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $Stash[$r][0] - 25, $Stash[$r][1] - 25, $Stash[$r][0] + 25, $Stash[$r][1] + 25, 0, 0, $Accuracy)
  971.       If Not $Target = 1 Then
  972.          MouseMove($Stash[$r][0], $Stash[$r][1], 1)
  973.          Sleep(150 + $SalvageDelay)
  974.          $Array = StringSplit($ImageFiles[5][1], "|")
  975.          $File = $Array[1]
  976.          $Accuracy = $Array[2]
  977.            
  978.          $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 0, $SellItemsArea[0], $SellItemsArea[1], $SellItemsArea[2], $SellItemsArea[3], $ISx, $ISy, $Accuracy)
  979.          If $Target = 1 Then
  980.             For $gI = 2 To 6
  981.                $Array = StringSplit($ImageFiles[5][$gI], "|")
  982.                $File = $Array[1]
  983.                $Accuracy = $Array[2]
  984.                    
  985.                $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $ISx, $ISy, $ISx + 420, $ISy + 75, 0, 0, $Accuracy)
  986.                    
  987.                If $Target = 1 Then
  988.                   If $Sell = True Then
  989.                      If $KeepHighLevel = True Then
  990.                         Switch $KeepLevel
  991.                            Case 60
  992.                               ExitLoop
  993.                              
  994.                            Case 61
  995.                               $Array = StringSplit($ImageFiles[4][1], "|")
  996.                               $File = $Array[1]
  997.                               $Accuracy = $Array[2]
  998.                                        
  999.                               $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $ISx, $ISy + 210, $ISx + 140, $ISy + 420, 0, 0, $Accuracy)
  1000.                                        
  1001.                               If $Target = 1 Then
  1002.                                  MouseClick("LEFT")
  1003.                                  MouseClick("LEFT", $SalvageButton[0], $SalvageButton[1], 1, 2)
  1004.                                  $Count += 1
  1005.                                  $Salvaged += 1
  1006.                                  Sleep(50 + $SalvageDelay)
  1007.                                  ExitLoop
  1008.                               EndIf
  1009.                                        
  1010.                            Case 62
  1011.                               For $gI = 1 To 2
  1012.                                  $Array = StringSplit($ImageFiles[4][$gI], "|")
  1013.                                  $File = $Array[1]
  1014.                                  $Accuracy = $Array[2]
  1015.                                            
  1016.                                  $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $ISx, $ISy + 210, $ISx + 140, $ISy + 420, 0, 0, $Accuracy)
  1017.                                            
  1018.                                  If $Target = 1 Then
  1019.                                     MouseClick("LEFT")
  1020.                                     MouseClick("LEFT", $SalvageButton[0], $SalvageButton[1], 1, 2)
  1021.                                     $Count += 1
  1022.                                     $Salvaged += 1
  1023.                                     Sleep(50 + $SalvageDelay)
  1024.                                     ExitLoop 2
  1025.                                  EndIf
  1026.                               Next
  1027.                                        
  1028.                            Case 63
  1029.                               For $gI = 1 To 3
  1030.                                  $Array = StringSplit($ImageFiles[4][$gI], "|")
  1031.                                  $File = $Array[1]
  1032.                                  $Accuracy = $Array[2]
  1033.                                            
  1034.                                  $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $ISx, $ISy + 210, $ISx + 140, $ISy + 420, 0, 0, $Accuracy)
  1035.                                            
  1036.                                  If $Target = 1 Then
  1037.                                     MouseClick("LEFT")
  1038.                                     MouseClick("LEFT", $SalvageButton[0], $SalvageButton[1], 1, 2)
  1039.                                     $Count += 1
  1040.                                     $Salvaged += 1
  1041.                                     Sleep(50 + $SalvageDelay)
  1042.                                     ExitLoop 2
  1043.                                  EndIf
  1044.                               Next
  1045.                         EndSwitch
  1046.                         ExitLoop
  1047.                      Else
  1048.                         For $gI = 1 To 4
  1049.                            $Array = StringSplit($ImageFiles[4][$gI], "|")
  1050.                            $File = $Array[1]
  1051.                            $Accuracy = $Array[2]
  1052.  
  1053.                            $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $ISx, $ISy + 210, $ISx + 140, $ISy + 420, 0, 0, $Accuracy)
  1054.                                    
  1055.                            If $Target = 1 Then
  1056.                               MouseClick("LEFT")
  1057.                               MouseClick("LEFT", $SalvageButton[0], $SalvageButton[1], 1, 2)
  1058.                               $Count += 1
  1059.                               $Salvaged += 1
  1060.                               Sleep(50 + $SalvageDelay)
  1061.                               ExitLoop 2
  1062.                            EndIf
  1063.                         Next
  1064.                      EndIf
  1065.                   Else
  1066.                      MouseClick("LEFT")
  1067.                      MouseClick("LEFT", $SalvageButton[0], $SalvageButton[1], 1, 2)
  1068.                      $Count += 1
  1069.                      $Salvaged += 1
  1070.                      Sleep(50 + $SalvageDelay)
  1071.                      ExitLoop
  1072.                   EndIf
  1073.                EndIf
  1074.             Next
  1075.             MouseMove(Random(1710, 1770, 1), Random(970, 1030, 1), 2)
  1076.             Sleep(150 + $SalvageDelay)
  1077.          EndIf
  1078.       EndIf
  1079.       _ArrayDelete($Stash, $r)
  1080.    WEnd
  1081.  
  1082.    ToLog("Salvaging... done - Salvaged " & $Count & " items")
  1083. EndFunc
  1084.  
  1085. Func PutInStash()
  1086.    ToLog("Storing items in the stash...")
  1087.  
  1088.    RandomizeInventory()
  1089.  
  1090.    While UBound($Stash) > 0
  1091.       $r = Random(0, UBound($Stash) - 1, 1)
  1092.       $Array = StringSplit($ImageFiles[5][0], "|")
  1093.       $File = $Array[1]
  1094.       $Accuracy = $Array[2]
  1095.        
  1096.       $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $Stash[$r][0] - 25, $Stash[$r][1] - 25, $Stash[$r][0] + 25, $Stash[$r][1] + 25, $ISx, $ISy, $Accuracy)
  1097.       If Not $Target = 1 Then
  1098.          MouseClick("RIGHT", $Stash[$r][0], $Stash[$r][1], 1, 0)
  1099.          Sleep(50 + $StashDelay)
  1100.          If Not CheckStashFull() = 1 Then
  1101.             _ArrayDelete($Stash, $r)
  1102.          EndIf
  1103.       Else
  1104.          _ArrayDelete($Stash, $r)
  1105.       EndIf
  1106.       If $UseStash = False Then
  1107.          ExitLoop
  1108.       EndIf
  1109.    WEnd
  1110.  
  1111.    ToLog("Storing items in the stash... done")
  1112. EndFunc
  1113.  
  1114. Func CheckStashFull()
  1115.    $Array = StringSplit($ImageFiles[6][3], "|")
  1116.    $File = $Array[1]
  1117.    $Accuracy = $Array[2]
  1118.  
  1119.    $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $FullStashSearchArea[0], $FullStashSearchArea[1], $FullStashSearchArea[2], $FullStashSearchArea[3], $ISx, $ISy, $Accuracy)
  1120.    If $Target = 1 Then
  1121.       Switch $StashBag
  1122.          Case 1
  1123.             ToLog("First stashbag is full - changing...")
  1124.             Sleep(100 + ($ComputerLag / 2))
  1125.             MouseClick("LEFT", $StashBag2[0], $StashBag2[1], 1, 2)
  1126.             $StashBag = 2
  1127.             Sleep(5000)
  1128.          Case 2
  1129.             ToLog("Second stashbag is full - changing...")
  1130.             Sleep(100 + ($ComputerLag / 2))
  1131.             MouseClick("LEFT", $StashBag3[0], $StashBag3[1], 1, 2)
  1132.             $StashBag = 3
  1133.             Sleep(5000)
  1134.          Case 3
  1135.             ToLog("Third stashbag is full - aborting...")
  1136.             $UseStash = False
  1137.       EndSwitch
  1138.       Return 1
  1139.    EndIf
  1140.    Return 0
  1141. EndFunc
  1142.  
  1143. Func RepairItems()
  1144.    If Not CheckForRepair() Then
  1145.       Return "NotDamaged"
  1146.    EndIf
  1147.  
  1148.    Switch MoveToMerchant()
  1149.       Case "LeftGame"
  1150.          Return "LeftGame"
  1151.       Case "Network connection lost"
  1152.          Return "Network connection lost"
  1153.       Case "Relogged"
  1154.          Return "Relogged"
  1155.    EndSwitch
  1156.  
  1157.    ToLog("Repairing...")
  1158.    MouseClick('LEFT', $RepairButton[0], $RepairButton[1], 1, 2)
  1159.    Sleep(100 + ($ComputerLag / 2))
  1160.  
  1161.    MouseClick('LEFT', $AllItemsButton[0], $AllItemsButton[1], 1, 2)
  1162.    Sleep(100 + ($ComputerLag / 2))
  1163.  
  1164.    Send("{ESC}")
  1165.    ToLog("Repairing... done")
  1166.    Return "Repaired"
  1167. EndFunc
  1168.  
  1169. Func CheckForRepair()
  1170.    $RepairNeeded = PixelSearch($RepairSearchArea[0], $RepairSearchArea[1], $RepairSearchArea[2], $RepairSearchArea[3], 0xFFE801, 10)
  1171.    If Not @error Then
  1172.       ToLog("We need to repair")
  1173.       Return True
  1174.    Else
  1175.       $RepairNeeded = PixelSearch($RepairSearchArea[0], $RepairSearchArea[1], $RepairSearchArea[2], $RepairSearchArea[3], 0xDE0000, 10)
  1176.       If Not @error Then
  1177.          ToLog("We need to repair")
  1178.          Return True
  1179.       Else
  1180.          Return False
  1181.       EndIf
  1182.    EndIf
  1183. EndFunc
  1184.  
  1185. Func MoveToSalvage()
  1186.    Sleep(350 + $ComputerLag)
  1187.    ToLog("Waiting to get to the salvage... (TimeOut " & $ArtisanTimeOut & "s)")
  1188.  
  1189.    ToLog("Moving to salvage - 1")
  1190.    Move($MoveToSalvage1[0], $MoveToSalvage1[1])
  1191.    Sleep($SleepToSalvage + $MoveDelay)
  1192.  
  1193.    ToLog("Moving to salvage - 2")
  1194.    Move($MoveToSalvage2[0], $MoveToSalvage2[1])
  1195.    Sleep($SleepToSalvage + $MoveDelay)
  1196.  
  1197.    ToLog("Moving to salvage - 3")
  1198.    MouseClick('LEFT', $SalvageLocation[0], $SalvageLocation[1], 1, 2)
  1199.  
  1200.    Switch AtSalvage()
  1201.       Case "LeftGame"
  1202.          Return "LeftGame"
  1203.       Case "Network connection lost"
  1204.          Return "Network connection lost"
  1205.       Case "Relogged"
  1206.          Return "Relogged"
  1207.    EndSwitch
  1208.  
  1209.    SalvageItems()
  1210.    Sleep(100 + ($ComputerLag / 2))
  1211.    Send("{ESC}")
  1212.    Return "Salvaged"
  1213. EndFunc
  1214.  
  1215. Func MoveToMerchant()
  1216.    Sleep(350 + $ComputerLag)
  1217.    ToLog("Waiting to get to the merchant... (TimeOut " & $MerchantTimeOut & "s)")
  1218.  
  1219.    ToLog("Moving to merchant - 1")
  1220.    Move($MoveToMerchant[0], $MoveToMerchant[1])
  1221.    Sleep(3500 + $MoveDelay)
  1222.  
  1223.    ToLog("Moving to merchant - 2")
  1224.    MouseClick('LEFT', $MerchantLocation[0], $MerchantLocation[1], 1, 2)
  1225.  
  1226.    Switch AtMerchant()
  1227.       Case "AtMerchant"
  1228.          Return "AtMerchant"
  1229.       Case "LeftGame"
  1230.          Return "LeftGame"
  1231.       Case "Network connection lost"
  1232.          Return "Network connection lost"
  1233.       Case "Relogged"
  1234.          Return "Relogged"
  1235.    EndSwitch
  1236. EndFunc
  1237.  
  1238. Func MoveToStash()
  1239.    ToLog("Waiting to get to the stash... (TimeOut " & $StashTimeOut & "s)")
  1240.  
  1241.    If $Salvage = True Or $Sell = True Then
  1242.       ToLog("Moving to stash - 1")
  1243.       Move($MoveToStash1[0], $MoveToStash1[1])
  1244.       Sleep($SleepToStash + $MoveDelay)
  1245.  
  1246.       ToLog("Moving to stash - 2")
  1247.       Move($MoveToStash2[0], $MoveToStash2[1])
  1248.       Sleep($SleepToStash + $MoveDelay)
  1249.    EndIf
  1250.  
  1251.    If $UseStash = True Then
  1252.       $StashBag = 1
  1253.       MouseClick("LEFT", $StashLocation[0], $StashLocation[1], 1, 2)
  1254.       Switch AtStash()
  1255.          Case "LeftGame"
  1256.             Return "LeftGame"
  1257.          Case "Network connection lost"
  1258.             Return "Network connection lost"
  1259.          Case "Relogged"
  1260.             Return "Relogged"
  1261.       EndSwitch
  1262.       PutInStash()
  1263.       Sleep(100 + ($ComputerLag / 2))
  1264.       Send("{ESC}")
  1265.    EndIf
  1266.    Return "AtStash"
  1267. EndFunc
  1268.  
  1269.  
  1270. ;Check state, disconnect and death
  1271. Func InLoginScreen()
  1272.    ToLog("Waiting to get into the login screen...")
  1273.  
  1274.    While 1
  1275.       $Array = StringSplit($ImageFiles[7][4], "|")
  1276.       $File = $Array[1]
  1277.       $Accuracy = $Array[2]
  1278.  
  1279.       $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $LoginButtonSearchArea[0], $LoginButtonSearchArea[1], $LoginButtonSearchArea[2], $LoginButtonSearchArea[3], $ISx, $ISy, $Accuracy)
  1280.       If $Target = 1 Then
  1281.          Return True
  1282.       Else
  1283.          Sleep(200)
  1284.       EndIf
  1285.    WEnd
  1286. EndFunc
  1287.  
  1288. Func InGameLobby()
  1289.    ToLog("Waiting to get into the game lobby... (TimeOut " & $GameLobbyTimeOut & "s)")
  1290.    $TimeOutTimer = TimerInit()
  1291.  
  1292.    While 1
  1293.       $Array = StringSplit($ImageFiles[7][2], "|")
  1294.       $File = $Array[1]
  1295.       $Accuracy = $Array[2]
  1296.  
  1297.       $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $ResumeButtonSearchArea[0], $ResumeButtonSearchArea[1], $ResumeButtonSearchArea[2], $ResumeButtonSearchArea[3], $ISx, $ISy, $Accuracy)
  1298.       If $Target = 1 Then
  1299.          $DisconnectState = 0
  1300.          Return "InGameLobby"
  1301.       Else
  1302.          If Floor(TimerDiff($TimeOutTimer) / 1000) >= $GameLobbyTimeOut Then
  1303.             ToLog("GameLobby TimeOut - Trying again")
  1304.                
  1305.             If $Relogged = True Then
  1306.                Send("{ESC}")
  1307.                MouseClick("LEFT", $PasswordField[0] + 250, $PasswordField[1], 1, 2)
  1308.                For $i = 0 To StringLen($Password) - 1
  1309.                   Send("{BACKSPACE}")
  1310.                Next
  1311.                $Relogged = False
  1312.             Else
  1313.                MouseMove($ResumeButton[0], $ResumeButton[1] - 100, 0)
  1314.                LeaveGame()
  1315.             EndIf
  1316.                
  1317.             Return "LeftGame"
  1318.          EndIf
  1319.          Switch CheckForDisconnect()
  1320.             Case "Network connection lost"
  1321.                Return "Network connection lost"
  1322.             Case "Relogged"
  1323.                Return "Relogged"
  1324.          EndSwitch
  1325.          Sleep(200)
  1326.       EndIf
  1327.    WEnd
  1328. EndFunc
  1329.  
  1330. Func InGameplayScreen()
  1331.    ToLog("Waiting to get into the game... (TimeOut " & $GameplayScreenTimeOut & "s)")
  1332.    $TimeOutTimer = TimerInit()
  1333.  
  1334.    While 1
  1335.       $Array = StringSplit($ImageFiles[7][3], "|")
  1336.       $File = $Array[1]
  1337.       $Accuracy = $Array[2]
  1338.  
  1339.       $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $PortalIconSearchArea[0], $PortalIconSearchArea[1], $PortalIconSearchArea[2], $PortalIconSearchArea[3], $ISx, $ISy, $Accuracy)
  1340.       If $Target = 1 Then
  1341.          $Alive = True
  1342.          $DisconnectState = 0
  1343.          Return "InGamePlayScreen"
  1344.       Else
  1345.          If Floor(TimerDiff($TimeOutTimer) / 1000) >= $GameplayScreenTimeOut Then
  1346.             $TimeOutTimer = TimerInit()
  1347.             ToLog("GameplayScreen TimeOut - Leaving")
  1348.             Return "LeftGame"
  1349.          EndIf
  1350.          If CheckForDeath() = "LeftGame" Then
  1351.             Return "LeftGame"
  1352.          EndIf
  1353.          Sleep(100)
  1354.          Switch CheckForDisconnect()
  1355.             Case "Network connection lost"
  1356.                Return "Network connection lost"
  1357.             Case "Relogged"
  1358.                Return "Relogged"
  1359.          EndSwitch
  1360.          Sleep(100)
  1361.       EndIf
  1362.    WEnd
  1363. EndFunc
  1364.  
  1365. Func InCellar()
  1366.    ToLog("Waiting to get into the cellar... (TimeOut " & $CellarTimeOut & "s)")
  1367.    $TimeOutTimer = TimerInit()
  1368.  
  1369.    While 1
  1370.       $Array = StringSplit($ImageFiles[7][0], "|")
  1371.       $File = $Array[1]
  1372.       $Accuracy = $Array[2]
  1373.  
  1374.       $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $CellarNameSearchArea[0], $CellarNameSearchArea[1], $CellarNameSearchArea[2], $CellarNameSearchArea[3], $ISx, $ISy, $Accuracy)
  1375.       If $Target = 1 Then
  1376.          Return "InCellar"
  1377.       Else
  1378.          If Floor(TimerDiff($TimeOutTimer) / 1000) >= $CellarTimeOut Then
  1379.             ToLog("Cellar TimeOut - Leaving")
  1380.             LeaveGame()
  1381.             Return "LeftGame"
  1382.          EndIf
  1383.          If CheckForDeath() = "LeftGame" Then
  1384.             Return "LeftGame"
  1385.          EndIf
  1386.          Sleep(100)
  1387.          Switch CheckForDisconnect()
  1388.             Case "Network connection lost"
  1389.                Return "Network connection lost"
  1390.             Case "Relogged"
  1391.                Return "Relogged"
  1392.          EndSwitch
  1393.          Sleep(100)
  1394.       EndIf
  1395.    WEnd
  1396. EndFunc
  1397.  
  1398. Func InTown()
  1399.    ToLog("Waiting to get into the town... (TimeOut " & $TownTimeOut & "s)")
  1400.    $TimeOutTimer = TimerInit()
  1401.  
  1402.    While 1
  1403.       $Array = StringSplit($ImageFiles[7][1], "|")
  1404.       $File = $Array[1]
  1405.       $Accuracy = $Array[2]
  1406.  
  1407.       $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $TownNameSearchArea[0], $TownNameSearchArea[1], $TownNameSearchArea[2], $TownNameSearchArea[3], $ISx, $ISy, $Accuracy)
  1408.       If $Target = 1 Then
  1409.          If $Repair And Not $FullBag Then
  1410.             Switch RepairItems()
  1411.                Case "LeftGame"
  1412.                   Return "LeftGame"
  1413.                Case "Network connection lost"
  1414.                   Return "Network connection lost"
  1415.                Case "Relogged"
  1416.                   Return "Relogged"
  1417.                EndSwitch
  1418.          EndIf
  1419.          Return "InTown"
  1420.       Else
  1421.          If Floor(TimerDiff($TimeOutTimer) / 1000) >= $TownTimeOut Then
  1422.             $TimeOutCount += 1
  1423.             If $TimeOutCount = 3 Then
  1424.                ToLog("Teleport TimeOut - Leaving")
  1425.                $TimeOutCount = 0
  1426.                LeaveGame()
  1427.                Return "LeftGame"
  1428.             EndIf
  1429.                $TimeOutTimer = TimerInit()
  1430.                ToLog("Teleport TimeOut - Trying to teleport again")
  1431.                ToLog("Teleporting to town...")
  1432.                Sleep(50 + ($ComputerLag / 2))
  1433.                Send("{t}")
  1434.          EndIf
  1435.          If CheckForDeath() = "LeftGame" Then
  1436.             Return "LeftGame"
  1437.          EndIf
  1438.          Sleep(100)
  1439.          Switch CheckForDisconnect()
  1440.             Case "Network connection lost"
  1441.                Return "Network connection lost"
  1442.             Case "Relogged"
  1443.                Return "Relogged"
  1444.          EndSwitch
  1445.          Sleep(100)
  1446.       EndIf
  1447.    WEnd
  1448. EndFunc
  1449.  
  1450. Func AtSalvage()
  1451.    $TimeOutTimer = TimerInit()
  1452.  
  1453.    While 1
  1454.       $Array = StringSplit($ImageFiles[7][5], "|")
  1455.       $File = $Array[1]
  1456.       $Accuracy = $Array[2]
  1457.  
  1458.       $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $MerchStashSearchArea[0], $MerchStashSearchArea[1], $MerchStashSearchArea[2], $MerchStashSearchArea[3], $ISx, $ISy, $Accuracy)
  1459.       If $Target = 1 Then
  1460.          Return "AtSalvage"
  1461.       Else
  1462.          If Floor(TimerDiff($TimeOutTimer) / 1000) >= $ArtisanTimeOut Then
  1463.             ToLog("Salvage TimeOut - Leaving")
  1464.             LeaveGame()
  1465.             Return "LeftGame"
  1466.          EndIf
  1467.          If CheckForDeath() = "LeftGame" Then
  1468.             Return "LeftGame"
  1469.          EndIf
  1470.          Sleep(100)
  1471.          Switch CheckForDisconnect()
  1472.             Case "Network connection lost"
  1473.                     Return "Network connection lost"
  1474.             Case "Relogged"
  1475.                     Return "Relogged"
  1476.          EndSwitch
  1477.          Sleep(100)
  1478.       EndIf
  1479.    WEnd
  1480. EndFunc
  1481.  
  1482. Func AtMerchant()
  1483.    $TimeOutTimer = TimerInit()
  1484.  
  1485.    While 1
  1486.       $Array = StringSplit($ImageFiles[7][5], "|")
  1487.       $File = $Array[1]
  1488.       $Accuracy = $Array[2]
  1489.  
  1490.       $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $MerchStashSearchArea[0], $MerchStashSearchArea[1], $MerchStashSearchArea[2], $MerchStashSearchArea[3], $ISx, $ISy, $Accuracy)
  1491.       If $Target = 1 Then
  1492.          Return "AtMerchant"
  1493.       Else
  1494.          If Floor(TimerDiff($TimeOutTimer) / 1000) >= $MerchantTimeOut Then
  1495.             ToLog("Merchant TimeOut - Leaving")
  1496.             LeaveGame()
  1497.             Return "LeftGame"
  1498.          EndIf
  1499.          If CheckForDeath() = "LeftGame" Then
  1500.             Return "LeftGame"
  1501.          EndIf
  1502.          Sleep(100)
  1503.          Switch CheckForDisconnect()
  1504.             Case "Network connection lost"
  1505.                Return "Network connection lost"
  1506.             Case "Relogged"
  1507.                Return "Relogged"
  1508.          EndSwitch
  1509.          Sleep(100)
  1510.       EndIf
  1511.    WEnd
  1512. EndFunc
  1513.  
  1514. Func AtStash()
  1515.    $TimeOutTimer = TimerInit()
  1516.  
  1517.    While 1
  1518.       $Array = StringSplit($ImageFiles[7][6], "|")
  1519.       $File = $Array[1]
  1520.       $Accuracy = $Array[2]
  1521.  
  1522.       $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $MerchStashSearchArea[0], $MerchStashSearchArea[1], $MerchStashSearchArea[2], $MerchStashSearchArea[3], $ISx, $ISy, $Accuracy)
  1523.       If $Target = 1 Then
  1524.          Return "AtStash"
  1525.       Else
  1526.          If Floor(TimerDiff($TimeOutTimer) / 1000) >= $StashTimeOut Then
  1527.             ToLog("Stash TimeOut - Leaving")
  1528.             LeaveGame()
  1529.             Return "LeftGame"
  1530.          EndIf
  1531.          If CheckForDeath() = "LeftGame" Then
  1532.             Return "LeftGame"
  1533.          EndIf
  1534.          Sleep(100)
  1535.          Switch CheckForDisconnect()
  1536.             Case "Network connection lost"
  1537.                Return "Network connection lost"
  1538.             Case "Relogged"
  1539.                Return "Relogged"
  1540.          EndSwitch
  1541.          Sleep(100)
  1542.       EndIf
  1543.    WEnd
  1544. EndFunc
  1545.  
  1546. Func CheckForDisconnect()
  1547.    $Array = StringSplit($ImageFiles[6][0], "|")
  1548.    $File = $Array[1]
  1549.    $Accuracy = $Array[2]
  1550.  
  1551.    $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $DisconnectSearchArea[0], $DisconnectSearchArea[1], $DisconnectSearchArea[2], $DisconnectSearchArea[3], $ISx, $ISy, $Accuracy)
  1552.    If $Target = 1 And $DisconnectState = 0 Then
  1553.       ToLog("We got disconnected")
  1554.       $Disconnects += 1
  1555.       RefreshStats()
  1556.       $DisconnectState = 1
  1557.        
  1558.       MouseClick("LEFT", $DisconnectButton[0], $DisconnectButton[1], 1, 2)
  1559.       Return "Network connection lost"
  1560.    EndIf
  1561.  
  1562.    $Array = StringSplit($ImageFiles[6][1], "|")
  1563.    $File = $Array[1]
  1564.    $Accuracy = $Array[2]
  1565.  
  1566.    $Target = _ImageSearchArea($ReqFiles & "\pics\" & $File, 1, $DisconnectSearchArea[0], $DisconnectSearchArea[1], $DisconnectSearchArea[2], $DisconnectSearchArea[3], $ISx, $ISy, 10)
  1567.    If $Target = 1 Then
  1568.       ToLog("We got totally disconnected")
  1569.       If $DisconnectState = 0 Then
  1570.          $Disconnects += 1
  1571.          RefreshStats()
  1572.       EndIf
  1573.       $DisconnectState = 2
  1574.        
  1575.       MouseClick("LEFT", $DisconnectButton[0], $DisconnectButton[1], 1, 2)
  1576.       InLoginScreen()
  1577.        
  1578.       If $UseRelogging = True Then
  1579.          Relog()
  1580.          Return "Relogged"
  1581.       Else
  1582.          Terminate()
  1583.       EndIf
  1584.    EndIf
  1585.    Return "Connected"
  1586. EndFunc
  1587.  
  1588. Func CheckForDeath()
  1589.    If $Alive = True Then
  1590.       $Death = PixelSearch($DeathSearchArea[0], $DeathSearchArea[1], $DeathSearchArea[2], $DeathSearchArea[3], 0xFFFFFF)
  1591.       If Not @error Then
  1592.          $Alive = False
  1593.          ToLog("We are dead... :(")
  1594.          $Deaths += 1
  1595.          RefreshStats()
  1596.          LeaveGame()
  1597.          Return "LeftGame"
  1598.       EndIf
  1599.    EndIf
  1600.    Return "Alive"
  1601. EndFunc
  1602.  
  1603.  
  1604. ;Miscellaneous
  1605. Func Initialize()
  1606.    OnAutoItExitRegister('OnAutoItExit')
  1607.    Opt('MouseCoordMode', 2)
  1608.    Opt('PixelCoordMode', 2)
  1609.  
  1610.    HotKeySet('{PAUSE}', 'Pause')
  1611.    HotKeySet('{INS}', 'HideLog')
  1612.    HotKeySet('{END}', 'Terminate')
  1613.  
  1614.    Global $LootAreaGUI
  1615.    Global $LogGUI
  1616.    Global $ImageFiles[8][7]
  1617.    Global $SoundFiles[6]
  1618.    Global $PasswordField[2]
  1619.    Global $ResumeButton[2]
  1620.    Global $LeaveButton[2]
  1621.    Global $DisconnectButton[2]
  1622.    Global $SalvageButton[2]
  1623.    Global $MoveToCellar1[2]
  1624.    Global $MoveToCellar2[2]
  1625.    Global $MoveToCellar3[2]
  1626.    Global $MoveInCellar1[2]
  1627.    Global $MoveInCellar2[2]
  1628.    Global $MoveToGoldLoot1a[2]
  1629.    Global $MoveToGoldLoot1b[2]
  1630.    Global $MoveToGoldLoot2[2]
  1631.    Global $MoveToGoldLoot3[2]
  1632.    Global $MoveToSalvage1[2]
  1633.    Global $MoveToSalvage2[2]
  1634.    Global $MoveToMerchant[2]
  1635.    Global $MoveToStash1[2]
  1636.    Global $MoveToStash2[2]
  1637.    Global $CellarLocation[2]
  1638.    Global $MonsterLocation[2]
  1639.    Global $SalvageLocation[2]
  1640.    Global $MerchantLocation[2]
  1641.    Global $StashLocation[2]
  1642.    Global $PortalLocation[2]
  1643.    Global $CharHitBox[4]
  1644.    Global $LoginButtonSearchArea[4]
  1645.    Global $ResumeButtonSearchArea[4]
  1646.    Global $PortalIconSearchArea[4]
  1647.    Global $CellarSearchArea[4]
  1648.    Global $CellarNameSearchArea[4]
  1649.    Global $TownNameSearchArea[4]
  1650.    Global $MerchStashSearchArea[4]
  1651.    Global $MonsterSearchArea[4]
  1652.    Global $LootingArea[4]
  1653.    Global $FullBagSearchArea[4]
  1654.    Global $SellItemsArea[4]
  1655.    Global $FullStashSearchArea[4]
  1656.    Global $RepairSearchArea[4]
  1657.    Global $DeathSearchArea[4]
  1658.    Global $DisconnectSearchArea[4]
  1659.    Global $StashBag2[2]
  1660.    Global $StashBag3[2]
  1661.    Global $RepairButton[2]
  1662.    Global $AllItemsButton[2]
  1663.    Global $CellarPixel
  1664.    Global $Log
  1665.    Global $StatsLabel
  1666.    Global $StartGoldLabel
  1667.    Global $CurrentGoldLabel
  1668.    Global $DifferenceGoldLabel
  1669.    Global $GPHLabel
  1670.    Global $LogList
  1671.    Global $RuntimeTimer
  1672.    Global $TimeOutTimer
  1673.    Global $RunTimer
  1674.    Global $Paused
  1675.    Global $Show
  1676.    Global $LegendaryLootAttempts = 0
  1677.    Global $SetLootAttempts = 0
  1678.    Global $RareLootAttempts = 0
  1679.    Global $MagicLootAttempts = 0
  1680.    Global $TomeLootAttempts = 0
  1681.    Global $GemLootAttempts = 0
  1682.    Global $StartTime = @HOUR & ":" & @MIN
  1683.    Global $Runs = 0
  1684.    Global $Closed = 0
  1685.    Global $Runtime = "0h 0m 0s"
  1686.    Global $Disconnects = 0
  1687.    Global $Deaths = 0
  1688.    Global $ISx = 0
  1689.    Global $ISy = 0
  1690.    Global $StashBag = 1
  1691.    Global $Alive = True
  1692.    Global $DisconnectState = 0
  1693.    Global $FullBag = False
  1694.    Global $TimeOutCount = 0
  1695.    Global $Relogged = False
  1696.    Global $SellCheck
  1697.    Global $SleepToSalvage
  1698.    Global $SleepToStash
  1699.    Global $StartGold = 0
  1700.    Global $CurrentGold = 0
  1701.    Global $LastGold = 0
  1702.    Global $GoldDifference = 0
  1703.    Global $LastDifferenceGoldLabel = 0
  1704.    Global $GPH = 0
  1705.  
  1706.    $ImageFiles[0][0] = "legendaryA.png|66"
  1707.    $ImageFiles[0][1] = "legendaryE.png|66"
  1708.    $ImageFiles[0][2] = "legendaryI.png|66"
  1709.    $ImageFiles[0][3] = "legendaryO.png|66"
  1710.    $ImageFiles[0][4] = "legendaryU.png|66"
  1711.  
  1712.    $ImageFiles[1][0] = "setA.png|90"
  1713.    $ImageFiles[1][1] = "setE.png|90"
  1714.    $ImageFiles[1][2] = "setU.png|90"
  1715.    $ImageFiles[1][3] = "setO.png|90"
  1716.    $ImageFiles[1][4] = "setI.png|90"
  1717.  
  1718.    $ImageFiles[2][0] = "rareA.png|104"
  1719.    $ImageFiles[2][1] = "rareE.png|104"
  1720.    $ImageFiles[2][2] = "rareI.png|104"
  1721.    $ImageFiles[2][3] = "rareO.png|104"
  1722.    $ImageFiles[2][4] = "rareU.png|104"
  1723.  
  1724.    $ImageFiles[3][0] = "blueA.png|70"
  1725.    $ImageFiles[3][1] = "blueE.png|70"
  1726.    $ImageFiles[3][2] = "blueI.png|70"
  1727.    $ImageFiles[3][3] = "blueO.png|70"
  1728.    $ImageFiles[3][4] = "blueU.png|70"
  1729.  
  1730.    $ImageFiles[4][0] = "tome.png|140"
  1731.    $ImageFiles[4][1] = "iLVL60.png|30"
  1732.    $ImageFiles[4][2] = "iLVL61.png|30"
  1733.    $ImageFiles[4][3] = "iLVL62.png|30"
  1734.    $ImageFiles[4][4] = "iLVL63.png|30"
  1735.    $ImageFiles[4][5] = "square.png|110"
  1736.    $ImageFiles[4][6] = "flawless.png|110"
  1737.  
  1738.    $ImageFiles[5][0] = "empty.png|75"
  1739.    $ImageFiles[5][1] = "corner.png|20"
  1740.    $ImageFiles[5][2] = "sellblueA.png|65"
  1741.    $ImageFiles[5][3] = "sellblueE.png|65"
  1742.    $ImageFiles[5][4] = "sellblueI.png|65"
  1743.    $ImageFiles[5][5] = "sellblueO.png|65"
  1744.    $ImageFiles[5][6] = "sellblueU.png|65"
  1745.    
  1746.    $ImageFiles[6][0] = "network.png|10"
  1747.    $ImageFiles[6][1] = "lost.png|10"
  1748.    $ImageFiles[6][2] = "bg.jpg|5"
  1749.    $ImageFiles[6][3] = "not.png|120"
  1750.    $ImageFiles[6][4] = "you.png|100"
  1751.    
  1752.    $ImageFiles[7][0] = "dank.png|120"
  1753.    $ImageFiles[7][1] = "new.png|120"
  1754.    $ImageFiles[7][2] = "game.png|20"
  1755.    $ImageFiles[7][3] = "portal.png|120"
  1756.    $ImageFiles[7][4] = "login.png|10"
  1757.    $ImageFiles[7][5] = "merchant.png|20"
  1758.    $ImageFiles[7][6] = "stash.png|20"
  1759.  
  1760.    $SoundFiles[0] = "legendary.wav"
  1761.    $SoundFiles[1] = "set.wav"
  1762.    $SoundFiles[2] = "rare.wav"
  1763.    $SoundFiles[3] = "magic.wav"
  1764.    $SoundFiles[4] = "tome.wav"
  1765.    $SoundFiles[5] = "gem.wav"
  1766.    
  1767.    $CharHitBox[0] = 790
  1768.    $CharHitBox[1] = 315
  1769.    $CharHitBox[2] = 1200
  1770.    $CharHitBox[3] = 730
  1771.  
  1772.    $LoginButtonSearchArea[0] = 930
  1773.    $LoginButtonSearchArea[1] = 845
  1774.    $LoginButtonSearchArea[2] = 985
  1775.    $LoginButtonSearchArea[3] = 860
  1776.  
  1777.    $ResumeButtonSearchArea[0] = 250
  1778.    $ResumeButtonSearchArea[1] = 410
  1779.    $ResumeButtonSearchArea[2] = 310
  1780.    $ResumeButtonSearchArea[3] = 425
  1781.  
  1782.    $PortalIconSearchArea[0] = 1095
  1783.    $PortalIconSearchArea[1] = 1000
  1784.    $PortalIconSearchArea[2] = 1140
  1785.    $PortalIconSearchArea[3] = 1060
  1786.  
  1787.    $CellarSearchArea[0] = 164
  1788.    $CellarSearchArea[1] = 0
  1789.    $CellarSearchArea[2] = 375
  1790.    $CellarSearchArea[3] = 110
  1791.  
  1792.    $CellarNameSearchArea[0] = 1760
  1793.    $CellarNameSearchArea[1] = 10
  1794.    $CellarNameSearchArea[2] = 1820
  1795.    $CellarNameSearchArea[3] = 30
  1796.  
  1797.    $TownNameSearchArea[0] = 1745
  1798.    $TownNameSearchArea[1] = 10
  1799.    $TownNameSearchArea[2] = 1795
  1800.    $TownNameSearchArea[3] = 30
  1801.  
  1802.    $MerchStashSearchArea[0] = 225
  1803.    $MerchStashSearchArea[1] = 30
  1804.    $MerchStashSearchArea[2] = 300
  1805.    $MerchStashSearchArea[3] = 115
  1806.  
  1807.    $MonsterSearchArea[0] = 170
  1808.    $MonsterSearchArea[1] = 75
  1809.    $MonsterSearchArea[2] = 1270
  1810.    $MonsterSearchArea[3] = 470
  1811.  
  1812.    $FullBagSearchArea[0] = 795
  1813.    $FullBagSearchArea[1] = 125
  1814.    $FullBagSearchArea[2] = 830
  1815.    $FullBagSearchArea[3] = 160
  1816.  
  1817.    $SellItemsArea[0] = 960
  1818.    $SellItemsArea[1] = 510
  1819.    $SellItemsArea[2] = 1680
  1820.    $SellItemsArea[3] = 910
  1821.    
  1822.    $FullStashSearchArea[0] = 700
  1823.    $FullStashSearchArea[1] = 135
  1824.    $FullStashSearchArea[2] = 730
  1825.    $FullStashSearchArea[3] = 155
  1826.  
  1827.    $RepairSearchArea[0] = 1507
  1828.    $RepairSearchArea[1] = 36
  1829.    $RepairSearchArea[2] = 1512
  1830.    $RepairSearchArea[3] = 41
  1831.  
  1832.    $DeathSearchArea[0] = 538
  1833.    $DeathSearchArea[1] = 335
  1834.    $DeathSearchArea[2] = 542
  1835.    $DeathSearchArea[3] = 339
  1836.  
  1837.    $DisconnectSearchArea[0] = 840
  1838.    $DisconnectSearchArea[1] = 410
  1839.    $DisconnectSearchArea[2] = 950
  1840.    $DisconnectSearchArea[3] = 440
  1841. EndFunc
  1842.  
  1843. Func Randomize()
  1844.    $MoveToCellar1[0] = Random(498, 503, 1)
  1845.    $MoveToCellar1[1] = Random(248, 253, 1)
  1846.    $MoveToCellar2[0] = Random(1, 4, 1)
  1847.    $MoveToCellar2[1] = Random(368, 373, 1)
  1848.    $MoveToCellar3[0] = Random(398, 403, 1)
  1849.    $MoveToCellar3[1] = Random(598, 603, 1)
  1850.  
  1851.    $MoveInCellar1[0] = Random(114, 119, 1)
  1852.    $MoveInCellar1[1] = Random(984, 989, 1)
  1853.    $MoveInCellar2[0] = Random(774, 779, 1)
  1854.    $MoveInCellar2[1] = Random(326, 331, 1)
  1855.    
  1856.    $MoveToGoldLoot1a[0] = Random(400, 405, 1)
  1857.    $MoveToGoldLoot1a[1] = Random(304, 309, 1)
  1858.    $MoveToGoldLoot1b[0] = Random(560, 575, 1)
  1859.    $MoveToGoldLoot1b[1] = Random(300, 305, 1)
  1860.    $MoveToGoldLoot2[0] = Random(1258, 1263, 1)
  1861.    $MoveToGoldLoot2[1] = Random(349, 354, 1)
  1862.    $MoveToGoldLoot3[0] = Random(909, 914, 1)
  1863.    $MoveToGoldLoot3[1] = Random(692, 697, 1)
  1864.  
  1865.    $MoveToMerchant[0] = Random(1688, 1693, 1)
  1866.    $MoveToMerchant[1] = Random(100, 105, 1)
  1867.    $MerchantLocation[0] = Random(928, 933, 1)
  1868.    $MerchantLocation[1] = Random(134, 139, 1)
  1869.  
  1870.    If $Salvage = False Then
  1871.       If $Sell = True Then
  1872.          $MoveToStash1[0] = Random(778, 783, 1)
  1873.          $MoveToStash1[1] = Random(948, 953, 1)
  1874.          $MoveToStash2[0] = Random(268, 273, 1)
  1875.          $MoveToStash2[1] = Random(928, 933, 1)
  1876.          $StashLocation[0] = Random(803, 808, 1)
  1877.          $StashLocation[1] = Random(428, 433, 1)
  1878.          $PortalLocation[0] = Random(648, 653, 1)
  1879.          $PortalLocation[1] = Random(498, 503, 1)
  1880.          $SleepToStash = 1675
  1881.       Else
  1882.          $StashLocation[0] = Random(1047, 1052, 1)
  1883.          $StashLocation[1] = Random(257, 262, 1)
  1884.          $PortalLocation[0] = Random(877, 882, 1)
  1885.          $PortalLocation[1] = Random(427, 432, 1)
  1886.       EndIf
  1887.    Else
  1888.       If $Sell = False Then
  1889.          $MoveToSalvage1[0] = Random(1397, 1402, 1)
  1890.          $MoveToSalvage1[1] = Random(497, 502, 1)
  1891.          $MoveToSalvage2[0] = Random(1497, 1502, 1)
  1892.          $MoveToSalvage2[1] = Random(497, 502, 1)
  1893.          $SalvageLocation[0] = Random(1280, 1285, 1)
  1894.          $SalvageLocation[1] = Random(397, 402, 1)
  1895.          $MoveToStash1[0] = Random(397, 402, 1)
  1896.          $MoveToStash1[1] = Random(482, 487, 1)
  1897.          $MoveToStash2[0] = Random(597, 602, 1)
  1898.          $MoveToStash2[1] = Random(447, 452, 1)
  1899.          $StashLocation[0] = Random(852, 857, 1)
  1900.          $StashLocation[1] = Random(347, 352, 1)
  1901.          $PortalLocation[0] = Random(782, 787, 1)
  1902.          $PortalLocation[1] = Random(427, 432, 1)
  1903.          $SleepToSalvage = 1250
  1904.          $SleepToStash = 1325
  1905.       Else
  1906.          $MoveToSalvage1[0] = Random(802, 807, 1)
  1907.          $MoveToSalvage1[1] = Random(957, 962, 1)
  1908.          $MoveToSalvage2[0] = Random(927, 932, 1)
  1909.          $MoveToSalvage2[1] = Random(942, 947, 1)
  1910.          $SalvageLocation[0] = Random(1557, 1562, 1)
  1911.          $SalvageLocation[1] = Random(587, 592, 1)
  1912.          $MoveToStash1[0] = Random(397, 402, 1)
  1913.          $MoveToStash1[1] = Random(482, 487, 1)
  1914.          $MoveToStash2[0] = Random(597, 602, 1)
  1915.          $MoveToStash2[1] = Random(447, 452, 1)
  1916.          $StashLocation[0] = Random(850, 855, 1)
  1917.          $StashLocation[1] = Random(382, 387, 1)
  1918.          $PortalLocation[0] = Random(747, 752, 1)
  1919.          $PortalLocation[1] = Random(447, 452, 1)
  1920.          $SleepToSalvage = 1550
  1921.          $SleepToStash = 1550
  1922.       EndIf
  1923.    EndIf
  1924.  
  1925.    $CellarLocation[0] = Random(305, 309, 1)
  1926.    $CellarLocation[1] = Random(72, 76, 1)
  1927.  
  1928.    $MonsterLocation[0] = Random(575, 580, 1)
  1929.    $MonsterLocation[1] = Random(181, 186, 1)
  1930.  
  1931.    $StashBag2[0] = Random(508, 513, 1)
  1932.    $StashBag2[1] = Random(358, 363, 1)
  1933.  
  1934.    $StashBag3[0] = Random(508, 513, 1)
  1935.    $StashBag3[1] = Random(488, 493, 1)
  1936.  
  1937.    $RepairButton[0] = Random(515, 520, 1)
  1938.    $RepairButton[1] = Random(481, 486, 1)
  1939.  
  1940.    $AllItemsButton[0] = Random(221, 226, 1)
  1941.    $AllItemsButton[1] = Random(590, 595, 1)
  1942.  
  1943.    $PasswordField[0] = Random(818, 823, 1)
  1944.    $PasswordField[1] = Random(703, 708, 1)
  1945.  
  1946.    $ResumeButton[0] = Random(317, 322, 1)
  1947.    $ResumeButton[1] = Random(414, 419, 1)
  1948.  
  1949.    $LeaveButton[0] = Random(967, 972, 1)
  1950.    $LeaveButton[1] = Random(580, 584, 1)
  1951.  
  1952.    $DisconnectButton[0] = Random(958, 963, 1)
  1953.    $DisconnectButton[1] = Random(628, 633, 1)
  1954.  
  1955.    $SalvageButton[0] = Random(262, 267, 1)
  1956.    $SalvageButton[1] = Random(292, 297, 1)
  1957. EndFunc
  1958.  
  1959. Func ScriptStarted()
  1960.    CheckRequiredFiles()
  1961.  
  1962.    If $LootLegendaries Then
  1963.       Global $Legendaries = 0
  1964.    Else
  1965.       Global $Legendaries = "-"
  1966.    EndIf
  1967.  
  1968.    If $LootSets Then
  1969.       Global $Sets = 0
  1970.    Else
  1971.       Global $Sets = "-"
  1972.    EndIf
  1973.  
  1974.    If $LootRares Then
  1975.       Global $Rares = 0
  1976.    Else
  1977.       Global $Rares = "-"
  1978.    EndIf
  1979.  
  1980.    If $LootMagics Then
  1981.       Global $Magics = 0
  1982.       Global $Tomes = "-"
  1983.    Else
  1984.       Global $Magics = "-"
  1985.       If $LootTomes Then
  1986.          Global $Tomes = "0"
  1987.       Else
  1988.          Global $Tomes = "-"
  1989.       EndIf
  1990.    EndIf
  1991.  
  1992.    If $LootGems Then
  1993.       Global $Gems = 0
  1994.    Else
  1995.       Global $Gems = "-"
  1996.    EndIf
  1997.  
  1998.    If $Sell Then
  1999.       Global $Sold = 0
  2000.    Else
  2001.       Global $Sold = "-"
  2002.    EndIf
  2003.  
  2004.    If $Salvage Then
  2005.       Global $Salvaged = 0
  2006.    Else
  2007.       Global $Salvaged = "-"
  2008.    EndIf
  2009.  
  2010.    Pause()
  2011.  
  2012.    $RuntimeTimer = TimerInit()
  2013.  
  2014.    If $ShowLog = True Then
  2015.       DrawLog()
  2016.    EndIf
  2017.  
  2018.    If $ShowLog = True Or $SaveStats = True Then
  2019.       DirGetSize($SaveLogsPath)
  2020.       If @error = 1 Then
  2021.          DirCreate($SaveLogsPath)
  2022.       EndIf
  2023.    EndIf
  2024.  
  2025.    ToLog("Bot started")
  2026.  
  2027.    WinActivate('Diablo III')
  2028. EndFunc
  2029.  
  2030. Func CheckRequiredFiles()
  2031.    If (@OSArch = "X64" Or @OSArch = "IA64") And Not @AutoItX64 Then
  2032.       MsgBox(4096, "Error", "You are running a 64bit system. You need to start the script" & @LF & "with 'Run Script (x64)' or 'Compile Script (x64)'" & @LF & "Exiting...")
  2033.       Exit 0
  2034.    EndIf
  2035.  
  2036.    Local $Files[4]
  2037.    $Files[0] = "msvcr110.dll"
  2038.    $Files[1] = "msvcr110d.dll"
  2039.  
  2040.    If @AutoItX64 Then
  2041.       $Files[2] = "ImageSearchDLL_x64.dll"
  2042.    Else
  2043.       $Files[2] = "ImageSearchDLL.dll"
  2044.    EndIf
  2045.      
  2046.    $Files[3] = "tesseract.exe"
  2047.  
  2048.    For $i = 0 To 2
  2049.       If Not FileExists(@WindowsDir & "\System32\" & $Files[$i]) Then
  2050.          If Not FileExists($Files[$i]) Then
  2051.             MsgBox(4096, "Error", "Couldn't find '" & $Files[$i] & "'." & @LF & "Make sure you have put that file into '" & @WindowsDir & "\System32\' or into the script folder." & @LF & "Exiting...")
  2052.             Exit 0
  2053.          EndIf
  2054.       EndIf
  2055.    Next
  2056.  
  2057.    If Not FileExists($ReqFiles & "tesseract\" & $Files[3]) Then
  2058.       MsgBox(4096, "Error", "Couldn't find '" & $Files[3] & "'." & @LF & "Make sure you are using the latest required files." & @LF & "Exiting...")
  2059.       Exit 0
  2060.    EndIf
  2061.  
  2062.    For $i = 0 To UBound($ImageFiles, 1) - 1
  2063.       For $x = 0 To UBound($ImageFiles, 2) - 1
  2064.          If Not $ImageFiles[$i][$x] = "" Then
  2065.             $Array = StringSplit($ImageFiles[$i][$x], "|")
  2066.             $File = $Array[1]
  2067.             If Not FileExists($ReqFiles & "pics\" & $File) Then
  2068.                MsgBox(4096, "Error", "Couldn't find '" & $File & "'." & @LF & "Either you have set the path to the required files folder wrong or you aren't using latest required files." & @LF & "Exiting...")
  2069.                Exit 0
  2070.             EndIf
  2071.          EndIf
  2072.       Next
  2073.    Next
  2074. EndFunc
  2075.  
  2076. Func Pause()
  2077.    $Paused = Not $Paused
  2078.    If $Paused Then ToLog("Paused...")
  2079.    
  2080.    While $Paused
  2081.       Sleep(250)
  2082.       ToolTip('Paused... Press {PAUSE} to continue...', 850, 0)
  2083.    WEnd
  2084.  
  2085.    ToolTip('Running... Press {PAUSE} to pause...', 850, 0)
  2086. EndFunc
  2087.  
  2088. Func RandomizeInventory()
  2089.    Global $Stash[60][2]
  2090.    $c = 0
  2091.    $d = -2
  2092.    For $a = 0 To 59
  2093.       $d += 1
  2094.       If $a = 10 Or $a = 20 Or $a = 30 Or $a = 40 Or $a = 50 Then
  2095.          $c += 1
  2096.          $d = -1
  2097.       EndIf
  2098.       For $b = 0 To 1
  2099.          If $a = 0 Then
  2100.             If $b = 0 Then
  2101.                $Stash[$a][$b] = 1430
  2102.             Else
  2103.                $Stash[$a][$b] = 560
  2104.             EndIf
  2105.          Else
  2106.             If $b = 0 Then
  2107.                $Stash[$a][$b] = Random(1473, 1483, 1) + (49 * $d)
  2108.             Else
  2109.                $Stash[$a][$b] = Random(606, 614, 1) + (49 * $c)
  2110.             EndIf
  2111.          EndIf
  2112.       Next
  2113.    Next
  2114. EndFunc
  2115.  
  2116. Func DrawLootArea()
  2117.    $LootingAreaWidth = $LootingArea[2] - $LootingArea[0]
  2118.    $LootingAreaHeight = $LootingArea[3] - $LootingArea[1]
  2119.    $LootAreaGUI = GUICreate("", $LootingAreaWidth + 2, $LootingAreaHeight + 2, $LootingArea[0], $LootingArea[1], $WS_POPUP, BitOR($WS_EX_LAYERED, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TRANSPARENT)))
  2120.    GUISetBkColor(0xABCDEF)
  2121.    _WinAPI_SetLayeredWindowAttributes($LootAreaGUI, 0xABCDEF, 0xA0)
  2122.    WinSetOnTop($LootAreaGUI, "", 1)
  2123.    GUISetState(@SW_SHOWNOACTIVATE, $LootAreaGUI)
  2124.    $hDC = _WinAPI_GetWindowDC($LootAreaGUI)
  2125.    $hPen = _WinAPI_CreatePen($PS_SOLID, 2, 0x0000FF)
  2126.    $obj_orig = _WinAPI_SelectObject($hDC, $hPen)
  2127.    $user32_dll = DllOpen("user32.dll")
  2128.    _WinAPI_DrawLine($hDC, 0, 1, $LootingAreaWidth, 0)
  2129.    _WinAPI_DrawLine($hDC, 1, 0, 0, $LootingAreaHeight)
  2130.    _WinAPI_DrawLine($hDC, $LootingAreaWidth, $LootingAreaHeight, $LootingAreaWidth, 0)
  2131.    _WinAPI_DrawLine($hDC, $LootingAreaWidth, $LootingAreaHeight, 0, $LootingAreaHeight)
  2132.  
  2133.    _WinAPI_SetTextColor($hDC, 0x0000FF)
  2134.    _WinAPI_SetBkMode($hDC, $TRANSPARENT)
  2135.  
  2136.    $tRECT = DllStructCreate($tagRect)
  2137.    DllStructSetData($tRECT, "Left", 5)
  2138.    DllStructSetData($tRECT, "Top", 5)
  2139.    DllStructSetData($tRECT, "Right", 250)
  2140.    DllStructSetData($tRECT, "Bottom", 50)
  2141.  
  2142.    _WinAPI_DrawText($hDC, "Loot Area", $tRECT, 0)
  2143. EndFunc
  2144.  
  2145. Func DrawLog()
  2146.    $Width = 475
  2147.    $Height = 225
  2148.    $LogGUI = GUICreate("", $Width, $Height, 900 - $Width, 1080 - $Height - 2, $WS_POPUPWINDOW, BitOR($WS_EX_LAYERED, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TRANSPARENT)))
  2149.    GUISetBkColor(0x424242)
  2150.    GUICtrlCreatePic($ReqFiles & "\pics\" & StringTrimRight($ImageFiles[6][2], 2), 0, 0, 0, 0)
  2151.    _WinAPI_SetLayeredWindowAttributes($LogGUI, 0xEEEEEF, 0xEE)
  2152.    WinSetOnTop($LogGUI, "", 1)
  2153.    GUISetState(@SW_SHOWNOACTIVATE, $LogGUI)
  2154.  
  2155.    $StatsLabel = GUICtrlCreateLabel("", 0, 10, $Width, 45, $SS_CENTER)
  2156.    GUICtrlSetFont($StatsLabel, 8, 500, 0, "")
  2157.    GUICtrlSetColor($StatsLabel, 0xFFFFFF)
  2158.    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
  2159.    
  2160.    $CurrentGoldLabel = GUICtrlCreateLabel("", 0, $Height - 23, 88, 15, $SS_RIGHT)
  2161.    GUICtrlSetFont($CurrentGoldLabel, 9, 2000, 0, "Arial")
  2162.    GUICtrlSetColor($CurrentGoldLabel, 0xFFFFFF)
  2163.    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
  2164.    GUICtrlSetData($CurrentGoldLabel, "Current Gold")
  2165.    
  2166.    $DifferenceGoldLabel = GUICtrlCreateLabel("", 115, $Height - 23, 88, 15, $SS_RIGHT)
  2167.    GUICtrlSetFont($DifferenceGoldLabel, 9, 2000, 0, "Arial")
  2168.    GUICtrlSetColor($DifferenceGoldLabel, 0xFFFFFF)
  2169.    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
  2170.    GUICtrlSetData($DifferenceGoldLabel, "Total gold gain")
  2171.    
  2172.    $LastDifferenceGoldLabel = GUICtrlCreateLabel("", 231, $Height - 23, 88, 15, $SS_RIGHT)
  2173.    GUICtrlSetFont($LastDifferenceGoldLabel, 9, 2000, 0, "Arial")
  2174.    GUICtrlSetColor($LastDifferenceGoldLabel, 0xFFFFFF)
  2175.    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
  2176.    GUICtrlSetData($LastDifferenceGoldLabel, "Last gold gain")
  2177.    
  2178.    $GPHLabel = GUICtrlCreateLabel("", 347, $Height - 23, 88, 15, $SS_RIGHT)
  2179.    GUICtrlSetFont($GPHLabel, 9, 2000, 0, "Arial")
  2180.    GUICtrlSetColor($GPHLabel, 0xFFFFFF)
  2181.    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
  2182.    GUICtrlSetData($GPHLabel, "Gold per hour")
  2183.        
  2184.    $Version = GUICtrlCreateLabel("", 5, 2, 100, 20, $SS_LEFT)
  2185.    GUICtrlSetFont($Version, 7, 500, 0, "")
  2186.    GUICtrlSetColor($Version, 0x000000)
  2187.    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
  2188.    GUICtrlSetData($Version, "v1.3d")
  2189.  
  2190.    $Copyright = GUICtrlCreateLabel("", $Width - 55, 2, 50, 20, $SS_RIGHT)
  2191.    GUICtrlSetFont($Copyright, 7, 500, 0, "")
  2192.    GUICtrlSetColor($Copyright, 0x000000)
  2193.    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
  2194.    GUICtrlSetData($Copyright, "©zEEneXx")
  2195.  
  2196.    $LogList = GUICtrlCreateList("", 5, 60, $Width - 10, $Height - 85, $LBS_NOSEL)
  2197.    GUICtrlSetColor($LogList, 0x000000)
  2198.    GUICtrlSetFont($LogList, 8)
  2199.    
  2200.    RefreshStats()
  2201. EndFunc
  2202.  
  2203. Func HideLog()
  2204.    If Not $Show Then
  2205.       GUISetState(@SW_HIDE, $LogGUI)
  2206.    Else
  2207.       GUISetState(@SW_SHOWNOACTIVATE, $LogGUI)
  2208.    EndIf
  2209.    $Show = Not $Show
  2210. EndFunc
  2211.  
  2212. Func GetGold()
  2213.    $Sek = Floor(TimerDiff($RuntimeTimer) / 1000)
  2214.    
  2215.    Send("{c}")
  2216.    Sleep(400 + ($ComputerLag/2))
  2217.    $CurrentGold = _TesseractScreenCapture(0, "", 1, 1, 6000, 905, 1435, 1000, 0)
  2218.    Sleep(100 + ($ComputerLag/2))
  2219.    $CurrentGold = StringReplace($CurrentGold,",","")
  2220.    $CurrentGold = StringReplace($CurrentGold,"'","")
  2221.    $CurrentGold = StringReplace($CurrentGold,"´","")
  2222.    $CurrentGold = StringReplace($CurrentGold,"`","")
  2223.    $CurrentGold = StringReplace($CurrentGold,"‘","")
  2224.    $CurrentGold = StringReplace($CurrentGold," ","")
  2225.    $CurrentGold = StringReplace($CurrentGold,"i","1")
  2226.    $CurrentGold = StringReplace($CurrentGold,"l","1")
  2227.    $CurrentGold = StringReplace($CurrentGold,"o","0")
  2228.    $CurrentGold = StringReplace($CurrentGold,"s","5")
  2229.    $CurrentGold = StringReplace($CurrentGold,@LF,"")
  2230.    Send("{c}")
  2231.    
  2232.    If $StartGold = 0 Then
  2233.       $StartGold = $CurrentGold
  2234.       $LastGold = $StartGold
  2235.       GUICtrlSetData($CurrentGoldLabel, _StringAddThousandsSep($CurrentGold))
  2236.    Else
  2237.       $GoldDifference = $CurrentGold - $StartGold
  2238.       $LastGoldDifference = $CurrentGold - $LastGold
  2239.       $LastGold = $CurrentGold
  2240.       $Sek = Floor(TimerDiff($RuntimeTimer) / 1000)
  2241.       $GPH = Floor(($CurrentGold - $StartGold) / ($Sek / 3600))
  2242.       GUICtrlSetData($CurrentGoldLabel, _StringAddThousandsSep($CurrentGold))
  2243.       GUICtrlSetData($DifferenceGoldLabel, _StringAddThousandsSep($GoldDifference))
  2244.       GUICtrlSetData($LastDifferenceGoldLabel, _StringAddThousandsSep($LastGoldDifference))
  2245.       GUICtrlSetData($GPHLabel, _StringAddThousandsSep($GPH))
  2246.    EndIf
  2247. EndFunc
  2248.  
  2249. Func RefreshStats()
  2250.    If $ShowLog = True Then
  2251.       GUICtrlSetData($StatsLabel, "Start: " & $StartTime & "  |  Runs: " & $Runs & "  |  Closed:  " & $Closed & "  |  Deaths: " & $Deaths & "  |  Disconnects: " & $Disconnects & @LF & @LF & "Sets: " & $Sets & "  |  Legendaries: " & $Legendaries & "  |  Rares: " & $Rares & "  |  Magics: " & $Magics & "  |  Tomes: " & $Tomes & "  |  Gems: " & $Gems & "  |  Sold: " & $Sold & "  |  Salvaged: " & $Salvaged)
  2252.    EndIf
  2253. EndFunc
  2254.  
  2255. Func ToLog($Text)
  2256.    If $ShowLog = True Then
  2257.       GUICtrlSetData($LogList, "<" & @HOUR & ":" & @MIN & ":" & @SEC & "> " & $Text)
  2258.       GUICtrlSendMsg($LogList, $WM_VSCROLL, $SB_LINEDOWN, 0)
  2259.  
  2260.       $Log = FileOpen($SaveLogsPath & "log.txt", 1)
  2261.       FileWriteLine($Log, "<" & @HOUR & ":" & @MIN & ":" & @SEC & "> " & $Text)
  2262.       If $Text = "Bot closed" Then
  2263.          FileWriteLine($Log, @LF)
  2264.       EndIf
  2265.       FileClose($Log)
  2266.    EndIf
  2267. EndFunc
  2268.  
  2269. Func Relog()
  2270.    ToLog("Relogging...")
  2271.    MouseClick("LEFT", $PasswordField[0], $PasswordField[1], 1, 2)
  2272.    Send($Password)
  2273.  
  2274.    Sleep(1000 + $ComputerLag)
  2275.    Send("{ENTER}")
  2276.  
  2277.    $Relogged = True
  2278.    $DisconnectState = 0
  2279. EndFunc
  2280.  
  2281. Func SaveStats()
  2282.    $File = FileOpen($SaveLogsPath & "statistics.txt", 1)
  2283.    FileWriteLine($File, "=========" & @HOUR & ":" & @MIN & ":" & @SEC & "=========")
  2284.    FileWriteLine($File, "Startime: " & @TAB & @TAB & $StartTime & @LF & "Runs: " & @TAB & @TAB & $Runs & @LF & "Closed: " & @TAB & @TAB & $Closed & @LF & "Deaths: " & @TAB & @TAB & $Deaths & @LF & "Disconnects: " & @TAB & $Disconnects & @LF & "Runtime: " & @TAB & @TAB & $Runtime & @LF & @LF & "Sets: " & @TAB & @TAB & $Sets & @LF & "Legendaries: " & @TAB & $Legendaries & @LF & "Rares: " & @TAB & @TAB & $Rares & @LF & "Magics: " & @TAB & @TAB & $Magics & @LF & "Tomes: " & @TAB & @TAB & $Tomes & @LF & "Gems: " & @TAB & @TAB & $Gems & @LF & "Sold: " & @TAB & @TAB & $Sold & @LF & "Salvaged: " & @TAB & @TAB & $Salvaged & @LF & @LF & "Startgold: " & @TAB & _StringAddThousandsSep($StartGold) & @LF & "Current gold: " & @TAB & _StringAddThousandsSep($CurrentGold) & @LF & "Gold gain: " & @TAB & _StringAddThousandsSep($GoldDifference) & @LF & "Gold per hour: " & @TAB & _StringAddThousandsSep($GPH))
  2285.    FileWriteLine($File, @LF)
  2286.    FileClose($File)
  2287. EndFunc
  2288.  
  2289. Func Move($x, $y)
  2290.    MouseClick('MIDDLE', $x, $y, 1, 2)
  2291. EndFunc
  2292.  
  2293. Func Attack($x, $y)
  2294.    Send("{SHIFTDOWN}")
  2295.    MouseClick('LEFT', $x, $y, 1, 2)
  2296.    Send("{SHIFTUP}")
  2297. EndFunc
  2298.  
  2299. Func AttackNearbyMonsters()
  2300.    $Logged = False
  2301.    While 1
  2302.       $MonsterData = PixelSearch($CharHitBox[0], $CharHitBox[1], $CharHitBox[2], $CharHitBox[3], 0xEE0000, 10)
  2303.       If @error Then
  2304.          ExitLoop
  2305.       EndIf
  2306.        
  2307.       If $Logged = False Then
  2308.          ToLog("Monster found...")
  2309.       EndIf
  2310.        
  2311.       Attack($MonsterData[0], $MonsterData[1])
  2312.       Sleep(100)
  2313.        
  2314.       $Logged = True
  2315.    WEnd
  2316. EndFunc
  2317.  
  2318. Func LeaveGame()
  2319.    $Sek = Floor(TimerDiff($RuntimeTimer) / 1000)
  2320.    $Min = Floor($Sek / 60)
  2321.    $Hour = Floor($Min / 60)
  2322.    $Runtime = $Hour & "h " & ($Min - $Hour * 60) & "m " & ($Sek - $Min * 60) & "s"
  2323.    If $SaveStats = True Then
  2324.       SaveStats()
  2325.    EndIf
  2326.    
  2327.    If $InstantLeave = True Then GetGold()
  2328.  
  2329.    ToLog("Leaving the game")
  2330.  
  2331.    Sleep(200 + ($ComputerLag / 2))
  2332.  
  2333.    Send("{ESC}")
  2334.    Sleep(100 + ($ComputerLag / 2))
  2335.  
  2336.    MouseClick('LEFT', $LeaveButton[0], $LeaveButton[1], 1, 2)
  2337.    Return "LeftGame"
  2338. EndFunc
  2339.  
  2340. Func Terminate()
  2341.    ToLog("Terminating... Good bye :)")
  2342.    Exit 0
  2343. EndFunc
  2344.  
  2345. Func _ImageSearchArea($FindImage, $ResultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $Tolerance)
  2346.    If $Tolerance > 0 Then $FindImage = "*" & $Tolerance & " " & $FindImage
  2347.    
  2348.    If @AutoItX64 Then
  2349.       $Result = DllCall("ImageSearchDLL_x64.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $FindImage)
  2350.    Else
  2351.       $Result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $FindImage)
  2352.    EndIf
  2353.    
  2354.    If $Result = "0" Then Return 0
  2355.    
  2356.    $Array = StringSplit($Result[0], "|")
  2357.  
  2358.    If (UBound($Array) >= 4) Then
  2359.       $x = Int(Number($Array[2]))
  2360.       $y = Int(Number($Array[3]))
  2361.        
  2362.       If $ResultPosition = 1 Then
  2363.          $x = $x + Int(Number($Array[4]) / 2)
  2364.          $y = $y + Int(Number($Array[5]) / 2)
  2365.       EndIf
  2366.       Return 1
  2367.    EndIf
  2368.  EndFunc
  2369.  
  2370. Func _TesseractScreenCapture($get_last_capture = 0, $delimiter = "", $cleanup = 1, $scale = 2, $left_indent = 0, $top_indent = 0, $right_indent = 0, $bottom_indent = 0, $show_capture = 0)
  2371.    Global $last_capture
  2372.    Global $tesseract_temp_path = "C:\"
  2373.    Local $tInfo
  2374.    Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO)
  2375.    Dim $aArray, $final_ocr[1], $xyPos_old = -1, $capture_scale = 3
  2376.    
  2377.    DllStructSetData($tSCROLLINFO, "cbSize", DllStructGetSize($tSCROLLINFO))
  2378.    DllStructSetData($tSCROLLINFO, "fMask", $SIF_ALL)
  2379.    
  2380.    If $last_capture = "" Then
  2381.       $last_capture = ObjCreate("Scripting.Dictionary")
  2382.    EndIf
  2383.  
  2384.    If $get_last_capture = 1 and $last_capture.item(0) <> "" Then
  2385.       Return $last_capture.item(0)
  2386.    EndIf
  2387.    
  2388.    $capture_filename = _TempFile($tesseract_temp_path, "~", ".tif")
  2389.    $ocr_filename = StringLeft($capture_filename, StringLen($capture_filename) - 4)
  2390.    $ocr_filename_and_ext = $ocr_filename & ".txt"
  2391.    
  2392.    CaptureToTIFF("", "", "", $capture_filename, $scale, $left_indent, $top_indent, $right_indent, $bottom_indent)
  2393.    ShellExecuteWait($ReqFiles & "\tesseract\tesseract.exe", $capture_filename & " " & $ocr_filename, "", "", @SW_HIDE)
  2394.    
  2395.    If StringCompare($delimiter, "") = 0 Then
  2396.       $final_ocr = FileRead($ocr_filename_and_ext)
  2397.    Else
  2398.       _FileReadToArray($ocr_filename_and_ext, $aArray)
  2399.       _ArrayDelete($aArray, 0)
  2400.       _ArrayConcatenate($final_ocr, $aArray)
  2401.    EndIf
  2402.    
  2403.    If $show_capture = 1 Then
  2404.       GUICreate("Tesseract Screen Capture.  Note: image displayed is not to scale", 640, 480, 0, 0, $WS_SIZEBOX + $WS_SYSMENU)
  2405.       GUISetBkColor(0xE0FFFF)
  2406.       $Obj1 = ObjCreate("Preview.Preview.1")  
  2407.       $Obj1_ctrl = GUICtrlCreateObj($Obj1, 0, 0, 640, 480)
  2408.       $Obj1.ShowFile ($capture_filename, 1)
  2409.       GUISetState()
  2410.       If IsArray($final_ocr) Then
  2411.          _ArrayDisplay($aArray, "Tesseract Text Capture")
  2412.       Else
  2413.          MsgBox(0, "Tesseract Text Capture", $final_ocr)
  2414.       EndIf
  2415.       GUIDelete()
  2416.    EndIf
  2417.    
  2418.    FileDelete($ocr_filename & ".*")
  2419.    
  2420.    If IsArray($final_ocr) And $cleanup = 1 Then
  2421.       For $final_ocr_num = 1 To (UBound($final_ocr)-1)
  2422.          $final_ocr[$final_ocr_num] = StringReplace($final_ocr[$final_ocr_num], ".", "")
  2423.          $final_ocr[$final_ocr_num] = StringReplace($final_ocr[$final_ocr_num], "'", "")
  2424.          $final_ocr[$final_ocr_num] = StringReplace($final_ocr[$final_ocr_num], ",", "")
  2425.          $final_ocr[$final_ocr_num] = StringStripWS($final_ocr[$final_ocr_num], 3)
  2426.       Next
  2427.      
  2428.       For $each in $final_ocr
  2429.          $found_item = _ArrayFindAll($final_ocr, $each)
  2430.          If IsArray($found_item) Then
  2431.             If StringCompare($final_ocr[$found_item[0]], "") = 0 Then
  2432.                _ArrayDelete($final_ocr, $found_item[0])
  2433.             EndIf
  2434.          EndIf
  2435.          For $found_item_num = 2 To UBound($found_item)
  2436.             _ArrayDelete($final_ocr, $found_item[$found_item_num-1])
  2437.          Next
  2438.       Next
  2439.    EndIf
  2440.    
  2441.    If $last_capture.item(0) = "" Then  
  2442.       $last_capture.item(0) = $final_ocr
  2443.    EndIf
  2444.    $tSCROLLINFO = 0
  2445.    Return $final_ocr
  2446. EndFunc
  2447.  
  2448. Func CaptureToTIFF($win_title = "", $win_text = "", $ctrl_id = "", $sOutImage = "", $scale = 1, $left_indent = 0, $top_indent = 0, $right_indent = 0, $bottom_indent = 0)
  2449.    Local $hWnd, $hwnd2, $hDC, $hBMP, $hImage1, $hGraphic, $CLSID, $tParams, $pParams, $tData, $i = 0, $hImage2, $pos[4]
  2450.    Local $Ext = StringUpper(StringMid($sOutImage, StringInStr($sOutImage, ".", 0, -1) + 1))
  2451.    Local $giTIFColorDepth = 24
  2452.    Local $giTIFCompression = $GDIP_EVTCOMPRESSIONNONE
  2453.    
  2454.    If StringCompare($ctrl_id, "") <> 0 Then
  2455.       $hwnd2 = ControlGetHandle($win_title, $win_text, $ctrl_id)
  2456.       $pos = ControlGetPos($win_title, $win_text, $ctrl_id)
  2457.    Else
  2458.       If StringCompare($win_title, "") <> 0 Then
  2459.          $hwnd2 = WinGetHandle($win_title, $win_text)
  2460.          $pos = WinGetPos($win_title, $win_text)
  2461.       Else 
  2462.          $hwnd2 = ""
  2463.          $pos[0] = 0
  2464.          $pos[1] = 0
  2465.          $pos[2] = @DesktopWidth
  2466.          $pos[3] = @DesktopHeight
  2467.       EndIf
  2468.    EndIf
  2469.    
  2470.    If IsHWnd($hwnd2) Then
  2471.       WinActivate($win_title, $win_text)
  2472.       $hBitmap2 = _ScreenCapture_CaptureWnd("", $hwnd2, 0, 0, -1, -1, False)
  2473.    Else
  2474.       $hBitmap2 = _ScreenCapture_Capture("", 0, 0, -1, -1, False)
  2475.    EndIf
  2476.    
  2477.    _GDIPlus_Startup ()
  2478.    $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap2)
  2479.    $hWnd = _WinAPI_GetDesktopWindow()
  2480.    $hDC = _WinAPI_GetDC($hWnd)
  2481.    $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, ($pos[2] * $scale) - ($right_indent * $scale), ($pos[3] * $scale) - ($bottom_indent * $scale))
  2482.    _WinAPI_ReleaseDC($hWnd, $hDC)
  2483.    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBMP)
  2484.    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)
  2485.    _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage2, 0 - ($left_indent * $scale), 0 - ($top_indent * $scale), ($pos[2] * $scale) + $left_indent, ($pos[3] * $scale) + $top_indent)
  2486.    $CLSID = _GDIPlus_EncodersGetCLSID($Ext)
  2487.    $tParams = _GDIPlus_ParamInit(2)
  2488.    $tData = DllStructCreate("int ColorDepth;int Compression")
  2489.    DllStructSetData($tData, "ColorDepth", $giTIFColorDepth)
  2490.    DllStructSetData($tData, "Compression", $giTIFCompression)
  2491.    _GDIPlus_ParamAdd($tParams, $GDIP_EPGCOLORDEPTH, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "ColorDepth"))
  2492.    _GDIPlus_ParamAdd($tParams, $GDIP_EPGCOMPRESSION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Compression"))
  2493.  
  2494.    If IsDllStruct($tParams) Then $pParams = DllStructGetPtr($tParams)
  2495.      
  2496.    _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID, $pParams)
  2497.    _GDIPlus_ImageDispose($hImage1)
  2498.    _GDIPlus_ImageDispose($hImage2)
  2499.    _GDIPlus_GraphicsDispose ($hGraphic)
  2500.    _WinAPI_DeleteObject($hBitmap2)
  2501.    _WinAPI_DeleteObject($hBMP)
  2502.    _GDIPlus_Shutdown()
  2503. EndFunc
  2504.  
  2505. Func _StringAddThousandsSep($number)
  2506.    $number = String($number)
  2507.    
  2508.    Switch StringLen($number)
  2509.       Case 1
  2510.          $number = $number
  2511.       Case 2
  2512.          $number = $number
  2513.       Case 3
  2514.          $number = $number
  2515.       Case 4
  2516.          $number = _StringInsert($number, ".", -3)
  2517.       Case 5
  2518.          $number = _StringInsert($number, ".", -3)
  2519.       Case 6
  2520.          $number = _StringInsert($number, ".", -3)
  2521.       Case 7
  2522.          $number = _StringInsert($number, ".", -3)
  2523.          $number = _StringInsert($number, ".", -7)
  2524.       Case 8
  2525.          $number = _StringInsert($number, ".", -3)
  2526.          $number = _StringInsert($number, ".", -7)
  2527.       Case 9
  2528.          $number = _StringInsert($number, ".", -3)
  2529.          $number = _StringInsert($number, ".", -7)
  2530.       Case 10
  2531.          $number = _StringInsert($number, ".", -3)
  2532.          $number = _StringInsert($number, ".", -7)
  2533.          $number = _StringInsert($number, ".", -11)
  2534.       Case 11
  2535.          $number = _StringInsert($number, ".", -3)
  2536.          $number = _StringInsert($number, ".", -7)
  2537.          $number = _StringInsert($number, ".", -11)
  2538.       Case 12
  2539.          $number = _StringInsert($number, ".", -3)
  2540.          $number = _StringInsert($number, ".", -7)
  2541.          $number = _StringInsert($number, ".", -11)
  2542.    EndSwitch
  2543.    Return $number
  2544. EndFunc
  2545.  
  2546. Func OnAutoItExit()
  2547.    ToLog("Bot closed")
  2548. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement