From 7a9d60cdbcfa5a66e32bdacd1ab33137e44cbc06 Mon Sep 17 00:00:00 2001 From: Roza Date: Tue, 22 Jun 2021 09:38:23 -0400 Subject: [PATCH] Set Ruby's ARGV based on the command line --- binding/binding-mri.cpp | 7 ++ mkxp.json | 12 +++ src/config.cpp | 5 + src/config.h | 212 ++++++++++++++++++++-------------------- 4 files changed, 131 insertions(+), 105 deletions(-) diff --git a/binding/binding-mri.cpp b/binding/binding-mri.cpp index df8764c..cf4196d 100644 --- a/binding/binding-mri.cpp +++ b/binding/binding-mri.cpp @@ -1077,6 +1077,13 @@ static void mriBindingExecute() { #endif #endif + VALUE rbArgv = rb_get_argv(); + for (const auto &str : conf.launchArgs) + rb_ary_push(rbArgv, rb_utf8_str_new_cstr(str.c_str())); + + // Duplicates get pushed for some reason + rb_funcall(rbArgv, rb_intern("uniq!"), 0); + VALUE lpaths = rb_gv_get(":"); if (!conf.rubyLoadpaths.empty()) { /* Setup custom load paths */ diff --git a/mkxp.json b/mkxp.json index 0417e94..a7fedd5 100644 --- a/mkxp.json +++ b/mkxp.json @@ -323,5 +323,17 @@ // is a tiny bit less intrusive. // // "execName": "Game" + + // You can define alternate terminology for the different + // inputs recognized by RPG Maker. A, B, C, X, Y, Z, L, and R + // can all be set using this dictionary, and will be displayed + // on the F1 menu. This is only a cosmetic effect, so it will + // have no effect on the game's scripts. + // + // "bindingNames": { + // "c": "Confirm", + // "b": "Cancel", + // "x": ... + // } } diff --git a/src/config.cpp b/src/config.cpp index 63794e5..9540937 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -236,6 +236,11 @@ try { exp } catch (...) {} editor.debug = true; else if (!strcmp(argv[1], "btest")) editor.battleTest = true; + + for (int i = 1; i < argc; i++) { + const char *arg = argv[i]; + launchArgs.push_back(argv[i]); + } } if (mkxp_fs::fileExists(CONF_FILE)) { diff --git a/src/config.h b/src/config.h index 11eb91a..8d7b697 100644 --- a/src/config.h +++ b/src/config.h @@ -1,23 +1,23 @@ /* -** config.h -** -** This file is part of mkxp. -** -** Copyright (C) 2013 Jonas Kulla -** -** mkxp is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** mkxp is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with mkxp. If not, see . -*/ + ** config.h + ** + ** This file is part of mkxp. + ** + ** Copyright (C) 2013 Jonas Kulla + ** + ** mkxp is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 2 of the License, or + ** (at your option) any later version. + ** + ** mkxp is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with mkxp. If not, see . + */ #ifndef CONFIG_H #define CONFIG_H @@ -27,85 +27,87 @@ #include struct Config { - int rgssVersion; - - bool debugMode; - bool printFPS; - - bool winResizable; - bool fullscreen; - bool fixedAspectRatio; - bool smoothScaling; - bool vsync; - - int defScreenW; - int defScreenH; - std::string windowTitle; - - int fixedFramerate; - bool frameSkip; - bool syncToRefreshrate; - - bool solidFonts; - - bool subImageFix; - bool enableBlitting; - int maxTextureSize; - - std::string gameFolder; - bool anyAltToggleFS; - bool enableReset; - bool allowSymlinks; - bool pathCache; - - std::string dataPathOrg; - std::string dataPathApp; - - std::string iconPath; - std::string execName; - std::string titleLanguage; - - struct { - std::string soundFont; - bool chorus; - bool reverb; - } midi; - - struct { - int sourceCount; - } SE; - - bool useScriptNames; - - std::string customScript; - std::vector preloadScripts; - std::vector rtps; - - std::vector fontSubs; - - std::vector rubyLoadpaths; - - /* Editor flags */ - struct { - bool debug; - bool battleTest; - } editor; - - /* Game INI contents */ - struct { - std::string scripts; - std::string title; - } game; + int rgssVersion; - // JIT Options - struct { - bool enabled; - int verboseLevel; - int maxCache; - int minCalls; - } jit; + bool debugMode; + bool printFPS; - // Keybinding action name mappings + bool winResizable; + bool fullscreen; + bool fixedAspectRatio; + bool smoothScaling; + bool vsync; + + int defScreenW; + int defScreenH; + std::string windowTitle; + + int fixedFramerate; + bool frameSkip; + bool syncToRefreshrate; + + bool solidFonts; + + bool subImageFix; + bool enableBlitting; + int maxTextureSize; + + std::string gameFolder; + bool anyAltToggleFS; + bool enableReset; + bool allowSymlinks; + bool pathCache; + + std::string dataPathOrg; + std::string dataPathApp; + + std::string iconPath; + std::string execName; + std::string titleLanguage; + + struct { + std::string soundFont; + bool chorus; + bool reverb; + } midi; + + struct { + int sourceCount; + } SE; + + bool useScriptNames; + + std::string customScript; + + std::vector launchArgs; + std::vector preloadScripts; + std::vector rtps; + + std::vector fontSubs; + + std::vector rubyLoadpaths; + + /* Editor flags */ + struct { + bool debug; + bool battleTest; + } editor; + + /* Game INI contents */ + struct { + std::string scripts; + std::string title; + } game; + + // JIT Options + struct { + bool enabled; + int verboseLevel; + int maxCache; + int minCalls; + } jit; + + // Keybinding action name mappings struct { std::string a; std::string b; @@ -118,15 +120,15 @@ struct Config { std::string l; std::string r; } kbActionNames; - - /* Internal */ - std::string customDataPath; - std::string commonDataPath; - - Config(); - - void read(int argc, char *argv[]); - void readGameINI(); + + /* Internal */ + std::string customDataPath; + std::string commonDataPath; + + Config(); + + void read(int argc, char *argv[]); + void readGameINI(); }; #endif // CONFIG_H