From fbc76dfe5e739f5ebfe52745da3be09ea5ebd373 Mon Sep 17 00:00:00 2001 From: Synth_Magic Date: Fri, 10 Jan 2025 20:52:07 +0800 Subject: [PATCH 1/3] Add config path sepcification --- src/lindbergh/config.c | 11 +++++++++-- src/lindbergh/config.h | 2 +- src/lindbergh/hook.c | 4 +++- src/lindbergh/lindbergh.c | 21 +++++++++++++++++++-- src/lindbergh/log.h | 1 - 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/lindbergh/config.c b/src/lindbergh/config.c index c3f071f..869c29b 100644 --- a/src/lindbergh/config.c +++ b/src/lindbergh/config.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -1341,7 +1342,7 @@ KeyMapping getDefaultKeymap() return defaultKeyMapping; } -int initConfig() +int initConfig(const char* configFilePath) { config.emulateRideboard = 0; config.emulateDriveboard = 0; @@ -1396,7 +1397,13 @@ int initConfig() config.inputMode = 0; // Default to all inputs - configFile = fopen(CONFIG_PATH, "r"); + char filePath[PATH_MAX] = CONFIG_PATH; + if (configFilePath != NULL && configFilePath[0] != '\0') + { + strcpy(filePath, configFilePath); + } + + configFile = fopen(filePath, "r"); if (configFile == NULL) { diff --git a/src/lindbergh/config.h b/src/lindbergh/config.h index e1e9824..6cbbd49 100644 --- a/src/lindbergh/config.h +++ b/src/lindbergh/config.h @@ -267,7 +267,7 @@ typedef struct } EmulatorConfig; KeyMapping getDefaultKeymap(); -int initConfig(); +int initConfig(const char* configFilePath); EmulatorConfig *getConfig(); char *getGameName(); char *getDVPName(); diff --git a/src/lindbergh/hook.c b/src/lindbergh/hook.c index 42288b7..a393718 100644 --- a/src/lindbergh/hook.c +++ b/src/lindbergh/hook.c @@ -174,7 +174,9 @@ void __attribute__((constructor)) hook_init() act.sa_flags = SA_SIGINFO; sigaction(SIGSEGV, &act, NULL); - initConfig(); + char *(*_getenv)(const char *name) = dlsym(RTLD_NEXT, "getenv"); + char* envPath = _getenv("LINDBERGH_CONFIG_PATH"); + initConfig(envPath); if (getConfig()->fpsLimiter == 1) { diff --git a/src/lindbergh/lindbergh.c b/src/lindbergh/lindbergh.c index 29b1989..f35bf41 100644 --- a/src/lindbergh/lindbergh.c +++ b/src/lindbergh/lindbergh.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -12,6 +13,7 @@ #define LD_PRELOAD "LD_PRELOAD" #define PRELOAD_FILE_NAME "lindbergh.so" #define TEAM "bobbydilley, retrofan, dkeruza-neo, doozer, francesco, rolel, caviar-x" +#define LINDBERGH_CONFIG_PATH "LINDBERGH_CONFIG_PATH" uint32_t elf_crc = 0; @@ -119,6 +121,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"); } /** @@ -248,8 +251,9 @@ int main(int argc, char *argv[]) int gdb = 0; int forceGame = 0; int segaboot = 0; - + char extConfigPath[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) @@ -269,7 +273,16 @@ int main(int argc, char *argv[]) gdb = 1; continue; } - + if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--config") == 0) + { + if (i+1 >= argc) + { + break; + } + strcpy(extConfigPath, argv[i+1]); + i += 1; + continue; + } // Treat the argument as the game name strcpy(forceGamePath, argv[i]); forceGame = 1; @@ -305,6 +318,10 @@ int main(int argc, char *argv[]) strcat(temp, command); strcpy(command, temp); } + if (extConfigPath[0] != '\0') + { + setenv(LINDBERGH_CONFIG_PATH,extConfigPath,1); + } log_info("Starting $ %s", command); diff --git a/src/lindbergh/log.h b/src/lindbergh/log.h index 6598d21..b646237 100644 --- a/src/lindbergh/log.h +++ b/src/lindbergh/log.h @@ -4,7 +4,6 @@ #include #include -#include // Structure to hold the formatted message and its size From dcae95fe03426eded82e10efb178e705724c18ea Mon Sep 17 00:00:00 2001 From: Synth Magic Date: Fri, 10 Jan 2025 20:54:24 +0800 Subject: [PATCH 2/3] rename linux/limits.h to limits.h --- src/lindbergh/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lindbergh/config.c b/src/lindbergh/config.c index 869c29b..0a38418 100644 --- a/src/lindbergh/config.c +++ b/src/lindbergh/config.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include From 51eaec106c62494ef88d92036af7e40c461664ef Mon Sep 17 00:00:00 2001 From: Synth_Magic Date: Fri, 10 Jan 2025 22:03:06 +0800 Subject: [PATCH 3/3] Do changes as requested --- src/lindbergh/config.c | 6 ++++-- src/lindbergh/lindbergh.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lindbergh/config.c b/src/lindbergh/config.c index 0a38418..74736d7 100644 --- a/src/lindbergh/config.c +++ b/src/lindbergh/config.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -1397,10 +1398,11 @@ int initConfig(const char* configFilePath) config.inputMode = 0; // Default to all inputs - char filePath[PATH_MAX] = CONFIG_PATH; + char filePath[PATH_MAX]; + strncpy(filePath, CONFIG_PATH, PATH_MAX); if (configFilePath != NULL && configFilePath[0] != '\0') { - strcpy(filePath, configFilePath); + strncpy(filePath, configFilePath, PATH_MAX); } configFile = fopen(filePath, "r"); diff --git a/src/lindbergh/lindbergh.c b/src/lindbergh/lindbergh.c index f35bf41..8af8852 100644 --- a/src/lindbergh/lindbergh.c +++ b/src/lindbergh/lindbergh.c @@ -279,7 +279,7 @@ int main(int argc, char *argv[]) { break; } - strcpy(extConfigPath, argv[i+1]); + strncpy(extConfigPath, argv[i+1], PATH_MAX); i += 1; continue; }