From fe5776c2c5852e7b65d1dafc6e2d116c831e195c Mon Sep 17 00:00:00 2001 From: pas2704 Date: Mon, 12 May 2025 17:16:39 -0400 Subject: [PATCH] Avoid duplicates in the mod list --- Plugin.ClientModLoader/ModInjector.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Plugin.ClientModLoader/ModInjector.cs b/Plugin.ClientModLoader/ModInjector.cs index 5ac76ea..0c969b0 100644 --- a/Plugin.ClientModLoader/ModInjector.cs +++ b/Plugin.ClientModLoader/ModInjector.cs @@ -1,5 +1,4 @@ using System.Reflection.Emit; -using System.Runtime.CompilerServices; using HarmonyLib; using Sandbox.Definitions; using Sandbox.Engine.Networking; @@ -94,10 +93,21 @@ internal static class ModInjector private static void AppendToList(ref List mods) { // copy - mods = mods.ToList(); + mods = [.. mods]; - mods.AddRange(AdditionalFilledModItems.Count > 0 - ? AdditionalFilledModItems - : Mods.Select(mod => new MyObjectBuilder_Checkpoint.ModItem(mod, "Steam"))); + if (AdditionalFilledModItems.Count > 0) + { + mods.AddRange(AdditionalFilledModItems); + return; + } + + foreach (var mod in Mods) + { + //avoid duplicates + if (mods.FindIndex(m => m.PublishedFileId == mod) != -1) + continue; + + mods.Add(new MyObjectBuilder_Checkpoint.ModItem(mod, "Steam")); + } } } \ No newline at end of file