From a5fa241fb11253b28880b7250b0fe4273496ea76 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Thu, 16 Mar 2023 01:34:46 -0500 Subject: [PATCH] Job Removal --- .gitignore | 5 ++ FuckCohtml/FuckCohtml.cs | 34 +++++++++++++ FuckCohtml/FuckCohtml.csproj | 3 +- FuckCohtml/HarmonyPatches.cs | 71 +++++++++++---------------- FuckCohtml/Main.cs | 24 +++++++-- FuckCohtml/ManagedLibs/.keep | 0 FuckCohtml/Properties/AssemblyInfo.cs | 2 +- FuckCohtml/format.json | 2 +- 8 files changed, 94 insertions(+), 47 deletions(-) create mode 100644 FuckCohtml/FuckCohtml.cs create mode 100644 FuckCohtml/ManagedLibs/.keep diff --git a/.gitignore b/.gitignore index 426d76d..7a20781 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,11 @@ ## ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore +# ManagedLibs & NStrip.exe +ManagedLibs/*.dll +ManagedLibs/*.db +NStrip + # User-specific files *.rsuser *.suo diff --git a/FuckCohtml/FuckCohtml.cs b/FuckCohtml/FuckCohtml.cs new file mode 100644 index 0000000..4d944b0 --- /dev/null +++ b/FuckCohtml/FuckCohtml.cs @@ -0,0 +1,34 @@ +using ABI_RC.Core.InteractionSystem; +using ABI_RC.Core.IO; + +namespace NAK.Melons.FuckCohtml +{ + public static class FuckCohtml + { + public static void ToggleMetrics(bool disable) + { + var job = SchedulerSystem.Instance.activeJobs.FirstOrDefault(pair => pair.Job.Method.Name == "UpdateMetrics").Job; + if (!disable && job == null) + { + SchedulerSystem.AddJob(new SchedulerSystem.Job(ViewManager.Instance.UpdateMetrics), 0f, 0.5f, -1); + } + else if (disable && job != null) + { + SchedulerSystem.RemoveJob(job); + } + } + + public static void ToggleCoreUpdates(bool disable) + { + var job = SchedulerSystem.Instance.activeJobs.FirstOrDefault(pair => pair.Job.Method.Name == "SendCoreUpdate").Job; + if (!disable && job == null) + { + SchedulerSystem.AddJob(new SchedulerSystem.Job(CVR_MenuManager.Instance.SendCoreUpdate), 0f, 0.1f, -1); + } + else if (disable && job != null) + { + SchedulerSystem.RemoveJob(job); + } + } + } +} diff --git a/FuckCohtml/FuckCohtml.csproj b/FuckCohtml/FuckCohtml.csproj index cf3b530..10c4ff7 100644 --- a/FuckCohtml/FuckCohtml.csproj +++ b/FuckCohtml/FuckCohtml.csproj @@ -6,6 +6,7 @@ enable latest false + True @@ -13,7 +14,7 @@ C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\0Harmony.dll - C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll + ManagedLibs\Assembly-CSharp.dll C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll diff --git a/FuckCohtml/HarmonyPatches.cs b/FuckCohtml/HarmonyPatches.cs index 83a8cd7..759140e 100644 --- a/FuckCohtml/HarmonyPatches.cs +++ b/FuckCohtml/HarmonyPatches.cs @@ -1,57 +1,46 @@ using ABI_RC.Core.InteractionSystem; -using ABI_RC.Core.IO; -using cohtml; +using ABI_RC.Core.Player; using HarmonyLib; -using System.Reflection; -using UnityEngine; namespace NAK.Melons.FuckCohtml.HarmonyPatches; -public static class CohtmlViewPatches +class PlayerSetupPatches { - private static CohtmlView _quickMenuView; - private static CohtmlView _gameMenuView; - private static Traverse _quickMenuOpenTraverse; - private static Traverse _gameMenuOpenTraverse; - private static readonly FieldInfo m_UISystemFieldInfo = AccessTools.Field(typeof(CohtmlView), "m_UISystem"); - - private static void CohtmlAdvanceView(CohtmlView cohtmlView, Traverse menuOpenTraverse) + [HarmonyPostfix] + [HarmonyPatch(typeof(PlayerSetup), "Start")] + private static void Postfix_PlayerSetup_Start() { - if (!FuckCohtmlMod.EntryEnabled.Value) return; + FuckCohtml.ToggleMetrics(FuckCohtmlMod.EntryDisableMetrics.Value); + FuckCohtml.ToggleCoreUpdates(FuckCohtmlMod.EntryDisableCoreUpdates.Value); + } +} - // Don't execute if menu is open - if (cohtmlView == null || menuOpenTraverse.GetValue()) return; - - // Disable cohtmlView (opening should enable) - cohtmlView.enabled = false; - - // Death - try +class CVR_MenuManagerPatches +{ + [HarmonyPostfix] + [HarmonyPatch(typeof(CVR_MenuManager), "ToggleQuickMenu", new Type[] { typeof(bool) })] + private static void Postfix_CVR_MenuManager_ToggleQuickMenu(bool show) + { + if (!FuckCohtmlMod.EntryDisableCoreUpdates.Value) return; + if (show) { - CohtmlUISystem cohtmlUISystem = (CohtmlUISystem)m_UISystemFieldInfo.GetValue(cohtmlView); - if (cohtmlUISystem != null) cohtmlView.View.Advance(cohtmlUISystem.Id, (double)Time.unscaledTime * 1000.0); - } - catch (Exception e) - { - FuckCohtmlMod.Logger.Error($"An exception was thrown while calling CohtmlView.Advance(). Error message: {e.Message}"); + CVR_MenuManager.Instance.SendCoreUpdate(); + ViewManager.Instance.UpdateMetrics(); } } +} +class ViewManagerPatches +{ [HarmonyPostfix] - [HarmonyPatch(typeof(CVR_MenuManager), "Start")] - private static void Postfix_CVR_MenuManager_Start(ref CVR_MenuManager __instance, ref CohtmlView ___quickMenu) + [HarmonyPatch(typeof(ViewManager), "UiStateToggle", new Type[] { typeof(bool) })] + private static void Postfix_ViewManager_UiStateToggle(bool show) { - _quickMenuView = ___quickMenu; - _quickMenuOpenTraverse = Traverse.Create(__instance).Field("_quickMenuOpen"); - SchedulerSystem.AddJob(new SchedulerSystem.Job(() => CohtmlAdvanceView(_quickMenuView, _quickMenuOpenTraverse)), 15f, 6f, -1); - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(ViewManager), "Start")] - private static void Postfix_ViewManager_Start(ref ViewManager __instance, ref CohtmlView ___gameMenuView) - { - _gameMenuView = ___gameMenuView; - _gameMenuOpenTraverse = Traverse.Create(__instance).Field("_gameMenuOpen"); - SchedulerSystem.AddJob(new SchedulerSystem.Job(() => CohtmlAdvanceView(_gameMenuView, _gameMenuOpenTraverse)), 12f, 6f, -1); + if (!FuckCohtmlMod.EntryDisableMetrics.Value) return; + if (show) + { + CVR_MenuManager.Instance.SendCoreUpdate(); + ViewManager.Instance.UpdateMetrics(); + } } } \ No newline at end of file diff --git a/FuckCohtml/Main.cs b/FuckCohtml/Main.cs index b8ecbeb..9237b66 100644 --- a/FuckCohtml/Main.cs +++ b/FuckCohtml/Main.cs @@ -5,16 +5,34 @@ namespace NAK.Melons.FuckCohtml; public class FuckCohtmlMod : MelonMod { public static MelonLogger.Instance Logger; + public const string SettingsCategory = "FuckCohtml"; public static readonly MelonPreferences_Category CategoryFuckCohtml = MelonPreferences.CreateCategory(SettingsCategory); - public static readonly MelonPreferences_Entry EntryEnabled = - CategoryFuckCohtml.CreateEntry("Enabled", true, description: "Enable FuckCohtml. This forces Cohtml to update at intervals instead of every frame while closed."); + public static readonly MelonPreferences_Entry EntryDisableMetrics = + CategoryFuckCohtml.CreateEntry("Disable Metrics", true, description: "Disables menu metrics (FPS & Ping). Updates once on menu open if disabled."); + + public static readonly MelonPreferences_Entry EntryDisableCoreUpdates = + CategoryFuckCohtml.CreateEntry("Disable Core Updates", true, description: "Disables menu core updates (Gamerule Icons & Debug Status). Updates once on menu open if disabled."); public override void OnInitializeMelon() { Logger = LoggerInstance; - ApplyPatches(typeof(HarmonyPatches.CohtmlViewPatches)); + EntryDisableMetrics.OnEntryValueChangedUntyped.Subscribe(OnDisableMetrics); + EntryDisableCoreUpdates.OnEntryValueChangedUntyped.Subscribe(OnDisableCoreUpdates); + ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches)); + ApplyPatches(typeof(HarmonyPatches.CVR_MenuManagerPatches)); + ApplyPatches(typeof(HarmonyPatches.ViewManagerPatches)); + } + + private void OnDisableMetrics(object arg1, object arg2) + { + FuckCohtml.ToggleMetrics(EntryDisableMetrics.Value); + } + + private void OnDisableCoreUpdates(object arg1, object arg2) + { + FuckCohtml.ToggleCoreUpdates(EntryDisableCoreUpdates.Value); } private void ApplyPatches(Type type) diff --git a/FuckCohtml/ManagedLibs/.keep b/FuckCohtml/ManagedLibs/.keep new file mode 100644 index 0000000..e69de29 diff --git a/FuckCohtml/Properties/AssemblyInfo.cs b/FuckCohtml/Properties/AssemblyInfo.cs index 6cb02b9..8878400 100644 --- a/FuckCohtml/Properties/AssemblyInfo.cs +++ b/FuckCohtml/Properties/AssemblyInfo.cs @@ -26,6 +26,6 @@ using System.Reflection; namespace NAK.Melons.FuckCohtml.Properties; internal static class AssemblyInfoParams { - public const string Version = "1.0.0"; + public const string Version = "1.0.1"; public const string Author = "NotAKidoS"; } \ No newline at end of file diff --git a/FuckCohtml/format.json b/FuckCohtml/format.json index 9af422b..966411e 100644 --- a/FuckCohtml/format.json +++ b/FuckCohtml/format.json @@ -6,7 +6,7 @@ "loaderversion": "0.5.7", "modtype": "Mod", "author": "NotAKidoS", - "description": "This mod disables the CohtmlView components on the menus and forces them to render at an interval while closed, helping alleviate hitching and performance issues.\n\nHelps with FPS drop while unmuted in online instances.", + "description": "This mod disables the CohtmlView components on the menus and forces them to render intermittently when closed. This helps to alleviate any hitching and performance issues that may arise, particularly with FPS drops while unmuted in online instances.\n\nPlease view the Github README for more info.", "searchtags": [ "cohtml", "menus",