public static void HookAll() { Log.Info($"Patching all terminal functions..."); FastNativeDetour.CreateAndApply(IL2CPP.il2cpp_resolve_icall("UnityEngine.Input::" + "get_inputString"), OurGetInputString, out originalInputStringGetter, CallingConvention.Cdecl); FastNativeDetour.CreateAndApply(IL2CPP.il2cpp_resolve_icall("UnityEngine.Input::" + "get_anyKeyDown"), OurGetAnyInput, out originalAnyInputDownGetter, CallingConvention.Cdecl); }
public static void HookIntoSpawnData() { unsafe { var originalMethodPointer = *(IntPtr *)(IntPtr)UnhollowerUtils .GetIl2CppMethodInfoPointerFieldForGeneratedMethod(typeof(EnemyGroup).GetMethod(nameof(EnemyGroup.GetSpawnData))) .GetValue(null); FastNativeDetour.CreateAndApply(originalMethodPointer, HackyHooks.GetEnemySpawnDataPatch, out ourGetEnemySpawnData, CallingConvention.Cdecl); } }
public static void HookIntoChatMessages() { unsafe { var originalMethodPointer = *(IntPtr *)(IntPtr)UnhollowerUtils .GetIl2CppMethodInfoPointerFieldForGeneratedMethod(typeof(PlayerChatManager).GetMethod(nameof(PlayerChatManager.DoSendChatMessage))) .GetValue(null); FastNativeDetour.CreateAndApply(originalMethodPointer, HackyHooks.ChatMsgPatch, out ourChatDelegate, CallingConvention.Cdecl); } }
public unsafe static void HookAll() { Log.Info("Creating detours for hammer attack checks..."); var hammerAttackTargetCheckPointer = *(IntPtr *)(IntPtr)UnhollowerUtils .GetIl2CppMethodInfoPointerFieldForGeneratedMethod(typeof(MeleeWeaponFirstPerson).GetMethod(nameof(MeleeWeaponFirstPerson.CheckForAttackTargets))) .GetValue(null); FastNativeDetour.CreateAndApply(hammerAttackTargetCheckPointer, OurAttackCheck, out OriginalHammerMethod, CallingConvention.Cdecl); }
public static FastNativeDetour CreateAndApply <T>(IntPtr from, T to, out T original, CallingConvention?callingConvention = null) where T : Delegate { var toPtr = callingConvention != null ? MonoExtensions.GetFunctionPointerForDelegate(to, callingConvention.Value) : Marshal.GetFunctionPointerForDelegate(to); var result = new FastNativeDetour(from, toPtr); original = result.GenerateTrampoline <T>(); result.Apply(); return(result); }
public override unsafe void Initialize(string gameExePath = null) { UnhollowerBaseLib.GeneratedDatabasesUtil.DatabasesLocationOverride = Preloader.IL2CPPUnhollowedPath; PatchManager.ResolvePatcher += IL2CPPDetourMethodPatcher.TryResolve; base.Initialize(gameExePath); Instance = this; var version = //Version.Parse(Application.unityVersion); Version.Parse(Process.GetCurrentProcess().MainModule.FileVersionInfo.FileVersion); UnityVersionHandler.Initialize(version.Major, version.Minor, version.Revision); // One or the other here for Unhollower to work correctly //ClassInjector.Detour = new DetourHandler(); ClassInjector.DoHook = (ptr, patchedFunctionPtr) => { IntPtr originalFunc = new IntPtr(*(void **)ptr); var detour = new FastNativeDetour(originalFunc, patchedFunctionPtr); detour.Apply(); *(void **)ptr = (void *)detour.TrampolinePtr; }; var gameAssemblyModule = Process.GetCurrentProcess().Modules.Cast <ProcessModule>().First(x => x.ModuleName.Contains("GameAssembly")); // TODO: Check that DynDll.GetFunction works fine now var runtimeInvokePtr = GetProcAddress(gameAssemblyModule.BaseAddress, "il2cpp_runtime_invoke"); //DynDll.GetFunction(gameAssemblyModule.BaseAddress, "il2cpp_runtime_invoke"); PreloaderLogger.Log.LogDebug($"Runtime invoke pointer: 0x{runtimeInvokePtr.ToInt64():X}"); RuntimeInvokeDetour = FastNativeDetour.CreateAndApply(runtimeInvokePtr, OnInvokeMethod, out originalInvoke, CallingConvention.Cdecl); var installTlsPtr = GetProcAddress(gameAssemblyModule.BaseAddress, "il2cpp_unity_install_unitytls_interface"); if (installTlsPtr != IntPtr.Zero) { InstallUnityTlsInterfaceDetour = FastNativeDetour.CreateAndApply(installTlsPtr, OnInstallUnityTlsInterface, out originalInstallUnityTlsInterface, CallingConvention.Cdecl); } Logger.LogDebug("Initializing TLS adapters"); Il2CppTlsAdapter.Initialize(); PreloaderLogger.Log.LogDebug("Runtime invoke patched"); }
public unsafe static void HookAll() { Log.Info("Patching bioscanner functions..."); var tryGetTaggableEnemiesPointer = *(IntPtr *)(IntPtr)UnhollowerUtils .GetIl2CppMethodInfoPointerFieldForGeneratedMethod(typeof(EnemyScanner).GetMethod(nameof(EnemyScanner.TryGetTaggableEnemies))) .GetValue(null); FastNativeDetour.CreateAndApply(tryGetTaggableEnemiesPointer, OurScannerMethod, out OriginalScannerMethod, CallingConvention.Cdecl); FastNativeDetour.CreateAndApply( IL2CPP.il2cpp_resolve_icall("UnityEngine.Transform::" + nameof(Transform.get_rotation_Injected)), OurGetRotation, out ourOriginalRotationGetter, CallingConvention.Cdecl); }
public override unsafe void Initialize(string gameExePath = null) { UnhollowerBaseLib.GeneratedDatabasesUtil.DatabasesLocationOverride = Preloader.IL2CPPUnhollowedPath; PatchManager.ResolvePatcher += IL2CPPDetourMethodPatcher.TryResolve; base.Initialize(gameExePath); Instance = this; var version = //Version.Parse(Application.unityVersion); Version.Parse(Process.GetCurrentProcess().MainModule.FileVersionInfo.FileVersion); UnityVersionHandler.Initialize(version.Major, version.Minor, version.Revision); // One or the other here for Unhollower to work correctly //ClassInjector.Detour = new DetourHandler(); ClassInjector.DoHook = (ptr, patchedFunctionPtr) => { IntPtr originalFunc = new IntPtr(*(void **)ptr); var detour = new FastNativeDetour(originalFunc, patchedFunctionPtr); detour.Apply(); *(void **)ptr = (void *)detour.TrampolinePtr; }; var gameAssemblyModule = Process.GetCurrentProcess().Modules.Cast <ProcessModule>().First(x => x.ModuleName.Contains("GameAssembly")); var functionPtr = GetProcAddress(gameAssemblyModule.BaseAddress, "il2cpp_runtime_invoke"); //DynDll.GetFunction(gameAssemblyModule.BaseAddress, "il2cpp_runtime_invoke"); PreloaderLogger.Log.LogDebug($"Runtime invoke pointer: 0x{functionPtr.ToInt64():X}"); RuntimeInvokeDetour = new FastNativeDetour(functionPtr, MonoExtensions.GetFunctionPointerForDelegate(new RuntimeInvokeDetourDelegate(OnInvokeMethod), CallingConvention.Cdecl)); RuntimeInvokeDetour.Apply(); originalInvoke = RuntimeInvokeDetour.GenerateTrampoline <RuntimeInvokeDetourDelegate>(); PreloaderLogger.Log.LogDebug("Runtime invoke patched"); }
public override void Initialize(string gameExePath = null) { GeneratedDatabasesUtil.DatabasesLocationOverride = Preloader.IL2CPPUnhollowedPath; PatchManager.ResolvePatcher += IL2CPPDetourMethodPatcher.TryResolve; base.Initialize(gameExePath); Instance = this; ClassInjector.Detour = new UnhollowerDetourHandler(); var gameAssemblyModule = Process.GetCurrentProcess().Modules.Cast <ProcessModule>() .FirstOrDefault(x => x.ModuleName.Contains("GameAssembly") || x.ModuleName.Contains("UserAssembly")); if (gameAssemblyModule == null) { Logger.Log(LogLevel.Fatal, "Could not locate Il2Cpp game assembly (GameAssembly.dll) or (UserAssembly.dll). The game might be obfuscated or use a yet unsupported build of Unity."); return; } gameAssemblyModule.BaseAddress.TryGetFunction("il2cpp_runtime_invoke", out var runtimeInvokePtr); PreloaderLogger.Log.Log(LogLevel.Debug, $"Runtime invoke pointer: 0x{runtimeInvokePtr.ToInt64():X}"); RuntimeInvokeDetour = FastNativeDetour.CreateAndApply(runtimeInvokePtr, OnInvokeMethod, out originalInvoke, CallingConvention.Cdecl); if (gameAssemblyModule.BaseAddress.TryGetFunction("il2cpp_unity_install_unitytls_interface", out var installTlsPtr)) { InstallUnityTlsInterfaceDetour = FastNativeDetour.CreateAndApply(installTlsPtr, OnInstallUnityTlsInterface, out originalInstallUnityTlsInterface, CallingConvention.Cdecl); } Logger.Log(LogLevel.Debug, "Initializing TLS adapters"); Il2CppTlsAdapter.Initialize(); PreloaderLogger.Log.Log(LogLevel.Debug, "Runtime invoke patched"); }
public override void Initialize(string gameExePath = null) { GeneratedDatabasesUtil.DatabasesLocationOverride = Preloader.IL2CPPUnhollowedPath; PatchManager.ResolvePatcher += IL2CPPDetourMethodPatcher.TryResolve; base.Initialize(gameExePath); Instance = this; ClassInjector.Detour = new UnhollowerDetourHandler(); var gameAssemblyModule = Process.GetCurrentProcess().Modules.Cast <ProcessModule>() .First(x => x.ModuleName.Contains("GameAssembly")); // TODO: Check that DynDll.GetFunction works fine now var runtimeInvokePtr = GetProcAddress(gameAssemblyModule.BaseAddress, "il2cpp_runtime_invoke"); //DynDll.GetFunction(gameAssemblyModule.BaseAddress, "il2cpp_runtime_invoke"); PreloaderLogger.Log.LogDebug($"Runtime invoke pointer: 0x{runtimeInvokePtr.ToInt64():X}"); RuntimeInvokeDetour = FastNativeDetour.CreateAndApply(runtimeInvokePtr, OnInvokeMethod, out originalInvoke, CallingConvention.Cdecl); var installTlsPtr = GetProcAddress(gameAssemblyModule.BaseAddress, "il2cpp_unity_install_unitytls_interface"); if (installTlsPtr != IntPtr.Zero) { InstallUnityTlsInterfaceDetour = FastNativeDetour.CreateAndApply(installTlsPtr, OnInstallUnityTlsInterface, out originalInstallUnityTlsInterface, CallingConvention.Cdecl); } Logger.LogDebug("Initializing TLS adapters"); Il2CppTlsAdapter.Initialize(); PreloaderLogger.Log.LogDebug("Runtime invoke patched"); }
public T Detour <T>(IntPtr from, T to) where T : Delegate { FastNativeDetour.CreateAndApply(from, to, out var original); return(original); }