summaryrefslogtreecommitdiff
path: root/src/SMAPI.Mods.ErrorHandler/Patches/ScheduleErrorPatch.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-07-13 09:14:07 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-07-13 09:14:07 -0400
commit8df578edb6d135796a48b219ecc7a7291c7ef460 (patch)
tree3b52286c16465a10722399350e9e3dc1a2bc0a73 /src/SMAPI.Mods.ErrorHandler/Patches/ScheduleErrorPatch.cs
parentbd20c2e1375ed5e32315ef5e292802bccc42f530 (diff)
downloadSMAPI-8df578edb6d135796a48b219ecc7a7291c7ef460.tar.gz
SMAPI-8df578edb6d135796a48b219ecc7a7291c7ef460.tar.bz2
SMAPI-8df578edb6d135796a48b219ecc7a7291c7ef460.zip
migrate to Harmony 2.1 (#711)
Diffstat (limited to 'src/SMAPI.Mods.ErrorHandler/Patches/ScheduleErrorPatch.cs')
-rw-r--r--src/SMAPI.Mods.ErrorHandler/Patches/ScheduleErrorPatch.cs50
1 files changed, 3 insertions, 47 deletions
diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/ScheduleErrorPatch.cs b/src/SMAPI.Mods.ErrorHandler/Patches/ScheduleErrorPatch.cs
index d2a5e988..d2e332b4 100644
--- a/src/SMAPI.Mods.ErrorHandler/Patches/ScheduleErrorPatch.cs
+++ b/src/SMAPI.Mods.ErrorHandler/Patches/ScheduleErrorPatch.cs
@@ -1,15 +1,10 @@
+using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
-using StardewModdingAPI.Framework.Patching;
-using StardewValley;
-#if HARMONY_2
-using System;
using HarmonyLib;
using StardewModdingAPI.Framework;
-#else
-using System.Reflection;
-using Harmony;
-#endif
+using StardewModdingAPI.Framework.Patching;
+using StardewValley;
namespace StardewModdingAPI.Mods.ErrorHandler.Patches
{
@@ -37,19 +32,11 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
}
/// <inheritdoc />
-#if HARMONY_2
public void Apply(Harmony harmony)
-#else
- public void Apply(HarmonyInstance harmony)
-#endif
{
harmony.Patch(
original: AccessTools.Method(typeof(NPC), nameof(NPC.parseMasterSchedule)),
-#if HARMONY_2
finalizer: new HarmonyMethod(this.GetType(), nameof(ScheduleErrorPatch.Finalize_NPC_parseMasterSchedule))
-#else
- prefix: new HarmonyMethod(this.GetType(), nameof(ScheduleErrorPatch.Before_NPC_parseMasterSchedule))
-#endif
);
}
@@ -57,7 +44,6 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
/*********
** Private methods
*********/
-#if HARMONY_2
/// <summary>The method to call instead of <see cref="NPC.parseMasterSchedule"/>.</summary>
/// <param name="rawData">The raw schedule data to parse.</param>
/// <param name="__instance">The instance being patched.</param>
@@ -74,35 +60,5 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
return null;
}
-#else
- /// <summary>The method to call instead of <see cref="NPC.parseMasterSchedule"/>.</summary>
- /// <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)
- {
- const string key = nameof(ScheduleErrorPatch.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)
- {
- ScheduleErrorPatch.MonitorForGame.Log($"Failed parsing schedule for NPC {__instance.Name}:\n{rawData}\n{ex.InnerException ?? ex}", LogLevel.Error);
- __result = new Dictionary<int, SchedulePathDescription>();
- return false;
- }
- finally
- {
- PatchHelper.StopIntercept(key);
- }
- }
-#endif
}
}