Beispiel #1
0
 private static void OnInstallUnityTlsInterface(IntPtr unityTlsInterfaceStruct)
 {
     Logger.Log(LogLevel.Debug, $"Captured UnityTls interface at {unityTlsInterfaceStruct.ToInt64():x8}");
     Il2CppTlsAdapter.Options.UnityTlsInterface = unityTlsInterfaceStruct;
     originalInstallUnityTlsInterface(unityTlsInterfaceStruct);
     InstallUnityTlsInterfaceDetour.Dispose();
     InstallUnityTlsInterfaceDetour = null;
 }
Beispiel #2
0
        /// <summary>
        /// Attempt to deserialize key combination from the string.
        /// </summary>
        public static KeyboardShortcut Deserialize(string str)
        {
            try
            {
                var parts = str.Split(new[] { ' ', '+', ',', ';', '|' }, StringSplitOptions.RemoveEmptyEntries)
                            .Select(x => (KeyCode)Enum.Parse(typeof(KeyCode), x)).ToArray();

                return(new KeyboardShortcut(parts));
            }
            catch (SystemException ex)
            {
                Logger.Log(LogLevel.Error, "Failed to read keybind from settings: " + ex.Message);
                return(Empty);
            }
        }
Beispiel #3
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");
    }
Beispiel #4
0
    private static IntPtr OnInvokeMethod(IntPtr method, IntPtr obj, IntPtr parameters, IntPtr exc)
    {
        var methodName = Marshal.PtrToStringAnsi(UnhollowerBaseLib.IL2CPP.il2cpp_method_get_name(method));

        var unhook = false;

        if (methodName == "Internal_ActiveSceneChanged")
        {
            try
            {
                if (ConfigUnityLogging.Value)
                {
                    Logger.Sources.Add(new IL2CPPUnityLogSource());

                    Application.CallLogCallback("Test call after applying unity logging hook", "", LogType.Assert,
                                                true);
                }

                unhook = true;

                Instance.Execute();
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Fatal, "Unable to execute IL2CPP chainloader");
                Logger.Log(LogLevel.Error, ex);
            }
        }

        var result = originalInvoke(method, obj, parameters, exc);

        if (unhook)
        {
            RuntimeInvokeDetour.Dispose();

            PreloaderLogger.Log.Log(LogLevel.Debug, "Runtime invoke unpatched");
        }

        return(result);
    }
Beispiel #5
0
        static UnityLogListener()
        {
            foreach (var methodInfo in typeof(UnityLogWriter).GetMethods(BindingFlags.Static | BindingFlags.Public))
            {
                try
                {
                    methodInfo.Invoke(null, new object[] { "" });
                }
                catch
                {
                    continue;
                }

                WriteStringToUnityLog = (Action <string>)Delegate.CreateDelegate(typeof(Action <string>), methodInfo);
                break;
            }

            if (WriteStringToUnityLog == null)
            {
                Logger.Log(LogLevel.Error, "Unable to start Unity log writer");
            }
        }