Decompiled source of HideBasePlugin v1.3.0

HideBasePlugin.dll

Decompiled 2 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 BepInEx;
using BepInEx.Configuration;
using Bounce.Singletons;
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("HideBasePlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HideBasePlugin")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("HideBasePlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.3.0.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.hidebase", "Hide Base Plug-In", "1.3.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class HideBasePlugin : BaseUnityPlugin
{
	public static class Utility
	{
		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);
				}
			};
		}

		public static bool isBoardLoaded()
		{
			return SimpleSingletonBehaviour<CameraController>.HasInstance && SingletonStateMBehaviour<BoardSessionManager, State<BoardSessionManager>>.HasInstance && !BoardSessionManager.IsLoading;
		}

		public static bool StrictKeyCheck(KeyboardShortcut check)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			if (!((KeyboardShortcut)(ref check)).IsUp())
			{
				return false;
			}
			KeyCode[] array = new KeyCode[6];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			KeyCode[] array2 = (KeyCode[])(object)array;
			foreach (KeyCode val in array2)
			{
				if (Input.GetKey(val) != ((KeyboardShortcut)(ref check)).Modifiers.Contains(val))
				{
					return false;
				}
			}
			return true;
		}

		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;
		}

		public static string GetCreatureName(string name)
		{
			if (name.Contains("<"))
			{
				name = name.Substring(0, name.IndexOf("<"));
			}
			return name;
		}

		public static GameObject GetBaseLoader(CreatureGuid cid)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			CreatureBoardAsset val = null;
			CreaturePresenter.TryGetAsset(cid, ref val);
			if ((Object)(object)val != (Object)null)
			{
				CreatureBase match = null;
				StartWith(val, "_base", ref match);
				Transform match2 = null;
				Traverse(((Component)match).transform, "BaseLoader", ref match2);
				if ((Object)(object)match2 != (Object)null)
				{
					return ((Component)match2.GetChild(0)).gameObject;
				}
				Debug.LogWarning((object)"Light Plugin: Could Not Find Base Loader");
				return null;
			}
			return null;
		}

		public static GameObject GetAssetLoader(CreatureGuid cid)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			CreatureBoardAsset val = null;
			CreaturePresenter.TryGetAsset(cid, ref val);
			if ((Object)(object)val != (Object)null)
			{
				Transform match = null;
				StartWith(val, "_creatureRoot", ref match);
				Transform match2 = null;
				Traverse(match, "AssetLoader", ref match2);
				if ((Object)(object)match2 != (Object)null)
				{
					return ((Component)match2.GetChild(0)).gameObject;
				}
				Debug.LogWarning((object)"Light Plugin: Could Not Find Asset Loader");
				return null;
			}
			return null;
		}

		public static void StartWith<T>(CreatureBoardAsset asset, string seek, ref T match)
		{
			Type typeFromHandle = typeof(CreatureBoardAsset);
			match = default(T);
			foreach (FieldInfo runtimeField in typeFromHandle.GetRuntimeFields())
			{
				if (runtimeField.Name == seek)
				{
					match = (T)runtimeField.GetValue(asset);
					break;
				}
			}
		}

		public static void Traverse(Transform root, string seek, ref Transform match, string path = "")
		{
			path = path + ((Object)root).name + ".";
			Debug.Log((object)("Light Plugin: Found '" + path + "' (with " + root.childCount + " Children)"));
			if ((Object)(object)match != (Object)null)
			{
				return;
			}
			if (Convert.ToString(((Object)root).name) == Convert.ToString(seek))
			{
				match = root;
				return;
			}
			foreach (Transform item in ExtensionMethods.Children(root))
			{
				Traverse(item, seek, ref match, path);
				if ((Object)(object)match != (Object)null)
				{
					break;
				}
			}
		}

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

	public const string Name = "Hide Base Plug-In";

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

	public const string Version = "1.3.0.0";

	private static List<Tuple<CreatureGuid, bool>> backlog = new List<Tuple<CreatureGuid, bool>>();

	private ConfigEntry<KeyboardShortcut> triggerKey { get; set; }

	private ConfigEntry<bool> addDiagnostoicsToLog { get; set; }

	private void Awake()
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		Debug.Log((object)("Hide Base Plugin: " + ((object)this).GetType().AssemblyQualifiedName + " Active."));
		triggerKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Toggle Base Vilibility", new KeyboardShortcut((KeyCode)118, (KeyCode[])(object)new KeyCode[1] { (KeyCode)307 }), (ConfigDescription)null);
		ConfigEntry<string> val = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Remove If Mini Fails N Times", "Unused", (ConfigDescription)null);
		val.Value = "Unused";
		((BaseUnityPlugin)this).Config.Save();
		addDiagnostoicsToLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Log Diagnostics", true, (ConfigDescription)null);
		AssetDataPlugin.Subscribe("org.lordashes.plugins.hidebase", (Action<DatumChange>)delegate(DatumChange obj)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			ChangeAction action = obj.action;
			ChangeAction val2 = action;
			if ((int)val2 != -1)
			{
				if ((int)val2 == 1)
				{
					if (addDiagnostoicsToLog.Value)
					{
						Debug.Log((object)("Hide Base Plugin: Queue Base Show For Creature " + obj.source));
					}
					ProcessBaseRequest(new CreatureGuid(obj.source), showBase: true);
				}
				else
				{
					if (addDiagnostoicsToLog.Value)
					{
						Debug.Log((object)("Hide Base Plugin: Queue Base " + (Convert.ToBoolean(obj.value) ? "Show" : "Hide") + " For Creature " + obj.source));
					}
					ProcessBaseRequest(new CreatureGuid(obj.source), Convert.ToBoolean(obj.value));
				}
			}
		}, (Func<DatumChange, bool>)Checker.CheckSourceAsCreature);
		Utility.PostOnMainPage(((object)this).GetType());
	}

	private void Update()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: 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)
		if (!Utility.isBoardLoaded() || !Utility.StrictKeyCheck(triggerKey.Value))
		{
			return;
		}
		if (addDiagnostoicsToLog.Value)
		{
			Debug.Log((object)"Hide Base Plugin: Toggle Base");
		}
		try
		{
			GameObject gameObject = Utility.GetBaseLoader(LocalClient.SelectedCreatureId).gameObject;
			Renderer component = gameObject.GetComponent<Renderer>();
			bool enabled = component.enabled;
			CreatureGuid selectedCreatureId;
			if (addDiagnostoicsToLog.Value)
			{
				selectedCreatureId = LocalClient.SelectedCreatureId;
				Debug.Log((object)("Hide Base Plugin: Requesting Creature '" + ((object)(CreatureGuid)(ref selectedCreatureId)).ToString() + "' Base To Show = " + !enabled));
			}
			selectedCreatureId = LocalClient.SelectedCreatureId;
			AssetDataPlugin.SetInfo(((object)(CreatureGuid)(ref selectedCreatureId)).ToString(), "org.lordashes.plugins.hidebase", (object)(!enabled), false);
		}
		catch (Exception)
		{
			SystemMessage.DisplayInfoText("Hide Base Function Requires Selected Asset", 2.5f);
		}
	}

	private bool ProcessBaseRequest(CreatureGuid cid, bool showBase)
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (addDiagnostoicsToLog.Value)
			{
				Debug.Log((object)("Hide Base Plugin: Setting Creature '" + ((object)(CreatureGuid)(ref cid)).ToString() + "' Base To: Show = " + showBase));
			}
			GameObject gameObject = Utility.GetBaseLoader(cid).gameObject;
			Renderer[] components = gameObject.GetComponents<Renderer>();
			Renderer[] array = components;
			foreach (Renderer val in array)
			{
				if (addDiagnostoicsToLog.Value)
				{
					Debug.Log((object)("Hide Base Plugin: Setting Creature '" + ((object)(CreatureGuid)(ref cid)).ToString() + "' Base Renderer '" + ((Object)val).name + "' To Enabled = " + showBase));
				}
				val.enabled = showBase;
			}
			CreatureBoardAsset val2 = null;
			CreaturePresenter.TryGetAsset(cid, ref val2);
			if ((Object)(object)val2 != (Object)null)
			{
				CreatureBase match = null;
				Utility.StartWith(val2, "_base", ref match);
				Transform match2 = null;
				Utility.Traverse(((Component)match).transform, "Indicator", ref match2);
				gameObject = ((Component)match2).gameObject;
				components = gameObject.GetComponents<Renderer>();
				Renderer[] array2 = components;
				foreach (Renderer val3 in array2)
				{
					if (addDiagnostoicsToLog.Value)
					{
						Debug.Log((object)("Hide Base Plugin: Setting Creature '" + ((object)(CreatureGuid)(ref cid)).ToString() + "' Indicator Renderer '" + ((Object)val3).name + "' To Enabled = " + showBase));
					}
					val3.enabled = showBase;
				}
			}
			return true;
		}
		catch
		{
			if (addDiagnostoicsToLog.Value)
			{
				Debug.Log((object)("Hide Base Plugin: Creature '" + ((object)(CreatureGuid)(ref cid)).ToString() + "' Has Not Fully Loaded"));
			}
			return false;
		}
	}
}