From 0a009d6fdaaac65dcac4c43fc51342dbf0d1c577 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 5 Dec 2018 22:49:49 -0500 Subject: add friendly error when Steam isn't loaded --- src/SMAPI/Framework/SCore.cs | 31 ++++++++++++++++++++++++++++--- src/SMAPI/Framework/SGame.cs | 6 +++--- 2 files changed, 31 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 5fb2dc61..d4dffea5 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -99,6 +99,20 @@ namespace StardewModdingAPI.Framework new Regex(@"^static SerializableDictionary<.+>\(\) called\.$", RegexOptions.Compiled | RegexOptions.CultureInvariant), }; + /// Regex patterns which match console messages to show a more friendly error for. + private readonly Tuple[] ReplaceConsolePatterns = + { + Tuple.Create( + new Regex(@"^System\.InvalidOperationException: Steamworks is not initialized\.", RegexOptions.Compiled | RegexOptions.CultureInvariant), +#if SMAPI_FOR_WINDOWS + "Oops! Steam achievements won't work because Steam isn't loaded. You can launch the game through Steam to fix that (see 'Part 2: Configure Steam' in the install guide for more info: https://smapi.io/install).", +#else + "Oops! Steam achievements won't work because Steam isn't loaded. You can launch the game through Steam to fix that.", +#endif + LogLevel.Error + ) + }; + /// The mod toolkit used for generic mod interactions. private readonly ModToolkit Toolkit = new ModToolkit(); @@ -1275,9 +1289,9 @@ namespace StardewModdingAPI.Framework } /// Redirect messages logged directly to the console to the given monitor. - /// The monitor with which to log messages. + /// The monitor with which to log messages as the game. /// The message to log. - private void HandleConsoleMessage(IMonitor monitor, string message) + private void HandleConsoleMessage(IMonitor gameMonitor, string message) { // detect exception LogLevel level = message.Contains("Exception") ? LogLevel.Error : LogLevel.Trace; @@ -1286,8 +1300,19 @@ namespace StardewModdingAPI.Framework if (level != LogLevel.Error && this.SuppressConsolePatterns.Any(p => p.IsMatch(message))) return; + // show friendly error if applicable + foreach (var entry in this.ReplaceConsolePatterns) + { + if (entry.Item1.IsMatch(message)) + { + this.Monitor.Log(entry.Item2, entry.Item3); + gameMonitor.Log(message, LogLevel.Trace); + return; + } + } + // forward to monitor - monitor.Log(message, level); + gameMonitor.Log(message, level); } /// Show a 'press any key to exit' message, and exit when they press a key. diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 9ad8d188..7b3335b7 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -31,7 +31,7 @@ using StardewValley.TerrainFeatures; using StardewValley.Tools; using xTile.Dimensions; using xTile.Layers; -using Object = StardewValley.Object; +using SObject = StardewValley.Object; namespace StardewModdingAPI.Framework { @@ -718,8 +718,8 @@ namespace StardewModdingAPI.Framework if (watcher.ObjectsWatcher.IsChanged) { GameLocation location = watcher.Location; - KeyValuePair[] added = watcher.ObjectsWatcher.Added.ToArray(); - KeyValuePair[] removed = watcher.ObjectsWatcher.Removed.ToArray(); + KeyValuePair[] added = watcher.ObjectsWatcher.Added.ToArray(); + KeyValuePair[] removed = watcher.ObjectsWatcher.Removed.ToArray(); watcher.ObjectsWatcher.Reset(); this.Events.ObjectListChanged.Raise(new ObjectListChangedEventArgs(location, added, removed)); -- cgit