thefrobel

DH SARKOTH XP

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