summaryrefslogtreecommitdiff
path: root/src/SMAPI/Program.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-11-04 13:59:34 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-11-04 13:59:34 -0500
commit01c612bc4aca5a1d8921432c94956f4d170d4d4b (patch)
treed21ecf60d464088b590807ad53f2eaef618c2a95 /src/SMAPI/Program.cs
parente454de1e11fd76130f373362ea38e224b1fcfaef (diff)
downloadSMAPI-01c612bc4aca5a1d8921432c94956f4d170d4d4b.tar.gz
SMAPI-01c612bc4aca5a1d8921432c94956f4d170d4d4b.tar.bz2
SMAPI-01c612bc4aca5a1d8921432c94956f4d170d4d4b.zip
add friendly error for BadImageFormatException on launch
Diffstat (limited to 'src/SMAPI/Program.cs')
-rw-r--r--src/SMAPI/Program.cs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs
index d6e0888b..6bacf564 100644
--- a/src/SMAPI/Program.cs
+++ b/src/SMAPI/Program.cs
@@ -40,6 +40,11 @@ namespace StardewModdingAPI
Program.AssertGameVersion();
Program.Start(args);
}
+ catch (BadImageFormatException ex) when (ex.FileName == "StardewValley")
+ {
+ string executableName = Program.GetExecutableAssemblyName();
+ Console.WriteLine($"SMAPI failed to initialize because your game's {executableName}.exe seems to be invalid.\nThis may be a pirated version which modified the executable in an incompatible way; if so, you can try a different download or buy a legitimate version.\n\nTechnical details:\n{ex}");
+ }
catch (Exception ex)
{
Console.WriteLine($"SMAPI failed to initialize: {ex}");
@@ -77,8 +82,7 @@ namespace StardewModdingAPI
/// <remarks>This must be checked *before* any references to <see cref="Constants"/>, and this method should not reference <see cref="Constants"/> itself to avoid errors in Mono.</remarks>
private static void AssertGamePresent()
{
- Platform platform = EnvironmentUtility.DetectPlatform();
- string gameAssemblyName = platform == Platform.Windows ? "Stardew Valley" : "StardewValley";
+ string gameAssemblyName = Program.GetExecutableAssemblyName();
if (Type.GetType($"StardewValley.Game1, {gameAssemblyName}", throwOnError: false) == null)
Program.PrintErrorAndExit("Oops! SMAPI can't find the game. Make sure you're running StardewModdingAPI.exe in your game folder. See the readme.txt file for details.");
}
@@ -102,6 +106,13 @@ namespace StardewModdingAPI
}
+ /// <summary>Get the game's executable assembly name.</summary>
+ private static string GetExecutableAssemblyName()
+ {
+ Platform platform = EnvironmentUtility.DetectPlatform();
+ return platform == Platform.Windows ? "Stardew Valley" : "StardewValley";
+ }
+
/// <summary>Initialize SMAPI and launch the game.</summary>
/// <param name="args">The command-line arguments.</param>
/// <remarks>This method is separate from <see cref="Main"/> because that can't contain any references to assemblies loaded by <see cref="CurrentDomain_AssemblyResolve"/> (e.g. via <see cref="Constants"/>), or Mono will incorrectly show an assembly resolution error before assembly resolution is set up.</remarks>