Пример #1
0
        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);
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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);
        }
Пример #5
0
    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);
    }
Пример #6
0
        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");
        }
Пример #7
0
        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);
        }
Пример #8
0
        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");
        }
Пример #9
0
    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");
    }
Пример #10
0
        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");
        }
Пример #11
0
 public T Detour <T>(IntPtr from, T to) where T : Delegate
 {
     FastNativeDetour.CreateAndApply(from, to, out var original);
     return(original);
 }