From af14f626177bb190c164fbc7d9d8164c3472f24d Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Tue, 23 Apr 2024 18:35:51 -0500 Subject: [PATCH] Do not let in-game menu saves mess with challenge score saving Lets use something that won't magically change if the in-game save menu was used, preventing score tips from being saved properly. --- src/challenge.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/challenge.cpp b/src/challenge.cpp index e54b5ef17af..0c6bd857752 100644 --- a/src/challenge.cpp +++ b/src/challenge.cpp @@ -98,30 +98,30 @@ const char* currentChallengeName() return nullptr; } -// quite the hack, game name is stored in global sRequestResult void updateChallenge(bool gameWon) { - char *fStr; + std::string fullName = challengeFileName.toStdString(); int seconds = 0, newtime = (gameTime - mission.startTime) / GAME_TICKS_PER_SEC; bool victory = false; WzConfig scores(CHALLENGE_SCORES, WzConfig::ReadAndWrite); - ASSERT_OR_RETURN(, strlen(sRequestResult) > 0, "Empty sRequestResult"); + ASSERT_OR_RETURN(, fullName.length() > 0, "Empty challengeFileName"); - fStr = strrchr(sRequestResult, '/'); - if (fStr != nullptr) + std::string fName; + size_t pos = fullName.find("/"); + if (pos != std::string::npos) { - fStr++; // skip slash + fName = fullName.substr(pos + 1); } else { - fStr = sRequestResult; + fName = fullName; // Likely if challengeFileName no longer has the path included in it. } - if (*fStr == '\0') + if (fName.empty()) { - debug(LOG_ERROR, "Bad path to challenge file (%s)", sRequestResult); + debug(LOG_ERROR, "Bad path to challenge file (%s)", fName.c_str()); return; } - WzString sPath = fStr; + WzString sPath = WzString::fromUtf8(fName); // remove .json if (sPath.endsWith(".json")) {