summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs b/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs
index 0f906f51..bca76981 100644
--- a/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs
+++ b/src/SMAPI/Framework/RewriteFacades/HarmonyInstanceMethods.cs
@@ -1,3 +1,5 @@
+using System;
+using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
@@ -24,10 +26,30 @@ namespace StardewModdingAPI.Framework.RewriteFacades
return new Harmony(id);
}
+ /// <summary>Apply one or more patches to a method.</summary>
+ /// <param name="original">The original method.</param>
+ /// <param name="prefix">The prefix to apply.</param>
+ /// <param name="postfix">The postfix to apply.</param>
+ /// <param name="transpiler">The transpiler to apply.</param>
public DynamicMethod Patch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod postfix = null, HarmonyMethod transpiler = null)
{
- MethodInfo method = base.Patch(original: original, prefix: prefix, postfix: postfix, transpiler: transpiler);
- return new DynamicMethod(method.Name, method.Attributes, method.CallingConvention, method.ReturnType, method.GetParameters().Select(p => p.ParameterType).ToArray(), method.Module, true);
+ try
+ {
+ MethodInfo method = base.Patch(original: original, prefix: prefix, postfix: postfix, transpiler: transpiler);
+ return new DynamicMethod(method.Name, method.Attributes, method.CallingConvention, method.ReturnType, method.GetParameters().Select(p => p.ParameterType).ToArray(), method.Module, true);
+ }
+ catch (Exception ex)
+ {
+ var patchTypes = new List<string>();
+ if (prefix != null)
+ patchTypes.Add("prefix");
+ if (postfix != null)
+ patchTypes.Add("postfix");
+ if (transpiler != null)
+ patchTypes.Add("transpiler");
+
+ throw new Exception($"Failed applying {string.Join("/", patchTypes)} to method {original.DeclaringType?.FullName}.{original.Name}", ex);
+ }
}
}
}