From 66bf2abd37cc0db146811a93a31841694639a42f Mon Sep 17 00:00:00 2001 From: LRFLEW Date: Sat, 6 Jun 2015 17:59:46 -0500 Subject: [PATCH 1/5] A fix for #1231 This has the side-effect of incorrect default names in the scenario editor, but that can be patched separately. --- src/config.c | 15 +-------------- src/util/util.c | 13 +++++++++++++ src/util/util.h | 1 + src/windows/loadsave.c | 6 +++++- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/config.c b/src/config.c index 1a6986dec7..d9cb2c5e30 100644 --- a/src/config.c +++ b/src/config.c @@ -1003,7 +1003,6 @@ bool config_shortcut_keys_save() #pragma region Themes -static void themes_remove_extension(char *path); static bool themes_open(const utf8string path); static bool themes_save(const utf8string path, int preset); static void themes_read_properties(int preset, window_colours **current_window_colours, const_utf8string line); @@ -1120,7 +1119,7 @@ bool themes_open(const utf8string path) gConfigThemes.num_presets++; gConfigThemes.presets = realloc(gConfigThemes.presets, sizeof(theme_preset) * gConfigThemes.num_presets); strcpy(gConfigThemes.presets[preset].name, path_get_filename(path)); - themes_remove_extension(gConfigThemes.presets[preset].name); + path_remove_extension(gConfigThemes.presets[preset].name); gConfigThemes.presets[preset].colour_schemes = malloc(sizeof(window_colours) * gNumColourSchemeWindows); for (int i = 0; i < (int)gNumColourSchemeWindows; i++) { for (int j = 0; j < 6; j++) @@ -1239,16 +1238,4 @@ static void themes_set_property(window_colours *colour_scheme, utf8string name, } } -static void themes_remove_extension(char *path) -{ - char *ch; - - for (ch = path; *ch != 0; ch++) { - if (*ch == '.') { - *ch = '\0'; - break; - } - } -} - #pragma endregion \ No newline at end of file diff --git a/src/util/util.c b/src/util/util.c index 93bc8b2460..1e6c743e4e 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -69,6 +69,19 @@ void path_set_extension(char *path, const char *extension) strcpy(ch, extension); } +void path_remove_extension(char *path) +{ + char *ch = path; + + while (*ch != '\0') ++ch; + for (--ch; ch >= path; --ch) { + if (*ch == '.') { + *ch = '\0'; + break; + } + } +} + long fsize(FILE *fp) { long originalPosition, size; diff --git a/src/util/util.h b/src/util/util.h index f68deabe2a..3d14485aa9 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -29,6 +29,7 @@ int mph_to_kmph(int mph); const char *path_get_filename(const char *path); void path_set_extension(char *path, const char *extension); +void path_remove_extension(char *path); long fsize(FILE *fp); bool readentirefile(const char *path, void **outBuffer, long *outLength); diff --git a/src/windows/loadsave.c b/src/windows/loadsave.c index 8c2ce3b618..b1ba7ee8ed 100644 --- a/src/windows/loadsave.c +++ b/src/windows/loadsave.c @@ -29,6 +29,7 @@ #include "../title.h" #include "../windows/error.h" #include "../interface/themes.h" +#include "../util/util.h" #pragma region Widgets @@ -345,7 +346,10 @@ static void window_loadsave_scrollmousedown() char *templateString; templateString = (char*)language_get_string(templateStringId); - strcpy(templateString, (char*)RCT2_ADDRESS_SCENARIO_NAME); + int folderlength = strlen(RCT2_ADDRESS(RCT2_ADDRESS_SAVED_GAMES_PATH, char)); + strcpy(templateString, RCT2_ADDRESS(RCT2_ADDRESS_SAVED_GAMES_PATH_2 + folderlength, char)); + path_remove_extension(templateString); + window_text_input_open(w, WIDX_SCROLL, STR_NONE, 2710, templateStringId, 0, 64); } else { if (_listItems[selectedItem].path[strlen(_listItems[selectedItem].path) - 1] == platform_get_path_separator()){ From 73acb02946a27424dfdaddc37d7a5bc87b0d82b7 Mon Sep 17 00:00:00 2001 From: LRFLEW Date: Sat, 6 Jun 2015 18:14:12 -0500 Subject: [PATCH 2/5] Code Cleanup thanks trigger-death --- src/util/util.c | 4 +--- src/windows/loadsave.c | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/util/util.c b/src/util/util.c index 1e6c743e4e..30f874385a 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -71,9 +71,7 @@ void path_set_extension(char *path, const char *extension) void path_remove_extension(char *path) { - char *ch = path; - - while (*ch != '\0') ++ch; + char *ch = path + strlen(path); for (--ch; ch >= path; --ch) { if (*ch == '.') { *ch = '\0'; diff --git a/src/windows/loadsave.c b/src/windows/loadsave.c index b1ba7ee8ed..c19ed2bac4 100644 --- a/src/windows/loadsave.c +++ b/src/windows/loadsave.c @@ -346,8 +346,7 @@ static void window_loadsave_scrollmousedown() char *templateString; templateString = (char*)language_get_string(templateStringId); - int folderlength = strlen(RCT2_ADDRESS(RCT2_ADDRESS_SAVED_GAMES_PATH, char)); - strcpy(templateString, RCT2_ADDRESS(RCT2_ADDRESS_SAVED_GAMES_PATH_2 + folderlength, char)); + strcpy(templateString, path_get_filename(RCT2_ADDRESS(RCT2_ADDRESS_SAVED_GAMES_PATH_2, char))); path_remove_extension(templateString); window_text_input_open(w, WIDX_SCROLL, STR_NONE, 2710, templateStringId, 0, 64); From 75903ec2d98f82c66911c752477e997ea63566fa Mon Sep 17 00:00:00 2001 From: LRFLEW Date: Sat, 6 Jun 2015 22:35:48 -0500 Subject: [PATCH 3/5] Fixed opening save game not changing recommended name It was originally handled by load_game(), but was changed when the loadsave window was implemented. --- src/game.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/game.c b/src/game.c index 7923bcff6d..87c8f1c815 100644 --- a/src/game.c +++ b/src/game.c @@ -611,6 +611,7 @@ int game_load_save(const char *path) log_verbose("loading saved game, %s", path); strcpy((char*)0x0141EF68, path); + strcpy((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2, path); file = fopen(path, "rb"); if (file == NULL) { log_error("unable to open %s", path); From d3a6965f95e538ac5f3b43bf3794fc3c25e7b2b0 Mon Sep 17 00:00:00 2001 From: LRFLEW Date: Sun, 7 Jun 2015 17:12:17 -0500 Subject: [PATCH 4/5] Made window_loadsave_open accept a default file name This fixes #1231, #1245, and adds room for future work, such as porting track saving. --- src/game.c | 10 +++++++--- src/interface/window.h | 2 +- src/scenario.c | 8 +++++++- src/scenario.h | 3 +++ src/windows/editor_bottom_toolbar.c | 2 +- src/windows/editor_object_selection.c | 2 +- src/windows/loadsave.c | 7 ++++--- src/windows/top_toolbar.c | 3 ++- 8 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/game.c b/src/game.c index 87c8f1c815..c691ff1a6a 100644 --- a/src/game.c +++ b/src/game.c @@ -568,7 +568,7 @@ static int open_load_game_dialog() */ static void load_landscape() { - window_loadsave_open(LOADSAVETYPE_LOAD | LOADSAVETYPE_LANDSCAPE); + window_loadsave_open(LOADSAVETYPE_LOAD | LOADSAVETYPE_LANDSCAPE, NULL); return; if (open_landscape_file_dialog() == 0) { @@ -612,6 +612,10 @@ int game_load_save(const char *path) strcpy((char*)0x0141EF68, path); strcpy((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2, path); + + strcpy(scenarioSaveName, path_get_filename(path)); + path_remove_extension(scenarioSaveName); + file = fopen(path, "rb"); if (file == NULL) { log_error("unable to open %s", path); @@ -738,7 +742,7 @@ void reset_all_sprite_quadrant_placements() */ static void load_game() { - window_loadsave_open(LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME); + window_loadsave_open(LOADSAVETYPE_LOAD | LOADSAVETYPE_GAME, NULL); return; if (open_load_game_dialog() == 0) { @@ -795,7 +799,7 @@ static int show_save_game_dialog(char *resultPath) char save_game() { - window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME); + window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME, scenarioSaveName); return 0; char path[256]; diff --git a/src/interface/window.h b/src/interface/window.h index f7163bb8fe..4e8e5074e2 100644 --- a/src/interface/window.h +++ b/src/interface/window.h @@ -576,7 +576,7 @@ void window_themes_open(); void window_text_input_open(rct_window* call_w, int call_widget, rct_string_id title, rct_string_id description, rct_string_id existing_text, uint32 existing_args, int maxLength); void window_text_input_raw_open(rct_window* call_w, int call_widget, rct_string_id title, rct_string_id description, utf8string existing_text, int maxLength); rct_window *window_mapgen_open(); -rct_window *window_loadsave_open(int type); +rct_window *window_loadsave_open(int type, char *defaultName); void window_editor_main_open(); void window_editor_bottom_toolbar_open(); diff --git a/src/scenario.c b/src/scenario.c index 4fdae3f241..2314653c15 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -46,6 +46,8 @@ static char _scenarioPath[MAX_PATH]; static const char *_scenarioFileName; +char scenarioSaveName[MAX_PATH]; + static int scenario_create_ducks(); /** @@ -305,8 +307,9 @@ int scenario_load_and_play_from_path(const char *path) } // Set the last saved game path + format_string(scenarioSaveName, RCT2_GLOBAL(RCT2_ADDRESS_PARK_NAME, rct_string_id), (void*)RCT2_ADDRESS_PARK_NAME_ARGS); strcpy((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2, (char*)RCT2_ADDRESS_SAVED_GAMES_PATH); - format_string((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2 + strlen((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2), RCT2_GLOBAL(0x0013573D4, uint16), (void*)0x0013573D8); + strcpy((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2 + strlen((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2), scenarioSaveName); strcat((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2, ".SV6"); memset((void*)0x001357848, 0, 56); @@ -968,6 +971,9 @@ int scenario_save(char *path, int flags) rct_viewport *viewport; int viewX, viewY, viewZoom, viewRotation; + strcpy(scenarioSaveName, path_get_filename(path)); + path_remove_extension(scenarioSaveName); + if (flags & 2) log_verbose("saving scenario, %s", path); else diff --git a/src/scenario.h b/src/scenario.h index 3ef3ce16fd..e5b48158bf 100644 --- a/src/scenario.h +++ b/src/scenario.h @@ -23,6 +23,7 @@ #include "rct2.h" #include "object.h" +#include "platform/platform.h" /** * SV6/SC6 header chunk @@ -400,6 +401,8 @@ extern int gScenarioListCount; extern int gScenarioListCapacity; extern rct_scenario_basic *gScenarioList; +extern char scenarioSaveName[MAX_PATH]; + int scenario_scores_save(); void scenario_load_list(); rct_scenario_basic *get_scenario_by_filename(const char *filename); diff --git a/src/windows/editor_bottom_toolbar.c b/src/windows/editor_bottom_toolbar.c index 4035526cfd..8485ded736 100644 --- a/src/windows/editor_bottom_toolbar.c +++ b/src/windows/editor_bottom_toolbar.c @@ -314,7 +314,7 @@ void window_editor_bottom_toolbar_jump_forward_to_save_scenario() window_close_all(); - window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_SCENARIO); + window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_SCENARIO, s6Info->name); return; if (!show_save_scenario_dialog(path)) { diff --git a/src/windows/editor_object_selection.c b/src/windows/editor_object_selection.c index a32f4bdf0f..cee5bef0be 100644 --- a/src/windows/editor_object_selection.c +++ b/src/windows/editor_object_selection.c @@ -354,7 +354,7 @@ static void window_editor_object_selection_mouseup() } window_invalidate(w); - window_loadsave_open(LOADSAVETYPE_LOAD | LOADSAVETYPE_TRACK); + window_loadsave_open(LOADSAVETYPE_LOAD | LOADSAVETYPE_TRACK, NULL); break; case WIDX_FILTER_STRING_BUTTON: //window_text_input_open(w, widgetIndex, 5275, 5276, 1170, (uint32)_filter_string, 40); diff --git a/src/windows/loadsave.c b/src/windows/loadsave.c index c19ed2bac4..4907433e01 100644 --- a/src/windows/loadsave.c +++ b/src/windows/loadsave.c @@ -113,6 +113,7 @@ int _listItemsCount = 0; loadsave_list_item *_listItems = NULL; char _directory[MAX_PATH]; char _extension[32]; +char *_defaultName = NULL; int _loadsaveType; int _type; @@ -123,12 +124,13 @@ static int hasExtension(char *path, char *extension); static rct_window *window_overwrite_prompt_open(const char *name, const char *path); -rct_window *window_loadsave_open(int type) +rct_window *window_loadsave_open(int type, char *defaultName) { char path[MAX_PATH], *ch; int includeNewItem; rct_window* w; _type = type; + _defaultName = defaultName; w = window_bring_to_front_by_class(WC_LOADSAVE); if (w == NULL) { @@ -346,8 +348,7 @@ static void window_loadsave_scrollmousedown() char *templateString; templateString = (char*)language_get_string(templateStringId); - strcpy(templateString, path_get_filename(RCT2_ADDRESS(RCT2_ADDRESS_SAVED_GAMES_PATH_2, char))); - path_remove_extension(templateString); + strcpy(templateString, _defaultName); window_text_input_open(w, WIDX_SCROLL, STR_NONE, 2710, templateStringId, 0, 64); } else { diff --git a/src/windows/top_toolbar.c b/src/windows/top_toolbar.c index 464c510e5a..df0c7a3e1e 100644 --- a/src/windows/top_toolbar.c +++ b/src/windows/top_toolbar.c @@ -434,7 +434,8 @@ static void window_top_toolbar_dropdown() case DDIDX_SAVE_GAME: if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_SCENARIO_EDITOR) { // RCT2_CALLPROC_EBPSAFE(0x0066FE2A); - window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_LANDSCAPE); + rct_s6_info *s6Info = (rct_s6_info*)0x0141F570; + window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_LANDSCAPE, s6Info->name); } else { tool_cancel(); save_game(); From c0f376aa775f80c893c89ca373d7db41d594b057 Mon Sep 17 00:00:00 2001 From: LRFLEW Date: Sun, 7 Jun 2015 17:20:46 -0500 Subject: [PATCH 5/5] fixed naming convention --- src/game.c | 6 +++--- src/scenario.c | 10 +++++----- src/scenario.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/game.c b/src/game.c index c691ff1a6a..4beb1b3cd1 100644 --- a/src/game.c +++ b/src/game.c @@ -613,8 +613,8 @@ int game_load_save(const char *path) strcpy((char*)0x0141EF68, path); strcpy((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2, path); - strcpy(scenarioSaveName, path_get_filename(path)); - path_remove_extension(scenarioSaveName); + strcpy(gScenarioSaveName, path_get_filename(path)); + path_remove_extension(gScenarioSaveName); file = fopen(path, "rb"); if (file == NULL) { @@ -799,7 +799,7 @@ static int show_save_game_dialog(char *resultPath) char save_game() { - window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME, scenarioSaveName); + window_loadsave_open(LOADSAVETYPE_SAVE | LOADSAVETYPE_GAME, gScenarioSaveName); return 0; char path[256]; diff --git a/src/scenario.c b/src/scenario.c index 2314653c15..79448e7747 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -46,7 +46,7 @@ static char _scenarioPath[MAX_PATH]; static const char *_scenarioFileName; -char scenarioSaveName[MAX_PATH]; +char gScenarioSaveName[MAX_PATH]; static int scenario_create_ducks(); @@ -307,9 +307,9 @@ int scenario_load_and_play_from_path(const char *path) } // Set the last saved game path - format_string(scenarioSaveName, RCT2_GLOBAL(RCT2_ADDRESS_PARK_NAME, rct_string_id), (void*)RCT2_ADDRESS_PARK_NAME_ARGS); + format_string(gScenarioSaveName, RCT2_GLOBAL(RCT2_ADDRESS_PARK_NAME, rct_string_id), (void*)RCT2_ADDRESS_PARK_NAME_ARGS); 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), scenarioSaveName); + strcpy((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2 + strlen((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2), gScenarioSaveName); strcat((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2, ".SV6"); memset((void*)0x001357848, 0, 56); @@ -971,8 +971,8 @@ int scenario_save(char *path, int flags) rct_viewport *viewport; int viewX, viewY, viewZoom, viewRotation; - strcpy(scenarioSaveName, path_get_filename(path)); - path_remove_extension(scenarioSaveName); + strcpy(gScenarioSaveName, path_get_filename(path)); + path_remove_extension(gScenarioSaveName); if (flags & 2) log_verbose("saving scenario, %s", path); diff --git a/src/scenario.h b/src/scenario.h index e5b48158bf..a5bf2ad84e 100644 --- a/src/scenario.h +++ b/src/scenario.h @@ -401,7 +401,7 @@ extern int gScenarioListCount; extern int gScenarioListCapacity; extern rct_scenario_basic *gScenarioList; -extern char scenarioSaveName[MAX_PATH]; +extern char gScenarioSaveName[MAX_PATH]; int scenario_scores_save(); void scenario_load_list();