#==============================================================================
# ** Drago - Core Engine (snap_to_bitmap)
# Version : --
# Contact : littledrago.blogspot.com / forum.chaos-project.com
#==============================================================================
module LiTTleDRAgo
#-------------------------------------------------------------------------
# * Constant
#-------------------------------------------------------------------------
VX = defined?(Window_ActorCommand)
VXA = defined?(Window_BattleActor)
RGSS1 = defined?(Hangup)
RGSS2 = RUBY_VERSION == '1.8.1' && !RGSS1
RGSS3 = RUBY_VERSION == '1.9.2'
APPPATHDRAGO = "#{ENV['APPDATA']}/Drago/"
end
$imported ||= {}
#==============================================================================
# ** CoreDLL
#------------------------------------------------------------------------------
#
#==============================================================================
module CoreDLL
#-------------------------------------------------------------------------
# * Constant
#-------------------------------------------------------------------------
Rtlmemory_pi = Win32API.new('kernel32','RtlMoveMemory','pii','i')
Rtlmemory_ip = Win32API.new('kernel32','RtlMoveMemory','ipi','i')
#-------------------------------------------------------------------------
# * Get the game window handle (specific to game)
#-------------------------------------------------------------------------
unless method_defined?(:hwnd)
def hwnd
@window_find ||= Win32API.new('user32', 'FindWindowEx', %w(l l p p), 'i')
@game_window ||= @window_find.call(0,0,"RGSS Player",0)
return @game_window
end
end
#-------------------------------------------------------------------------
# * Get the Game Window's width and height
#-------------------------------------------------------------------------
unless method_defined?(:client_size)
def client_size
@window_c_rect ||= Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
@window_c_rect.call(self.hwnd, (rect = [0, 0, 0, 0].pack('l4')))
right, bottom = rect.unpack('l4')[2..3]
return right, bottom
end
end
#--------------------------------------------------------------------------
# * snap_to_bitmap
#--------------------------------------------------------------------------
unless method_defined?(:snap_to_bitmap)
def snap_to_bitmap
@getdc ||= Win32API.new('user32','GetDC','i','i')
@ccdc ||= Win32API.new('gdi32','CreateCompatibleDC','i','i')
@ccbitmap ||= Win32API.new('gdi32','CreateCompatibleBitmap','iii','i')
@deleteobject||= Win32API.new('gdi32','DeleteObject','i','i')
@bitblt ||= Win32API.new('gdi32','BitBlt','iiiiiiiii','i')
@setdibits ||= Win32API.new('gdi32','SetDIBits','iiiiipi','i')
@getdibits ||= Win32API.new('gdi32','GetDIBits','iiiiipi','i')
@selectobject||= Win32API.new('gdi32','SelectObject','ii','i')
bitmap = Bitmap.new((width = Graphics.width), (height = Graphics.height))
info = [40,width,height,1,32,0,0,0,0,0,0].pack('LllSSLLllLL')
hDC = @ccdc.call((dc = @getdc.call(hwnd)))
hBM = @ccbitmap.call(dc, width, height)
@deleteobject.call(@selectobject.call(hDC, hBM))
@setdibits.call(hDC, hBM, 0, height, (address = bitmap.address), info, 0)
@bitblt.call(hDC, 0, 0, width, height, dc, 0, 0, 0xCC0020)
@getdibits.call(hDC, hBM, 0, height, address, info, 0)
@deleteobject.call(hBM)
@deleteobject.call(hDC)
bitmap
end
end
end
LiTTleDRAgo.extend(CoreDLL)
#==============================================================================
# ** Graphics
#------------------------------------------------------------------------------
# This module handles all Graphics
#==============================================================================
class << Graphics
#--------------------------------------------------------------------------
# ● Redefined method: width
#--------------------------------------------------------------------------
unless method_defined?(:width)
def width
LiTTleDRAgo.client_size.at(0)
end
end
#--------------------------------------------------------------------------
# ● Redefined method: height
#--------------------------------------------------------------------------
unless method_defined?(:height)
def height
LiTTleDRAgo.client_size.at(1)
end
end
#--------------------------------------------------------------------------
# ● Redefined method: snap_to_bitmap
#--------------------------------------------------------------------------
unless method_defined?(:snap_to_bitmap)
def snap_to_bitmap
LiTTleDRAgo.snap_to_bitmap
end
end
end
#==============================================================================
# ■ Bitmap
#------------------------------------------------------------------------------
#
#==============================================================================
class Bitmap
#----------------------------------------------------------------------------
# ● Constant
#----------------------------------------------------------------------------
RtlMoveMemory_pi = CoreDLL::Rtlmemory_pi
RtlMoveMemory_ip = CoreDLL::Rtlmemory_ip
#----------------------------------------------------------------------------
# ● New method: address
#----------------------------------------------------------------------------
unless method_defined?(:address)
def address
@address ||= (
RtlMoveMemory_pi.call(a="\0"*4, __id__*2+16, 4)
RtlMoveMemory_pi.call(a, a.unpack('L')[0]+8, 4)
RtlMoveMemory_pi.call(a, a.unpack('L')[0]+16, 4)
a.unpack('L')[0]
)
end
end
end
#==============================================================================
# ** END OF Drago - Core Engine
#==============================================================================