Config: Add 'preloadScript' entry to run raw scripts before the game scripts

Useful to insert common code, wrappers etc. without touching Scripts.rxdata.
This commit is contained in:
Jonas Kulla 2014-08-24 07:27:36 +02:00
parent d2fd692041
commit 117ddeee5c
4 changed files with 19 additions and 2 deletions

View File

@ -295,7 +295,8 @@ VALUE kernelLoadDataInt(const char *filename);
static void runRMXPScripts() 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()) if (scriptPack.empty())
{ {
@ -371,6 +372,10 @@ static void runRMXPScripts()
rb_ary_store(script, 3, rb_str_new_cstr(decodeBuffer.c_str())); 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) for (long i = 0; i < scriptCount; ++i)
{ {
VALUE script = rb_ary_entry(scriptArray, i); VALUE script = rb_ary_entry(scriptArray, i);
@ -379,7 +384,7 @@ static void runRMXPScripts()
RSTRING_LEN(scriptDecoded)); RSTRING_LEN(scriptDecoded));
VALUE fname; VALUE fname;
if (shState->rtData().config.useScriptNames) if (conf.useScriptNames)
{ {
fname = rb_ary_entry(script, 1); fname = rb_ary_entry(script, 1);
} }

View File

@ -100,6 +100,14 @@
# customScript=/path/to/script.rb # 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 # Index all accesible assets via their lower case path
# (emulates windows case insensitivity) # (emulates windows case insensitivity)
# (default: enabled) # (default: enabled)

View File

@ -177,6 +177,7 @@ void Config::read(int argc, char *argv[])
po::options_description podesc; po::options_description podesc;
podesc.add_options() podesc.add_options()
PO_DESC_ALL PO_DESC_ALL
("preloadScript", po::value<StringVec>()->composing())
("RTP", po::value<StringVec>()->composing()) ("RTP", po::value<StringVec>()->composing())
("fontSub", po::value<StringVec>()->composing()) ("fontSub", po::value<StringVec>()->composing())
("rubyLoadpath", po::value<StringVec>()->composing()) ("rubyLoadpath", po::value<StringVec>()->composing())
@ -210,6 +211,8 @@ void Config::read(int argc, char *argv[])
PO_DESC_ALL; PO_DESC_ALL;
GUARD_ALL( preloadScripts = vm["preloadScript"].as<StringVec>(); );
GUARD_ALL( rtps = vm["RTP"].as<StringVec>(); ); GUARD_ALL( rtps = vm["RTP"].as<StringVec>(); );
GUARD_ALL( fontSubs = vm["fontSub"].as<StringVec>(); ); GUARD_ALL( fontSubs = vm["fontSub"].as<StringVec>(); );

View File

@ -69,6 +69,7 @@ struct Config
bool useScriptNames; bool useScriptNames;
std::string customScript; std::string customScript;
std::vector<std::string> preloadScripts;
std::vector<std::string> rtps; std::vector<std::string> rtps;
std::vector<std::string> fontSubs; std::vector<std::string> fontSubs;