mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-07-03 07:05:17 +02:00
Merge pull request #109 from Splendide-Imaginarius/mkxp-z-preload-auto
`win32_wrap.rb`: Fallback to native `Win32API`
This commit is contained in:
commit
d7e43f0087
1 changed files with 49 additions and 11 deletions
|
@ -7,9 +7,18 @@
|
||||||
# all copyright and related or neighboring rights to win32_wrap.rb.
|
# all copyright and related or neighboring rights to win32_wrap.rb.
|
||||||
# https://creativecommons.org/publicdomain/zero/1.0/
|
# https://creativecommons.org/publicdomain/zero/1.0/
|
||||||
|
|
||||||
|
# Edits by Splendide Imaginarius (2023) also CC0.
|
||||||
|
|
||||||
# This preload script provides a subset of Win32API in a cross-platform way, so
|
# This preload script provides a subset of Win32API in a cross-platform way, so
|
||||||
# you can play Win32API-based games on Linux and macOS.
|
# you can play Win32API-based games on Linux and macOS.
|
||||||
|
|
||||||
|
# To tweak behavior, you can set the following Win32API class constants in an
|
||||||
|
# earlier preload script (these are usually only helpful for debugging):
|
||||||
|
#
|
||||||
|
# NATIVE_ON_WINDOWS=false
|
||||||
|
# TOLERATE_ERRORS=false
|
||||||
|
# LOG_NATIVE=true
|
||||||
|
|
||||||
module Scancodes
|
module Scancodes
|
||||||
SDL = { :UNKNOWN => 0x00,
|
SDL = { :UNKNOWN => 0x00,
|
||||||
:A => 0x04, :B => 0x05, :C => 0x06, :D => 0x07,
|
:A => 0x04, :B => 0x05, :C => 0x06, :D => 0x07,
|
||||||
|
@ -334,6 +343,11 @@ def kappatalize(s)
|
||||||
end
|
end
|
||||||
|
|
||||||
class Win32API
|
class Win32API
|
||||||
|
NATIVE_ON_WINDOWS = true unless const_defined?("NATIVE_ON_WINDOWS")
|
||||||
|
TOLERATE_ERRORS = true unless const_defined?("TOLERATE_ERRORS")
|
||||||
|
LOG_NATIVE = false unless const_defined?("LOG_NATIVE")
|
||||||
|
|
||||||
|
alias_method :mkxp_native_initialize, :initialize
|
||||||
def initialize(dll, func, *args)
|
def initialize(dll, func, *args)
|
||||||
@dll = dll
|
@dll = dll
|
||||||
@func = func
|
@func = func
|
||||||
|
@ -342,21 +356,45 @@ class Win32API
|
||||||
dll = kappatalize(dll.chomp(".dll"))
|
dll = kappatalize(dll.chomp(".dll"))
|
||||||
func = kappatalize(func)
|
func = kappatalize(func)
|
||||||
|
|
||||||
if Win32API_Impl.const_defined?(dll)
|
if !System.is_windows? or !NATIVE_ON_WINDOWS
|
||||||
dll_impl = Win32API_Impl.const_get(dll)
|
if Win32API_Impl.const_defined?(dll)
|
||||||
if dll_impl.const_defined?(func)
|
dll_impl = Win32API_Impl.const_get(dll)
|
||||||
@impl = dll_impl.const_get(func).new
|
if dll_impl.const_defined?(func)
|
||||||
|
@mkxp_wrap_impl = dll_impl.const_get(func).new
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
@mkxp_native_available = false
|
||||||
def call(*args)
|
begin
|
||||||
if @impl
|
mkxp_native_initialize(@dll, @func, *args)
|
||||||
return @impl.call(args)
|
@mkxp_native_available = true
|
||||||
|
return
|
||||||
|
rescue
|
||||||
end
|
end
|
||||||
|
|
||||||
System.puts("[#{@dll}:#{@func}] #{args.to_s}") if !@called
|
end
|
||||||
@called = true
|
|
||||||
return 0
|
alias_method :mkxp_native_call, :call
|
||||||
|
def call(*args)
|
||||||
|
if @mkxp_wrap_impl
|
||||||
|
return @mkxp_wrap_impl.call(args)
|
||||||
|
end
|
||||||
|
|
||||||
|
if @mkxp_native_available
|
||||||
|
if LOG_NATIVE
|
||||||
|
System.puts("[Win32API] [#{@dll}:#{@func}] #{args.to_s}")
|
||||||
|
end
|
||||||
|
return mkxp_native_call(*args)
|
||||||
|
end
|
||||||
|
|
||||||
|
if TOLERATE_ERRORS
|
||||||
|
System.puts("[Win32API] [#{@dll}:#{@func}] #{args.to_s}") if !@called
|
||||||
|
@called = true
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
raise RuntimeError, "[Win32API] [#{@dll}:#{@func}] #{args.to_s}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue