mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
Add back CohtmlView disabling.
This commit is contained in:
parent
f6e2c1622a
commit
87bb3fcb89
4 changed files with 81 additions and 4 deletions
|
@ -1,5 +1,8 @@
|
||||||
using ABI_RC.Core.InteractionSystem;
|
using ABI_RC.Core.InteractionSystem;
|
||||||
using ABI_RC.Core.IO;
|
using ABI_RC.Core.IO;
|
||||||
|
using cohtml;
|
||||||
|
using HarmonyLib;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace NAK.Melons.FuckMetrics
|
namespace NAK.Melons.FuckMetrics
|
||||||
{
|
{
|
||||||
|
@ -30,5 +33,26 @@ namespace NAK.Melons.FuckMetrics
|
||||||
SchedulerSystem.RemoveJob(job);
|
SchedulerSystem.RemoveJob(job);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CohtmlAdvanceView(CohtmlView cohtmlView, Traverse menuOpenTraverse)
|
||||||
|
{
|
||||||
|
if (!FuckMetricsMod.EntryDisableCohtmlViewOnIdle.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
|
||||||
|
{
|
||||||
|
if (cohtmlView.m_UISystem != null) cohtmlView.View.Advance(cohtmlView.m_UISystem.Id, (double)Time.unscaledTime * 1000.0);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
FuckMetricsMod.Logger.Error($"An exception was thrown while calling CohtmlView.Advance(). Error message: {e.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\cohtml.Net.dll</HintPath>
|
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\cohtml.Net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Cohtml.Runtime">
|
<Reference Include="Cohtml.Runtime">
|
||||||
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Cohtml.Runtime.dll</HintPath>
|
<HintPath>ManagedLibs\Cohtml.Runtime.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="MelonLoader">
|
<Reference Include="MelonLoader">
|
||||||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll</HintPath>
|
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll</HintPath>
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
using ABI_RC.Core.InteractionSystem;
|
using ABI_RC.Core.InteractionSystem;
|
||||||
|
using ABI_RC.Core.IO;
|
||||||
|
using cohtml;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
|
||||||
namespace NAK.Melons.FuckMetrics.HarmonyPatches;
|
namespace NAK.Melons.FuckMetrics.HarmonyPatches;
|
||||||
|
@ -60,3 +62,29 @@ class ViewManagerPatches
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class CohtmlViewPatches
|
||||||
|
{
|
||||||
|
private static CohtmlView _quickMenuView;
|
||||||
|
private static CohtmlView _gameMenuView;
|
||||||
|
private static Traverse _quickMenuOpenTraverse;
|
||||||
|
private static Traverse _gameMenuOpenTraverse;
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(CVR_MenuManager), "Start")]
|
||||||
|
private static void Postfix_CVR_MenuManager_Start(ref CVR_MenuManager __instance, ref CohtmlView ___quickMenu)
|
||||||
|
{
|
||||||
|
_quickMenuView = ___quickMenu;
|
||||||
|
_quickMenuOpenTraverse = Traverse.Create(__instance).Field("_quickMenuOpen");
|
||||||
|
SchedulerSystem.AddJob(new SchedulerSystem.Job(() => FuckMetrics.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(() => FuckMetrics.CohtmlAdvanceView(_gameMenuView, _gameMenuOpenTraverse)), 12f, 6f, -1);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,9 +6,13 @@ namespace NAK.Melons.FuckMetrics;
|
||||||
|
|
||||||
public class FuckMetricsMod : MelonMod
|
public class FuckMetricsMod : MelonMod
|
||||||
{
|
{
|
||||||
|
public static MelonLogger.Instance Logger;
|
||||||
public const string SettingsCategory = "FuckMetrics";
|
public const string SettingsCategory = "FuckMetrics";
|
||||||
public static readonly MelonPreferences_Category CategoryFuckMetrics = MelonPreferences.CreateCategory(SettingsCategory);
|
public static readonly MelonPreferences_Category CategoryFuckMetrics = MelonPreferences.CreateCategory(SettingsCategory);
|
||||||
|
|
||||||
|
public static readonly MelonPreferences_Entry<bool> EntryDisableCohtmlViewOnIdle =
|
||||||
|
CategoryFuckMetrics.CreateEntry("Disable CohtmlView On Idle", false, description: "Disables CohtmlView on the menus when idle. This can give a huge performance boost.");
|
||||||
|
|
||||||
public static readonly MelonPreferences_Entry<SettingState> EntryDisableMetrics =
|
public static readonly MelonPreferences_Entry<SettingState> EntryDisableMetrics =
|
||||||
CategoryFuckMetrics.CreateEntry("Menu Metrics", SettingState.MenuOnly, description: "Disables menu metrics (FPS & Ping). Updates once on menu open if disabled.");
|
CategoryFuckMetrics.CreateEntry("Menu Metrics", SettingState.MenuOnly, description: "Disables menu metrics (FPS & Ping). Updates once on menu open if disabled.");
|
||||||
|
|
||||||
|
@ -20,7 +24,6 @@ public class FuckMetricsMod : MelonMod
|
||||||
|
|
||||||
public static readonly MelonPreferences_Entry<float> EntryCoreUpdateRate =
|
public static readonly MelonPreferences_Entry<float> EntryCoreUpdateRate =
|
||||||
CategoryFuckMetrics.CreateEntry("Core Update Rate", 2f, description: "Sets the update rate for the menu core updates. Default is 0.1f. Recommended to be 2f or higher.");
|
CategoryFuckMetrics.CreateEntry("Core Update Rate", 2f, description: "Sets the update rate for the menu core updates. Default is 0.1f. Recommended to be 2f or higher.");
|
||||||
|
|
||||||
public enum SettingState
|
public enum SettingState
|
||||||
{
|
{
|
||||||
Always,
|
Always,
|
||||||
|
@ -30,10 +33,14 @@ public class FuckMetricsMod : MelonMod
|
||||||
|
|
||||||
public override void OnInitializeMelon()
|
public override void OnInitializeMelon()
|
||||||
{
|
{
|
||||||
|
Logger = LoggerInstance;
|
||||||
EntryDisableMetrics.OnEntryValueChangedUntyped.Subscribe(OnDisableMetrics);
|
EntryDisableMetrics.OnEntryValueChangedUntyped.Subscribe(OnDisableMetrics);
|
||||||
EntryDisableCoreUpdates.OnEntryValueChangedUntyped.Subscribe(OnDisableCoreUpdates);
|
EntryDisableCoreUpdates.OnEntryValueChangedUntyped.Subscribe(OnDisableCoreUpdates);
|
||||||
|
EntryMetricsUpdateRate.OnEntryValueChangedUntyped.Subscribe(OnChangeMetricsUpdateRate);
|
||||||
|
EntryCoreUpdateRate.OnEntryValueChangedUntyped.Subscribe(OnChangeCoreUpdateRate);
|
||||||
ApplyPatches(typeof(HarmonyPatches.CVR_MenuManagerPatches));
|
ApplyPatches(typeof(HarmonyPatches.CVR_MenuManagerPatches));
|
||||||
ApplyPatches(typeof(HarmonyPatches.ViewManagerPatches));
|
ApplyPatches(typeof(HarmonyPatches.ViewManagerPatches));
|
||||||
|
ApplyPatches(typeof(HarmonyPatches.CohtmlViewPatches));
|
||||||
MelonCoroutines.Start(WaitForLocalPlayer());
|
MelonCoroutines.Start(WaitForLocalPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +67,24 @@ public class FuckMetricsMod : MelonMod
|
||||||
FuckMetrics.ToggleCoreUpdates(EntryDisableCoreUpdates.Value == SettingState.Always);
|
FuckMetrics.ToggleCoreUpdates(EntryDisableCoreUpdates.Value == SettingState.Always);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnChangeMetricsUpdateRate(object arg1, object arg2)
|
||||||
|
{
|
||||||
|
if (EntryDisableMetrics.Value != SettingState.Disabled)
|
||||||
|
{
|
||||||
|
FuckMetrics.ToggleMetrics(false);
|
||||||
|
FuckMetrics.ToggleMetrics(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnChangeCoreUpdateRate(object arg1, object arg2)
|
||||||
|
{
|
||||||
|
if (EntryDisableCoreUpdates.Value != SettingState.Disabled)
|
||||||
|
{
|
||||||
|
FuckMetrics.ToggleCoreUpdates(false);
|
||||||
|
FuckMetrics.ToggleCoreUpdates(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ApplyPatches(Type type)
|
private void ApplyPatches(Type type)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -68,8 +93,8 @@ public class FuckMetricsMod : MelonMod
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
LoggerInstance.Msg($"Failed while patching {type.Name}!");
|
Logger.Msg($"Failed while patching {type.Name}!");
|
||||||
LoggerInstance.Error(e);
|
Logger.Error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue