Skip to content

Commit 0c338aa

Browse files
Coalesce
1 parent 035390b commit 0c338aa

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

Patches/PatchHandler.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,9 @@ public static void UnpatchAll()
6767
public static void ApplyPatch(Type targetClass, string methodName, MethodInfo prefix = null, MethodInfo postfix = null, Type[] parameterTypes = null)
6868
{
6969
var original =
70-
parameterTypes == null ?
70+
(parameterTypes == null ?
7171
targetClass.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static) :
72-
targetClass.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static, null, parameterTypes, null);
73-
74-
if (original == null)
75-
throw new Exception($"Method '{methodName}' not found on {targetClass.FullName}");
76-
72+
targetClass.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static, null, parameterTypes, null)) ?? throw new Exception($"Method '{methodName}' not found on {targetClass.FullName}");
7773
instance.Patch(original,
7874
prefix: prefix != null ? new HarmonyMethod(prefix) : null,
7975
postfix: postfix != null ? new HarmonyMethod(postfix) : null);
@@ -82,12 +78,9 @@ public static void ApplyPatch(Type targetClass, string methodName, MethodInfo pr
8278
public static void RemovePatch(Type targetClass, string methodName, Type[] parameterTypes = null)
8379
{
8480
var original =
85-
parameterTypes == null ?
81+
(parameterTypes == null ?
8682
targetClass.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static) :
87-
targetClass.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static, null, parameterTypes, null);
88-
if (original == null)
89-
throw new Exception($"Method '{methodName}' not found on {targetClass.FullName}");
90-
83+
targetClass.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static, null, parameterTypes, null)) ?? throw new Exception($"Method '{methodName}' not found on {targetClass.FullName}");
9184
instance.Unpatch(original, HarmonyPatchType.All, instance.Id);
9285
}
9386

0 commit comments

Comments
 (0)