From 18356ae748bf6454d73a98c7fec686fc6d9c016d Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 14 Feb 2026 09:59:30 +0100 Subject: [PATCH] Add additional comments to make "gLoadOnNextLaunch" logic clearer --- source/main.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index e1fa5d7..203e851 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -240,26 +240,31 @@ WUMS_APPLICATION_STARTS() { // Check if we want to link a plugin that's currently unloaded // E.g. if you disable a plugin from the config menu and then wiiload it, the disabled plugin copy should be unloaded for (const auto &pluginLoadWrapper : gLoadOnNextLaunch) { + // If a plugin is not enabled... if (!pluginLoadWrapper.isLoadAndLink()) { const auto unloadedMetaInfoIt = pluginMetaInformationCache.find(pluginLoadWrapper.getPluginData()->getHandle()); if (unloadedMetaInfoIt == pluginMetaInformationCache.end()) { DEBUG_FUNCTION_LINE_WARN("Failed to find meta information for plugin data handle %08X", pluginLoadWrapper.getPluginData()->getHandle()); continue; } - if (const auto it = std::ranges::find_if(gLoadOnNextLaunch, [&pluginLoadWrapper, &pluginMetaInformationCache, &unloadedMetaInfoIt](const PluginLoadWrapper &plugin) { - const bool differentPluginData = plugin.getPluginData()->getHandle() != pluginLoadWrapper.getPluginData()->getHandle(); - const bool otherWillBeLinked = plugin.isLoadAndLink(); - bool sameAuthorAndName = false; - if (const auto otherMetaInfoIt = pluginMetaInformationCache.find(plugin.getPluginData()->getHandle()); otherMetaInfoIt != pluginMetaInformationCache.end()) { - const auto &otherMetaInfo = otherMetaInfoIt->second; - const auto &unloadedMetaInfo = unloadedMetaInfoIt->second; - sameAuthorAndName = otherMetaInfo == unloadedMetaInfo; - } - return differentPluginData && otherWillBeLinked && sameAuthorAndName; - }); + // Check if there is another plugin which will be loaded and has the same author/name + const auto isPluginWithSameMetaLoaded = [&pluginLoadWrapper, &pluginMetaInformationCache, &unloadedMetaInfoIt](const PluginLoadWrapper &plugin) { + const bool differentPluginData = plugin.getPluginData()->getHandle() != pluginLoadWrapper.getPluginData()->getHandle(); + const bool otherWillBeLinked = plugin.isLoadAndLink(); + bool sameAuthorAndName = false; + if (const auto otherMetaInfoIt = pluginMetaInformationCache.find(plugin.getPluginData()->getHandle()); otherMetaInfoIt != pluginMetaInformationCache.end()) { + const auto &otherMetaInfo = otherMetaInfoIt->second; + const auto &unloadedMetaInfo = unloadedMetaInfoIt->second; + sameAuthorAndName = otherMetaInfo == unloadedMetaInfo; + } + return differentPluginData && otherWillBeLinked && sameAuthorAndName; + }; + if (const auto it = std::ranges::find_if(gLoadOnNextLaunch, isPluginWithSameMetaLoaded); it != gLoadOnNextLaunch.end()) { + // If yes, we want to drop the currently unloaded one, so lets NOT add it to the list continue; } + // otherwise add it to the list to keep it added. } filteredLoadOnNextLaunch.push_back(pluginLoadWrapper); }