diff --git a/mkxp.json b/mkxp.json index 3c69d76..6e25484 100644 --- a/mkxp.json +++ b/mkxp.json @@ -318,7 +318,7 @@ // execution starts // (default: none) // - // "preloadScript": ["scripts/preload/ruby18_wrap.rb", + // "preloadScript": ["scripts/preload/ruby_classic_wrap.rb", // "scripts/preload/mkxp_wrap.rb", // "scripts/preload/win32_wrap.rb"], diff --git a/scripts/preload/ruby18_wrap.rb b/scripts/preload/ruby18_wrap.rb deleted file mode 100644 index 82f8a29..0000000 --- a/scripts/preload/ruby18_wrap.rb +++ /dev/null @@ -1,17 +0,0 @@ -# ruby18_wrap.rb -# Author: Splendide Imaginarius (2022) - -# Creative Commons CC0: To the extent possible under law, Splendide Imaginarius -# has waived all copyright and related or neighboring rights to ruby18_wrap.rb. -# https://creativecommons.org/publicdomain/zero/1.0/ - -# This preload script provides functions that existed in RPG Maker's Ruby v1.8, -# but were renamed in the current Ruby version used in mkxp-z, so that games -# (or other preload scripts) that expect Ruby v1.8's function names can find -# them. - -class Hash - def index(*args) - key(*args) - end -end diff --git a/scripts/preload/ruby_classic_wrap.rb b/scripts/preload/ruby_classic_wrap.rb new file mode 100644 index 0000000..2c0de55 --- /dev/null +++ b/scripts/preload/ruby_classic_wrap.rb @@ -0,0 +1,44 @@ +# ruby_classic_wrap.rb +# Author: WaywardHeart (2023) + +# Creative Commons CC0: To the extent possible under law, WaywardHeart has +# dedicated all copyright and related and neighboring rights to this script +# to the public domain worldwide. +# https://creativecommons.org/publicdomain/zero/1.0/ + +# This preload script provides functions that existed in RPG Maker's versions of Ruby, +# but were renamed or changed in the current Ruby version used in mkxp-z, so that games +# (or other preload scripts) that expect the older Ruby behavior can function. + +class Hash + alias_method :index, :key unless method_defined?(:index) +end + +class Object + TRUE = true unless const_defined?("TRUE") + FALSE = false unless const_defined?("FALSE") + NIL = nil unless const_defined?("NIL") + + alias_method :id, :object_id unless method_defined?(:id) + alias_method :type, :class unless method_defined?(:type) +end + +class NilClass + def id + 4 # Starting with Ruby2, 64-bit builds of ruby make this 8 + end +end + +class TrueClass + def id + 2 # Starting with Ruby2, 64-bit builds of ruby make this 20 + end +end + +if defined?(BasicObject) && BasicObject.instance_method(:initialize).arity == 0 + # In ruby 1.9.2, and only ruby 1.9.2, BasicObject.initialize accepted any number of arguments + class BasicObject + def initialize(*args) + end + end +end