From 83b72d568b573daa82d406fd5f174bf0c5c61dce Mon Sep 17 00:00:00 2001 From: Kasuromi <29818914+Kasuromi@users.noreply.github.com> Date: Thu, 5 May 2022 23:31:48 +0300 Subject: [PATCH] Add config option for forced detour provider --- BepInEx.IL2CPP/Hook/NativeDetourHelper.cs | 28 +++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/BepInEx.IL2CPP/Hook/NativeDetourHelper.cs b/BepInEx.IL2CPP/Hook/NativeDetourHelper.cs index 25a70fa..9a9d79f 100644 --- a/BepInEx.IL2CPP/Hook/NativeDetourHelper.cs +++ b/BepInEx.IL2CPP/Hook/NativeDetourHelper.cs @@ -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 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(nint from, T to, out T original, CallingConvention? callingConvention = null)