Decompiled source of InvisibilityPlugin v1.3.0

InvisibilityPlugin.dll

Decompiled 6 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 Bounce.Unmanaged;
using ModdingTales;
using RadialUI;
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("InvisibilityPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Nth Dimension")]
[assembly: AssemblyProduct("InvisibilityPlugin")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("InvisibilityPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.3.0.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.invisibility", "Invisibility Plug-In", "1.3.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class InvisibilityPlugin : BaseUnityPlugin
{
	public enum VisibleState
	{
		visibleAll,
		visibleOwnerOrGM,
		visibleNot
	}

	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)
				{
					Transform match = null;
					Traverse(((Component)val).transform, "BaseLoader", 0, 10, ref match);
					if ((Object)(object)match != (Object)null)
					{
						return ((Component)match.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;
					Traverse(((Component)val).transform, "AssetLoader", 0, 10, ref match);
					if ((Object)(object)match != (Object)null)
					{
						if (match.childCount > 0)
						{
							return ((Component)match.GetChild(0)).gameObject;
						}
						return null;
					}
					return null;
				}
				return null;
			}
			catch
			{
				return null;
			}
		}

		public static void Traverse(Transform root, string seek, int depth, int depthMax, 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))
				{
					if (depth < depthMax)
					{
						Traverse(item, seek, depth + 1, depthMax, ref match);
					}
				}
			}
			catch
			{
			}
		}
	}

	public const string Name = "Invisibility Plug-In";

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

	public const string Version = "1.3.0.0";

	public const string Author = "Lord Ashes";

	private Dictionary<CreatureGuid, Texture> invisible = new Dictionary<CreatureGuid, Texture>();

	private Guid subscription = System.Guid.Empty;

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

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

	public void HandleRequest(DatumChange change)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		string[] obj = new string[8] { "Change For ", change.source, ", Type: ", null, null, null, null, null };
		ChangeAction action = change.action;
		obj[3] = ((object)(ChangeAction)(ref action)).ToString();
		obj[4] = ", From: ";
		obj[5] = change.previous?.ToString();
		obj[6] = ", To: ";
		obj[7] = change.value?.ToString();
		LoggingPlugin.LogInfo(string.Concat(obj));
		ApplyVisibility(change);
	}

	private void ApplyVisibility(DatumChange change)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: 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_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Invalid comparison between Unknown and I4
		//IL_0149: 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_0169: 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_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0298: Unknown result type (might be due to invalid IL or missing references)
		CreatureBoardAsset val = default(CreatureBoardAsset);
		CreaturePresenter.TryGetAsset(new CreatureGuid(change.source), ref val);
		if (!((Object)(object)val != (Object)null))
		{
			return;
		}
		string[] obj = new string[8] { "Creature : ", val.Name, " : ", null, null, null, null, null };
		CreatureGuid creatureId = val.CreatureId;
		obj[3] = ((object)(CreatureGuid)(ref creatureId)).ToString();
		obj[4] = " : ";
		ChangeAction action = change.action;
		obj[5] = ((object)(ChangeAction)(ref action)).ToString();
		obj[6] = " : Controlled? ";
		obj[7] = LocalClient.HasControlOfCreature(new CreatureGuid(change.source)).ToString();
		LoggingPlugin.LogDebug(string.Concat(obj));
		VisibleState visibleState = VisibleState.visibleNot;
		if ((int)change.action == 1)
		{
			visibleState = VisibleState.visibleAll;
			if (invisible.ContainsKey(new CreatureGuid(change.source)))
			{
				LoggingPlugin.LogDebug("Restoring Base Loader Texture");
				((Renderer)Utility.GetBaseLoader(val.CreatureId).GetComponent<MeshRenderer>()).material.mainTexture = invisible[new CreatureGuid(change.source)];
				Debug.Log((object)"Removing Mini From Invisibility List");
				invisible.Remove(new CreatureGuid(change.source));
			}
		}
		else
		{
			if (LocalClient.HasControlOfCreature(new CreatureGuid(change.source)))
			{
				visibleState = VisibleState.visibleOwnerOrGM;
			}
			if (!invisible.ContainsKey(new CreatureGuid(change.source)))
			{
				LoggingPlugin.LogDebug("Storing Base Loader Texture");
				try
				{
					invisible.Add(new CreatureGuid(change.source), ((Renderer)Utility.GetBaseLoader(val.CreatureId).GetComponent<MeshRenderer>()).material.mainTexture);
				}
				catch (Exception)
				{
					Debug.Log((object)"Mini Not Yet Ready");
					AssetDataPlugin.Reset("org.lordashes.plugins.invisibility");
					return;
				}
			}
			LoggingPlugin.LogDebug("Changing Base Loader Texture");
			((Renderer)Utility.GetBaseLoader(val.CreatureId).GetComponent<MeshRenderer>()).material.mainTexture = (Texture)(object)Image.LoadTexture("org.lordashes.plugins.invisibility\\Invisibility.png", (CacheType)999);
		}
		Debug.Log((object)"Getting Renderer");
		Renderer componentInChildren = (Renderer)(object)Utility.GetAssetLoader(val.CreatureId).GetComponentInChildren<MeshRenderer>();
		if ((Object)(object)componentInChildren == (Object)null)
		{
			componentInChildren = (Renderer)(object)Utility.GetAssetLoader(val.CreatureId).GetComponentInChildren<SkinnedMeshRenderer>();
		}
		if ((Object)(object)componentInChildren != (Object)null)
		{
			LoggingPlugin.LogDebug("Turned " + ((object)componentInChildren).GetType().ToString() + " To " + visibleState);
			componentInChildren.enabled = visibleState != VisibleState.visibleNot;
			componentInChildren = (Renderer)(object)Utility.GetBaseLoader(val.CreatureId).GetComponentInChildren<MeshRenderer>();
			componentInChildren.enabled = visibleState != VisibleState.visibleNot;
		}
		else
		{
			LoggingPlugin.LogDebug("Could Not Find Renderer To Turn On For " + val.Name);
		}
		LoggingPlugin.LogDebug("Getting Indicator Renderer");
		MeshRenderer[] componentsInChildren = Utility.GetBaseLoader(val.CreatureId).GetComponentsInChildren<MeshRenderer>();
		MeshRenderer[] array = componentsInChildren;
		foreach (MeshRenderer val2 in array)
		{
			if (((Object)val2).name == "Indicator")
			{
				LoggingPlugin.LogDebug("Turned Indicator To " + visibleState);
				((Renderer)val2).enabled = visibleState != VisibleState.visibleNot;
				break;
			}
		}
	}

	private void SetRequest(CreatureGuid cid)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		if (!invisible.ContainsKey(cid))
		{
			AssetDataPlugin.SetInfo(((object)(CreatureGuid)(ref cid)).ToString(), "org.lordashes.plugins.invisibility", "Invisible", false);
		}
		else
		{
			AssetDataPlugin.ClearInfo(((object)(CreatureGuid)(ref cid)).ToString(), "org.lordashes.plugins.invisibility", false);
		}
	}

	private void Awake()
	{
		//IL_002d: 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_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: 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_00ba: 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)
		//IL_0188: Expected O, but got Unknown
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Expected O, but got Unknown
		LoggingPlugin.LogInfo("I'm Ready To Make Minis Disappear.");
		triggerInvisibility = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Toggle Invisibility", new KeyboardShortcut((KeyCode)105, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), (ConfigDescription)null);
		triggerRefresh = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "Refresh", new KeyboardShortcut((KeyCode)105, (KeyCode[])(object)new KeyCode[1] { (KeyCode)305 }), (ConfigDescription)null);
		if (((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Move Original Hide To GM Menu", false, (ConfigDescription)null).Value)
		{
			RadialUIPlugin.HideDefaultCharacterMenuItem("org.lordashes.plugins.invisibility.hideGMHide", "Hide", (ShouldShowMenu)null);
			RadialUIPlugin.AddCustomButtonGMSubmenu("org.lordashes.plugins.invisibility.addGMHide", new ItemArgs
			{
				Title = "GM Hide",
				Icon = Image.LoadSprite("Hide.png", (CacheType)999),
				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)
					//IL_0035: Unknown result type (might be due to invalid IL or missing references)
					//IL_003a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0069: Unknown result type (might be due to invalid IL or missing references)
					CreatureBoardAsset val2 = default(CreatureBoardAsset);
					CreaturePresenter.TryGetAsset(new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature()), ref val2);
					string[] obj4 = new string[5] { "GM Hiding ", val2.Name, " (", null, null };
					CreatureGuid creatureId2 = val2.CreatureId;
					obj4[3] = ((object)(CreatureGuid)(ref creatureId2)).ToString();
					obj4[4] = ")";
					LoggingPlugin.LogInfo(string.Concat(obj4));
					if ((Object)(object)val2 != (Object)null)
					{
						CreatureManager.SetCreatureExplicitHideState(val2.CreatureId, !val2.IsExplicitlyHidden);
					}
				},
				CloseMenuOnActivate = true
			}, (Func<NGuid, NGuid, bool>)((NGuid m, NGuid r) => true));
		}
		RadialUIPlugin.AddCustomButtonOnCharacter("org.lordashes.plugins.invisibility.addPCHide", new ItemArgs
		{
			Title = "PC Hide",
			Icon = Image.LoadSprite("Hide.png", (CacheType)999),
			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)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: 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)
				CreatureBoardAsset val = default(CreatureBoardAsset);
				CreaturePresenter.TryGetAsset(new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature()), ref val);
				string[] obj3 = new string[5] { "Player Hiding ", val.Name, " (", null, null };
				CreatureGuid creatureId = val.CreatureId;
				obj3[3] = ((object)(CreatureGuid)(ref creatureId)).ToString();
				obj3[4] = ")";
				LoggingPlugin.LogInfo(string.Concat(obj3));
				if ((Object)(object)val != (Object)null)
				{
					SetRequest(val.CreatureId);
				}
			},
			CloseMenuOnActivate = true
		}, (Func<NGuid, NGuid, bool>)((NGuid m, NGuid r) => LocalClient.CanControlCreature(new CreatureGuid(r))));
		Utility.PostOnMainPage((BaseUnityPlugin)(object)this);
	}

	private void Update()
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: 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_00e4: 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_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_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Expected O, but got Unknown
		if (Utility.isBoardLoaded())
		{
			if (subscription == System.Guid.Empty)
			{
				LoggingPlugin.LogInfo("Subscribing To Invisibility Plugin Stat Messages...");
				AssetDataPlugin.Reset("org.lordashes.plugins.invisibility");
				subscription = AssetDataPlugin.Subscribe("org.lordashes.plugins.invisibility", (Action<DatumChange>)HandleRequest);
			}
			KeyboardShortcut value = triggerInvisibility.Value;
			if (((KeyboardShortcut)(ref value)).IsUp())
			{
				LoggingPlugin.LogInfo("Toggling Invisibility State...");
				_ = LocalClient.SelectedCreatureId;
				if (true)
				{
					SetRequest(LocalClient.SelectedCreatureId);
				}
			}
			value = triggerRefresh.Value;
			if (!((KeyboardShortcut)(ref value)).IsUp())
			{
				return;
			}
			LoggingPlugin.LogInfo("Refreshing Invisibility States...");
			{
				foreach (CreatureBoardAsset item in (IEnumerable<CreatureBoardAsset>)CreaturePresenter.GetTempReadOnlyViewOfAllCreatureAssets())
				{
					DatumChange val = new DatumChange();
					CreatureGuid creatureId = item.CreatureId;
					val.source = ((object)(CreatureGuid)(ref creatureId)).ToString();
					creatureId = item.CreatureId;
					val.action = (ChangeAction)((!(AssetDataPlugin.ReadInfo(((object)(CreatureGuid)(ref creatureId)).ToString(), "org.lordashes.plugins.invisibility") != "")) ? 1 : 3);
					val.key = "org.lordashes.plugins.invisibility";
					val.value = "Refresh:" + DateTime.UtcNow;
					ApplyVisibility(val);
				}
				return;
			}
		}
		if (subscription != System.Guid.Empty)
		{
			AssetDataPlugin.Unsubscribe(subscription);
			subscription = System.Guid.Empty;
		}
	}

	private void PlayerHide(CreatureGuid cid, string txt, MapMenuItem mmi)
	{
		//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)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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)
		CreatureBoardAsset val = default(CreatureBoardAsset);
		CreaturePresenter.TryGetAsset(new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature()), ref val);
		string[] obj = new string[5] { "Player Hiding ", val.Name, " (", null, null };
		CreatureGuid creatureId = val.CreatureId;
		obj[3] = ((object)(CreatureGuid)(ref creatureId)).ToString();
		obj[4] = ")";
		LoggingPlugin.LogInfo(string.Concat(obj));
		if ((Object)(object)val != (Object)null)
		{
			SetRequest(val.CreatureId);
		}
	}

	private void GMHide(CreatureGuid cid, string txt, MapMenuItem mmi)
	{
		//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)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		CreatureBoardAsset val = default(CreatureBoardAsset);
		CreaturePresenter.TryGetAsset(new CreatureGuid(RadialUIPlugin.GetLastRadialTargetCreature()), ref val);
		string[] obj = new string[5] { "GM Hiding ", val.Name, " (", null, null };
		CreatureGuid creatureId = val.CreatureId;
		obj[3] = ((object)(CreatureGuid)(ref creatureId)).ToString();
		obj[4] = ")";
		LoggingPlugin.LogInfo(string.Concat(obj));
		if ((Object)(object)val != (Object)null)
		{
			CreatureManager.SetCreatureExplicitHideState(val.CreatureId, !val.IsExplicitlyHidden);
		}
	}
}