Decompiled source of TootTallyKeyOverlay v1.0.1

plugin/TootTallyKeyOverlay.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 BaboonAPI.Hooks.Initializer;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TootTallyCore;
using TootTallyCore.Graphics;
using TootTallyCore.Utils.TootTallyModules;
using TootTallySettings;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[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("TootTallyKeyOverlay")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("KeyOverlay, a visual representation of key strokes for streaming or recordings")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("TootTallyKeyOverlay")]
[assembly: AssemblyTitle("TootTallyKeyOverlay")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TootTallyKeyOverlay
{
	[BepInPlugin("TootTallyKeyOverlay", "TootTallyKeyOverlay", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin, ITootTallyModule
	{
		public static class KeyOverlayPatches
		{
			private static Dictionary<KeyCode, SingleKey> _keyPressedDict;

			private static CustomButton _keyPrefab;

			private static GameObject _keyOverlayUI;

			[HarmonyPatch(typeof(GameObjectFactory), "OnHomeControllerInitialize")]
			[HarmonyPostfix]
			public static void SetKeyOverlayPrefab()
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0103: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)_keyPrefab != (Object)null))
				{
					CustomButton val = GameObjectFactory.CreateCustomButton((Transform)null, Vector2.zero, new Vector2(50f, 50f), "test", "tempObj", (Action)null);
					_keyPrefab = Object.Instantiate<CustomButton>(val);
					((Object)((Component)_keyPrefab).gameObject).name = "KeyOverlayPrefab";
					((Component)_keyPrefab).GetComponent<RectTransform>().sizeDelta = Vector2.one * 30f;
					_keyPrefab.textHolder.fontSize = 10;
					Transform val2 = Object.Instantiate<Transform>(((Component)_keyPrefab).transform.Find("Text"), ((Component)_keyPrefab).transform);
					((Object)val2).name = "KeyText";
					((Graphic)((Component)val2).GetComponent<Text>()).color = new Color(((Graphic)_keyPrefab.textHolder).color.r, ((Graphic)_keyPrefab.textHolder).color.g, ((Graphic)_keyPrefab.textHolder).color.b, 0.45f);
					((Component)val2).GetComponent<Text>().fontSize = 30;
					Object.DestroyImmediate((Object)(object)((Component)val).gameObject);
					Object.DontDestroyOnLoad((Object)(object)_keyPrefab);
				}
			}

			[HarmonyPatch(typeof(GameController), "Start")]
			[HarmonyPostfix]
			public static void OnGameControllerStartSetupOverlay(GameController __instance)
			{
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				if (!__instance.freeplay)
				{
					GameObject val = GameObject.Find("GameplayCanvas/UIHolder");
					_keyOverlayUI = ((Component)Object.Instantiate<CustomButton>(_keyPrefab, val.transform)).gameObject;
					Object.DestroyImmediate((Object)(object)_keyOverlayUI.transform.Find("Text"));
					Object.DestroyImmediate((Object)(object)_keyOverlayUI.GetComponent<Image>());
					RectTransform component = _keyOverlayUI.GetComponent<RectTransform>();
					component.sizeDelta = new Vector2(30f, 180f);
					component.anchoredPosition = new Vector2(17f, -90f);
					VerticalLayoutGroup val2 = _keyOverlayUI.AddComponent<VerticalLayoutGroup>();
					((LayoutGroup)val2).childAlignment = (TextAnchor)4;
					bool childScaleWidth = (((HorizontalOrVerticalLayoutGroup)val2).childScaleHeight = false);
					((HorizontalOrVerticalLayoutGroup)val2).childScaleWidth = childScaleWidth;
					childScaleWidth = (((HorizontalOrVerticalLayoutGroup)val2).childForceExpandHeight = false);
					((HorizontalOrVerticalLayoutGroup)val2).childForceExpandWidth = childScaleWidth;
					childScaleWidth = (((HorizontalOrVerticalLayoutGroup)val2).childControlHeight = false);
					((HorizontalOrVerticalLayoutGroup)val2).childControlWidth = childScaleWidth;
					_keyPressedDict = new Dictionary<KeyCode, SingleKey>();
				}
			}

			[HarmonyPatch(typeof(GameController), "Update")]
			[HarmonyPostfix]
			public static void OnUpdateDetectKeyPressed(GameController __instance, List<KeyCode> ___toot_keys)
			{
				if (__instance.freeplay || _keyPressedDict == null)
				{
					return;
				}
				___toot_keys.ForEach(delegate(KeyCode key)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
					//IL_0014: Unknown result type (might be due to invalid IL or missing references)
					//IL_010a: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
					//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
					//IL_007d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0093: Unknown result type (might be due to invalid IL or missing references)
					//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
					//IL_0123: Unknown result type (might be due to invalid IL or missing references)
					if (Input.GetKey(key))
					{
						if (!_keyPressedDict.ContainsKey(key))
						{
							if (_keyPressedDict.Count < 6)
							{
								CustomButton val = Object.Instantiate<CustomButton>(_keyPrefab, _keyOverlayUI.transform);
								((Component)((Component)val).transform.Find("KeyText")).GetComponent<Text>().text = ((object)(KeyCode)(ref key)).ToString();
								((Object)val).name = $"KeyOverlay{key}";
								_keyPressedDict.Add(key, new SingleKey(val));
								_keyPressedDict[key].OnKeyPress();
								LogInfo($"New key pressed, adding {key} to overlay.");
							}
						}
						else if (!_keyPressedDict[key].isPressed)
						{
							_keyPressedDict[key].OnKeyPress();
						}
					}
					else if (_keyPressedDict.ContainsKey(key) && _keyPressedDict[key].isPressed)
					{
						_keyPressedDict[key].OnKeyRelease();
					}
				});
			}
		}

		public static Plugin Instance;

		private Harmony _harmony;

		public static TootTallySettingPage settingPage;

		public ConfigEntry<bool> ModuleConfigEnabled { get; set; }

		public bool IsConfigInitialized { get; set; }

		public string Name
		{
			get
			{
				return "KeyOverlay";
			}
			set
			{
				Name = value;
			}
		}

		public static void LogInfo(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)msg);
		}

		public static void LogError(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogError((object)msg);
		}

		private void Awake()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			if (!((Object)(object)Instance != (Object)null))
			{
				Instance = this;
				_harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				GameInitializationEvent.Register(((BaseUnityPlugin)this).Info, (Action)TryInitialize);
			}
		}

		private void TryInitialize()
		{
			ModuleConfigEnabled = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Modules", "KeyOverlay", true, "Enabled visual display for key strokes during a song.");
			TootTallyModuleManager.AddModule((ITootTallyModule)(object)this);
			Plugin.Instance.AddModuleToSettingPage((ITootTallyModule)(object)this);
		}

		public void LoadModule()
		{
			_harmony.PatchAll(typeof(KeyOverlayPatches));
			LogInfo("Module loaded!");
		}

		public void UnloadModule()
		{
			_harmony.UnpatchSelf();
			settingPage.Remove();
			LogInfo("Module unloaded!");
		}
	}
	public class SingleKey
	{
		private CustomButton _gameObject;

		public bool isPressed;

		private int _pressCount;

		public SingleKey(CustomButton gameObject)
		{
			_gameObject = gameObject;
		}

		public void OnKeyPress()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			((Selectable)_gameObject.button).OnPointerEnter(new PointerEventData(EventSystem.current));
			_pressCount++;
			_gameObject.textHolder.text = _pressCount.ToString();
			isPressed = true;
		}

		public void OnKeyRelease()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			((Selectable)_gameObject.button).OnPointerExit(new PointerEventData(EventSystem.current));
			isPressed = false;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "TootTallyKeyOverlay";

		public const string PLUGIN_NAME = "TootTallyKeyOverlay";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}