diff --git a/src/cmdline/RootCommands.cpp b/src/cmdline/RootCommands.cpp index 2a49e8ab17..131518a4ab 100644 --- a/src/cmdline/RootCommands.cpp +++ b/src/cmdline/RootCommands.cpp @@ -49,6 +49,7 @@ static uint32 _port = 0; static utf8 * _password = nullptr; static utf8 * _userDataPath = nullptr; static utf8 * _openrctDataPath = nullptr; +static utf8 * _rct2DataPath = nullptr; static bool _silentBreakpad = false; #ifdef USE_BREAKPAD @@ -72,6 +73,7 @@ static const CommandLineOptionDefinition StandardOptions[] { CMDLINE_TYPE_STRING, &_password, NAC, "password", "password needed to join the server" }, { CMDLINE_TYPE_STRING, &_userDataPath, NAC, "user-data-path", "path to the user data directory (containing config.ini)" }, { CMDLINE_TYPE_STRING, &_openrctDataPath, NAC, "openrct-data-path", "path to the OpenRCT2 data directory (containing languages)" }, + { CMDLINE_TYPE_STRING, &_rct2DataPath, NAC, "rct2-data-path", "path to the RollerCoaster Tycoon 2 data directory (containing data/g1.dat)" }, #ifdef USE_BREAKPAD { CMDLINE_TYPE_SWITCH, &_silentBreakpad, NAC, "silent-breakpad", "make breakpad crash reporting silent" }, #endif // USE_BREAKPAD @@ -173,17 +175,26 @@ exitcode_t CommandLine::HandleCommandDefault() gOpenRCT2Headless = _headless; gOpenRCT2SilentBreakpad = _silentBreakpad || _headless; - if (_userDataPath != NULL) { + if (_userDataPath != nullptr) + { String::Set(gCustomUserDataPath, sizeof(gCustomUserDataPath), _userDataPath); Memory::Free(_userDataPath); } - if (_openrctDataPath != NULL) { + if (_openrctDataPath != nullptr) + { String::Set(gCustomOpenrctDataPath, sizeof(gCustomOpenrctDataPath), _openrctDataPath); Memory::Free(_openrctDataPath); } - if (_password != NULL) { + if (_rct2DataPath != nullptr) + { + String::Set(gCustomRCT2DataPath, sizeof(gCustomRCT2DataPath), _rct2DataPath); + Memory::Free(_rct2DataPath); + } + + if (_password != nullptr) + { String::Set(gCustomPassword, sizeof(gCustomPassword), _password); Memory::Free(_password); } diff --git a/src/openrct2.c b/src/openrct2.c index 8c301c6436..c7ccbe3d06 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -60,6 +60,7 @@ utf8 gOpenRCT2StartupActionPath[512] = { 0 }; utf8 gExePath[MAX_PATH]; utf8 gCustomUserDataPath[MAX_PATH] = { 0 }; utf8 gCustomOpenrctDataPath[MAX_PATH] = { 0 }; +utf8 gCustomRCT2DataPath[MAX_PATH] = { 0 }; utf8 gCustomPassword[MAX_PATH] = { 0 }; // This should probably be changed later and allow a custom selection of things to initialise like SDL_INIT diff --git a/src/openrct2.h b/src/openrct2.h index d546e758f3..88b3d6a5ef 100644 --- a/src/openrct2.h +++ b/src/openrct2.h @@ -39,6 +39,7 @@ extern utf8 gOpenRCT2StartupActionPath[512]; extern utf8 gExePath[MAX_PATH]; extern utf8 gCustomUserDataPath[MAX_PATH]; extern utf8 gCustomOpenrctDataPath[MAX_PATH]; +extern utf8 gCustomRCT2DataPath[MAX_PATH]; extern utf8 gCustomPassword[MAX_PATH]; extern bool gOpenRCT2Headless; extern bool gOpenRCT2ShowChangelog; diff --git a/src/rct2.c b/src/rct2.c index ece6203659..e42432716a 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -114,6 +114,7 @@ uint8 gSavePromptMode; sint32 gScreenWidth; sint32 gScreenHeight; +char gRCT2AddressAppPath[MAX_PATH]; char gRCT2AddressSavedGamesPath[MAX_PATH]; char gRCT2AddressSavedGamesPath2[MAX_PATH]; char gRCT2AddressScenariosPath[MAX_PATH]; @@ -211,22 +212,23 @@ int rct2_init_directories() { // windows_get_registry_install_info((rct2_install_info*)0x009AA10C, "RollerCoaster Tycoon 2 Setup", "MS Sans Serif", 0); - // check install directory - if (!platform_original_game_data_exists(gConfigGeneral.game_path)) { - log_verbose("install directory does not exist or invalid directory selected, %s", gConfigGeneral.game_path); - if (!config_find_or_browse_install_directory()) { - utf8 path[MAX_PATH]; - config_get_default_path(path); - log_fatal("Invalid RCT2 installation path. Please correct \"game_path\" in %s.", path); - return 0; - } - } - char separator[] = {platform_get_path_separator(), 0}; - char gRCT2AddressAppPath[MAX_PATH] = { 0 }; - - strcpy(gRCT2AddressAppPath, gConfigGeneral.game_path); + if (str_is_null_or_empty(gCustomRCT2DataPath)) { + // check install directory + if (!platform_original_game_data_exists(gConfigGeneral.game_path)) { + log_verbose("install directory does not exist or invalid directory selected, %s", gConfigGeneral.game_path); + if (!config_find_or_browse_install_directory()) { + utf8 path[MAX_PATH]; + config_get_default_path(path); + log_fatal("Invalid RCT2 installation path. Please correct \"game_path\" in %s.", path); + return 0; + } + } + strcpy(gRCT2AddressAppPath, gConfigGeneral.game_path); + } else { + strcpy(gRCT2AddressAppPath, gCustomRCT2DataPath); + } strcat(gRCT2AddressAppPath, separator); strcpy(gRCT2AddressSavedGamesPath, gRCT2AddressAppPath); @@ -475,34 +477,8 @@ void rct2_update() const utf8 *get_file_path(int pathId) { static utf8 path[MAX_PATH]; - strcpy(path, gConfigGeneral.game_path); - - // Make sure base path is terminated with a slash - if (strlen(path) == 0 || path[strlen(path) - 1] != platform_get_path_separator()) { - if (strlen(path) >= MAX_PATH - 1) { - log_error("Path for %s too long", RCT2FilePaths[pathId]); - path[0] = '\0'; - return path; - } - - char separator[] = {platform_get_path_separator(), 0}; - strcat(path, separator); - } - - // Concatenate file path - if (strlen(path) + strlen(RCT2FilePaths[pathId]) > MAX_PATH) { - log_error("Path for %s too long", RCT2FilePaths[pathId]); - path[0] = '\0'; - return path; - } - - char *pathp = path + strnlen(path, sizeof(path)); - strcat(path, RCT2FilePaths[pathId]); - while (*pathp) { - if (*pathp == '\\') *pathp = platform_get_path_separator(); - pathp++; - } - + strcpy(path, gRCT2AddressAppPath); + safe_strcat_path(path, RCT2FilePaths[pathId], sizeof(path)); return path; } diff --git a/src/rct2.h b/src/rct2.h index e8c60dc381..fc25e97275 100644 --- a/src/rct2.h +++ b/src/rct2.h @@ -279,6 +279,7 @@ extern uint8 gSavePromptMode; extern sint32 gScreenWidth; extern sint32 gScreenHeight; +extern char gRCT2AddressAppPath[]; extern char gRCT2AddressSavedGamesPath[]; extern char gRCT2AddressSavedGamesPath2[]; extern char gRCT2AddressScenariosPath[]; diff --git a/src/ride/track_design_index.c b/src/ride/track_design_index.c index d2af592ce5..6d06a96092 100644 --- a/src/ride/track_design_index.c +++ b/src/ride/track_design_index.c @@ -266,7 +266,7 @@ static void track_design_index_scan() utf8 directory[MAX_PATH]; // Get track directory from RCT2 - safe_strcpy(directory, gConfigGeneral.game_path, sizeof(directory)); + safe_strcpy(directory, gRCT2AddressAppPath, sizeof(directory)); safe_strcat_path(directory, "Tracks", sizeof(directory)); track_design_index_include(directory); diff --git a/src/scenario_list.c b/src/scenario_list.c index 2c8670a28e..686c82539c 100644 --- a/src/scenario_list.c +++ b/src/scenario_list.c @@ -18,6 +18,7 @@ #include "localisation/localisation.h" #include "object_list.h" #include "platform/platform.h" +#include "rct2.h" #include "scenario.h" #include "util/util.h" @@ -55,7 +56,7 @@ void scenario_load_list() gScenarioListCount = 0; // Get scenario directory from RCT2 - safe_strcpy(directory, gConfigGeneral.game_path, sizeof(directory)); + safe_strcpy(directory, gRCT2AddressAppPath, sizeof(directory)); safe_strcat_path(directory, "Scenarios", sizeof(directory)); scenario_list_include(directory);