Advertisement
Guest User

Don DooBee v1.3

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