Decompiled source of TidyAllies v1.0.2

TidyAllies.dll

Decompiled 6 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.UI;
using TMPro;
using TidyAllies.Patches;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Networking;
using UnityEngine.UI;

[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("TidyAllies")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Hides minion ally cards and shows turret health as a filled icon")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+0d3be6b514f5b509d5ab3adf9776db0e23293a19")]
[assembly: AssemblyProduct("TidyAllies")]
[assembly: AssemblyTitle("TidyAllies")]
[assembly: AssemblyVersion("1.0.2.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 TidyAllies
{
	[RequireComponent(typeof(Graphic))]
	internal class CardFade : BaseMeshEffect
	{
		private const float FadeStart = 0.55f;

		public override void ModifyMesh(VertexHelper vh)
		{
			//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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			if (!((UIBehaviour)this).IsActive())
			{
				return;
			}
			Rect rect = ((BaseMeshEffect)this).graphic.rectTransform.rect;
			if (!(((Rect)(ref rect)).width <= 0f))
			{
				UIVertex val = default(UIVertex);
				for (int i = 0; i < vh.currentVertCount; i++)
				{
					vh.PopulateUIVertex(ref val, i);
					float num = Mathf.InverseLerp(((Rect)(ref rect)).xMin, ((Rect)(ref rect)).xMax, val.position.x);
					float num2 = 1f - Mathf.InverseLerp(0.55f, 1f, num);
					Color32 color = val.color;
					color.a = (byte)Mathf.RoundToInt((float)(int)color.a * num2);
					val.color = color;
					vh.SetUIVertex(val, i);
				}
			}
		}
	}
	internal class CardHealthText : MonoBehaviour
	{
		public const float VerticalOffset = 6f;

		private AllyCardController _card;

		private TextMeshProUGUI _text;

		private float _lastCurrent = -1f;

		private float _lastFull = -1f;

		public static void Ensure(AllyCardController card)
		{
			if (!((Object)(object)card == (Object)null) && !((Object)(object)((Component)card).GetComponent<CardHealthText>() != (Object)null))
			{
				CardHealthText cardHealthText = ((Component)card).gameObject.AddComponent<CardHealthText>();
				cardHealthText._card = card;
				cardHealthText.Build();
			}
		}

		private void Build()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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)
			HealthBar healthBar = _card.healthBar;
			if (!((Object)(object)healthBar == (Object)null))
			{
				GameObject val = new GameObject("TidyAlliesHealthText", new Type[1] { typeof(RectTransform) });
				RectTransform component = val.GetComponent<RectTransform>();
				((Transform)component).SetParent(((Component)healthBar).transform, false);
				component.anchorMin = Vector2.zero;
				component.anchorMax = Vector2.one;
				component.offsetMin = Vector2.zero;
				component.offsetMax = Vector2.zero;
				_text = (TextMeshProUGUI)(object)val.AddComponent<HGTextMeshProUGUI>();
				((TMP_Text)_text).alignment = (TextAlignmentOptions)516;
				((TMP_Text)_text).enableWordWrapping = false;
				((Graphic)_text).raycastTarget = false;
				((TMP_Text)_text).overflowMode = (TextOverflowModes)0;
				TextMeshProUGUI nameLabel = _card.nameLabel;
				if ((Object)(object)nameLabel != (Object)null)
				{
					((TMP_Text)_text).font = ((TMP_Text)nameLabel).font;
					((TMP_Text)_text).fontSharedMaterial = ((TMP_Text)nameLabel).fontSharedMaterial;
					((TMP_Text)_text).fontStyle = ((TMP_Text)nameLabel).fontStyle;
				}
				((TMP_Text)_text).fontSize = 15f;
				((TMP_Text)_text).enableAutoSizing = false;
				((TMP_Text)_text).margin = new Vector4(0f, 0f, 4f, 0f);
				component.anchoredPosition = new Vector2(0f, -6f);
			}
		}

		private void LateUpdate()
		{
			if ((Object)(object)_text == (Object)null)
			{
				return;
			}
			HealthComponent val = (((Object)(object)_card.healthBar != (Object)null) ? _card.healthBar.source : null);
			if ((Object)(object)val == (Object)null)
			{
				((Behaviour)_text).enabled = false;
				return;
			}
			((Behaviour)_text).enabled = true;
			float num = Mathf.Ceil(val.combinedHealth);
			float num2 = Mathf.Ceil(val.fullHealth);
			if (num != _lastCurrent || num2 != _lastFull)
			{
				_lastCurrent = num;
				_lastFull = num2;
				float num3 = ((num2 > 0f) ? Mathf.Round(num / num2 * 100f) : 0f);
				((TMP_Text)_text).SetText("{0}/{1} ({2}%)", num, num2, num3);
			}
		}
	}
	internal class CardMinionIcons : MonoBehaviour
	{
		private class MinionIcon
		{
			private readonly RectTransform _root;

			private readonly Image _empty;

			private readonly Image _fill;

			private CharacterMaster _master;

			public MinionIcon(RectTransform parent)
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0067: 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)
				GameObject val = new GameObject("MinionIcon", new Type[1] { typeof(RectTransform) });
				_root = val.GetComponent<RectTransform>();
				((Transform)_root).SetParent((Transform)(object)parent, false);
				_root.anchorMin = new Vector2(0f, 0f);
				_root.anchorMax = new Vector2(0f, 0f);
				_root.pivot = new Vector2(0f, 0f);
				_empty = CreateImage(_root, "Empty");
				_fill = CreateImage(_root, "Fill");
				_fill.type = (Type)3;
				_fill.fillMethod = (FillMethod)1;
				_fill.fillOrigin = 0;
				Unbind();
			}

			private static Image CreateImage(RectTransform parent, string name)
			{
				//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_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: 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)
				GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
				RectTransform component = val.GetComponent<RectTransform>();
				((Transform)component).SetParent((Transform)(object)parent, false);
				component.anchorMin = Vector2.zero;
				component.anchorMax = Vector2.one;
				component.offsetMin = Vector2.zero;
				component.offsetMax = Vector2.zero;
				Image obj = val.AddComponent<Image>();
				((Graphic)obj).raycastTarget = false;
				return obj;
			}

			public void Bind(CharacterMaster master, Vector2 position, float size)
			{
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				_master = master;
				CharacterBody val = (((Object)(object)master != (Object)null) ? master.GetBody() : null);
				Sprite val2 = (((Object)(object)val != (Object)null) ? IconCache.Get(val.portraitIcon) : null);
				if ((Object)(object)val2 == (Object)null)
				{
					Unbind();
					return;
				}
				_empty.sprite = val2;
				_fill.sprite = val2;
				_root.sizeDelta = new Vector2(size, size);
				_root.anchoredPosition = position;
				((Component)_root).gameObject.SetActive(true);
			}

			public void Unbind()
			{
				_master = null;
				((Component)_root).gameObject.SetActive(false);
			}

			public void UpdateHealth()
			{
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)_master == (Object)null) && ((Component)_root).gameObject.activeSelf)
				{
					CharacterBody body = _master.GetBody();
					HealthComponent val = (((Object)(object)body != (Object)null) ? body.healthComponent : null);
					if (!((Object)(object)val == (Object)null) && !(val.fullHealth <= 0f))
					{
						float num = Mathf.Clamp01(val.health / val.fullHealth);
						((Graphic)_empty).color = ModConfig.EmptyColor.Value;
						_fill.fillAmount = num;
						((Graphic)_fill).color = Color.Lerp(ModConfig.LowHealthColor.Value, ModConfig.FillColor.Value, Mathf.InverseLerp(0f, Mathf.Max(0.01f, ModConfig.LowHealthThreshold.Value), num));
					}
				}
			}
		}

		private AllyCardController _card;

		private RectTransform _container;

		private readonly List<CharacterMaster> _minions = new List<CharacterMaster>();

		private readonly List<MinionIcon> _icons = new List<MinionIcon>();

		private float _refreshTimer;

		private float _baseCardHeight;

		private bool _baseCardHeightKnown;

		public static void Ensure(AllyCardController card)
		{
			if (!((Object)(object)card == (Object)null) && !((Object)(object)((Component)card).GetComponent<CardMinionIcons>() != (Object)null))
			{
				CardMinionIcons cardMinionIcons = ((Component)card).gameObject.AddComponent<CardMinionIcons>();
				cardMinionIcons._card = card;
				cardMinionIcons.Build();
			}
		}

		private void Build()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_card.layoutElement != (Object)null)
			{
				_baseCardHeight = _card.layoutElement.preferredHeight;
				_baseCardHeightKnown = true;
			}
			if ((Object)(object)((Component)this).GetComponent<CardFade>() == (Object)null && (Object)(object)((Component)this).GetComponent<Graphic>() != (Object)null)
			{
				((Component)this).gameObject.AddComponent<CardFade>();
			}
			GameObject val = new GameObject("TidyAlliesMinionIcons", new Type[1] { typeof(RectTransform) });
			_container = val.GetComponent<RectTransform>();
			((Transform)_container).SetParent(((Component)this).transform, false);
			val.AddComponent<LayoutElement>().ignoreLayout = true;
			_container.anchorMin = new Vector2(0f, 0f);
			_container.anchorMax = new Vector2(0f, 0f);
			_container.pivot = new Vector2(0f, 0f);
			_container.sizeDelta = Vector2.zero;
			_container.anchoredPosition = Vector2.zero;
		}

		private void ApplyCardPadding()
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			HorizontalLayoutGroup component = ((Component)this).GetComponent<HorizontalLayoutGroup>();
			if (!((Object)(object)component == (Object)null) && ((LayoutGroup)component).padding != null)
			{
				int num = Mathf.RoundToInt(ModConfig.CardPadding.Value);
				if (((LayoutGroup)component).padding.left != num || ((LayoutGroup)component).padding.right != num || ((LayoutGroup)component).padding.top != num || ((LayoutGroup)component).padding.bottom != num)
				{
					((LayoutGroup)component).padding = new RectOffset(num, num, num, num);
					LayoutRebuilder.MarkLayoutForRebuild(_card.rectTransform);
				}
			}
		}

		private void LateUpdate()
		{
			if ((Object)(object)_card == (Object)null || (Object)(object)_container == (Object)null)
			{
				return;
			}
			if (!ModConfig.Enabled.Value)
			{
				((Component)_container).gameObject.SetActive(false);
				RestoreCardHeight();
				return;
			}
			((Component)_container).gameObject.SetActive(true);
			_refreshTimer -= Time.unscaledDeltaTime;
			if (_refreshTimer <= 0f)
			{
				_refreshTimer = Mathf.Max(0.05f, ModConfig.RefreshInterval.Value);
				CollectMinions();
				SyncIcons();
			}
			ApplyCardPadding();
			ApplyCardHeight();
			for (int i = 0; i < _icons.Count; i++)
			{
				_icons[i].UpdateHealth();
			}
		}

		private void ApplyCardHeight()
		{
			LayoutElement layoutElement = _card.layoutElement;
			if (!((Object)(object)layoutElement == (Object)null) && _baseCardHeightKnown)
			{
				float num = ModConfig.CardPadding.Value * 2f;
				num = ((_minions.Count <= 0) ? (num + 6f) : (num + (ModConfig.IconSize.Value + ModConfig.IconMargin.Value)));
				float num2 = _baseCardHeight + num;
				if (!Mathf.Approximately(layoutElement.preferredHeight, num2))
				{
					layoutElement.preferredHeight = num2;
				}
			}
		}

		private void RestoreCardHeight()
		{
			LayoutElement val = (((Object)(object)_card != (Object)null) ? _card.layoutElement : null);
			if ((Object)(object)val != (Object)null && _baseCardHeightKnown)
			{
				val.preferredHeight = _baseCardHeight;
			}
		}

		private void OnDestroy()
		{
			RestoreCardHeight();
		}

		private void CollectMinions()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			_minions.Clear();
			CharacterMaster sourceMaster = _card.sourceMaster;
			if ((Object)(object)sourceMaster == (Object)null)
			{
				return;
			}
			MinionGroup val = MinionGroup.FindGroup(((NetworkBehaviour)sourceMaster).netId);
			if (val == null)
			{
				return;
			}
			MinionOwnership[] members = val.members;
			int num = Mathf.Min(val.memberCount, members.Length);
			for (int i = 0; i < num; i++)
			{
				MinionOwnership val2 = members[i];
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				CharacterMaster component = ((Component)val2).GetComponent<CharacterMaster>();
				if (!((Object)(object)component == (Object)null))
				{
					CharacterBody body = component.GetBody();
					if (!((Object)(object)body == (Object)null) && !((Object)(object)body.portraitIcon == (Object)null) && !component.hideAllyCard && (!((Object)(object)body.teamComponent != (Object)null) || !body.teamComponent.hideAllyCardDisplay))
					{
						_minions.Add(component);
					}
				}
			}
		}

		private void SyncIcons()
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			while (_icons.Count < _minions.Count)
			{
				_icons.Add(new MinionIcon(_container));
			}
			float value = ModConfig.IconSize.Value;
			float value2 = ModConfig.IconSpacing.Value;
			float value3 = ModConfig.OffsetX.Value;
			float value4 = ModConfig.OffsetY.Value;
			float num = value + value2;
			if (_minions.Count > 0)
			{
				float num2 = ModConfig.IconAreaWidth.Value;
				if (num2 <= 0f && (Object)(object)_card.rectTransform != (Object)null)
				{
					Rect rect = _card.rectTransform.rect;
					num2 = ((Rect)(ref rect)).width - ModConfig.CardPadding.Value * 2f;
				}
				if (num2 > 0f)
				{
					num = Mathf.Min(num, num2 / (float)_minions.Count);
				}
			}
			float num3 = value4 + ModConfig.CardPadding.Value;
			float num4 = value3 + ModConfig.CardPadding.Value;
			for (int i = 0; i < _icons.Count; i++)
			{
				if (i >= _minions.Count)
				{
					_icons[i].Unbind();
					continue;
				}
				float num5 = num4 + (float)i * num;
				_icons[i].Bind(_minions[i], new Vector2(num5, num3), value);
			}
		}
	}
	internal static class IconCache
	{
		private static readonly Dictionary<Texture, Sprite> Cache = new Dictionary<Texture, Sprite>();

		public static Sprite Get(Texture texture)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)texture == (Object)null)
			{
				return null;
			}
			if (Cache.TryGetValue(texture, out var value))
			{
				return value;
			}
			Sprite val = null;
			Texture2D val2 = (Texture2D)(object)((texture is Texture2D) ? texture : null);
			if (val2 != null)
			{
				val = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f));
				((Object)val).name = "TidyAllies_" + ((Object)val2).name;
			}
			else
			{
				Plugin.Log.LogWarning((object)("portraitIcon が Texture2D ではないため Sprite にできません: " + ((object)texture).GetType().Name));
			}
			Cache[texture] = val;
			return val;
		}

		public static void Clear()
		{
			Cache.Clear();
		}
	}
	internal static class ModConfig
	{
		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<bool> ShowSelf;

		public static ConfigEntry<float> RefreshInterval;

		public static ConfigEntry<float> IconSize;

		public static ConfigEntry<float> IconSpacing;

		public static ConfigEntry<float> IconAreaWidth;

		public static ConfigEntry<float> IconMargin;

		public static ConfigEntry<float> PlayerGap;

		public static ConfigEntry<float> CardPadding;

		public static ConfigEntry<float> OffsetX;

		public static ConfigEntry<float> OffsetY;

		public static ConfigEntry<Color> EmptyColor;

		public static ConfigEntry<Color> FillColor;

		public static ConfigEntry<Color> LowHealthColor;

		public static ConfigEntry<float> LowHealthThreshold;

		public static void Init(ConfigFile config)
		{
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			EnsureColorConverter();
			Enabled = config.Bind<bool>("General", "Enabled", true, "ミニオンのカードを畳んで、持ち主のカードにアイコンとして添える。off にするとバニラのカードに戻る。");
			ShowSelf = config.Bind<bool>("General", "Show Self", true, "自分のカードも出す。バニラは自分のカードを作らないため、off にするとソロでは何も出なくなる。");
			RefreshInterval = config.Bind<float>("General", "Refresh Interval", 0.25f, "ミニオンの一覧を組み直す間隔(秒)。HP の反映は毎フレーム行うのでここは影響しない。");
			IconSize = config.Bind<float>("Layout", "Icon Size", 30f, "アイコン 1 つの大きさ(ピクセル)。");
			IconSpacing = config.Bind<float>("Layout", "Icon Spacing", 4f, "アイコン同士の間隔(ピクセル)。");
			IconAreaWidth = config.Bind<float>("Layout", "Icon Area Width", 0f, "アイコンを並べてよい幅(ピクセル)。0 にするとカードの幅と同じだけ使う。ミニオンが増えて入りきらなくなると、バニラのカードと同じようにアイコンを重ねてこの幅に収める。数で打ち切らないので、連れているものは必ずどれか見える。");
			IconMargin = config.Bind<float>("Layout", "Icon Margin", 10f, "アイコンの上に空ける余白(ピクセル)。HP バーとの間隔になる。下と左の余白は Card Padding が受け持つ。");
			PlayerGap = config.Bind<float>("Layout", "Player Gap", 9f, "プレイヤーのカード同士を離す間隔(ピクセル)。");
			CardPadding = config.Bind<float>("Layout", "Card Padding", 9f, "カードの背景と中身のあいだの余白(ピクセル)。バニラは 0 で、顔や名前が背景の縁に貼り付いている。");
			OffsetX = config.Bind<float>("Layout", "Offset X", 0f, "カードの左辺からの水平方向のずれ(ピクセル)。右が正。");
			OffsetY = config.Bind<float>("Layout", "Offset Y", 0f, "カードの下辺からの垂直方向のずれ(ピクセル)。上が正。");
			EmptyColor = config.Bind<Color>("Appearance", "Empty Color", new Color(0.15f, 0.15f, 0.15f, 0.6f), "HP が減ったぶんに見える、下地のアイコンの色。");
			FillColor = config.Bind<Color>("Appearance", "Fill Color", Color.white, "HP が残っているぶんのアイコンの色。");
			LowHealthColor = config.Bind<Color>("Appearance", "Low Health Color", new Color(1f, 0.25f, 0.2f, 1f), "HP が減ったときに近づく色。");
			LowHealthThreshold = config.Bind<float>("Appearance", "Low Health Threshold", 1f, "この割合を下回ると色が Low Health Color へ寄っていく。");
			if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
			{
				try
				{
					RegisterRiskOfOptions();
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Risk of Options への設定登録に失敗しました: " + ex.Message));
				}
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void RegisterRiskOfOptions()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_0058: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//IL_0101: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Expected O, but got Unknown
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Expected O, but got Unknown
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Expected O, but got Unknown
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Expected O, but got Unknown
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Expected O, but got Unknown
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Expected O, but got Unknown
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Expected O, but got Unknown
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Expected O, but got Unknown
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Expected O, but got Unknown
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Expected O, but got Unknown
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Expected O, but got Unknown
			//IL_0237: 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_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Expected O, but got Unknown
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Expected O, but got Unknown
			ModSettingsManager.SetModDescription("ミニオンのアライカードを畳んで、持ち主のカードにアイコンとして添えます。アイコンの中を HP が下から満たします。");
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(Enabled));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(ShowSelf));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(RefreshInterval, new SliderConfig
			{
				min = 0.05f,
				max = 1f,
				FormatString = "{0:F2} s"
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(IconSize, new SliderConfig
			{
				min = 8f,
				max = 64f,
				FormatString = "{0:F0} px"
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(IconSpacing, new SliderConfig
			{
				min = 0f,
				max = 20f,
				FormatString = "{0:F0} px"
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(IconMargin, new SliderConfig
			{
				min = 0f,
				max = 40f,
				FormatString = "{0:F0} px"
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(PlayerGap, new SliderConfig
			{
				min = 0f,
				max = 80f,
				FormatString = "{0:F0} px"
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(CardPadding, new SliderConfig
			{
				min = 0f,
				max = 30f,
				FormatString = "{0:F0} px"
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(IconAreaWidth, new SliderConfig
			{
				min = 0f,
				max = 600f,
				FormatString = "{0:F0} px"
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(OffsetX, new SliderConfig
			{
				min = -200f,
				max = 200f,
				FormatString = "{0:F0} px"
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(OffsetY, new SliderConfig
			{
				min = -200f,
				max = 200f,
				FormatString = "{0:F0} px"
			}));
			ModSettingsManager.AddOption((BaseOption)new ColorOption(EmptyColor));
			ModSettingsManager.AddOption((BaseOption)new ColorOption(FillColor));
			ModSettingsManager.AddOption((BaseOption)new ColorOption(LowHealthColor));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(LowHealthThreshold, new SliderConfig
			{
				min = 0.05f,
				max = 1f,
				FormatString = "{0:F2}"
			}));
		}

		private static void EnsureColorConverter()
		{
			//IL_001c: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			if (TomlTypeConverter.CanConvert(typeof(Color)))
			{
				return;
			}
			TomlTypeConverter.AddConverter(typeof(Color), new TypeConverter
			{
				ConvertToString = (object obj, Type type) => "#" + ColorUtility.ToHtmlStringRGBA((Color)obj),
				ConvertToObject = delegate(string str, Type type)
				{
					//IL_0010: 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_000f: Unknown result type (might be due to invalid IL or missing references)
					Color white = default(Color);
					if (!ColorUtility.TryParseHtmlString(str, ref white))
					{
						white = Color.white;
					}
					return white;
				}
			});
		}
	}
	[BepInPlugin("OchaDashiMan.TidyAllies", "TidyAllies", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "OchaDashiMan.TidyAllies";

		public const string ModName = "TidyAllies";

		public const string Version = "1.0.2";

		internal const string RiskOfOptionsGuid = "com.rune580.riskofoptions";

		internal static ManualLogSource Log;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			ModConfig.Init(((BaseUnityPlugin)this).Config);
			_harmony = new Harmony("OchaDashiMan.TidyAllies");
			_harmony.PatchAll(typeof(AllyCardManagerPatch));
			_harmony.PatchAll(typeof(AllyCardLayoutPatch));
			_harmony.PatchAll(typeof(AllyCardPatch));
			Log.LogInfo((object)"TidyAllies 1.0.2 loaded.");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace TidyAllies.Patches
{
	[HarmonyPatch]
	internal static class AllyCardLayoutPatch
	{
		private static MethodBase ResolveTarget()
		{
			return AccessTools.Method(typeof(AllyCardManager), "SetLayoutVertical", (Type[])null, (Type[])null);
		}

		[HarmonyPrepare]
		private static bool Prepare()
		{
			if (ResolveTarget() != null)
			{
				return true;
			}
			Plugin.Log.LogError((object)"AllyCardManager.SetLayoutVertical が見つかりませんでした。カードの間隔は調整されません。");
			return false;
		}

		[HarmonyTargetMethod]
		private static MethodBase TargetMethod()
		{
			return ResolveTarget();
		}

		[HarmonyPostfix]
		private static void Postfix(AllyCardManager __instance)
		{
			if (!ModConfig.Enabled.Value)
			{
				return;
			}
			try
			{
				ApplyHudSkew(__instance);
				Arrange(__instance);
			}
			catch
			{
			}
		}

		private static void ApplyHudSkew(AllyCardManager manager)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ResolveSkewSource(manager);
			if (!((Object)(object)val == (Object)null) && ((Component)manager).transform.localRotation != val.localRotation)
			{
				((Component)manager).transform.localRotation = val.localRotation;
			}
		}

		private static Transform ResolveSkewSource(AllyCardManager manager)
		{
			Transform val = (((Object)(object)((Component)manager).transform.parent != (Object)null) ? ((Component)manager).transform.parent.parent : null);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			foreach (HUD readOnlyInstance in HUD.readOnlyInstanceList)
			{
				if (!((Object)(object)readOnlyInstance == (Object)null) && !((Object)(object)readOnlyInstance.allyCardManager != (Object)(object)manager) && !((Object)(object)readOnlyInstance.healthBar == (Object)null))
				{
					Transform val2 = ((Component)readOnlyInstance.healthBar).transform;
					while ((Object)(object)val2.parent != (Object)null && (Object)(object)val2.parent != (Object)(object)val)
					{
						val2 = val2.parent;
					}
					return ((Object)(object)val2.parent == (Object)(object)val) ? val2 : null;
				}
			}
			return null;
		}

		private static void Arrange(AllyCardManager manager)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			IList cardElements = GetCardElements(manager);
			if (cardElements == null || cardElements.Count == 0)
			{
				return;
			}
			float value = ModConfig.PlayerGap.Value;
			float num = 0f;
			for (int i = 0; i < cardElements.Count; i++)
			{
				object? obj = cardElements[i];
				AllyCardController val = (AllyCardController)((obj is AllyCardController) ? obj : null);
				if (val != null && !((Object)(object)val.rectTransform == (Object)null))
				{
					float num2;
					if (!((Object)(object)val.layoutElement != (Object)null))
					{
						Rect rect = val.rectTransform.rect;
						num2 = ((Rect)(ref rect)).height;
					}
					else
					{
						num2 = val.layoutElement.preferredHeight;
					}
					float num3 = num2;
					val.rectTransform.SetSizeWithCurrentAnchors((Axis)1, num3);
					Vector2 anchoredPosition = val.rectTransform.anchoredPosition;
					anchoredPosition.y = num;
					val.rectTransform.anchoredPosition = anchoredPosition;
					num -= num3 + value;
				}
			}
		}

		private static IList GetCardElements(AllyCardManager manager)
		{
			object obj = AccessTools.Field(typeof(AllyCardManager), "cardAllocator")?.GetValue(manager);
			if (obj == null)
			{
				return null;
			}
			return AccessTools.Field(obj.GetType(), "elements")?.GetValue(obj) as IList;
		}
	}
	[HarmonyPatch]
	internal static class AllyCardManagerPatch
	{
		internal static bool Applied { get; private set; }

		private static MethodBase ResolveTarget()
		{
			return AccessTools.Method(typeof(AllyCardManager), "PopulateCharacterDataSet", (Type[])null, (Type[])null);
		}

		[HarmonyPrepare]
		private static bool Prepare()
		{
			if (ResolveTarget() != null)
			{
				return true;
			}
			Plugin.Log.LogError((object)"AllyCardManager.PopulateCharacterDataSet が見つかりませんでした。ゲーム側の更新で変わった可能性があります。TidyAllies のカード制御は無効になります。");
			return false;
		}

		[HarmonyTargetMethod]
		private static MethodBase TargetMethod()
		{
			return ResolveTarget();
		}

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			FieldInfo fieldInfo = AccessTools.Field(typeof(CharacterMaster), "hideAllyCard");
			MethodInfo methodInfo = AccessTools.Method(typeof(AllyCardManagerPatch), "ShouldHide", (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(AllyCardManagerPatch), "ShouldSkipSelf", (Type[])null, (Type[])null);
			bool flag = false;
			bool flag2 = false;
			for (int i = 0; i < list.Count; i++)
			{
				if (!flag && fieldInfo != null && list[i].opcode == OpCodes.Ldfld && list[i].operand == fieldInfo)
				{
					CodeInstruction item = list[i - 1].Clone();
					list.Insert(i + 1, item);
					list.Insert(i + 2, new CodeInstruction(OpCodes.Call, (object)methodInfo));
					list.Insert(i + 3, new CodeInstruction(OpCodes.Or, (object)null));
					i += 3;
					flag = true;
				}
				else if (!flag2 && (list[i].opcode == OpCodes.Beq || list[i].opcode == OpCodes.Beq_S))
				{
					object operand = list[i].operand;
					list[i] = new CodeInstruction(OpCodes.Call, (object)methodInfo2);
					list.Insert(i + 1, new CodeInstruction(OpCodes.Brtrue, operand));
					i++;
					flag2 = true;
				}
			}
			if (!flag || !flag2)
			{
				Plugin.Log.LogError((object)("PopulateCharacterDataSet の IL に目印が見つかりませんでした (hideAllyCard=" + flag + ", self=" + flag2 + ")。ゲーム側の更新で変わった可能性があります。カードはバニラのまま動きます。"));
				return instructions;
			}
			Applied = true;
			return list;
		}

		private static bool ShouldHide(CharacterMaster master)
		{
			if ((Object)(object)master == (Object)null || !ModConfig.Enabled.Value)
			{
				return false;
			}
			return (Object)(object)master.playerCharacterMasterController == (Object)null;
		}

		private static bool ShouldSkipSelf(CharacterMaster sourceMaster, CharacterMaster candidate)
		{
			if (sourceMaster != candidate)
			{
				return false;
			}
			if (ModConfig.Enabled.Value)
			{
				return !ModConfig.ShowSelf.Value;
			}
			return true;
		}
	}
	[HarmonyPatch]
	internal static class AllyCardPatch
	{
		private static MethodBase ResolveUpdateInfo()
		{
			return AccessTools.Method(typeof(AllyCardController), "UpdateInfo", (Type[])null, (Type[])null);
		}

		[HarmonyPrepare]
		private static bool Prepare()
		{
			if (ResolveUpdateInfo() != null)
			{
				return true;
			}
			Plugin.Log.LogError((object)"AllyCardController.UpdateInfo が見つかりませんでした。ゲーム側の更新で変わった可能性があります。ミニオンのアイコンは出ません。");
			return false;
		}

		[HarmonyTargetMethod]
		private static MethodBase TargetMethod()
		{
			return ResolveUpdateInfo();
		}

		[HarmonyPostfix]
		private static void Postfix(AllyCardController __instance)
		{
			try
			{
				CardMinionIcons.Ensure(__instance);
				CardHealthText.Ensure(__instance);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("ミニオンアイコンの取り付けに失敗しました: " + ex));
			}
		}
	}
}