Advertisement
BlackSack

Blaksack's mod 1.93hyb.f HYBRID SCRIPT!

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