赞 | 153 |
VIP | 10 |
好人卡 | 39 |
积分 | 93 |
经验 | 146191 |
最后登录 | 2024-5-6 |
在线时间 | 2504 小时 |
Lv4.逐梦者
- 梦石
- 0
- 星屑
- 9280
- 在线时间
- 2504 小时
- 注册时间
- 2011-5-20
- 帖子
- 15389
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
=begin 该脚本用于截图,F5为截图快捷键,VXVA通用 =end #============================================================================== # ■ Kernel #------------------------------------------------------------------------------ # 该模块中定义了可供所有类使用的方法。Object 类中包含了该模块。 #============================================================================== module Kernel #-------------------------------------------------------------------------- # ● 需要的 Windows API 函数 #-------------------------------------------------------------------------- GetWindowThreadProcessId = Win32API.new("user32", "GetWindowThreadProcessId", "LP", "L") GetWindow = Win32API.new("user32", "GetWindow", "LL", "L") GetClassName = Win32API.new("user32", "GetClassName", "LPL", "L") GetCurrentThreadId = Win32API.new("kernel32", "GetCurrentThreadId", "V", "L") GetForegroundWindow = Win32API.new("user32", "GetForegroundWindow", "V", "L") #-------------------------------------------------------------------------- # ● 获取窗口句柄 #-------------------------------------------------------------------------- def get_hWnd # 获取调用线程(RM 的主线程)的进程标识 threadID = GetCurrentThreadId.call # 获取 Z 次序中最靠前的窗口 hWnd = GetWindow.call(GetForegroundWindow.call, 0) # 枚举所有窗口 while hWnd != 0 # 如果创建该窗口的线程标识匹配本线程标识 if threadID == GetWindowThreadProcessId.call(hWnd, 0) # 分配一个 11 个字节的缓冲区 className = " " * 11 # 获取该窗口的类名 GetClassName.call(hWnd, className, 12) # 如果匹配 RGSS Player 则跳出循环 break if className == "RGSS Player" end # 获取下一个窗口 hWnd = GetWindow.call(hWnd, 2) end return hWnd end end #============================================================================== # ■ Bitmap #------------------------------------------------------------------------------ # 处理影像的类。 #============================================================================== class Bitmap RtlMoveMemory = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i') #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def address # [[[bitmap.object_id * 2 + 16] + 8] + 16] == 数据的开头 buffer, ad = "xxxx", object_id * 2 + 16 RtlMoveMemory.call(buffer, ad, 4) ad = buffer.unpack("L")[0] + 8 RtlMoveMemory.call(buffer, ad, 4) ad = buffer.unpack("L")[0] + 16 RtlMoveMemory.call(buffer, ad, 4) return buffer.unpack("L")[0] end end #============================================================================== # ■ Bitmap #------------------------------------------------------------------------------ # 处理影像的类。 #============================================================================== class Bitmap RtlMoveMemory = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i') #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def address # [[[bitmap.object_id * 2 + 16] + 8] + 16] == 数据的开头 buffer, ad = "xxxx", object_id * 2 + 16 RtlMoveMemory.call(buffer, ad, 4) ad = buffer.unpack("L")[0] + 8 RtlMoveMemory.call(buffer, ad, 4) ad = buffer.unpack("L")[0] + 16 RtlMoveMemory.call(buffer, ad, 4) return buffer.unpack("L")[0] end end #============================================================================== # ■ Bitmap #------------------------------------------------------------------------------ # 位图的类。所谓位图即表示图像其本身。 #============================================================================== class Bitmap #-------------------------------------------------------------------------- # ● 传送到内存的API函数 #-------------------------------------------------------------------------- RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i') #-------------------------------------------------------------------------- # ● Bitmap地址 #-------------------------------------------------------------------------- # [[[bitmap.object_id * 2 + 16] + 8] + 16] == 数据的开头 def address buffer, ad = "rgba", object_id * 2 + 16 RtlMoveMemory_pi.call(buffer, ad, 4) ad = buffer.unpack("L")[0] + 8 RtlMoveMemory_pi.call(buffer, ad, 4) ad = buffer.unpack("L")[0] + 16 RtlMoveMemory_pi.call(buffer, ad, 4) return buffer.unpack("L")[0] end module Bitmap2PNG module_function Malloc = Win32API.new('msvcrt.dll','malloc','i','i') Memcpy_pi = Win32API.new('kernel32.dll','RtlMoveMemory','pii','v') Memcpy_ii = Win32API.new('kernel32.dll','RtlMoveMemory','iii','v') Memcpy_ip = Win32API.new('kernel32.dll','RtlMoveMemory','ipi','v') Free = Win32API.new('msvcrt.dll','free','i','v') Callsub = Win32API.new('user32.dll','CallWindowProcW','iiiii','i') #-------------------------------------------------------------------------- # ● 主处理 #-------------------------------------------------------------------------- def make_png(bitmap_Fx) @bitmap_Fx = bitmap_Fx return make_header + make_ihdr + make_idat + make_iend end #-------------------------------------------------------------------------- # ● PNG文件头数据块 #-------------------------------------------------------------------------- def make_header return [0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a].pack("C*") end #-------------------------------------------------------------------------- # ● PNG文件情报头数据块(IHDR) #-------------------------------------------------------------------------- def make_ihdr ih_size = [13].pack("N") ih_sign = "IHDR" ih_width = [@bitmap_Fx.width].pack("N") ih_height = [@bitmap_Fx.height].pack("N") ih_bit_depth = [8].pack("C") ih_color_type = [6].pack("C") ih_compression_method = [0].pack("C") ih_filter_method = [0].pack("C") ih_interlace_method = [0].pack("C") string = ih_sign + ih_width + ih_height + ih_bit_depth + ih_color_type + ih_compression_method + ih_filter_method + ih_interlace_method ih_crc = [Zlib.crc32(string)].pack("N") return ih_size + string + ih_crc end #-------------------------------------------------------------------------- # ● 生成图像数据(IDAT) #-------------------------------------------------------------------------- def make_idat header = "IDAT" data = make_bitmap_data_dant data = Zlib::Deflate.deflate(data) crc = [Zlib.crc32(header + data)].pack("N") size = [data.length].pack("N") return size + header + data + crc end #-------------------------------------------------------------------------- # ● 从Bitmap对象的原始数据生成PNG图像数据 #-------------------------------------------------------------------------- def make_bitmap_data_dant len = @bitmap_Fx.width * @bitmap_Fx.height * 4 pBuf = Malloc.call(len) bitmap=@bitmap_Fx#.reverse addr=bitmap.address Memcpy_ii.call(pBuf,addr,len) Callsub.call(@pCode,pBuf,bitmap.width*bitmap.height,0,0) len2=len+bitmap.height len3=bitmap.width*4 pBuf2 = Malloc.call(len2+512) pos=pBuf2 pos2=pBuf+len-len3 Memcpy_ip.call(pos,0.chr,1) pos+=1 for i in 0...bitmap.height Memcpy_ii.call(pos,pos2,len3) pos+=len3 pos2-=len3 Memcpy_ip.call(pos,0.chr,1) pos+=1 end buf="\0"*len2 Memcpy_pi.call(buf,pBuf2,len2) Free.call(pBuf) Free.call(pBuf2) #~ bitmap.dispose return buf end #-------------------------------------------------------------------------- # ● PNG文件尾数据块(IEND) #-------------------------------------------------------------------------- def make_iend return [0x00,0x00,0x00,0x00,0x49,0x45,0x4E,0x44,0xAE,0x42,0x60,0x82].pack("C*") #ie_size = [0].pack("N") #ie_sign = "IEND" #ie_crc = [Zlib.crc32(ie_sign)].pack("N") #return ie_size + ie_sign + ie_crc end def init @pCode=Malloc.call(512) =begin qwe proc src,pixels,un,used mov eax,src xor ecx,ecx .while ecx < pixels mov edx,[eax] ;AARRGGBB|BB GG RR AA bswap edx ;BBGGRRAA|AA RR GG BB ror edx,8 ;AABBGGRR|RR GG BB AA mov [eax],edx inc ecx add eax,4 .endw ret qwe endp =end code = [0x55,0x8B,0xEC,0x8B,0x45,0x8,0x33,0xC9,0xEB,0xD,0x8B,0x10,0xF,0xCA,0xC1,0xCA,0x8,0x89,0x10,0x41,0x83,0xC0,0x4,0x3B,0x4D,0xC,0x72,0xEE,0xC9,0xC2,0x10,0x0].pack('C*') Memcpy_ip.call(@pCode,code,code.length) end def close Free.call(@pCode) end end #Bitmap2PNG def save_png(filename) File.open(filename,"wb"){|f|f.write(Bitmap2PNG.make_png(self))} end end #Bitmap Bitmap::Bitmap2PNG.init END {Bitmap::Bitmap2PNG.close} class << Graphics alias s_update update unless method_defined?(:s_update) def update Screenshot.shot if Input.trigger?(Screenshot::KEY) s_update end end module Screenshot KEY = Input::F5 #截图的快捷键 DIR = "Screenshot" #截图保存目录 def self.shot Dir.mkdir(DIR) unless File.directory?(DIR) time_now = Time.now.strftime("%Y-%m-%d %H-%M-%S") if File.exist?("#{DIR}/#{time_now}.png") index = 2 index += 1 while File.exist?("#{DIR}/#{time_now}_#{index}.png") filename = "#{DIR}/#{time_now}_#{index}.png" else filename = "#{DIR}/#{time_now}.png" end Graphics.snap_to_bitmap.save_png(filename) end end
=begin
该脚本用于截图,F5为截图快捷键,VXVA通用
=end
#==============================================================================
# ■ Kernel
#------------------------------------------------------------------------------
# 该模块中定义了可供所有类使用的方法。Object 类中包含了该模块。
#==============================================================================
module Kernel
#--------------------------------------------------------------------------
# ● 需要的 Windows API 函数
#--------------------------------------------------------------------------
GetWindowThreadProcessId = Win32API.new("user32", "GetWindowThreadProcessId", "LP", "L")
GetWindow = Win32API.new("user32", "GetWindow", "LL", "L")
GetClassName = Win32API.new("user32", "GetClassName", "LPL", "L")
GetCurrentThreadId = Win32API.new("kernel32", "GetCurrentThreadId", "V", "L")
GetForegroundWindow = Win32API.new("user32", "GetForegroundWindow", "V", "L")
#--------------------------------------------------------------------------
# ● 获取窗口句柄
#--------------------------------------------------------------------------
def get_hWnd
# 获取调用线程(RM 的主线程)的进程标识
threadID = GetCurrentThreadId.call
# 获取 Z 次序中最靠前的窗口
hWnd = GetWindow.call(GetForegroundWindow.call, 0)
# 枚举所有窗口
while hWnd != 0
# 如果创建该窗口的线程标识匹配本线程标识
if threadID == GetWindowThreadProcessId.call(hWnd, 0)
# 分配一个 11 个字节的缓冲区
className = " " * 11
# 获取该窗口的类名
GetClassName.call(hWnd, className, 12)
# 如果匹配 RGSS Player 则跳出循环
break if className == "RGSS Player"
end
# 获取下一个窗口
hWnd = GetWindow.call(hWnd, 2)
end
return hWnd
end
end
#==============================================================================
# ■ Bitmap
#------------------------------------------------------------------------------
# 处理影像的类。
#==============================================================================
class Bitmap
RtlMoveMemory = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
#--------------------------------------------------------------------------
# ●
#--------------------------------------------------------------------------
def address
# [[[bitmap.object_id * 2 + 16] + 8] + 16] == 数据的开头
buffer, ad = "xxxx", object_id * 2 + 16
RtlMoveMemory.call(buffer, ad, 4)
ad = buffer.unpack("L")[0] + 8
RtlMoveMemory.call(buffer, ad, 4)
ad = buffer.unpack("L")[0] + 16
RtlMoveMemory.call(buffer, ad, 4)
return buffer.unpack("L")[0]
end
end
#==============================================================================
# ■ Bitmap
#------------------------------------------------------------------------------
# 处理影像的类。
#==============================================================================
class Bitmap
RtlMoveMemory = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
#--------------------------------------------------------------------------
# ●
#--------------------------------------------------------------------------
def address
# [[[bitmap.object_id * 2 + 16] + 8] + 16] == 数据的开头
buffer, ad = "xxxx", object_id * 2 + 16
RtlMoveMemory.call(buffer, ad, 4)
ad = buffer.unpack("L")[0] + 8
RtlMoveMemory.call(buffer, ad, 4)
ad = buffer.unpack("L")[0] + 16
RtlMoveMemory.call(buffer, ad, 4)
return buffer.unpack("L")[0]
end
end
#==============================================================================
# ■ Bitmap
#------------------------------------------------------------------------------
# 位图的类。所谓位图即表示图像其本身。
#==============================================================================
class Bitmap
#--------------------------------------------------------------------------
# ● 传送到内存的API函数
#--------------------------------------------------------------------------
RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
#--------------------------------------------------------------------------
# ● Bitmap地址
#--------------------------------------------------------------------------
# [[[bitmap.object_id * 2 + 16] + 8] + 16] == 数据的开头
def address
buffer, ad = "rgba", object_id * 2 + 16
RtlMoveMemory_pi.call(buffer, ad, 4)
ad = buffer.unpack("L")[0] + 8
RtlMoveMemory_pi.call(buffer, ad, 4)
ad = buffer.unpack("L")[0] + 16
RtlMoveMemory_pi.call(buffer, ad, 4)
return buffer.unpack("L")[0]
end
module Bitmap2PNG
module_function
Malloc = Win32API.new('msvcrt.dll','malloc','i','i')
Memcpy_pi = Win32API.new('kernel32.dll','RtlMoveMemory','pii','v')
Memcpy_ii = Win32API.new('kernel32.dll','RtlMoveMemory','iii','v')
Memcpy_ip = Win32API.new('kernel32.dll','RtlMoveMemory','ipi','v')
Free = Win32API.new('msvcrt.dll','free','i','v')
Callsub = Win32API.new('user32.dll','CallWindowProcW','iiiii','i')
#--------------------------------------------------------------------------
# ● 主处理
#--------------------------------------------------------------------------
def make_png(bitmap_Fx)
@bitmap_Fx = bitmap_Fx
return make_header + make_ihdr + make_idat + make_iend
end
#--------------------------------------------------------------------------
# ● PNG文件头数据块
#--------------------------------------------------------------------------
def make_header
return [0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a].pack("C*")
end
#--------------------------------------------------------------------------
# ● PNG文件情报头数据块(IHDR)
#--------------------------------------------------------------------------
def make_ihdr
ih_size = [13].pack("N")
ih_sign = "IHDR"
ih_width = [@bitmap_Fx.width].pack("N")
ih_height = [@bitmap_Fx.height].pack("N")
ih_bit_depth = [8].pack("C")
ih_color_type = [6].pack("C")
ih_compression_method = [0].pack("C")
ih_filter_method = [0].pack("C")
ih_interlace_method = [0].pack("C")
string = ih_sign + ih_width + ih_height + ih_bit_depth + ih_color_type +
ih_compression_method + ih_filter_method + ih_interlace_method
ih_crc = [Zlib.crc32(string)].pack("N")
return ih_size + string + ih_crc
end
#--------------------------------------------------------------------------
# ● 生成图像数据(IDAT)
#--------------------------------------------------------------------------
def make_idat
header = "IDAT"
data = make_bitmap_data_dant
data = Zlib::Deflate.deflate(data)
crc = [Zlib.crc32(header + data)].pack("N")
size = [data.length].pack("N")
return size + header + data + crc
end
#--------------------------------------------------------------------------
# ● 从Bitmap对象的原始数据生成PNG图像数据
#--------------------------------------------------------------------------
def make_bitmap_data_dant
len = @bitmap_Fx.width * @bitmap_Fx.height * 4
pBuf = Malloc.call(len)
bitmap=@bitmap_Fx#.reverse
addr=bitmap.address
Memcpy_ii.call(pBuf,addr,len)
Callsub.call(@pCode,pBuf,bitmap.width*bitmap.height,0,0)
len2=len+bitmap.height
len3=bitmap.width*4
pBuf2 = Malloc.call(len2+512)
pos=pBuf2
pos2=pBuf+len-len3
Memcpy_ip.call(pos,0.chr,1)
pos+=1
for i in 0...bitmap.height
Memcpy_ii.call(pos,pos2,len3)
pos+=len3
pos2-=len3
Memcpy_ip.call(pos,0.chr,1)
pos+=1
end
buf="\0"*len2
Memcpy_pi.call(buf,pBuf2,len2)
Free.call(pBuf)
Free.call(pBuf2)
#~ bitmap.dispose
return buf
end
#--------------------------------------------------------------------------
# ● PNG文件尾数据块(IEND)
#--------------------------------------------------------------------------
def make_iend
return [0x00,0x00,0x00,0x00,0x49,0x45,0x4E,0x44,0xAE,0x42,0x60,0x82].pack("C*")
#ie_size = [0].pack("N")
#ie_sign = "IEND"
#ie_crc = [Zlib.crc32(ie_sign)].pack("N")
#return ie_size + ie_sign + ie_crc
end
def init
@pCode=Malloc.call(512)
=begin
qwe proc src,pixels,un,used
mov eax,src
xor ecx,ecx
.while ecx < pixels
mov edx,[eax] ;AARRGGBB|BB GG RR AA
bswap edx ;BBGGRRAA|AA RR GG BB
ror edx,8 ;AABBGGRR|RR GG BB AA
mov [eax],edx
inc ecx
add eax,4
.endw
ret
qwe endp
=end
code = [0x55,0x8B,0xEC,0x8B,0x45,0x8,0x33,0xC9,0xEB,0xD,0x8B,0x10,0xF,0xCA,0xC1,0xCA,0x8,0x89,0x10,0x41,0x83,0xC0,0x4,0x3B,0x4D,0xC,0x72,0xEE,0xC9,0xC2,0x10,0x0].pack('C*')
Memcpy_ip.call(@pCode,code,code.length)
end
def close
Free.call(@pCode)
end
end #Bitmap2PNG
def save_png(filename)
File.open(filename,"wb"){|f|f.write(Bitmap2PNG.make_png(self))}
end
end #Bitmap
Bitmap::Bitmap2PNG.init
END {Bitmap::Bitmap2PNG.close}
class << Graphics
alias s_update update unless method_defined?(:s_update)
def update
Screenshot.shot if Input.trigger?(Screenshot::KEY)
s_update
end
end
module Screenshot
KEY = Input::F5 #截图的快捷键
DIR = "Screenshot" #截图保存目录
def self.shot
Dir.mkdir(DIR) unless File.directory?(DIR)
time_now = Time.now.strftime("%Y-%m-%d %H-%M-%S")
if File.exist?("#{DIR}/#{time_now}.png")
index = 2
index += 1 while File.exist?("#{DIR}/#{time_now}_#{index}.png")
filename = "#{DIR}/#{time_now}_#{index}.png"
else
filename = "#{DIR}/#{time_now}.png"
end
Graphics.snap_to_bitmap.save_png(filename)
end
end
这是目前正在用的截图脚本···因为某些问题需要添加局部截图(比如只截取四分之一)的功能··· |
|