Example #1
0
        public static void EnableHook()
        {
            if (hookEnabled)
            {
                return;
            }

            try
            {
                log = RedirectionHelper.RedirectCalls
                      (
                    typeof(UnityEngine.Debug).GetMethod("Log", new[] { typeof(object) }),
                    typeof(UnityLoggingHook).GetMethod("Log", new[] { typeof(object) })
                      );

                logFormat = RedirectionHelper.RedirectCalls
                            (
                    typeof(UnityEngine.Debug).GetMethod("LogFormat", new[] { typeof(string), typeof(object[]) }),
                    typeof(UnityLoggingHook).GetMethod("LogFormat", new[] { typeof(string), typeof(object[]) })
                            );

                logWarning = RedirectionHelper.RedirectCalls
                             (
                    typeof(UnityEngine.Debug).GetMethod("LogWarning", new[] { typeof(object) }),
                    typeof(UnityLoggingHook).GetMethod("LogWarning", new[] { typeof(object) })
                             );

                logWarningFormat = RedirectionHelper.RedirectCalls
                                   (
                    typeof(UnityEngine.Debug).GetMethod("LogWarningFormat", new[] { typeof(string), typeof(object[]) }),
                    typeof(UnityLoggingHook).GetMethod("LogWarningFormat", new[] { typeof(string), typeof(object[]) })
                                   );

                logError = RedirectionHelper.RedirectCalls
                           (
                    typeof(UnityEngine.Debug).GetMethod("LogError", new[] { typeof(object) }),
                    typeof(UnityLoggingHook).GetMethod("LogError", new[] { typeof(object) })
                           );

                logErrorFormat = RedirectionHelper.RedirectCalls
                                 (
                    typeof(UnityEngine.Debug).GetMethod("LogErrorFormat", new[] { typeof(string), typeof(object[]) }),
                    typeof(UnityLoggingHook).GetMethod("LogErrorFormat", new[] { typeof(string), typeof(object[]) })
                                 );

                logException = RedirectionHelper.RedirectCalls
                               (
                    typeof(UnityEngine.Debug).GetMethod("LogException", new[] { typeof(Exception) }),
                    typeof(UnityLoggingHook).GetMethod("LogException", new[] { typeof(Exception) })
                               );
            }
            catch (Exception ex)
            {
                global::ModTools.Log.Error("Failed to hook Unity's debug logging, reason: " + ex.Message);
            }

            hookEnabled = true;
            global::ModTools.Log.Warning("Unity logging subsystem hooked by ModTools");
        }
Example #2
0
        public static void Bootstrap()
        {
            try
            {
                InitModTools(SimulationManager.UpdateMode.Undefined);

                var target = typeof(LoadingWrapper).GetMethod("OnLevelLoaded",
                                                              new[] { typeof(SimulationManager.UpdateMode) });

                var replacement = typeof(ModToolsBootstrap).GetMethod("OnLevelLoaded",
                                                                      new[] { typeof(SimulationManager.UpdateMode) });

                RedirectionHelper.RedirectCalls(target, replacement);
            }
            catch (Exception ex)
            {
                DebugOutputPanel.AddMessage(PluginManager.MessageType.Error, ex.Message);
            }
        }
Example #3
0
        public static void Bootstrap()
        {
            if (thisGameObject == null)
            {
                thisGameObject      = new GameObject();
                thisGameObject.name = "ImprovedWorkshopIntegration";
                thisGameObject.AddComponent <ImprovedWorkshopIntegration>();
                thisGameObject.transform.parent = ModTools.Instance.gameObject.transform;
            }

            improvedModsPanelExists = CheckForImprovedModsPanel();

            if (!improvedModsPanelExists)
            {
                InitializeModSortDropDown();
            }

            if (bootstrapped)
            {
                return;
            }

            var go = GameObject.Find("(Library) WorkshopModUploadPanel");

            if (go == null)
            {
                return;
            }

            workshopModUploadPanel = go.GetComponent <WorkshopModUploadPanel>();

            if (workshopModUploadPanel == null)
            {
                return;
            }

            var modsList = GameObject.Find("ModsList");

            if (modsList == null)
            {
                return;
            }

            m_StagingPath              = Util.FindField(workshopModUploadPanel, "m_StagingPath");
            m_PreviewPath              = Util.FindField(workshopModUploadPanel, "m_PreviewPath");
            m_ContentPath              = Util.FindField(workshopModUploadPanel, "m_ContentPath");
            m_CurrentHandle            = Util.FindField(workshopModUploadPanel, "m_CurrentHandle");
            m_ShareButton              = Util.FindField(workshopModUploadPanel, "m_ShareButton");
            m_TargetFolder             = Util.FindField(workshopModUploadPanel, "m_TargetFolder");
            m_ShareButton              = Util.FindField(workshopModUploadPanel, "m_ShareButton");
            m_Title                    = Util.FindField(workshopModUploadPanel, "m_Title");
            m_Desc                     = Util.FindField(workshopModUploadPanel, "m_Desc");
            m_ChangeNote               = Util.FindField(workshopModUploadPanel, "m_ChangeNote");
            m_DefaultModPreviewTexture = Util.FindField(workshopModUploadPanel, "m_DefaultModPreviewTexture");

            reloadPreviewImage = typeof(WorkshopModUploadPanel).GetMethod("ReloadPreviewImage",
                                                                          BindingFlags.Instance | BindingFlags.NonPublic);

            startWatchingPath = typeof(WorkshopModUploadPanel).GetMethod("StartWatchingPath",
                                                                         BindingFlags.Instance | BindingFlags.NonPublic);

            revertState = RedirectionHelper.RedirectCalls
                          (
                typeof(WorkshopModUploadPanel).GetMethod("SetAssetInternal",
                                                         BindingFlags.Instance | BindingFlags.NonPublic),
                typeof(ImprovedWorkshopIntegration).GetMethod("SetAssetInternal",
                                                              BindingFlags.Instance | BindingFlags.NonPublic)
                          );

            if (!improvedModsPanelExists)
            {
                modsPanelBootstrapped = true;
                revertState2          = RedirectionHelper.RedirectCalls
                                        (
                    typeof(PackageEntry).GetMethod("FormatPackageName",
                                                   BindingFlags.Static | BindingFlags.NonPublic),
                    typeof(ImprovedWorkshopIntegration).GetMethod("FormatPackageName",
                                                                  BindingFlags.Static | BindingFlags.NonPublic)
                                        );

                revertState3 = RedirectionHelper.RedirectCalls
                               (
                    typeof(CustomContentPanel).GetMethod("RefreshPlugins",
                                                         BindingFlags.Instance | BindingFlags.NonPublic),
                    typeof(ImprovedWorkshopIntegration).GetMethod("RefreshPlugins",
                                                                  BindingFlags.Static | BindingFlags.Public)
                               );
            }
            else
            {
                modsPanelBootstrapped = false;
            }

            bootstrapped = true;
        }