From 7e5d77fb8c2606795af239717a596de460bc58f7 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 21 Jul 2021 00:43:43 -0400 Subject: add error if some SMAPI DLLs have mismatched versions --- src/SMAPI/Program.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 0257a03e..e6e51ac6 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Threading; using StardewModdingAPI.Framework; using StardewModdingAPI.Toolkit.Framework; +using StardewModdingAPI.Toolkit.Serialization.Models; namespace StardewModdingAPI { @@ -32,6 +33,7 @@ namespace StardewModdingAPI AppDomain.CurrentDomain.AssemblyResolve += Program.CurrentDomain_AssemblyResolve; Program.AssertGamePresent(); Program.AssertGameVersion(); + Program.AssertSmapiVersions(); Program.Start(args); } catch (BadImageFormatException ex) when (ex.FileName == "StardewValley" || ex.FileName == "Stardew Valley") // don't use EarlyConstants.GameAssemblyName, since we want to check both possible names @@ -122,6 +124,20 @@ namespace StardewModdingAPI #endif } + /// Assert that the versions of all SMAPI components are correct. + /// Players sometimes have mismatched versions (particularly when installed through Vortex), which can cause some very confusing bugs without this check. + private static void AssertSmapiVersions() + { + // SMAPI toolkit + foreach (var type in new[] { typeof(IManifest), typeof(Manifest) }) + { + Assembly assembly = type.Assembly; + var assemblyVersion = new SemanticVersion(assembly.GetName().Version); + if (!assemblyVersion.Equals(Constants.ApiVersion)) + Program.PrintErrorAndExit($"Oops! The 'smapi-internal/{assembly.GetName().Name}.dll' file is version {assemblyVersion} instead of the required {Constants.ApiVersion}. SMAPI doesn't seem to be installed correctly."); + } + } + /// Initialize SMAPI and launch the game. /// The command-line arguments. /// This method is separate from because that can't contain any references to assemblies loaded by (e.g. via ), or Mono will incorrectly show an assembly resolution error before assembly resolution is set up. -- cgit