From 28b82c7c9697901f09b3b1f2bb22d0e6381e9cc0 Mon Sep 17 00:00:00 2001 From: pas2704 Date: Wed, 14 May 2025 12:35:26 -0400 Subject: [PATCH] Exclude requested mods that are also in the world --- Plugin.ClientModLoader/ModInjector.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Plugin.ClientModLoader/ModInjector.cs b/Plugin.ClientModLoader/ModInjector.cs index b2fdbb3..d1441fb 100644 --- a/Plugin.ClientModLoader/ModInjector.cs +++ b/Plugin.ClientModLoader/ModInjector.cs @@ -1,6 +1,7 @@ using System.Collections.Immutable; using System.Reflection.Emit; using HarmonyLib; +using Plugin.ClientModLoader.Utils; using Sandbox.Definitions; using Sandbox.Engine.Networking; using Sandbox.Game.World; @@ -29,11 +30,11 @@ internal static class ModInjector { var worldMods = __state.Select(b => b.PublishedFileId).ToImmutableHashSet(); var resolvedMods = mods.ToImmutableDictionary(b => b.PublishedFileId); - + // list of selected mods which are resolved - var requestedMods = mods.IntersectBy(Mods, b => b.PublishedFileId) + var requestedMods = mods.IntersectBy(Mods, b => b.PublishedFileId).ExceptBy(worldMods, b => b.PublishedFileId) .ToDictionary(b => b.PublishedFileId); - + // add dependencies of requested mods // but skip if those are also requested by world we're loading in foreach (var dependency in requestedMods.Values @@ -42,13 +43,13 @@ internal static class ModInjector { if (worldMods.Contains(dependency)) continue; - + requestedMods.TryAdd(dependency, resolvedMods[dependency]); } - + // add resolved client mods and their exclusive dependencies AdditionalFilledModItems.AddRange(requestedMods.Values); - + // upsert world mods by resolved ones excluding our client ones and their exclusive dependencies // so world mods is only populated by dependencies of original world mods foreach (var mod in mods.ExceptBy(requestedMods.Keys, b => b.PublishedFileId))