The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
MixamAO beta5prerelease.au3
Posted by: MixamAO beta5prerelease.au3 | March 12, 2008 @ 4:06pm
AutoIT Code
[
Download
]
#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> #include <GuiToolBar.au3> Global $thisprogram = "MixamAO beta5" Global $redvexname = IniRead($thisprogram & ".ini", "Settings", "RedVex", "") Global $preventrd = IniRead($thisprogram & ".ini", "Settings", "RDprevention", "1") Global $managelogs = IniRead($thisprogram & ".ini", "Settings", "ManageLogs", "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") Global $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 $line = 0 Global $mixamAOlog = (@ScriptDir & "\MixamAO.log") Global $lastgamestr, $runforsecs, $rdgametime Global $nextgamenumber = 1 Global $newlogfolder = @ScriptDir & "\Game Logs\" & @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & "." & @MIN & "." & @SEC Opt("TrayAutoPause",0) TraySetClick(8) 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") Opt("OnExitFunc", "_normalexit") Exit EndIf If 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() EndIf If Not FileExists($thisprogram & ".ini") Then MsgBox(4096, "Error", "Can't find " & $thisprogram & ".ini :(") _FileWriteLog(@ScriptDir & "\MixamAO.log", "ERROR: Can't find " & $thisprogram & ".ini :(") Exit EndIf If Not FileExists($mixamAOlog) Then _FileCreate(@ScriptDir & "\MixamAO.log") _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: MixamAO.log was missing. It has been created") EndIf If Not FileExists($redvexexe) Then MsgBox(4096, "Error", "Can't find " & $redvexexe & " :(") _FileWriteLog(@ScriptDir & "\MixamAO.log", "ERROR: Can't find " & $redvexexe & " :(") Exit EndIf _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. ; Also now saves all the log files to Game Logs folder in the MixamAO folder Func _Kill() ProcessClose($redvexname & ".exe") ProcessClose($diabloprocess) If ProcessExists($diabloprocess) Then While ProcessExists($diabloprocess) ProcessClose($diabloprocess) WEnd EndIf _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: Redvex and D2 killed") IniWrite($redvexdir & "Awesom-O.ini", "Bot0", "StartNumber", $nextgamenumber) _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: game start number changed to " & $nextgamenumber) _CleanTray($redvexname, $refreshtray) If $managelogs = 1 Then DirCreate($newlogfolder) FileCopy ($redvexdir & "\Awesom-O.log", $newlogfolder & "\" & @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & "." & @MIN & "." & @SEC & " Awesom-O.log") EndIf EndFunc ;==>_Kill ; _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() If $lastgamestr = "Empty" Then $nextgamenumber = 1 Else $nextgamenumber = _FindLastGameNumber() + 1 EndIf 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 If WinExists("End Program - Diablo_0") Then WinClose("End Program - Diablo_0") _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: End Program window detected. Closing D2") If ProcessExists($diabloprocess) Then While ProcessExists($diabloprocess) ProcessClose($diabloprocess) WEnd EndIf EndIf If WinExists("Diablo_0: Diablo II.exe - Application Error") Then WinClose("Diablo_0: Diablo II.exe - Application Error") _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: Application Error window detected. Closing D2") If ProcessExists($diabloprocess) Then While ProcessExists($diabloprocess) ProcessClose($diabloprocess) WEnd EndIf EndIf 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 Not ProcessExists($redvexname & ".exe") Then _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: Detected that Redvex is not running") _Kill() _Load() EndIf EndFunc ;==>_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 support Func _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 $line >= 0 $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 $linstr = "Empty" ExitLoop EndIf WEnd FileClose($logfile) Return $linestr EndFunc ;==>_FindLastGame ; _FindLastGameNumber() returns the last game number made in the games.txt file Func _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 If ($line = 0 And $nextgamenumber = 1) Then _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: No games found, setting last game number to 0") FileClose($logfile) Sleep(5000) Return 0 ElseIf ($line = 0 And $nextgamenumber <> 1) Then _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: No games found, setting last game number to last found lastgamenumber") Return $nextgamenumber - 1 EndIf While 1 If $line = 0 Then _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: No games found, setting last game number to last found lastgamenumber") Return $nextgamenumber - 1 EndIf $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 $linestr EndFunc ;==>_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() If $lastgamestr = "Empty" Then Sleep(120000) $lastgamestr = _FindLastGame() If $lastgamestr = "Empty" Then Return ($maxgametimesecs + 1) EndIf EndIf 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 $secsago EndFunc ;==>_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 If $line < 39 Then FileClose($logfile) Return 3601 Else $rdgame = FileReadLine($logfile, $line - 39) EndIf 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 $secsago EndFunc ;==>_RDGameSecsAgo ; This function clicks on each icon with the name = $iTitle to remove the old icons at the moment it does ; The Redvex icons, but if kingsob brings back the Awesom-O icon then I can clean that too. Func _CleanTray($iTitle, $a) If $a = 1 Then Local $hToolbar, $ItemCount, $ID, $i $hToolbar = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]') If @error Then Return $ItemCount = _GUICtrlToolbar_ButtonCount($hToolbar) If $ItemCount = 0 Then Return For $i = 0 To $ItemCount - 1 $ID = _GUICtrlToolbar_IndexToCommand($hToolbar, $i) If StringInStr(_GUICtrlToolbar_GetButtonText($hToolbar, $ID), $iTitle) Then _GUICtrlToolbar_ClickButton2($hToolbar, $ID) Sleep(50) EndIf Next _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: Tray cleaned") EndIf EndFunc ; #FUNCTION# ==================================================================================================== ; Name...........: _GUICtrlToolbar_ClickButton ; Description ...: Clicks a specific button ; Syntax.........: _GUICtrlToolbar_ClickButton($hWnd, $iCommandID[, $sButton = "left"[, $fMove = False[, $iClicks = 1[, $iSpeed = 1]]]]) ; Parameters ....: $hWnd - Handle to the control ; $iCommandID - Button command ID ; $sButton - Button to click ; $fMove - Mouse movement flag: ; | True - Mouse will be moved ; |False - Mouse will not be moved ; $iClicks - Number of clicks ; $iSpeed - Mouse movement speed ; Return values .: ; Author ........: Paul Campbell (PaulIA) ; Modified.......: Gary Frost ; Remarks .......: ; Related .......: _GUICtrlToolbar_ClickAccel, _GUICtrlToolbar_ClickIndex ; Link ..........; ; Example .......; Yes ; ============================================================================================================== Func _GUICtrlToolbar_ClickButton2($hWnd, $iCommandID, $sButton = "left", $fMove = False, $iClicks = 1, $iSpeed = 1) If $Debug_TB Then _GUICtrlToolbar_ValidateClassName($hWnd) Local $tPoint, $tRect, $iX, $iY, $iMode, $aPos $tRect = _GUICtrlToolbar_GetButtonRectEx($hWnd, $iCommandID) $tPoint = _WinAPI_PointFromRect2($tRect) $tPoint = _WinAPI_ClientToScreen($hWnd, $tPoint) _WinAPI_GetXYFromPoint2($tPoint, $iX, $iY) If Not $fMove Then $iMode = Opt("MouseCoordMode", 1) $aPos = MouseGetPos() Opt("MouseCoordMode", $iMode) _WinAPI_ShowCursor(False) MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed) MouseMove($aPos[0], $aPos[1], 0) _WinAPI_ShowCursor(True) Else MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed) EndIf EndFunc ;==>_GUICtrlToolbar_ClickButton ; #FUNCTION# ==================================================================================================== ; Description ...: Returns the top/left coordinates of a tagRECT as a tagPOINT structure ; Parameters ....: $tRect - tagRECT structure ; $fCenter - If True, the return will be a point at the center of the rectangle, otherwise the left/top ; +coordinates are returned. ; Return values .: Success - tagPOINT structure ; Author ........: Paul Campbell (PaulIA) ; Remarks .......: This function is used to get the click position for many of the click functions in the library ; Related .......: ; =============================================================================================================== Func _WinAPI_PointFromRect2(ByRef $tRect, $fCenter = True) Local $iX1, $iY1, $iX2, $iY2, $tPoint $iX1 = DllStructGetData($tRect, "Left") $iY1 = DllStructGetData($tRect, "Top") $iX2 = DllStructGetData($tRect, "Right") $iY2 = DllStructGetData($tRect, "Bottom") If $fCenter Then $iX1 = $iX1 + (($iX2 - $iX1) / 2) $iY1 = $iY1 + (($iY2 - $iY1) / 2) EndIf $tPoint = DllStructCreate($tagPOINT) DllStructSetData($tPoint, "X", $iX1) DllStructSetData($tPoint, "Y", $iY1) Return $tPoint EndFunc ;==>_WinAPI_PointFromRect ; #FUNCTION# ==================================================================================================== ; Description ...: Returns the X/Y values from a tagPOINT structure ; Parameters ....: $tPoint - tagPOINT structure ; $iX - X value ; $iY - Y value ; Return values .: ; Author ........: Paul Campbell (PaulIA) ; Remarks .......: This function extracts the X/Y values from a tagPOINT structure ; Related .......: _Lib_GetPointFromXY, _Lib_GetXYFromRect ; =============================================================================================================== Func _WinAPI_GetXYFromPoint2(ByRef $tPoint, ByRef $iX, ByRef $iY) $iX = DllStructGetData($tPoint, "X") $iY = DllStructGetData($tPoint, "Y") EndFunc ;==>_WinAPI_GetXYFromPoint ; This function changes the defualt exit for auto it to run _kill then exit so exiting MixamAO ; will also exit D2 and Redvex Func _cleangameslog() _FileCreate ($gamelog & ".temp.txt") Local $lines = _FileCountLines($gamelog) Local $hgamelog = FileOpen($gamelog, 0) For $x = ($lines - 39) to $lines If $x > 0 Then FileWriteLine($gamelog & ".temp.txt", FileReadLine($hgamelog, $x)) EndIf Next FileClose($hgamelog) FileMove($gamelog & ".temp.txt", $gamelog, 1) EndFunc Func _normalexit() Exit EndFunc Func OnAutoItExit() _Kill() IniWrite($redvexdir & "Awesom-O.ini", "Bot0", "StartNumber", 1) _FileWriteLog(@ScriptDir & "\MixamAO.log", "Notice: MixamAO Closed Manually. Game start number changed back to 1") If $managelogs = 1 Then DirCreate($newlogfolder) FileMove (@ScriptDir & "\MixamAO.log", $newlogfolder & "\MixamAO.log") _FileCreate(@ScriptDir & "\MixamAO.log") FileCopy ($gamelog, $newlogfolder & "\games.txt") _cleangameslog() $line = 0 EndIf Exit EndFunc ;==>OnAutoItExit
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.62 / 8
181 Votes
http://codebin.yi.org/136
page generated in 0.01 seconds