From e447ce225f46f60131519a1ff77dfddf520696bb Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 13 Dec 2018 01:16:38 -0500 Subject: add content pack API --- src/SMAPI/StardewModdingAPI.csproj | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/SMAPI/StardewModdingAPI.csproj') diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index 49a88f37..2c769f41 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -174,6 +174,7 @@ + @@ -207,6 +208,7 @@ + -- cgit From 39341d772e99492f239ad8aff09cca8760ff5b83 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 15 Dec 2018 13:33:22 -0500 Subject: prevent invalid items from crashing the game --- docs/README.md | 6 ++-- docs/release-notes.md | 3 +- src/SMAPI/Framework/SCore.cs | 3 +- src/SMAPI/Patches/ObjectErrorPatch.cs | 55 +++++++++++++++++++++++++++++++++++ src/SMAPI/StardewModdingAPI.csproj | 1 + 5 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 src/SMAPI/Patches/ObjectErrorPatch.cs (limited to 'src/SMAPI/StardewModdingAPI.csproj') diff --git a/docs/README.md b/docs/README.md index b8e3b50b..e4220de2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@ -**SMAPI** is an open-source modding API for [Stardew Valley](https://stardewvalley.net/) that lets -you play the game with mods. It's safely installed alongside the game's executable, and doesn't -change any of your game files. It serves eight main purposes: +**SMAPI** is an open-source modding framework and API for [Stardew Valley](https://stardewvalley.net/) +that lets you play the game with mods. It's safely installed alongside the game's executable, and +doesn't change any of your game files. It serves eight main purposes: 1. **Load mods into the game.** _SMAPI loads mods when the game is starting up so they can interact with it. (Code mods aren't diff --git a/docs/release-notes.md b/docs/release-notes.md index fa7f4109..bcbdee22 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,6 +1,7 @@ # Release notes ## Upcoming release * For players: + * SMAPI now prevents invalid items from crashing the game on hover. * Fixed cryptic error message when the game isn't installed correctly. * Fixed error when a mod makes invalid changes to an NPC schedule. * Fixed invalid NPC data propagated when a mod changes NPC dispositions. @@ -10,7 +11,7 @@ * For modders: * Added dedicated content pack API. - * **Deprecations:** + * **Deprecations:** * The `assetData.AsDictionary().Set` methods are deprecated and will be removed in SMAPI 3.0. Mods should access the `Data` property directly instead. * FOR SMAPI developers: diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 3bc0aca4..679838ba 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -184,7 +184,8 @@ namespace StardewModdingAPI.Framework // apply game patches new GamePatcher(this.Monitor).Apply( - new DialogueErrorPatch(this.MonitorForGame, this.Reflection) + new DialogueErrorPatch(this.MonitorForGame, this.Reflection), + new ObjectErrorPatch() ); } diff --git a/src/SMAPI/Patches/ObjectErrorPatch.cs b/src/SMAPI/Patches/ObjectErrorPatch.cs new file mode 100644 index 00000000..2cbb60c5 --- /dev/null +++ b/src/SMAPI/Patches/ObjectErrorPatch.cs @@ -0,0 +1,55 @@ +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using Harmony; +using StardewModdingAPI.Framework.Patching; +using StardewValley; +using SObject = StardewValley.Object; + +namespace StardewModdingAPI.Patches +{ + /// A Harmony patch for which intercepts crashes due to the item no longer existing. + internal class ObjectErrorPatch : IHarmonyPatch + { + /********* + ** Accessors + *********/ + /// A unique name for this patch. + public string Name => $"{nameof(ObjectErrorPatch)}"; + + + /********* + ** Public methods + *********/ + /// Apply the Harmony patch. + /// The Harmony instance. + public void Apply(HarmonyInstance harmony) + { + MethodInfo method = AccessTools.Method(typeof(SObject), nameof(SObject.getDescription)); + MethodInfo prefix = AccessTools.Method(this.GetType(), nameof(ObjectErrorPatch.Prefix)); + + harmony.Patch(method, new HarmonyMethod(prefix), null); + } + + + /********* + ** Private methods + *********/ + /// The method to call instead of . + /// The instance being patched. + /// The patched method's return value. + /// Returns whether to execute the original method. + /// This method must be static for Harmony to work correctly. See the Harmony documentation before renaming arguments. + [SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Argument names are defined by Harmony.")] + private static bool Prefix(SObject __instance, ref string __result) + { + // invalid bigcraftables crash instead of showing '???' like invalid non-bigcraftables + if (!__instance.IsRecipe && __instance.bigCraftable.Value && !Game1.bigCraftablesInformation.ContainsKey(__instance.ParentSheetIndex)) + { + __result = "???"; + return false; + } + + return false; + } + } +} diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index 2c769f41..3f1a273d 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -326,6 +326,7 @@ + -- cgit From 7cbc716b85d950d8deb5d9aeadeb2d2f267aea79 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 16 Dec 2018 17:12:44 -0500 Subject: remove default SMAPI 3.0 strict mode in debug builds --- src/SMAPI/StardewModdingAPI.csproj | 2 +- .../StardewModdingAPI.Toolkit.CoreInterfaces.csproj | 4 ---- src/StardewModdingAPI.Toolkit/StardewModdingAPI.Toolkit.csproj | 4 ---- 3 files changed, 1 insertion(+), 9 deletions(-) (limited to 'src/SMAPI/StardewModdingAPI.csproj') diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index 3f1a273d..9b00e777 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -32,7 +32,7 @@ x86 false - DEBUG;TRACE;SMAPI_3_0_STRICT + DEBUG;TRACE true false $(SolutionDir)\..\bin\Debug\SMAPI diff --git a/src/StardewModdingAPI.Toolkit.CoreInterfaces/StardewModdingAPI.Toolkit.CoreInterfaces.csproj b/src/StardewModdingAPI.Toolkit.CoreInterfaces/StardewModdingAPI.Toolkit.CoreInterfaces.csproj index 539cb5d8..525931e5 100644 --- a/src/StardewModdingAPI.Toolkit.CoreInterfaces/StardewModdingAPI.Toolkit.CoreInterfaces.csproj +++ b/src/StardewModdingAPI.Toolkit.CoreInterfaces/StardewModdingAPI.Toolkit.CoreInterfaces.csproj @@ -8,10 +8,6 @@ ..\..\bin\$(Configuration)\SMAPI.Toolkit.CoreInterfaces\$(TargetFramework)\StardewModdingAPI.Toolkit.CoreInterfaces.xml - - $(DefineConstants);SMAPI_3_0_STRICT - - diff --git a/src/StardewModdingAPI.Toolkit/StardewModdingAPI.Toolkit.csproj b/src/StardewModdingAPI.Toolkit/StardewModdingAPI.Toolkit.csproj index 29667b1e..3fa28d19 100644 --- a/src/StardewModdingAPI.Toolkit/StardewModdingAPI.Toolkit.csproj +++ b/src/StardewModdingAPI.Toolkit/StardewModdingAPI.Toolkit.csproj @@ -7,10 +7,6 @@ ..\..\bin\$(Configuration)\SMAPI.Toolkit\$(TargetFramework)\StardewModdingAPI.Toolkit.xml - - $(DefineConstants);SMAPI_3_0_STRICT - - -- cgit