Skip to content

Commit

Permalink
Allow patching undeclared methods; emit warning instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ghorsington committed Nov 8, 2020
1 parent 0e6860c commit 9a08670
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Harmony/Public/PatchProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Reflection.Emit;
using HarmonyLib.Internal.Patching;
using HarmonyLib.Public.Patching;
using HarmonyLib.Tools;

namespace HarmonyLib
{
Expand Down Expand Up @@ -130,10 +131,7 @@ public MethodInfo Patch()
throw new NullReferenceException($"Null method for {instance.Id}");

if (original.IsDeclaredMember() is false)
{
var declaredMember = original.GetDeclaredMember();
throw new ArgumentException($"You can only patch implemented methods/constructors. Path the declared method {declaredMember.FullDescription()} instead.");
}
Logger.Log(Logger.LogChannel.Warn, () => $"{instance.Id}: You should only patch implemented methods/constructors to avoid issues. Path the declared method {original.GetDeclaredMember().FullDescription()} instead of {original.FullDescription()}.");

lock (locker)
{
Expand Down

0 comments on commit 9a08670

Please sign in to comment.