Advertisement
zEEneXx

farming_sarkoth_dank_cellar_wd_1.4b_zeenexx

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