Skip to content

Commit 5bb676c

Browse files
support data hook parameter
1 parent 713be62 commit 5bb676c

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

Runtimes/Unity/BepInEx.Unity.IL2CPP/Hook/NativeDetour.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Runtime.InteropServices;
33
using Il2CppInterop.Runtime.Injection;
44

@@ -8,12 +8,19 @@ public unsafe class NativeDetour : IDetour
88
{
99
public IntPtr Target { get; }
1010
public IntPtr Detour { get; }
11+
public bool UnityFunction { get; }
1112
public IntPtr OriginalTrampoline { get; private set; }
1213

1314
public NativeDetour(IntPtr target, Delegate detour)
15+
: this(target, detour, false)
16+
{
17+
}
18+
19+
public NativeDetour(IntPtr target, Delegate detour, bool unityFunction)
1420
{
1521
Target = target;
1622
Detour = Marshal.GetFunctionPointerForDelegate(detour);
23+
UnityFunction = unityFunction;
1724
Apply();
1825
}
1926

@@ -23,7 +30,7 @@ public void Apply()
2330
{
2431
return;
2532
}
26-
OriginalTrampoline = StarlightInterop.hook(Target, Detour);
33+
OriginalTrampoline = StarlightInterop.hook(Target, Detour, UnityFunction);
2734
}
2835

2936
public void Dispose()

Runtimes/Unity/BepInEx.Unity.IL2CPP/Hook/NativeDetourProvider.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using Il2CppInterop.Runtime.Injection;
33

44
namespace BepInEx.Unity.IL2CPP.Hook;
@@ -10,4 +10,10 @@ public IDetour Create<TDelegate>(IntPtr original, TDelegate target) where TDeleg
1010
var detour = new NativeDetour(original, target);
1111
return new CacheDetourWrapper(detour, target);
1212
}
13+
14+
public IDetour Create<TDelegate>(IntPtr original, TDelegate target, bool unityFunction) where TDelegate : Delegate
15+
{
16+
var detour = new NativeDetour(original, target, unityFunction);
17+
return new CacheDetourWrapper(detour, target);
18+
}
1319
}

Runtimes/Unity/BepInEx.Unity.IL2CPP/StarlightInterop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal static partial class StarlightInterop
1313
public static unsafe partial void write_log([MarshalAs(UnmanagedType.LPStr)] string message);
1414

1515
[LibraryImport(LIBRARY_NAME)]
16-
public static unsafe partial IntPtr hook(IntPtr target, IntPtr detour);
16+
public static unsafe partial IntPtr hook(IntPtr target, IntPtr detour, [MarshalAs(UnmanagedType.I1)] bool unityFunction);
1717

1818
[LibraryImport(LIBRARY_NAME)]
1919
public static unsafe partial void unhook(IntPtr target);

0 commit comments

Comments
 (0)