diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-07-21 22:49:53 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-07-21 22:49:53 -0400 |
commit | 92bcb8405c4dc0f4af283146a2ad6ea3a178fd06 (patch) | |
tree | 2e5bae4b7e8c1a625c2c8f1e3b8729c5ca61c8aa /src/SMAPI.Mods.ErrorHandler/Patches/UtilityErrorPatches.cs | |
parent | 7e5d77fb8c2606795af239717a596de460bc58f7 (diff) | |
parent | 72b3c9d14314a3f69a0ca9d6ac9de9de1d31943d (diff) | |
download | SMAPI-92bcb8405c4dc0f4af283146a2ad6ea3a178fd06.tar.gz SMAPI-92bcb8405c4dc0f4af283146a2ad6ea3a178fd06.tar.bz2 SMAPI-92bcb8405c4dc0f4af283146a2ad6ea3a178fd06.zip |
Merge branch 'harmony-2' into develop
Diffstat (limited to 'src/SMAPI.Mods.ErrorHandler/Patches/UtilityErrorPatches.cs')
-rw-r--r-- | src/SMAPI.Mods.ErrorHandler/Patches/UtilityErrorPatches.cs | 48 |
1 files changed, 1 insertions, 47 deletions
diff --git a/src/SMAPI.Mods.ErrorHandler/Patches/UtilityErrorPatches.cs b/src/SMAPI.Mods.ErrorHandler/Patches/UtilityErrorPatches.cs index 1ddd407c..cd57736f 100644 --- a/src/SMAPI.Mods.ErrorHandler/Patches/UtilityErrorPatches.cs +++ b/src/SMAPI.Mods.ErrorHandler/Patches/UtilityErrorPatches.cs @@ -1,12 +1,6 @@ -#if HARMONY_2 -using System; -using HarmonyLib; -#else -using Harmony; -#endif using System; using System.Diagnostics.CodeAnalysis; -using System.Reflection; +using HarmonyLib; using StardewModdingAPI.Framework.Patching; using StardewValley; @@ -22,7 +16,6 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches ** Public methods *********/ /// <inheritdoc /> -#if HARMONY_2 public void Apply(Harmony harmony) { harmony.Patch( @@ -30,21 +23,11 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches finalizer: new HarmonyMethod(this.GetType(), nameof(UtilityErrorPatches.Finalize_Utility_GetItemFromStandardTextDescription)) ); } -#else - public void Apply(HarmonyInstance harmony) - { - harmony.Patch( - original: AccessTools.Method(typeof(Utility), nameof(Utility.getItemFromStandardTextDescription)), - prefix: new HarmonyMethod(this.GetType(), nameof(UtilityErrorPatches.Before_Utility_GetItemFromStandardTextDescription)) - ); - } -#endif /********* ** Private methods *********/ -#if HARMONY_2 /// <summary>The method to call instead of <see cref="Utility.getItemFromStandardTextDescription"/>.</summary> /// <param name="description">The item text description to parse.</param> /// <param name="delimiter">The delimiter by which to split the text description.</param> @@ -56,34 +39,5 @@ namespace StardewModdingAPI.Mods.ErrorHandler.Patches ? new FormatException($"Failed to parse item text description \"{description}\" with delimiter \"{delimiter}\".", __exception) : null; } -#else - /// <summary>The method to call instead of <see cref="Utility.getItemFromStandardTextDescription"/>.</summary> - /// <param name="__result">The return value of the original method.</param> - /// <param name="description">The item text description to parse.</param> - /// <param name="who">The player for which the item is being parsed.</param> - /// <param name="delimiter">The delimiter by which to split the text description.</param> - /// <param name="__originalMethod">The method being wrapped.</param> - /// <returns>Returns whether to execute the original method.</returns> - private static bool Before_Utility_GetItemFromStandardTextDescription(ref Item __result, string description, Farmer who, char delimiter, MethodInfo __originalMethod) - { - const string key = nameof(UtilityErrorPatches.Before_Utility_GetItemFromStandardTextDescription); - if (!PatchHelper.StartIntercept(key)) - return true; - - try - { - __result = (Item)__originalMethod.Invoke(null, new object[] { description, who, delimiter }); - return false; - } - catch (TargetInvocationException ex) - { - throw new FormatException($"Failed to parse item text description \"{description}\" with delimiter \"{delimiter}\".", ex.InnerException); - } - finally - { - PatchHelper.StopIntercept(key); - } - } -#endif } } |