From f4428deccf55d3d5b03a5601bb36d20c4cf536ac Mon Sep 17 00:00:00 2001 From: GrooveypenguinX <79855395+GrooveypenguinX@users.noreply.github.com> Date: Sun, 1 Jun 2025 10:34:14 -0400 Subject: [PATCH] fixed missing import for customitemservice, added bundle loading sequence in the program.cs (#333) * Added missing import for reflection /bonk * Implemented bundles.json loading directly into program.cs `IsBundleMod` is now read from all loaded mods metadata, and if set to true the bundles.json is read from the mod directory. * re-assign the sorted valid mods to the loadedMods list since ValidateMods returns the sortedLoadedMods, this is the list of mods we should be passing to our other spots --------- Co-authored-by: Chomp <27521899+chompDev@users.noreply.github.com> --- .../Services/Mod/CustomItemService.cs | 1 + SPTarkov.Server/Program.cs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Libraries/SPTarkov.Server.Core/Services/Mod/CustomItemService.cs b/Libraries/SPTarkov.Server.Core/Services/Mod/CustomItemService.cs index 9f19ef0f..1d5f172e 100644 --- a/Libraries/SPTarkov.Server.Core/Services/Mod/CustomItemService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/Mod/CustomItemService.cs @@ -7,6 +7,7 @@ using SPTarkov.Server.Core.Models.Spt.Mod; using SPTarkov.Server.Core.Models.Utils; using SPTarkov.Server.Core.Utils; using SPTarkov.Server.Core.Utils.Cloners; +using System.Reflection; namespace SPTarkov.Server.Core.Services.Mod; diff --git a/SPTarkov.Server/Program.cs b/SPTarkov.Server/Program.cs index 8bead8f3..4b1bc28d 100644 --- a/SPTarkov.Server/Program.cs +++ b/SPTarkov.Server/Program.cs @@ -3,6 +3,7 @@ using System.Runtime.InteropServices; using SPTarkov.Common.Semver; using SPTarkov.Common.Semver.Implementations; using SPTarkov.DI; +using SPTarkov.Server.Core.Loaders; using SPTarkov.Server.Core.Models.Spt.Mod; using SPTarkov.Server.Core.Models.Utils; using SPTarkov.Server.Core.Servers; @@ -36,6 +37,9 @@ public static class Program // validate and sort mods, this will also discard any mods that are invalid var sortedLoadedMods = ValidateMods(loadedMods); + // update the loadedMods list with our validated sorted mods + loadedMods = sortedLoadedMods; + diHandler.AddInjectableTypesFromAssemblies(sortedLoadedMods.SelectMany(a => a.Assemblies)); } diHandler.InjectAll(); @@ -44,7 +48,24 @@ public static class Program builder.Services.AddSingleton>(loadedMods); var serviceProvider = builder.Services.BuildServiceProvider(); var logger = serviceProvider.GetService().CreateLogger("Server"); + // Load bundles for bundle mods + if (ProgramStatics.MODS()) + { + var bundleLoader = serviceProvider.GetService(); + foreach (var mod in loadedMods) + { + if (mod.ModMetadata?.IsBundleMod == true) + { + // Convert to relative path + string relativeModPath = Path.GetRelativePath( + Directory.GetCurrentDirectory(), + mod.Directory + ).Replace('\\', '/'); + bundleLoader.AddBundles(relativeModPath); + } + } + } try { SetConsoleOutputMode();