Decompiled source of HideBasePlugin v1.4.1

HideBasePlugin.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Bounce.Singletons;
using ModdingTales;
using UnityEngine;

[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("Nth Dimension")]
[assembly: AssemblyProduct("HideBasePlugin")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("HideBasePlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.4.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.4.1.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.hidebase", "Hide Base Plug-In", "1.4.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class HideBasePlugin : BaseUnityPlugin
{
	public static class Utility
	{
		public static void PostOnMainPage(BaseUnityPlugin plugin)
		{
			string text = "Lord Ashes" + ("Lord Ashes".ToUpper().EndsWith("S") ? "'" : "'s");
			ModdingUtils.AddPluginToMenuList(plugin, text);
		}

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

		public static GameObject GetBaseLoader(CreatureGuid cid)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				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;
					}
					return null;
				}
				return null;
			}
			catch
			{
				return null;
			}
		}

		public static GameObject GetAssetLoader(CreatureGuid cid)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				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)
					{
						if (match2.childCount > 0)
						{
							return ((Component)match2.GetChild(0)).gameObject;
						}
						return null;
					}
					return null;
				}
				return null;
			}
			catch
			{
				return null;
			}
		}

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

		public static void Traverse(Transform root, string seek, ref Transform match)
		{
			try
			{
				if ((Object)(object)match != (Object)null)
				{
					return;
				}
				if (((Object)root).name == seek)
				{
					match = root;
					return;
				}
				foreach (Transform item in ExtensionMethods.Children(root))
				{
					Traverse(item, seek, ref match);
				}
			}
			catch
			{
			}
		}
	}

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

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

	public const string Version = "1.4.1.0";

	public const string Author = "Lord Ashes";

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

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

	private void Awake()
	{
		//IL_0018: 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)
		LoggingPlugin.SetLogLevel(((BaseUnityPlugin)this).Config.Bind<DiagnosticLevel>("Settings", "Log Level", (DiagnosticLevel)1, (ConfigDescription)null).Value);
		LoggingPlugin.LogInfo(((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);
		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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			ChangeAction action = obj.action;
			ChangeAction val = action;
			if ((int)val != -1)
			{
				if ((int)val == 1)
				{
					LoggingPlugin.LogDebug("Queue Base Show For Creature " + obj.source);
					ProcessBaseRequest(new CreatureGuid(obj.source), showBase: true);
				}
				else
				{
					LoggingPlugin.LogDebug("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((BaseUnityPlugin)(object)this);
	}

	private void Update()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		if (!Utility.isBoardLoaded())
		{
			return;
		}
		KeyboardShortcut value = triggerKey.Value;
		if (((KeyboardShortcut)(ref value)).IsUp())
		{
			LoggingPlugin.LogDebug("Toggle Base");
			try
			{
				GameObject gameObject = Utility.GetBaseLoader(LocalClient.SelectedCreatureId).gameObject;
				Renderer component = gameObject.GetComponent<Renderer>();
				bool enabled = component.enabled;
				CreatureGuid selectedCreatureId = LocalClient.SelectedCreatureId;
				LoggingPlugin.LogDebug("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, 0f);
			}
		}
	}

	private bool ProcessBaseRequest(CreatureGuid cid, bool showBase)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			LoggingPlugin.LogDebug("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)
			{
				LoggingPlugin.LogDebug("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)
				{
					LoggingPlugin.LogDebug("Setting Creature '" + ((object)(CreatureGuid)(ref cid)).ToString() + "' Indicator Renderer '" + ((Object)val3).name + "' To Enabled = " + showBase);
					val3.enabled = showBase;
				}
			}
			return true;
		}
		catch
		{
			LoggingPlugin.LogDebug("Creature '" + ((object)(CreatureGuid)(ref cid)).ToString() + "' Has Not Fully Loaded");
			return false;
		}
	}
}