major cleanup

This commit is contained in:
NotAKidoS 2023-04-26 15:32:02 -05:00
parent b33e15377f
commit e5242f76c7
85 changed files with 584 additions and 571 deletions

View file

@ -1,92 +0,0 @@
using ABI_RC.Core.InteractionSystem;
using ABI_RC.Core.IO;
using cohtml;
using HarmonyLib;
using UnityEngine;
namespace NAK.FuckMetrics;
public static class FuckMetrics
{
public enum SettingState
{
Always,
MenuOnly,
Disabled
}
public static void ToggleMetrics(bool enable)
{
var job = SchedulerSystem.Instance.activeJobs.FirstOrDefault(pair => pair.Job.Method.Name == "UpdateMetrics").Job;
if (enable && job == null)
{
SchedulerSystem.AddJob(new SchedulerSystem.Job(ViewManager.Instance.UpdateMetrics), 0f, FuckMetricsMod.EntryMetricsUpdateRate.Value, -1);
}
else if (!enable && job != null)
{
SchedulerSystem.RemoveJob(job);
}
}
public static void ToggleCoreUpdates(bool enable)
{
var job = SchedulerSystem.Instance.activeJobs.FirstOrDefault(pair => pair.Job.Method.Name == "SendCoreUpdate").Job;
if (enable && job == null)
{
SchedulerSystem.AddJob(new SchedulerSystem.Job(CVR_MenuManager.Instance.SendCoreUpdate), 0f, FuckMetricsMod.EntryCoreUpdateRate.Value, -1);
}
else if (!enable && job != null)
{
SchedulerSystem.RemoveJob(job);
}
}
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)
{
if (!FuckMetricsMod.EntryDisableCohtmlViewOnIdle.Value) return;
if (cohtmlView != null && !menuOpenTraverse.GetValue<bool>())
{
cohtmlView.enabled = false;
try
{
cohtmlView.View.Advance(cohtmlView.CohtmlUISystem?.Id ?? 0, (double)Time.unscaledTime * 1000.0);
}
catch (Exception e)
{
FuckMetricsMod.Logger.Error($"An exception was thrown while calling CohtmlView.Advance(). Error message: {e.Message}");
}
}
}
}

View file

@ -1,14 +1,20 @@
using ABI_RC.Core.Player;
using ABI_RC.Core.InteractionSystem;
using ABI_RC.Core.IO;
using ABI_RC.Core.Player;
using cohtml;
using HarmonyLib;
using MelonLoader;
using System.Collections;
using UnityEngine;
namespace NAK.FuckMetrics;
public class FuckMetricsMod : MelonMod
public class FuckMetrics : MelonMod
{
public static MelonLogger.Instance Logger;
public const string SettingsCategory = "FuckMetrics";
public static readonly MelonPreferences_Category CategoryFuckMetrics = MelonPreferences.CreateCategory(SettingsCategory);
internal static MelonLogger.Instance Logger;
public static readonly MelonPreferences_Category CategoryFuckMetrics =
MelonPreferences.CreateCategory(nameof(FuckMetrics));
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.");
@ -95,4 +101,86 @@ public class FuckMetricsMod : MelonMod
Logger.Error(e);
}
}
public enum SettingState
{
Always,
MenuOnly,
Disabled
}
public static void ToggleMetrics(bool enable)
{
var job = SchedulerSystem.Instance.activeJobs.FirstOrDefault(pair => pair.Job.Method.Name == "UpdateMetrics").Job;
if (enable && job == null)
{
SchedulerSystem.AddJob(new SchedulerSystem.Job(ViewManager.Instance.UpdateMetrics), 0f, FuckMetrics.EntryMetricsUpdateRate.Value, -1);
}
else if (!enable && job != null)
{
SchedulerSystem.RemoveJob(job);
}
}
public static void ToggleCoreUpdates(bool enable)
{
var job = SchedulerSystem.Instance.activeJobs.FirstOrDefault(pair => pair.Job.Method.Name == "SendCoreUpdate").Job;
if (enable && job == null)
{
SchedulerSystem.AddJob(new SchedulerSystem.Job(CVR_MenuManager.Instance.SendCoreUpdate), 0f, FuckMetrics.EntryCoreUpdateRate.Value, -1);
}
else if (!enable && job != null)
{
SchedulerSystem.RemoveJob(job);
}
}
public static void ApplyMetricsSettings(bool show)
{
var disableMetrics = FuckMetrics.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 = FuckMetrics.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)
{
if (!FuckMetrics.EntryDisableCohtmlViewOnIdle.Value) return;
if (cohtmlView != null && !menuOpenTraverse.GetValue<bool>())
{
cohtmlView.enabled = false;
try
{
cohtmlView.View.Advance(cohtmlView.CohtmlUISystem?.Id ?? 0, (double)Time.unscaledTime * 1000.0);
}
catch (Exception e)
{
FuckMetrics.Logger.Error($"An exception was thrown while calling CohtmlView.Advance(). Error message: {e.Message}");
}
}
}
}

View file

@ -2,7 +2,6 @@
using NAK.FuckMetrics.Properties;
using System.Reflection;
[assembly: AssemblyVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)]
@ -11,11 +10,11 @@ using System.Reflection;
[assembly: AssemblyProduct(nameof(NAK.FuckMetrics))]
[assembly: MelonInfo(
typeof(NAK.FuckMetrics.FuckMetricsMod),
typeof(NAK.FuckMetrics.FuckMetrics),
nameof(NAK.FuckMetrics),
AssemblyInfoParams.Version,
AssemblyInfoParams.Author,
downloadLink: "https://github.com/NotAKidOnSteam/FuckMetrics"
downloadLink: "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/FuckMetrics"
)]
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]

View file

@ -17,8 +17,8 @@
"requirements": [
"None"
],
"downloadlink": "https://github.com/NotAKidOnSteam/FuckMetrics/releases/download/v1.0.4/FuckMetrics.dll",
"sourcelink": "https://github.com/NotAKidOnSteam/FuckMetrics/",
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r3/FuckMetrics.dll",
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/FuckMetrics/",
"changelog": "- Initial Release.\n- Renamed to FuckMetrics.\n- Add Update Rate settings.\n- Add back CohtmlView disabling as option.\n- Update CoreUpdate on mic toggle if QM is open.\n- Fix Cohtml disabling not using menu instance.",
"embedcolor": "#8ed6fb"
}