[COLOR=#669900]#============================================================================== [/COLOR][/FONT]
[COLOR=#669900]# Console [/COLOR][/FONT]
[COLOR=#669900]#============================================================================== [/COLOR][/FONT]
[COLOR=#669900]# This module works much like the Logging module, only instead of saving to a [/COLOR][/FONT]
[COLOR=#669900]# file, output goes to a debugging window. The window only shows up in Debug [/COLOR][/FONT]
[COLOR=#669900]# mode, so launching it from RMXP it will show up, but it won't when run from [/COLOR][/FONT]
[COLOR=#669900]# Game.exe. [/COLOR][/FONT]
[COLOR=#669900]# To use the console, simply call Console::setup() from your Main script, then [/COLOR][/FONT]
[COLOR=#669900]# use echo(string) from any other script you want, like you would print(). [/COLOR][/FONT]
[COLOR=#669900]# [/COLOR][/FONT]
[COLOR=#669900]# The Console allows for quick access to information without having to open a log [/COLOR][/FONT]
[COLOR=#669900]# and without bringing up a message window that halts progress, so it's perfect [/COLOR][/FONT]
[COLOR=#669900]# [/COLOR][COLOR=#0000aa]for[/COLOR][COLOR=#669900] having to track changes in a loop with many iterations. My own tests show [/COLOR][/FONT]
[COLOR=#669900]# no lag, so it should be all good. [/COLOR][/FONT]
[COLOR=#669900]#============================================================================== [/COLOR][/FONT]
[COLOR=#0000aa]module[/COLOR] Console [/FONT]
attr_reader :bufferHandle [/FONT]
GENERIC_READ = 0x80000000 [/FONT]
GENERIC_WRITE = 0x40000000 [/FONT]
FILE_SHARE_READ = 0x00000001 [/FONT]
FILE_SHARE_WRITE = 0x00000002 [/FONT]
CONSOLE_TEXTMODE_BUFFER = 0x00000001 [/FONT]
[COLOR=#0000aa]def[/COLOR] Console::AllocConsole [/FONT]
return @apiAllocConsole.call [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
[COLOR=#0000aa]def[/COLOR] Console::CreateConsoleScreenBuffer(dwDesiredAccess,dwShareMode,dwFlags) [/FONT]
return @apiCreateConsoleScreenBuffer.call(dwDesiredAccess,dwShareMode,nil,dwFlags,nil) [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
[COLOR=#0000aa]def[/COLOR] Console::WriteConsole(lpBuffer) [/FONT]
hFile = @bufferHandle [/FONT]
return @apiWriteConsole.call(hFile,lpBuffer,lpBuffer.size,0,0) [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
[COLOR=#0000aa]def[/COLOR] Console::SetConsoleActiveScreenBuffer(hScreenBuffer) [/FONT]
return @apiSetConsoleActiveScreenBuffer.call(hScreenBuffer) [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
[COLOR=#0000aa]def[/COLOR] Console::SetConsoleTitle(title) [/FONT]
return @apiSetConsoleTitle.call(title) [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
[COLOR=#0000aa]def[/COLOR] self.setup [/FONT]
unless $DEBUG [/FONT]
return [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
@apiAllocConsole = Win32API.new([COLOR=#800080]"kernel32","AllocConsole","","l"[/COLOR]) [/FONT]
@apiCreateConsoleScreenBuffer = Win32API.new([COLOR=#800080]"kernel32","CreateConsoleScreenBuffer",['l','l','p','l','p'],"l"[/COLOR]) [/FONT]
@apiSetConsoleActiveScreenBuffer = Win32API.new([COLOR=#800080]"kernel32","SetConsoleActiveScreenBuffer","l","s"[/COLOR]) [/FONT]
@apiWriteConsole = Win32API.new([COLOR=#800080]"kernel32","WriteConsole","lpnnn","S"[/COLOR]) [/FONT]
@apiSetConsoleTitle = Win32API.new([COLOR=#800080]"kernel32","SetConsoleTitle","p","s"[/COLOR]) [/FONT]
access = (GENERIC_READ | GENERIC_WRITE) [/FONT]
sharemode = (FILE_SHARE_READ | FILE_SHARE_WRITE) [/FONT]
returnCode = AllocConsole() [/FONT]
@bufferHandle = CreateConsoleScreenBuffer(access,sharemode,CONSOLE_TEXTMODE_BUFFER) [/FONT]
f = File.open([COLOR=#800080]"Game.ini"[/COLOR]) [/FONT]
lines = f.readlines() [/FONT]
s = lines[3] [/FONT]
len = s.size [/FONT]
title = (s[6,len - 7]) [/FONT]
SetConsoleTitle([/FONT][COLOR=#800080]"Debug Console -- #{title}") [/COLOR][/FONT]
echo [/FONT][COLOR=#800080]"#{title} Output Window\n" [/COLOR][/FONT]
echo [COLOR=#800080]"-------------------------------\n"[/COLOR] [/FONT]
echo [COLOR=#800080]"If you are seeing this window, you are running\n"[/COLOR] [/FONT]
echo [/FONT][COLOR=#800080]"#{title} in Debug Mode. This means\n" [/COLOR][/FONT]
echo [COLOR=#800080]"that you're either playing a Debug Version, or\n"[/COLOR] [/FONT]
echo [COLOR=#800080]"you are playing from within RPG Maker XP.\n"[/COLOR] [/FONT]
echo [COLOR=#800080]"\n"[/COLOR] [/FONT]
echo [COLOR=#800080]"Closing this window will close the game. If \n"[/COLOR] [/FONT]
echo [COLOR=#800080]"you want to get rid of this window, run the\n"[/COLOR] [/FONT]
echo [COLOR=#800080]"program from the Shell, or download a Release\n"[/COLOR] [/FONT]
echo [COLOR=#800080]"version.\n"[/COLOR] [/FONT]
echo [COLOR=#800080]"\n"[/COLOR] [/FONT]
echo [COLOR=#800080]"Gameplay will be paused while the console has\n"[/COLOR] [/FONT]
echo [COLOR=#800080]"focus. To resume playing, switch to the Game\n"[/COLOR] [/FONT]
echo [COLOR=#800080]"Window.\n"[/COLOR] [/FONT]
echo [COLOR=#800080]"-------------------------------\n"[/COLOR] [/FONT]
echo [COLOR=#800080]"Debug Ouput:\n"[/COLOR] [/FONT]
echo [COLOR=#800080]"-------------------------------\n\n"[/COLOR] [/FONT]
SetConsoleActiveScreenBuffer(@bufferHandle) [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
[COLOR=#0000aa]def[/COLOR] self.get_input [/FONT]
[COLOR=#0000aa]loop[/COLOR] do [/FONT]
poo = $stdin [/FONT]
[COLOR=#0000aa]if[/COLOR] poo[poo.size - 1] == [COLOR=#800080]"\n"[/COLOR] [/FONT]
break [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
echo poo [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
[COLOR=#0000aa]module[/COLOR] Kernel [/FONT]
[COLOR=#0000aa]def[/COLOR] echo(string) [/FONT]
unless $DEBUG [/FONT]
return [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
Console::WriteConsole(string) [/FONT]
[COLOR=#0000aa]end[/COLOR] [/FONT]
[COLOR=#0000aa]end[/COLOR][/FONT]