summaryrefslogtreecommitdiff
path: root/src/SMAPI.Mods.ErrorHandler/Patches/ObjectErrorPatch.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-07-21 22:49:53 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-07-21 22:49:53 -0400
commit92bcb8405c4dc0f4af283146a2ad6ea3a178fd06 (patch)
tree2e5bae4b7e8c1a625c2c8f1e3b8729c5ca61c8aa /src/SMAPI.Mods.ErrorHandler/Patches/ObjectErrorPatch.cs
parent7e5d77fb8c2606795af239717a596de460bc58f7 (diff)
parent72b3c9d14314a3f69a0ca9d6ac9de9de1d31943d (diff)
downloadSMAPI-92bcb8405c4dc0f4af283146a2ad6ea3a178fd06.tar.gz
SMAPI-92bcb8405c4dc0f4af283146a2ad6ea3a178fd06.tar.bz2
SMAPI-92bcb8405c4dc0f4af283146a2ad6ea3a178fd06.zip
Merge branch 'harmony-2' into develop
Diffstat (limited to 'src/SMAPI.Mods.ErrorHandler/Patches/ObjectErrorPatch.cs')
-rw-r--r--src/SMAPI.Mods.ErrorHandler/Patches/ObjectErrorPatch.cs50
1 files changed, 2 insertions, 48 deletions
diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/ObjectErrorPatch.cs b/src/SMAPI.Mods.ErrorHandler/Patches/ObjectErrorPatch.cs
index 9f8a98cd..a68e359c 100644
--- a/src/SMAPI.Mods.ErrorHandler/Patches/ObjectErrorPatch.cs
+++ b/src/SMAPI.Mods.ErrorHandler/Patches/ObjectErrorPatch.cs
@@ -1,16 +1,11 @@
+using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
+using HarmonyLib;
using StardewModdingAPI.Framework.Patching;
using StardewValley;
using StardewValley.Menus;
using SObject = StardewValley.Object;
-#if HARMONY_2
-using System;
-using HarmonyLib;
-#else
-using System.Reflection;
-using Harmony;
-#endif
namespace StardewModdingAPI.Mods.ErrorHandler.Patches
{
@@ -24,11 +19,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
** Public methods
*********/
/// <inheritdoc />
-#if HARMONY_2
public void Apply(Harmony harmony)
-#else
- public void Apply(HarmonyInstance harmony)
-#endif
{
// object.getDescription
harmony.Patch(
@@ -39,11 +30,7 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
// object.getDisplayName
harmony.Patch(
original: AccessTools.Method(typeof(SObject), "loadDisplayName"),
-#if HARMONY_2
finalizer: new HarmonyMethod(this.GetType(), nameof(ObjectErrorPatch.Finalize_Object_loadDisplayName))
-#else
- prefix: new HarmonyMethod(this.GetType(), nameof(ObjectErrorPatch.Before_Object_loadDisplayName))
-#endif
);
// IClickableMenu.drawToolTip
@@ -73,7 +60,6 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
return true;
}
-#if HARMONY_2
/// <summary>The method to call after <see cref="StardewValley.Object.loadDisplayName"/>.</summary>
/// <param name="__result">The patched method's return value.</param>
/// <param name="__exception">The exception thrown by the wrapped method, if any.</param>
@@ -88,38 +74,6 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches
return __exception;
}
-#else
- /// <summary>The method to call instead of <see cref="StardewValley.Object.loadDisplayName"/>.</summary>
- /// <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_Object_loadDisplayName(SObject __instance, ref string __result, MethodInfo __originalMethod)
- {
- const string key = nameof(ObjectErrorPatch.Before_Object_loadDisplayName);
- if (!PatchHelper.StartIntercept(key))
- return true;
-
- try
- {
- __result = (string)__originalMethod.Invoke(__instance, new object[0]);
- return false;
- }
- catch (TargetInvocationException ex) when (ex.InnerException is KeyNotFoundException)
- {
- __result = "???";
- return false;
- }
- catch
- {
- return true;
- }
- finally
- {
- PatchHelper.StopIntercept(key);
- }
- }
-#endif
/// <summary>The method to call instead of <see cref="IClickableMenu.drawToolTip"/>.</summary>
/// <param name="hoveredItem">The item for which to draw a tooltip.</param>