Decompiled source of AnimateMenuPlugin v1.2.0

AnimateMenuPlugin.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using Bounce.Singletons;
using Bounce.Unmanaged;
using Newtonsoft.Json;
using RadialUI;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AnimateMenuPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AnimateMenuPlugin")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("AnimateMenuPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.2.0.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.animatemenu", "Animate Menu Plug-In", "1.2.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class AnimateMenuPlugin : BaseUnityPlugin
{
	public static class Utility
	{
		public static bool isBoardLoaded()
		{
			return SimpleSingletonBehaviour<CameraController>.HasInstance && SingletonStateMBehaviour<BoardSessionManager, State<BoardSessionManager>>.HasInstance && !BoardSessionManager.IsLoading;
		}

		public static Guid GuidFromString(string input)
		{
			using MD5 mD = MD5.Create();
			byte[] b = mD.ComputeHash(Encoding.Default.GetBytes(input));
			return new Guid(b);
		}

		public static float ParseFloat(string value)
		{
			return float.Parse(value, CultureInfo.InvariantCulture);
		}

		public static string GetCreatureName(string nameBlock)
		{
			if (nameBlock == null)
			{
				return "(Unknown)";
			}
			if (!nameBlock.Contains("<size=0>"))
			{
				return nameBlock;
			}
			return nameBlock.Substring(0, nameBlock.IndexOf("<size=0>")).Trim();
		}

		public static void PostOnMainPage(MemberInfo plugin)
		{
			SceneManager.sceneLoaded += delegate(Scene scene, LoadSceneMode mode)
			{
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Expected O, but got Unknown
				try
				{
					if (((Scene)(ref scene)).name == "UI")
					{
						TextMeshProUGUI uITextByName = GetUITextByName("BETA");
						if (Object.op_Implicit((Object)(object)uITextByName))
						{
							((TMP_Text)uITextByName).text = "INJECTED BUILD - unstable mods";
						}
					}
					else
					{
						TextMeshProUGUI uITextByName2 = GetUITextByName("TextMeshPro Text");
						if (Object.op_Implicit((Object)(object)uITextByName2))
						{
							BepInPlugin val = (BepInPlugin)Attribute.GetCustomAttribute(plugin, typeof(BepInPlugin));
							if (((TMP_Text)uITextByName2).text.EndsWith("</size>"))
							{
								((TMP_Text)uITextByName2).text = ((TMP_Text)uITextByName2).text + "\n\nMods Currently Installed:\n";
							}
							TextMeshProUGUI val2 = uITextByName2;
							((TMP_Text)val2).text = ((TMP_Text)val2).text + "\nLord Ashes' " + val.Name + " - " + val.Version;
						}
					}
				}
				catch (Exception ex)
				{
					Debug.Log((object)ex);
				}
			};
		}

		private static TextMeshProUGUI GetUITextByName(string name)
		{
			TextMeshProUGUI[] array = Object.FindObjectsOfType<TextMeshProUGUI>();
			for (int i = 0; i < array.Length; i++)
			{
				if (((Object)array[i]).name == name)
				{
					return array[i];
				}
			}
			return null;
		}
	}

	private class AnimationInfo
	{
		public string name { get; set; } = "Anim";


		public object rigged { get; set; } = null;


		public object blendShape { get; set; } = null;


		public int sound { get; set; } = -1;

	}

	public enum DiagnosticMode
	{
		none,
		low,
		high,
		ultra
	}

	public const string Name = "Animate Menu Plug-In";

	public const string Guid = "org.lordashes.plugins.animatemenu";

	public const string Version = "1.2.0.0";

	public const string Author = "Lord Ashes";

	public static DiagnosticMode diagnostics = DiagnosticMode.low;

	private static Dictionary<BoardObjectGuid, int> animationsForObjectType = new Dictionary<BoardObjectGuid, int>();

	public static Dictionary<BoardObjectGuid, List<ItemArgs>> menuItems = new Dictionary<BoardObjectGuid, List<ItemArgs>>();

	private void Awake()
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: 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)
		//IL_008f: 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)
		//IL_00d3: Expected O, but got Unknown
		diagnostics = ((BaseUnityPlugin)this).Config.Bind<DiagnosticMode>("Troubleshooting", "Amount Of Diagnostic Messages In Logs", DiagnosticMode.low, (ConfigDescription)null).Value;
		Debug.Log((object)("Animate Menu Plugin: " + ((object)this).GetType().AssemblyQualifiedName + " Active. Diagnostic Mode = " + diagnostics));
		RadialUIPlugin.AddCustomButtonOnCharacter("org.lordashes.plugins.animatemenu", new ItemArgs
		{
			Action = delegate
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				openMenu(new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature()));
			},
			CloseMenuOnActivate = false,
			FadeName = true,
			Icon = Image.LoadSprite("org.lordashes.plugins.animatemenu/AnimateMenu.png", (CacheType)999),
			Title = "Animations"
		}, (Func<NGuid, NGuid, bool>)((NGuid selected, NGuid radial) => check(new CreatureGuid(selected), new CreatureGuid(radial))));
		Utility.PostOnMainPage(((object)this).GetType());
	}

	private static void register(CreatureBoardAsset __instance)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Expected O, but got Unknown
		//IL_04d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_049e: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_051f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0529: Unknown result type (might be due to invalid IL or missing references)
		//IL_052e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0541: Unknown result type (might be due to invalid IL or missing references)
		//IL_0548: Unknown result type (might be due to invalid IL or missing references)
		//IL_054f: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c4: Expected O, but got Unknown
		BoardObjectGuid boardObjectId;
		CreatureGuid creatureId;
		if (diagnostics >= DiagnosticMode.high)
		{
			boardObjectId = __instance.BoardObjectId;
			string? text = ((object)(BoardObjectGuid)(ref boardObjectId)).ToString();
			creatureId = __instance.CreatureId;
			Debug.Log((object)("Animate Menu Plugin: Registering Animations From Object Type " + text + " Based On Mini " + ((object)(CreatureGuid)(ref creatureId)).ToString()));
		}
		string text2 = "";
		if (diagnostics >= DiagnosticMode.ultra)
		{
			string[] obj = new string[5] { "Animate Menu Plugin: Animate File For Asset '", null, null, null, null };
			creatureId = __instance.CreatureId;
			obj[1] = ((object)(CreatureGuid)(ref creatureId)).ToString();
			obj[2] = "' Is '";
			boardObjectId = __instance.BoardObjectId;
			obj[3] = ((object)(BoardObjectGuid)(ref boardObjectId)).ToString();
			obj[4] = ".Animate'";
			Debug.Log((object)string.Concat(obj));
		}
		try
		{
			boardObjectId = __instance.BoardObjectId;
			text2 = File.Find(((object)(BoardObjectGuid)(ref boardObjectId)).ToString() + ".Animate", (CacheType)999)[0];
		}
		catch
		{
		}
		List<AnimationInfo> list = new List<AnimationInfo>();
		if (text2 != null && text2 != "")
		{
			if (diagnostics >= DiagnosticMode.ultra)
			{
				Debug.Log((object)("Animate Menu Plugin: Using File " + text2 + " For Animation List"));
			}
			list = JsonConvert.DeserializeObject<List<AnimationInfo>>(File.ReadAllText(text2, (CacheType)999));
		}
		else
		{
			if (diagnostics >= DiagnosticMode.ultra)
			{
				Debug.Log((object)"Animate Menu Plugin: Extracting Animation From Asset");
			}
			Animation componentInChildren = ((Component)__instance).GetComponentInChildren<Animation>();
			if (!((Object)(object)componentInChildren != (Object)null))
			{
				if (diagnostics >= DiagnosticMode.ultra)
				{
					Debug.Log((object)"Animate Menu Plugin: Asset Has No Animations");
				}
				return;
			}
			int num = 0;
			foreach (AnimationState item in componentInChildren)
			{
				AnimationState val = item;
				if (diagnostics >= DiagnosticMode.ultra)
				{
					Debug.Log((object)("Animate Menu Plugin: Found '" + val.name + "'"));
				}
				num++;
				list.Add(new AnimationInfo
				{
					name = val.name,
					rigged = val.name,
					sound = 0
				});
			}
		}
		if (diagnostics >= DiagnosticMode.ultra)
		{
			Debug.Log((object)"Animate Menu Plugin: Sorting Animation Items By Name");
		}
		list = list.OrderBy((AnimationInfo n) => n.name).ToList();
		foreach (AnimationInfo anim in list)
		{
			string name = anim.name;
			if (anim.rigged != null && anim.rigged.ToString() != "" && anim.blendShape != null)
			{
				name = name + " (LCTRL+" + anim.rigged?.ToString() + " & LALT+" + anim.blendShape?.ToString() + ")";
			}
			else if (anim.rigged != null && anim.rigged.ToString() != "")
			{
				name = name + " (LCTRL+" + anim.rigged?.ToString() + ")";
			}
			else if (anim.blendShape != null)
			{
				name = name + " (LALT+" + anim.blendShape?.ToString() + ")";
			}
			if (diagnostics >= DiagnosticMode.ultra)
			{
				string[] obj3 = new string[5] { "Animate Menu Plugin: Storing Animation Item '", anim.name, "' For Object Typpe '", null, null };
				boardObjectId = __instance.BoardObjectId;
				obj3[3] = ((object)(BoardObjectGuid)(ref boardObjectId)).ToString();
				obj3[4] = "'";
				Debug.Log((object)string.Concat(obj3));
			}
			if (!menuItems.ContainsKey(__instance.BoardObjectId))
			{
				menuItems.Add(__instance.BoardObjectId, new List<ItemArgs>());
			}
			menuItems[__instance.BoardObjectId].Add(new ItemArgs
			{
				Action = delegate
				{
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					callback(__instance.CreatureId, anim);
				},
				CloseMenuOnActivate = true,
				FadeName = true,
				Icon = (File.Exists("org.lordashes.plugins.animatemenu/" + anim.name + ".png") ? Image.LoadSprite("org.lordashes.plugins.animatemenu/" + anim.name + ".png", (CacheType)999) : Image.LoadSprite("org.lordashes.plugins.animatemenu/AnimateMenu.png", (CacheType)999)),
				Title = anim.name
			});
		}
		if (diagnostics >= DiagnosticMode.ultra)
		{
			Debug.Log((object)("Animate Menu Plugin: Added " + list.Count + " Animations"));
		}
	}

	private static void openMenu(CreatureGuid cid)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		if (diagnostics >= DiagnosticMode.high)
		{
			Debug.Log((object)"Animate Menu Plugin: Opening Animations Sub Menu");
		}
		CreatureBoardAsset val = null;
		CreaturePresenter.TryGetAsset(cid, ref val);
		if (!((Object)(object)val != (Object)null))
		{
			return;
		}
		BoardObjectGuid boardObjectId;
		if (diagnostics >= DiagnosticMode.high)
		{
			string[] obj = new string[5] { "Animate Menu Plugin: Obtained Radial Mini ", null, null, null, null };
			CreatureGuid creatureId = val.CreatureId;
			obj[1] = ((object)(CreatureGuid)(ref creatureId)).ToString();
			obj[2] = " (Type ";
			boardObjectId = val.BoardObjectId;
			obj[3] = ((object)(BoardObjectGuid)(ref boardObjectId)).ToString();
			obj[4] = ")";
			Debug.Log((object)string.Concat(obj));
		}
		MapMenu val2 = MapMenuManager.OpenMenu(((Component)RadialMenus.GetTargetCreature()).transform.position + Vector3.up * RadialMenus.GetHeightDiff(), true);
		if (!menuItems.ContainsKey(val.BoardObjectId))
		{
			return;
		}
		if (diagnostics >= DiagnosticMode.high)
		{
			boardObjectId = val.BoardObjectId;
			Debug.Log((object)("Animate Menu Plugin: Animations Found For Object Type " + ((object)(BoardObjectGuid)(ref boardObjectId)).ToString()));
		}
		foreach (ItemArgs item in menuItems[val.BoardObjectId])
		{
			if (diagnostics >= DiagnosticMode.high)
			{
				Debug.Log((object)("Animate Menu Plugin: Added Animation " + item.Title));
			}
			val2.AddItem(item);
		}
	}

	private static void callback(CreatureGuid animationItemOwnerGuid, AnimationInfo anim)
	{
		if (diagnostics >= DiagnosticMode.low)
		{
			Debug.Log((object)("Animate Menu Plugin: Requesting Animation " + JsonConvert.SerializeObject((object)anim)));
		}
		if (anim.rigged != null)
		{
			if (diagnostics >= DiagnosticMode.ultra)
			{
				Debug.Log((object)("Animate Menu Plugin: Requesting Animation Index " + anim.rigged?.ToString() + " For Creature " + ((object)(CreatureGuid)(ref animationItemOwnerGuid)).ToString()));
			}
			AssetDataPlugin.SetInfo(((object)(CreatureGuid)(ref animationItemOwnerGuid)).ToString(), "org.lordashes.plugins.customassetslibraryintegratedextension.animate", anim.rigged.ToString(), false);
		}
		if (anim.blendShape != null)
		{
			if (diagnostics >= DiagnosticMode.ultra)
			{
				Debug.Log((object)("Animate Menu Plugin: Requesting Animation Index " + anim.blendShape?.ToString() + " For Creature " + ((object)(CreatureGuid)(ref animationItemOwnerGuid)).ToString()));
			}
			AssetDataPlugin.SetInfo(((object)(CreatureGuid)(ref animationItemOwnerGuid)).ToString(), "org.lordashes.plugins.customassetslibraryintegratedextension.blendshape", anim.blendShape.ToString(), false);
		}
		if (anim.sound != -1)
		{
			if (diagnostics >= DiagnosticMode.ultra)
			{
				Debug.Log((object)("Animate Menu Plugin: Requesting Sound " + anim.sound + " For Creature " + ((object)(CreatureGuid)(ref animationItemOwnerGuid)).ToString()));
			}
			AssetDataPlugin.SetInfo(((object)(CreatureGuid)(ref animationItemOwnerGuid)).ToString(), "org.lordashes.plugins.customassetslibraryintegratedextension.audio", (object)anim.sound, false);
		}
	}

	private static bool check(CreatureGuid selected, CreatureGuid radial)
	{
		//IL_0043: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		if (diagnostics >= DiagnosticMode.ultra)
		{
			Debug.Log((object)("Animate Menu Plugin: Main Menu Check. Selected=" + ((object)(CreatureGuid)(ref selected)).ToString() + ", Radial=" + ((object)(CreatureGuid)(ref radial)).ToString()));
		}
		CreatureBoardAsset val = null;
		CreaturePresenter.TryGetAsset(radial, ref val);
		if ((Object)(object)val != (Object)null)
		{
			if (diagnostics >= DiagnosticMode.ultra)
			{
				Debug.Log((object)"Animate Menu Plugin: Radial Asset Found");
			}
			if (!menuItems.ContainsKey(val.BoardObjectId))
			{
				if (diagnostics >= DiagnosticMode.ultra)
				{
					Debug.Log((object)"Animate Menu Plugin: Registering Animations");
				}
				register(val);
			}
			if (menuItems.ContainsKey(val.BoardObjectId) && menuItems[val.BoardObjectId].Count > 0)
			{
				if (diagnostics >= DiagnosticMode.ultra)
				{
					Debug.Log((object)"Animate Menu Plugin: Animations Found");
				}
				return true;
			}
			if (diagnostics >= DiagnosticMode.ultra)
			{
				Debug.Log((object)"Animate Menu Plugin: Animations Not Found");
			}
		}
		return false;
	}
}