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");
        }
Exemple #2
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");
    }
        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");
        }