summaryrefslogtreecommitdiff
path: root/src/SMAPI.Mods.ErrorHandler
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Mods.ErrorHandler')
-rw-r--r--src/SMAPI.Mods.ErrorHandler/Patches/GameLocationPatches.cs59
-rw-r--r--src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj3
-rw-r--r--src/SMAPI.Mods.ErrorHandler/manifest.json4
3 files changed, 59 insertions, 7 deletions
diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/GameLocationPatches.cs b/src/SMAPI.Mods.ErrorHandler/Patches/GameLocationPatches.cs
index 1edf2d6a..7a48133e 100644
--- a/src/SMAPI.Mods.ErrorHandler/Patches/GameLocationPatches.cs
+++ b/src/SMAPI.Mods.ErrorHandler/Patches/GameLocationPatches.cs
@@ -8,10 +8,11 @@ using Harmony;
#endif
using StardewModdingAPI.Framework.Patching;
using StardewValley;
+using xTile;
namespace StardewModdingAPI.Mods.ErrorHandler.Patches
{
- /// <summary>A Harmony patch for <see cref="GameLocation.checkEventPrecondition"/> which intercepts invalid preconditions and logs an error instead of crashing.</summary>
+ /// <summary>Harmony patches for <see cref="GameLocation.checkEventPrecondition"/> and <see cref="GameLocation.updateSeasonalTileSheets"/> which intercept errors instead of crashing.</summary>
/// <remarks>Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Argument names are defined by Harmony and methods are named for clarity.")]
[SuppressMessage("ReSharper", "IdentifierTypo", Justification = "Argument names are defined by Harmony and methods are named for clarity.")]
@@ -39,17 +40,25 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
public void Apply(Harmony harmony)
{
harmony.Patch(
- original: AccessTools.Method(typeof(GameLocation), "checkEventPrecondition"),
+ original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.checkEventPrecondition)),
finalizer: new HarmonyMethod(this.GetType(), nameof(EventErrorPatch.Finalize_GameLocation_CheckEventPrecondition))
);
+harmony.Patch(
+ original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.updateSeasonalTileSheets)),
+ finalizer: new HarmonyMethod(this.GetType(), nameof(EventErrorPatch.Before_GameLocation_UpdateSeasonalTileSheets))
+ );
}
#else
public void Apply(HarmonyInstance harmony)
{
harmony.Patch(
- original: AccessTools.Method(typeof(GameLocation), "checkEventPrecondition"),
+ original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.checkEventPrecondition)),
prefix: new HarmonyMethod(this.GetType(), nameof(GameLocationPatches.Before_GameLocation_CheckEventPrecondition))
);
+ harmony.Patch(
+ original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.updateSeasonalTileSheets)),
+ prefix: new HarmonyMethod(this.GetType(), nameof(GameLocationPatches.Before_GameLocation_UpdateSeasonalTileSheets))
+ );
}
#endif
@@ -74,7 +83,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
return null;
}
#else
- /// <summary>The method to call instead of GameLocation.checkEventPrecondition.</summary>
+ /// <summary>The method to call instead of <see cref="GameLocation.checkEventPrecondition"/>.</summary>
/// <param name="__instance">The instance being patched.</param>
/// <param name="__result">The return value of the original method.</param>
/// <param name="precondition">The precondition to be parsed.</param>
@@ -103,5 +112,47 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
}
}
#endif
+
+#if HARMONY_2
+ /// <summary>The method to call instead of <see cref="GameLocation.updateSeasonalTileSheets"/>.</summary>
+ /// <param name="__instance">The instance being patched.</param>
+ /// <param name="map">The map whose tilesheets to update.</param>
+ /// <param name="__exception">The exception thrown by the wrapped method, if any.</param>
+ /// <returns>Returns the exception to throw, if any.</returns>
+ private static Exception Before_GameLocation_UpdateSeasonalTileSheets(GameLocation __instance, Map map, Exception __exception)
+ {
+ if (__exception != null)
+ GameLocationPatches.MonitorForGame.Log($"Failed updating seasonal tilesheets for location '{__instance.NameOrUniqueName}': \n{__exception}", LogLevel.Error);
+
+ return null;
+ }
+#else
+ /// <summary>The method to call instead of <see cref="GameLocation.updateSeasonalTileSheets"/>.</summary>
+ /// <param name="__instance">The instance being patched.</param>
+ /// <param name="map">The map whose tilesheets to update.</param>
+ /// <param name="__originalMethod">The method being wrapped.</param>
+ /// <returns>Returns whether to execute the original method.</returns>
+ private static bool Before_GameLocation_UpdateSeasonalTileSheets(GameLocation __instance, Map map, MethodInfo __originalMethod)
+ {
+ const string key = nameof(GameLocationPatches.Before_GameLocation_UpdateSeasonalTileSheets);
+ if (!PatchHelper.StartIntercept(key))
+ return true;
+
+ try
+ {
+ __originalMethod.Invoke(__instance, new object[] { map });
+ return false;
+ }
+ catch (TargetInvocationException ex)
+ {
+ GameLocationPatches.MonitorForGame.Log($"Failed updating seasonal tilesheets for location '{__instance.NameOrUniqueName}'. Technical details:\n{ex.InnerException}", LogLevel.Error);
+ return false;
+ }
+ finally
+ {
+ PatchHelper.StopIntercept(key);
+ }
+ }
+#endif
}
}
diff --git a/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj b/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj
index 788f6f16..006a09ca 100644
--- a/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj
+++ b/src/SMAPI.Mods.ErrorHandler/SMAPI.Mods.ErrorHandler.csproj
@@ -15,11 +15,12 @@
<ItemGroup>
<Reference Include="$(GameExecutableName)" HintPath="$(GamePath)\$(GameExecutableName).exe" Private="False" />
+ <Reference Include="xTile" HintPath="$(GamePath)\xTile.dll" Private="False" />
</ItemGroup>
<!-- Windows only -->
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
- <Reference Include="Netcode" HintPath="$(GamePath)\Netcode.dll" Private="False" />
+ <Reference Include="Netcode" HintPath="$(GamePath)\Netcode.dll" Private="False" Condition="!$(DefineConstants.Contains(SMAPI_FOR_WINDOWS_64BIT_HACK))" />
</ItemGroup>
<!-- Game framework -->
diff --git a/src/SMAPI.Mods.ErrorHandler/manifest.json b/src/SMAPI.Mods.ErrorHandler/manifest.json
index 1e810113..ab519781 100644
--- a/src/SMAPI.Mods.ErrorHandler/manifest.json
+++ b/src/SMAPI.Mods.ErrorHandler/manifest.json
@@ -1,9 +1,9 @@
{
"Name": "Error Handler",
"Author": "SMAPI",
- "Version": "3.9.5",
+ "Version": "3.10.0",
"Description": "Handles some common vanilla errors to log more useful info or avoid breaking the game.",
"UniqueID": "SMAPI.ErrorHandler",
"EntryDll": "ErrorHandler.dll",
- "MinimumApiVersion": "3.9.5"
+ "MinimumApiVersion": "3.10.0"
}