#==============================================================================#
# RMXP/RMVX Web Browser #
#------------------------------------------------------------------------------#
# Original script by Berka #
# Modified by Armorphor (aka CollosalPokemon) #
# Version: 2.1 #
# Date: 04.08.2009 #
# Last Modification: 03.01.2010 #
# - DON'T POST THIS SCRIPT ANYWHERE WITHOUT PERMISSION. #
# - GIVE CREDITS WHERE THEY ARE NEEDED. #
#------------------------------------------------------------------------------#
# HOWTO: #
# #
# - Copy WebBrowser.dll to your /Data/ folder. #
# - To close the browser you can use the Esc, F5, or the Back keys #
# - If you're using VX then change "$RMXP = true" to "$RMXP = false" otherwise#
# DON'T change it. #
# #
# Current Bugs/Glitches: #
# #
# - Page is black if the mouse does not click on a spot that does something.(?)#
# - Can't guarantee it'll work with the SDKs but I don't know why it wouldn't #
# b/c it doesn't alias anything in RMXP or RMVX that has to do with anything #
# the SDK uses. But still, not tested yet. #
# #
# Removed Features: #
# #
# - Resizing the Game Window. Reason: Not ideal for other scripts and processes#
#==============================================================================#
# Changelog: #
# #
# v1.0 (04.08.2009) (Public) #
# --> Initial Release (For RPG Maker VX and NOT RPG Maker XP) #
# #
# v2.0 (02.25.2010) (Not Public) #
# --> Support for RMXP brought. (Albeit a bit buggy) #
# --> Rewritten details behind the hashes (#) #
# --> Renamed DLL and checking if you have it (Ensures the script can run) #
# v2.1 (03.01.2010) (Public) #
# --> Patch created so it is guarantee to work in RMVX and RMXP. #
# --> Maintenance. #
#==============================================================================#
# Call using: Net.browser("URL") #
# Of course replace URL with a URL to go to. #
#==============================================================================#
class Win32API
@@RGSSWINDOW=nil
@@GetCurrentThreadId=Win32API.new('kernel32','GetCurrentThreadId', '%w()','l')
@@GetWindowThreadProcessId=Win32API.new('user32','GetWindowThreadProcessId', '%w(l p)','l')
@@FindWindowEx=Win32API.new('user32','FindWindowEx', '%w(l l p p)','l')
def Win32API.SetWindowText(text)
hWnd = pbFindRgssWindow
swp = Win32API.new('user32', 'SetWindowTextA', %(l, p), 'i')
swp.call(hWnd, text)
end
# Added by Peter O. as a more reliable way to get the RGSS window
def Win32API.pbFindRgssWindow
return @@RGSSWINDOW if @@RGSSWINDOW
processid=[0].pack('l')
threadid=@@GetCurrentThreadId.call
nextwindow=0
begin
nextwindow=@@FindWindowEx.call(0,nextwindow,"RGSS Player",0)
if nextwindow
wndthreadid=@@GetWindowThreadProcessId.call(nextwindow,processid)
if wndthreadid==threadid
@@RGSSWINDOW=nextwindow
return @@RGSSWINDOW
end
end
end until nextwindow==0
raise "Can't find RGSS player window"
return 0
end
def Win32API.GetPrivateProfileString(section, key)
val = "\0"*256
gps = Win32API.new('kernel32', 'GetPrivateProfileString',%w(p p p p l p), 'l')
gps.call(section, key, "", val, 256, ".\\Game.ini")
val.delete!("\0")
return val
end
def Win32API.SetWindowPos(w, h)
hWnd = pbFindRgssWindow
windowrect=Win32API.GetWindowRect
clientsize=Win32API.client_size
xExtra=windowrect.width-clientsize[0]
yExtra=windowrect.height-clientsize[1]
swp = Win32API.new('user32', 'SetWindowPos', %(l, l, i, i, i, i, i), 'i')
win = swp.call(hWnd, 0, windowrect.x, windowrect.y,
w+xExtra,h+yExtra, 0)
return win
end
def Win32API.client_size
hWnd = pbFindRgssWindow
rect = [0, 0, 0, 0].pack('l4')
Win32API.new('user32', 'GetClientRect', %w(l p), 'i').call(hWnd, rect)
width, height = rect.unpack('l4')[2..3]
return width, height
end
def Win32API.GetWindowRect
hWnd = pbFindRgssWindow
rect = [0, 0, 0, 0].pack('l4')
Win32API.new('user32', 'GetWindowRect', %w(l p), 'i').call(hWnd, rect)
x,y,width, height = rect.unpack('l4')
return Rect.new(x,y,width-x,height-y)
end
end
if FileTest.exist?("Data/WebBrowser.dll") #Ensures n00bs didn't delete the webpage DLL.
wdll='Data/WebBrowser.dll'
else
raise ArgumentError.new(_INTL("Error: Web Browsing DLL somehow not found.\nContact the game's owner if the problem persists."))
end
$RMXP = true # If true you're using RMXP, if false, you're using RMVX.(YOU need to edit this)
GPPS = Win32API.new('kernel32', 'GetPrivateProfileString', 'pppplp', 'l')
FW = Win32API.new('user32','FindWindowEx', '%w(l l p p)','l')
GCR = Win32API.new('user32', 'GetClientRect', 'lp', 'i')
GAKS = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
TID = Win32API.new('kernel32','GetCurrentThreadId', '%w()','l')
WTPID = Win32API.new('user32','GetWindowThreadProcessId', '%w(l p)','l')
EBO = Win32API.new(wdll, 'EmbedBrowserObject', 'l', 'i')
DHP = Win32API.new(wdll, 'DisplayHTMLPage', 'lp', 'i')
UEBO = Win32API.new(wdll, 'UnEmbedBrowserObject', 'l', 'l')
DPA = Win32API.new(wdll, 'DoPageAction', 'll', 'l')
if $RMXP==true
def handle
@@RGSSWINDOW=nil
processid=[0].pack('l')
threadid=TID.call
nextwindow=0
begin
nextwindow=FW.call(0,nextwindow,"RGSS Player",0)
if nextwindow
wndthreadid=TID.call
if wndthreadid==threadid
@@RGSSWINDOW=nextwindow
return @@RGSSWINDOW
end
end
end until nextwindow==0
GPPS.call("Game","Title","",title="\0"*255,255,".//Game.ini")
FW.call(0,nextwindow,"RGSS Player",title.delete!("\0"))
end
def dimensions
return Win32API.client_size
end
module Net
def self.browser(url)
EBO.call(handle)
DHP.call(handle,url)
loop do
sleep(0.1)
EBO.call(handle)
DPA.call(handle,0)if GAKS.call(0x08)&0x01==1
DPA.call(handle,4)if GAKS.call(0x74)&0x01==1
Graphics.update
EBO.call(handle)
DPA.call(handle,0)if GAKS.call(0x08)&0x01==1
DPA.call(handle,4)if GAKS.call(0x74)&0x01==1
Input.update
break if GAKS.call(0x1b)&0x01==1
end
UEBO.call(handle)
end
end
else
def handle
GPPS.call("Game","Title","",title="\0"*256,256,".//Game.ini")
FW.call("RGSS Player",title.delete!("\0"))
end
def dimensions
GCR.call(handle,rect=[0,0,0,0].pack('l4'))
rect.unpack('l4')[2..3]
end
module Net
def self.browser(url)
EBO.call(handle)
DHP.call(handle,url)
RB.call(handle,*dimensions)
loop do
break if GAKS.call(0x1b)&0x01==1
DPA.call(handle,0)if GAKS.call(0x08)&0x01==1
DPA.call(handle,4)if GAKS.call(0x74)&0x01==1
RB.call(handle,*dimensions)
end
UEBO.call(handle)
end
end
end