mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 14:29:25 +00:00
what
This commit is contained in:
parent
ddb6c85717
commit
453d8023c1
3 changed files with 95 additions and 100 deletions
|
@ -8,6 +8,13 @@ namespace NAK.Melons.FuckMetrics
|
||||||
{
|
{
|
||||||
public static class FuckMetrics
|
public static class FuckMetrics
|
||||||
{
|
{
|
||||||
|
public enum SettingState
|
||||||
|
{
|
||||||
|
Always,
|
||||||
|
MenuOnly,
|
||||||
|
Disabled
|
||||||
|
}
|
||||||
|
|
||||||
public static void ToggleMetrics(bool enable)
|
public static void ToggleMetrics(bool enable)
|
||||||
{
|
{
|
||||||
var job = SchedulerSystem.Instance.activeJobs.FirstOrDefault(pair => pair.Job.Method.Name == "UpdateMetrics").Job;
|
var job = SchedulerSystem.Instance.activeJobs.FirstOrDefault(pair => pair.Job.Method.Name == "UpdateMetrics").Job;
|
||||||
|
@ -34,6 +41,36 @@ namespace NAK.Melons.FuckMetrics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ApplyMetricsSettings(bool show)
|
||||||
|
{
|
||||||
|
var disableMetrics = FuckMetricsMod.EntryDisableMetrics.Value;
|
||||||
|
if (disableMetrics == FuckMetrics.SettingState.Always) return;
|
||||||
|
|
||||||
|
if (disableMetrics == FuckMetrics.SettingState.MenuOnly)
|
||||||
|
{
|
||||||
|
FuckMetrics.ToggleMetrics(show);
|
||||||
|
}
|
||||||
|
else if (disableMetrics == FuckMetrics.SettingState.Disabled && show)
|
||||||
|
{
|
||||||
|
ViewManager.Instance.UpdateMetrics();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ApplyCoreUpdatesSettings(bool show)
|
||||||
|
{
|
||||||
|
var disableCoreUpdates = FuckMetricsMod.EntryDisableCoreUpdates.Value;
|
||||||
|
if (disableCoreUpdates == FuckMetrics.SettingState.Always) return;
|
||||||
|
|
||||||
|
if (disableCoreUpdates == FuckMetrics.SettingState.MenuOnly)
|
||||||
|
{
|
||||||
|
FuckMetrics.ToggleCoreUpdates(show);
|
||||||
|
}
|
||||||
|
else if (disableCoreUpdates == FuckMetrics.SettingState.Disabled && show)
|
||||||
|
{
|
||||||
|
CVR_MenuManager.Instance.SendCoreUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void CohtmlAdvanceView(CohtmlView cohtmlView, Traverse menuOpenTraverse)
|
public static void CohtmlAdvanceView(CohtmlView cohtmlView, Traverse menuOpenTraverse)
|
||||||
{
|
{
|
||||||
if (!FuckMetricsMod.EntryDisableCohtmlViewOnIdle.Value) return;
|
if (!FuckMetricsMod.EntryDisableCohtmlViewOnIdle.Value) return;
|
||||||
|
|
|
@ -3,101 +3,63 @@ using ABI_RC.Core.IO;
|
||||||
using cohtml;
|
using cohtml;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
|
||||||
namespace NAK.Melons.FuckMetrics.HarmonyPatches;
|
namespace NAK.Melons.FuckMetrics.HarmonyPatches
|
||||||
|
|
||||||
class CVR_MenuManagerPatches
|
|
||||||
{
|
{
|
||||||
[HarmonyPostfix]
|
public static class CVR_MenuManagerPatches
|
||||||
[HarmonyPatch(typeof(CVR_MenuManager), "ToggleQuickMenu", new Type[] { typeof(bool) })]
|
|
||||||
private static void Postfix_CVR_MenuManager_ToggleQuickMenu(bool show)
|
|
||||||
{
|
{
|
||||||
var disableMetrics = FuckMetricsMod.EntryDisableMetrics.Value;
|
[HarmonyPostfix]
|
||||||
var disableCoreUpdates = FuckMetricsMod.EntryDisableCoreUpdates.Value;
|
[HarmonyPatch(typeof(CVR_MenuManager), "ToggleQuickMenu", new Type[] { typeof(bool) })]
|
||||||
|
private static void Postfix_CVR_MenuManager_ToggleQuickMenu(bool show)
|
||||||
if (disableMetrics == FuckMetricsMod.SettingState.MenuOnly)
|
|
||||||
{
|
{
|
||||||
FuckMetrics.ToggleMetrics(show);
|
FuckMetrics.ApplyMetricsSettings(show);
|
||||||
}
|
FuckMetrics.ApplyCoreUpdatesSettings(show);
|
||||||
else if (disableMetrics == FuckMetricsMod.SettingState.Disabled && show)
|
|
||||||
{
|
|
||||||
ViewManager.Instance.UpdateMetrics();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (disableCoreUpdates == FuckMetricsMod.SettingState.MenuOnly)
|
|
||||||
{
|
|
||||||
FuckMetrics.ToggleCoreUpdates(show);
|
|
||||||
}
|
|
||||||
else if (disableCoreUpdates == FuckMetricsMod.SettingState.Disabled && show)
|
|
||||||
{
|
|
||||||
CVR_MenuManager.Instance.SendCoreUpdate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
class ViewManagerPatches
|
public static class ViewManagerPatches
|
||||||
{
|
|
||||||
[HarmonyPostfix]
|
|
||||||
[HarmonyPatch(typeof(ViewManager), "UiStateToggle", new Type[] { typeof(bool) })]
|
|
||||||
private static void Postfix_ViewManager_UiStateToggle(bool show)
|
|
||||||
{
|
{
|
||||||
var disableMetrics = FuckMetricsMod.EntryDisableMetrics.Value;
|
[HarmonyPostfix]
|
||||||
var disableCoreUpdates = FuckMetricsMod.EntryDisableCoreUpdates.Value;
|
[HarmonyPatch(typeof(ViewManager), "UiStateToggle", new Type[] { typeof(bool) })]
|
||||||
|
private static void Postfix_ViewManager_UiStateToggle(bool show)
|
||||||
if (disableMetrics == FuckMetricsMod.SettingState.MenuOnly)
|
|
||||||
{
|
{
|
||||||
FuckMetrics.ToggleMetrics(show);
|
FuckMetrics.ApplyMetricsSettings(show);
|
||||||
}
|
FuckMetrics.ApplyCoreUpdatesSettings(show);
|
||||||
else if (disableMetrics == FuckMetricsMod.SettingState.Disabled && show)
|
|
||||||
{
|
|
||||||
ViewManager.Instance.UpdateMetrics();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (disableCoreUpdates == FuckMetricsMod.SettingState.MenuOnly)
|
|
||||||
{
|
|
||||||
FuckMetrics.ToggleCoreUpdates(show);
|
|
||||||
}
|
|
||||||
else if (disableCoreUpdates == FuckMetricsMod.SettingState.Disabled && show)
|
|
||||||
{
|
|
||||||
CVR_MenuManager.Instance.SendCoreUpdate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static class CohtmlViewPatches
|
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;
|
private static CohtmlView _quickMenuView;
|
||||||
_quickMenuOpenTraverse = Traverse.Create(__instance).Field("_quickMenuOpen");
|
private static CohtmlView _gameMenuView;
|
||||||
SchedulerSystem.AddJob(new SchedulerSystem.Job(() => FuckMetrics.CohtmlAdvanceView(_quickMenuView, _quickMenuOpenTraverse)), 15f, 6f, -1);
|
private static Traverse _quickMenuOpenTraverse;
|
||||||
}
|
private static Traverse _gameMenuOpenTraverse;
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(ViewManager), "Start")]
|
[HarmonyPatch(typeof(CVR_MenuManager), "Start")]
|
||||||
private static void Postfix_ViewManager_Start(ref ViewManager __instance, ref CohtmlView ___gameMenuView)
|
private static void Postfix_CVRMenuManager_Start(ref CohtmlView ___quickMenu)
|
||||||
{
|
|
||||||
_gameMenuView = ___gameMenuView;
|
|
||||||
_gameMenuOpenTraverse = Traverse.Create(__instance).Field("_gameMenuOpen");
|
|
||||||
SchedulerSystem.AddJob(new SchedulerSystem.Job(() => FuckMetrics.CohtmlAdvanceView(_gameMenuView, _gameMenuOpenTraverse)), 12f, 6f, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPostfix]
|
|
||||||
[HarmonyPatch(typeof(ViewManager), "OnMicrophoneStatusSwitched")]
|
|
||||||
private static void Postfix_ViewManager_OnMicrophoneStatusSwitched()
|
|
||||||
{
|
|
||||||
if (_quickMenuOpenTraverse.GetValue<bool>())
|
|
||||||
{
|
{
|
||||||
if (FuckMetricsMod.EntryDisableMetrics.Value != FuckMetricsMod.SettingState.Always)
|
_quickMenuView = ___quickMenu;
|
||||||
|
_quickMenuOpenTraverse = Traverse.Create<CVR_MenuManager>().Field("_quickMenuOpen");
|
||||||
|
SchedulerSystem.AddJob(() => FuckMetrics.CohtmlAdvanceView(_quickMenuView, _quickMenuOpenTraverse), 15f, 6f, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(ViewManager), "Start")]
|
||||||
|
private static void Postfix_ViewManager_Start(ref CohtmlView ___gameMenuView)
|
||||||
|
{
|
||||||
|
_gameMenuView = ___gameMenuView;
|
||||||
|
_gameMenuOpenTraverse = Traverse.Create<ViewManager>().Field("_gameMenuOpen");
|
||||||
|
SchedulerSystem.AddJob(() => FuckMetrics.CohtmlAdvanceView(_gameMenuView, _gameMenuOpenTraverse), 12f, 6f, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(ViewManager), "OnMicrophoneStatusSwitched")]
|
||||||
|
private static void Postfix_ViewManager_OnMicrophoneStatusSwitched()
|
||||||
|
{
|
||||||
|
if (_quickMenuOpenTraverse.GetValue<bool>())
|
||||||
{
|
{
|
||||||
CVR_MenuManager.Instance.SendCoreUpdate();
|
CVR_MenuManager.Instance.SendCoreUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,63 +13,59 @@ public class FuckMetricsMod : MelonMod
|
||||||
public static readonly MelonPreferences_Entry<bool> EntryDisableCohtmlViewOnIdle =
|
public static readonly MelonPreferences_Entry<bool> EntryDisableCohtmlViewOnIdle =
|
||||||
CategoryFuckMetrics.CreateEntry("Disable CohtmlView On Idle", false, description: "Disables CohtmlView on the menus when idle. Takes up to 6 seconds after menu exit. This can give a huge performance boost.");
|
CategoryFuckMetrics.CreateEntry("Disable CohtmlView On Idle", false, description: "Disables CohtmlView on the menus when idle. Takes up to 6 seconds after menu exit. This can give a huge performance boost.");
|
||||||
|
|
||||||
public static readonly MelonPreferences_Entry<SettingState> EntryDisableMetrics =
|
public static readonly MelonPreferences_Entry<FuckMetrics.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", FuckMetrics.SettingState.MenuOnly, description: "Disables menu metrics (FPS & Ping). Updates once on menu open if disabled.");
|
||||||
|
|
||||||
public static readonly MelonPreferences_Entry<SettingState> EntryDisableCoreUpdates =
|
public static readonly MelonPreferences_Entry<FuckMetrics.SettingState> EntryDisableCoreUpdates =
|
||||||
CategoryFuckMetrics.CreateEntry("Menu Core Updates", SettingState.MenuOnly, description: "Disables menu core updates (Gamerule Icons & Debug Status). Updates once on menu open if disabled.");
|
CategoryFuckMetrics.CreateEntry("Menu Core Updates", FuckMetrics.SettingState.MenuOnly, description: "Disables menu core updates (Gamerule Icons & Debug Status). Updates once on menu open if disabled.");
|
||||||
|
|
||||||
public static readonly MelonPreferences_Entry<float> EntryMetricsUpdateRate =
|
public static readonly MelonPreferences_Entry<float> EntryMetricsUpdateRate =
|
||||||
CategoryFuckMetrics.CreateEntry("Metrics Update Rate", 1f, description: "Sets the update rate for the menu metrics. Default is 0.5f. Recommended to be 1f or higher.");
|
CategoryFuckMetrics.CreateEntry("Metrics Update Rate", 1f, description: "Sets the update rate for the menu metrics. Default is 0.5f. Recommended to be 1f or higher.");
|
||||||
|
|
||||||
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
|
|
||||||
{
|
|
||||||
Always,
|
|
||||||
MenuOnly,
|
|
||||||
Disabled
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnInitializeMelon()
|
public override void OnInitializeMelon()
|
||||||
{
|
{
|
||||||
Logger = LoggerInstance;
|
Logger = LoggerInstance;
|
||||||
|
|
||||||
EntryDisableMetrics.OnEntryValueChangedUntyped.Subscribe(OnDisableMetrics);
|
EntryDisableMetrics.OnEntryValueChangedUntyped.Subscribe(OnDisableMetrics);
|
||||||
EntryDisableCoreUpdates.OnEntryValueChangedUntyped.Subscribe(OnDisableCoreUpdates);
|
EntryDisableCoreUpdates.OnEntryValueChangedUntyped.Subscribe(OnDisableCoreUpdates);
|
||||||
EntryMetricsUpdateRate.OnEntryValueChangedUntyped.Subscribe(OnChangeMetricsUpdateRate);
|
EntryMetricsUpdateRate.OnEntryValueChangedUntyped.Subscribe(OnChangeMetricsUpdateRate);
|
||||||
EntryCoreUpdateRate.OnEntryValueChangedUntyped.Subscribe(OnChangeCoreUpdateRate);
|
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));
|
ApplyPatches(typeof(HarmonyPatches.CohtmlViewPatches));
|
||||||
MelonCoroutines.Start(WaitForLocalPlayer());
|
MelonCoroutines.Start(WaitForLocalPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator WaitForLocalPlayer()
|
private IEnumerator WaitForLocalPlayer()
|
||||||
{
|
{
|
||||||
while (PlayerSetup.Instance == null)
|
while (PlayerSetup.Instance == null)
|
||||||
yield return null;
|
yield return null;
|
||||||
UpdateSettings();
|
UpdateSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateSettings()
|
||||||
|
{
|
||||||
|
FuckMetrics.ToggleMetrics(EntryDisableMetrics.Value == FuckMetrics.SettingState.Always);
|
||||||
|
FuckMetrics.ToggleCoreUpdates(EntryDisableCoreUpdates.Value == FuckMetrics.SettingState.Always);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnDisableMetrics(object arg1, object arg2)
|
private void OnDisableMetrics(object arg1, object arg2)
|
||||||
{
|
{
|
||||||
FuckMetrics.ToggleMetrics(EntryDisableMetrics.Value == SettingState.Always);
|
FuckMetrics.ToggleMetrics(EntryDisableMetrics.Value == FuckMetrics.SettingState.Always);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDisableCoreUpdates(object arg1, object arg2)
|
private void OnDisableCoreUpdates(object arg1, object arg2)
|
||||||
{
|
{
|
||||||
FuckMetrics.ToggleCoreUpdates(EntryDisableCoreUpdates.Value == SettingState.Always);
|
FuckMetrics.ToggleCoreUpdates(EntryDisableCoreUpdates.Value == FuckMetrics.SettingState.Always);
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateSettings()
|
|
||||||
{
|
|
||||||
FuckMetrics.ToggleMetrics(EntryDisableMetrics.Value == SettingState.Always);
|
|
||||||
FuckMetrics.ToggleCoreUpdates(EntryDisableCoreUpdates.Value == SettingState.Always);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnChangeMetricsUpdateRate(object arg1, object arg2)
|
private void OnChangeMetricsUpdateRate(object arg1, object arg2)
|
||||||
{
|
{
|
||||||
if (EntryDisableMetrics.Value != SettingState.Disabled)
|
if (EntryDisableMetrics.Value != FuckMetrics.SettingState.Disabled)
|
||||||
{
|
{
|
||||||
FuckMetrics.ToggleMetrics(false);
|
FuckMetrics.ToggleMetrics(false);
|
||||||
FuckMetrics.ToggleMetrics(true);
|
FuckMetrics.ToggleMetrics(true);
|
||||||
|
@ -78,7 +74,7 @@ public class FuckMetricsMod : MelonMod
|
||||||
|
|
||||||
private void OnChangeCoreUpdateRate(object arg1, object arg2)
|
private void OnChangeCoreUpdateRate(object arg1, object arg2)
|
||||||
{
|
{
|
||||||
if (EntryDisableCoreUpdates.Value != SettingState.Disabled)
|
if (EntryDisableCoreUpdates.Value != FuckMetrics.SettingState.Disabled)
|
||||||
{
|
{
|
||||||
FuckMetrics.ToggleCoreUpdates(false);
|
FuckMetrics.ToggleCoreUpdates(false);
|
||||||
FuckMetrics.ToggleCoreUpdates(true);
|
FuckMetrics.ToggleCoreUpdates(true);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue