From 6665f4f8f64a0f363e10a3b0313f203d46b0616c Mon Sep 17 00:00:00 2001 From: Misa Date: Tue, 31 Jan 2023 20:04:18 -0800 Subject: [PATCH] Prioritize loading processed script names This makes it so that whenever the game loads a script as directed by a script command, it will first try to load the script from the processed argument, and if that fails only then will it try to load the script from the raw argument. This fixes a regression reported by Dav999 in the custom level "Vungeon" created by Dynaboom, where a script `ifflag`s to `aselectP1.1` even though the actual script name is `aselectp1.1`. In 2.3, it would lowercase `aselectP1.1` and load the script properly, but previous to this commit it would try to load the script with a capital name and then fail. --- desktop_version/src/Script.cpp | 41 +++++++++++++++++++++------------ desktop_version/src/Script.h | 5 ++-- desktop_version/src/Scripts.cpp | 6 ++--- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index f972f0fd..cc9a4b7e 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -231,7 +231,7 @@ void scriptclass::run(void) const RoomProperty* const room = cl.getroomprop(ss_toi(words[1])-1, ss_toi(words[2])-1); if (room->warpdir == ss_toi(words[3])) { - load("custom_" + raw_words[4]); + loadalts("custom_" + words[4], "custom_" + raw_words[4]); position--; } } @@ -264,7 +264,7 @@ void scriptclass::run(void) { if (game.trinkets() >= ss_toi(words[1])) { - load("custom_" + raw_words[2]); + loadalts("custom_" + words[2], "custom_" + raw_words[2]); position--; } } @@ -272,7 +272,7 @@ void scriptclass::run(void) { if (game.trinkets() < ss_toi(words[1])) { - load("custom_" + raw_words[2]); + loadalts("custom_" + words[2], "custom_" + raw_words[2]); position--; } } @@ -281,7 +281,7 @@ void scriptclass::run(void) int flag = ss_toi(words[1]); if (INBOUNDS_ARR(flag, obj.flags) && obj.flags[flag]) { - load("custom_" + raw_words[2]); + loadalts("custom_" + words[2], "custom_" + raw_words[2]); position--; } } @@ -1189,7 +1189,7 @@ void scriptclass::run(void) { if (map.isexplored(ss_toi(words[1]), ss_toi(words[2]))) { - load(raw_words[3]); + loadalts(words[3], raw_words[3]); position--; } } @@ -1197,7 +1197,7 @@ void scriptclass::run(void) { if (game.lastsaved==ss_toi(words[1])) { - load(raw_words[2]); + loadalts(words[2], raw_words[2]); position--; } } @@ -1205,7 +1205,7 @@ void scriptclass::run(void) { if (game.nocutscenes) { - load(raw_words[1]); + loadalts(words[1], raw_words[1]); position--; } } @@ -1214,7 +1214,7 @@ void scriptclass::run(void) int flag = ss_toi(words[1]); if (INBOUNDS_ARR(flag, obj.flags) && obj.flags[flag]) { - load(raw_words[2]); + loadalts(words[2], raw_words[2]); position--; } } @@ -1223,7 +1223,7 @@ void scriptclass::run(void) int crewmate = ss_toi(words[1]); if (INBOUNDS_ARR(crewmate, game.crewstats) && !game.crewstats[crewmate]) { - load(raw_words[2]); + loadalts(words[2], raw_words[2]); position--; } } @@ -1231,7 +1231,7 @@ void scriptclass::run(void) { if (game.trinkets() >= ss_toi(words[1])) { - load(raw_words[2]); + loadalts(words[2], raw_words[2]); position--; } } @@ -1239,7 +1239,7 @@ void scriptclass::run(void) { if (game.stat_trinkets < ss_toi(words[1])) { - load(raw_words[2]); + loadalts(words[2], raw_words[2]); position--; } } @@ -1413,7 +1413,7 @@ void scriptclass::run(void) } else if (words[0] == "loadscript") { - load(raw_words[1]); + loadalts(words[1], raw_words[1]); position--; } else if (words[0] == "rollcredits") @@ -2414,7 +2414,7 @@ void scriptclass::run(void) { if (loc::lang == words[1]) { - load("custom_" + raw_words[2]); + loadalts("custom_" + words[2], "custom_" + raw_words[2]); position--; } } @@ -3226,7 +3226,7 @@ void scriptclass::hardreset(void) obj.customactivitypositiony = -1; } -void scriptclass::loadcustom(const std::string& t) +bool scriptclass::loadcustom(const std::string& t) { //this magic function breaks down the custom script and turns into real scripting! std::string cscriptname=""; @@ -3246,7 +3246,7 @@ void scriptclass::loadcustom(const std::string& t) } } if(contents == NULL){ - return; + return false; } std::vector& lines = *contents; @@ -3514,6 +3514,17 @@ void scriptclass::loadcustom(const std::string& t) add("endcutscene()"); add("untilbars()"); } + + return true; +} + +void scriptclass::loadalts(const std::string& processed, const std::string& raw) +{ + const bool exists = load(processed); + if (!exists) + { + load(raw); + } } void scriptclass::add_test_line(const std::string& speaker, const std::string& english, char textcase) diff --git a/desktop_version/src/Script.h b/desktop_version/src/Script.h index e18319da..95137ac4 100644 --- a/desktop_version/src/Script.h +++ b/desktop_version/src/Script.h @@ -63,9 +63,10 @@ public: scriptclass(void); - void load(const std::string& name); + bool load(const std::string& name); void loadother(const char* t); - void loadcustom(const std::string& t); + bool loadcustom(const std::string& t); + void loadalts(const std::string& processed, const std::string& raw); void add_test_line(const std::string& speaker, const std::string& english, char textcase); void loadtest(const std::string& name); diff --git a/desktop_version/src/Scripts.cpp b/desktop_version/src/Scripts.cpp index 9cf2f473..0de5fe4a 100644 --- a/desktop_version/src/Scripts.cpp +++ b/desktop_version/src/Scripts.cpp @@ -2,7 +2,7 @@ #include -void scriptclass::load(const std::string& name) +bool scriptclass::load(const std::string& name) { //loads script name t into the array position = 0; @@ -14,7 +14,7 @@ void scriptclass::load(const std::string& name) if (SDL_strncmp(t, "custom_", 7) == 0) { - loadcustom(name); + return loadcustom(name); } else if (SDL_strcmp(t, "intro") == 0) { @@ -420,7 +420,6 @@ void scriptclass::load(const std::string& name) "untilbars()", }; filllines(lines); - return; } if (SDL_strcmp(t, "communicationstation") == 0) { @@ -6763,4 +6762,5 @@ void scriptclass::load(const std::string& name) loadother(t); } + return !commands.empty(); }