Advertisement
onedoesnotsimply

Untitled

Jul 11th, 2012
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 76.15 KB | None | 0 0
  1. ; Blaksack's mod 1.93hyb
  2. ; added TP fail detection
  3. ; made ilvl optional
  4. ; timing improvements
  5. ;- optional cellar grid search
  6. ;- optional hour wait after X runs
  7. ;-Added latest changes from NotAres 1.93 including all the iLVL60-63 stuff dont forget new images: http://www45.zippyshare.com/v/15622375/file.html
  8. ;-Fixed the OCR bug where 0 is seen as O
  9. ;-Added option to use another war shout and call ancients before warping out on failed runs called $ExtraSafeExit
  10. ;-Added LATMs legendary item count fix
  11. ;-cleaned up cellar detection code - i hate repeated lines! you can define your own cellar co-ords at line 234ish
  12. ; enhanced cellar find
  13. ; item salvaging
  14. ; stash tab choosing
  15. ; full logging
  16. ; gold income OCR
  17. ; custom keys for skills
  18.  
  19. ; for latest version see http://pastebin.com/PtE6XJ4W
  20. ; you will need tesseract from https://tesseract-ocr.googlecode.com/files/tesseract-ocr-setup-3.01-1.exe
  21. ; and you will need tesserect library to in your auto it include folder from https://dl.dropbox.com/u/22203901/Tesseract.au3
  22. ; you will also need image files and search dlls from https://dl.dropbox.com/u/9955791/BotFiles.zip
  23. ; and http://www45.zippyshare.com/v/15622375/file.html
  24. ; see for instructions http://www.ownedcore.com/forums/diablo-3/diablo-3-bots-programs/d3-gold-profiles/354464-goldfarming-notares-sarkoth-dh-gold-script-autoit-script-1920x1080.html
  25. ; use this build http://us.battle.net/d3/en/calculator/barbarian#TUXgkj!ghV!bYcbZa
  26.  
  27. ;=========== DO NOT TOUCH ===========;
  28. #RequireAdmin
  29. #include <GUIConstantsEx.au3>
  30. #include <StaticConstants.au3>
  31. #include <WindowsConstants.au3>
  32. #include <FastFind.au3>
  33. #include <Tesseract.au3>
  34.  
  35. AutoItSetOption("WinTitleMatchMode", 4)
  36. Global $FFhWnd = WinGetHandle("Diablo III"), $size = WinGetClientSize("[CLASS:D3 Main Window Class]"), $ver = "BlackSack 1.9.3hyb.f ", $hFont = 0, $title, $Paused, $Go = False, $i = 0, $gX = 0, $gY = 0, $LegendaryCount = 0, $SetCount = 0, $RareCount = 0, $MagicCount = 0, $GemCount = 0, $TomeCount = 0, $deathCount = 0, $cellarCount = 0, $t = TimerInit(), $rt = 0, $run = 0, $yellow = 0xFFF000, $red = 0xD90000, $lblRun, $lblLocation, $lblStatus, $lblLast, $lblRuntime, $lblGear, $lblItems
  37. Global $str_Stash, $str_StashGems, $str_StashMisc, $str_Vendor, $str_Salvage, $int_TownPosition, $IDitemX, $IDitemY
  38. Global $numitem, $numgem, $numtomb, $numgold, $numpot, $lblGold, $numsold, $numstashed, $monold = 0, $mon = 0, $monstart = 0, $SprintStart, $lootany, $attackTime, $HeroID, $Hero, $TownTrips = 0, $movementSpeed, $OpenCount = 0, $CloseCount = 0, $FailCount = 0, $UseMultiHeros
  39. Global $gems[8] = ["Ru1.png", "Ru2.png", "Em1.png", "Em2.png", "To1.png", "To2.png", "Am1.png", "Am2.png"]
  40. ;====================================;
  41.  
  42. $pngLoc = "C:\Users\Stox\Desktop\NewBotFiles\pics\" ;Location of the .PNGs (NO SUBFOLDERS - ALL PNGS GO HERE)
  43.  
  44. ;FOR A SINGLE HERO ===============================================
  45. $Hero = "Hunter"
  46. $movementSpeed = 25
  47.  
  48. ;For MULTIPLE HEROS===============================================
  49. $UseMultiHeros = False ; set to true first
  50. ; CLASS = Wizard, Monk, Hunter, Barbarian, Witch
  51. ;                            ID 1               ID2            "CLASS|POSITION IN HERO LIST|MOVESPEED"
  52. Global $HeroSelectList[2] = ["Barbarian|2|11", "Wizard|3|12"]
  53. ;Set the hero in the list above that you want to start with
  54. $HeroID = 2;
  55. ;=================================================================
  56.  
  57. ; WIZARD ONLY OPTIONS
  58. $AddDPS = 13700 ; set your wizard base DPS, assumes improved archeon and magic weapon
  59.  
  60. ;BARBARIAN ONLY OPTIONS
  61. $SarkothKillTime = 0 ;additional time delay to wait for sarkoth to die use 2800 for 10K dps 800 for 15kdps etc
  62. $ExtraSafeExit = False ;use ancients when you port back to prevent death if you have low HP
  63.  
  64. ;HUNTER ONLY OPTIONS
  65. $DHSarkothKillTime = 3000 ;additional time delay to wait for sarkoth to die use 2800 for 10K dps 800 for 15kdps etc
  66.  
  67. ;General
  68. $RunsUntilMenuWait = 0 ;wait for 1 hour at menu after x successful runs, set to 0 to disable
  69. $TakeMissShots = False ;take screenshots into \shots folder on every cellar miss for finding positions
  70. $DetectTPFail = True ;set true to immediatly exit game if TP is inturrupted (requires TP.png)
  71. $TPProtectTime = 2.0 ;number of seconds to check for TP inturrupt if TPfail detection is enabled if your pc is slow reduce this number
  72. $ReduceLegendSearch = True ; limit legendary searching to lower part of screen to reduce false finds
  73. $CheckLootWhilePorting = False; continue scanning for loot while you port back incase sakroth dies late
  74. $CellarEnterHelp = False; Extra click on the cellar if you get stuck ontop of the entrance
  75. $DetectTownFailRetry = True; set true to retry town visit if somthing goes wrong
  76.  
  77. ;AutoStart
  78. $gameDiabloIIILoc = "C:\Program Files (x86)\Diablo III\" ;Location of Diablo 3 executable
  79. $gameAutoStart = 0 ; Set this to 1 to start game from desktop or recover from closed game
  80. $gameStartTime = 9000 ;Change depending on computer/internet speed
  81. $gamePassword = "" ;Symbols go in brackets "Password1{!}"
  82. $gameExecutable = "Diablo III.exe"
  83. GameAutostart()
  84. DoSetupStuff()
  85.  
  86. ;Buttons
  87. $Skill1 = "1"
  88. $Skill2 = "2"
  89. $Skill3 = "3"
  90. $Skill4 = "4"
  91. $TownPortalButton = "t"
  92. $Inventory = "i"
  93.  
  94. ;Looting
  95. $LootSets = True ;True if you want to pick up Sets
  96. $LootLegendaries = True;True if you want to pick up Legendaries
  97. $LootRares = True ;True if you want to pick up Rares
  98. $LootMagic = True ;True if you want to pick up Magic
  99. $LootGems = False ;True if you want to pick up Gems
  100. $LootTomes = True ;True if you want to pick up Tome of Secrets
  101. $LootCustom = True ;True if you want to pick up Custom Items (The items in the $pick array above)
  102. ;Global $pick[1] = ["gold.png|50"];Array of items to loot (GEMS AND TOMES ALREADY INCLUDED)
  103. Global $pick[2] = ["design.png|50", "prosp.png|50"]
  104.  
  105. ;Manage Loot
  106. $Identify = True ;True to enable identifying items before stashing/vendoring
  107. $mLoot = 7 ;Nuber of successful runs until Stash and Vendor
  108. $mLootOff = 3 ;Stash and Vendor after mLoot +- X number of runs (Variability)
  109.  
  110. ;Variability ==NEW SETTINGS==
  111. $Timer = False ;True and the bot will add random sleep intervals
  112. $loadtime = 3400 ;Time (in ms) the script waits for the game to load before it starts pathfinding. Slow this down for slower hard drives
  113. $tptime = 6000 ;Time (in ms) the script waits for teleport before exiting the game
  114.  
  115. ;Stashing/vendoring COMMON
  116. $StashRare = False ;True if you want to store Rare items in the stash
  117. $StashMagic = False ;True if you want to store Magic items in the stash
  118.  
  119. $VendorRare = True;True if you want to vendor Rares
  120. $VendorMagic = True ;True if you want to vendor Magic
  121.  
  122. $GemTab = 1 ;Tab to put gems and tombs in
  123. $ItemTab = 1 ;Tab to put any items in
  124. $NextItemTab = 2 ;Next Tab to put any items in when first one is full
  125. $FinalItemTab = 3 ;Next, Next Tab to put any items in when Next one is full
  126.  
  127. $UseiLVL = True ;set true or false to enable the iLVL system THIS OVERRIDES ALL "TRADITIONAL" SETTINGS
  128.  
  129. ;--------------------------------------------TRADITIONAL----------------------------------------------------
  130. ;Stashing/vendoring TRADITIONAL METHOD to enable set line 155 to FALSE
  131. $StashLoot = True ;True if you want to store Items in the stash
  132. $StashLegendary = True;True if you want to store Legendary items in the stash
  133. $StashTomes = True ;True if you want to store Tomes items in the stash
  134. $StashGems = False ;True if you want to store Gems items in the stash
  135. $StashIdentified = True; Stash all items that have just been identified
  136.  
  137. ;SALVAGE - setting this will OVERRIDE traditional vendoring options - it will be skipped
  138. ; make sure you have a stack of each material in your bottom row( which is not scanned )for it to add To
  139. ; otherwise it will start tying to salvage your craft items and do nothing!
  140. $SalvageLoot = True
  141.  
  142. ;Vendoring ==NEW SETTINGS==
  143. $VendorLoot = True ;True if you want to vendor anything
  144. $vendorAll = False ;True if you want to right click all items when talking to vendor
  145. $vendorRows = 6 ;# of rows to vendor, starting from the top (default = 5: bottom row is safe)
  146. $vendorCols = 10 ;# of columns to vendor, starting from left
  147. ;--------------------------------------------TRADITIONAL----------------------------------------------------
  148.  
  149. ; OPTIONS ABOVE AND BELOW ARE MUTUALLY EXCLUSIVE
  150.  
  151. ;--------------------------------------------iLVL----------------------------------------------------
  152. ;====================================;
  153. ;New Analyze Loot Settings Options are "salvage", "stash", and "vend"
  154. $i59Rare = "stash"
  155. $i60Rare = "stash"
  156. $i61Rare = "stash"
  157. $i62Rare = "stash"
  158. $i63Rare = "stash"
  159.  
  160. $i59Magic = "vend"
  161. $i60Magic = "vend"
  162. $i61Magic = "salvage"
  163. $i62Magic = "salvage"
  164. $i63Magic = "salvage"
  165. ;====================================;
  166. ;--------------------------------------------iLVL----------------------------------------------------
  167. $x_ratio = $size[0] / 1920
  168. $y_ratio = $size[1] / 1080
  169.  
  170. $mLootIn = $mLoot ;DO NOT CHANGE, how many more runs till next manage
  171. $RunsUntilMenuWaitCnt = $RunsUntilMenuWait
  172. $totalItems = UBound($pick) ;Number of items in the pick array
  173. If $totalItems < 1 Then $LootCustom = False
  174. $AddDPS = $AddDPS * 3.25
  175. $attackTime = (170000 / $AddDPS) * 1000
  176. $movementSpeed = 1 + ($movementSpeed / 100)
  177.  
  178. If $TakeMissShots Then
  179.     DirCreate("shots")
  180. EndIf
  181.  
  182. If Not FileExists($pngLoc & "MainMenu.png") Then
  183.     $pngLoc = @ScriptDir & "\pics\"
  184.     If Not FileExists($pngLoc & "MainMenu.png") Then
  185.         MsgBox(16, "Fatal Error", "FATAL ERROR: Cannot find: " & $pngLoc & "MainMenu.png" & @CRLF & "Make sure your directory is set properly in the script")
  186.         Exit
  187.     EndIf
  188. EndIf
  189.  
  190. Call("SetupGUI")
  191. WinActivate("Diablo III")
  192. Sleep(1000)
  193. If $gameAutoStart Then Begin()
  194.  
  195. While 1
  196.     Call("RestartRun")
  197. WEnd
  198.  
  199. Func RestartRun()
  200.     If ($Go) Then
  201.         $i = 0
  202.         Send("{SPACE}")
  203.         WinSetTitle($title, "", $title & $ver & " - Running")
  204.         MouseMove(Round(Random(1000, 1400) * $x_ratio), Round(Random(400, 680) * $y_ratio), 1) ;Moves mouse out of the way
  205.         ;Checks if the player is Dead/Logout/Window, then if in Main Menu, etc.
  206.         If CheckDead() Then
  207.             Return
  208.         ElseIf CheckFor("ExitGame", "", Round(860 * $x_ratio), Round(400 * $y_ratio), Round(1040 * $x_ratio), Round(450 * $y_ratio), 0.2, 140) Then
  209.             GUICtrlSetData($lblStatus, "Status: Exit window up")
  210.             MouseClick("left", Round(1064 * $x_ratio), Round(632 * $y_ratio))
  211.             Sleep(100)
  212.             Send("{SPACE}")
  213.             Return
  214.         ElseIf CheckFor("MainMenu", "", Round(40 * $x_ratio), Round(300 * $y_ratio), Round(400 * $x_ratio), Round(450 * $y_ratio)) Then
  215.             GUICtrlSetData($lblRun, "Runs till vendor: " & $mLootIn & ", Run Number: " & $run)
  216.             GUICtrlSetData($lblLocation, "Location: Main Menu")
  217.             GUICtrlSetData($lblStatus, "Status: Starting Game")
  218.             If ($run = 0) And $UseMultiHeros Then SelectHero($HeroID)
  219.             RandClick("left", Round(230 * $x_ratio), Round(416 * $y_ratio), 120, 20, 1, 2) ;Random Click on the resume button
  220.             CheckFor("OldRuins", "Area", 0, 0, 0, 0, $loadtime / 1000)
  221.             ;Sleep($loadtime)
  222.             $rt = TimerInit()
  223.             $run += 1
  224.         ElseIf CheckFor("OldRuins", "Area") Or CheckFor("NewTristram", "Area") Or CheckFor("DankCellar", "Area") Then
  225.             Call("TownPortal")
  226.             Call("LeaveGame")
  227.             Return
  228.         ElseIf CheckFor("LimitError", "", Round(700 * $x_ratio), Round(340 * $y_ratio), Round(1200 * $x_ratio), Round(600 * $y_ratio), 1, 140) Then
  229.             MouseClick("left", Round(960 * $y_ratio), Round(635 * $x_ratio))
  230.             $rand = Random(40000, 80000)
  231.             GUICtrlSetData($lblStatus, "Status: Input Limit - Waiting " & Round($rand / 1000) & " seconds.")
  232.             Sleep($rand)
  233.             Send("{SPACE}")
  234.             Return
  235.         ElseIf CheckFor("Disconnect", "", Round(700 * $x_ratio), Round(340 * $y_ratio), Round(1200 * $x_ratio), Round(600 * $y_ratio), 1, 140) Then
  236.             GUICtrlSetData($lblStatus, "Status: Network Disconnect window up")
  237.             MouseClick("left", Round(960 * $x_ratio), Round(632 * $y_ratio))
  238.             Sleep(100)
  239.             Send("{SPACE}")
  240.             Return
  241.         Else
  242.             GUICtrlSetData($lblStatus, "ERROR: Cannot find Resume button")
  243.             Addlog("ERROR: Cannot find Resume button")
  244.             If $gameAutoStart Then GameRestart()
  245.             Return
  246.         EndIf
  247.        
  248.         $CellarWasFound = 0
  249.         ;Make sure we are in the right area before beginning run
  250.         If CheckFor("OldRuins", "Area") Then
  251.             Sleep(Random(200, 300))
  252.             GUICtrlSetData($lblLocation, "Location: Old Ruins")
  253.             Call("CheckRepair")
  254.            
  255.             If $run = 1 Then
  256.                 GetMoney(True)
  257.                 $monstart = Number($mon)
  258.             EndIf
  259.            
  260.             If $Hero == 'Barbarian' Then;----------------------------------------------------------------------- HERO DEPENDANT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  261.                 Send($Skill3)
  262.                 Sleep(Random(100, 200))
  263.                 RandClick("middle", Round(587 * $x_ratio), Round(350 * $y_ratio), 15, 5) ;starts the main run
  264.                 Sleep(Random(700, 710))
  265.                 RandMove(Round(16 * $x_ratio), Round(350 * $y_ratio), 20, 6)
  266.                 Sleep(Random(5, 10))
  267.                 Send($Skill1) ;leap
  268.                 $leaptime = TimerInit()
  269.                 Sleep(Random(600, 800))
  270.                 DoSprint()
  271.                 Sleep(Random(50, 80))
  272.                 RandClick("middle", Round(2 * $x_ratio), Round(350 * $y_ratio), 10, 10, 1, 2)
  273.                 Sleep(Random(700, 900))
  274.                 RandClick("middle", Round(2 * $x_ratio), Round(400 * $y_ratio), 15, 15, 1, 2)
  275.                 walktime(Round(2 * $x_ratio), Round(400 * $y_ratio))
  276.                
  277.             ElseIf $Hero == 'Wizard' Then
  278.                 Sleep(100)
  279.                 MouseClick("middle", Round(300 * $x_ratio), Round(100 * $y_ratio), 1) ;starts the main run
  280.                 Sleep(300)
  281.                 MouseClick("middle", Round(0 * $x_ratio), Round(300 * $y_ratio), 1) ;starts the main run
  282.                 Sleep(50)
  283.                 Send("{" & $Skill3 & " down}")
  284.                 Sleep(1000)
  285.                 MouseMove(Round(0 * $x_ratio), Round(450 * $y_ratio), 1)
  286.                 Sleep(900)
  287.                 Send("{" & $Skill3 & " up}")
  288.                 Sleep(100)
  289.                 Send($Skill1)
  290.                
  291.             ElseIf $Hero == 'Hunter' Then
  292.                 Sleep(50)
  293.                 RandClick("middle", Round(500 * $x_ratio), Round(250 * $y_ratio), 2, 2) ;starts the run [waypoint 1]
  294.                 Moving(900)
  295.                 Send($Skill2)
  296.                 Moving(600)
  297.                 RandClick("middle", Round(3 * $y_ratio), Round(370 * $y_ratio), 2, 2) ;waits ~1 second then [waypoint 2]
  298.                 Moving(1850)
  299.                 RandClick("middle", Round(400 * $x_ratio), Round(600 * $y_ratio), 2, 2) ;middle of courtyard [waypoint 3]
  300.                 Moving(100)
  301.                 Send($Skill2)
  302.                 Moving(100)
  303.                 Send($Skill3)
  304.                 Moving(750)
  305.                 Send($Skill1)
  306.                 Moving(100)
  307.                 RandMove(Round(300 * $x_ratio), Round(70 * $y_ratio), 1, 1) ;moves cursor over to the cellar so the proper blue pixel becomes highlighted
  308.                 Sleep(350)         
  309.        
  310.                
  311.                
  312.             ElseIf $Hero == 'Monk' Then
  313.                 Sleep(200)
  314.                 MouseClick("middle", Round(10 * $x_ratio), Round(250 * $y_ratio)) ;starts the main run
  315.                 Send("{" & $Skill4 & " down}")
  316.                 Sleep(4000)
  317.                 Send("{" & $Skill4 & " up}")
  318.                 Sleep(100)
  319.                
  320.             EndIf
  321.            
  322.            
  323.     ; cellar check on minimap
  324.             $cellfound = CheckForCellar()
  325.             If CheckDead() Then Return
  326.  
  327.             ;Checks if Dank Cellar is Open
  328.             If $cellfound Then
  329.                
  330.                 $OpenCount += 1
  331.                 GUICtrlSetData($lblStatus, "Status: Cellar Found")
  332.                 Call("AddLog", "Cellar Found")
  333.                 $cellarCount += 1
  334.                
  335.                 $cellaratx = 1000 * $x_ratio
  336.                 $cellaraty = 500 * $y_ratio
  337.                
  338.                 If $Hero == 'Barbarian' Then;----------------------------------------------------------------------- HERO DEPENDANT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  339.                     DoSprint()
  340.                     RandClick("middle", Round(400 * $x_ratio), Round(430 * $y_ratio), 10, 10)
  341.                     walktime(Round(400 * $x_ratio), Round(430 * $y_ratio), 0)
  342.                 ElseIf $Hero == 'Wizard' Then
  343.                     RandClick("middle", Round(423 * $x_ratio), Round(421 * $y_ratio), 10, 10)
  344.                     walktime(Round(423 * $x_ratio), Round(421 * $y_ratio))
  345.                 ElseIf $Hero == 'Monk' Then
  346.                     RandClick("middle", Round(407 * $x_ratio), Round(427 * $y_ratio), 10, 10)
  347.                     Send("{" & $Skill4 & " down}")
  348.                     Moving(600)
  349.                     Send("{" & $Skill4 & " up}")
  350.                     Sleep(200)
  351.                 ElseIf $Hero == 'Hunter' Then
  352.                         MouseClick("left", Round(300 * $x_ratio), Round(70 * $y_ratio), 1) ;Entrance to cellar
  353.                     Sleep(800 * $movementSpeed)
  354.                     Send($Skill2)
  355.                     walktime(Round(285 * $x_ratio), Round(397 * $y_ratio), -150)
  356.                    
  357.                 EndIf
  358.                
  359.                 ;Local $cellpos = EnhancedFind(0, 0, 1300, 300, 1090, 280)
  360.                 ;$cellaratx = $cellpos[0]
  361.                 ;$cellaraty = $cellpos[1]
  362.                 ;MouseMove(Round($cellaratx), Round($cellaraty), 1) ;Entrance to cellar
  363.                 ;Sleep(100)
  364.                 ;RandClick("left", Round($cellaratx), Round($cellaraty), 5, 2, 2, 2) ;Entrance to cellar
  365.                 ;walktime(Round($cellaratx), Round($cellaraty))
  366.                 ;Call("AddLog",walktime(Round($cellaratx), Round($cellaraty),0,True))
  367.                
  368.                 If $CellarEnterHelp Then RandClick("left", Round(993 * $x_ratio), Round(469 * $y_ratio), 5, 5, 2, 2) ;Entrance to cellar
  369.                
  370.                 CheckFor("DankCellar", "Area", 0, 0, 0, 0, 2)
  371.                 $CellarWasFound = 1
  372.                
  373.             Else ;ABORT RUN
  374.                 $CloseCount += 1
  375.                 GUICtrlSetData($lblStatus, "Status: Cellar - Not Found" & @CRLF)
  376.                 Call("AddLog", 'No Cellar')
  377.                
  378.                 If $TakeMissShots Then CaptureToTIFF("", "", "", "shots\NoCell_" & String($run) & ".tif", 1, 0, 0, 0, 0)
  379.                 SafeExit()
  380.                
  381.                 If $CheckLootWhilePorting Then
  382.                     Send($TownPortalButton)
  383.                     Sleep(200)
  384.                     CheckLootWhilePorting()
  385.                 Else
  386.                     Call("TownPortal")
  387.                 EndIf
  388.                
  389.                 Call("LeaveGame")
  390.                 Return
  391.             EndIf
  392.         Else ; WE'RE NOT IN OLD RUINS
  393.             Call("TownPortal")
  394.             Call("LeaveGame")
  395.             Return
  396.         EndIf
  397.        
  398.         ; CELLAR ENTRANCE RECOVERY
  399.         $TryRecover = 0
  400.         If Not CheckFor("DankCellar", "Area", 0, 0, 0, 0, .5) Then
  401.             ; recover from standing on entrance
  402.             RandClick("left", Round(993 * $x_ratio), Round(469 * $y_ratio), 1) ;Entrance to cellar
  403.             $TryRecover = 1
  404.            
  405.             If Not CheckFor("DankCellar", "Area", 0, 0, 0, 0, 1.5) Then
  406.                 ;recover from wall gateway
  407.                 $TryRecover = 3
  408.                 $cellpos = EnhancedFind(0, 0, 1300, 450, 1000, 350, True)
  409.                 RandClick("left", Round($cellpos[0]), Round($cellpos[1]), 1) ;Entrance to cellar
  410.                 CheckFor("DankCellar", "Area", 0, 0, 0, 0, 4)
  411.             EndIf
  412.         EndIf
  413.  
  414.         ;Checks that the player is in the Dank Cellar
  415.         If CheckFor("DankCellar", "Area") Then
  416.             GUICtrlSetData($lblLocation, "Location: Dank Cellar")
  417.             If $TryRecover = 1 Then Call("AddLog", 'OnCellar Recovery Success from ontop')
  418.             If $TryRecover = 2 Then Call("AddLog", 'OnCellar Recovery Success From wall')
  419.             If $TryRecover = 3 Then Call("AddLog", 'OnCellar Recovery Success using enhanced find')
  420.            
  421.             If $Hero == 'Barbarian' Then;----------------------------------------------------------------------- HERO DEPENDANT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  422.                
  423.                 RandClick("middle", Round(80 * $x_ratio), Round(830 * $y_ratio), 5, 5) ;moves to doorway leading to rare inside cellar
  424.                 walktime(Round(80 * $x_ratio), Round(830 * $y_ratio), -100)
  425.                 ;Sleep(Random(2250, 2300))
  426.                 GUICtrlSetData($lblStatus, "Status: Attacking Sarkoth")
  427.                 RandMove(Round(350 * $x_ratio), Round(60 * $y_ratio), 1) ;hovers over the rare Sarkoth
  428.                 If TimerDiff($leaptime) < 10500 Then
  429.                     Sleep(10500 - TimerDiff($leaptime))
  430.                 EndIf
  431.                 Send($Skill1)
  432.                 Sleep(200)
  433.                 Send("{SHIFTDOWN}")
  434.                 RandClick("left", Round(11 * $x_ratio), Round(1037 * $y_ratio), 10, 10) ;earthquake
  435.                 Sleep(200)
  436.                 RandClick("left", Round(11 * $x_ratio), Round(1037 * $y_ratio), 10, 10) ;earthquake
  437.                 Send("{SHIFTUP}")
  438.                 Sleep(300)
  439.                 Send($Skill2)
  440.                 Sleep(300)
  441.                 Send($Skill4)
  442.                 Sleep(200)
  443.                 MouseClick("right", Round(694 * $x_ratio), Round(929 * $y_ratio)) ;cancel aura thanks to LATM
  444.                 If CheckDead() Then Return
  445.                 Sleep(Random($SarkothKillTime, $SarkothKillTime + 400))
  446.                 RandClick("middle", Round(730 * $x_ratio), Round(585 * $y_ratio), 10, 10) ;move to left top corner for gold
  447.                 Sleep(Random(850, 1350))
  448.                 RandClick("middle", Round(1205 * $x_ratio), Round(380 * $y_ratio), 10, 10) ;move to right top corner for gold
  449.                 Sleep(Random(900, 1400))
  450.                 RandClick("middle", Round(1121 * $x_ratio), Round(805 * $y_ratio), 10, 10) ;move to middle before looting
  451.                 Sleep(Random(900, 1150))
  452.                
  453.             ElseIf $Hero == 'Wizard' Then
  454.                
  455.                 RandClick("middle", Round(20 * $x_ratio), Round(708 * $y_ratio), 1, 1) ;moves to doorway leading to rare inside cellar
  456.                 walktime(Round(20 * $x_ratio), Round(708 * $y_ratio), -100)
  457.                 RandMove(Round(440 * $x_ratio), Round(80 * $y_ratio), 1, 1) ;hovers over the rare Sarkoth
  458.                 Sleep(150)
  459.                 Send("4")
  460.                 Sleep(200)
  461.                 Send("{SHIFTDOWN}")
  462.                 GUICtrlSetData($lblStatus, "Status: Attacking Sarkoth")
  463.                 MouseDown("right") ;ATTACK
  464.                 Sleep($attackTime)
  465.                 MouseUp("right")
  466.                 Sleep(150)
  467.                 Send("{SHIFTUP}")
  468.                 RandClick("middle", Round(558 * $x_ratio), Round(224 * $y_ratio), 1, 1)
  469.                 walktime(Round(558 * $x_ratio), Round(224 * $y_ratio), -800)
  470.                 MouseClick("right", Round(755 * $x_ratio), Round(936 * $y_ratio), 1) ;cancel archon
  471.                
  472.             ElseIf $Hero == 'Hunter' Then
  473.                 Send($Skill4)
  474.                 RandClick("middle", Round(20 * $x_ratio), Round(708 * $y_ratio), 1, 1) ;moves to doorway leading to rare inside cellar
  475.                 Moving(2800)
  476.                 RandMove(Round(425 * $x_ratio), Round(70 * $y_ratio), 1, 1)
  477.                 ;Send($Skill4)
  478.                 Send("{SHIFTDOWN}")
  479.                 MouseDown("right") ;ATTACK
  480.                 Sleep(1200)
  481.                 MouseUp("right")
  482.                 MouseDown("left")
  483.                 Sleep($DHSarkothKillTime)
  484.                 MouseUp("left")
  485.                 Sleep(Random(50, 150))
  486.                 Send("{SHIFTUP}")
  487.                 RandClick("middle", Round(470 * $x_ratio), Round(280 * $y_ratio)) ;Left
  488.                 Moving(2500)
  489.                
  490.             ElseIf $Hero == 'Monk' Then
  491.                
  492.                 MouseClick("middle", Round(110 * $x_ratio), Round(1000 * $y_ratio)) ;moves to doorway leading to rare inside cellar
  493.                 ;Sleep(Random(2200, 2300))
  494.                 Send("{" & $Skill4 & " down}")
  495.                 Sleep(1000)
  496.                 Send("{" & $Skill4 & " up}")
  497.                 Send($Skill3)
  498.                 Sleep(30)
  499.                 MouseClick("middle", Round(440 * $x_ratio), Round(80 * $y_ratio), 1) ;attacks the rare Sarkoth
  500.                 Send("{" & $Skill4 & " down}")
  501.                 Sleep(1200)
  502.                 Send("{" & $Skill4 & " up}")
  503.                 Send("{SHIFTDOWN}")
  504.                 Sleep(10)
  505.                 GUICtrlSetData($lblStatus, "Status: Attacking Sarkoth")
  506.                 MouseClick("left")
  507.                 Sleep(10)
  508.                 Send($Skill2)
  509.                 Sleep(10)
  510.                 MouseDown("right") ;attack middle
  511.                 Sleep(1500)
  512.                 MouseClick("right", Round(960 * $x_ratio), Round(502 * $y_ratio), 2)
  513.                 Sleep(100)
  514.                 Send("{SHIFTUP}")
  515.                 Sleep(10)
  516.                 Send($Skill3)
  517.                 Sleep(10)
  518.                 MouseClick("middle", Round(637 * $x_ratio), Round(540 * $y_ratio)) ;move to left top corner for gold
  519.                 Sleep(600)
  520.                 MouseClick("middle", Round(1320 * $x_ratio), Round(310 * $y_ratio)) ;move to right top corner for gold
  521.                 Sleep(600)
  522.                 MouseClick("middle", Round(975 * $x_ratio), Round(827 * $y_ratio)) ;move to middle before looting
  523.                 Sleep(600)
  524.                
  525.                
  526.             EndIf
  527.            
  528.             GUICtrlSetData($lblStatus, "Status: Looting")
  529.            
  530.             $numgem = 0
  531.             $numtomb = 0
  532.             $numgold = 0
  533.             $numpot = 0
  534.             $numitem = 0
  535.            
  536.             If ($Hero == 'Barbarian') Or ($Hero == 'Hunter') Then
  537.                 DoSprint()
  538.             EndIf
  539.             Call("Loot")
  540.            
  541.             RandSleep(0, 6, 30)
  542.            
  543.             If $CheckLootWhilePorting Then Send($TownPortalButton)
  544.             Sleep(200)
  545.            
  546.             $mondelt = GetMoney(True)
  547.             If $Hero == 'Hunter' Then Send($Skill4)
  548.            
  549.            
  550.             If $CheckLootWhilePorting Then
  551.                 CheckLootWhilePorting()
  552.             Else
  553.                 Call("TownPortal")
  554.             EndIf
  555.            
  556.             GUICtrlSetData($lblGold, "Gold: " & $mon & ", Run: " & $mondelt & ", Gain: " & Number($mon) - $monstart)
  557.             Call("AddLog", 'Gold: ' & $mon & ', Gold Delt: ' & $mondelt & ', Items: ' & $numitem & ', Gems: ' & $numgem & ', Books: ' & $numtomb & ', Potions: ' & $numpot & ', GoldPick: ' & $numgold)
  558.            
  559.         Else
  560.             If $TryRecover = 1 Then Call("AddLog", 'OnCellar Recovery Failure')
  561.             If $CellarWasFound = 1 Then Call("AddLog", 'Cellar was found but didnt end up there')
  562.             If $TakeMissShots Then CaptureToTIFF("", "", "", "shots\MissCell_" & String($run) & ".tif", 1, 0, 0, 0, 0)
  563.             $FailCount += 1
  564.             SafeExit()
  565.             Call("TownPortal")
  566.             If Not CheckDead() Then Call("LeaveGame")
  567.             Return
  568.         EndIf
  569.        
  570.         ;After successful run
  571.         If Not CheckDead() Then
  572.             Sleep(600)
  573.             $JustVendored = False
  574.             If $mLootIn = 1 And CheckFor("NewTristram", "Area") Then ;If its time to manage loot and we are in town
  575.                 $mLootIn = Round(Random($mLoot - $mLootOff, $mLoot + $mLootOff)) ;Reset Counter
  576.                
  577.                 If $UseiLVL Then
  578.                     Call("AnalyseLoots")
  579.                 Else
  580.                     If $Identify Then Call("Identify")
  581.                     If $StashLoot Then Call("StashLoot")
  582.                    
  583.                     If $SalvageLoot Then
  584.                         Call("SalvageLoot")
  585.                     Else
  586.                         If $VendorLoot Then Call("VendorLoot")
  587.                     EndIf
  588.                 EndIf
  589.                
  590.                 If $mLootIn > 1 Then $JustVendored = True
  591.                
  592.             ElseIf Not CheckFor("NewTristram", "Area") Then
  593.                 GUICtrlSetData($lblStatus, "Status: Skipping vendor, not in New Tristram")
  594.                 Sleep(3000)
  595.             ElseIf $mLootIn <= 0 Then
  596.                 $mLootIn = 1
  597.             Else
  598.                 $mLootIn -= 1
  599.             EndIf
  600.             If Not CheckDead() Then
  601.                 Call("LeaveGame")
  602.             EndIf
  603.            
  604.             If $UseMultiHeros Then
  605.                 ;Select random hero
  606.                 If $JustVendored Then
  607.                     $newid = Random(1, UBound($HeroSelectList), 1)
  608.                     If UBound($HeroSelectList) = 1 Then $newid = 1
  609.                     If $newid <> $HeroID Then
  610.                         SelectHero($newid)
  611.                         Addlog("Switched to hero: " & $Hero)
  612.                     EndIf
  613.                 EndIf
  614.             EndIf
  615.            
  616.             If ($RunsUntilMenuWaitCnt = 1) And ($RunsUntilMenuWait > 0) Then
  617.                 $RunsUntilMenuWaitCnt = $RunsUntilMenuWait
  618.                 Sleep(Random(3550000, 3650000)) ;wait 1 hour
  619.             Else
  620.                 $RunsUntilMenuWaitCnt -= 1
  621.             EndIf
  622.            
  623.             Return
  624.         Else
  625.             Return
  626.         EndIf
  627.     EndIf
  628. EndFunc   ;==>RestartRun
  629.  
  630. Func SafeExit()
  631.    
  632.     If $Hero == 'Barbarian' Then;----------------------------------------------------------------------- HERO DEPENDANT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  633.         If $ExtraSafeExit Then
  634.             Send($Skill2) ;grim harvest
  635.             Sleep(Random(200, 300))
  636.            
  637.             Send($Skill4) ;ancients
  638.             Sleep(Random(500, 600))
  639.         EndIf
  640.         Send("{SHIFTDOWN}")
  641.         RandClick("left", Round(900 * $x_ratio), Round(600 * $y_ratio), 100, 100) ;earthquake
  642.         Send("{SHIFTUP}")
  643.         Sleep(Random(550, 650))
  644.        
  645.     ElseIf $Hero == 'Wizard' Then
  646.         Send($Skill2)
  647.         Sleep(Random(200, 300))
  648.         Send("{SHIFTDOWN}")
  649.         Sleep(Random(200, 300))
  650.         MouseClick("left")
  651.         Sleep(Random(200, 300))
  652.         Send("{SHIFTUP}")
  653.         Sleep(Random(750, 850))
  654.     ElseIf $Hero == 'Hunter' Then
  655.        
  656.         Sleep(10)
  657.         RandClick("middle", Round(1100 * $x_ratio), Round(600 * $y_ratio)) ;moves between caltrops for safety before teleporting back to town
  658.         Moving(250)
  659.         Send($Skill1)
  660.         Sleep(620)
  661.         Send($Skill2)
  662.         Sleep(40)
  663.        
  664.     ElseIf $Hero == 'Monk' Then
  665.         Sleep(10)
  666.         Send($Skill3)
  667.         Moving(250)
  668.         Send($Skill1)
  669.         Sleep(620)
  670.         Send($Skill2)
  671.         Sleep(40)
  672.        
  673.     EndIf
  674. EndFunc   ;==>SafeExit
  675.  
  676. Func VendorLoot()
  677.     GUICtrlSetData($lblStatus, "Status: Vendoring Items")
  678.    
  679.     If $Hero == 'Barbarian' Or $Hero == 'Hunter' Or $Hero == 'Monk' Then ;----------------------------------------------------------------------- HERO DEPENDANT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  680.         Sleep(Random(200, 300))
  681.         If $Hero == 'Barbarian' Then
  682.             Send($Skill3)
  683.             Sleep(Random(300, 400))
  684.            
  685.         EndIf
  686.         If $Hero == 'Barbarian' Or $Hero == 'Hunter' Then
  687.             DoSprint()
  688.         EndIf
  689.         If Not $StashLoot Then ;Move from TP towards vendor
  690.             Sleep(Random(100, 300))
  691.             MouseClick("middle", 1565 * $x_ratio, 50 * $y_ratio)
  692.             walktime(1565 * $x_ratio, 50 * $y_ratio, 150)
  693.         Else ;Move from Stash towards vendor
  694.             Sleep(Random(100, 300))
  695.             MouseClick("middle", 1560 * $x_ratio, 120 * $y_ratio)
  696.             walktime(1560 * $x_ratio, 120 * $y_ratio, 150)
  697.         EndIf
  698.  
  699.         MouseClick("left", 1030 * $x_ratio, 210 * $y_ratio) ;Talk to vendor
  700.         walktime(1030 * $x_ratio, 210 * $y_ratio, 250)
  701.  
  702.  
  703.     ElseIf $Hero == 'Wizard' Then
  704.        
  705.         If Not $StashLoot Then
  706.             MouseMove(1530 * $x_ratio), 0 * $y_ratio), 1) ;begin movement towards merchant
  707.             Send("{3 down}")
  708.             Sleep(1300)
  709.             Send("{3 up}")
  710.         Else ;Move from Stash towards vendor
  711.             Sleep(Random(300, 500))
  712.             MouseMove(1525 * $x_ratio, 70 * $y_ratio)
  713.             Send("{3 down}")
  714.             Sleep(1300)
  715.             Send("{3 up}")
  716.         EndIf
  717.         MouseClick("left", Round(796 * $x_ratio), Round(474 * $y_ratio), 6) ;NPC Merchant to the right of cain's
  718.        
  719.     EndIf
  720.    
  721.     Sleep(300)
  722.     $numsold = 0;
  723.     $TownTrips += 1;
  724.  
  725.     ;All
  726.     If $vendorAll Or (Mod($TownTrips, 4) = 0) Then
  727.         For $c = 1 To $vendorCols
  728.             For $r = 1 To $vendorRows
  729.                 RandClick("right", (((($c - 1) * 50) + 32 + 1400) * $x_ratio), (((($r - 1) * 51) + 32 + 580) * $y_ratio), 2, 2, 1, 2.5)
  730.             Next
  731.         Next
  732.     Else
  733.        
  734.         ;Rares
  735.         If $VendorRare Then
  736.             ClickItems(0x4A3C0B, 2)
  737.         EndIf
  738.         ;Magic
  739.         If $VendorMagic Then
  740.             ClickItems(0x182037, 2)
  741.         EndIf
  742.        
  743.     EndIf
  744.    
  745.     $montmp = $mon
  746.     $mondelt = GetMoney()
  747.    
  748.     If $mon > 0 Or (Not $DetectTownFailRetry) Then
  749.         GUICtrlSetData($lblGold, "Gold: " & $mon & ", Sold value: " & $mondelt)
  750.         Call("AddLog", "Sold Items: " & $numsold & ", Sold value: " & $mondelt)
  751.     Else
  752.         $mLootIn = 1
  753.         $mon = $montmp
  754.         Call("AddLog", "Somthing went wrong in town, retrying next time")
  755.         GUICtrlSetData($lblGold, "Vend fail, retry next run")
  756.         Return
  757.     EndIf
  758.    
  759.     Sleep(200)
  760.     RandClick("left", Round(521 * $x_ratio), Round(506 * $y_ratio), 1, 1) ;button to open up repair menu
  761.     Sleep(300)
  762.     RandClick("left", Round(260 * $x_ratio), Round(595 * $y_ratio), 1, 1) ;button to pay for repairs
  763.     Sleep(400)
  764.  
  765.     $mondelt = GetMoney()
  766.     GUICtrlSetData($lblGold, "Gold: " & $mon & ", Repair cost: " & $mondelt)
  767.     Call("AddLog", "Repair Cost: " & - $mondelt)
  768.  
  769.     GUICtrlSetData($lblStatus, "Status: Done With Vendor")
  770.     Send("{ESCAPE}")
  771. EndFunc   ;==>VendorLoot
  772.  
  773. Func StashLoot()
  774.     GUICtrlSetData($lblStatus, "Status: Putting Items in Stash")
  775.     MouseClick("left", 1064 * $x_ratio, 256 * $y_ratio)
  776.     Sleep(Random(800, 1000))
  777.  
  778.     ClickTab($GemTab)
  779.     ;Tomes
  780.     If $StashTomes Then
  781.         GUICtrlSetData($lblStatus, "Status: Stashing Tomes")
  782.         ClickImage("TomeIcon.png", 140, 1)
  783.     EndIf
  784.    
  785.     ;Gems (DOESN'T STASH BOTTOM ROW!)
  786.     If $StashGems Then
  787.         GUICtrlSetData($lblStatus, "Status: Stashing Gems")
  788.         For $i = 0 To 7
  789.             ClickImage($gems[$i], 150, 1)
  790.         Next
  791.     EndIf
  792.    
  793.     $numstashed = 0;
  794.     ClickTab($ItemTab)
  795.  
  796.     If $Identify And $StashIdentified Then
  797.         If (StringLen($IDitemX) > 1) Then
  798.             $unidx = StringSplit($IDitemX, "|")
  799.             $unidy = StringSplit($IDitemY, "|")
  800.  
  801.             MouseMove(Round(Random(1000, 1300) * $x_ratio), Round(Random(300, 500) * $y_ratio), 1) ;Moves mouse out of the way
  802.             Sleep(100)
  803.             For $i = 1 To $unidx[0]
  804.  
  805.                 $psum = PixelChecksum($unidx[$i] - 2, $unidy[$i] - 2, $unidx[$i] + 2, $unidy[$i] + 2)
  806.                 randclick("right", $unidx[$i], $unidy[$i], 3, 3, 1, 3)
  807.                 Sleep(100)
  808.                 MouseMove(Round(Random(1000, 1300) * $x_ratio), Round(Random(300, 500) * $y_ratio), 1) ;Moves mouse out of the way
  809.                 For $j = 1 To 4
  810.                     Sleep(200)
  811.                     If PixelChecksum($unidx[$i] - 2, $unidy[$i] - 2, $unidx[$i] + 2, $unidy[$i] + 2) = $psum Then
  812.                         If $j = 4 Then
  813.                             UseNextTab()
  814.                             ClickTab($ItemTab)
  815.                             Sleep(200)
  816.                         EndIf
  817.                     Else
  818.                         ExitLoop
  819.                     EndIf
  820.                 Next
  821.  
  822.             Next
  823.         EndIf
  824.     Else
  825.  
  826.         If $StashLegendary Then
  827.             ClickItems(0xFF7F00, 2, True, 5)
  828.             ClickItems(0x8F5C25, 2, True, 5)
  829.         EndIf
  830.  
  831.         If $StashRare Then
  832.             ClickItems(0x4A3C0B, 1, True, 20)
  833.         EndIf
  834.        
  835.     EndIf
  836.    
  837.     If $StashMagic Then
  838.         ClickItems(0x182037, 1, True, 30)
  839.     EndIf
  840.    
  841.  
  842.  
  843.     Call("AddLog", "Stashed Items: " & $numstashed)
  844.    
  845.     Sleep(Random(300, 400))
  846.    
  847.    
  848.     Send("{SPACE}")
  849. EndFunc   ;==>StashLoot
  850.  
  851.  
  852.  
  853. Func Loot($extra = False)
  854.  
  855.     MouseMove(Round(Random(0, 400) * $x_ratio), Round(Random(700, 1080) * $y_ratio), 3) ;Moves mouse out of the way
  856.    
  857.     If Not $extra Then
  858.         If $LootGems Then
  859.             LootImage("square.png", 90, 10)
  860.         EndIf
  861.         If $LootTomes Then
  862.             LootImage("tome.png", 90, 10)
  863.         EndIf
  864.        
  865.  
  866.         If $LootMagic Then
  867.             $mac = LootGear(0x6969FF, 0)
  868.             $MagicCount += $mac
  869.             $numitem -= $mac
  870.         EndIf
  871.     EndIf
  872.  
  873.     If $LootRares Then
  874.         $RareCount += LootGear(0xBBBB00, 1)
  875.     EndIf
  876.  
  877.     If $LootCustom Then
  878.         Call("LootCustom")
  879.     EndIf
  880.    
  881.     If $LootLegendaries Then
  882.         If $ReduceLegendSearch Then
  883.             $LegendaryCount += LootGear(0xBF642F, 1, 365, 442, 380)
  884.             $LegendaryCount += LootGear(0xBF642F, 1, 442, 1690, 115)
  885.         Else
  886.             $LegendaryCount += LootGear(0xBF642F, 1)
  887.         EndIf
  888.     EndIf
  889.    
  890.     If $LootSets Then
  891.         $SetCount += LootGear(0x02CE01, 2)
  892.     EndIf
  893.    
  894.     Call("ShowLoot")
  895. EndFunc   ;==>Loot
  896.  
  897. Func SelectHero($ID)
  898.     $HeroID = $ID
  899.     $array = StringSplit($HeroSelectList[$HeroID - 1], "|")
  900.     $Hero = $array[1]
  901.     $Listnum = $array[2]
  902.     $movementSpeed = $array[3] ;This is the % increase movement speed you have. 25 = 25%, 0 = 0%, 50 = 50%
  903.     $movementSpeed = 1 + ($movementSpeed / 100)
  904.  
  905.     RandClick("left", Round(955 * $x_ratio), Round(932 * $y_ratio), 20, 6) ;select button
  906.     Sleep(Random(800, 1000))
  907.     RandClick("left", Round(221 * $x_ratio), Round((234 + 87 * ($Listnum - 1)) * $y_ratio), 20, 10) ;hero slot
  908.     Sleep(Random(800, 1000))
  909.     RandClick("left", Round(966 * $x_ratio), Round(961 * $y_ratio), 20, 6) ;select hero
  910.     Sleep(Random(1800, 2200))
  911. EndFunc   ;==>SelectHero
  912.  
  913.  
  914. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ THINGS  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~###########################################################
  915.  
  916. Func CheckLootWhilePorting()
  917.  
  918.     $lootany = 0
  919.  
  920.     For $retryloot = 1 To 3
  921.  
  922.         Sleep(550)
  923.         Loot(True)
  924.         If $lootany > 0 Then
  925.             GUICtrlSetData($lblStatus, "GOLD!" & @CRLF)
  926.             Call("AddLog", 'Got gold on failrun on pass ' & $retryloot)
  927.             Call("TownPortal")
  928.             ExitLoop
  929.         EndIf
  930.         If Not _ImageSearchArea($pngLoc & "TP.png", 1, 600, 200, 1000, 500, $gX, $gY, 50) Then
  931.             GUICtrlSetData($lblStatus, "INTURRUPTED" & @CRLF)
  932.             Return
  933.            
  934.         EndIf
  935.     Next
  936.    
  937.     CheckFor("NewTristram", "Area")
  938.  
  939. EndFunc   ;==>CheckLootWhilePorting
  940.  
  941. Func GetMoney($OpenInv = False)
  942.  
  943.     If $OpenInv Then Send($Inventory)
  944.     Sleep(200)
  945.     $mon = _TesseractScreenCapture(0, "", 1, 2, 1454 * $x_ratio, 508 * $y_ratio, (1920 - 1571) * $x_ratio, (1080 - 525) * $y_ratio, 0)
  946.     $mon = CleanOCR($mon)
  947.     If $OpenInv Then Send($Inventory)
  948.     Sleep(50)
  949.  
  950.     $mondelt = $mon - $monold
  951.     $monold = $mon
  952.     Return $mondelt
  953. EndFunc   ;==>GetMoney
  954.  
  955. Func CheckForCellar()
  956.  
  957.     ; cellar check on minimap
  958.     $cellfoundat = False
  959.     $Pixel2 = PixelSearch(0, 0, Round(600 * $x_ratio), Round(600 * $y_ratio), 0x334FB7, 3)
  960.     ;FFSnapShot(1593 * $x_ratio, 62 * $y_ratio, 1824 * $x_ratio, 350 * $y_ratio, 0)
  961.     ;Local $bColorArray[3] = [0x692A09, 0x5A2408, 0x6A2A0A]
  962.  
  963.     ;FFAddColor($bColorArray)
  964.     ;FFAddExcludedArea(1824 * $x_ratio, 80 * $y_ratio, 1912 * $x_ratio, 353 * $y_ratio)
  965.     ;FFSaveBMP("CellarMinimap_" & @HOUR & @MIN & @SEC, false) ;->uncomment if you wanna see  the cellar minimap detection bmp ( gets saved where the script runs )
  966.     ;Local $aCoords = FFBestSpot(2, 1, 4, 367 * $x_ratio, 135 * $y_ratio, -1, 25, False)
  967.  
  968.     If Not @error Then
  969.         $cellfoundat = True ;found the cellar
  970.         FFResetColors()
  971.     Else
  972.         AddLog("enhanced fail")
  973.     EndIf
  974.     Return $cellfoundat
  975. EndFunc   ;==>CheckForCellar
  976.  
  977. Func DoSetupStuff()
  978.  
  979.     FFSetDebugMode(0)
  980.     Opt('MouseCoordMode', 2)
  981.     Opt('PixelCoordMode', 2)
  982.     For $i = 0 To Random(0, 3, 1)
  983.         $title &= Chr(Random(97, 122, 1))
  984.     Next
  985.     For $i = 0 To Random(2, 5, 1)
  986.         $title &= Chr(Random(65, 90, 1))
  987.     Next
  988.     $title &= " "
  989.  
  990.     If @OSArch = "X64" Then DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)
  991.     If @OSArch = "X64" And Not @AutoItX64 Then MsgBox(16, "ERROR", "Why aren't you running the 64-bit AutoIt??? Expect bugs!")
  992.     If $size = 0 Then
  993.         MsgBox(16, "Error", "Diablo III is not running, cannot grab resolution!" & @CRLF & "Exiting...")
  994.         Exit
  995.     EndIf
  996.     $Kill = ProcessList("AutoIt3_x64.exe")
  997.     For $i = 1 To $Kill[0][0]
  998.         $CurrentPID = @AutoItPID
  999.         If $CurrentPID < $Kill[$i][1] Or $CurrentPID > $Kill[$i][1] Then
  1000.             ProcessClose($Kill[$i][1])
  1001.         EndIf
  1002.     Next
  1003.  
  1004.     ;============= SETTINGS =============;
  1005.     HotKeySet("=", "Begin") ;script toggled on/off by pressing =
  1006.     HotKeySet("{PAUSE}", "TogglePause") ;script toggle pause by pressing Pause/Break key
  1007.     HotKeySet("x", "Stop") ;script stopped by pressing x
  1008.     HotKeySet("0", "GoTown") ;script stopped by pressing x
  1009.  
  1010. EndFunc   ;==>DoSetupStuff
  1011.  
  1012. Func GameRestart()
  1013.     ProcessClose("Diablo III.exe")
  1014.     Sleep(1000)
  1015.     GameAutostart()
  1016. EndFunc   ;==>GameRestart
  1017.  
  1018. Func Decode($inp)
  1019.     $outp = ""
  1020.     For $i = 1 To StringLen($inp)
  1021.         $outp &= Chr(Asc(StringMid($inp, $i, 1)) - $i)
  1022.     Next
  1023.     Return $outp
  1024. EndFunc   ;==>Decode
  1025.  
  1026. Func GameAutostart()
  1027.     If ProcessExists($gameExecutable) = 0 Then
  1028.         If FileExists("password.txt") And (StringLen($gamePassword) = 0) Then
  1029.             $gamePassword = FileReadLine("password.txt")
  1030.             $gamePassword = Decode($gamePassword)
  1031.         EndIf
  1032.         ;GUICtrlSetData($lblStatus, "Status: Starting Game Client")
  1033.         Run($gameDiabloIIILoc & $gameExecutable & " -launch")
  1034.         Sleep($gameStartTime)
  1035.         WinActivate("Diablo III")
  1036.         Sleep(500)
  1037.         Send($gamePassword)
  1038.         Sleep(500)
  1039.         Send("{ENTER}")
  1040.         Sleep($gameStartTime)
  1041.         $size = WinGetClientSize("[CLASS:D3 Main Window Class]")
  1042.  
  1043.     Else
  1044.         $size = WinGetClientSize("[CLASS:D3 Main Window Class]")
  1045.  
  1046.     EndIf
  1047. EndFunc   ;==>GameAutostart
  1048.  
  1049. Func CheckFor($img, $type = "", $startX = 0, $startY = 0, $endX = @DesktopWidth, $endY = @DesktopHeight, $seconds = 6, $tolerance = 140)
  1050.     If $type = "Area" Then
  1051.         $startX = 1500 * $x_ratio
  1052.         $startY = 0 * $y_ratio
  1053.         $endX = 1920 * $x_ratio
  1054.         $endY = 90 * $y_ratio
  1055.         If $seconds = 6 Then $seconds = 2.5
  1056.     EndIf
  1057.  
  1058.     $c = 0
  1059.     $string = $pngLoc & $img & ".png"
  1060.     If _ImageSearchArea($string, 1, $startX, $startY, $endX, $endY, $gX, $gY, $tolerance) Then Return True
  1061.     Do
  1062.         $c += 1
  1063.         Sleep(200)
  1064.         If $c > ($seconds * 5) Then ;Make sure we never get stuck here for infinity.
  1065.             If $type = "Area" Then
  1066.                 GUICtrlSetData($lblStatus, "Status: Area not found - " & $img)
  1067.             EndIf
  1068.             Return False
  1069.         EndIf
  1070.     Until _ImageSearchArea($string, 1, $startX, $startY, $endX, $endY, $gX, $gY, $tolerance)
  1071.     GUICtrlSetData($lblStatus, "Status: Area found! " & $img)
  1072.     Return True
  1073. EndFunc   ;==>CheckFor
  1074.  
  1075. Func DoSprint()
  1076.     If $Hero = "Hunter" Then
  1077.         Send($Skill2)
  1078.     Else
  1079.         RandClick("right", Round(15 * $x_ratio), Round(1055 * $y_ratio)) ;sprint
  1080.     EndIf
  1081.     $SprintStart = TimerInit()
  1082. EndFunc   ;==>DoSprint
  1083.  
  1084. Func WalkTime($lootx, $looty, $extra = 0, $returnv = False)
  1085.     $PPmSsprint = (960 / 2100) * $movementSpeed
  1086.     $PPmSwalk = (960 / 3000) * $movementSpeed
  1087.     Dim $BarbFeet[2] = [960 * $x_ratio, 505 * $y_ratio]
  1088.    
  1089.     $dist = Sqrt(($BarbFeet[0] - $lootx) ^ 2 + ($BarbFeet[1] - $looty) ^ 2)
  1090.     If $Hero == "Hunter" Then
  1091.         $sprintremain = 2000 - TimerDiff($SprintStart)
  1092.     Else
  1093.         $sprintremain = 3000 - TimerDiff($SprintStart)
  1094.     EndIf
  1095.  
  1096.     ;determine if sprint is still active to choose run speed
  1097.     If $sprintremain > 0 Then ;duration of sprint - 100 for safty
  1098.         ;calculate milliseconds per pixel for this run, return delay
  1099.         ;calculate composite sleep time
  1100.         If $dist < $PPmSsprint * $sprintremain Then
  1101.             $stime = ($dist / $PPmSsprint + $extra)
  1102.         Else
  1103.             $stime = (($sprintremain + ($dist - $sprintremain * $PPmSsprint) / $PPmSwalk) + $extra)
  1104.         EndIf
  1105.     Else
  1106.         $stime = ($dist / $PPmSwalk + $extra)
  1107.     EndIf
  1108.  
  1109.     If $stime < 0 Then $stime = 0
  1110.     If Not $returnv Then
  1111.         Sleep($stime)
  1112.     EndIf
  1113.     Return $stime
  1114. EndFunc   ;==>WalkTime
  1115.  
  1116. Func LootGear($color, $tolerance = 2, $x1 = 450, $x2 = 1690, $y1 = 20, $y2 = 900)
  1117.     $count = 0
  1118.     $Loot = PixelSearch(Round($x1 * $x_ratio), Round($y1 * $y_ratio), Round($x2 * $x_ratio), Round($y2 * $y_ratio), $color, $tolerance)
  1119.     If Not @error Then
  1120.         While Not @error
  1121.             $count += 1
  1122.             MouseClick('left', $Loot[0], $Loot[1], 1, 1)
  1123.             Sleep(20)
  1124.             MouseMove(Round(Random(0, 400) * $x_ratio), Round(Random(700, 1080) * $y_ratio), 3) ;Moves mouse out of the way
  1125.             WalkTime($Loot[0], $Loot[1])
  1126.             ;Sleep(Random(700, 800))
  1127.             ;Run at max 10 times per quality
  1128.             $lootany += 1
  1129.             If $count >= 10 Then
  1130.                 ExitLoop
  1131.             EndIf
  1132.             $Loot = PixelSearch(Round($x1 * $x_ratio), Round($y1 * $y_ratio), Round($x2 * $x_ratio), Round($y2 * $y_ratio), $color, $tolerance)
  1133.         WEnd
  1134.     EndIf
  1135.     $numitem += $count;
  1136.     Return $count
  1137. EndFunc   ;==>LootGear
  1138.  
  1139. Func LootImage($img, $tol, $max = 10, $x1 = 0, $y1 = 0, $x2 = @DesktopWidth, $y2 = @DesktopHeight)
  1140.     $count = 0
  1141.     $gX = 0
  1142.     $gY = 0
  1143.     GUICtrlSetData($lblStatus, "Status: Looting - " & $img)
  1144.     While _ImageSearchArea($pngLoc & $img, 1, $x1, $y1, $x2, $y2, $gX, $gY, $tol)
  1145.         $count += 1
  1146.         MouseClick("left", $gX, $gY - 3, 1, 1)
  1147.         Sleep(50)
  1148.         MouseMove(Round(Random(0, 400) * $x_ratio), Round(Random(700, 1080) * $y_ratio), 3) ;Moves mouse out of the way
  1149.         $lootany += 1
  1150.         If $img == "square.png" Then
  1151.             $GemCount += 1
  1152.             $numgem += 1
  1153.         ElseIf $img == "tome.png" Then
  1154.             $TomeCount += 1
  1155.             $numtomb += 1
  1156.         ElseIf $img == "gold.png" Then
  1157.             $numgold += 1
  1158.         ElseIf $img == "mythic.png" Then
  1159.             $numpot += 1
  1160.         EndIf
  1161.         If $img == "gold.png" Then
  1162.             WalkTime($gX, $gY, -500)
  1163.         Else
  1164.             WalkTime($gX, $gY)
  1165.         EndIf
  1166.         If $count >= $max Then
  1167.             ExitLoop
  1168.         EndIf
  1169.     WEnd
  1170.     Return $count
  1171. EndFunc   ;==>LootImage
  1172.  
  1173. Func LootCustom()
  1174.     For $i = 0 To ($totalItems - 1)
  1175.         $array = StringSplit($pick[$i], "|")
  1176.         LootImage($array[1], $array[2], 5)
  1177.     Next
  1178. EndFunc   ;==>LootCustom
  1179.  
  1180. Func Identify()
  1181.     Send($Inventory)
  1182.     Sleep(1300)
  1183.     $count = 0
  1184.     $IDitemX = ""
  1185.     $IDitemY = ""
  1186.    
  1187.     While _ImageSearchArea($pngLoc & "unidentified.png", 1, 1400 * $x_ratio, 580 * $y_ratio, 1914 * $x_ratio, 888 * $y_ratio, $gX, $gY, 120)
  1188.         $count += 1
  1189.         GUICtrlSetData($lblStatus, "Status: Identifying")
  1190.         MouseClick("right", $gX, $gY, 1, 4)
  1191.         $IDitemX = $IDitemX & $gX & "|"
  1192.         $IDitemY = $IDitemY & $gY & "|"
  1193.         MouseMove(Round(Random(0, 400) * $x_ratio), Round(Random(700, 1080) * $y_ratio), 3) ;Moves mouse out of the way
  1194.         Sleep(Random(3000, 3500))
  1195.         If $count >= 30 Then
  1196.             ExitLoop
  1197.         EndIf
  1198.     WEnd
  1199.     Send($Inventory)
  1200.     $IDitemX = StringLeft($IDitemX, StringLen($IDitemX) - 1)
  1201.     $IDitemY = StringLeft($IDitemY, StringLen($IDitemY) - 1)
  1202.     Sleep(200)
  1203. EndFunc   ;==>Identify
  1204.  
  1205. Func CleanOCR($text)
  1206.     $out = ""
  1207.     For $i = 1 To StringLen($text)
  1208.         $chr = Asc(StringMid($text, $i, 1))
  1209.         If $chr >= 48 And $chr <= 57 Then $out = $out & Chr($chr)
  1210.         If $chr = 79 Then $out = $out & '0'
  1211.     Next
  1212.     Return $out
  1213. EndFunc   ;==>CleanOCR
  1214.  
  1215. Func ClickTab($Tabno)
  1216.     If $Tabno = 1 Then RandClick("left", Round(517 * $x_ratio), Round(229 * $y_ratio), 3, 4)
  1217.     If $Tabno = 2 Then RandClick("left", Round(517 * $x_ratio), Round(361 * $y_ratio), 3, 4)
  1218.     If $Tabno = 3 Then RandClick("left", Round(517 * $x_ratio), Round(486 * $y_ratio), 3, 4)
  1219.     Sleep(Random(100, 200))
  1220.  
  1221. EndFunc   ;==>ClickTab
  1222.  
  1223. Func UseNextTab()
  1224.  
  1225.     If $ItemTab = $NextItemTab Then
  1226.         Call("AddLog", "Second Stash full Using Last tab")
  1227.         $ItemTab = $FinalItemTab
  1228.     ElseIf $ItemTab = $FinalItemTab Then
  1229.         Call("AddLog", "Stash full, disabling stashing and magic looting")
  1230.         $StashLegendary = False
  1231.         $StashRare = False
  1232.         $StashMagic = False
  1233.         $LootMagic = False
  1234.     Else
  1235.         Call("AddLog", "Stash full Using next tab")
  1236.         $ItemTab = $NextItemTab
  1237.     EndIf
  1238.    
  1239. EndFunc   ;==>UseNextTab
  1240.  
  1241. Func AddLog($logtxt)
  1242.     Local $file = FileOpen(@ScriptName & ".txt", 1)
  1243.     $msg = @MDAY & '/' & @MON & '/' & @YEAR & ' ' & @HOUR & ':' & @MIN & ':' & @SEC & ': ' & $logtxt & @CRLF
  1244.     FileWrite($file, $msg)
  1245.     FileClose($file)
  1246.     ConsoleWrite($msg)
  1247. EndFunc   ;==>AddLog
  1248.  
  1249.  
  1250. ;Helper Functions
  1251. Func EnhancedFind($x1 = 0, $y1 = 0, $x2 = 577, $y2 = 220, $xpos = 367, $ypos = 135, $recov = False)
  1252.  
  1253.     For $retry = 1 To 3
  1254.         ; take 2 snapshots and black out everything that did not change
  1255.         FFSnapShot($x1 * $x_ratio, $y1 * $y_ratio, $x2 * $x_ratio, $y2 * $y_ratio, 2)
  1256.         Sleep(50)
  1257.         FFSnapShot($x1 * $x_ratio, $y1 * $y_ratio, $x2 * $x_ratio, $y2 * $y_ratio, 3)
  1258.         FFKeepChanges(3, 2, 25)
  1259.         ;FFSaveBMP("CellarOpen_" & @HOUR & @MIN & @SEC, false) ->uncomment if you wanna see  the cellar minimap motion map
  1260.  
  1261.         ; do special search for the color in our motionmap
  1262.         Local $aColorArray[3] = [0x7897EB, 0x404E9E, 0x536CB6]
  1263.         FFAddColor($aColorArray) ; add color to find array
  1264.         ;Func FFBestSpot($SizeSearch, $MinNbPixel, $OptNbPixel, $PosX, $PosY, $Color, $ShadeVariation = 0, $ForceNewSnap = True, $Left = 0, $Top = 0, $Right = 0, $Bottom = 0, $NoSnapShot = $FFLastSnap, $WindowHandle = -1)
  1265.         Local $cellarCoords = FFBestSpot(10, 1, 4, $xpos * $x_ratio, $ypos * $y_ratio, -1, 25, False) ; search for the opening
  1266.        
  1267.         If @error Or Not IsArray($cellarCoords) Then
  1268.             Call("AddLog", "The motionmap failed on try " & $retry & " with code " & @error)
  1269.             FFResetColors()
  1270.         Else
  1271.             ExitLoop
  1272.         EndIf
  1273.  
  1274.     Next
  1275.  
  1276.     If (Not @error) And IsArray($cellarCoords) Then
  1277.         FFResetColors()
  1278.         If Not $recov Then GUICtrlSetData($lblStatus, "Status: Cellar - Found position " & $cellarCoords[0] * $x_ratio & ", " & $cellarCoords[1] * $y_ratio)
  1279.         If Not $recov Then Call("AddLog", "Cellar - Found position " & $cellarCoords[0] * $x_ratio & ", " & $cellarCoords[1] * $y_ratio)
  1280.     Else
  1281.         If $TakeMissShots Then
  1282.             CaptureToTIFF("", "", "", "shots\NoCell_" & String($run) & ".tif", 1, 0, 0, 0, 0)
  1283.         EndIf
  1284.         Dim $cellarCoords[2]
  1285.         $cellarCoords[0] = 1000 * $x_ratio
  1286.         $cellarCoords[1] = 500 * $y_ratio
  1287.     EndIf
  1288.    
  1289.     Return $cellarCoords
  1290.    
  1291. EndFunc   ;==>EnhancedFind
  1292.  
  1293. Func SetupGUI()
  1294.     $frmBot = GUICreate($title & $ver & " - Updating", 290, 140, Round(1580 * $x_ratio), Round(900 * $y_ratio), -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW), 0)
  1295.     GUISetBkColor(0xC0C0C0)
  1296.     $lblRun = GUICtrlCreateLabel("Run Number: 0 - Runs till vendor: 0", 4, 0, 280, 24)
  1297.     GUICtrlSetFont(-1, 10, 600, 0, "Segoe UI")
  1298.     GUICtrlSetColor(-1, 0xFF0000)
  1299.     $lblLocation = GUICtrlCreateLabel("Location: Main Menu", 12, 20, 240, 17)
  1300.     $lblStatus = GUICtrlCreateLabel("Status: ", 12, 35, 240, 17)
  1301.     $lblLast = GUICtrlCreateLabel("Last Runtime: 0 seconds", 12, 50, 240, 17)
  1302.     $lblRuntime = GUICtrlCreateLabel("Total Runtime: 0 hours, 0 minutes", 12, 65, 240, 17)
  1303.     $lblGear = GUICtrlCreateLabel("Legendary: 0 - Set: 0 - Rare: 0", 12, 80, 240, 17)
  1304.     $lblItems = GUICtrlCreateLabel("Magic: 0 - Gems: 0 - Tomes: 0", 12, 95, 240, 17)
  1305.     $lblGold = GUICtrlCreateLabel("Gold: 0", 12, 110, 240, 17)
  1306.     GUISetState(@SW_SHOW)
  1307. EndFunc   ;==>SetupGUI
  1308.  
  1309.  
  1310. Func CheckDead()
  1311.     $LogoutTimerCancel = PixelSearch(Round(900 * $x_ratio), Round(240 * $y_ratio), Round(1010 * $x_ratio), Round(290 * $y_ratio), 0x993827) ; checks for cancel button on logout timer
  1312.     If Not @error Then
  1313.        
  1314.         Call("AddLog", "Logged out")
  1315.         GUICtrlSetData($lblStatus, "Status: Logging out")
  1316.         CheckFor("MainMenu", "", Round(40 * $x_ratio), Round(300 * $y_ratio), Round(400 * $x_ratio), Round(450 * $y_ratio), $loadtime / 1000)
  1317.  
  1318.         Return 1
  1319.     EndIf
  1320.  
  1321.     $CloseButton = PixelSearch(Round(1570 * $x_ratio), Round(110 * $y_ratio), Round(1590 * $x_ratio), Round(120 * $y_ratio), 0x8C2300) ; checks for the red color of the "X" on an open window
  1322.     If Not @error Then
  1323.         GUICtrlSetData($lblStatus, "Status: Open Window")
  1324.         Call("AddLog", "Open Window")
  1325.         Sleep(200)
  1326.         Send("{SPACE}") ;close any open windows
  1327.         Return 1
  1328.     EndIf
  1329.     $YouHaveDied = PixelSearch(Round(620 * $x_ratio), Round(325 * $y_ratio), Round(625 * $x_ratio), Round(330 * $y_ratio), 0xFFFFFF) ; checks for white text "YOU HAVE DIED"
  1330.     If Not @error Then
  1331.         GUICtrlSetData($lblStatus, "Status: Dead")
  1332.         Call("AddLog", "You have died")
  1333.         $deathCount += 1
  1334.         Call("LeaveGame")
  1335.         For $c = 1 To 110 + $loadtime / 100
  1336.             Sleep(100)
  1337.             If CheckFor("MainMenu", "", Round(40 * $x_ratio), Round(300 * $y_ratio), Round(400 * $x_ratio), Round(450 * $y_ratio), 0.1) Then ExitLoop
  1338.         Next
  1339.         Return 1
  1340.     Else
  1341.         Return 0
  1342.     EndIf
  1343. EndFunc   ;==>CheckDead
  1344.  
  1345. Func CheckRepair()
  1346.     $RepairArea = PixelSearch(Round(1480 * $x_ratio), 0, Round(1570 * $x_ratio), Round(100 * $y_ratio), $yellow)
  1347.     If Not @error Then
  1348.         Call("DoRepair")
  1349.     EndIf
  1350.     $RepairAreaRed = PixelSearch(Round(1480 * $x_ratio), 0, Round(1570 * $x_ratio), Round(100 * $y_ratio), $red)
  1351.     If Not @error Then
  1352.         Call("DoRepair")
  1353.     EndIf
  1354. EndFunc   ;==>CheckRepair
  1355.  
  1356. Func DoRepair()
  1357.     Sleep(Random(75, 150))
  1358.     Call("TownPortal")
  1359.     If CheckDead() Then
  1360.         Return
  1361.     EndIf
  1362.     If CheckFor("NewTristram", "Area") Then
  1363.         RandClick("left", Round(1480 * $x_ratio), Round(281 * $y_ratio), 1, 1) ;begin movement towards merchant
  1364.         WalkTime(Round(1480 * $x_ratio), Round(281 * $y_ratio))
  1365.         RandClick("left", Round(1316 * $x_ratio), Round(206 * $y_ratio), 1, 1) ;moves to get merchant in screen
  1366.         WalkTime(Round(1316 * $x_ratio), Round(206 * $y_ratio))
  1367.         RandClick("left", Round(845 * $x_ratio), Round(225 * $y_ratio), 1, 1) ;NPC Merchant to the right of cain's home
  1368.         Sleep(1200)
  1369.         RandClick("left", Round(521 * $x_ratio), Round(506 * $y_ratio), 1, 1) ;button to open up repair menu
  1370.         Sleep(400)
  1371.         RandClick("left", Round(260 * $x_ratio), Round(595 * $y_ratio), 1, 1) ;button to pay for repairs
  1372.         Sleep(200)
  1373.         Send("{Escape}")
  1374.         Call("AddLog", "Repair")
  1375.         If Not CheckDead() Then
  1376.             Call("LeaveGame")
  1377.         EndIf
  1378.     EndIf
  1379. EndFunc   ;==>DoRepair
  1380.  
  1381. Func CalcTime()
  1382.     $srt = TimerDiff($rt)
  1383.     GUICtrlSetData($lblLast, "Last Runtime: " & Round($srt / 1000, 2) & "s. Open/Close: " & $OpenCount & "/" & $CloseCount & ": " & Round($OpenCount / ($OpenCount + $CloseCount) * 100) & "%, Fail: " & $FailCount)
  1384.     $trt = TimerDiff($t)
  1385.     $total = Round((($trt / 1000) / 60) / 60, 4)
  1386.  
  1387.     Call("AddLog", "Last Runtime: " & Round($srt / 1000, 2) & " seconds. Open/Close: " & $OpenCount & "/" & $CloseCount & ", Fail: " & $FailCount)
  1388.  
  1389.     ;Total runtime calculation.
  1390.     $hours = Floor((($trt / 1000) / 60) / 60)
  1391.     $minutes = (($trt / 1000) / 60)
  1392.     ;trim minutes if runtime is more then 1 hour.
  1393.     If $minutes > 60 Then
  1394.         While $minutes > 60
  1395.             $minutes -= 60
  1396.         WEnd
  1397.     EndIf
  1398.     GUICtrlSetData($lblRuntime, "Runtime: " & $hours & ":" & Ceiling($minutes) & ", GPH: " & Round(Ceiling((Number($mon) - $monstart) / ($trt / 3600000)) / 1000) & "K")
  1399. EndFunc   ;==>CalcTime
  1400.  
  1401.  
  1402. Func ClickItems($color, $tolerance, $checkfull = False, $max = 30)
  1403.     $c = 0
  1404.     While $c < $max
  1405.         RandMove(1200 * $x_ratio, 600 * $y_ratio, 5, 5, 2)
  1406.         Sleep(Random(60, 120))
  1407.         $StashPixel = PixelSearch(1400 * $x_ratio, 580 * $y_ratio, 1914 * $x_ratio, 888 * $y_ratio, $color, $tolerance)
  1408.         If Not @error Then
  1409.             MouseClick("right", $StashPixel[0], $StashPixel[1], 1, 4)
  1410.             $c += 1
  1411.             If $checkfull Then
  1412.                 $numstashed += 1
  1413.             Else
  1414.                 $numsold += 1
  1415.             EndIf
  1416.         Else
  1417.             ExitLoop
  1418.         EndIf
  1419.     WEnd
  1420.     Sleep(Random(60, 120))
  1421.     If $checkfull Then
  1422.         If $c = $max Then Call("UseNextTab")
  1423.         ClickTab($ItemTab)
  1424.     EndIf
  1425. EndFunc   ;==>ClickItems
  1426.  
  1427. Func ClickImage($image, $tolerance, $max = 20)
  1428.     For $c = 1 To $max
  1429.         RandMove(1200 * $x_ratio, 600 * $y_ratio, 5, 5, 2)
  1430.         Sleep(Random(100, 300))
  1431.         If _ImageSearchArea($pngLoc & $image, 1, 1400 * $x_ratio, 580 * $y_ratio, 1914 * $x_ratio, 888 * $y_ratio, $gX, $gY, $tolerance) Then
  1432.             MouseClick("right", $gX, $gY, 1, 4)
  1433.             Sleep(120)
  1434.         Else
  1435.             ExitLoop
  1436.         EndIf
  1437.     Next
  1438. EndFunc   ;==>ClickImage
  1439.  
  1440. Func SalvageLoot()
  1441.  
  1442.     DoSprint()
  1443.  
  1444.     GUICtrlSetData($lblStatus, "Status: Salvaging Items")
  1445.     Sleep(Random(300, 500))
  1446.     MouseClick("middle", 1786 * $x_ratio, 535 * $y_ratio)
  1447.     walktime(1786 * $x_ratio, 535 * $y_ratio, 100)
  1448.     ;Sleep(2000)
  1449.     MouseClick("left", 1430 * $x_ratio, 390 * $y_ratio) ;Talk to anvil
  1450.     ;Sleep(3000)
  1451.     walktime(1430 * $x_ratio, 390 * $y_ratio, 100)
  1452.  
  1453.     $c = 0
  1454.     While $c <= 20
  1455.         Sleep(Random(200, 300))
  1456.         $MagicPixel = PixelSearch(1400 * $x_ratio, 580 * $y_ratio, 1914 * $x_ratio, 830 * $y_ratio, 0x182037, 1)
  1457.         If Not @error Then
  1458.             MouseClick("left", 265 * $x_ratio, 291 * $y_ratio, 1, 4)
  1459.             Sleep(Random(200, 300))
  1460.             MouseClick("left", $MagicPixel[0], $MagicPixel[1], 1, 4)
  1461.             Sleep(Random(200, 300))
  1462.             MouseClick("left", 1072 * $x_ratio, 375 * $y_ratio, 1, 4)
  1463.             RandMove(1200 * $x_ratio, 600 * $y_ratio, 5, 5, 2)
  1464.             Sleep(40)
  1465.             $c += 1
  1466.         Else
  1467.             ExitLoop
  1468.         EndIf
  1469.     WEnd
  1470.     Call("AddLog", "Salvaged Items: " & $c)
  1471.  
  1472.     Send("{ESCAPE}")
  1473.     Sleep(Random(300, 500))
  1474. EndFunc   ;==>SalvageLoot
  1475.  
  1476. Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance)
  1477.     If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $findImage
  1478.     $findImage = "*TRANSBLACK " & $findImage
  1479.     If @AutoItX64 Then
  1480.         $result = DllCall("ImageSearchDLL_x64.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage)
  1481.     Else
  1482.         $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage)
  1483.     EndIf
  1484.     If $result = "0" Then
  1485.         Return 0
  1486.     EndIf
  1487.  
  1488.     ; Otherwise get the x,y location of the match and the size of the image to
  1489.     ; compute the centre of search
  1490.     $array = StringSplit($result[0], "|")
  1491.     If (UBound($array) >= 4) Then
  1492.         $x = Int(Number($array[2]))
  1493.         $y = Int(Number($array[3]))
  1494.         If $resultPosition = 1 Then
  1495.             $x = $x + Int(Number($array[4]) / 2)
  1496.             $y = $y + Int(Number($array[5]) / 2)
  1497.         EndIf
  1498.         Return 1
  1499.     EndIf
  1500. EndFunc   ;==>_ImageSearchArea
  1501.  
  1502. Func LeaveGame()
  1503.  
  1504.     If CheckFor("MainMenu", "", Round(40 * $x_ratio), Round(300 * $y_ratio), Round(400 * $x_ratio), Round(450 * $y_ratio), .5) Then Return
  1505.     Call("RandSleep")
  1506.     GUICtrlSetData($lblStatus, "Status: Leaving Game")
  1507.     Send("{Escape}")
  1508.     Sleep(200)
  1509.     RandClick("left", Round(956 * $x_ratio), Round(579 * $y_ratio), 120, 20) ;Random Click on the leave button
  1510.     Call("CalcTime")
  1511.     CheckFor("MainMenu", "", Round(40 * $x_ratio), Round(300 * $y_ratio), Round(400 * $x_ratio), Round(450 * $y_ratio), $loadtime / 1000)
  1512. EndFunc   ;==>LeaveGame
  1513.  
  1514. Func TownPortalShort()
  1515.  
  1516.     $gX = 0
  1517.     $gY = 0
  1518.     $c = 0
  1519.     GUICtrlSetData($lblStatus, "Status: Waiting for TP bar")
  1520.     Do
  1521.         $c += 1
  1522.         Sleep(200)
  1523.         If $c > 4 Then Return
  1524.     Until _ImageSearchArea($pngLoc & "TP.png", 1, 600, 200, 1000, 500, $gX, $gY, 50)
  1525.  
  1526.     $seconds = $TPProtectTime
  1527.     $c = 0
  1528.  
  1529.     Do
  1530.         $c += 1
  1531.         GUICtrlSetData($lblStatus, "Status: Prepared for inturrupt, " & $seconds * 5 - $c)
  1532.         Sleep(200)
  1533.         If $c > ($seconds * 5) Then ;Make sure we never get stuck here for infinity.
  1534.             GUICtrlSetData($lblStatus, "Status: safe, doing long wait for town")
  1535.             Sleep($tptime - $seconds * 1000 - 1200)
  1536.             GUICtrlSetData($lblStatus, "Status: detecting town")
  1537.             CheckFor("NewTristram", "Area")
  1538.             Sleep(300)
  1539.             Return
  1540.         EndIf
  1541.     Until Not _ImageSearchArea($pngLoc & "TP.png", 1, 600, 200, 1000, 500, $gX, $gY, 50)
  1542.  
  1543. EndFunc   ;==>TownPortalShort
  1544.  
  1545. Func Moving($time)
  1546.     Sleep($time / $movementSpeed)
  1547. EndFunc   ;==>Moving
  1548.  
  1549. Func TownPortal()
  1550.  
  1551.     GUICtrlSetData($lblStatus, "Status: Returning to Town")
  1552.     Send($TownPortalButton)
  1553.    
  1554.     If $DetectTPFail Then
  1555.         Call("TownPortalShort")
  1556.     Else
  1557.         CheckFor("NewTristram", "Area", 0, 0, 0, 0, ($tptime + 500) / 1000)
  1558.     EndIf
  1559.    
  1560. EndFunc   ;==>TownPortal
  1561.  
  1562. #region OtherStuff
  1563.  
  1564. Func RandClick($clickType, $xpos, $ypos, $xOff = 10, $yOff = 10, $clicks = 1, $speed = 4)
  1565.     If $xOff < 1 Then $xOff = 1
  1566.     If $yOff < 1 Then $yOff = 1
  1567.     $randX = Round(Random($xpos - ($xOff * $x_ratio), $xpos + ($xOff * $x_ratio)))
  1568.     $randY = Round(Random($ypos - ($yOff * $y_ratio), $ypos + ($yOff * $y_ratio)))
  1569.     MouseClick($clickType, $randX, $randY, $clicks, $speed)
  1570. EndFunc   ;==>RandClick
  1571.  
  1572. Func RandMove($xpos, $ypos, $xOff = 10, $yOff = 10, $speed = 1)
  1573.     $randX = Round(Random($xpos - ($xOff * $x_ratio), $xpos + ($xOff * $x_ratio)))
  1574.     $randY = Round(Random($ypos - ($yOff * $y_ratio), $ypos + ($yOff * $y_ratio)))
  1575.     MouseMove($randX, $randY, $speed)
  1576. EndFunc   ;==>RandMove
  1577.  
  1578. Func RandSleep($min = 5, $max = 45, $chance = 3)
  1579.     $randNum = Round(Random(1, 100))
  1580.     If $Timer And $randNum <= $chance Then
  1581.         $sleepTime = Random($min * 1000, $max * 1000)
  1582.         GUICtrlSetData($lblStatus, "Status: Random Sleep - " & Round($sleepTime / 1000) & " secs")
  1583.         For $c = 0 To 10
  1584.             Sleep($sleepTime / 10)
  1585.         Next
  1586.     EndIf
  1587. EndFunc   ;==>RandSleep
  1588. ;Hotkey Functions
  1589.  
  1590. Func Begin()
  1591.     $Go = Not $Go
  1592.     If Not $Go Then WinSetTitle($title, "", $title & $ver & " - Halted")
  1593. EndFunc   ;==>Begin
  1594.  
  1595. Func TogglePause()
  1596.     $Paused = Not $Paused
  1597.     While $Paused
  1598.         Sleep(100)
  1599.         WinSetTitle($title, "", $title & $ver & " - Paused")
  1600.         ToolTip('[PAUSED] - Deaths: ' & $deathCount & ' | Cellars: ' & $cellarCount, 0, 0)
  1601.     WEnd
  1602.     WinSetTitle($title, "", $title & $ver & " - Running")
  1603.     ToolTip("")
  1604. EndFunc   ;==>TogglePause
  1605.  
  1606. Func ShowLoot()
  1607.     GUICtrlSetData($lblGear, "Legendary: " & $LegendaryCount & " - Set: " & $SetCount & " - Rare: " & $RareCount)
  1608.     GUICtrlSetData($lblItems, "Magic: " & $MagicCount & " - Gems: " & $GemCount & " - Tomes: " & $TomeCount)
  1609. EndFunc   ;==>ShowLoot
  1610.  
  1611. Func Stop() ;to allow the script to stop
  1612.     ;Time Function
  1613.     $trt = TimerDiff($t)
  1614.     $hours = Floor((($trt / 1000) / 60) / 60)
  1615.     $minutes = (($trt / 1000) / 60)
  1616.     $sec = ($trt / 1000)
  1617.     If $minutes > 60 Then
  1618.         While $minutes > 60
  1619.             $minutes -= 60
  1620.         WEnd
  1621.     EndIf
  1622.     If $sec > 60 Then
  1623.         While $sec > 60
  1624.             $sec -= 60
  1625.         WEnd
  1626.     EndIf
  1627.     ;Gold Function
  1628.     $mondelt = Number($mon) - Number($monold)
  1629.     If $monstart = 0 Then $monstart = Number($mon) - $mondelt
  1630.     ;Item Function
  1631.     $Totalpick = $LegendaryCount + $SetCount + $RareCount + $MagicCount
  1632.     ;Log Printer
  1633.     Call("AddLog", "=============== iLog Zummarizer Start xD ===============")
  1634.     Call("AddLog", 'Total Runtime: ' & $hours & ":" & Ceiling($minutes) & ":" & Ceiling($sec))
  1635.     Call("AddLog", '=================================================')
  1636.     Call("AddLog", 'Current Gold: ' & $mon & ", Total Gold Gain: " & Number($mon) - $monstart)
  1637.     Call("AddLog", 'Gold Per Hour: ' & Ceiling((Number($mon) - $monstart) / ($trt / 3600000)) & ', Gold Per Trip: ' & Ceiling((Number($mon) - $monstart) / $run))
  1638.     Call("AddLog", 'Total Items Pick: ' & $Totalpick & ', Per Hour: ' & Ceiling(($Totalpick) / ($trt / 3600000)) & ', Per Trip: ' & $Totalpick / $cellarCount)
  1639.     ;enable these 4 lines below if you wants detailed item picks
  1640.     ;Call("AddLog", 'Total Items Pick: ' & $LegendaryCount & ', Per Hour: ' & Ceiling(($LegendaryCount) / ($trt / 3600000)) & ', Per Trip: ' & $LegendaryCount / $cellarCount)
  1641.     ;Call("AddLog", 'Total Items Pick: ' & $SetCount & ', Per Hour: ' & Ceiling(($SetCount) / ($trt / 3600000)) & ', Per Trip: ' & $SetCount / $cellarCount)
  1642.     ;Call("AddLog", 'Total Items Pick: ' & $RareCount & ', Per Hour: ' & Ceiling(($RareCount) / ($trt / 3600000)) & ', Per Trip: ' & $RareCount / $cellarCount)
  1643.     ;Call("AddLog", 'Total Items Pick: ' & $MagicCount & ', Per Hour: ' & Ceiling(($MagicCount) / ($trt / 3600000)) & ', Per Trip: ' & $MagicCount / $cellarCount)
  1644.     ;more stuff soon
  1645.     Call("AddLog", 'Total Gems Pick: ' & $GemCount & ', Per Hour: ' & Ceiling(($GemCount) / ($trt / 3600000)) & ', Per Trip: ' & $GemCount / $cellarCount)
  1646.     Call("AddLog", 'Total Tomes Pick: ' & $TomeCount & ', Per Hour: ' & Ceiling(($TomeCount) / ($trt / 3600000)) & ', Per Trip: ' & $TomeCount / $cellarCount)
  1647.     Call("AddLog", '=================================================')
  1648.     Call("AddLog", 'Cellar freq. (success/total runs): ' & $cellarCount & '/' & $run & ' = ' & ($cellarCount / $run) * 100 & ' %')
  1649.     Call("AddLog", 'Trips Per Hour: ' & ((Number($run)) / ($trt / 3600000)) & ', Success runs: ' & $cellarCount & ', Fail runs: ' & Number($run) - $cellarCount)
  1650.     Call("AddLog", '=================================================')
  1651.     Call("AddLog", 'Deaths total: ' & $deathCount & ', Deaths Per Hour: ' & Number($deathCount) / ($trt / 3600000))
  1652.     Call("AddLog", "=============== End of Log Summary ===============")
  1653.     Exit
  1654. EndFunc   ;==>Stop
  1655. Func GoTown()
  1656.     $mLootIn = 1
  1657. EndFunc   ;==>GoTown
  1658.  
  1659. Func AnalyseLoots() ; Grid search + ilvl detection, a little bit slower than old method but computes db for fast stashing/vendoring/new salvaging
  1660.     ;ConsoleWrite("---- NEW ANALYSIS ----" & @crlf)
  1661.     $str_Stash = ""
  1662.     $str_StashGems = ""
  1663.     $str_StashMisc = ""
  1664.     $str_Vendor = ""
  1665.     $str_Salvage = ""
  1666.     $int_TownPosition = 0
  1667.     $int_emptygrid = 0
  1668.     $str_Ignore = ""
  1669.     $nX = 0
  1670.     $nY = 0
  1671.     GUICtrlSetData($lblStatus, "Status: Analysing loots")
  1672.     Send($Inventory)
  1673.     Sleep(500)
  1674.     For $y = 0 To 5
  1675.         $int_emptygrid = 0
  1676.         MouseMove(1435, Round(609 + (45 * $y)), 1)
  1677.         Sleep(500)
  1678.         For $x = 0 To 9
  1679.             If StringInStr($str_Ignore, 1435 + (48 * $x) & "," & 609 + (45 * $y)) Then ContinueLoop
  1680.             MouseMove(1435 + (48 * $x), 609 + (45 * $y), 1)
  1681.             Sleep(300)
  1682.             If _ImageSearchArea($pngLoc & "tt_check.png", 0, Round((1435 + (48 * $x) - 455) * $x_ratio), Round((609 + (45 * $y) - 500) * $y_ratio), Round((1435 + (48 * $x) - 35) * $x_ratio), Round(1080 * $y_ratio), $gX, $gY, 10) Then ; If tooltip exists
  1683.                 $int_emptygrid = 0
  1684.                 If _ImageSearchArea($pngLoc & "tt_unidentified.png", 0, $gX, $gY, $gX + 425, $gY + 70, $gX, $gY, 40) And $Identify Then ; Identify items.
  1685.                     MouseClick("secondary")
  1686.                     Sleep(Random(3000, 3500, 1))
  1687.                 EndIf
  1688.                 If _ImageSearchArea($pngLoc & "tt_square.png", 0, $gX, $gY, $gX + 425, $gY + 70, $gX, $gY, 40) Then ; Gem, automatic stashing.
  1689.                     $str_StashGems = $str_StashGems & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1690.                     ContinueLoop
  1691.                 EndIf
  1692.                 If _ImageSearchArea($pngLoc & "tt_tome.png", 0, $gX, $gY, $gX + 425, $gY + 70, $gX, $gY, 40) Then ; Tome, automatic stashing.
  1693.                     $str_StashMisc = $str_StashMisc & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1694.                     ContinueLoop
  1695.                 EndIf
  1696.                 If _ImageSearchArea($pngLoc & "tt_exquisite.png", 0, $gX, $gY, $gX + 425, $gY + 70, $gX, $gY, 40) Then ; Crafting, automatic stashing.
  1697.                     $str_StashMisc = $str_StashMisc & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1698.                     ContinueLoop
  1699.                 EndIf
  1700.                 If _ImageSearchArea($pngLoc & "tt_iridescent.png", 0, $gX, $gY, $gX + 425, $gY + 70, $gX, $gY, 40) Then ; Crafting, automatic stashing.
  1701.                     $str_StashMisc = $str_StashMisc & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1702.                     ContinueLoop
  1703.                 EndIf
  1704.                 If _ImageSearchArea($pngLoc & "tt_fiery.png", 0, $gX, $gY, $gX + 425, $gY + 70, $gX, $gY, 40) Then ; Crafting, automatic stashing (faster than the pixel detection below).
  1705.                     $str_StashMisc = $str_StashMisc & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1706.                     ContinueLoop
  1707.                 EndIf
  1708.                 If _ImageSearchArea($pngLoc & "tt_plan.png", 0, $gX, $gY, $gX + 425, $gY + 70, $gX, $gY, 60) Then ; Plans, automatic stashing.
  1709.                     $str_StashMisc = $str_StashMisc & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1710.                     ContinueLoop
  1711.                 EndIf
  1712.                 If _ImageSearchArea($pngLoc & "tt_neck.png", 0, $gX + 320, $gY + 60, $gX + 425, $gY + 150, $nX, $nY, 60) == 0 And _ImageSearchArea($pngLoc & "tt_waist.png", 0, $gX + 320, $gY + 60, $gX + 425, $gY + 150, $nX, $nY, 60) == 0 And _ImageSearchArea($pngLoc & "tt_finger.png", 0, $gX + 320, $gY + 60, $gX + 425, $gY + 150, $nX, $nY, 60) == 0 And _ImageSearchArea($pngLoc & "tt_follower.png", 0, $gX + 320, $gY + 60, $gX + 425, $gY + 150, $nX, $nY, 60) == 0 Then
  1713.                     $str_Ignore = $str_Ignore & "|" & 1435 + (48 * $x) & "," & 609 + (45 * ($y + 1))
  1714.                 EndIf
  1715.                 $tt_title = PixelSearch($gX, $gY, $gX + 425, $gY + 70, 0x00FF00, 1) ; Set, no ilvl check since they drop rarely. Goes to stash.
  1716.                 If Not @error Then
  1717.                     $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1718.                     ContinueLoop
  1719.                 EndIf
  1720.                 $tt_title = PixelSearch($gX, $gY, $gX + 425, $gY + 70, 0xBF642F, 1) ; Legendary, no ilvl check since they drop rarely. Goes to stash.
  1721.                 If Not @error Then
  1722.                     $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1723.                     ContinueLoop
  1724.                 EndIf
  1725.                 $tt_title = PixelSearch($gX, $gY, $gX + 425, $gY + 70, 0xFFFF00, 1) ; Rare
  1726.                 If Not @error Then
  1727.                     If _ImageSearchArea($pngLoc & "ilvl59.png", 0, $gX, $gY, $gX + 125, Round(1080 * $y_ratio), $gX, $gY, 20) Then ; Rare ilvl 59
  1728.                         If (getOption("i59r") == 1) Then
  1729.                             $str_Salvage = $str_Salvage & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y) & ",r"
  1730.                         ElseIf (getOption("i59r") == 2) Then
  1731.                             $str_Vendor = $str_Vendor & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y) & ",r"
  1732.                         Else
  1733.                             $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y) & ",r"
  1734.                         EndIf
  1735.                         ContinueLoop
  1736.                     EndIf
  1737.                     If _ImageSearchArea($pngLoc & "ilvl60.png", 0, $gX, $gY, $gX + 125, Round(1080 * $y_ratio), $gX, $gY, 20) Then ; Rare ilvl 60,  goes to salvage
  1738.                         If (getOption("i60r") == 1) Then
  1739.                             $str_Salvage = $str_Salvage & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y) & ",r"
  1740.                         ElseIf (getOption("i60r") == 2) Then
  1741.                             $str_Vendor = $str_Vendor & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y) & ",r"
  1742.                         Else
  1743.                             $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y) & ",r"
  1744.                         EndIf
  1745.                         ContinueLoop
  1746.                     EndIf
  1747.                     If _ImageSearchArea($pngLoc & "ilvl61.png", 0, $gX, $gY, $gX + 125, Round(1080 * $y_ratio), $gX, $gY, 20) Then ; Rare ilvl 61,  goes to salvage
  1748.                         If (getOption("i61r") == 1) Then
  1749.                             $str_Salvage = $str_Salvage & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y) & ",r"
  1750.                         ElseIf (getOption("i61r") == 2) Then
  1751.                             $str_Vendor = $str_Vendor & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y) & ",r"
  1752.                         Else
  1753.                             $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y) & ",r"
  1754.                         EndIf
  1755.                         ContinueLoop
  1756.                     EndIf
  1757.                     If _ImageSearchArea($pngLoc & "ilvl62.png", 0, $gX, $gY, $gX + 125, Round(1080 * $y_ratio), $gX, $gY, 20) Then ; Rare ilvl 62,  goes to salvage
  1758.                         If (getOption("i62r") == 1) Then
  1759.                             $str_Salvage = $str_Salvage & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y) & ",r"
  1760.                         ElseIf (getOption("i62r") == 2) Then
  1761.                             $str_Vendor = $str_Vendor & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y) & ",r"
  1762.                         Else
  1763.                             $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y) & ",r"
  1764.                         EndIf
  1765.                         ContinueLoop
  1766.                     EndIf
  1767.                     If _ImageSearchArea($pngLoc & "ilvl63.png", 0, $gX, $gY, $gX + 125, Round(1080 * $y_ratio), $gX, $gY, 20) Then ; Rare ilvl 63,  goes to stash
  1768.                         If (getOption("i63r") == 1) Then
  1769.                             $str_Salvage = $str_Salvage & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1770.                         ElseIf (getOption("i63r") == 2) Then
  1771.                             $str_Vendor = $str_Vendor & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1772.                         Else
  1773.                             $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1774.                         EndIf
  1775.                         ContinueLoop
  1776.                     EndIf
  1777.                     ; Below ilvl 59
  1778.                     If $StashRare Then
  1779.                         $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1780.                     ElseIf $VendorRare Then
  1781.                         $str_Vendor = $str_Vendor & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1782.                     Else
  1783.                         $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1784.                     EndIf
  1785.                     ContinueLoop
  1786.                 EndIf
  1787.                
  1788.                 $tt_title = PixelSearch($gX, $gY, $gX + 425, $gY + 40, 0xFF0000, 1) ; unusable rares, legendaries & sets. Goes to stash.
  1789.                 If Not @error Then
  1790.                     $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1791.                     ContinueLoop
  1792.                 EndIf
  1793.                
  1794.                 $tt_title = PixelSearch($gX, $gY, $gX + 425, $gY + 70, 0x6969FF, 1) ; Magic
  1795.                 If Not @error Then
  1796.                     If _ImageSearchArea($pngLoc & "ilvl59.png", 0, $gX, $gY, $gX + 125, Round(1080 * $y_ratio), $gX, $gY, 20) Then ; Magic ilvl 59
  1797.                         If (getOption("i59m") == 1) Then
  1798.                             $str_Salvage = $str_Salvage & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1799.                         ElseIf (getOption("i59m") == 2) Then
  1800.                             $str_Vendor = $str_Vendor & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1801.                         Else
  1802.                             $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1803.                         EndIf
  1804.                         ContinueLoop
  1805.                     EndIf
  1806.                     If _ImageSearchArea($pngLoc & "ilvl60.png", 0, $gX, $gY, $gX + 125, Round(1080 * $y_ratio), $gX, $gY, 20) Then ; Magic ilvl 60, goes to salvage
  1807.                         If (getOption("i60m") == 1) Then
  1808.                             $str_Salvage = $str_Salvage & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1809.                         ElseIf (getOption("i60m") == 2) Then
  1810.                             $str_Vendor = $str_Vendor & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1811.                         Else
  1812.                             $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1813.                         EndIf
  1814.                         ContinueLoop
  1815.                     EndIf
  1816.                     If _ImageSearchArea($pngLoc & "ilvl61.png", 0, $gX, $gY, $gX + 125, Round(1080 * $y_ratio), $gX, $gY, 20) Then ; Magic ilvl 61, goes to salvage
  1817.                         If (getOption("i61m") == 1) Then
  1818.                             $str_Salvage = $str_Salvage & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1819.                         ElseIf (getOption("i61m") == 2) Then
  1820.                             $str_Vendor = $str_Vendor & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1821.                         Else
  1822.                             $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1823.                         EndIf
  1824.                         ContinueLoop
  1825.                     EndIf
  1826.                     If _ImageSearchArea($pngLoc & "ilvl62.png", 0, $gX, $gY, $gX + 125, Round(1080 * $y_ratio), $gX, $gY, 20) Then ; Magic ilvl 62, goes to salvage
  1827.                         If (getOption("i62m") == 1) Then
  1828.                             $str_Salvage = $str_Salvage & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1829.                         ElseIf (getOption("i62m") == 2) Then
  1830.                             $str_Vendor = $str_Vendor & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1831.                         Else
  1832.                             $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1833.                         EndIf
  1834.                         ContinueLoop
  1835.                     EndIf
  1836.                     If _ImageSearchArea($pngLoc & "ilvl63.png", 0, $gX, $gY, $gX + 125, Round(1080 * $y_ratio), $gX, $gY, 20) Then ; Magic ilvl 63, goes to stash
  1837.                         If (getOption("i63m") == 1) Then
  1838.                             $str_Salvage = $str_Salvage & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1839.                         ElseIf (getOption("i63m") == 2) Then
  1840.                             $str_Vendor = $str_Vendor & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1841.                         Else
  1842.                             $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1843.                         EndIf
  1844.                         ContinueLoop
  1845.                     EndIf
  1846.                     ; Below ilvl 59
  1847.                     If $StashMagic Then
  1848.                         $str_Stash = $str_Stash & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1849.                     ElseIf $VendorMagic Then
  1850.                         $str_Vendor = $str_Vendor & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1851.                     Else
  1852.                         $str_Ignore = $str_Ignore & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1853.                     EndIf
  1854.                     ContinueLoop
  1855.                 EndIf
  1856.                 ; Probably white/gray trash bugged pick, add to vendor string
  1857.                 $str_Vendor = $str_Vendor & "|" & 1435 + (48 * $x) & "," & 609 + (45 * $y)
  1858.             Else
  1859.                 $int_emptygrid += 1
  1860.                 If $int_emptygrid == 2 Then ; If there's nothing 2 times in a row in a row (see wut i did thar?), it probably ends here, skip to the next row.
  1861.                     $int_emptygrid = 0
  1862.                     ExitLoop
  1863.                 Else
  1864.                     ContinueLoop
  1865.                 EndIf
  1866.             EndIf
  1867.         Next
  1868.     Next
  1869.     Send($Inventory)
  1870.     Sleep(500)
  1871.     ;Call("AddLog", "Stash gear : "  & $str_Stash )
  1872.     ;Call("AddLog", "Stash misc : "  & $str_StashMisc )
  1873.     ;Call("AddLog", "Stash gems : "  & $str_StashGems )
  1874.     ;Call("AddLog", "Salvage : "  & $str_Salvage )
  1875.     ;Call("AddLog", "Vendor : "  & $str_Vendor )
  1876.     ;Call("AddLog", "Ignored Square : "  & $str_Ignore )
  1877.  
  1878.  
  1879.     Call("AddLog", "Stashed Items: " & UBound(StringSplit($str_Stash, "|")))
  1880.  
  1881.     If $str_Stash <> "" Or $str_StashGems <> "" Or $str_StashMisc <> "" Then Call("StashLoot_new")
  1882.     If $str_Salvage <> "" Then Call("SalvageLoot_new")
  1883.     If $str_Vendor <> "" Then Call("VendorLoot_new")
  1884. EndFunc   ;==>AnalyseLoots
  1885.  
  1886. Func StashLoot_new()
  1887.     $arr_split = ""
  1888.     $pos_split = ""
  1889.     GUICtrlSetData($lblStatus, "Status: Putting Items in Stash")
  1890.     MouseClick("left", 1064 * $x_ratio, 256 * $y_ratio)
  1891.     walktime(1064 * $x_ratio, 256 * $y_ratio, 500)
  1892.     $int_TownPosition = 1
  1893.  
  1894.     ;Gems Page 1
  1895.     If $str_StashGems <> "" Then
  1896.         ClickTab($GemTab)
  1897.         $str_StashGems = StringMid($str_StashGems, 2)
  1898.         $arr_split = StringSplit($str_StashGems, "|")
  1899.         For $i = 1 To $arr_split[0]
  1900.             Sleep(Random(300, 350))
  1901.             $pos_split = StringSplit($arr_split[$i], ",", 2)
  1902.             MouseClick("right", $pos_split[0], $pos_split[1], 1, 3)
  1903.         Next
  1904.     EndIf
  1905.  
  1906.     ;Tomes/Crafting Materials/Plans/Etc Page 2
  1907.     If $str_StashMisc <> "" Then
  1908.         ClickTab($GemTab)
  1909.         $str_StashMisc = StringMid($str_StashMisc, 2)
  1910.         $arr_split = StringSplit($str_StashMisc, "|")
  1911.         For $i = 1 To $arr_split[0]
  1912.             Sleep(Random(300, 350))
  1913.             $pos_split = StringSplit($arr_split[$i], ",", 2)
  1914.             MouseClick("right", $pos_split[0], $pos_split[1], 1, 3)
  1915.         Next
  1916.     EndIf
  1917.  
  1918.     ;Gears Page 2
  1919.     If $str_Stash <> "" Then
  1920.         $str_Stash = StringMid($str_Stash, 2)
  1921.         $arr_split = StringSplit($str_Stash, "|")
  1922.         For $i = 1 To $arr_split[0]
  1923.             Sleep(Random(80, 100))
  1924.             If Random() < 0.5 Then
  1925.                 ClickTab($ItemTab)
  1926.             Else
  1927.                 ClickTab($NextItemTab)
  1928.             EndIf
  1929.            
  1930.             Sleep(Random(300, 350))
  1931.             $pos_split = StringSplit($arr_split[$i], ",", 2)
  1932.             MouseClick("right", $pos_split[0], $pos_split[1], 1, 3)
  1933.         Next
  1934.     EndIf
  1935.  
  1936.     Sleep(Random(100, 150))
  1937.     Send("{SPACE}")
  1938. EndFunc   ;==>StashLoot_new
  1939.  
  1940. Func SalvageLoot_new()
  1941.     $arr_split = ""
  1942.     $pos_split = ""
  1943.     GUICtrlSetData($lblStatus, "Status: Salvaging loots")
  1944.     If $int_TownPosition = 0 Then ; Starting from TP
  1945.         MouseClick("middle", 1582 * $x_ratio, 527 * $y_ratio)
  1946.         walktime(1582 * $x_ratio, 527 * $y_ratio, 500)
  1947.         MouseClick("left", 1661 * $x_ratio, 409 * $y_ratio)
  1948.         walktime(1661 * $x_ratio, 409 * $y_ratio, 500)
  1949.     Else ; Starting from Stash
  1950.         MouseClick("middle", 1484 * $x_ratio, 583 * $y_ratio)
  1951.         walktime(1484 * $x_ratio, 583 * $y_ratio, 500)
  1952.        
  1953.         MouseClick("left", 1773 * $x_ratio, 484 * $y_ratio)
  1954.         walktime(1773 * $x_ratio, 484 * $y_ratio, 500)
  1955.     EndIf
  1956.     $int_TownPosition = 2
  1957.     MouseClick("left", 263 * $x_ratio, 287 * $y_ratio)
  1958.     $str_Salvage = StringMid($str_Salvage, 2)
  1959.     $arr_split = StringSplit($str_Salvage, "|")
  1960.     For $i = 1 To $arr_split[0]
  1961.         Sleep(Random(300, 400))
  1962.         $pos_split = StringSplit($arr_split[$i], ",")
  1963.         MouseClick("left", $pos_split[1], $pos_split[2], 1, 3)
  1964.         If $pos_split[0] == 3 Then
  1965.             Send("{ENTER}")
  1966.             Sleep(1000)
  1967.         EndIf
  1968.     Next
  1969.     Sleep(Random(300, 400))
  1970.     Send("{SPACE}")
  1971. EndFunc   ;==>SalvageLoot_new
  1972.  
  1973. Func VendorLoot_new()
  1974.     $arr_split = ""
  1975.     $pos_split = ""
  1976.     GUICtrlSetData($lblStatus, "Status: Vendoring Items")
  1977.     If $int_TownPosition = 0 Then ; Starting from TP
  1978.         MouseClick("middle", 1565 * $x_ratio, 50 * $y_ratio)
  1979.         WalkTime(1565 * $x_ratio, 50 * $y_ratio, 500)
  1980.     ElseIf $int_TownPosition = 1 Then ; Starting from Stash
  1981.         MouseClick("middle", 1560 * $x_ratio, 120 * $y_ratio)
  1982.         WalkTime(1560 * $x_ratio, 120 * $y_ratio, 500)
  1983.     Else ; Starting from Blacksmith
  1984.         MouseClick("middle", 738 * $x_ratio, 64 * $y_ratio)
  1985.         WalkTime(738 * $x_ratio, 64 * $y_ratio, 500)
  1986.     EndIf
  1987.     MouseClick("left", 1030 * $x_ratio, 210 * $y_ratio) ;Talk to vendor
  1988.     WalkTime(1030 * $x_ratio, 210 * $y_ratio, 500)
  1989.  
  1990.     $str_Vendor = StringMid($str_Vendor, 2)
  1991.     $arr_split = StringSplit($str_Vendor, "|")
  1992.     For $i = 1 To $arr_split[0]
  1993.         Sleep(Random(100, 300))
  1994.         $pos_split = StringSplit($arr_split[$i], ",", 2)
  1995.         MouseClick("right", $pos_split[0], $pos_split[1], 1, 3)
  1996.         If PixelGetColor(819 * $x_ratio, 375 * $y_ratio) == 0x370C00 Then Send("{ENTER}")
  1997.     Next
  1998.     Sleep(Random(100, 200))
  1999.    
  2000.     $mon = _TesseractScreenCapture(0, "", 1, 2, 1454 * $x_ratio, 508 * $y_ratio, (1920 - 1571) * $x_ratio, (1080 - 525) * $y_ratio, 0)
  2001.     $mon = CleanOCR($mon)
  2002.     $mondelt = Number($mon) - Number($monold)
  2003.     GUICtrlSetData($lblGold, "Gold: " & $mon & ", Sold value: " & $mondelt)
  2004.     $monold = $mon
  2005.     Call("AddLog", "Sold Items: " & $arr_split[0] & ", Sold value: " & $mondelt)
  2006.    
  2007.     Sleep(Random(200, 300))
  2008.    
  2009.  
  2010.     RandClick("left", Round(521 * $x_ratio), Round(506 * $y_ratio), 1, 1) ;button to open up repair menu
  2011.     Sleep(200)
  2012.     RandClick("left", Round(260 * $x_ratio), Round(595 * $y_ratio), 1, 1) ;button to pay for repairs
  2013.     Sleep(400)
  2014.    
  2015.     $mon = _TesseractScreenCapture(0, "", 1, 2, 1454 * $x_ratio, 508 * $y_ratio, (1920 - 1571) * $x_ratio, (1080 - 525) * $y_ratio, 0)
  2016.     $mon = CleanOCR($mon)
  2017.     $mondelt = Number($mon) - Number($monold)
  2018.     GUICtrlSetData($lblGold, "Gold: " & $mon & ", Repair cost: " & $mondelt)
  2019.     $monold = $mon
  2020.     Call("AddLog", "Repair Cost: " & - $mondelt)
  2021.    
  2022.  
  2023.     GUICtrlSetData($lblStatus, "Status: Done With Vendor")
  2024.    
  2025.     Send("{SPACE}")
  2026.    
  2027. EndFunc   ;==>VendorLoot_new
  2028.  
  2029. Func getOption($option) ;Gets the correct INI settings corrisponding to the vend/stash/salvage of items.
  2030.  
  2031.     If ($option == "i59r") Then
  2032.         If ($i59Rare = "salvage") Then
  2033.             Return 1
  2034.         ElseIf ($i59Rare = "vend") Then
  2035.             Return 2
  2036.         Else
  2037.             Return 0
  2038.         EndIf
  2039.     ElseIf ($option == "i60r") Then
  2040.         If ($i60Rare = "salvage") Then
  2041.             Return 1
  2042.         ElseIf ($i60Rare = "vend") Then
  2043.             Return 2
  2044.         Else
  2045.             Return 0
  2046.         EndIf
  2047.     ElseIf ($option == "i61r") Then
  2048.         If ($i61Rare = "salvage") Then
  2049.             Return 1
  2050.         ElseIf ($i61Rare = "vend") Then
  2051.             Return 2
  2052.         Else
  2053.             Return 0
  2054.         EndIf
  2055.     ElseIf ($option == "i62r") Then
  2056.         If ($i62Rare = "salvage") Then
  2057.             Return 1
  2058.         ElseIf ($i62Rare = "vend") Then
  2059.             Return 2
  2060.         Else
  2061.             Return 0
  2062.         EndIf
  2063.     ElseIf ($option == "i63r") Then
  2064.         If ($i63Rare = "salvage") Then
  2065.             Return 1
  2066.         ElseIf ($i63Rare = "vend") Then
  2067.             Return 2
  2068.         Else
  2069.             Return 0
  2070.         EndIf
  2071.     ElseIf ($option == "i59m") Then
  2072.         If ($i59Magic = "salvage") Then
  2073.             Return 1
  2074.         ElseIf ($i59Magic = "vend") Then
  2075.             Return 2
  2076.         Else
  2077.             Return 0
  2078.         EndIf
  2079.     ElseIf ($option == "i60m") Then
  2080.         If ($i60Magic = "salvage") Then
  2081.             Return 1
  2082.         ElseIf ($i60Magic = "vend") Then
  2083.             Return 2
  2084.         Else
  2085.             Return 0
  2086.         EndIf
  2087.     ElseIf ($option == "i61m") Then
  2088.         If ($i61Magic = "salvage") Then
  2089.             Return 1
  2090.         ElseIf ($i61Magic = "vend") Then
  2091.             Return 2
  2092.         Else
  2093.             Return 0
  2094.         EndIf
  2095.     ElseIf ($option == "i62m") Then
  2096.         If ($i62Magic = "salvage") Then
  2097.             Return 1
  2098.         ElseIf ($i62Magic = "vend") Then
  2099.             Return 2
  2100.         Else
  2101.             Return 0
  2102.         EndIf
  2103.     ElseIf ($option == "i63m") Then
  2104.         If ($i63Magic = "salvage") Then
  2105.             Return 1
  2106.         ElseIf ($i63Magic = "vend") Then
  2107.             Return 2
  2108.         Else
  2109.             Return 0
  2110.         EndIf
  2111.     Else
  2112.         Return 0
  2113.     EndIf
  2114.  
  2115. EndFunc   ;==>getOption
  2116. #endregion OtherStuff
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement