Change to using builtin SemVer type for AbstractModMetadata and ProgramStatistics.Generated (#536)

* Change to using SemVer builtin type

* Remove SptVersion from config, remove redundant .ToString()

* Update test mod, fix watermark string conversion
This commit is contained in:
Cj
2025-08-09 16:40:25 -04:00
committed by GitHub
parent c16c988fda
commit 4d0eb4d4f3
35 changed files with 85 additions and 108 deletions
+1 -3
View File
@@ -78,13 +78,11 @@ public class ModDllLoader
string.IsNullOrEmpty(result.ModMetadata.ModGuid)
|| string.IsNullOrEmpty(result.ModMetadata.Name)
|| string.IsNullOrEmpty(result.ModMetadata.Author)
|| string.IsNullOrEmpty(result.ModMetadata.Version)
|| string.IsNullOrEmpty(result.ModMetadata.License)
|| string.IsNullOrEmpty(result.ModMetadata.SptVersion)
)
{
throw new Exception(
$"The mod metadata for: {Path.GetFullPath(path)} is missing one of these properties: ModGuid, Name, Author, License, Version or SptVersion"
$"The mod metadata for: {Path.GetFullPath(path)} is missing one of these properties: ModGuid, Name, Author, or License"
);
}
+8 -18
View File
@@ -6,6 +6,7 @@ using SPTarkov.Server.Core.Servers;
using SPTarkov.Server.Core.Services;
using SPTarkov.Server.Core.Utils;
using LogLevel = SPTarkov.Server.Core.Models.Spt.Logging.LogLevel;
using Version = SemanticVersioning.Version;
namespace SPTarkov.Server.Modding;
@@ -215,7 +216,7 @@ public class ModValidator(
/// <returns>True if compatible</returns>
protected bool IsModCompatibleWithSpt(AbstractModMetadata mod)
{
var sptVersion = ProgramStatics.SPT_VERSION() ?? sptConfig.SptVersion;
var sptVersion = ProgramStatics.SPT_VERSION();
var modName = $"{mod.Author}-{mod.Name}";
// Error and prevent loading if sptVersion property is not a valid semver string
@@ -306,13 +307,13 @@ public class ModValidator(
foreach (var (modDependency, requiredVersion) in pkg.ModDependencies)
{
// Raise dependency version incompatible if the dependency is not found in the mod list
if (!loadedMods.ContainsKey(modDependency))
if (!loadedMods.TryGetValue(modDependency, out var value))
{
logger.Error(localisationService.GetText("modloader-missing_dependency", new { mod = modName, modDependency }));
return false;
}
if (!semVer.Satisfies(loadedMods[modDependency].Version, requiredVersion))
if (!semVer.Satisfies(value.Version, requiredVersion))
{
logger.Error(
localisationService.GetText(
@@ -321,7 +322,7 @@ public class ModValidator(
{
mod = modName,
modDependency,
currentVersion = loadedMods[modDependency].Version,
currentVersion = value.Version,
requiredVersion,
}
)
@@ -335,13 +336,12 @@ public class ModValidator(
protected bool IsModCompatible(AbstractModMetadata mod, Dictionary<string, AbstractModMetadata> loadedMods)
{
var incompatbileModsList = mod.Incompatibilities;
if (incompatbileModsList == null)
if (mod.Incompatibilities == null)
{
return true;
}
foreach (var incompatibleModName in incompatbileModsList)
foreach (var incompatibleModName in mod.Incompatibilities)
{
// Raise dependency version incompatible if any incompatible mod is found
if (loadedMods.ContainsKey(incompatibleModName))
@@ -400,16 +400,6 @@ public class ModValidator(
return false;
}
// Validate mod
var config = mod.ModMetadata;
var issue = false;
if (!semVer.IsValid(config.Version))
{
logger.Error(localisationService.GetText("modloader-invalid_version_property", modName));
issue = true;
}
return !issue;
return true;
}
}