From 699735ab6bfc3a38a98f7f3b90cb31f8489de68f Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Sat, 6 Jul 2024 17:36:00 -0400 Subject: [PATCH] modding: Additional sanity checks --- src/modding.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/modding.cpp b/src/modding.cpp index 7b932318b7c..4e8d76e620f 100644 --- a/src/modding.cpp +++ b/src/modding.cpp @@ -45,6 +45,7 @@ static std::vector mod_hash_list; static void addLoadedMod(std::string modname, std::string filename, const std::string& fullRealPath); +static bool hasLoadedModRealPath(const std::string& fullRealPath); static inline std::vector split(std::string const &str, std::string const &sep) @@ -122,6 +123,11 @@ size_t addSubdirs(const char *basedir, const char *subdir, const bool appendToPa #ifdef DEBUG debug(LOG_NEVER, "Adding [%s] to search path", tmpFullModRealPath.c_str()); #endif // DEBUG + if (hasLoadedModRealPath(tmpFullModRealPath)) + { + debug(LOG_INFO, "Already loaded: %s, skipping", tmpFullModRealPath.c_str()); + return true; // continue + } if (PHYSFS_mount(tmpFullModRealPath.c_str(), NULL, appendToPath) != 0) // platform-dependent notation { numAddedMods++; @@ -218,6 +224,13 @@ static void addLoadedMod(std::string modname, std::string filename, const std::s mod_hash_list.clear(); } +static bool hasLoadedModRealPath(const std::string& fullRealPath) +{ + return std::any_of(loaded_mods.begin(), loaded_mods.end(), [fullRealPath](const WzMods::LoadedMod& loadedMod) -> bool { + return loadedMod.fullRealPath == fullRealPath; + }); +} + void clearLoadedMods() { loaded_mods.clear();