Esempio n. 1
0
        public static void Setup()
        {
            IL2CPP.il2cpp_thread_attach(IL2CPP.il2cpp_domain_get());
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Console.WriteLine(Environment.Version);
            Console.WriteLine(Application.unityVersion);
            Console.WriteLine(Directory.GetCurrentDirectory());
            UnhollowerBaseLib.Runtime.UnityVersionHandler.Initialize(2018, 4, 20);
            LogSupport.RemoveAllHandlers();
            LogSupport.TraceHandler   += LogSupport_TraceHandler;
            LogSupport.ErrorHandler   += LogSupport_TraceHandler;
            LogSupport.InfoHandler    += LogSupport_TraceHandler;
            LogSupport.WarningHandler += LogSupport_TraceHandler;

            ClassInjector.Detour = new DoHookDetour();
            //ClassInjector.DoHook?.GetInvocationList().ToList().ForEach(d => ClassInjector.DoHook -= (Action<IntPtr, IntPtr>)d);
            //ClassInjector.DoHook += JmpPatch;
            ClassInjector.RegisterTypeInIl2Cpp <ModManager>();
            while (BaseObject = GameObject.Find("ModManager"))
            {
                GameObject.DestroyImmediate(BaseObject);
            }
            BaseObject = new GameObject("ModManager");
            GameObject.DontDestroyOnLoad(BaseObject);
            var modMgr = BaseObject.AddComponent <ModManager>();
            var types  = Assembly.GetExecutingAssembly().GetTypes().ToList().Where(t => t.BaseType == typeof(ModBase) && !t.IsNested);

            foreach (var type in types)
            {
                modMgr.Mods.Add((ModBase)Activator.CreateInstance(type));
            }
        }
Esempio n. 2
0
        public static void Setup()
        {
#if DEBUG
            Console.WriteLine(Environment.Version);
            Console.WriteLine(Application.unityVersion);
            Console.WriteLine(Directory.GetCurrentDirectory());

            LogSupport.RemoveAllHandlers();
            LogSupport.TraceHandler   += LogSupport_TraceHandler;
            LogSupport.ErrorHandler   += LogSupport_TraceHandler;
            LogSupport.InfoHandler    += LogSupport_TraceHandler;
            LogSupport.WarningHandler += LogSupport_TraceHandler;
#endif

            ClassInjector.DoHook?.GetInvocationList().ToList().ForEach(d => ClassInjector.DoHook -= (Action <IntPtr, IntPtr>)d);
            ClassInjector.DoHook += JmpPatch;
            UnityVersionHandler.Initialize(2019, 3, 14);
            ClassInjector.RegisterTypeInIl2Cpp <ModManager>();

            while (BaseObject = GameObject.Find("ModManager"))
            {
                GameObject.DestroyImmediate(BaseObject);
            }
            BaseObject = new GameObject("ModManager");
            GameObject.DontDestroyOnLoad(BaseObject);
            var modMgr = BaseObject.AddComponent <ModManager>();
            var types  = Assembly.GetExecutingAssembly().GetTypes().ToList().Where(t => t.BaseType == typeof(ModBase) && !t.IsNested);
            foreach (var type in types)
            {
                modMgr.Mods.Add((ModBase)Activator.CreateInstance(type));
            }
        }
Esempio n. 3
0
 private static ISupportModule_To Initialize(ISupportModule_From interface_from)
 {
     Interface = interface_from;
     LogSupport.RemoveAllHandlers();
     if (MelonDebug.IsEnabled())
     {
         LogSupport.InfoHandler += MelonLogger.Msg;
     }
     LogSupport.WarningHandler += MelonLogger.Warning;
     LogSupport.ErrorHandler   += MelonLogger.Error;
     if (MelonDebug.IsEnabled())
     {
         LogSupport.TraceHandler += MelonLogger.Msg;
     }
     ClassInjector.DoHook = MelonUtils.NativeHookAttach;
     InitializeUnityVersion();
     ConsoleCleaner();
     SceneManager.sceneLoaded = (
         (SceneManager.sceneLoaded == null)
            ? new Action <Scene, LoadSceneMode>(OnSceneLoad)
            : Il2CppSystem.Delegate.Combine(SceneManager.sceneLoaded, (UnityAction <Scene, LoadSceneMode>) new Action <Scene, LoadSceneMode>(OnSceneLoad)).Cast <UnityAction <Scene, LoadSceneMode> >()
         );
     Camera.onPostRender = (
         (Camera.onPostRender == null)
         ? new Action <Camera>(OnPostRender)
         : Il2CppSystem.Delegate.Combine(Camera.onPostRender, (Camera.CameraCallback) new Action <Camera>(OnPostRender)).Cast <Camera.CameraCallback>()
         );
     ClassInjector.RegisterTypeInIl2Cpp <Component>();
     Component.Create();
     return(new SupportModule_To());
 }
        private static ISupportModule Initialize()
        {
            LogSupport.RemoveAllHandlers();
            if (true)
            {
                LogSupport.InfoHandler += MelonLogger.Log;
            }
            LogSupport.WarningHandler += MelonLogger.LogWarning;
            LogSupport.ErrorHandler   += MelonLogger.LogError;
            if (true)
            {
                LogSupport.TraceHandler += MelonLogger.Log;
            }

            ClassInjector.DoHook += Imports.Hook;
            GetUnityVersionNumbers(out var major, out var minor, out var patch);
            UnityVersionHandler.Initialize(major, minor, patch);

            // Il2CppSystem.Console.SetOut(new Il2CppSystem.IO.StreamWriter(Il2CppSystem.IO.Stream.Null));
            try
            {
                var il2CppSystemAssembly = Assembly.Load("Il2Cppmscorlib");

                var consoleType      = il2CppSystemAssembly.GetType("Il2CppSystem.Console");
                var streamWriterType = il2CppSystemAssembly.GetType("Il2CppSystem.IO.StreamWriter");
                var streamType       = il2CppSystemAssembly.GetType("Il2CppSystem.IO.Stream");

                var setOutMethod     = consoleType.GetMethod("SetOut", BindingFlags.Static | BindingFlags.Public);
                var nullStreamField  = streamType.GetProperty("Null", BindingFlags.Static | BindingFlags.Public).GetGetMethod();
                var streamWriterCtor = streamWriterType.GetConstructor(new[] { streamType });

                var nullStream  = nullStreamField.Invoke(null, new object[0]);
                var steamWriter = streamWriterCtor.Invoke(new[] { nullStream });
                setOutMethod.Invoke(null, new[] { steamWriter });
            }
            catch (Exception ex)
            {
                MelonLogger.LogError($"Console cleaning failed: {ex}");
            }

            SetAsLastSiblingDelegateField = IL2CPP.ResolveICall <SetAsLastSiblingDelegate>("UnityEngine.Transform::SetAsLastSibling");

            ClassInjector.RegisterTypeInIl2Cpp <MelonLoaderComponent>();
            //MelonLogger.Log("ClassInjector.RegisterTypeInIl2Cpp<MelonLoaderComponent> done");
            MelonLoaderComponent.Create();
            //MelonLogger.Log("MelonLoaderComponent.Create() done");
            SceneManager.sceneLoaded = (
                (SceneManager.sceneLoaded == null)
                ? new Action <Scene, LoadSceneMode>(OnSceneLoad)
                : Il2CppSystem.Delegate.Combine(SceneManager.sceneLoaded, (UnityAction <Scene, LoadSceneMode>) new Action <Scene, LoadSceneMode>(OnSceneLoad)).Cast <UnityAction <Scene, LoadSceneMode> >()
                );
            Camera.onPostRender = (
                (Camera.onPostRender == null)
                ? new Action <Camera>(OnPostRender)
                : Il2CppSystem.Delegate.Combine(Camera.onPostRender, (Camera.CameraCallback) new Action <Camera>(OnPostRender)).Cast <Camera.CameraCallback>()
                );

            return(new Module());
        }
Esempio n. 5
0
        private static ISupportModule_To Initialize(ISupportModule_From interface_from)
        {
            Interface = interface_from;
            UnityMappers.RegisterMappers();

            LogSupport.RemoveAllHandlers();
            if (MelonDebug.IsEnabled())
            {
                LogSupport.InfoHandler += MelonLogger.Msg;
            }
            LogSupport.WarningHandler += MelonLogger.Warning;
            LogSupport.ErrorHandler   += MelonLogger.Error;
            if (MelonDebug.IsEnabled())
            {
                LogSupport.TraceHandler += MelonLogger.Msg;
            }

            ClassInjector.Detour = new UnhollowerDetour();
            UnityVersionHandler.Initialize(
                InternalUtils.UnityInformationHandler.EngineVersion.Major,
                InternalUtils.UnityInformationHandler.EngineVersion.Minor,
                InternalUtils.UnityInformationHandler.EngineVersion.Build);

            if (MelonLaunchOptions.Console.CleanUnityLogs)
            {
                ConsoleCleaner();
            }

            try
            {
                SceneManager.sceneLoaded = (
                    (ReferenceEquals(SceneManager.sceneLoaded, null))
                    ? new Action <Scene, LoadSceneMode>(OnSceneLoad)
                    : Il2CppSystem.Delegate.Combine(SceneManager.sceneLoaded, (UnityAction <Scene, LoadSceneMode>) new Action <Scene, LoadSceneMode>(OnSceneLoad)).Cast <UnityAction <Scene, LoadSceneMode> >()
                    );
            }
            catch (Exception ex) { MelonLogger.Error($"SceneManager.sceneLoaded override failed: {ex}"); }

            try
            {
                SceneManager.sceneUnloaded = (
                    (ReferenceEquals(SceneManager.sceneUnloaded, null))
                    ? new Action <Scene>(OnSceneUnload)
                    : Il2CppSystem.Delegate.Combine(SceneManager.sceneUnloaded, (UnityAction <Scene>) new Action <Scene>(OnSceneUnload)).Cast <UnityAction <Scene> >()
                    );
            }
            catch (Exception ex) { MelonLogger.Error($"SceneManager.sceneUnloaded override failed: {ex}"); }

            MonoEnumeratorWrapper.Register();

            ClassInjector.RegisterTypeInIl2Cpp <SM_Component>();
            SM_Component.Create();
            unhollower = new UnhollowerInterface();
            Interface.SetUnhollowerSupportInterface(unhollower);
            HarmonyLib.Public.Patching.PatchManager.ResolvePatcher += HarmonyMethodPatcher.TryResolve;

            return(new SupportModule_To());
        }
Esempio n. 6
0
        internal static ISupportModule_To Initialize(ISupportModule_From interface_from)
        {
            Interface = interface_from;
            UnityMappers.RegisterMappers();

            LogSupport.RemoveAllHandlers();
            if (MelonDebug.IsEnabled())
            {
                LogSupport.InfoHandler += MelonLogger.Msg;
            }
            LogSupport.WarningHandler += MelonLogger.Warning;
            LogSupport.ErrorHandler   += MelonLogger.Error;
            if (MelonDebug.IsEnabled())
            {
                LogSupport.TraceHandler += MelonLogger.Msg;
            }

            ClassInjector.Detour = new UnhollowerDetour();
            InitializeUnityVersion();
            ConsoleCleaner();

            try
            {
                SceneManager.sceneLoaded = (
                    (SceneManager.sceneLoaded == null)
                    ? new Action <Scene, LoadSceneMode>(OnSceneLoad)
                    : Il2CppSystem.Delegate.Combine(SceneManager.sceneLoaded, (UnityAction <Scene, LoadSceneMode>) new Action <Scene, LoadSceneMode>(OnSceneLoad)).Cast <UnityAction <Scene, LoadSceneMode> >()
                    );
            }
            catch (Exception ex) { MelonLogger.Error($"SceneManager.sceneLoaded override failed: {ex}"); }

            try
            {
                SceneManager.sceneUnloaded = (
                    (SceneManager.sceneUnloaded == null)
                    ? new Action <Scene>(OnSceneUnload)
                    : Il2CppSystem.Delegate.Combine(SceneManager.sceneUnloaded, (UnityAction <Scene>) new Action <Scene>(OnSceneUnload)).Cast <UnityAction <Scene> >()
                    );
            }
            catch (Exception ex) { MelonLogger.Error($"SceneManager.sceneUnloaded override failed: {ex}"); }

            try
            {
                Camera.onPostRender = (
                    (Camera.onPostRender == null)
                    ? new Action <Camera>(OnPostRender)
                    : Il2CppSystem.Delegate.Combine(Camera.onPostRender, (Camera.CameraCallback) new Action <Camera>(OnPostRender)).Cast <Camera.CameraCallback>()
                    );
            }
            catch (Exception ex) { MelonLogger.Error($"Camera.onPostRender override failed: {ex}"); }

            ClassInjector.RegisterTypeInIl2Cpp <SM_Component>();
            SM_Component.Create();
            return(new SupportModule_To());
        }
Esempio n. 7
0
        private static ISupportModule Initialize()
        {
            LogSupport.RemoveAllHandlers();
            if (Console.Enabled || Imports.IsDebugMode())
            {
                LogSupport.InfoHandler += MelonModLogger.Log;
            }
            LogSupport.WarningHandler += MelonModLogger.LogWarning;
            LogSupport.ErrorHandler   += MelonModLogger.LogError;
            if (Imports.IsDebugMode())
            {
                LogSupport.TraceHandler += MelonModLogger.Log;
            }

            try
            {
                Assembly il2cppSystem = Assembly.Load("Il2CppSystem");
                if (il2cppSystem != null)
                {
                    Type unitytls = il2cppSystem.GetType("Il2CppMono.Unity.UnityTls");
                    if (unitytls != null)
                    {
                        unsafe
                        {
                            var tlsHookTarget    = typeof(Uri).Assembly.GetType("Mono.Unity.UnityTls").GetMethod("GetUnityTlsInterface", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).MethodHandle.GetFunctionPointer();
                            var unityMethodField = UnhollowerUtils.GetIl2CppMethodInfoPointerFieldForGeneratedMethod(unitytls.GetMethod("GetUnityTlsInterface", BindingFlags.Public | BindingFlags.Static));
                            var unityMethodPtr   = (IntPtr)unityMethodField.GetValue(null);
                            var unityMethod      = *(IntPtr *)unityMethodPtr;
                            Imports.Hook((IntPtr)(&tlsHookTarget), unityMethod);
                        }
                    }
                    else
                    {
                        throw new Exception("Failed to get Type Il2CppMono.Unity.UnityTls!");
                    }
                }
                else
                {
                    throw new Exception("Failed to get Assembly Il2CppSystem!");
                }
            }
            catch (Exception ex)
            {
                MelonModLogger.LogWarning("Exception while setting up TLS, mods will not be able to use HTTPS: " + ex);
            }

            if (MelonLoader.Main.IsVRChat)
            {
                try
                {
                    Assembly Transmtn = Assembly.Load("Transmtn");
                    if (Transmtn != null)
                    {
                        Type Transmtn_HttpConnection = Transmtn.GetType("Transmtn.HttpConnection");
                        if (Transmtn_HttpConnection != null)
                        {
                            Il2CppSystem_Console_WriteLine = typeof(Il2CppSystem.Console).GetMethods(BindingFlags.Public | BindingFlags.Static).First(x => (x.Name.Equals("WriteLine") && (x.GetParameters().Count() == 1) && (x.GetParameters()[0].ParameterType == typeof(string))));
                            if (harmonyInstance == null)
                            {
                                harmonyInstance = HarmonyInstance.Create("MelonLoader.Support.Il2Cpp");
                            }
                            harmonyInstance.Patch(Transmtn_HttpConnection.GetMethod("get", BindingFlags.Public | BindingFlags.Instance), new HarmonyMethod(typeof(Main).GetMethod("Transmtn_HttpConnection_get_Prefix", BindingFlags.NonPublic | BindingFlags.Static)), new HarmonyMethod(typeof(Main).GetMethod("Transmtn_HttpConnection_get_Postfix", BindingFlags.NonPublic | BindingFlags.Static)));
                        }
                        else
                        {
                            throw new Exception("Failed to get Type Transmtn.HttpConnection!");
                        }
                    }
                    else
                    {
                        throw new Exception("Failed to get Assembly Transmtn!");
                    }
                }
                catch (Exception ex)
                {
                    MelonModLogger.LogWarning("Exception while setting up Auth Token Hider, Auth Tokens may show in Console: " + ex);
                }
            }

            ClassInjector.DoHook += Imports.Hook;
            GetUnityVersionNumbers(out var major, out var minor, out var patch);
            UnityVersionHandler.Initialize(major, minor, patch);

            SetAsLastSiblingDelegateField = IL2CPP.ResolveICall <SetAsLastSiblingDelegate>("UnityEngine.Transform::SetAsLastSibling");

            ClassInjector.RegisterTypeInIl2Cpp <MelonLoaderComponent>();
            MelonLoaderComponent.Create();

            SceneManager.sceneLoaded = (
                (SceneManager.sceneLoaded == null)
                ? new Action <Scene, LoadSceneMode>(OnSceneLoad)
                : Il2CppSystem.Delegate.Combine(SceneManager.sceneLoaded, (UnityAction <Scene, LoadSceneMode>) new Action <Scene, LoadSceneMode>(OnSceneLoad)).Cast <UnityAction <Scene, LoadSceneMode> >()
                );
            Camera.onPostRender = (
                (Camera.onPostRender == null)
                ? new Action <Camera>(OnPostRender)
                : Il2CppSystem.Delegate.Combine(Camera.onPostRender, (Camera.CameraCallback) new Action <Camera>(OnPostRender)).Cast <Camera.CameraCallback>()
                );

            return(new Module());
        }
Esempio n. 8
0
        private static ISupportModule Initialize()
        {
            LogSupport.RemoveAllHandlers();
            if (MelonConsole.Enabled || Imports.IsDebugMode())
            {
                LogSupport.InfoHandler += MelonLogger.Log;
            }
            LogSupport.WarningHandler += MelonLogger.LogWarning;
            LogSupport.ErrorHandler   += MelonLogger.LogError;
            if (Imports.IsDebugMode())
            {
                LogSupport.TraceHandler += MelonLogger.Log;
            }

            if (MelonLoaderBase.IsVRChat)
            {
                try
                {
                    Assembly Transmtn = Assembly.Load("Transmtn");
                    if (Transmtn != null)
                    {
                        Type Transmtn_HttpConnection = Transmtn.GetType("Transmtn.HttpConnection");
                        if (Transmtn_HttpConnection != null)
                        {
                            Il2CppSystem_Console_WriteLine = typeof(Il2CppSystem.Console).GetMethods(BindingFlags.Public | BindingFlags.Static).First(x => (x.Name.Equals("WriteLine") && (x.GetParameters().Count() == 1) && (x.GetParameters()[0].ParameterType == typeof(string))));
                            if (harmonyInstance == null)
                            {
                                harmonyInstance = HarmonyInstance.Create("MelonLoader.Support.Il2Cpp");
                            }
                            harmonyInstance.Patch(Transmtn_HttpConnection.GetMethod("get", BindingFlags.Public | BindingFlags.Instance), new HarmonyMethod(typeof(Main).GetMethod("Transmtn_HttpConnection_get_Prefix", BindingFlags.NonPublic | BindingFlags.Static)), new HarmonyMethod(typeof(Main).GetMethod("Transmtn_HttpConnection_get_Postfix", BindingFlags.NonPublic | BindingFlags.Static)));
                        }
                        else
                        {
                            throw new Exception("Failed to get Type Transmtn.HttpConnection!");
                        }
                    }
                    else
                    {
                        throw new Exception("Failed to get Assembly Transmtn!");
                    }
                }
                catch (Exception ex)
                {
                    MelonLogger.LogWarning("Exception while setting up Auth Token Hider, Auth Tokens may show in Console: " + ex);
                }
            }

            ClassInjector.DoHook += Imports.Hook;
            GetUnityVersionNumbers(out var major, out var minor, out var patch);
            UnityVersionHandler.Initialize(major, minor, patch);

            SetAsLastSiblingDelegateField = IL2CPP.ResolveICall <SetAsLastSiblingDelegate>("UnityEngine.Transform::SetAsLastSibling");

            ClassInjector.RegisterTypeInIl2Cpp <MelonLoaderComponent>();
            MelonLoaderComponent.Create();

            SceneManager.sceneLoaded = (
                (SceneManager.sceneLoaded == null)
                ? new Action <Scene, LoadSceneMode>(OnSceneLoad)
                : Il2CppSystem.Delegate.Combine(SceneManager.sceneLoaded, (UnityAction <Scene, LoadSceneMode>) new Action <Scene, LoadSceneMode>(OnSceneLoad)).Cast <UnityAction <Scene, LoadSceneMode> >()
                );
            Camera.onPostRender = (
                (Camera.onPostRender == null)
                ? new Action <Camera>(OnPostRender)
                : Il2CppSystem.Delegate.Combine(Camera.onPostRender, (Camera.CameraCallback) new Action <Camera>(OnPostRender)).Cast <Camera.CameraCallback>()
                );

            return(new Module());
        }