summaryrefslogtreecommitdiff
path: root/src/SMAPI/Program.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Program.cs')
-rw-r--r--src/SMAPI/Program.cs32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs
index e830f799..3249e02f 100644
--- a/src/SMAPI/Program.cs
+++ b/src/SMAPI/Program.cs
@@ -4,6 +4,8 @@ using System.Linq;
using System.Reflection;
using System.Threading;
using StardewModdingAPI.Framework;
+using StardewModdingAPI.Toolkit.Framework;
+using StardewModdingAPI.Toolkit.Serialization.Models;
namespace StardewModdingAPI
{
@@ -31,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
@@ -107,8 +110,35 @@ namespace StardewModdingAPI
}
// max version
- else if (Constants.MaximumGameVersion != null && Constants.GameVersion.IsNewerThan(Constants.MaximumGameVersion))
+ if (Constants.MaximumGameVersion != null && Constants.GameVersion.IsNewerThan(Constants.MaximumGameVersion))
Program.PrintErrorAndExit($"Oops! You're running Stardew Valley {Constants.GameVersion}, but this version of SMAPI is only compatible up to Stardew Valley {Constants.MaximumGameVersion}. Please check for a newer version of SMAPI: https://smapi.io.");
+
+ // bitness
+ bool is64BitGame = LowLevelEnvironmentUtility.Is64BitAssembly(Path.Combine(EarlyConstants.ExecutionPath, $"{EarlyConstants.GameAssemblyName}.exe"));
+#if SMAPI_FOR_WINDOWS_64BIT_HACK
+ if (!is64BitGame)
+ Program.PrintErrorAndExit("Oops! This is the 64-bit version of SMAPI, but you have the 32-bit version of Stardew Valley. You can reinstall SMAPI using its installer to automatically install the correct version of SMAPI.");
+#elif SMAPI_FOR_WINDOWS
+ if (is64BitGame)
+ Program.PrintErrorAndExit("Oops! This is the 32-bit version of SMAPI, but you have the 64-bit version of Stardew Valley. You can reinstall SMAPI using its installer to automatically install the correct version of SMAPI.");
+#endif
+ }
+
+ /// <summary>Assert that the versions of all SMAPI components are correct.</summary>
+ /// <remarks>Players sometimes have mismatched versions (particularly when installed through Vortex), which can cause some very confusing bugs without this check.</remarks>
+ private static void AssertSmapiVersions()
+ {
+ // get SMAPI version without prerelease suffix (since we can't get that from the assembly versions)
+ ISemanticVersion smapiVersion = new SemanticVersion(Constants.ApiVersion.MajorVersion, Constants.ApiVersion.MinorVersion, Constants.ApiVersion.PatchVersion);
+
+ // compare with assembly versions
+ foreach (var type in new[] { typeof(IManifest), typeof(Manifest) })
+ {
+ AssemblyName assemblyName = type.Assembly.GetName();
+ ISemanticVersion assemblyVersion = new SemanticVersion(assemblyName.Version);
+ if (!assemblyVersion.Equals(smapiVersion))
+ Program.PrintErrorAndExit($"Oops! The 'smapi-internal/{assemblyName.Name}.dll' file is version {assemblyVersion} instead of the required {Constants.ApiVersion}. SMAPI doesn't seem to be installed correctly.");
+ }
}
/// <summary>Initialize SMAPI and launch the game.</summary>