#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.10.0 Author: Mixam Script Function: Run Awesom-O 24/7#ce ----------------------------------------------------------------------------#include <String.au3>#include <Misc.au3>#include <WinAPI.au3>#include <File.au3>Global $thisprogram = "MixamAO beta4.1"Global $redvexname = IniRead($thisprogram & ".ini", "Settings", "RedVex", "")Global $preventrd = IniRead($thisprogram & ".ini", "Settings", "RDprevention", "1")Global $maxgametimesecs = IniRead($thisprogram & ".ini", "Settings", "MaxGameLength", 600)Global $banwait = IniRead($thisprogram & ".ini", "Settings", "BanWaitTime", 3600000)Global $redvexdir = IniRead($thisprogram & ".ini", "Settings", "RedVexDir", "")Global $refreshtray = IniRead($thisprogram & ".ini", "Settings", "RefreshTray", 1)Global $redvexexe = ($redvexdir & $redvexname & ".exe")Global $gamename = StringTrimRight(IniRead($redvexdir & "Awesom-O.ini", "Bot0", "GameName", ""), 2)Global $gamelog = $redvexdir & "games.txt"Global $sleep = IniRead($thisprogram & ".ini", "Settings", "Sleep", "1000"); Window infoGlobal $diablofull= IniRead($redvexdir & "Awesom-O.ini", "Settings", "GameExe", "Diablo II.exe")Global $diabloprocess = StringTrimLeft($diablofull, StringInStr ( $diablofull, "\", 0, -1 )) $diabloprocess = StringTrimLeft($diabloprocess , StringInStr ( $diabloprocess, "/", 0, -1 ))Global $windownames = IniRead($thisprogram & ".ini", "Settings", "D2Windows", "Diablo_0") $windownames = StringSplit($windownames, ",")Global $line = 0Global $lastgamestrGlobal $runforsecsGlobal $rdgametimeGlobal $mixamAOlog = (@ScriptDir & "\MixamAO.log")If _Singleton("\" & $thisprogram, 1) = 0 Then MsgBox(4096, "Warning", "An occurence of " & $thisprogram & " is already running") _FileWriteLog(@ScriptDir & "\MixamAO.log", "ERROR: An occurence of " & $thisprogram & " is already running") ExitEndIfIf ProcessExists($redvexname & ".exe") Then MsgBox(4096, "Warning", "RedVex is running already. Hitting OK will close redvex and D2 and start MixamAO") _FileWriteLog(@ScriptDir & "\MixamAO.log", "ERROR: RedVex is running already.") _Kill()EndIfIf Not FileExists($thisprogram & ".ini") Then MsgBox(4096, "Error", "Can't find " & $thisprogram & ".ini :(") _FileWriteLog(@ScriptDir & "\MixamAO.log", "ERROR: Can't find " & $thisprogram & ".ini :(") ExitEndIfIf Not FileExists($mixamAOlog) Then _FileCreate(@ScriptDir & "\MixamAO.log") _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: MixamAO.log was missing. It has been created")EndIfIf Not FileExists($redvexexe) Then MsgBox(4096, "Error", "Can't find " & $redvexexe & " :(") _FileWriteLog(@ScriptDir & "\MixamAO.log", "ERROR: Can't find " & $redvexexe & " :(") ExitEndIf_FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: MixamAO Started")_Load()While 1 Sleep($sleep) _CrashCheck()WEnd; _Load runs redvex then waits for Awesom-O to open. Then it sleeps for 2 mins to; allow the first game to be made before _LastGameSecsAgo runs.Func _Load() Run($redvexexe & " -run -hide", $redvexdir) _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: Redvex Loaded") Sleep(120000)EndFunc ;==>_Load; _Kill closes redvex and all D2's you have open. Be aware that it doesn't just; close the bot's window, it closes all D2 windows. Also cleans the tray now.Func _Kill() ProcessClose($redvexname & ".exe") $plist = ProcessList($diabloprocess) for $i = 1 to $windownames[0] $wlist = WinList($windownames[$i]) for $j = 1 to $wlist[0][0] for $k = 1 to $plist[0][0] $curPid = WinGetProcess($wlist[$j][1]) If $curPid = $plist[$k][1] Then ProcessClose($curPid) ; Is this even necessary? If ProcessExists($curPid) Then While ProcessExists($curPid) ProcessClose($curPid) WEnd EndIf EndIf Next Next Next _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: Redvex and D2 killed") IniWrite($redvexdir & "Awesom-O.ini", "Bot0", "StartNumber", (_FindLastGameNumber() + 1)) _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: game start number changed") _CleanTray($refreshtray)EndFunc ;==>_Kill; _KillD2() kills only D2 windows listed in the ini.Func _KillD2() $plist = ProcessList($diabloprocess) for $i = 1 to $windownames[0] $wlist = WinList($windownames[$i]) for $j = 1 to $wlist[0][0] for $k = 1 to $plist[0][0] $curPid = WinGetProcess($wlist[$j][1]) If $curPid = $plist[$k][1] Then ProcessClose($curPid) ; Is this even necessary? If ProcessExists($curPid) Then While ProcessExists($curPid) ProcessClose($curPid) WEnd EndIf EndIf Next Next Next _FileWriteLog(@ScriptDir & "\MixamAO.log","Notice: D2 killed")EndFunc ;==>_KillD2(); _CrashCheck checks if its been over your set max time since the last game was created; or if redvex has closed and if either happens, it kills and restarts D2 and RedVex; It now also checks for r/d and if some errors pop up.Func _CrashCheck() $lastgamestr = _FindLastGame() $runforsecs = _LastGameSecsAgo() $rdgametime = _RDGameSecsAgo() Local $bansleep = $banwait While StringInStr($lastgamestr, "IP Ban") _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: IP Ban detected") _Kill() _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: Waiting " & $bansleep & "ms for ban to be over") Sleep($bansleep) $bansleep = $bansleep * 2 _Load() Sleep(120000) $lastgamestr = _FindLastGame() WEnd If $runforsecs > $maxgametimesecs Then _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: " & $maxgametimesecs & "secs is up. Crash detected") _Kill() _Load() EndIf If $rdgametime < 3600 Then If $preventrd = 1 Then _Kill() _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: 19 games made in " & $rdgametime & "secs. Waiting " & (3660 - $rdgametime) & "secs to restart") Sleep((3660 - $rdgametime) * 1000) _Load() EndIf EndIf for $i = 1 to $windownames[0] If WinExists("End Program - " & $windownames[$i]) Then WinClose("End Program - " & $windownames[$i]) _FileWriteLog(@ScriptDir & "\MixamAO.log","Notice: End Program window detected. Closing D2 (" & $windownames[$i] & ")") _KillD2() EndIf Next for $i = 1 to $windownames[0] If WinExists($windownames[$i] & ": " & $diabloprocess & " - Application Error") Then WinClose($windownames[$i] & ": " & $diabloprocess & " - Application Error") _FileWriteLog(@ScriptDir & "\MixamAO.log","Notice: Application Error window detected. Closing D2 (" & $windownames[$i] & ")") _KillD2() EndIf Next If WinExists($redvexname & ".exe") Then WinClose($redvexname & ".exe") _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: Redvex Error Detected") _Kill() _Load() EndIf If WinExists("Microsoft Visual C++ Runtime Library") Then WinClose("Microsoft Visual C++ Runtime Library") _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: Microsoft Visual C++ Runtime Library Error detected") _Kill() _Load() EndIf If WinExists("Visual Studio Just-In-Time Debugger") Then WinKill("Visual Studio Just-In-Time Debugger") _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: Debugger Error detected") _Kill() _Load() EndIf If Not ProcessExists($redvexname & ".exe") Then _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: Detected that Redvex is not running") _Kill() _Load() EndIfEndFunc ;==>_CrashCheck; _FindLastGame searches the log file for the last entry with the game name in it then; returns a string with that last game name and the time the game was made. It also now; returns a string if there is a ban message for r/d supportFunc _FindLastGame() Local $logfile = FileOpen($gamelog, 0) Local $linestr If $logfile = -1 Then MsgBox(4096, "Error", "Unable to locate the game log.") _FileWriteLog(@ScriptDir & "\MixamAO.log", "ERROR: Unable to locate the game log") Exit EndIf While 1 $line = $line + 1 $linestr = FileReadLine($logfile, $line) If @error = -1 Then While 1 $line = $line - 1 $linestr = FileReadLine($logfile, $line) If StringInStr($linestr, $gamename) Or StringInStr($linestr, "IP Ban") Then $linestr = FileReadLine($logfile, $line - 1) & FileReadLine($logfile, $line) ExitLoop 2 EndIf WEnd EndIf WEnd FileClose($logfile) Return $linestrEndFunc ;==>_FindLastGame; _FindLastGameNumber() returns the last game number made in the games.txt fileFunc _FindLastGameNumber() Local $logfile = FileOpen($gamelog, 0) Local $linestr If $logfile = -1 Then MsgBox(4096, "Error", "Unable to locate the game log.") _FileWriteLog(@ScriptDir & "\MixamAO.log", "ERROR: Unable to locate the game log") Exit EndIf While 1 $linestr = FileReadLine($logfile, $line) If StringInStr($linestr, $gamename) Then $linestr = StringTrimLeft($linestr, (StringInStr($linestr, $gamename, 0, -1) + StringLen($gamename) - 1)) ExitLoop EndIf $line = $line - 1 WEnd FileClose($logfile) Return $linestrEndFunc ;==>_FindLastGameNumber; _LastGameSecsAgo searches the string returned by _FindLastGame and compares its time; to the current time to see how long ago the game was made. Not sure if Number(); is required here or not yet. Have to test without it. The +86400 is for when the game was; made at 00:??:??Func _LastGameSecsAgo() Local $gamehour = Number(StringMid($lastgamestr, 12, 2)) Local $gamemin = Number(StringMid($lastgamestr, 15, 2)) Local $gamesec = Number(StringMid($lastgamestr, 18, 2)) Local $secsago = (@HOUR * 3600 + @MIN * 60 + @SEC) - ($gamehour * 3600 + $gamemin * 60 + $gamesec) If $secsago < 0 Then $secsago = $secsago + 86400 EndIf Return $secsagoEndFunc ;==>_LastGameSecsAgo; This function checks how long ago the 19th game was made. This is so i can detect if; it is likely that 20 games will be made in an hour or less. For preventing r/d.Func _RDGameSecsAgo() Local $logfile = FileOpen($gamelog, 0) Local $rdgame = FileReadLine($logfile, $line - 39) Local $gamehour = Number(StringMid($rdgame, 12, 2)) Local $gamemin = Number(StringMid($rdgame, 15, 2)) Local $gamesec = Number(StringMid($rdgame, 18, 2)) Local $secsago = (@HOUR * 3600 + @MIN * 60 + @SEC) - ($gamehour * 3600 + $gamemin * 60 + $gamesec) If $secsago < 0 Then $secsago = $secsago + 86400 EndIf FileClose($logfile) Return $secsagoEndFunc ;==>_RDGameSecsAgo; This function moves the mouse around in the area around the toolbar to get rid of old icons.; I figured out what worked on 1024 by 768 and used that as a ratio for the other resolutions.Func _CleanTray(ByRef $a) If $a = 1 Then Local $desktophandle = _WinAPI_GetDesktopWindow() Local $desktopheight = _WinAPI_GetClientHeight($desktophandle) Local $desktopwidth = _WinAPI_GetClientWidth($desktophandle) Local $firstcoordx = (800 / 1024) * $desktopwidth Local $bothcoordy = (755 / 768) * $desktopheight Local $secondcoordx = (1000 / 1024) * $desktopwidth MouseMove($firstcoordx, $bothcoordy, 0) MouseMove($secondcoordx, $bothcoordy, 10) MouseMove($firstcoordx, $bothcoordy, 10) EndIf _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: Tray cleaned")EndFunc ;==>_CleanTray; This function changes the defualt exit for auto it to run _kill then exit so exiting MixamAO; will also exit D2 and RedvexFunc OnAutoItExit() _Kill() IniWrite($redvexdir & "Awesom-O.ini", "Bot0", "StartNumber", 1) _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: MixamAO Closed. Game start number changed back to 1") ExitEndFunc ;==>OnAutoItExit