summaryrefslogtreecommitdiff
path: root/src/SMAPI/Patches/ScheduleErrorPatch.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-20 19:38:08 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-20 19:38:08 -0400
commit310eb1fe9afdb820d5584a46200bf073fc00ccb7 (patch)
tree72c16c6d4f8447f45e8e6612cb25cd255d2b308c /src/SMAPI/Patches/ScheduleErrorPatch.cs
parentaa5cc2c9be8bdc79c6fa7b1b9c2581a05b88117d (diff)
parentc5c30189e43f93c3f3c66207945187a974656c9e (diff)
downloadSMAPI-310eb1fe9afdb820d5584a46200bf073fc00ccb7.tar.gz
SMAPI-310eb1fe9afdb820d5584a46200bf073fc00ccb7.tar.bz2
SMAPI-310eb1fe9afdb820d5584a46200bf073fc00ccb7.zip
Merge branch 'mod/harmony-2.0' into develop
# Conflicts: # docs/release-notes.md # src/SMAPI/Framework/ModLoading/AssemblyLoader.cs
Diffstat (limited to 'src/SMAPI/Patches/ScheduleErrorPatch.cs')
-rw-r--r--src/SMAPI/Patches/ScheduleErrorPatch.cs35
1 files changed, 12 insertions, 23 deletions
diff --git a/src/SMAPI/Patches/ScheduleErrorPatch.cs b/src/SMAPI/Patches/ScheduleErrorPatch.cs
index 799fcb40..df6ffab3 100644
--- a/src/SMAPI/Patches/ScheduleErrorPatch.cs
+++ b/src/SMAPI/Patches/ScheduleErrorPatch.cs
@@ -1,7 +1,8 @@
+using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
-using System.Reflection;
-using Harmony;
+using HarmonyLib;
+using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Patching;
using StardewValley;
@@ -39,11 +40,11 @@ namespace StardewModdingAPI.Patches
/// <summary>Apply the Harmony patch.</summary>
/// <param name="harmony">The Harmony instance.</param>
- public void Apply(HarmonyInstance harmony)
+ public void Apply(Harmony harmony)
{
harmony.Patch(
original: AccessTools.Method(typeof(NPC), "parseMasterSchedule"),
- prefix: new HarmonyMethod(this.GetType(), nameof(ScheduleErrorPatch.Before_NPC_parseMasterSchedule))
+ finalizer: new HarmonyMethod(this.GetType(), nameof(ScheduleErrorPatch.Finalize_NPC_parseMasterSchedule))
);
}
@@ -55,29 +56,17 @@ namespace StardewModdingAPI.Patches
/// <param name="rawData">The raw schedule data to parse.</param>
/// <param name="__instance">The instance being patched.</param>
/// <param name="__result">The patched method's return value.</param>
- /// <param name="__originalMethod">The method being wrapped.</param>
- /// <returns>Returns whether to execute the original method.</returns>
- private static bool Before_NPC_parseMasterSchedule(string rawData, NPC __instance, ref Dictionary<int, SchedulePathDescription> __result, MethodInfo __originalMethod)
+ /// <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 Finalize_NPC_parseMasterSchedule(string rawData, NPC __instance, ref Dictionary<int, SchedulePathDescription> __result, Exception __exception)
{
- const string key = nameof(Before_NPC_parseMasterSchedule);
- if (!PatchHelper.StartIntercept(key))
- return true;
-
- try
- {
- __result = (Dictionary<int, SchedulePathDescription>)__originalMethod.Invoke(__instance, new object[] { rawData });
- return false;
- }
- catch (TargetInvocationException ex)
+ if (__exception != null)
{
- ScheduleErrorPatch.MonitorForGame.Log($"Failed parsing schedule for NPC {__instance.Name}:\n{rawData}\n{ex.InnerException ?? ex}", LogLevel.Error);
+ ScheduleErrorPatch.MonitorForGame.Log($"Failed parsing schedule for NPC {__instance.Name}:\n{rawData}\n{__exception.GetLogSummary()}", LogLevel.Error);
__result = new Dictionary<int, SchedulePathDescription>();
- return false;
- }
- finally
- {
- PatchHelper.StopIntercept(key);
}
+
+ return null;
}
}
}