Decompiled source of WhatchaGotThere v1.0.5

plugins/WhatchaGotThere.dll

Decompiled a month 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 JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using WhatchaGotThere.API;
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.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5+1db30b3472c1571122d466ac69589d5b8e4a8d72")]
[assembly: AssemblyProduct("WhatchaGotThere")]
[assembly: AssemblyTitle("WhatchaGotThere")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/WarperSan/WhatchaGotThere/")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	[Embedded]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	[Embedded]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace Microsoft.CodeAnalysis
{
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
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.5")]
	internal class Plugin : BaseUnityPlugin
	{
		public const string Id = "dev.warpersan.whatchagotthere";

		public static string Name => "WhatchaGotThere";

		public static string Version => "1.0.5";

		private void Awake()
		{
			Configuration.Load(((BaseUnityPlugin)this).Config);
			Patch.ApplyAll();
			Log.Info(Name + " v" + Version + " has loaded!");
		}
	}
}
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 = DisplayHandler.IsDisplayed(__instance.sourceMaster);
					equipmentIcon.targetInventory = __instance.sourceMaster.inventory;
					((Component)equipmentIcon).gameObject.SetActive(active);
				}
			}
		}
	}
	[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<bool> UseAllowedTarget;

		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
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_0059: Expected O, but got Unknown
			UseAllowedTarget = cfg.Bind<bool>(new ConfigDefinition("Mod", "UseAllowedTarget"), true, new ConfigDescription("Determines if the allowed targets should be used to determine if the equipment is shown.", (AcceptableValueBase)null, Array.Empty<object>()));
			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("dev.warpersan.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
	{
		public static void ApplyAll()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			Harmony val = new Harmony("dev.warpersan.whatchagotthere");
			val.PatchAll(typeof(AllyCardController_Patches));
			val.PatchAll(typeof(AllyCardManager_Patches));
			Log.Debug("All patches applied.");
		}
	}
}
namespace WhatchaGotThere.API
{
	public static class DisplayHandler
	{
		private static readonly List<Func<CharacterMaster, bool?>> DisplayConditions = new List<Func<CharacterMaster, bool?>>(2) { DisableIfNoEquipment, DisableIfTargetNotAllowed };

		public static bool IsDisplayed(CharacterMaster master)
		{
			foreach (Func<CharacterMaster, bool?> displayCondition in DisplayConditions)
			{
				bool? flag = displayCondition(master);
				if (flag.HasValue)
				{
					return flag.Value;
				}
			}
			return false;
		}

		[PublicAPI]
		public static void AddCondition(Func<CharacterMaster, bool?> condition)
		{
			DisplayConditions.Add(condition);
		}

		private static bool? DisableIfNoEquipment(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
			if ((int)master.inventory.currentEquipmentState.equipmentIndex == -1)
			{
				return false;
			}
			return null;
		}

		private static bool? DisableIfTargetNotAllowed(CharacterMaster master)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0065: Invalid comparison between Unknown and I4
			//IL_007e: 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_0085: Invalid comparison between Unknown and I4
			Configuration instance = Configuration.Instance;
			if (instance == null)
			{
				return null;
			}
			if (!instance.UseAllowedTarget.Value)
			{
				return null;
			}
			Configuration.TargetType value = instance.AllowedTargets.Value;
			if (value == Configuration.TargetType.None)
			{
				return false;
			}
			if (!master.hasBody)
			{
				return null;
			}
			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 null;
		}
	}
}