Skip to content

Commit 7b58644

Browse files
committed
Add Delegate constraint to detour provider
1 parent f9faf96 commit 7b58644

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

Il2CppInterop.HarmonySupport/Il2CppDetourMethodPatcher.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,8 @@ public override MethodBase DetourTo(MethodBase replacement)
143143

144144
DelegateCache[Original] = unmanagedDelegate;
145145

146-
var detourPtr =
147-
Marshal.GetFunctionPointerForDelegate(unmanagedDelegate);
148146
nativeDetour =
149-
Il2CppInteropRuntime.Instance.DetourProvider.Create(originalNativeMethodInfo.MethodPointer, detourPtr);
147+
Il2CppInteropRuntime.Instance.DetourProvider.Create(originalNativeMethodInfo.MethodPointer, unmanagedDelegate);
150148
nativeDetour.Apply();
151149
modifiedNativeMethodInfo.MethodPointer = nativeDetour.OriginalTrampoline;
152150

Il2CppInterop.Runtime/Injection/DetourProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface IDetour : IDisposable
1515

1616
public interface IDetourProvider
1717
{
18-
IDetour Create<TDelegate>(nint original, TDelegate target);
18+
IDetour Create<TDelegate>(nint original, TDelegate target) where TDelegate : Delegate;
1919
}
2020

2121
internal static class Detour

0 commit comments

Comments
 (0)