add 64-bit compatibility check before loading mods
That reduces time spent trying to rewrite them (which won't work anyway), and shows a more informative message than the default 'DLL couldn't be loaded' error.
This commit is contained in:
parent
e1d8838587
commit
f8c76bde39
|
@ -3,6 +3,7 @@
|
|||
# Release notes
|
||||
## Upcoming release
|
||||
* For players:
|
||||
* Added friendly error in 64-bit mode when a mod is 32-bit only.
|
||||
* Fixed some installer errors now show info header.
|
||||
|
||||
* For mod authors:
|
||||
|
|
|
@ -90,10 +90,10 @@ namespace StardewModdingAPI.Toolkit.Framework
|
|||
}
|
||||
|
||||
/// <summary>Get whether an executable is 64-bit.</summary>
|
||||
/// <param name="executablePath">The absolute path to the executable file.</param>
|
||||
public static bool Is64BitAssembly(string executablePath)
|
||||
/// <param name="path">The absolute path to the assembly file.</param>
|
||||
public static bool Is64BitAssembly(string path)
|
||||
{
|
||||
return AssemblyName.GetAssemblyName(executablePath).ProcessorArchitecture != ProcessorArchitecture.X86;
|
||||
return AssemblyName.GetAssemblyName(path).ProcessorArchitecture != ProcessorArchitecture.X86;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -46,5 +46,12 @@ namespace StardewModdingAPI.Toolkit.Utilities
|
|||
{
|
||||
return LowLevelEnvironmentUtility.GetExecutableName(platform.ToString());
|
||||
}
|
||||
|
||||
/// <summary>Get whether an executable is 64-bit.</summary>
|
||||
/// <param name="path">The absolute path to the assembly file.</param>
|
||||
public static bool Is64BitAssembly(string path)
|
||||
{
|
||||
return LowLevelEnvironmentUtility.Is64BitAssembly(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1704,12 +1704,21 @@ namespace StardewModdingAPI.Framework
|
|||
// load as mod
|
||||
else
|
||||
{
|
||||
// get mod info
|
||||
IManifest manifest = mod.Manifest;
|
||||
string assemblyPath = Path.Combine(mod.DirectoryPath, manifest.EntryDll);
|
||||
|
||||
// assert 64-bit
|
||||
#if SMAPI_FOR_WINDOWS_64BIT_HACK
|
||||
if (!EnvironmentUtility.Is64BitAssembly(assemblyPath))
|
||||
{
|
||||
errorReasonPhrase = "it needs to be updated for 64-bit mode.";
|
||||
failReason = ModFailReason.LoadFailed;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// load mod
|
||||
string assemblyPath = manifest?.EntryDll != null
|
||||
? Path.Combine(mod.DirectoryPath, manifest.EntryDll)
|
||||
: null;
|
||||
Assembly modAssembly;
|
||||
try
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue