Decompiled source of AnimSeer v1.0.1

AnimSeer/AnimSeer.dll

Decompiled 2 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 Microsoft.CodeAnalysis;
using MonoMod.RuntimeDetour;
using UnityEngine;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("AnimSeer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("AnimSeer")]
[assembly: AssemblyTitle("AnimSeer")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace AnimSeer
{
	[BepInPlugin("me.cometcake575.animseer", "AnimSeer", "1.0.1")]
	public class AnimSeerPlugin : BaseUnityPlugin
	{
		private class AnimSeen : MonoBehaviour
		{
			public int scanned;
		}

		private class AnimSeer : MonoBehaviour
		{
			public tk2dSpriteAnimator? anim;

			public int offset;

			private Text? _text;

			private void Start()
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				Label label = MakeLabel(((Component)this).gameObject, _canvasObj, Vector2.zero, Centre, Centre);
				_text = label.textComponent;
				((Graphic)_text).raycastTarget = false;
			}

			private void Update()
			{
				//IL_006a: 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_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)anim))
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
				}
				else if (Object.op_Implicit((Object)(object)GameCameras.instance) && Object.op_Implicit((Object)(object)GameCameras.instance.mainCamera))
				{
					((Component)this).transform.position = GameCameras.instance.mainCamera.WorldToScreenPoint(((Component)anim).transform.position) + new Vector3(0f, (float)(offset * 50));
					if (!((Behaviour)anim).enabled || anim.currentClip == null || anim.currentClip.name == "" || !_show)
					{
						_text.text = "";
					}
					else
					{
						_text.text = anim.currentClip.name ?? "";
					}
				}
			}
		}

		public class Label : MonoBehaviour
		{
			public string font = "Perpetua";

			public Text? textComponent;

			private void Start()
			{
				textComponent.font = GetFont(font);
			}
		}

		private static bool _show;

		private static GameObject? _canvasObj;

		private static readonly Vector2 Centre = new Vector2(0.5f, 0.5f);

		private static readonly Dictionary<string, Font> Fonts = new Dictionary<string, Font>();

		public const string Id = "me.cometcake575.animseer";

		public static string Name => "AnimSeer";

		public static string Version => "1.0.1";

		private void Awake()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin " + Name + " (me.cometcake575.animseer) has loaded!"));
			new Hook((MethodBase)typeof(tk2dSpriteAnimator).GetMethod("Start", BindingFlags.Instance | BindingFlags.NonPublic), (Delegate)new Action<Action<tk2dSpriteAnimator>, tk2dSpriteAnimator>(StartDebug));
			Settings.Init(((BaseUnityPlugin)this).Config);
		}

		private void Update()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(Settings.ToggleKey.Value))
			{
				_show = !_show;
			}
		}

		private static void StartDebug(Action<tk2dSpriteAnimator> orig, tk2dSpriteAnimator self)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			orig(self);
			if (!Object.op_Implicit((Object)(object)((Component)self).GetComponentInParent<HUDCamera>()) && (!Object.op_Implicit((Object)(object)((Component)self).GetComponentInParent<HeroController>()) || Object.op_Implicit((Object)(object)((Component)self).GetComponent<HeroController>())))
			{
				SetupCanvas();
				AnimSeen animSeen = ((Component)self).GetComponentInParent<AnimSeen>();
				if (!Object.op_Implicit((Object)(object)animSeen))
				{
					animSeen = ((Component)self).GetComponentInChildren<AnimSeen>();
				}
				if (!Object.op_Implicit((Object)(object)animSeen))
				{
					animSeen = ((Component)self).gameObject.AddComponent<AnimSeen>();
				}
				animSeen.scanned++;
				GameObject val = new GameObject("[AnimSeer] " + ((Object)self).name + " Debug");
				val.transform.parent = _canvasObj.transform;
				AnimSeer animSeer = val.AddComponent<AnimSeer>();
				animSeer.anim = self;
				animSeer.offset = animSeen.scanned;
			}
		}

		private static void SetupCanvas()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)_canvasObj))
			{
				_canvasObj = new GameObject("[AnimSeer] Anim Visualiser Canvas");
				Object.DontDestroyOnLoad((Object)(object)_canvasObj);
				_canvasObj.AddComponent<Canvas>().renderMode = (RenderMode)0;
				_canvasObj.AddComponent<CanvasScaler>().uiScaleMode = (ScaleMode)1;
				_canvasObj.AddComponent<GraphicRaycaster>();
			}
		}

		public static Label MakeLabel(GameObject gameObject, GameObject parent, Vector2 pos, Vector2 anchorMin, Vector2 anchorMax)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = gameObject.AddComponent<RectTransform>();
			Label label = gameObject.AddComponent<Label>();
			label.textComponent = gameObject.AddComponent<Text>();
			label.textComponent.supportRichText = false;
			label.textComponent.horizontalOverflow = (HorizontalWrapMode)1;
			label.textComponent.fontSize = 10;
			((Component)label).transform.localScale = Vector3.one;
			((Transform)val).SetParent(parent.transform, false);
			((Transform)val).SetAsFirstSibling();
			val.anchorMin = anchorMin;
			val.anchorMax = anchorMax;
			val.anchoredPosition = pos;
			return label;
		}

		public static Font GetFont(string fontName)
		{
			if (Fonts.TryGetValue(fontName, out Font value))
			{
				return value;
			}
			Font[] array = Resources.FindObjectsOfTypeAll<Font>();
			foreach (Font val in array)
			{
				if (((Object)val).name == fontName)
				{
					Fonts[fontName] = val;
					return val;
				}
			}
			return Fonts.GetValueOrDefault(fontName);
		}
	}
	public static class Settings
	{
		public static ConfigEntry<KeyCode>? ToggleKey;

		public static void Init(ConfigFile config)
		{
			ToggleKey = config.Bind<KeyCode>("States", "ToggleKey", (KeyCode)285, "The keybind used to toggle the AnimSeer info.");
		}
	}
}