예제 #1
0
        private unsafe static bool PatchMonoExport()
        {
            IntPtr monolib = MonoLibrary.GetLibPtr();

            if (monolib == IntPtr.Zero)
            {
                return(false);
            }

            NativeLibrary monoLibrary = new NativeLibrary(monolib);
            IntPtr        export      = monoLibrary.GetExport("mono_unity_get_unitytls_interface");

            if (export == IntPtr.Zero)
            {
                Logger.Error("Failed to find mono_unity_get_unitytls_interface! This should never happen...");
                return(false);
            }

            Logger.Msg("Patching mono_unity_get_unitytls_interface...");
            MethodInfo patch    = typeof(Il2CppUnityTls_Module).GetMethod("GetUnityTlsInterface", BindingFlags.NonPublic | BindingFlags.Static);
            IntPtr     patchptr = patch.MethodHandle.GetFunctionPointer();

            MelonUtils.NativeHookAttach((IntPtr)(&export), patchptr);

            return(true);
        }
예제 #2
0
        private unsafe static bool PatchExports()
        {
            IntPtr monolib = MonoLibrary.GetLibPtr();

            if (monolib == IntPtr.Zero)
            {
                Logger.Warning("Unable to find Mono Library Pointer!");
                return(false);
            }

            NativeLibrary monoLibrary = new NativeLibrary(monolib);
            IntPtr        mono_export = monoLibrary.GetExport("mono_unity_get_unitytls_interface");

            if (mono_export == IntPtr.Zero)
            {
                Logger.Warning("Unable to find Mono's mono_unity_get_unitytls_interface Export!");
                return(false);
            }

            NativeLibrary il2cppLibrary = NativeLibrary.Load(Path.Combine(MelonUtils.GameDirectory, "GameAssembly.dll"));
            IntPtr        il2cpp_export = il2cppLibrary.GetExport("il2cpp_unity_install_unitytls_interface");

            if (il2cpp_export == IntPtr.Zero)
            {
                Logger.Warning("Unable to find Il2Cpp's il2cpp_unity_install_unitytls_interface Export!");
                return(false);
            }

            Logger.Msg("Patching mono_unity_get_unitytls_interface...");
            MelonUtils.NativeHookAttach((IntPtr)(&mono_export), typeof(Il2CppUnityTls_Module).GetMethod("GetUnityTlsInterface", BindingFlags.NonPublic | BindingFlags.Static).MethodHandle.GetFunctionPointer());

            Logger.Msg("Patching il2cpp_unity_install_unitytls_interface...");
            MelonUtils.NativeHookAttach((IntPtr)(&il2cpp_export), typeof(Il2CppUnityTls_Module).GetMethod("SetUnityTlsInterface", BindingFlags.NonPublic | BindingFlags.Static).MethodHandle.GetFunctionPointer());
            OriginalSetUnityTlsInterface = (dSetUnityTlsInterface)Marshal.GetDelegateForFunctionPointer(il2cpp_export, typeof(dSetUnityTlsInterface));

            return(true);
        }