Exclude requested mods that are also in the world
All checks were successful
Build / Compute Version (push) Successful in 5s
Build / Build Nuget package (push) Successful in 34s

This commit is contained in:
2025-05-14 12:35:26 -04:00
parent 41f38444a5
commit 28b82c7c96

View File

@@ -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))