;------------------------------------------------ ;--------------------PotThread------------------- ;------------------------------------------------ ;Scripts & Design by Smorg with health/mana pots added by Payne ;www.mmbot.net ;Version 5.0 ;------------------------------------------------ ;#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") ;Requires AutoIt 3.2.0 + opt("PixelCoordMode", 2) opt("MouseCoordMode", 2) opt("ColorMode", 1) #Include ;------------------------------------------------ ;Special string logic function to move up the folter tree. $CurrentDir = StringSplit(@ScriptDir, "\") _ArrayPop($CurrentDir) $BotDir = $CurrentDir[1] For $Rebuild = 2 to ($CurrentDir[0] - 1) $BotDir = $BotDir & "\" & $CurrentDir[$Rebuild] Next ;------------------------------------------------ ;Internal Vars LogEvent(0, "---------------------------------------------") LogEvent(0, "PotThread Launched, Loading vars & Pixel Data") LogEvent(0, "---------------------------------------------") $ExtraDebug = "Yes" ;Show Extra pixel info, for debugging purposes only $Top = 509 ;Top of the health/mana orbs $Bottom = 587 ;Bottom of the health/mana orbs $HealthX = 0 ;Xcoord to scan the health orb $ManaX = 799 ;Xcoord to scan the mana orb $BeltX = 437 ;Left Belt Slot pixel reference $BeltY = 582 ;Left Belt Slot pixel reference $MercBarLeft = 15 ;Left side of the merc bar $MercBarRight = 60 ;Right side of the merc bar $MercBarY = 18 ;Merc bar Y coord $beltfrjchecksum = 713163619 ;belt checksum for full rejuvs $beltrjchecksum = 1805125736 ;belt checksum for regular rejuvs $beltshpchecksum = 1813383517 ;belt checksum for super healing potions $beltsmpchecksum = 1408763614 ;belt checksum for super mana potions $ChickenTimeout = 1000 ;Time to wait for sucessful chicken before retrying $ChickenRetries = 3 ;Times to retry chicken $LifeBarColor = 11519 ;Life bar color $ManaBarColor = 14573857 ;Mana bar color Global $Char_Key_PotionsRow[5] ;Potion drink keys Global $BeltData[6] ;Potions info. 0 = no pot, 1 = full rejuv pot, 2 = regular rejuv pot, 3 = healing pot, 4 = mana pot Dim $HealthPixel = $Top ;Current Health Pixel y coord Dim $ManaPixel = $Top ;Current Mana Pixel y coord Dim $MercPixel = $MercBarRight ;Current merc bar pixel Dim $Timer = 0 ;Timer flag, weather or not the drink timer is active Dim $LifePercent Dim $ManaPercent Dim $MercPercent Dim $Sleep ;------------------------------------------------ ;Importing Vars $Char_Key_PotionsRow[1] = IniRead($BotDir & "\Config\mm.BOT.ini", "Character", "Char_Key_PotionsRow1", "") $Char_Key_PotionsRow[2] = IniRead($BotDir & "\Config\mm.BOT.ini", "Character", "Char_Key_PotionsRow2", "") $Char_Key_PotionsRow[3] = IniRead($BotDir & "\Config\mm.BOT.ini", "Character", "Char_Key_PotionsRow3", "") $Char_Key_PotionsRow[4] = IniRead($BotDir & "\Config\mm.BOT.ini", "Character", "Char_Key_PotionsRow4", "") $PauseBot = IniRead($BotDir & "\Config\mm.BOT.ini", "Advanced Settings", "Bot_PAUSE_HotKey", "") $PauseBot = "{" & $PauseBot & "}" $ClearScreen = IniRead($BotDir & "\Config\mm.BOT.ini", "Character", "Char_Key_ClearScreen", "") $ClearScreen = "{" & $ClearScreen & "}" $D2WinTitle = IniRead($BotDir & "\Config\mm.BOT.ini", "Advanced Settings", "D2_WName", "") $LifeRpotDrinkPercent = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Settings", "Rpot_Life_Percent", "") $LifeFpotDrinkPercent = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Settings", "FRJ_Life_Percent", "") $ManaRpotDrinkPercent = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Settings", "Rpot_Mana_Percent", "") $ManaFpotDrinkPercent = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Settings", "FRJ_Mana_Percent", "") $LifeSHpotDrinkPercent = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Settings", "SHP_Life_Percent", "") $ManaSMpotDrinkPercent = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Settings", "SMP_Life_Percent", "") $ChickenPercent = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Settings", "Chicken_Percent", "") $ChickenMana = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Settings", "Chicken_Mana", "") $ScanDelay = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Settings", "Scan_Delay", "") $DrinkDelay = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Settings", "Drink_Delay", "") $ChickenWaitDelay = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Settings", "Chicken_Wait_Delay", "") $MaxLife = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Settings", "Max_Life", "") $MaxMana = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Settings", "Max_Mana", "") $UseMerc = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Merc", "Use_Merc", "") $MercChicken = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Merc", "Merc_Chicken", "") $MercHealPercent = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Merc", "Merc_Heal_Percent", "") $MercChickenPercent = IniRead($BotDir & "\Config\mm.LifeCheck.ini", "Merc", "Merc_Chicken_Percent", "") ;Get base stats If $UseMerc = "No" Then $MercPercent = "None" SuspendCheck() ;ChickenWait() GetBaseStats($HealthPixel, $ManaPixel, $MercPixel, $LifePercent, $ManaPercent) LogEvent(0, "Base Stats loading Successful! Begining main loop check...") LogEvent(0, "HealthPixel = " & $HealthPixel & ", ManaPixel = " & $ManaPixel & ", Top = " & $Top) ShowTip() ;------------------------------------------------ While 1 Sleep($ScanDelay) ;Pause if not in game If PixelGetColor(481, 535) <> 5406092 Then If (PixelGetColor(320, 537) <> 6521492) OR (WinActive($D2WinTitle) = 0) Then SuspendCheck() EndIf EndIf ;Check if life has moved either up or down If PixelGetColor($HealthX, $HealthPixel) <> $LifeBarColor Then GetLife("down", $HealthPixel, $LifePercent, $Timer) ElseIf $HealthPixel <> $Top Then If PixelGetColor($HealthX, $HealthPixel - 1) = $LifeBarColor Then GetLife("up", $HealthPixel, $LifePercent, $Timer) EndIf ;Check if mana has moved either up or down If PixelGetColor($ManaX, $ManaPixel) <> $ManaBarColor Then GetMana("down", $ManaPixel, $ManaPercent, $Timer) ElseIf $ManaPixel <> $Top Then If PixelGetColor($ManaX, $ManaPixel - 1) = $ManaBarColor Then GetMana("up", $ManaPixel, $ManaPercent, $Timer) EndIf ;Check if merc's life has changed & merc chicken check If $UseMerc = "Yes" Then If PixelGetColor($MercPixel, $MercBarY) = 0 Then GetMerc("down", $MercPixel, $MercPercent, $Timer) ElseIf $MercPixel <> $MercBarRight Then If PixelGetColor($MercPixel + 1, $MercBarY) <> 0 Then GetMerc("up", $MercPixel, $MercPercent, $Timer) EndIf EndIf WEnd ;------------------------------------------------ Func GetLife($Direction, ByRef $HealthPixel, ByRef $LifePercent, ByRef $Timer) Select Case $Direction = "up" For $Search = $HealthPixel To $Top Step - 1 If (PixelGetColor($HealthX, $Search) <> $LifeBarColor) Or $Search = $Top Then $LifePercent = Round(100 * (($Bottom - $Top) - ($Search - $Top)) / ($Bottom - $Top)) $HealthPixel = $Search ExitLoop EndIf Next Case $Direction = "down" For $Search = $HealthPixel To $Bottom If (PixelGetColor($HealthX, $Search) = $LifeBarColor) Or $Search = $Bottom Then $LifePercent = Round(100 * (($Bottom - $Top) - ($Search - $Top)) / ($Bottom - $Top)) $HealthPixel = $Search ExitLoop EndIf Next EndSelect ShowTip() If $Timer = 1 Then If TimerDiff($Sleep) > $DrinkDelay Then $Timer = 0 EndIf If $Timer = 0 Then If ($LifePercent < $LifeSHpotDrinkPercent) And ($LifePercent > $LifeRpotDrinkPercent) Then LogEvent(0, "Life has dropped to " & $LifePercent & "%, Will try to drink a Super Healing pot.") Drink(3) $Timer = 1 $Sleep = TimerInit() ElseIf ($LifePercent < $LifeRpotDrinkPercent) And ($LifePercent > $LifeFpotDrinkPercent) Then LogEvent(0, "Life has dropped to " & $LifePercent & "%, Will try to drink a regular rejuv.") Drink(1) $Timer = 1 $Sleep = TimerInit() ElseIf $LifePercent < $LifeFpotDrinkPercent Then LogEvent(0, "Life is critical! Life has dropped to " & $LifePercent & "%, Will try to drink a Full rejuv.") Drink(0) $Timer = 1 $Sleep = TimerInit() EndIf EndIf If $LifePercent < $ChickenPercent Then LogEvent(0, "Life is very low! Life has dropped to " & $LifePercent & "%, Bot will attempt to chicken...") Chicken() EndIf EndFunc ;==>GetLife Func GetMana($Direction, ByRef $ManaPixel, Byref $ManaPercent, ByRef $Timer) Select Case $Direction = "up" For $Search = $ManaPixel To $Top Step - 1 If (PixelGetColor($ManaX, $Search) <> $ManaBarColor) Or $Search = $Top Then $ManaPercent = Round(100 * (($Bottom - $Top) - ($Search - $Top)) / ($Bottom - $Top)) $ManaPixel = $Search ExitLoop EndIf Next Case $Direction = "down" For $Search = $ManaPixel To $Bottom If (PixelGetColor($ManaX, $Search) = $ManaBarColor) Or $Search = $Bottom Then $ManaPercent = Round(100 * (($Bottom - $Top) - ($Search - $Top)) / ($Bottom - $Top)) $ManaPixel = $Search ExitLoop EndIf Next EndSelect ShowTip() If $Timer = 1 Then If TimerDiff($Sleep) > $DrinkDelay Then $Timer = 0 EndIf If $Timer = 0 Then If ($ManaPercent < $ManaSMpotDrinkPercent) And ($ManaPercent > $ManaRpotDrinkPercent) Then LogEvent(0, "Mana has dropped to " & $ManaPercent & "%, Will try to drinka Mana pot.") Drink(4) $Timer = 1 $Sleep = TimerInit() ElseIf ($ManaPercent < $ManaRpotDrinkPercent) And ($ManaPercent > $ManaFpotDrinkPercent) Then LogEvent(0, "Mana has dropped to " & $ManaPercent & "%, Will try to drink a regular rejuv.") Drink(1) $Timer = 1 $Sleep = TimerInit() ElseIf $ManaPercent < $ManaFpotDrinkPercent Then LogEvent(0, "Mana is critical! Mana has dropped to " & $ManaPercent & "%, Will try to drink a Full rejuv.") Drink(0) $Timer = 1 $Sleep = TimerInit() EndIf If $ChickenMana <> "Off" Then If $ManaPercent < $ChickenMana Then LogEvent(0, "Mana is very low! Mana has dropped to " & $ManaPercent & "%, Bot will attempt to chicken...") Chicken() EndIf EndIf EndIf EndFunc ;==>GetMana Func GetMerc($Direction, ByRef $MercPixel, ByRef $MercPercent, ByRef $Timer) Select Case $Direction = "up" For $Search = $MercPixel To $MercBarRight If (PixelGetColor($Search, $MercBarY) = 0) Or $Search = $MercBarRight Then $MercPercent = Round(100 * (($Search - $MercBarLeft) / ($MercBarRight - $MercBarLeft))) $MercPixel = $Search ExitLoop EndIf Next Case $Direction = "down" For $Search = $MercPixel To $MercBarLeft Step - 1 If (PixelGetColor($Search, $MercBarY) <> 0) Or $Search = $MercBarLeft Then $MercPercent = Round(100 * (($Search - $MercBarLeft) / ($MercBarRight - $MercBarLeft))) $MercPixel = $Search ExitLoop EndIf Next EndSelect ShowTip() If $Timer = 1 Then If TimerDiff($Sleep) > $DrinkDelay Then $Timer = 0 EndIf If $Timer = 0 Then If ($MercPercent < $MercHealPercent) And ($UseMerc = "Yes") Then LogEvent(0, "Merc has dropped below " & $MercHealPercent & "%, Will try to drink a regular rejuv.") Drink(2) $Timer = 1 $Sleep = TimerInit() EndIf EndIf If ($MercPercent < $MercChickenPercent) And ($MercChicken = "Yes") Then LogEvent(0, "Merc life is very low! Merc has dropped below " & $MercChickenPercent & "%, Bot will attempt to chicken...") Chicken() EndIf EndFunc ;==>GetMerc Func GetBaseStats(ByRef $HealthPixel, ByRef $ManaPixel, ByRef $MercPixel, ByRef $LifePercent, ByRef $ManaPercent) Local $HT = PixelSearch($HealthX, $Top - 10, $HealthX, $Bottom, $LifeBarColor) Local $MT = PixelSearch($ManaX, $Top - 10, $ManaX, $Bottom, $ManaBarColor) $HealthPixel = $HT[1] $ManaPixel = $MT[1] $MercPixel = $MercBarRight If $UseMerc = "Yes" Then GetMerc("down", $MercPixel, $MercPercent, $Timer) $LifePercent = Round(100 * (($Bottom - $Top) - ($HT[1] - $Top)) / ($Bottom - $Top)) $ManaPercent = Round(100 * (($Bottom - $Top) - ($MT[1] - $Top)) / ($Bottom - $Top)) EndFunc ;==>GetBaseStats Func ChickenWait() LogEvent(0, "Sleeping to avoid an infinant chicken loop. Wait to visit malah. Chicken_Wait_Delay = " & $ChickenWaitDelay) $Sleep = TimerInit() While TimerDiff($Sleep) < ($ChickenWaitDelay * 1000) ToolTip("Sleep Timer: " & Round($ChickenWaitDelay - (TimerDiff($Sleep)/1000)), 252, 578) Sleep(500) WEnd LogEvent(0, "Chicken Wait finished, Bot will continue checking...") EndFunc Func ShowTip() If $ExtraDebug = "No" Then ToolTip("Life: " & Round($MaxLife * ($LifePercent / 100)) & " / " & $MaxLife & " - " & Round($LifePercent) & "%" & @CRLF _ & "Mana: " & Round($MaxMana * ($ManaPercent / 100)) & " / " & $MaxMana & " - " & Round($ManaPercent) & "%" & @CRLF _ & "Merc: " & Round($MercPercent) & "%", 252, 578) ElseIf $ExtraDebug = "Yes" Then ToolTip("Life: " & $MaxLife * ($LifePercent / 100) & " / " & $MaxLife & " - " & $LifePercent & "%" & @CRLF _ & "Mana: " & $MaxMana * ($ManaPercent / 100) & " / " & $MaxMana & " - " & $ManaPercent & "%" & @CRLF _ & "Merc: " & $MercPercent & "%" & @CRLF _ & "HealthPix: " & $HealthPixel - $Top & " ManaPix: " & $ManaPixel - $Top & @CRLF _ & "MercPix: " & $MercPixel, 252, 578) EndIf EndFunc ;==>ShowTip Func Drink($DrinkType) ;Type of drink. 0 = Full rejuv, 1 = Regular rejuv, 2 = Merc For $N = 0 To 3 $Check = PixelChecksum(($BeltX + ($N * 31)) - 1, $BeltY - 1, ($BeltX + ($N * 31)) + 1, $BeltY + 1, 1) If $Check = $beltfrjchecksum Then $BeltData[$N] = 1 ElseIf $Check = $beltrjchecksum Then $BeltData[$N] = 2 ElseIf $Check = $beltshpchecksum Then $BeltData[$N] = 3 ElseIf $Check = $beltsmpchecksum Then $BeltData[$N] = 4 Else $BeltData[$N] = 0 EndIf Next LogEvent(0, "Belt Data:") $LogFile = FileOpen($BotDir & "\Logs\LifeCheck.txt", 1) For $N = 0 To 3 Select Case $BeltData[$N] = 1 FileWrite($LogFile, "(F)") Case $BeltData[$N] = 2 FileWrite($LogFile, "(R)") Case $BeltData[$N] = 3 FileWrite($LogFile, "(H)") Case $BeltData[$N] = 4 FileWrite($LogFile, "(S)") Case Else FileWrite($LogFile, "(E)") EndSelect Next FileWrite($LogFile, @CRLF) FileClose($LogFile) $A = 0 Select Case $DrinkType = 0 ;Prioritize Full rejuves For $N = 0 To 3 If $BeltData[$N] = 1 Then Send($Char_Key_PotionsRow[$N + 1]) $A = 1 LogEvent(0, "Drank a Full Rejuv from belt slot " & $N + 1) ExitLoop EndIf If $A = 0 Then For $N = 0 To 3 If $BeltData[$N] = 2 Then Send($Char_Key_PotionsRow[$N + 1]) $A = 1 LogEvent(0, "No more Full Rejuvs, so we Drank a Regular Rejuv instead from belt slot " & $N + 1) ExitLoop EndIf Next If $A = 0 Then For $N = 0 to 3 If $BeltData[$N] = 3 Then Send($Char_Key_PotionsRow[$N + 1]) $A =1 LogEvent(0, "No more Rejuvs, so we Drank a Super Healing instead from belt slot " & $N +1) ExitLoop EndIf Next EndIf EndIf Next If $A = 0 Then LogEvent(0, "We are out of pots, Chickening...") Chicken() EndIf Case $DrinkType = 1 ;Prioritize Regular rejuves For $N = 0 To 3 If $BeltData[$N] = 2 Then Send($Char_Key_PotionsRow[$N + 1]) $A = 1 LogEvent(0, "Drank a Regular Rejuv from belt slot " & $N + 1) ExitLoop EndIf Next If $A = 0 Then For $N = 0 To 3 If $BeltData[$N] = 3 Then Send($Char_Key_PotionsRow[$N + 1]) $A = 1 LogEvent(0, "No more Regular Rejuvs, so we Drank a Super Healing instead from belt slot " & $N + 1) ExitLoop EndIf Next If $A = 0 Then For $N = 0 to 3 If $BeltData[$N] = 1 Then Send($Char_Key_PotionsRow[$N + 1]) $A =1 LogEvent(0, "No more Rejuvs, so we Drank a Full Rejuv instad from belt slot " & $N +1) ExitLoop EndIf Next EndIf EndIf If $A = 0 Then LogEvent(0, "We are out of pots, Chickening...") Chicken() EndIf Case $DrinkType = 2 ;Send a pot to the merc, Prioritize Regular rejuves Send("{SHIFTDOWN}") For $N = 0 To 3 If $BeltData[$N] = 2 Then Send($Char_Key_PotionsRow[$N + 1]) $A = 1 LogEvent(0, "Sent a Regular Rejuv to the Merc from belt slot " & $N + 1) ExitLoop EndIf Next If $A = 0 Then For $N = 0 To 3 If $BeltData[$N] = 3 Then Send($Char_Key_PotionsRow[$N + 1]) $A = 1 LogEvent(0, "No more Regular Rejuvs to send to the Merc, so we'll send a Healing pot instead from belt slot " & $N + 1) ExitLoop EndIf Next EndIf If $A = 0 Then For $N = 0 to 3 If $BeltData[$N] = 3 Then Send($Char_Key_PotionsRow[$N + 1]) $A =1 LogEvent(0, "No more Rejuvs, so we Drank a Full Rejuv instad from belt slot " & $N +1) ExitLoop EndIf Next EndIf Send("{SHIFTUP}") If $A = 0 Then LogEvent(0, "We are out of pots, Chickening...") ;Chicken() EndIf Case $DrinkType = 3 ;Prioritize SuperHealing For $N = 0 To 3 If $BeltData[$N] = 3 Then Send($Char_Key_PotionsRow[$N + 1]) $A = 1 LogEvent(0, "Drank a Super Healing from belt slot " & $N + 1) ExitLoop EndIf Next Case $DrinkType = 4 ;Prioritize SuperMana For $N = 0 To 3 If $BeltData[$N] = 4 Then Send($Char_Key_PotionsRow[$N + 1]) $A = 1 LogEvent(0, "Drank a Super Mana from belt slot " & $N + 1) ExitLoop EndIf Next EndSelect EndFunc ;==>Drink Func Chicken() ToolTip("") Send($PauseBot) For $Retries = 1 To $ChickenRetries Send($ClearScreen) If (PixelGetColor(481, 535) <> 5406092) OR (PixelGetColor(320, 537) <> 6521492) Then MouseClick("Left", 400, 575, 1, 0) 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(0, "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(0, "Max Retries exceeded, Will terminate the Game.exe process") ProcessClose("Game.exe") Else LogEvent(0, "Failed to chicken, Will retry the chicken...") EndIf Next LogEvent(0, "Chicken was a success! Your ass has been saved by PotThread(tm), gib Smorg a dollar! ^^") Send($PauseBot) SuspendCheck() ChickenWait() GetBaseStats($HealthPixel, $ManaPixel, $MercPixel, $LifePercent, $ManaPercent) EndFunc ;==>Chicken Func SuspendCheck() ToolTip("") Do Sleep(100) If WinExists($D2WinTitle) = 0 Then LogEvent(0, "Diablo has been closed, Terminating PotThread...") Exit(1) EndIf Until ((PixelGetColor(481, 535) = 5406092) OR (PixelGetColor(320, 537) = 6521492)) AND (WinActive($D2WinTitle) = 1) ShowTip() EndFunc ;==>SuspendCheck Func LogEvent($Code, $String) $LogFile = FileOpen($BotDir & "\Logs\LifeCheck.txt", 1) Select Case $Code = 0 FileWriteLine($LogFile, @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [I]> " & $String) Case $Code = 1 FileWriteLine($LogFile, @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " [E]> " & $String) EndSelect FileClose($LogFile) EndFunc Func OnAutoItExit() MouseUp("Right") MouseUp("Left") LogEvent(0, "PotThread Stopped.") EndFunc ;----------