diff options
Diffstat (limited to 'src/SMAPI')
-rw-r--r-- | src/SMAPI/Program.cs | 15 |
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> |