Decompiled source of GameplayUIReducer v1.1.0

GameplayUIReducer.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("GameplayUIReducer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Hides UI elements during gameplay")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("GameplayUIReducer")]
[assembly: AssemblyTitle("GameplayUIReducer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
namespace GameplayUIReducer;

public class OptionalTootTallySettings
{
	public static object AddNewPage(string pageName, string headerText, float elementSpacing, Color bgColor)
	{
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Type type = Type.GetType("TootTallySettings.TootTallySettingsManager, TootTallySettings");
			if (type == null)
			{
				Plugin.Log.LogDebug((object)"TootTallySettings not found.");
				return null;
			}
			MethodInfo method = type.GetMethod("AddNewPage", new Type[4]
			{
				typeof(string),
				typeof(string),
				typeof(float),
				typeof(Color)
			});
			return method.Invoke(type, new object[4] { pageName, headerText, elementSpacing, bgColor });
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)"Exception trying to get config page. Reporting TootTallySettings as not found.");
			Plugin.Log.LogError((object)ex.Message);
			Plugin.Log.LogError((object)ex.StackTrace);
			return null;
		}
	}

	public static void AddToggle(object page, string name, ConfigEntry<bool> config)
	{
		MethodInfo method = page.GetType().GetMethod("AddToggle", new Type[3]
		{
			typeof(string),
			typeof(ConfigEntry<bool>),
			typeof(UnityAction<bool>)
		});
		if (method != null)
		{
			method.Invoke(page, new object[3] { name, config, null });
		}
	}

	public static void AddSlider(object page, string name, float min, float max, ConfigEntry<float> config, bool integerOnly)
	{
		MethodInfo method = page.GetType().GetMethod("AddSlider", new Type[5]
		{
			typeof(string),
			typeof(float),
			typeof(float),
			typeof(ConfigEntry<float>),
			typeof(bool)
		});
		if (method != null)
		{
			method.Invoke(page, new object[5] { name, min, max, config, integerOnly });
		}
	}

	public static void AddDropdown(object page, string name, ConfigEntryBase config)
	{
		MethodInfo method = page.GetType().GetMethod("AddDropdown", new Type[2]
		{
			typeof(string),
			typeof(ConfigEntryBase)
		});
		if (method != null)
		{
			method.Invoke(page, new object[2] { name, config });
		}
	}

	public static void AddLabel(object page, string label, int fontSize, TextAlignmentOptions textAlignment)
	{
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		MethodInfo method = page.GetType().GetMethod("AddLabel", new Type[5]
		{
			typeof(string),
			typeof(string),
			typeof(int),
			typeof(FontStyles),
			typeof(TextAlignmentOptions)
		});
		if (method != null)
		{
			method.Invoke(page, new object[5]
			{
				label,
				label,
				fontSize,
				(object)(FontStyles)0,
				textAlignment
			});
		}
	}
}
[BepInPlugin("GameplayUIReducer", "GameplayUIReducer", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
	internal static readonly Dictionary<string, ConfigEntry<bool>> ConfigEntries = new Dictionary<string, ConfigEntry<bool>>();

	internal static readonly Dictionary<string, string> ElementPaths = new Dictionary<string, string>();

	internal static ManualLogSource Log { get; set; }

	private void Awake()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		DeclareElements();
		SetupConfig();
		new Harmony("GameplayUIReducer").PatchAll();
	}

	private void SetupConfig()
	{
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		foreach (KeyValuePair<string, string> elementPath in ElementPaths)
		{
			ConfigEntries.Add(elementPath.Key, ((BaseUnityPlugin)this).Config.Bind<bool>("Element Hiding", elementPath.Key, false, "Hides the " + elementPath.Key.ToLower() + " element."));
		}
		object obj = OptionalTootTallySettings.AddNewPage("Gameplay UI Reducer", "Gameplay UI Reducer", 40f, new Color(0.1f, 0.1f, 0.1f, 0.1f));
		if (obj == null)
		{
			return;
		}
		foreach (KeyValuePair<string, ConfigEntry<bool>> configEntry in ConfigEntries)
		{
			OptionalTootTallySettings.AddToggle(obj, "Hide " + configEntry.Key, configEntry.Value);
		}
	}

	private void DeclareElements()
	{
		ElementPaths.Add("Breath Meter", "BreathCanvas");
		ElementPaths.Add("Champ Text", "ChampCanvas");
		ElementPaths.Add("Health Meter", "HealthMask");
		ElementPaths.Add("Rainbow Borders", null);
		ElementPaths.Add("Longest Combo", "GameplayCanvas/UIHolder/maxcombo");
		ElementPaths.Add("Left Bounds", "GameplayCanvas/GameSpace/LeftBounds");
		ElementPaths.Add("Note Lines", "GameplayCanvas/GameSpace/NoteLinesHolder");
		ElementPaths.Add("Notes", "GameplayCanvas/GameSpace/NotesHolder");
		ElementPaths.Add("Lyrics", "GameplayCanvas/GameSpace/NotesHolder/AllLyrics");
		ElementPaths.Add("Note Explosions", "GameplayCanvas/GameSpace/NoteEndExplosions");
		ElementPaths.Add("Note Cursor", "GameplayCanvas/GameSpace/TargetNote");
		ElementPaths.Add("Multiplier Popup", "GameplayCanvas/Popups/popup_mult");
		ElementPaths.Add("Accuracy Popup", "GameplayCanvas/Popups/popup_text");
		ElementPaths.Add("No Gap Popup", "GameplayCanvas/Popups/no_gap");
		ElementPaths.Add("Max Popup", "GameplayCanvas/Popups/MAX");
		ElementPaths.Add("Song Name", "GameplayCanvas/UIHolder/upper_right/Song Name Shadow");
		ElementPaths.Add("Score Counter", "GameplayCanvas/UIHolder/upper_right/ScoreShadow");
		ElementPaths.Add("Time Elapsed", "GameplayCanvas/UIHolder/time_elapsed");
		ElementPaths.Add("Time Elapsed Progress Bar", "GameplayCanvas/UIHolder/time_elapsed_bar");
		ElementPaths.Add("Tromboner Model", "PlayerModelHolder");
		ElementPaths.Add("Beat Lines", null);
		ElementPaths.Add("Improv Zones", null);
	}

	internal static bool IsRainbowVisible()
	{
		ConfigEntry<bool> obj = ConfigEntries["Rainbow Borders"];
		return obj == null || !obj.Value;
	}

	internal static bool AreBeatLinesVisible()
	{
		ConfigEntry<bool> obj = ConfigEntries["Beat Lines"];
		return obj == null || !obj.Value;
	}

	internal static bool AreImprovZonesVisible()
	{
		ConfigEntry<bool> obj = ConfigEntries["Improv Zones"];
		return obj == null || !obj.Value;
	}
}
[HarmonyPatch(typeof(GameController), "Start")]
internal class GameControllerStartPatch
{
	private static void Postfix()
	{
		foreach (KeyValuePair<string, string> elementPath in Plugin.ElementPaths)
		{
			ConfigEntry<bool> obj = Plugin.ConfigEntries[elementPath.Key];
			if (obj != null && obj.Value && !string.IsNullOrWhiteSpace(elementPath.Value))
			{
				GameObject val = GameObject.Find(elementPath.Value);
				if ((Object)(object)val == (Object)null)
				{
					Plugin.Log.LogError((object)("Unable to find " + elementPath.Key + " at '" + elementPath.Value + "', it will not be hidden."));
				}
				else
				{
					Plugin.Log.LogDebug((object)("Hiding element " + elementPath.Key + "..."));
					val.SetActive(false);
				}
			}
		}
	}
}
[HarmonyPatch(typeof(GameController), "tryToLoadLevel")]
internal class GameControllerLoadPatch
{
	private static void Postfix(GameController __instance)
	{
		if (!Plugin.AreBeatLinesVisible())
		{
			__instance.beatspermeasure = int.MaxValue;
		}
		if (!Plugin.AreImprovZonesVisible())
		{
			__instance.improv_zones = new List<float[]>();
		}
	}
}
[HarmonyPatch(typeof(GameController), "buildImprovZones")]
internal class GameControllerImprovZonesPatch
{
	private static bool Prefix()
	{
		return Plugin.AreImprovZonesVisible();
	}
}
[HarmonyPatch(typeof(RainbowEffect), "startRainbowLess")]
internal class RainbowEffectStartPatch
{
	private static bool Prefix(ref bool ___champmode)
	{
		___champmode = true;
		return Plugin.IsRainbowVisible();
	}
}
[HarmonyPatch(typeof(RainbowEffect), "stopRainbow")]
internal class RainbowEffectStopPatch
{
	private static bool Prefix(ref bool ___champmode)
	{
		___champmode = false;
		return Plugin.IsRainbowVisible();
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "GameplayUIReducer";

	public const string PLUGIN_NAME = "GameplayUIReducer";

	public const string PLUGIN_VERSION = "1.1.0";
}