Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Graphics.snap_to_bitmap VX function to XP.

Code:
module Graphics

  RtlMoveMemory          = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')

  BitBlt                 = Win32API.new('gdi32', 'BitBlt', 'iiiiiiiii', 'i')

  CreateCompatibleBitmap = Win32API.new('gdi32', 'CreateCompatibleBitmap', 'iii', 'i')

  CreateCompatibleDC     = Win32API.new('gdi32', 'CreateCompatibleDC', 'i', 'i')

  DeleteObject           = Win32API.new('gdi32', 'DeleteObject', 'i', 'i')

  GetDIBits              = Win32API.new('gdi32', 'GetDIBits', 'iiiiipi', 'i')

  SelectObject           = Win32API.new('gdi32', 'SelectObject', 'ii', 'i')

  SetDIBits              = Win32API.new('gdi32', 'SetDIBits', 'iiiiipi', 'i')

  hWnd = Win32API.new('user32', 'FindWindow', 'pp', 'i').call('RGSS Player', 0)

  DC   = Win32API.new('user32', 'GetDC', 'i', 'i').call(hWnd)

  def self.snap_to_bitmap

    bitmap = Bitmap.new(width=640, height=480)

    RtlMoveMemory.call(address="\0"*4, bitmap.__id__*2+16, 4)

    RtlMoveMemory.call(address, address.unpack('L')[0]+8, 4)

    RtlMoveMemory.call(address, address.unpack('L')[0]+16, 4)

    address = address.unpack('L')[0]

    info = [40,width,height,1,32,0,0,0,0,0,0].pack('LllSSLLllLL')

    hDC = CreateCompatibleDC.call(DC)

    hBM = CreateCompatibleBitmap.call(DC, width, height)

    DeleteObject.call(SelectObject.call(hDC, hBM))

    SetDIBits.call(hDC, hBM, 0, height, 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
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top