summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-12-05 22:49:49 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-12-05 22:49:49 -0500
commit0a009d6fdaaac65dcac4c43fc51342dbf0d1c577 (patch)
tree5f8ad24748ad63646fca9730c80ddcfc25c42e9c
parentaba15074b3d3ab6f655c976f84e9a597d0115efd (diff)
downloadSMAPI-0a009d6fdaaac65dcac4c43fc51342dbf0d1c577.tar.gz
SMAPI-0a009d6fdaaac65dcac4c43fc51342dbf0d1c577.tar.bz2
SMAPI-0a009d6fdaaac65dcac4c43fc51342dbf0d1c577.zip
add friendly error when Steam isn't loaded
-rw-r--r--docs/release-notes.md1
-rw-r--r--src/SMAPI/Framework/SCore.cs31
-rw-r--r--src/SMAPI/Framework/SGame.cs6
3 files changed, 32 insertions, 6 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 6ac4e90b..5ac702b1 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -2,6 +2,7 @@
## Upcoming
* For players:
* Added support for ModDrop in update checks and the mod compatibility list.
+ * Added friendly error when Steam isn't loaded (for Steam players).
* Fixed cryptic error when running the installer from inside a zip file on Windows.
* Fixed error when leaving and rejoining a multiplayer server in the same session.
* Fixed Console Commands' handling of tool upgrade levels for item commands.
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),
};
+ /// <summary>Regex patterns which match console messages to show a more friendly error for.</summary>
+ private readonly Tuple<Regex, string, LogLevel>[] 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
+ )
+ };
+
/// <summary>The mod toolkit used for generic mod interactions.</summary>
private readonly ModToolkit Toolkit = new ModToolkit();
@@ -1275,9 +1289,9 @@ namespace StardewModdingAPI.Framework
}
/// <summary>Redirect messages logged directly to the console to the given monitor.</summary>
- /// <param name="monitor">The monitor with which to log messages.</param>
+ /// <param name="gameMonitor">The monitor with which to log messages as the game.</param>
/// <param name="message">The message to log.</param>
- 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);
}
/// <summary>Show a 'press any key to exit' message, and exit when they press a key.</summary>
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<Vector2, Object>[] added = watcher.ObjectsWatcher.Added.ToArray();
- KeyValuePair<Vector2, Object>[] removed = watcher.ObjectsWatcher.Removed.ToArray();
+ KeyValuePair<Vector2, SObject>[] added = watcher.ObjectsWatcher.Added.ToArray();
+ KeyValuePair<Vector2, SObject>[] removed = watcher.ObjectsWatcher.Removed.ToArray();
watcher.ObjectsWatcher.Reset();
this.Events.ObjectListChanged.Raise(new ObjectListChangedEventArgs(location, added, removed));