This commit is contained in:
NotAKidoS 2023-03-16 02:25:41 -05:00
parent 28347e45a4
commit 994d04fe9a
3 changed files with 51 additions and 36 deletions

View file

@ -5,27 +5,27 @@ namespace NAK.Melons.FuckMetrics
{ {
public static class FuckMetrics public static class FuckMetrics
{ {
public static void ToggleMetrics(bool disable) 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;
if (!disable && job == null) if (enable && job == null)
{ {
SchedulerSystem.AddJob(new SchedulerSystem.Job(ViewManager.Instance.UpdateMetrics), 0f, 0.5f, -1); SchedulerSystem.AddJob(new SchedulerSystem.Job(ViewManager.Instance.UpdateMetrics), 0f, 0.5f, -1);
} }
else if (disable && job != null) else if (!enable && job != null)
{ {
SchedulerSystem.RemoveJob(job); SchedulerSystem.RemoveJob(job);
} }
} }
public static void ToggleCoreUpdates(bool disable) public static void ToggleCoreUpdates(bool enable)
{ {
var job = SchedulerSystem.Instance.activeJobs.FirstOrDefault(pair => pair.Job.Method.Name == "SendCoreUpdate").Job; var job = SchedulerSystem.Instance.activeJobs.FirstOrDefault(pair => pair.Job.Method.Name == "SendCoreUpdate").Job;
if (!disable && job == null) if (enable && job == null)
{ {
SchedulerSystem.AddJob(new SchedulerSystem.Job(CVR_MenuManager.Instance.SendCoreUpdate), 0f, 0.1f, -1); SchedulerSystem.AddJob(new SchedulerSystem.Job(CVR_MenuManager.Instance.SendCoreUpdate), 0f, 0.1f, -1);
} }
else if (disable && job != null) else if (!enable && job != null)
{ {
SchedulerSystem.RemoveJob(job); SchedulerSystem.RemoveJob(job);
} }

View file

@ -1,36 +1,32 @@
using ABI_RC.Core.InteractionSystem; using ABI_RC.Core.InteractionSystem;
using ABI_RC.Core.Player;
using HarmonyLib; using HarmonyLib;
namespace NAK.Melons.FuckMetrics.HarmonyPatches; namespace NAK.Melons.FuckMetrics.HarmonyPatches;
class PlayerSetupPatches
{
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerSetup), "Start")]
private static void Postfix_PlayerSetup_Start()
{
FuckMetrics.ToggleMetrics(FuckMetricsMod.EntryDisableMetrics.Value == FuckMetricsMod.SettingState.Enabled);
FuckMetrics.ToggleCoreUpdates(FuckMetricsMod.EntryDisableCoreUpdates.Value == FuckMetricsMod.SettingState.Enabled);
}
}
class CVR_MenuManagerPatches class CVR_MenuManagerPatches
{ {
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(CVR_MenuManager), "ToggleQuickMenu", new Type[] { typeof(bool) })] [HarmonyPatch(typeof(CVR_MenuManager), "ToggleQuickMenu", new Type[] { typeof(bool) })]
private static void Postfix_CVR_MenuManager_ToggleQuickMenu(bool show) private static void Postfix_CVR_MenuManager_ToggleQuickMenu(bool show)
{ {
if (FuckMetricsMod.EntryDisableCoreUpdates.Value == FuckMetricsMod.SettingState.Disabled) return; var disableMetrics = FuckMetricsMod.EntryDisableMetrics.Value;
var disableCoreUpdates = FuckMetricsMod.EntryDisableCoreUpdates.Value;
if (FuckMetricsMod.EntryDisableCoreUpdates.Value == FuckMetricsMod.SettingState.MenuOnly) if (disableMetrics == FuckMetricsMod.SettingState.MenuOnly)
{ {
FuckMetrics.ToggleMetrics(show); FuckMetrics.ToggleMetrics(show);
FuckMetrics.ToggleCoreUpdates(show);
} }
else if (show) else if (disableMetrics == FuckMetricsMod.SettingState.Disabled && show)
{ {
ViewManager.Instance.UpdateMetrics(); ViewManager.Instance.UpdateMetrics();
}
if (disableCoreUpdates == FuckMetricsMod.SettingState.MenuOnly)
{
FuckMetrics.ToggleCoreUpdates(show);
}
else if (disableCoreUpdates == FuckMetricsMod.SettingState.Disabled && show)
{
CVR_MenuManager.Instance.SendCoreUpdate(); CVR_MenuManager.Instance.SendCoreUpdate();
} }
} }
@ -42,16 +38,24 @@ class ViewManagerPatches
[HarmonyPatch(typeof(ViewManager), "UiStateToggle", new Type[] { typeof(bool) })] [HarmonyPatch(typeof(ViewManager), "UiStateToggle", new Type[] { typeof(bool) })]
private static void Postfix_ViewManager_UiStateToggle(bool show) private static void Postfix_ViewManager_UiStateToggle(bool show)
{ {
if (FuckMetricsMod.EntryDisableCoreUpdates.Value == FuckMetricsMod.SettingState.Disabled) return; var disableMetrics = FuckMetricsMod.EntryDisableMetrics.Value;
var disableCoreUpdates = FuckMetricsMod.EntryDisableCoreUpdates.Value;
if (FuckMetricsMod.EntryDisableCoreUpdates.Value == FuckMetricsMod.SettingState.MenuOnly) if (disableMetrics == FuckMetricsMod.SettingState.MenuOnly)
{ {
FuckMetrics.ToggleMetrics(show); FuckMetrics.ToggleMetrics(show);
FuckMetrics.ToggleCoreUpdates(show);
} }
else if (show) else if (disableMetrics == FuckMetricsMod.SettingState.Disabled && show)
{ {
ViewManager.Instance.UpdateMetrics(); ViewManager.Instance.UpdateMetrics();
}
if (disableCoreUpdates == FuckMetricsMod.SettingState.MenuOnly)
{
FuckMetrics.ToggleCoreUpdates(show);
}
else if (disableCoreUpdates == FuckMetricsMod.SettingState.Disabled && show)
{
CVR_MenuManager.Instance.SendCoreUpdate(); CVR_MenuManager.Instance.SendCoreUpdate();
} }
} }

View file

@ -1,11 +1,11 @@
using MelonLoader; using ABI_RC.Core.Player;
using MelonLoader;
using System.Collections;
namespace NAK.Melons.FuckMetrics; 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);
@ -17,29 +17,40 @@ public class FuckMetricsMod : MelonMod
public enum SettingState public enum SettingState
{ {
Enabled, Always,
MenuOnly, MenuOnly,
Disabled Disabled
} }
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);
ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches));
ApplyPatches(typeof(HarmonyPatches.CVR_MenuManagerPatches)); ApplyPatches(typeof(HarmonyPatches.CVR_MenuManagerPatches));
ApplyPatches(typeof(HarmonyPatches.ViewManagerPatches)); ApplyPatches(typeof(HarmonyPatches.ViewManagerPatches));
MelonCoroutines.Start(WaitForLocalPlayer());
}
IEnumerator WaitForLocalPlayer()
{
yield return PlayerSetup.Instance == null;
UpdateSettings();
} }
private void OnDisableMetrics(object arg1, object arg2) private void OnDisableMetrics(object arg1, object arg2)
{ {
FuckMetrics.ToggleMetrics(EntryDisableMetrics.Value == SettingState.Enabled); FuckMetrics.ToggleMetrics(EntryDisableMetrics.Value == SettingState.Always);
} }
private void OnDisableCoreUpdates(object arg1, object arg2) private void OnDisableCoreUpdates(object arg1, object arg2)
{ {
FuckMetrics.ToggleCoreUpdates(EntryDisableMetrics.Value == SettingState.Enabled); FuckMetrics.ToggleCoreUpdates(EntryDisableCoreUpdates.Value == SettingState.Always);
}
private void UpdateSettings()
{
FuckMetrics.ToggleMetrics(EntryDisableMetrics.Value == SettingState.Always);
FuckMetrics.ToggleCoreUpdates(EntryDisableCoreUpdates.Value == SettingState.Always);
} }
private void ApplyPatches(Type type) private void ApplyPatches(Type type)
@ -50,8 +61,8 @@ public class FuckMetricsMod : MelonMod
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Msg($"Failed while patching {type.Name}!"); LoggerInstance.Msg($"Failed while patching {type.Name}!");
Logger.Error(e); LoggerInstance.Error(e);
} }
} }
} }