diff --git a/SPTarkov.Server/Modding/ModValidator.cs b/SPTarkov.Server/Modding/ModValidator.cs index 88e4e0e01..40ee87003 100644 --- a/SPTarkov.Server/Modding/ModValidator.cs +++ b/SPTarkov.Server/Modding/ModValidator.cs @@ -18,6 +18,12 @@ public List ValidateMods(IEnumerable mods) 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 @@ protected bool IsModCompatibleWithSpt(AbstractModMetadata mod) 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" ///