Advertisement
onedoesnotsimply

onedoesnotsimply DH sarkoth 2.0

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