Advertisement
Guest User

Monk Sarkoth Run

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