Add config option for forced detour provider

This commit is contained in:
Kasuromi authored and ghorsington committed 2022-08-14 17:18:58 +03:00
1 parent 9432878863
commit 83b72d568b
1 file changed
+26 -2
+26 -2
View File
@@ -1,3 +1,4 @@
using BepInEx.Configuration;
using BepInEx.IL2CPP.Hook.Dobby;
using BepInEx.IL2CPP.Hook.Funchook;
using System;
@@ -7,11 +8,34 @@ namespace BepInEx.IL2CPP.Hook;
public class NativeDetourHelper
{
internal enum DetourProvider
{
Default,
Dobby,
Funchook
}
private static readonly ConfigEntry<DetourProvider> DetourProviderType = ConfigFile.CoreConfig.Bind(
"Detours", "DetourProviderType",
DetourProvider.Default,
"The native provider to use for managed detours"
);
public static bool DEBUG_DETOURS = false;
private static INativeDetour CreateDefault(nint original, nint target)
{
// TODO: check and provide an OS accurate provider
return new DobbyDetour(original, target);
}
public static INativeDetour Create(nint original, nint target)
{
return new DobbyDetour(original, target);
//return new FunchookDetour(original, target);
return DetourProviderType.Value switch
{
DetourProvider.Dobby => new DobbyDetour(original, target),
DetourProvider.Funchook => new FunchookDetour(original, target),
_ => CreateDefault(original, target)
};
}
public static INativeDetour CreateAndApply<T>(nint from, T to, out T original, CallingConvention? callingConvention = null)