Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions SPTarkov.Server/Modding/ModValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public List<SptMod> ValidateMods(IEnumerable<SptMod> 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
Expand Down Expand Up @@ -147,6 +153,39 @@ protected bool IsModCompatibleWithSpt(AbstractModMetadata mod)
return true;
}

/// <summary>
/// Validate that the SPTarkov.Server.Core assembly is compatible with this mod. Semver is not enough.<br/>
///
/// Throws an exception if the mod was built for a newer SPT version than the current running SPT version
/// </summary>
/// <param name="mod">mod to validate</param>
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."
);
}
}
}

/// <summary>
/// Add into class property "Imported"
/// </summary>
Expand Down
Loading