Decompiled source of WhatchaGotThere v1.0.4

plugins/WhatchaGotThere.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using WhatchaGotThere.Helpers;
using WhatchaGotThere.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("WarperSan")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Shows what equipment an ally is currently holding.")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4+7ad935099797e1506a109149b4d9532be0efa3c0")]
[assembly: AssemblyProduct("WhatchaGotThere")]
[assembly: AssemblyTitle("WhatchaGotThere")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/WarperSan/WhatchaGotThere/")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 WhatchaGotThere
{
	[RequireComponent(typeof(AllyCardController))]
	internal class AllyCardData : MonoBehaviour
	{
		private static readonly Dictionary<AllyCardController, AllyCardData> CachedInstances = new Dictionary<AllyCardController, AllyCardData>();

		public AllyCardController? Controller { get; private set; }

		public EquipmentIcon? EquipmentIcon { get; private set; }

		public EquipmentIndex EquipmentIndex { get; private set; }

		private void Awake()
		{
			Controller = ((Component)this).gameObject.GetComponent<AllyCardController>();
			EquipmentIcon = ((Component)this).gameObject.GetComponentInChildren<EquipmentIcon>();
			EquipmentIndex = (EquipmentIndex)(-1);
			CachedInstances.Add(Controller, this);
		}

		public static bool TryGet(AllyCardController instance, out AllyCardData data)
		{
			return CachedInstances.TryGetValue(instance, out data);
		}

		public void UpdateCache()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Controller != (Object)null)
			{
				EquipmentIndex = Controller.sourceMaster.inventory.currentEquipmentState.equipmentIndex;
			}
			else
			{
				EquipmentIndex = (EquipmentIndex)(-1);
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)Controller != (Object)null)
			{
				CachedInstances.Remove(Controller);
			}
		}
	}
	public static class AllyCardEquipmentIconBuilder
	{
		public static void CreateIcon(Transform transform)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_009c: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_0150: Expected O, but got Unknown
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: 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_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Expected O, but got Unknown
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Expected O, but got Unknown
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("WhatchaGotThere EquipmentSlot", new Type[4]
			{
				typeof(RectTransform),
				typeof(LayoutElement),
				typeof(Image),
				typeof(TooltipProvider)
			});
			val.transform.SetParent(transform, false);
			val.AddComponent<MPEventSystemLocator>();
			val.AddComponent<HGButton>();
			Transform obj = transform.Find("Portrait");
			int num = ((obj != null) ? obj.GetSiblingIndex() : (-1));
			if (num != -1)
			{
				val.transform.SetSiblingIndex(num + 1);
			}
			RectTransform component = val.GetComponent<RectTransform>();
			component.sizeDelta = new Vector2(48f, 48f);
			LayoutElement component2 = val.GetComponent<LayoutElement>();
			Rect rect = component.rect;
			component2.preferredWidth = ((Rect)(ref rect)).width;
			rect = component.rect;
			component2.preferredHeight = ((Rect)(ref rect)).height;
			Image component3 = val.GetComponent<Image>();
			((Graphic)component3).color = Color.clear;
			((Graphic)component3).raycastTarget = false;
			HGButton component4 = val.GetComponent<HGButton>();
			((Selectable)component4).image = component3;
			((MPButton)component4).selectOnPointerEnter = false;
			UIInputPassthrough val2 = val.AddComponent<UIInputPassthrough>();
			val2.OnlyAllowMovement = false;
			EquipmentIcon val3 = val.AddComponent<EquipmentIcon>();
			val3.tooltipProvider = val.GetComponent<TooltipProvider>();
			GameObject val4 = new GameObject("DisplayRoot", new Type[1] { typeof(RectTransform) });
			val4.transform.SetParent(val.transform, false);
			val3.displayRoot = val4;
			RectTransform component5 = val4.GetComponent<RectTransform>();
			component5.anchorMin = Vector2.zero;
			component5.anchorMax = Vector2.one;
			component5.offsetMin = Vector2.zero;
			component5.offsetMax = Vector2.zero;
			GameObject val5 = new GameObject("IconPanel", new Type[2]
			{
				typeof(RectTransform),
				typeof(RawImage)
			});
			val5.transform.SetParent(val4.transform, false);
			val3.iconImage = val5.GetComponent<RawImage>();
			RectTransform component6 = val5.GetComponent<RectTransform>();
			component6.anchorMin = Vector2.zero;
			component6.anchorMax = Vector2.one;
			component6.offsetMin = Vector2.zero;
			component6.offsetMax = Vector2.zero;
			GameObject val6 = new GameObject("Cooldown Text", new Type[2]
			{
				typeof(RectTransform),
				typeof(HGTextMeshProUGUI)
			});
			val6.transform.SetParent(val4.transform, false);
			RectTransform component7 = val6.GetComponent<RectTransform>();
			component7.anchorMin = Vector2.zero;
			component7.anchorMax = Vector2.one;
			component7.offsetMin = Vector2.zero;
			component7.offsetMax = Vector2.zero;
			HGTextMeshProUGUI component8 = val6.GetComponent<HGTextMeshProUGUI>();
			((TMP_Text)component8).alignment = (TextAlignmentOptions)514;
			val3.cooldownText = (TextMeshProUGUI)(object)component8;
		}
	}
	[BepInPlugin("dev.warpersan.whatchagotthere", "WhatchaGotThere", "1.0.4")]
	internal class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			Configuration.Load(((BaseUnityPlugin)this).Config);
			Patch.ApplyAll();
			Log.Info("dev.warpersan.whatchagotthere v1.0.4 has loaded!");
		}

		private void OnDestroy()
		{
			Patch.RevertAll();
			Log.Info("dev.warpersan.whatchagotthere v1.0.4 has unloaded!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "dev.warpersan.whatchagotthere";

		public const string PLUGIN_NAME = "WhatchaGotThere";

		public const string PLUGIN_VERSION = "1.0.4";
	}
}
namespace WhatchaGotThere.Patches
{
	[HarmonyPatch(typeof(AllyCardController))]
	internal static class AllyCardController_Patches
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void Awake_Postfix(AllyCardController __instance)
		{
			AllyCardEquipmentIconBuilder.CreateIcon((Transform)(object)__instance.rectTransform);
			((Component)__instance).gameObject.AddComponent<AllyCardData>();
		}

		[HarmonyPatch("ShouldWeUpdate")]
		[HarmonyPostfix]
		private static void ShouldWeUpdate_Postfix(AllyCardController __instance, ref bool __result)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!__result && AllyCardData.TryGet(__instance, out AllyCardData data))
			{
				EquipmentIndex currentEquipmentIndex = __instance.sourceMaster.inventory.currentEquipmentIndex;
				if (currentEquipmentIndex != data.EquipmentIndex)
				{
					__result = true;
				}
			}
		}

		[HarmonyPatch("UpdateInfo")]
		[HarmonyPostfix]
		private static void UpdateInfo_Postfix(AllyCardController __instance)
		{
			if (!AllyCardData.TryGet(__instance, out AllyCardData data))
			{
				return;
			}
			EquipmentIcon equipmentIcon = data.EquipmentIcon;
			if (!((Object)(object)equipmentIcon == (Object)null))
			{
				data.UpdateCache();
				if (Object.op_Implicit((Object)(object)__instance.sourceMaster))
				{
					bool active = ShouldDisplayUI(__instance.sourceMaster);
					equipmentIcon.targetInventory = __instance.sourceMaster.inventory;
					((Component)equipmentIcon).gameObject.SetActive(active);
				}
			}
		}

		private static bool ShouldDisplayUI(CharacterMaster master)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_0043: 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_0049: 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_0050: Invalid comparison between Unknown and I4
			//IL_0064: 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_006b: Invalid comparison between Unknown and I4
			if ((int)master.inventory.currentEquipmentState.equipmentIndex == -1)
			{
				return false;
			}
			if (Configuration.Instance == null)
			{
				return true;
			}
			Configuration.TargetType value = Configuration.Instance.AllowedTargets.Value;
			if (value == Configuration.TargetType.None)
			{
				return false;
			}
			if (!master.hasBody)
			{
				return false;
			}
			BodyIndex bodyIndex = master.GetBody().bodyIndex;
			if ((int)SurvivorCatalog.GetSurvivorIndexFromBodyIndex(bodyIndex) != -1)
			{
				return value.HasFlag(Configuration.TargetType.Survivors);
			}
			if ((int)DroneCatalog.GetDroneIndexFromBodyIndex(bodyIndex) != -1)
			{
				return value.HasFlag(Configuration.TargetType.Drones);
			}
			if ((Object)(object)master.minionOwnership.ownerMaster != (Object)null)
			{
				return value.HasFlag(Configuration.TargetType.Allies);
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(AllyCardManager))]
	internal static class AllyCardManager_Patches
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void Awake_Postfix(AllyCardManager __instance)
		{
			Canvas componentInParent = ((Component)((Component)__instance).transform).GetComponentInParent<Canvas>();
			if (!((Object)(object)componentInParent == (Object)null) && !((Object)(object)((Component)componentInParent).gameObject.GetComponent<GraphicRaycaster>() != (Object)null))
			{
				((Component)componentInParent).gameObject.AddComponent<GraphicRaycaster>();
			}
		}
	}
}
namespace WhatchaGotThere.Helpers
{
	internal class Configuration
	{
		[Flags]
		public enum TargetType : byte
		{
			None = 0,
			Survivors = 1,
			Drones = 2,
			Allies = 4,
			All = 7
		}

		private const string SECTION = "Mod";

		public readonly ConfigEntry<TargetType> AllowedTargets;

		public static Configuration? Instance;

		private Configuration(ConfigFile cfg)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_002d: Expected O, but got Unknown
			AllowedTargets = cfg.Bind<TargetType>(new ConfigDefinition("Mod", "AllowedTargets"), TargetType.All, new ConfigDescription("Determines who can display their equipment.", (AcceptableValueBase)null, Array.Empty<object>()));
		}

		public static void Load(ConfigFile cfg)
		{
			Instance = new Configuration(cfg);
		}
	}
	internal static class Log
	{
		private static ManualLogSource? _logger;

		private static void LogSelf(string message, LogLevel level)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (_logger == null)
			{
				_logger = Logger.CreateLogSource("WhatchaGotThere");
			}
			ManualLogSource? logger = _logger;
			if (logger != null)
			{
				logger.Log(level, (object)message);
			}
		}

		public static void Debug(string message)
		{
			LogSelf(message, (LogLevel)32);
		}

		public static void Info(string message)
		{
			LogSelf(message, (LogLevel)8);
		}

		public static void Warning(string message)
		{
			LogSelf(message, (LogLevel)4);
		}

		public static void Error(string message)
		{
			LogSelf(message, (LogLevel)2);
		}
	}
	internal static class Patch
	{
		private static Harmony? _harmony;

		public static void ApplyAll()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			if (_harmony != null)
			{
				Log.Debug("Unpatching the existing harmony instance.");
				RevertAll();
			}
			_harmony = new Harmony("dev.warpersan.whatchagotthere");
			_harmony.PatchAll(typeof(AllyCardController_Patches));
			_harmony.PatchAll(typeof(AllyCardManager_Patches));
			Log.Debug("All patches applied.");
		}

		public static void RevertAll()
		{
			if (_harmony != null)
			{
				_harmony.UnpatchSelf();
				_harmony = null;
				Log.Debug("All patches reverted.");
			}
		}
	}
}