Job Removal

This commit is contained in:
NotAKidoS 2023-03-16 01:34:46 -05:00
parent 1ce18e6aa6
commit a5fa241fb1
8 changed files with 94 additions and 47 deletions

5
.gitignore vendored
View file

@ -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

34
FuckCohtml/FuckCohtml.cs Normal file
View file

@ -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);
}
}
}
}

View file

@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
@ -13,7 +14,7 @@
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>ManagedLibs\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>

View file

@ -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)
{
if (!FuckCohtmlMod.EntryEnabled.Value) return;
// Don't execute if menu is open
if (cohtmlView == null || menuOpenTraverse.GetValue<bool>()) return;
// Disable cohtmlView (opening should enable)
cohtmlView.enabled = false;
// Death
try
{
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}");
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(CVR_MenuManager), "Start")]
private static void Postfix_CVR_MenuManager_Start(ref CVR_MenuManager __instance, ref CohtmlView ___quickMenu)
[HarmonyPatch(typeof(PlayerSetup), "Start")]
private static void Postfix_PlayerSetup_Start()
{
_quickMenuView = ___quickMenu;
_quickMenuOpenTraverse = Traverse.Create(__instance).Field("_quickMenuOpen");
SchedulerSystem.AddJob(new SchedulerSystem.Job(() => CohtmlAdvanceView(_quickMenuView, _quickMenuOpenTraverse)), 15f, 6f, -1);
FuckCohtml.ToggleMetrics(FuckCohtmlMod.EntryDisableMetrics.Value);
FuckCohtml.ToggleCoreUpdates(FuckCohtmlMod.EntryDisableCoreUpdates.Value);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(ViewManager), "Start")]
private static void Postfix_ViewManager_Start(ref ViewManager __instance, ref CohtmlView ___gameMenuView)
class CVR_MenuManagerPatches
{
_gameMenuView = ___gameMenuView;
_gameMenuOpenTraverse = Traverse.Create(__instance).Field("_gameMenuOpen");
SchedulerSystem.AddJob(new SchedulerSystem.Job(() => CohtmlAdvanceView(_gameMenuView, _gameMenuOpenTraverse)), 12f, 6f, -1);
[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)
{
CVR_MenuManager.Instance.SendCoreUpdate();
ViewManager.Instance.UpdateMetrics();
}
}
}
class ViewManagerPatches
{
[HarmonyPostfix]
[HarmonyPatch(typeof(ViewManager), "UiStateToggle", new Type[] { typeof(bool) })]
private static void Postfix_ViewManager_UiStateToggle(bool show)
{
if (!FuckCohtmlMod.EntryDisableMetrics.Value) return;
if (show)
{
CVR_MenuManager.Instance.SendCoreUpdate();
ViewManager.Instance.UpdateMetrics();
}
}
}

View file

@ -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<bool> 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<bool> EntryDisableMetrics =
CategoryFuckCohtml.CreateEntry("Disable Metrics", true, description: "Disables menu metrics (FPS & Ping). Updates once on menu open if disabled.");
public static readonly MelonPreferences_Entry<bool> 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)

View file

View file

@ -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";
}

View file

@ -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",