Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
suppress Harmony's MemberNotFound logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Chasmical committed Jul 9, 2021
1 parent 2f446c4 commit 08a7408
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions RogueLibsCore/Utilities/RoguePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public void LogResults()
log.LogDebug($"Total: {total,5:#####}ms");
}

private static readonly BindingFlags All = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

public bool Prefix(Type targetType, string targetMethod, Type[] targetParameterTypes = null)
{
if (targetType is null) throw new ArgumentNullException(nameof(targetType));
Expand All @@ -73,22 +75,20 @@ public bool Prefix(Type targetType, string targetMethod, string patchMethod, Typ
{
sw = new Stopwatch();
sw.Start();
MethodInfo target = AccessTools.Method(targetType, targetMethod, targetParameterTypes)
MethodInfo target = targetType.GetMethod(targetMethod, All, null, targetParameterTypes, null)
?? throw new MemberNotFoundException($"Target method {targetType.FullName}.{targetMethod} could not be found.");

MethodInfo patch = AccessTools.Method(TypeWithPatches, patchMethod)
MethodInfo patch = TypeWithPatches.GetMethod(patchMethod, All)
?? throw new MemberNotFoundException($"Patch method {TypeWithPatches.FullName}.{patchMethod} could not be found.");

harmony.Patch(target, new HarmonyMethod(patch));
sw.Stop();

results.Add(new PatchTime("Prefix", target, patch, sw.Elapsed));
}
else
{
MethodInfo target = AccessTools.Method(targetType, targetMethod, targetParameterTypes)
MethodInfo target = targetType.GetMethod(targetMethod, All, null, targetParameterTypes, null)
?? throw new MemberNotFoundException($"Target method {targetType.FullName}.{targetMethod} could not be found.");
MethodInfo patch = AccessTools.Method(TypeWithPatches, patchMethod)
MethodInfo patch = TypeWithPatches.GetMethod(patchMethod, All)
?? throw new MemberNotFoundException($"Patch method {TypeWithPatches.FullName}.{patchMethod} could not be found.");
harmony.Patch(target, new HarmonyMethod(patch));
}
Expand Down Expand Up @@ -120,22 +120,20 @@ public bool Postfix(Type targetType, string targetMethod, string patchMethod, Ty
{
sw = new Stopwatch();
sw.Start();
MethodInfo target = AccessTools.Method(targetType, targetMethod, targetParameterTypes)
MethodInfo target = targetType.GetMethod(targetMethod, All, null, targetParameterTypes, null)
?? throw new MemberNotFoundException($"Target method {targetType.FullName}.{targetMethod} could not be found.");

MethodInfo patch = AccessTools.Method(TypeWithPatches, patchMethod)
MethodInfo patch = TypeWithPatches.GetMethod(patchMethod, All)
?? throw new MemberNotFoundException($"Patch method {TypeWithPatches.FullName}.{patchMethod} could not be found.");

harmony.Patch(target, null, new HarmonyMethod(patch));
sw.Stop();

results.Add(new PatchTime("Postfix", target, patch, sw.Elapsed));
}
else
{
MethodInfo target = AccessTools.Method(targetType, targetMethod, targetParameterTypes)
MethodInfo target = targetType.GetMethod(targetMethod, All, null, targetParameterTypes, null)
?? throw new MemberNotFoundException($"Target method {targetType.FullName}.{targetMethod} could not be found.");
MethodInfo patch = AccessTools.Method(TypeWithPatches, patchMethod)
MethodInfo patch = TypeWithPatches.GetMethod(patchMethod, All)
?? throw new MemberNotFoundException($"Patch method {TypeWithPatches.FullName}.{patchMethod} could not be found.");
harmony.Patch(target, null, new HarmonyMethod(patch));
}
Expand Down Expand Up @@ -167,22 +165,20 @@ public bool Transpiler(Type targetType, string targetMethod, string patchMethod,
{
sw = new Stopwatch();
sw.Start();
MethodInfo target = AccessTools.Method(targetType, targetMethod, targetParameterTypes)
MethodInfo target = targetType.GetMethod(targetMethod, All, null, targetParameterTypes, null)
?? throw new MemberNotFoundException($"Target method {targetType.FullName}.{targetMethod} could not be found.");

MethodInfo patch = AccessTools.Method(TypeWithPatches, patchMethod)
MethodInfo patch = TypeWithPatches.GetMethod(patchMethod, All)
?? throw new MemberNotFoundException($"Patch method {TypeWithPatches.FullName}.{patchMethod} could not be found.");

harmony.Patch(target, null, null, new HarmonyMethod(patch));
sw.Stop();

results.Add(new PatchTime("Transpiler", target, patch, sw.Elapsed));
}
else
{
MethodInfo target = AccessTools.Method(targetType, targetMethod, targetParameterTypes)
MethodInfo target = targetType.GetMethod(targetMethod, All, null, targetParameterTypes, null)
?? throw new MemberNotFoundException($"Target method {targetType.FullName}.{targetMethod} could not be found.");
MethodInfo patch = AccessTools.Method(TypeWithPatches, patchMethod)
MethodInfo patch = TypeWithPatches.GetMethod(patchMethod, All)
?? throw new MemberNotFoundException($"Patch method {TypeWithPatches.FullName}.{patchMethod} could not be found.");
harmony.Patch(target, null, null, new HarmonyMethod(patch));
}
Expand Down Expand Up @@ -214,22 +210,20 @@ public bool Finalizer(Type targetType, string targetMethod, string patchMethod,
{
sw = new Stopwatch();
sw.Start();
MethodInfo target = AccessTools.Method(targetType, targetMethod, targetParameterTypes)
MethodInfo target = targetType.GetMethod(targetMethod, All, null, targetParameterTypes, null)
?? throw new MemberNotFoundException($"Target method {targetType.FullName}.{targetMethod} could not be found.");

MethodInfo patch = AccessTools.Method(TypeWithPatches, patchMethod)
MethodInfo patch = TypeWithPatches.GetMethod(patchMethod, All)
?? throw new MemberNotFoundException($"Patch method {TypeWithPatches.FullName}.{patchMethod} could not be found.");

harmony.Patch(target, null, null, null, new HarmonyMethod(patch));
sw.Stop();

results.Add(new PatchTime("Finalizer", target, patch, sw.Elapsed));
}
else
{
MethodInfo target = AccessTools.Method(targetType, targetMethod, targetParameterTypes)
MethodInfo target = targetType.GetMethod(targetMethod, All, null, targetParameterTypes, null)
?? throw new MemberNotFoundException($"Target method {targetType.FullName}.{targetMethod} could not be found.");
MethodInfo patch = AccessTools.Method(TypeWithPatches, patchMethod)
MethodInfo patch = TypeWithPatches.GetMethod(patchMethod, All)
?? throw new MemberNotFoundException($"Patch method {TypeWithPatches.FullName}.{patchMethod} could not be found.");
harmony.Patch(target, null, null, null, new HarmonyMethod(patch));
}
Expand Down

0 comments on commit 08a7408

Please sign in to comment.