All pastes #719258 Raw Edit

Anonymous

public text v1 · immutable
#719258 ·published 2007-09-29 02:59 UTC
rendered paste body
;------------------------------------------------ 
;--------------Smorg's PotBot V3.1--------------- 
;------------------------------------------------ 
;www.mmbot.net 
;#NoTrayIcon                      ;Comment for tests, Uncomment for bot use 
WinActivate("Diablo II")          ;Comment for bot use, Uncomment for tests 
WinMove("Diablo II", "", 0, 0)    ;Optional 
opt("OnExitFunc", "OnAutoItExit") 
opt("PixelCoordMode", 2) 
opt("MouseCoordMode", 2) 
opt("ColorMode", 1) 
#Include <Array.Au3> 
$TotalTime = TimerInit() 
;------------------------------------------------ 
$DrinkExcess = "Yes"              ;Drinks any non-rejuv pots in the belt, if present. Set to "No" to disable this check (not recomended) 
$MouseSpeed = 0                   ;Duh 
$MouseDelay = 50                  ;delay after each mouse movment and before each mouseclick. increase if first click fails. 
$ClickDelay = 50                  ;delay before lag scan starts in order to limit bot speed slightly 
$DrinkCheckDelay = 0              ;time to sleep between drink lag checks 
$MaxLag = 1000                    ;amount of time to wait for pot to drink before retry (milliseconds) 
$ScreenTimeout = 1000             ;timeout for all screen open and close checks (milliseconds) 
$MaxRetries = 10                  ;number of times to retry upon failed to drink, and menu open/closes 
$check = 0                        ;potion pixelchecksum 
$frj = 0                          ;frjs in invantory 
$rj = 0                           ;regular rejuvs in invantory 
$beltfrj = 0                      ;frjs in belt 
$beltrj = 0                       ;regular rejuvs in belt 
$beltNum = 0                      ;total potions in belt 
$ChickenTimeout = 1000            ;Time to wait for sucessful chicken before retrying 
$ChickenRetries = 3               ;Times to retry chicken 
Dim $invArray[4][10]              ;the inventory array data. 0 = no pot, 1 = full rejuv pot, 2 = regular rejuv pot 
Dim $beltArray[4][4]              ;the belt array data. 0 = no pot, 1 = full rejuv pot, 2 = regular rejuv pot 
$beltfrjchecksum = 713163619      ;belt checksum for full rejuvs
$beltrjchecksum = 1805125736      ;belt checksum for regular rejuvs
$invfrjchecksum = 853607181       ;inventory full rejuv checksum
$invrjchecksum = 1757546291       ;inventory regular rejuv checksum
$invscreenchecksum = 657791128    ;inventory screen check. coords are: 750, 40, 760, 50, resolution 2
$InvScreenBeltSum = 372771323     ;checks the belt is open over the inventory. coords: 500, 500, 510, 510, resolution 2 
$BeltStartX = 437                 ;Starting points for upper left inventory and belt squares 
$BeltStartY = 486 
$InvStartX = 432 
$InvStartY = 335 
Dim $DrinkSuccess                 ;returns weather or not the drink was a success 
Dim $Type                         ;type of inventory click. "Left" = send pot to belt, "Right" = Drink pot. 
Global $BotDir 
;------------------------------------------------ 
MouseMove(100, 100, $MouseSpeed) 

$CurrentDir = StringSplit(@ScriptDir, "\") 
_ArrayPop($CurrentDir) 
$BotDir = $CurrentDir[1] 

For $Rebuild = 2 to ($CurrentDir[0] - 1) 
   $BotDir = $BotDir & "\" & $CurrentDir[$Rebuild] 
Next 
LogEvent("PotBot script Launched") 

$KEY_ClearScreen = IniRead($BotDir & "\Config\mm.BOT.ini", "Character", "Char_Key_ClearScreen", "") 
$KEY_ClearScreen = "{" & $KEY_ClearScreen & "}" 
$KEY_Inventory = IniRead($BotDir & "\Config\mm.BOT.ini", "Character", "Char_Key_Inventory", "") 
$KEY_Belt = IniRead($BotDir & "\Config\mm.BOT.ini", "Character", "Char_Key_ShowBelt", "") 
$KEY_Belt = "{" & $KEY_Belt & "}" 

;CHECK IF MINIPANEL IS OPEN (Required) 
If (PixelGetColor(481, 535) <> 5406092) OR (PixelGetColor(320, 537) <> 6521492) Then MouseClick("Left", 400, 575, 1, 0) 
MouseMove(100, 100, $MouseSpeed) 

;OPEN THE BELT & INVENTORY 
For $Retry = 1 to $MaxRetries 
   If $Retry = $MaxRetries Then 
      LogEvent("Max Retries reached. Chickening...") 
      Chicken() 
      Exit(0) 
   EndIf 
   Send($KEY_Belt) 
   Send($KEY_Inventory) 

   $Timeout = TimerInit() 
   While 1 
      If PixelChecksum(750, 40, 760, 50, 2) = $InvScreenChecksum Then 
         ExitLoop 
      ElseIf TimerDiff($Timeout) > $ScreenTimeout Then 
         If CloseInv() = 1 Then 
            Chicken() 
            Exit(0) 
         EndIf 
         Sleep(100) 
         LogEvent("Failed to open the Inventory, Retrying. Retry #: " & $Retry) 
         ContinueLoop 2 
      EndIf 
      Sleep(100) 
   WEnd 

   $Timeout = TimerInit() 
   While TimerDiff($Timeout) < $ScreenTimeout 
      If PixelChecksum(500, 500, 510, 510, 2) <> $InvScreenBeltSum Then ExitLoop 2 
      Sleep(100) 
   WEnd 
   Send($Key_ClearScreen) 
   Sleep(100) 
   LogEvent("Failed to open the Belt, Retrying. Retry #: " & $Retry) 
Next 
;------------------------------------------------ 

If $DrinkExcess <> "No" Then
   If DrinkPots() = 1 Then
		LogEvent("Failed to drink a pot while drinking non rejuves in belt slot (" & $row & ", " & $col & ")") 
		CloseInv() 
		Chicken() 
		Exit(0)
   EndIf
EndIf

;GENERATE BELT ARRAY 
For $row = 0 To 3 
   For $col = 0 To 3 
      $check = PixelChecksum(($BeltStartX - 1) + (31 * $col) , ($BeltStartY - 1) + ($row * 32) , ($BeltStartX + 1) + (31 * $col) , ($BeltStartY + 1) + ($row * 32), 1) 
      If $check = $beltfrjchecksum Then 
         $beltArray[$row][$col] = 1 
         $beltfrj = $beltfrj + 1 
      ElseIf $check = $beltrjchecksum Then 
         $beltArray[$row][$col] = 2 
         $beltrj = $beltrj + 1 
      Else 
         $beltArray[$row][$col] = 0 
      EndIf 
   Next 
Next 

;GENERATE INVENTORY ARRAY 
For $row = 0 To 3 
   For $col = 0 To 9 
      $check = PixelChecksum(($InvStartX - 1) + ($col * 29) , ($InvStartY - 1) + ($row * 29) , ($InvStartX + 1) + ($col * 29) , ($InvStartY + 1) + ($row * 29), 1) 
      If $check = $invfrjchecksum Then 
         $invArray[$row][$col] = 1 
         $frj = $frj + 1 
      ElseIf $check = $invrjchecksum Then 
         $invArray[$row][$col] = 2 
         $rj = $rj + 1 
      Else 
         $invArray[$row][$col] = 0 
      EndIf 
   Next 
Next 

$beltfree = 16 - ($beltfrj + $beltrj) ;16 - sum of belt pots = free belt spaces. 
$beltdrink = $frj - $beltfree         ;available frjs in inventory - belt freespaces = max # of belt rjs to drink & replace. 

;LOG BELT 
$LogFile = FileOpen($BotDir & "\Logs\LifeCheck.txt", 1) 
FileWriteLine($LogFile, @CRLF & "== Belt: ==") 
For $row = 0 To 3 
   For $col = 0 To 3 
      Select 
         Case $BeltArray[$row][$col] = 1 
            FileWrite($LogFile, "F ") 
         Case $BeltArray[$row][$col] = 2 
            FileWrite($LogFile, "R ") 
         Case Else 
            FileWrite($LogFile, "E ") 
      EndSelect 
   Next 
   FileWrite($LogFile, @CRLF) 
Next 

;LOG INVENTORY 
FileWriteLine($LogFile, @CRLF & "== Inventory: ==") 
For $row = 0 To 3 
   For $col = 0 To 9 
      Select 
         Case $InvArray[$row][$col] = 1 
            FileWrite($LogFile, "F ") 
         Case $InvArray[$row][$col] = 2 
            FileWrite($LogFile, "R ") 
         Case Else 
            FileWrite($LogFile, "E ") 
      EndSelect 
   Next 
   FileWrite($LogFile, @CRLF) 
Next 
FileWrite($LogFile, @CRLF) 
FileClose($LogFile) 

;DRINK EXCESS BELT REJUVS 
For $row = 0 To 3 
   For $col = 0 To 3 
      If $beltdrink <= 0 Then ExitLoop 2 
      If $beltArray[$row][$col] = 2 Then 
         If BeltClick($col, $row) = 1 Then 
            $beltdrink = $beltdrink - 1 
            $beltfree = $beltfree + 1 
         Else 
            CloseInv() 
            LogEvent("Failed to drink a pot while drinking excess belt rejuvs at belt slot (" & $row & ", " & $col & ")") 
            Chicken() 
            Exit(0) 
         EndIf 
      EndIf 
   Next 
Next 

;SEND INVENTORY FRJS TO BELT 
For $row = 0 To 3 
   For $col = 0 To 9 
      If $beltfree <= 0 Then ExitLoop 2 
      If $invArray[$row][$col] = 1 Then 
         If InvClick("Left", $col, $row) = 1 Then 
            $invArray[$row][$col] = 0 
            $frj = $frj - 1 
            $beltfree = $beltfree - 1 
         Else 
            CloseInv() 
            LogEvent("Failed to drink a pot while sending inventory FRJs to belt at inventory slot (" & $row & ", " & $col & ")") 
            Chicken() 
            Exit(0) 
         EndIf 
      EndIf 
   Next 
Next 

;SEND INVENTORY REJUVS TO BELT 
For $row = 0 To 3 
   For $col = 0 To 9 
      If $beltfree <= 0 Then ExitLoop 2 
      If $invArray[$row][$col] = 2 Then 
         If InvClick("Left", $col, $row) = 1 Then 
            $invArray[$row][$col] = 0 
            $rj = $rj - 1 
            $beltfree = $beltfree - 1 
         Else 
            CloseInv() 
            LogEvent("Failed to drink a pot while sending inventory regular rejuves to belt at inventory slot (" & $row & ", " & $col & ")") 
            Chicken() 
            Exit(0) 
         EndIf 
      EndIf 
   Next 
Next 

;DRINK ALL EXCESS INVENTORY POTS 
For $row = 0 To 3 
   For $col = 0 To 9 
      If $invArray[$row][$col] <> 0 Then 
         If InvClick("Right", $col, $row) = 0 Then 
            CloseInv() 
            LogEvent("Failed to drink an excess pot at inventory slot (" & $row & ", " & $col & ")") 
            Chicken() 
            Exit(0) 
         EndIf 
      EndIf 
   Next 
Next 

If CloseInv() = 1 Then 
   Chicken() 
   Exit(0) 
EndIf 
LogEvent("Finished! PotBot took " & Round(TimerDiff($TotalTime)/1000, 2) & " seconds.") 
Exit(1) 
;------------------------------------------------ 
Func CloseInv() 
   For $Retry = 1 To $MaxRetries 
      Send($KEY_ClearScreen) 
      $timeout = TimerInit() 
      While 1 
         If PixelChecksum(750, 40, 760, 50, 2) <> $invscreenchecksum Then 
            Return 0 
         ElseIf TimerDiff($timeout) > $ScreenTimeout Then 
            ExitLoop 
         EndIf 
         Sleep(100) 
      WEnd 
      LogEvent("Failed to close inventory, Retry# " & $Retry) 
   Next 
   LogEvent("Cannot close the inventory, Ensure your ClearScreen key is correct.") 
   Return 1 
EndFunc 

Func BeltClick($col, $row) 
   Local $DrinkFlag = 0 
   For $Retry = 1 To $MaxRetries 
      MouseMove($BeltStartX + ($col * 31), $BeltStartY + ($row * 32), $MouseSpeed) 
      Sleep($MouseDelay) 
      $PotRef = PixelGetColor($BeltStartX + ($col * 31) - 3, $BeltStartY + ($row * 32) - 3) 
      MouseClick("Right") 
      Sleep($ClickDelay) 
      $TimeStart = TimerInit() 
      While TimerDiff($TimeStart) < $MaxLag 
         If PixelGetColor($BeltStartX + ($col * 31) - 3, $BeltStartY + ($row * 32) - 3) <> $PotRef Then 
            $DrinkFlag = 1 
            ExitLoop 2 
         EndIf 
         Sleep($DrinkCheckDelay) 
      WEnd 
      LogEvent("Failed to click belt pot, Retry# " & $Retry) 
   Next 
   Return $DrinkFlag 
EndFunc 

Func InvClick($Type, $col, $row) 
   Local $DrinkFlag = 0 
   If $Type = "Left" Then Send("{ShiftDown}") 
   For $Retry = 1 To $MaxRetries 
      MouseMove($InvStartX + ($col * 29), $InvStartY + ($row * 29), $MouseSpeed) 
      Sleep($MouseDelay) 
      $PotRef = PixelGetColor($InvStartX + ($col * 29) - 3, $InvStartY + ($row * 29) - 3) 
      If $Type = "Left" Then 
         MouseClick("left") 
      Else 
         MouseClick("Right") 
      EndIf 
      Sleep($ClickDelay) 
      $TimeStart = TimerInit() 
      While TimerDiff($TimeStart) < $MaxLag 
         If PixelGetColor($InvStartX + ($col * 29) - 3, $InvStartY + ($row * 29) - 3) <> $PotRef Then 
            $DrinkFlag = 1 
            ExitLoop 2 
         EndIf 
         Sleep($DrinkCheckDelay) 
      WEnd 
      LogEvent("Failed to click inventory pot, Retry# " & $Retry) 
   Next 
   If $Type = "Left" Then Send("{ShiftUp}") 
   Return $DrinkFlag 
EndFunc 

Func DrinkPots() 
   Local $a = 0 
   For $row = 0 To 3 
      For $col = 0 To 3 
         $Mana = PixelSearch(($BeltStartX - 10) + ($col * 31) , ($BeltStartY - 10) + ($row * 32) , ($BeltStartX + 10) + ($col * 31) , ($BeltStartY + 10) + ($row * 32), 9711665, 0, 1) ;Mana 
         $Healing = PixelSearch(($BeltStartX - 10) + ($col * 31) , ($BeltStartY - 10) + ($row * 32) , ($BeltStartX + 10) + ($col * 31) , ($BeltStartY + 10) + ($row * 32), 148, 0, 1) ;Healing 
         If IsArray($Mana) Or IsArray($Healing) Then 
            If BeltClick($col, $row) = 1 Then 
               LogEvent("Drank a Healing or Mana pot in belt slot (" & $row & ", " & $col & ")") 
               $a = 1 
            Else
			   Return 1
            EndIf 
         EndIf 
      Next 
   Next 
   If $a = 1 Then
		MouseMove(100, 100, $MouseSpeed) 
		Sleep(200)
		Return 0
	EndIf
	Return 0
EndFunc 

Func Chicken() 
   For $Retries = 1 To $ChickenRetries 
      Send($KEY_ClearScreen) 
      MouseUp("Right") 
      MouseUp("Left") 
      Send("{ESC}") 
      $Timeout = TimerInit() 
      While 1 
         If (PixelGetColor(481, 535) <> 5406092) AND (PixelGetColor(320, 537) <> 6521492) Then 
            ExitLoop 
         ElseIf TimerDiff($Timeout) > 500 Then 
            LogEvent("Failed to open the main menu, will retry... Retry # " & $Retries) 
            ContinueLoop 2 
         EndIf 
         Sleep(100) 
      WEnd 
      MouseClick("Left", 400, 280, 1, 0) 
      $Timeout = TimerInit() 
      While TimerDiff($Timeout) < $ChickenTimeout 
         If (PixelGetColor(600, 575) <> 6512995) AND (PixelGetColor(5, 575) <> 2697257) Then ExitLoop 2 
         Sleep(100) 
      WEnd 
      If $Retries >= $ChickenRetries Then 
         LogEvent("Max Retries exceeded, Will terminate the Game.exe process") 
         ProcessClose("Game.exe") 
      Else 
         LogEvent("Failed to chicken, Will retry the chicken...") 
      EndIf 
   Next 
   LogEvent("Chicken was a success! Your ass has been saved by PotThread(tm), gib Smorg a dollar! ^^") 
EndFunc   ;==>Chicken 

Func LogEvent($String) 
   $LogFile = FileOpen($BotDir & "\Logs\LifeCheck.txt", 1) 
   FileWriteLine($LogFile, @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [P]> " & $String) 
   FileClose($LogFile) 
EndFunc 

Func OnAutoItExit() 
   MouseUp("Right") 
   MouseUp("Left") 
   Send("{ShiftUp}") 
EndFunc 
;------------------------------------------------