if $TEST or $DEBUG
Win32API.new("kernel32", "AllocConsole", "v", "i").call # 创建
# Win32API.new("kernel32", "FreeConsole", "v", "i").call # 释放
Win32API.new("kernel32", "SetConsoleTitle", "p", "i").call("RGSS Console") #setTitle
# GetStdHandle = Win32API.new("kernel32", "GetStdHandle", "i", "i") #I/O_hWnd
# WriteConsole = Win32API.new("kernel32", "WriteConsole", "ipiii", "i") #WriteConsole
# GetStringLength = Win32API.new("kernel32", "lstrlenA", "p", "i") #getStringLength
$stdout = open('CONOUT$', 'w')
def puts(*args)
str = args.map{|a| a.inspect }.join("\n")
#处理编码
m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
len = m2w.call(0xFDE9,0,str,-1,nil,0)
buf = "\0" * (len*2)
m2w.call(0xFDE9,0,str,-1,buf,buf.size/2)
len = w2m.call(0,0,buf,-1,nil,0,nil,nil)
ret = "\0" * len
w2m.call(0,0,buf,-1,ret,ret.size,nil,nil)
str = ret.delete!("\0")
$stdout.puts str; $stdout.flush
# WriteConsole.call(GetStdHandle.call(-12), str, GetStringLength.call(str), 0, 0)
end
HWND = Win32API.new('user32','FindWindowEx','llpp','i').call(0, 0, 'RGSS Player', 0)
Win32API.new('user32','SetForegroundWindow','i','i').call HWND
else
def puts(*args);end
end