From 402e5a32a05896f0ed44015f468b0306df0ebb38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sun, 19 Jun 2016 23:47:06 +0200 Subject: [PATCH] Integrate path variables used by game --- src/game.c | 2 +- src/interface/console.c | 2 +- src/object.c | 8 +++--- src/object_list.c | 6 ++--- src/openrct2.c | 4 +-- src/rct2.c | 60 +++++++++++++++++++++-------------------- src/rct2.h | 7 +++++ src/scenario.c | 8 +++--- src/windows/loadsave.c | 2 +- 9 files changed, 54 insertions(+), 45 deletions(-) diff --git a/src/game.c b/src/game.c index d58214672c..9cdff4b448 100644 --- a/src/game.c +++ b/src/game.c @@ -783,7 +783,7 @@ bool game_load_save(const utf8 *path) log_verbose("loading saved game, %s", path); safe_strcpy((char*)0x0141EF68, path, MAX_PATH); - safe_strcpy((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2, path, MAX_PATH); + safe_strcpy((char*)gRCT2AddressSavedGamesPath2, path, MAX_PATH); safe_strcpy(gScenarioSavePath, path, MAX_PATH); diff --git a/src/interface/console.c b/src/interface/console.c index 6bfde3df3b..998aa73a15 100644 --- a/src/interface/console.c +++ b/src/interface/console.c @@ -893,7 +893,7 @@ static int cc_load_object(const utf8 **argv, int argc) { if (argc > 0) { utf8 path[MAX_PATH]; - substitute_path(path, RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char), argv[0]); + substitute_path(path, gRCT2AddressObjectDataPath, argv[0]); strcat(path, ".DAT\0"); rct_object_entry entry; diff --git a/src/object.c b/src/object.c index d8cd4a360b..c49e72f152 100644 --- a/src/object.c +++ b/src/object.c @@ -57,7 +57,7 @@ int object_load_file(int groupIndex, const rct_object_entry *entry, int* chunkSi char path[MAX_PATH]; SDL_RWops* rw; - substitute_path(path, RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char), (char*)installedObject + 16); + substitute_path(path, gRCT2AddressObjectDataPath, (char*)installedObject + 16); log_verbose("loading object, %s", path); @@ -345,7 +345,7 @@ int object_load_packed(SDL_RWops* rw) objectPath[i] = '\0'; } - substitute_path(path, RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char), objectPath); + substitute_path(path, gRCT2AddressObjectDataPath, objectPath); // Require pointer to start of filename char* last_char = path + strlen(path); strcat(path, ".DAT"); @@ -355,7 +355,7 @@ int object_load_packed(SDL_RWops* rw) for (; platform_file_exists(path);){ for (char* curr_char = last_char - 1;; --curr_char){ if (*curr_char == '\\'){ - substitute_path(path, RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char), "00000000.DAT"); + substitute_path(path, gRCT2AddressObjectDataPath, "00000000.DAT"); break; } if (*curr_char < '0') *curr_char = '0'; @@ -2608,7 +2608,7 @@ int object_get_scenario_text(rct_object_entry *entry) char path[MAX_PATH]; char *objectPath = (char*)installedObject + 16; - substitute_path(path, RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char), objectPath); + substitute_path(path, gRCT2AddressObjectDataPath, objectPath); rct_object_entry openedEntry; SDL_RWops* rw = SDL_RWFromFile(path, "rb"); diff --git a/src/object_list.c b/src/object_list.c index 7212a4625e..a0f5f9956c 100644 --- a/src/object_list.c +++ b/src/object_list.c @@ -253,7 +253,7 @@ static int object_list_query_directory(int *outTotalFiles, uint64 *outTotalFileS fileDateModifiedChecksum = 0; // Enumerate through each object in the directory - enumFileHandle = platform_enumerate_files_begin(RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char)); + enumFileHandle = platform_enumerate_files_begin(gRCT2AddressObjectDataPath); if (enumFileHandle == INVALID_HANDLE) return 0; @@ -321,7 +321,7 @@ void object_list_load() _installedObjectFilters = NULL; } - enumFileHandle = platform_enumerate_files_begin(RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char)); + enumFileHandle = platform_enumerate_files_begin(gRCT2AddressObjectDataPath); if (enumFileHandle != INVALID_HANDLE) { size_t installedObjectsCapacity = 4096; while (platform_enumerate_files_next(enumFileHandle, &enumFileInfo)) { @@ -338,7 +338,7 @@ void object_list_load() } char path[MAX_PATH]; - substitute_path(path, RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char), enumFileInfo.path); + substitute_path(path, gRCT2AddressObjectDataPath, enumFileInfo.path); rct_object_entry entry; if (object_load_entry(path, &entry)) { diff --git a/src/openrct2.c b/src/openrct2.c index 7b4dd5dbe5..918a99dda1 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -166,10 +166,10 @@ static void openrct2_copy_original_user_files_over() utf8 path[MAX_PATH]; platform_get_user_directory(path, "save"); - openrct2_copy_files_over((utf8*)RCT2_ADDRESS_SAVED_GAMES_PATH, path, ".sv6"); + openrct2_copy_files_over((utf8*)gRCT2AddressSavedGamesPath, path, ".sv6"); platform_get_user_directory(path, "landscape"); - openrct2_copy_files_over((utf8*)RCT2_ADDRESS_LANDSCAPES_PATH, path, ".sc6"); + openrct2_copy_files_over((utf8*)gRCT2AddressLandscapesPath, path, ".sc6"); } bool openrct2_initialise() diff --git a/src/rct2.c b/src/rct2.c index b61f92046b..b081a7db5b 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -114,6 +114,13 @@ uint8 gSavePromptMode; sint32 gScreenWidth; sint32 gScreenHeight; +char gRCT2AddressSavedGamesPath[MAX_PATH]; +char gRCT2AddressSavedGamesPath2[MAX_PATH]; +char gRCT2AddressScenariosPath[MAX_PATH]; +char gRCT2AddressLandscapesPath[MAX_PATH]; +char gRCT2AddressObjectDataPath[MAX_PATH]; +char gRCT2AddressTracksPath[MAX_PATH]; + typedef struct tm tm_t; void print_launch_information(); @@ -213,41 +220,36 @@ int rct2_init_directories() char separator[] = {platform_get_path_separator(), 0}; - strcpy(RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH, char), gConfigGeneral.game_path); + char gRCT2AddressAppPath[MAX_PATH] = { 0 }; - strcpy(RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH_SLASH, char), RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH, char)); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH_SLASH, char), separator); + strcpy(gRCT2AddressAppPath, gConfigGeneral.game_path); + strcat(gRCT2AddressAppPath, separator); - strcpy(RCT2_ADDRESS(RCT2_ADDRESS_SAVED_GAMES_PATH, char), RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH, char)); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_SAVED_GAMES_PATH, char), separator); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_SAVED_GAMES_PATH, char), "Saved Games"); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_SAVED_GAMES_PATH, char), separator); + strcpy(gRCT2AddressSavedGamesPath, gRCT2AddressAppPath); + strcat(gRCT2AddressSavedGamesPath, "Saved Games"); + strcat(gRCT2AddressSavedGamesPath, separator); - strcpy(RCT2_ADDRESS(RCT2_ADDRESS_SCENARIOS_PATH, char), RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH, char)); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_SCENARIOS_PATH, char), separator); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_SCENARIOS_PATH, char), "Scenarios"); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_SCENARIOS_PATH, char), separator); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_SCENARIOS_PATH, char), "*.SC6"); + strcpy(gRCT2AddressScenariosPath, gRCT2AddressAppPath); + strcat(gRCT2AddressScenariosPath, "Scenarios"); + strcat(gRCT2AddressScenariosPath, separator); + strcat(gRCT2AddressScenariosPath, "*.SC6"); - strcpy(RCT2_ADDRESS(RCT2_ADDRESS_LANDSCAPES_PATH, char), RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH, char)); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_LANDSCAPES_PATH, char), separator); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_LANDSCAPES_PATH, char), "Landscapes"); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_LANDSCAPES_PATH, char), separator); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_LANDSCAPES_PATH, char), "*.SC6"); + strcpy(gRCT2AddressLandscapesPath, gRCT2AddressAppPath); + strcat(gRCT2AddressLandscapesPath, "Landscapes"); + strcat(gRCT2AddressLandscapesPath, separator); + strcat(gRCT2AddressLandscapesPath, "*.SC6"); - strcpy(RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char), RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH, char)); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char), separator); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char), "ObjData"); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char), separator); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char), "*.DAT"); + strcpy(gRCT2AddressObjectDataPath, gRCT2AddressAppPath); + strcat(gRCT2AddressObjectDataPath, "ObjData"); + strcat(gRCT2AddressObjectDataPath, separator); + strcat(gRCT2AddressObjectDataPath, "*.DAT"); - strcpy(RCT2_ADDRESS(RCT2_ADDRESS_TRACKS_PATH, char), RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH, char)); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_TRACKS_PATH, char), separator); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_TRACKS_PATH, char), "Tracks"); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_TRACKS_PATH, char), separator); - strcat(RCT2_ADDRESS(RCT2_ADDRESS_TRACKS_PATH, char), "*.TD?"); + strcpy(gRCT2AddressTracksPath, gRCT2AddressAppPath); + strcat(gRCT2AddressTracksPath, "Tracks"); + strcat(gRCT2AddressTracksPath, separator); + strcat(gRCT2AddressTracksPath, "*.TD?"); - strcpy(RCT2_ADDRESS(RCT2_ADDRESS_SAVED_GAMES_PATH_2, char), RCT2_ADDRESS(RCT2_ADDRESS_SAVED_GAMES_PATH, char)); + strcpy(gRCT2AddressSavedGamesPath2, gRCT2AddressSavedGamesPath); return 1; } @@ -351,7 +353,7 @@ bool rct2_open_file(const char *path) extension++; if (_stricmp(extension, "sv6") == 0) { - strcpy((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2, path); + strcpy((char*)gRCT2AddressSavedGamesPath2, path); game_load_save(path); gFirstTimeSave = 0; return true; diff --git a/src/rct2.h b/src/rct2.h index 923ab22f65..1d12df5cd1 100644 --- a/src/rct2.h +++ b/src/rct2.h @@ -279,6 +279,13 @@ extern uint8 gSavePromptMode; extern sint32 gScreenWidth; extern sint32 gScreenHeight; +extern char gRCT2AddressSavedGamesPath[]; +extern char gRCT2AddressSavedGamesPath2[]; +extern char gRCT2AddressScenariosPath[]; +extern char gRCT2AddressLandscapesPath[]; +extern char gRCT2AddressObjectDataPath[]; +extern char gRCT2AddressTracksPath[]; + int rct2_init(); void rct2_dispose(); void rct2_update(); diff --git a/src/scenario.c b/src/scenario.c index 018bbea720..d576cfc5c4 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -244,9 +244,9 @@ void scenario_begin() strncat(gScenarioSavePath, parkName, sizeof(gScenarioSavePath) - strlen(gScenarioSavePath) - 1); strncat(gScenarioSavePath, ".sv6", sizeof(gScenarioSavePath) - strlen(gScenarioSavePath) - 1); - strcpy((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2, (char*)RCT2_ADDRESS_SAVED_GAMES_PATH); - strcpy((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2 + strlen((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2), gScenarioSavePath); - strcat((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2, ".SV6"); + strcpy(gRCT2AddressSavedGamesPath2, gRCT2AddressSavedGamesPath); + strcpy(gRCT2AddressSavedGamesPath2 + strlen(gRCT2AddressSavedGamesPath2), gScenarioSavePath); + strcat(gRCT2AddressSavedGamesPath2, ".SV6"); memset((void*)0x001357848, 0, 56); gCurrentExpenditure = 0; @@ -299,7 +299,7 @@ void scenario_end() void scenario_set_filename(const char *value) { - substitute_path(_scenarioPath, RCT2_ADDRESS(RCT2_ADDRESS_SCENARIOS_PATH, char), value); + substitute_path(_scenarioPath, gRCT2AddressScenariosPath, value); _scenarioFileName = path_get_filename(_scenarioPath); } diff --git a/src/windows/loadsave.c b/src/windows/loadsave.c index c068229904..c77eedc847 100644 --- a/src/windows/loadsave.c +++ b/src/windows/loadsave.c @@ -237,7 +237,7 @@ rct_window *window_loadsave_open(int type, char *defaultName) } */ - safe_strcpy(path, RCT2_ADDRESS(RCT2_ADDRESS_TRACKS_PATH, char), MAX_PATH); + safe_strcpy(path, gRCT2AddressTracksPath, MAX_PATH); ch = strchr(path, '*'); if (ch != NULL) *ch = 0;