From 117ddeee5cdfc04f92cffcfba61578631f77d4e0 Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Sun, 24 Aug 2014 07:27:36 +0200 Subject: [PATCH] Config: Add 'preloadScript' entry to run raw scripts before the game scripts Useful to insert common code, wrappers etc. without touching Scripts.rxdata. --- binding-mri/binding-mri.cpp | 9 +++++++-- mkxp.conf.sample | 8 ++++++++ src/config.cpp | 3 +++ src/config.h | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/binding-mri/binding-mri.cpp b/binding-mri/binding-mri.cpp index 01599c8..00567eb 100644 --- a/binding-mri/binding-mri.cpp +++ b/binding-mri/binding-mri.cpp @@ -295,7 +295,8 @@ VALUE kernelLoadDataInt(const char *filename); static void runRMXPScripts() { - const std::string &scriptPack = shState->rtData().config.game.scripts; + const Config &conf = shState->rtData().config; + const std::string &scriptPack = conf.game.scripts; if (scriptPack.empty()) { @@ -371,6 +372,10 @@ static void runRMXPScripts() rb_ary_store(script, 3, rb_str_new_cstr(decodeBuffer.c_str())); } + /* Execute preloaded scripts */ + for (size_t i = 0; i < conf.preloadScripts.size(); ++i) + runCustomScript(conf.preloadScripts[i]); + for (long i = 0; i < scriptCount; ++i) { VALUE script = rb_ary_entry(scriptArray, i); @@ -379,7 +384,7 @@ static void runRMXPScripts() RSTRING_LEN(scriptDecoded)); VALUE fname; - if (shState->rtData().config.useScriptNames) + if (conf.useScriptNames) { fname = rb_ary_entry(script, 1); } diff --git a/mkxp.conf.sample b/mkxp.conf.sample index 602f551..819c0a6 100644 --- a/mkxp.conf.sample +++ b/mkxp.conf.sample @@ -100,6 +100,14 @@ # customScript=/path/to/script.rb +# Define raw scripts to be executed before the +# actual Scripts.rxdata execution starts +# (default: none) +# +# preloadScript=my_win32_wrapper.rb +# preloadScript=ruby18_fixes.rb + + # Index all accesible assets via their lower case path # (emulates windows case insensitivity) # (default: enabled) diff --git a/src/config.cpp b/src/config.cpp index c11a593..ae1d71b 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -177,6 +177,7 @@ void Config::read(int argc, char *argv[]) po::options_description podesc; podesc.add_options() PO_DESC_ALL + ("preloadScript", po::value()->composing()) ("RTP", po::value()->composing()) ("fontSub", po::value()->composing()) ("rubyLoadpath", po::value()->composing()) @@ -210,6 +211,8 @@ void Config::read(int argc, char *argv[]) PO_DESC_ALL; + GUARD_ALL( preloadScripts = vm["preloadScript"].as(); ); + GUARD_ALL( rtps = vm["RTP"].as(); ); GUARD_ALL( fontSubs = vm["fontSub"].as(); ); diff --git a/src/config.h b/src/config.h index 498a052..3f7143b 100644 --- a/src/config.h +++ b/src/config.h @@ -69,6 +69,7 @@ struct Config bool useScriptNames; std::string customScript; + std::vector preloadScripts; std::vector rtps; std::vector fontSubs;