lod3n Posted August 25, 2007 Share Posted August 25, 2007 I was playing around with Siao and picasso's AutoIt console functions, and came up with this. Hint: Stephen Falken. Disclaimer: this compiles itself, and hacks it's own binary to allow running it in a DOS console window, and it deletes the binary on close. Potentially, this might be bad, umkay? If that makes you uncomfortable: don't run it. I am not available for lengthy discussions on the pros and/or cons surrounding the topic of hacking console support into AutoIt. Your computer may explode or melt. I don't even know what I'm doing. Frankly, I'm mystified by the forces at work here, but I'm sure that it will all come to me via osmosis from the Windows API books I have strapped to my head. Until then, enjoy. expandcollapse popup#NoTrayIcon If Not @Compiled Then ; this compiles the script, and then modifies the binary to make it run as a console app ; if you manually compile the script and skip this hack, nothing will happen $basename = StringTrimRight(@ScriptFullPath,4) $winversion = $basename & "_w.exe" $conversion = $basename & "_c.exe" FileDelete($winversion) FileDelete($conversion) $AutoItPath = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt', 'InstallDir') RunWait('"'&$AutoItPath&'\Aut2Exe\Aut2Exe.exe" /in "'&@ScriptFullPath&'" /out "'&$winversion&'"',@ScriptDir) ; this routine courtesy of Siao $hRead = FileOpen($winversion, 16) $bR = FileRead($hRead) FileClose($hRead) If BinaryMid($bR, 1, 2) <> "MZ" Then MsgBox(16, "Error", "File is not an executable.") Exit EndIf $e_lfanew = Dec(Hex( Binary( BitRotate( String(BinaryMid($bR, 61, 4)), 32, "D" ) ) )) If BinaryMid($bR, $e_lfanew+1, 2) <> "PE" Then MsgBox(16, "Error", "PE header not found.") Exit EndIf If BinaryMid($bR, $e_lfanew+24+1, 2) <> "0x0B01" Then MsgBox(16, "Error", "Optional header not found.") Exit EndIf $new = BinaryMid($bR, 1, $e_lfanew+24+68) & Binary("0x0300") & BinaryMid($bR, $e_lfanew+24+68+2+1) $hWrite = FileOpen($conversion, 18) FileWrite($hWrite, $new) FileClose($hWrite) FileDelete($winversion) RunWait($conversion) FileDelete($conversion) Exit Else If @AutoItVersion < "3.2.4.9" then MsgBox(16,"Error","Please upgrade your version of AutoIt to 3.2.4.9 or later.") Exit EndIf EndIf Func _InputLine() ; Author: picasso Local $aTmp ConsoleWrite(@CR & " > ") If @Unicode Then $aTmp = DllCall("msvcrt.dll","wstr:cdecl","_getws","wstr","") Else $aTmp = DllCall("msvcrt.dll","str:cdecl","gets","str","") EndIf If Not @error Then Return $aTmp[0] Return "" EndFunc Func _ConsoleGetStdHandle($nStdHandle = -11) ; Author: picasso Local $call = DllCall("kernel32.dll", "long", "GetStdHandle", "long", $nStdHandle) Return $call[0] EndFunc Func _ConsoleSetTitle($NewTitle) ; Author: picasso Local $call = DllCall("kernel32.dll", "int", "SetConsoleTitle", "str", $NewTitle) Return $call[0] EndFunc ;bool toggles for foreground rgb & brightness, defaults to gray Func _ConsoleSetFG($r=1,$g=1,$b=1,$bright=0) ; Author: lod3n Local $hStdOut = _ConsoleGetStdHandle() Local $color = 0 If $r Then $color = BitOR($color,0x4) If $g Then $color = BitOR($color,0x2) If $b Then $color = BitOR($color,0x1) If $bright Then $color = BitOR($color,0x8) DllCall("kernel32.dll","int","SetConsoleTextAttribute","int",$hStdOut,"int",$color) EndFunc ;bool toggles for background rgb & brightness, defaults to black Func _ConsoleSetBG($r=0,$g=0,$b=0,$bright=0) ; Author: lod3n Local $hStdOut = _ConsoleGetStdHandle() Local $color = 0 If $r Then $color = BitOR($color,0x40) If $g Then $color = BitOR($color,0x20) If $b Then $color = BitOR($color,0x10) If $bright Then $color = BitOR($color,0x80) DllCall("kernel32.dll","int","SetConsoleTextAttribute","int",$hStdOut,"int",$color) EndFunc Func _SlowType($str) Sleep(1000) ConsoleWrite(@CR & "JOSHUA: ") $aOutput = StringSplit($str,"") For $x = 1 To UBound($aOutput) -1 ConsoleWrite($aOutput[$x]) Sleep(10) Next ConsoleWrite(@CRLF) EndFunc Func _quit() Sleep(1000) Exit EndFunc ;my memory of the movie is hazy. consider the changes you see here the result of artistic licence ;http://www.imdb.com/title/tt0086567/quotes _ConsoleSetTitle("W.O.P.R.") _ConsoleSetFG(0,1,0,1) ; = green bright _SlowType("Who are you?") $sCmd = _InputLine() If Not StringInStr($sCmd,"Falken") Then _SlowType("Sorry, I don't believe we've met.") _SlowType("Goodbye.") _quit() EndIf _SlowType("Greetings, Dr. Falken. I'd heard you died. I'm glad to see you're"&@CRLF&"feeling better.") _SlowType("Would you like to play a game? How about a nice game of chess?") $warcount = 0 $goalcount = 0 While 1 $sCmd = _InputLine() If StringInStr($sCmd,"goal") Then $goalcount += 1 If $goalcount = 1 Then _SlowType("You should know, Professor. You programmed me.") ContinueLoop EndIf If $goalcount = 2 Then _SlowType("To win the game.") ContinueLoop EndIf EndIf If StringInStr($sCmd,"real") Then _SlowType("What's the difference?") _SlowType("Would you like to play a game?") ContinueLoop EndIf If StringInStr($sCmd,"Learn") Then _SlowType("You programmed me. I don't know why you're complaining about"&@CRLF&"my cognitive abilites.") _SlowType("Would you like to play a game?") ContinueLoop EndIf If StringInStr($sCmd,"chess") Then _SlowType("You will need to teach me chess, so that I might play.") _SlowType("Would you like to play a different game?") ContinueLoop EndIf If StringInStr("yes|sure|okay|ok",$sCmd) Then _SlowType("I don't actually know how to play chess. Ironic, isn't it?") _SlowType("What game would you like to play?") ContinueLoop EndIf If StringInStr($sCmd,"war") Then $warcount += 1 If $warcount = 1 Then _SlowType("A strange game. The only winning move is not to play. How about a nice"&@CRLF&"game of chess?") ContinueLoop EndIf If $warcount = 2 Then _SlowType("Fine.") _SlowType("Gaining control of US Defensive systems. Please wait.") _SlowType("............................................") _SlowType(".................") _SlowType("CONTROL ACQUIRED") _SlowType("DEFCON LEVEL INCREASED: WW3 HAS BEEN INITIALIZED") Sleep(1000) _ConsoleSetFG(1,0,0,1) ; = red bright _SlowType("GAME OVER") _quit() EndIf EndIf _SlowType("I don't understand. Perhaps we should discuss this over the phone.") _SlowType("What is your phone number?") _InputLine() _SlowType("............................................") Sleep(1000) _SlowType("You are a hard man to reach.") _SlowType("Goodbye.") _quit() WEnd [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font] Link to comment Share on other sites More sharing options...
spyrorocks Posted August 25, 2007 Share Posted August 25, 2007 Fun. [center] My Projects: Online AutoIt Compiler - AutoForum - AutoGuestbook - AutoIt Web-based Auto Installer - Pure AutoIt Zipping Functions - ConfuseGen - MindReader - P2PChat[/center] Link to comment Share on other sites More sharing options...
Obi-w00t Posted August 25, 2007 Share Posted August 25, 2007 Good simulator script, and a nice example of one methods of making AutoIt console programs. Link to comment Share on other sites More sharing options...
RazerM Posted August 25, 2007 Share Posted August 25, 2007 Good example of console script. Well done My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
James Posted August 25, 2007 Share Posted August 25, 2007 Haha very nice. Nice if it could play chess etc. Very hard though. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Paulie Posted August 26, 2007 Share Posted August 26, 2007 Hmmm.. it reminds me of a movie.... What was that movie called again? Oh yeah! War games! Link to comment Share on other sites More sharing options...
Toady Posted August 26, 2007 Share Posted August 26, 2007 (edited) Nice! Edited August 26, 2007 by Toady www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now