diff --git a/src/lindbergh/config.c b/src/lindbergh/config.c index 447da67..9fa0767 100644 --- a/src/lindbergh/config.c +++ b/src/lindbergh/config.c @@ -1297,7 +1297,7 @@ KeyMapping getDefaultKeymap() return defaultKeyMapping; } -int initConfig() +int initConfig(const char* configPath) { config.emulateRideboard = 0; config.emulateDriveboard = 0; @@ -1348,15 +1348,20 @@ int initConfig() } config.inputMode = 0; // Default to all inputs + char* configFilePath = CONFIG_PATH; + if (configPath != NULL) + strcpy(configFilePath, configPath); - configFile = fopen(CONFIG_PATH, "r"); + configFile = fopen(configFilePath, "r"); if (configFile == NULL) { - printf("Warning: Cannot open %s, using default values.\n", CONFIG_PATH); + printf("Warning: Cannot open %s, using default config values.\n", configFilePath); return 1; } + + readConfig(configFile, &config); fclose(configFile); diff --git a/src/lindbergh/config.h b/src/lindbergh/config.h index 8c42a2a..8a793ac 100644 --- a/src/lindbergh/config.h +++ b/src/lindbergh/config.h @@ -264,7 +264,7 @@ typedef struct } EmulatorConfig; KeyMapping getDefaultKeymap(); -int initConfig(); +int initConfig(const char* configPath); EmulatorConfig *getConfig(); char *getGameName(); char *getDVPName(); diff --git a/src/lindbergh/hook.c b/src/lindbergh/hook.c index bc1869a..3b5914c 100644 --- a/src/lindbergh/hook.c +++ b/src/lindbergh/hook.c @@ -49,7 +49,6 @@ #include "evdevinput.h" #define HOOK_FILE_NAME "/dev/zero" - #define BASEBOARD 0 #define EEPROM 1 #define SERIAL0 2 @@ -171,8 +170,11 @@ void __attribute__((constructor)) hook_init() act.sa_sigaction = handleSegfault; act.sa_flags = SA_SIGINFO; sigaction(SIGSEGV, &act, NULL); + // use unmodified version of getenv + char *(*_getenv)(const char *name) = dlsym(RTLD_NEXT, "getenv"); + char* envPath = _getenv("LINDBERGH_CONFIG_PATH"); - initConfig(); + initConfig(envPath); if (getConfig()->fpsLimiter == 1) { diff --git a/src/lindbergh/lindbergh.c b/src/lindbergh/lindbergh.c index 0e21f38..0383cec 100644 --- a/src/lindbergh/lindbergh.c +++ b/src/lindbergh/lindbergh.c @@ -3,11 +3,13 @@ #include #include #include +#include #include "evdevinput.h" #include "version.h" #define LD_LIBRARY_PATH "LD_LIBRARY_PATH" +#define LINDBERGH_CONFIG_PATH "LINDBERGH_CONFIG_PATH" #define LD_PRELOAD "LD_PRELOAD" #define PRELOAD_FILE_NAME "lindbergh.so" #define TEAM "bobbydilley, retrofan, dkeruza-neo, doozer, francesco, rolel, caviar-x" @@ -118,6 +120,7 @@ void printUsage(char *argv[]) printf(" --list-controllers Lists available controllers and inputs\n"); printf(" --version Displays the version of the loader and team's names\n"); printf(" --help Displays this usage text\n"); + printf(" --config | -c Specifies configuration path\n"); } /** @@ -247,8 +250,10 @@ int main(int argc, char *argv[]) int gdb = 0; int forceGame = 0; int segaboot = 0; - + int extConfig = 0; + char envConfigPath[PATH_MAX] = {0}; char forceGamePath[128] = {0}; + for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--test") == 0) @@ -268,12 +273,31 @@ int main(int argc, char *argv[]) gdb = 1; continue; } + if (strcmp(argv[i], "--config") == 0 || strcmp(argv[i], "-c") == 0) + { + // prevent wild pointer + if (i+1 >= argc) + { + printf("Unable to read config file because it's the end of argument list\n"); + break; + } + extConfig = 1; + strcpy(envConfigPath, argv[i+1]); + + // skip the next argument + i += 1; + continue; + } // Treat the argument as the game name strcpy(forceGamePath, argv[i]); forceGame = 1; } - + if (extConfig) + { + // always override the old environment + setenv(LINDBERGH_CONFIG_PATH, envConfigPath, 1); + } char command[128] = {0}; strcpy(command, "./"); if (forceGame)