Skip to content
Permalink
Browse files

Merge pull request #103 from BepInEx/bepin-version-warning

Added warning if a plugin was built against a newer version of bepinex
  • Loading branch information
denikson committed Dec 12, 2019
2 parents deb55fd + 181f0c2 commit b4d5ee5ac11eadde26848a443bfb932311abbd0f
Showing with 28 additions and 2 deletions.
  1. +20 −1 BepInEx/Bootstrap/Chainloader.cs
  2. +8 −1 BepInEx/Contract/PluginInfo.cs
@@ -172,13 +172,16 @@ public static PluginInfo ToPluginInfo(TypeDefinition type)
var dependencies = BepInDependency.FromCecilType(type);
var incompatibilities = BepInIncompatibility.FromCecilType(type);

var bepinVersion = type.Module.AssemblyReferences.FirstOrDefault(reference => reference.Name == "BepInEx")?.Version ?? new Version();

return new PluginInfo
{
Metadata = metadata,
Processes = filters,
Dependencies = dependencies,
Incompatibilities = incompatibilities,
TypeName = type.FullName
TypeName = type.FullName,
TargettedBepInExVersion = bepinVersion
};
}

@@ -195,6 +198,16 @@ private static bool HasBepinPlugins(AssemblyDefinition ass)
return true;
}

private static bool PluginTargetsWrongBepin(PluginInfo pluginInfo)
{
var pluginTarget = pluginInfo.TargettedBepInExVersion;
// X.X.X.x - compare normally. x.x.x.X - nightly build number, ignore
if (pluginTarget.Major != CurrentAssemblyVersion.Major) return true;
if (pluginTarget.Minor > CurrentAssemblyVersion.Minor) return true;
if (pluginTarget.Minor < CurrentAssemblyVersion.Minor) return false;
return pluginTarget.Build > CurrentAssemblyVersion.Build;
}

/// <summary>
/// The entrypoint for the BepInEx plugin system.
/// </summary>
@@ -276,6 +289,12 @@ public static void Start()
DependencyErrors.Add(message);
Logger.LogError(message);
}
else if (PluginTargetsWrongBepin(pluginInfo))
{
string message = $@"Plugin [{pluginInfo.Metadata.Name}] targets a wrong version of BepInEx ({pluginInfo.TargettedBepInExVersion}) and might not work until you update";
DependencyErrors.Add(message);
Logger.LogWarning(message);
}
}

var emptyDependencies = new string[0];
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BepInEx.Bootstrap;
@@ -21,6 +22,8 @@ public class PluginInfo : ICacheable

internal string TypeName { get; set; }

internal Version TargettedBepInExVersion { get; set; }

void ICacheable.Save(BinaryWriter bw)
{
bw.Write(TypeName);
@@ -43,6 +46,8 @@ void ICacheable.Save(BinaryWriter bw)
bw.Write(incList.Count);
foreach (var bepInIncompatibility in incList)
((ICacheable)bepInIncompatibility).Save(bw);

bw.Write(TargettedBepInExVersion.ToString(4));
}

void ICacheable.Load(BinaryReader br)
@@ -78,6 +83,8 @@ void ICacheable.Load(BinaryReader br)
}

Incompatibilities = incList;

TargettedBepInExVersion = new Version(br.ReadString());
}
}
}

0 comments on commit b4d5ee5

Please sign in to comment.
You can’t perform that action at this time.