From b99f3f67cc4012bd4506887470125e35ce7d55bf Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Tue, 28 Oct 2025 17:01:46 -0400 Subject: [PATCH] Merge pull request #669 from sp-tarkov/Assembly-ref-validation Validate core assembly reference when loading mods --- SPTarkov.Server/Modding/ModValidator.cs | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/SPTarkov.Server/Modding/ModValidator.cs b/SPTarkov.Server/Modding/ModValidator.cs index 88e4e0e0..40ee8700 100644 --- a/SPTarkov.Server/Modding/ModValidator.cs +++ b/SPTarkov.Server/Modding/ModValidator.cs @@ -18,6 +18,12 @@ public class ModValidator(ISptLogger logger, ServerLocalisationSer return []; } + // Validate all assemblies for references. This will deprecate AbstractMetadata semver checks in 4.1 + foreach (var mod in mods) + { + ValidateCoreAssemblyReference(mod); + } + logger.Info(localisationService.GetText("modloader-loading_mods", mods.Count())); // Validate and remove broken mods from mod list @@ -147,6 +153,39 @@ public class ModValidator(ISptLogger logger, ServerLocalisationSer return true; } + /// + /// Validate that the SPTarkov.Server.Core assembly is compatible with this mod. Semver is not enough.
+ /// + /// Throws an exception if the mod was built for a newer SPT version than the current running SPT version + ///
+ /// mod to validate + protected void ValidateCoreAssemblyReference(SptMod mod) + { + var sptVersion = ProgramStatics.SPT_VERSION(); + var modName = $"{mod.ModMetadata.Author}-{mod.ModMetadata.Name}"; + + foreach (var assembly in mod.Assemblies) + { + var sptCoreAsmRefVersion = assembly + .GetReferencedAssemblies() + .FirstOrDefault(asm => asm.Name == "SPTarkov.Server.Core") + ?.Version?.ToString(); + + if (sptCoreAsmRefVersion is null) + { + continue; + } + + var modRefVersion = new SemanticVersioning.Version(sptCoreAsmRefVersion?[..^2]!); + if (modRefVersion > sptVersion) + { + throw new Exception( + $"Mod: {modName} requires a minimum SPT version of `{modRefVersion}`, but you are running `{sptVersion}`. Please update SPT to use this mod." + ); + } + } + } + /// /// Add into class property "Imported" ///