Project1

标题: 【VX\XP】高仿VA控制台 [打印本页]

作者: 张咚咚    时间: 2017-9-11 11:46
标题: 【VX\XP】高仿VA控制台
本帖最后由 张咚咚 于 2018-11-20 17:44 编辑
  1. #==============================================================================
  2. # ■ Console
  3. #     By QQEat
  4. #------------------------------------------------------------------------------
  5. #  高仿VA控制台。
  6. #   puts:控制台打印
  7. #==============================================================================

  8. if $TEST or $DEBUG
  9.   Win32API.new("kernel32", "AllocConsole", "v", "i").call #创建
  10.   #~ Win32API.new("kernel32", "FreeConsole", "v", "i").call #释放
  11.   Win32API.new("kernel32", "SetConsoleTitle", "p", "i").call("RGSS Console") #setTitle
  12.   GetStdHandle = Win32API.new("kernel32", "GetStdHandle", "i", "i") #I/O_hWnd
  13.   WriteConsole = Win32API.new("kernel32", "WriteConsole", "ipiii", "i") #WriteConsole
  14.   GetStringLength = Win32API.new("kernel32", "lstrlenA", "p", "i") #getStringLength
  15.   
  16.   def puts(*args)
  17.     str = ""
  18.     args.each{|a| str << (a.is_a?(String) ? "\"" << a.to_s << "\"" : a.inspect) << "\n" }
  19.    
  20.     #处理编码
  21.     m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
  22.     w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
  23.     len = m2w.call(0xFDE9,0,str,-1,nil,0)
  24.     buf = "\0" * (len*2)
  25.     m2w.call(0xFDE9,0,str,-1,buf,buf.size/2)
  26.     len = w2m.call(0,0,buf,-1,nil,0,nil,nil)
  27.     ret = "\0" * len
  28.     w2m.call(0,0,buf,-1,ret,ret.size,nil,nil)
  29.     str = ret.delete!("\0")
  30.    
  31.     WriteConsole.call(GetStdHandle.call(-12), str, GetStringLength.call(str), 0, 0)
  32.   end
  33. else
  34.   def puts(*args);end
  35. end
  36. HWnd = Win32API.new('user32','FindWindowEx','llpp','i')
  37. Win32API.new('user32','SetForegroundWindow','i','i').call(HWnd.call(0, 0, 'RGSS Player', 0)) if $TEST or $DEBUG #获取焦点置前台
复制代码

作者: guoxiaomi    时间: 2017-9-18 00:08
GetStringLength = Win32API.new("kernel32", "lstrlenA", "p", "i") #getStringLength
这个会不会因为输出中间含有 "\0" 的字符而提前终止?




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1