Decompiled source of EssenceData v0.2.0

plugins/EssenceData.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using Conductor.Extensions;
using EssenceData;
using EssenceData.code;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Configuration;
using ShinyShoe;
using SimpleInjector;
using TMPro;
using TrainworksReloaded.Base.Extensions;
using TrainworksReloaded.Core;
using TrainworksReloaded.Core.Extensions;
using TrainworksReloaded.Core.Interfaces;
using UnityEngine;
using UnityEngine.EventSystems;
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("EssenceData")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0+6d5f5aa9ca4f41c1a833628d52a1594988dc8be4")]
[assembly: AssemblyProduct("EssenceData")]
[assembly: AssemblyTitle("EssenceData")]
[assembly: AssemblyVersion("0.2.0.0")]
[module: RefSafetyRules(11)]
[CompilerGenerated]
internal sealed class <>z__ReadOnlyArray<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
	int ICollection.Count => _items.Length;

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => this;

	object IList.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	bool IList.IsFixedSize => true;

	bool IList.IsReadOnly => true;

	int IReadOnlyCollection<T>.Count => _items.Length;

	T IReadOnlyList<T>.this[int index] => _items[index];

	int ICollection<T>.Count => _items.Length;

	bool ICollection<T>.IsReadOnly => true;

	T IList<T>.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	public <>z__ReadOnlyArray(T[] items)
	{
		_items = items;
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		return ((IEnumerable)_items).GetEnumerator();
	}

	void ICollection.CopyTo(Array array, int index)
	{
		((ICollection)_items).CopyTo(array, index);
	}

	int IList.Add(object value)
	{
		throw new NotSupportedException();
	}

	void IList.Clear()
	{
		throw new NotSupportedException();
	}

	bool IList.Contains(object value)
	{
		return ((IList)_items).Contains(value);
	}

	int IList.IndexOf(object value)
	{
		return ((IList)_items).IndexOf(value);
	}

	void IList.Insert(int index, object value)
	{
		throw new NotSupportedException();
	}

	void IList.Remove(object value)
	{
		throw new NotSupportedException();
	}

	void IList.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}

	IEnumerator<T> IEnumerable<T>.GetEnumerator()
	{
		return ((IEnumerable<T>)_items).GetEnumerator();
	}

	void ICollection<T>.Add(T item)
	{
		throw new NotSupportedException();
	}

	void ICollection<T>.Clear()
	{
		throw new NotSupportedException();
	}

	bool ICollection<T>.Contains(T item)
	{
		return ((ICollection<T>)_items).Contains(item);
	}

	void ICollection<T>.CopyTo(T[] array, int arrayIndex)
	{
		((ICollection<T>)_items).CopyTo(array, arrayIndex);
	}

	bool ICollection<T>.Remove(T item)
	{
		throw new NotSupportedException();
	}

	int IList<T>.IndexOf(T item)
	{
		return ((IList<T>)_items).IndexOf(item);
	}

	void IList<T>.Insert(int index, T item)
	{
		throw new NotSupportedException();
	}

	void IList<T>.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
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;
		}
	}
}
[HarmonyPatch(typeof(CharacterData), "GetCharacterCardText")]
internal class CharacterData_GetCharacterCardText_AddFusedMonster_Patch
{
	public static void Postfix(ref string text, CardState cardState)
	{
		List<CardUpgradeState> list = ((cardState != null) ? cardState.GetCardStateModifiers().GetCardUpgrades() : null);
		if (IEnumerableUtility.IsNullOrEmpty<CardUpgradeState>(list))
		{
			return;
		}
		foreach (CardUpgradeState item in list)
		{
			if (EssenceExtensions.IsEssenceUpgrade(item))
			{
				CharacterData sourceEssenceCharacter = EssenceExtensions.GetSourceEssenceCharacter(item);
				string text2 = string.Format(LocalizationExtensions.Localize("TextFormat_Fused", (ILocalizationParameterContext)null), sourceEssenceCharacter.GetName());
				text = text + Environment.NewLine + text2 + Environment.NewLine;
			}
		}
	}
}
[HarmonyPatch(typeof(CardTooltipContainer), "AddUpgradedCharacterTriggers")]
internal class CardTooltipContainer_AddUpgradedCharacterTriggers_SynthesisTooltipsPatch
{
	public static void Postfix(CardStateModifiers cardStateModifiers, CardTooltipContainer __instance)
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Expected O, but got Unknown
		if (cardStateModifiers == null)
		{
			return;
		}
		foreach (CardUpgradeState cardUpgrade in cardStateModifiers.GetCardUpgrades())
		{
			CharacterData sourceEssenceCharacter = EssenceExtensions.GetSourceEssenceCharacter(cardUpgrade);
			if (EssenceExtensions.IsEssenceUpgrade(cardUpgrade) && (Object)(object)sourceEssenceCharacter != (Object)null)
			{
				TooltipUI obj = ((TooltipContainer)__instance).InstantiateTooltip("synthesis", Plugin.Synthesis, false, false, false);
				string text = string.Format(LocalizationExtensions.Localize("CardFrameUI_SynthesisTextFormat", (ILocalizationParameterContext)null), sourceEssenceCharacter.GetName());
				if (obj != null)
				{
					obj.Set(text, LocalizationExtensions.Localize(cardUpgrade.GetUpgradeDescriptionKey(), (ILocalizationParameterContext)new CardEffectLocalizationContext((ILocalizationEffectPower)(object)cardUpgrade.GetSourceCardUpgradeData(), (CharacterState)null, (CardState)null, (IRoomStateModifier)null, (CharacterStatusEffectAdjustments)null)), false);
				}
			}
		}
	}
}
[HarmonyPatch(typeof(CardUI), "ApplyStateToUI", new Type[]
{
	typeof(CardState),
	typeof(CardStatistics),
	typeof(MonsterManager),
	typeof(HeroManager),
	typeof(RelicManager),
	typeof(SaveManager),
	typeof(MasteryType),
	typeof(bool),
	typeof(bool),
	typeof(List<CardUpgradeState>),
	typeof(CardArtPool),
	typeof(CardEdgeVfxPool)
})]
internal static class CardUI_UpdateTextContent_ShowSynthesisEffectPatch
{
	public static bool EnableShowingSynthesis = false;

	public static bool DisableSynthesisButton = false;

	private static readonly FieldInfo CardUI_CardFrontTinter = AccessTools.Field(typeof(CardUI), "cardFrontTinter");

	private static readonly FieldInfo CardUI_FilteredReasonLabel = AccessTools.Field(typeof(CardUI), "filteredReasonLabel");

	public static void Postfix(CardUI __instance, CardState cardState, CardFrameUI ____cardFrame, ContentTinter ___cardFrontTinter, TMP_Text ___filteredReasonLabel)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Invalid comparison between Unknown and I4
		bool flag = (int)cardState.CurrentDisabledReason == 0;
		if (!EnableShowingSynthesis && flag)
		{
			__instance.ResetSyntheisPreview();
		}
		else if (EnableShowingSynthesis && flag)
		{
			__instance.EnableSynthesisPreview(___cardFrontTinter, ___filteredReasonLabel);
		}
	}

	public static void EnableSynthesisPreview(this CardUI cardUI, ContentTinter? cardFrontTinter = null, TMP_Text? filteredReasonLabel = null)
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Expected O, but got Unknown
		CardState cardState = cardUI.GetCardState();
		if (cardState == null)
		{
			return;
		}
		if (cardFrontTinter == null)
		{
			object? value = CardUI_CardFrontTinter.GetValue(cardUI);
			cardFrontTinter = (ContentTinter?)((value is ContentTinter) ? value : null);
		}
		if (filteredReasonLabel == null)
		{
			object? value2 = CardUI_FilteredReasonLabel.GetValue(cardUI);
			filteredReasonLabel = (TMP_Text?)((value2 is TMP_Text) ? value2 : null);
		}
		cardFrontTinter.Toggle(true);
		if (cardState.IsMonsterCard() && !cardState.IsChampionCard())
		{
			CharacterData spawnCharacterData = cardState.GetSpawnCharacterData();
			CardUpgradeData val = ((spawnCharacterData != null) ? EssenceExtensions.GetEssence(spawnCharacterData) : null);
			object obj;
			if (val == null)
			{
				obj = null;
			}
			else
			{
				string upgradeDescriptionKey = val.GetUpgradeDescriptionKey();
				obj = ((upgradeDescriptionKey != null) ? LocalizationExtensions.Localize(upgradeDescriptionKey, (ILocalizationParameterContext)new CardEffectLocalizationContext((ILocalizationEffectPower)(object)val, (CharacterState)null, cardState, (IRoomStateModifier)null, (CharacterStatusEffectAdjustments)null)) : null);
			}
			if (obj == null)
			{
				obj = "No essence";
			}
			string text = (string)obj;
			filteredReasonLabel.SetText(text, true);
			((Component)filteredReasonLabel).gameObject.SetActive(true);
			((Behaviour)filteredReasonLabel).enabled = true;
		}
	}
}
internal static class UnitEssenceToggle
{
	[HarmonyPatch]
	private static class Toggle
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			return Screens("ApplyScreenInput", "ApplyScreenInput", "ApplyScreenInput");
		}

		private static bool Prefix(MonoBehaviour __instance, Controls triggeredMappingID, ref bool __result)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			EventSystem current = EventSystem.current;
			GameObject val = ((current != null) ? current.currentSelectedGameObject : null);
			TMP_InputField val2 = default(TMP_InputField);
			if ((int)triggeredMappingID != 61 || ((Object)(object)val != (Object)null && val.TryGetComponent<TMP_InputField>(ref val2) && val2.isFocused))
			{
				return true;
			}
			bool flag = (CardUI_UpdateTextContent_ShowSynthesisEffectPatch.EnableShowingSynthesis = !CardUI_UpdateTextContent_ShowSynthesisEffectPatch.EnableShowingSynthesis);
			_ = Traverse.Create((object)__instance).Field<CardStatistics>("cardStatistics").Value;
			CardUI[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<CardUI>();
			foreach (CardUI val3 in componentsInChildren)
			{
				if (val3.GetCardState() != null)
				{
					if (flag)
					{
						val3.EnableSynthesisPreview();
					}
					else
					{
						val3.ResetSyntheisPreview();
					}
				}
			}
			ShowState((Component)(object)__instance);
			__result = true;
			return false;
		}
	}

	[HarmonyPatch]
	private static class AddButton
	{
		private static readonly FieldInfo DeckScreen_Mode = AccessTools.Field(typeof(DeckScreen), "mode");

		private static IEnumerable<MethodBase> TargetMethods()
		{
			return Screens("Setup", "Setup", "Open");
		}

		private static void Postfix(MonoBehaviour __instance)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Invalid comparison between Unknown and I4
			if (!((Component)__instance).GetComponentsInChildren<GameUISelectableButton>(true).Any((GameUISelectableButton b) => ((Object)b).name == "ToggleUnitEssencesButton"))
			{
				Create(__instance);
			}
			bool enable = !CardUI_UpdateTextContent_ShowSynthesisEffectPatch.DisableSynthesisButton;
			DeckScreen val = (DeckScreen)(object)((__instance is DeckScreen) ? __instance : null);
			if (val != null && (int)(Mode)DeckScreen_Mode.GetValue(val) == 6)
			{
				enable = false;
			}
			ShowState((Component)(object)__instance, enable);
		}

		private static void Create(MonoBehaviour __instance)
		{
			//IL_0081: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_00a9: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: 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_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: 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_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			CompendiumSectionCards val = (CompendiumSectionCards)(object)((__instance is CompendiumSectionCards) ? __instance : null);
			if (val != null)
			{
				CreateFilterRow(Traverse.Create((object)val).Field<FilterToolbar>("filterToolbar").Value);
				return;
			}
			GameUISelectableButton value = Traverse.Create((object)Object.FindObjectOfType<DialogScreen>(true)).Field("dialogPrefab").Field("button1")
				.GetValue<GameUISelectableButton>();
			if ((Object)(object)value == (Object)null)
			{
				return;
			}
			GameUISelectableButton val2 = Object.Instantiate<GameUISelectableButton>(value, ((Component)__instance).transform);
			((Object)val2).name = "ToggleUnitEssencesButton";
			Traverse.Create((object)val2).Field("inputType").SetValue((object)(int)new CoreSymbol("DragonsHoard").m_value);
			RectTransform val3 = (RectTransform)((Component)val2).transform;
			Vector2 val4 = (val3.pivot = Vector2.one);
			Vector2 anchorMin = (val3.anchorMax = val4);
			val3.anchorMin = anchorMin;
			val3.anchoredPosition = new Vector2(-23.5f, -201f);
			val3.sizeDelta = new Vector2(255f, 64f);
			Transform obj = ((Component)val2).transform.Find("Target Graphic");
			RectTransform val6 = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			if (val6 != null)
			{
				val6.sizeDelta = new Vector2(val6.sizeDelta.x, 80f);
			}
			TMP_Text obj2 = ((Component)val2).GetComponentsInChildren<TMP_Text>(true).First((TMP_Text text) => (Object)(object)((Component)text).GetComponentInParent<GameUIControlMapping>() == (Object)null);
			TextMeshProHelper.SetLocKey(obj2, "DeckScreen_ShowEssence");
			obj2.fontSizeMin *= 0.8f;
			obj2.fontSizeMax *= 0.8f;
			obj2.margin = new Vector4(8f, 0f, 60f, 0f);
			RectTransform value2 = Traverse.Create((object)Object.FindObjectOfType<SettingsDialog>(true)).Field("backgroundMuteToggle").Field("handle")
				.GetValue<RectTransform>();
			if (!((Object)(object)value2 == (Object)null))
			{
				RectTransform obj3 = Object.Instantiate<RectTransform>(value2, ((Component)val2).transform);
				((Vector2)(ref val4))..ctor(1f, 0.5f);
				obj3.pivot = val4;
				anchorMin = (obj3.anchorMax = val4);
				obj3.anchorMin = anchorMin;
				obj3.anchoredPosition = new Vector2(-20f, 0f);
				obj3.sizeDelta = new Vector2(56f, 56f);
				((Object)((Component)obj3).GetComponentsInChildren<Transform>(true).First((Transform t) => ((Object)t).name == "Image toggle on")).name = "UnitEssencesGem";
			}
		}

		private static void CreateFilterRow(FilterToolbar toolbar)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0121: 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_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: 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_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			Traverse val = Traverse.Create((object)toolbar);
			OptionsFilterUI value = val.Field<OptionsFilterUI>("costFilterUI").Value;
			SearchFilterUI value2 = val.Field<SearchFilterUI>("searchFilterUI").Value;
			RectTransform val2 = (RectTransform)((Component)value2).transform.parent;
			GameObject obj = Object.Instantiate<GameObject>(((Component)value).gameObject, (Transform)(object)val2);
			((Object)obj).name = "UnitEssencesFilter";
			obj.transform.SetSiblingIndex(((Component)value2).transform.GetSiblingIndex());
			Object.DestroyImmediate((Object)(object)obj.GetComponent<OptionsFilterUI>());
			TextMeshProHelper.SetLocKey(obj.GetComponentsInChildren<TMP_Text>(true).First((TMP_Text t) => (Object)(object)((Component)t).GetComponentInParent<FilterOptionButton>() == (Object)null), "EssenceData_Essences");
			FilterOptionButton[] componentsInChildren = obj.GetComponentsInChildren<FilterOptionButton>(true);
			foreach (FilterOptionButton item in componentsInChildren.Skip(1))
			{
				Object.DestroyImmediate((Object)(object)((Component)item).gameObject);
			}
			FilterOptionButton option = componentsInChildren[0];
			((Object)option).name = "ToggleUnitEssencesButton";
			option.Set(new OptionDisplay("LogBook_ShowEssence", "", "", 0, false), 0);
			Traverse.Create((object)option.Button).Field("inputType").SetValue((object)(int)new CoreSymbol("DragonsHoard").m_value);
			GridLayoutGroup component = ((Component)((Component)option).transform.parent).GetComponent<GridLayoutGroup>();
			float num;
			if (component != null)
			{
				LayoutRebuilder.ForceRebuildLayoutImmediate(val2);
				Transform transform = ((Component)((Component)val.Field<DropdownFilterUI>("masteryFilterUI").Value).GetComponentInChildren<GameUISelectableDropdown>(true)).transform;
				RectTransform val3 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				if (val3 != null)
				{
					Rect rect = val3.rect;
					if (((Rect)(ref rect)).width > 0f)
					{
						rect = val3.rect;
						num = ((Rect)(ref rect)).width;
						goto IL_01f9;
					}
				}
				num = component.cellSize.x * 6f + component.spacing.x * 5f;
				goto IL_01f9;
			}
			goto IL_02ab;
			IL_02ab:
			TMP_Text[] componentsInChildren2 = ((Component)option).GetComponentsInChildren<TMP_Text>(true);
			foreach (TMP_Text obj2 in componentsInChildren2)
			{
				obj2.enableAutoSizing = true;
				obj2.fontSizeMax = obj2.fontSize;
				obj2.fontSizeMin = obj2.fontSize * 0.5f;
			}
			VerticalLayoutGroup component2 = ((Component)val2).GetComponent<VerticalLayoutGroup>();
			if (component2 != null)
			{
				((HorizontalOrVerticalLayoutGroup)component2).spacing = Mathf.Min(((HorizontalOrVerticalLayoutGroup)component2).spacing, 4f);
			}
			val2.anchoredPosition += new Vector2(0f, 5f);
			Transform obj3 = ((Transform)val2).Find("Bottom divider");
			RectTransform val4 = (RectTransform)(object)((obj3 is RectTransform) ? obj3 : null);
			if (val4 != null)
			{
				val4.anchoredPosition -= new Vector2(0f, 10f);
			}
			return;
			IL_01f9:
			float num3 = num - component.cellSize.x;
			component.cellSize += new Vector2(num3, 0f);
			component.constraint = (Constraint)1;
			component.constraintCount = 1;
			foreach (RectTransform item2 in from r in ((Component)option).GetComponentsInChildren<RectTransform>(true)
				where (Object)(object)r != (Object)(object)((Component)option).transform && r.anchorMin.x == r.anchorMax.x
				select r)
			{
				item2.sizeDelta += new Vector2(num3, 0f);
			}
			goto IL_02ab;
		}
	}

	[HarmonyPatch]
	private static class Reset
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			return Screens("Close", "Close", "Close");
		}

		private static void Postfix()
		{
			CardUI_UpdateTextContent_ShowSynthesisEffectPatch.EnableShowingSynthesis = false;
			CardUI_UpdateTextContent_ShowSynthesisEffectPatch.DisableSynthesisButton = false;
		}
	}

	private const string ButtonName = "ToggleUnitEssencesButton";

	private const string GemName = "UnitEssencesGem";

	private static void ShowState(Component screen, bool enable = true)
	{
		bool enableShowingSynthesis = CardUI_UpdateTextContent_ShowSynthesisEffectPatch.EnableShowingSynthesis;
		foreach (Transform item in from t in screen.GetComponentsInChildren<Transform>(true)
			where ((Object)t).name == "UnitEssencesGem"
			select t)
		{
			((Component)item).gameObject.SetActive(enableShowingSynthesis && enable);
		}
		foreach (Transform item2 in from b in screen.GetComponentsInChildren<Transform>(true)
			where ((Object)b).name == "ToggleUnitEssencesButton"
			select b)
		{
			FilterOptionButton component = ((Component)item2).GetComponent<FilterOptionButton>();
			if ((Object)(object)component != (Object)null)
			{
				component.SetSelected(enableShowingSynthesis, false);
			}
			((Component)item2).gameObject.SetActive(enable);
		}
	}

	private static IEnumerable<MethodBase> Screens(string deck, string draft, string logbook)
	{
		return new <>z__ReadOnlyArray<MethodBase>(new MethodBase[3]
		{
			AccessTools.Method(typeof(DeckScreen), deck, (Type[])null, (Type[])null),
			AccessTools.Method(typeof(CardDraftScreen), draft, (Type[])null, (Type[])null),
			AccessTools.Method(typeof(CompendiumSectionCards), logbook, (Type[])null, (Type[])null)
		});
	}
}
[HarmonyPatch(typeof(CardState), "SetupBodyUpgradeText")]
public static class SetupBodyUpgradeText_Patch
{
	private static readonly MethodInfo FilterMethod = AccessTools.Method(typeof(SetupBodyUpgradeText_Patch), "ExcludeUpgrade", (Type[])null, (Type[])null);

	public static bool ExcludeUpgrade(CardUpgradeState cardUpgrade)
	{
		return EssenceExtensions.IsEssenceUpgrade(cardUpgrade);
	}

	[HarmonyTranspiler]
	public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Expected O, but got Unknown
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Expected O, but got Unknown
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Expected O, but got Unknown
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Expected O, but got Unknown
		CodeMatcher val = new CodeMatcher(instructions, il);
		val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => (i.opcode == OpCodes.Call || i.opcode == OpCodes.Callvirt) && (i.operand?.ToString().Contains("MoveNext") ?? false)), (string)null)
		});
		if (val.IsInvalid)
		{
			Plugin.Logger.LogError((object)"[SetupBodyUpgradeText_Patch] Failed to locate MoveNext call. Patch needs to be redone.");
			return instructions;
		}
		Label label = il.DefineLabel();
		val.Instruction.labels.Add(label);
		val.Start();
		val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => (i.opcode == OpCodes.Call || i.opcode == OpCodes.Callvirt) && (i.operand?.ToString().Contains("get_Current") ?? false)), (string)null),
			new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.IsStloc(i, (LocalBuilder)null)), (string)null)
		});
		if (val.IsInvalid)
		{
			Plugin.Logger.LogError((object)"[SetupBodyUpgradeText_Patch] Failed to locate get_Current assignment. Patch needs to be redone");
			return instructions;
		}
		val.Advance(1);
		CodeInstruction val2 = ConvertStlocToLdloc(val.Instruction);
		val.Advance(1);
		val.Insert((CodeInstruction[])(object)new CodeInstruction[3]
		{
			val2,
			new CodeInstruction(OpCodes.Call, (object)FilterMethod),
			new CodeInstruction(OpCodes.Brtrue, (object)label)
		});
		return val.InstructionEnumeration();
	}

	private static CodeInstruction ConvertStlocToLdloc(CodeInstruction stloc)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Expected O, but got Unknown
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Expected O, but got Unknown
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Expected O, but got Unknown
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Expected O, but got Unknown
		if (stloc.opcode == OpCodes.Stloc_0)
		{
			return new CodeInstruction(OpCodes.Ldloc_0, (object)null);
		}
		if (stloc.opcode == OpCodes.Stloc_1)
		{
			return new CodeInstruction(OpCodes.Ldloc_1, (object)null);
		}
		if (stloc.opcode == OpCodes.Stloc_2)
		{
			return new CodeInstruction(OpCodes.Ldloc_2, (object)null);
		}
		if (stloc.opcode == OpCodes.Stloc_3)
		{
			return new CodeInstruction(OpCodes.Ldloc_3, (object)null);
		}
		if (stloc.opcode == OpCodes.Stloc_S)
		{
			return new CodeInstruction(OpCodes.Ldloc_S, stloc.operand);
		}
		if (stloc.opcode == OpCodes.Stloc)
		{
			return new CodeInstruction(OpCodes.Ldloc, stloc.operand);
		}
		throw new InvalidOperationException($"Unexpected store local opcode: {stloc.opcode}");
	}
}
namespace EssenceData
{
	[BepInPlugin("EssenceData", "EssenceData", "0.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger = new ManualLogSource("EssenceData");

		public static TooltipDesignType Synthesis;

		public void Awake()
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			Railhead.GetBuilder().Configure("EssenceData", (Action<IConfigurationBuilder>)delegate(IConfigurationBuilder c)
			{
				ConfigurationExtensions.AddMergedJsonFile(c, new List<string>(92)
				{
					"json/localizations.json", "json/tooltips.json", "json/unit_synthesis_reward_setup.json", "json/essences/awoken/Animus of Speed.json", "json/essences/awoken/Animus of Will.json", "json/essences/awoken/Awoken Hollow.json", "json/essences/awoken/Edge Prior.json", "json/essences/awoken/Husk Hermit.json", "json/essences/awoken/Shard Channeler.json", "json/essences/awoken/Shattered Shell.json",
					"json/essences/awoken/Steelsinger.json", "json/essences/awoken/Thorned Hollow.json", "json/essences/awoken/Vinemother.json", "json/essences/awoken/Wildwood Custodian.json", "json/essences/awoken/Wilting Sapwood.json", "json/essences/clanless/Shield Steward.json", "json/essences/clanless/Spear Steward.json", "json/essences/clanless/Dante.json", "json/essences/hellhorned/Alpha Fiend.json", "json/essences/hellhorned/Apex Imp.json",
					"json/essences/hellhorned/Branded Warrior.json", "json/essences/hellhorned/Consumer of Crowns.json", "json/essences/hellhorned/Demon Fiend.json", "json/essences/hellhorned/Deranged Brute.json", "json/essences/hellhorned/Fledgling Imp.json", "json/essences/hellhorned/Horned Warrior.json", "json/essences/hellhorned/Impish Scholar.json", "json/essences/hellhorned/Molting Imp.json", "json/essences/hellhorned/Pyre Chomper.json", "json/essences/hellhorned/Queen's Impling.json",
					"json/essences/hellhorned/Railbeater.json", "json/essences/hellhorned/Steelworker.json", "json/essences/hellhorned/Transcendimp.json", "json/essences/hellhorned/Welder Helper.json", "json/essences/remnant/Big Sludge.json", "json/essences/remnant/Bounty Stalker.json", "json/essences/remnant/Devourer of Death.json", "json/essences/remnant/Draff.json", "json/essences/remnant/Dreg.json", "json/essences/remnant/Entombed Explosive.json",
					"json/essences/remnant/Formless Child.json", "json/essences/remnant/Lady of the House.json", "json/essences/remnant/Lady of the Reformed.json", "json/essences/remnant/Legion of Wax.json", "json/essences/remnant/Molten Encasement.json", "json/essences/remnant/Paraffin Enforcer.json", "json/essences/remnant/Paraffin Thug.json", "json/essences/remnant/Remnant Host.json", "json/essences/remnant/Votivary.json", "json/essences/remnant/Wickless Baron.json",
					"json/essences/remnant/Wickless Tycoon.json", "json/essences/stygian/Coldcaelia.json", "json/essences/stygian/Cuttlehex.json", "json/essences/stygian/Eel Gorgon.json", "json/essences/stygian/Glacial Seal.json", "json/essences/stygian/Guard of the Unnamed.json", "json/essences/stygian/Guardian Stone.json", "json/essences/stygian/Icy Cilophyte.json", "json/essences/stygian/Lodestone Totem.json", "json/essences/stygian/Molluscmage.json",
					"json/essences/stygian/Nameless Siren.json", "json/essences/stygian/Offering Monument.json", "json/essences/stygian/Siren of the Sea.json", "json/essences/stygian/Titan Sentry.json", "json/essences/umbra/Alloyed Construct.json", "json/essences/umbra/Antumbra Morsel.json", "json/essences/umbra/Crucible Collector.json", "json/essences/umbra/Crucible Warden.json", "json/essences/umbra/Ember Forge.json", "json/essences/umbra/Magma Morsel.json",
					"json/essences/umbra/Morsel Excavator.json", "json/essences/umbra/Morsel Jeweler.json", "json/essences/umbra/Morsel Miner.json", "json/essences/umbra/Morsel-Made.json", "json/essences/umbra/Morselmaker.json", "json/essences/umbra/Morselmaster.json", "json/essences/umbra/Overgorger.json", "json/essences/umbra/Rubble Morsel.json", "json/essences/umbra/Shadoweater.json", "json/essences/umbra/Shadowsiege.json",
					"json/essences/wurmkin/Bog Chrysalis.json", "json/essences/wurmkin/Bog Fly.json", "json/essences/wurmkin/Bog Wurmling.json", "json/essences/wurmkin/Bogdeep Cocoon.json", "json/essences/wurmkin/First of Kin.json", "json/essences/wurmkin/Glareminder.json", "json/essences/wurmkin/Glugsider.json", "json/essences/wurmkin/Keeper of Echoes.json", "json/essences/wurmkin/Kinhost Carapace.json", "json/essences/wurmkin/Kinhost Pupa.json",
					"json/essences/wurmkin/Kinhost Vessel.json", "json/essences/wurmkin/Shardsoul Carver.json"
				});
			});
			Railend.ConfigurePostAction((Action<Container>)delegate(Container c)
			{
				//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)
				Synthesis = IEnumerableUtility.GetValueOrDefault<string, TooltipDesignType>((IDictionary<string, TooltipDesignType>)c.GetInstance<IRegister<TooltipDesignType>>(), StringExtensions.GetId("EssenceData", "TooltipDesignTypeEnum", "Synthesis"), (TooltipDesignType)0);
				IEnumerableUtility.GetValueOrDefault<string, RewardData>((IDictionary<string, RewardData>)c.GetInstance<IRegister<RewardData>>(), StringExtensions.GetId("EssenceData", "RewardData", "unit_synthesis_reward"), (RewardData)null);
				UnitSynthesisRewardData.FilterMask = IEnumerableUtility.GetValueOrDefault<string, CardUpgradeMaskData>((IDictionary<string, CardUpgradeMaskData>)c.GetInstance<IRegister<CardUpgradeMaskData>>(), StringExtensions.GetId("EssenceData", "UpgradeMask", "HasBeenFused"), (CardUpgradeMaskData)null);
				UnitSynthesisRewardData.fusedUpgrade = IEnumerableUtility.GetValueOrDefault<string, CardUpgradeData>((IDictionary<string, CardUpgradeData>)c.GetInstance<IRegister<CardUpgradeData>>(), StringExtensions.GetId("EssenceData", "Upgrade", "Fusion"), (CardUpgradeData)null);
			});
			Logger.LogInfo((object)"Plugin EssenceData is loaded!");
			new Harmony("EssenceData").PatchAll();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "EssenceData";

		public const string PLUGIN_NAME = "EssenceData";

		public const string PLUGIN_VERSION = "0.2.0";
	}
}
namespace EssenceData.code
{
	public class CardTraitFused : CardTraitState
	{
		public override PropDescriptions CreateEditorInspectorDescriptions()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new PropDescriptions();
		}
	}
	public sealed class UnitSynthesisRewardData : GrantableRewardData
	{
		public readonly int numCardsToSelect = 2;

		[SerializeField]
		public static CardUpgradeMaskData? FilterMask;

		[SerializeField]
		public static CardUpgradeData? fusedUpgrade;

		[SerializeField]
		[LocalizedTextKey(false, true)]
		public string? purgeCardTitleKey = "UnitSynthesisRewardData_purgeTitleKey";

		[SerializeField]
		[LocalizedTextKey(false, true)]
		public string? upgradeUnitTitleKey = "UnitSynthesisRewardData_upgradeUnitTitleKey";

		private List<CardState> cardsChosen = new List<CardState>();

		public override InteractionType interactionType => (InteractionType)2;

		public UnitSynthesisRewardData()
		{
			((RewardData)this)._rewardTitleKey = "UnitSynthesisRewardData_rewardTitleKey";
			((RewardData)this)._rewardDescriptionKey = "UnitSynthesisRewardData_rewardDescriptionKey";
		}

		public override void GrantReward(GrantParams grantParams)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			((MonoBehaviour)grantParams.coreGameManagers.GetSaveManager()).StartCoroutine(ShowDeckSelection(grantParams));
		}

		private IEnumerator ShowDeckSelection(GrantParams grantParams)
		{
			//IL_000e: 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)
			cardsChosen.Clear();
			for (int i = 0; i < numCardsToSelect; i++)
			{
				string instructionContent = LocalizationExtensions.Localize(purgeCardTitleKey, (ILocalizationParameterContext)null);
				FilterCardStateDelegate func = new FilterCardStateDelegate(OnlyUnfusedMonstersWithEssences);
				CardUpgradeData upgrade = null;
				CardUI_UpdateTextContent_ShowSynthesisEffectPatch.EnableShowingSynthesis = true;
				CardUI_UpdateTextContent_ShowSynthesisEffectPatch.DisableSynthesisButton = true;
				if (i > 0)
				{
					CardUI_UpdateTextContent_ShowSynthesisEffectPatch.EnableShowingSynthesis = false;
					upgrade = EssenceExtensions.GetEssence(cardsChosen[i - 1].GetSpawnCharacterData());
					string format = LocalizationExtensions.Localize(upgradeUnitTitleKey, (ILocalizationParameterContext)null);
					string upgradeDescriptionKey = upgrade.GetUpgradeDescriptionKey();
					instructionContent = string.Format(format, ((upgradeDescriptionKey != null) ? LocalizationExtensions.Localize(upgradeDescriptionKey, (ILocalizationParameterContext)new CardEffectLocalizationContext((ILocalizationEffectPower)(object)upgrade, (CharacterState)null, cardsChosen[i - 1], (IRoomStateModifier)null, (CharacterStatusEffectAdjustments)null)) : null) ?? "");
					func = null;
				}
				bool cardChosen = false;
				bool interactionCompleted = false;
				ref Action interactionCompleteCallback = ref grantParams.interactionCompleteCallback;
				interactionCompleteCallback = (Action)Delegate.Combine(interactionCompleteCallback, (Action)delegate
				{
					interactionCompleted = true;
				});
				((GrantableRewardData)this).DoUIScreenConfirmationFlow((ScreenName)3, grantParams, (Action<IScreen, ScreenSetupConfirmationDelegate>)delegate(IScreen screen, ScreenSetupConfirmationDelegate screenSetupConfirmation)
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: 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)
					//IL_0014: Unknown result type (might be due to invalid IL or missing references)
					//IL_001b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0027: Unknown result type (might be due to invalid IL or missing references)
					//IL_002c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0031: Unknown result type (might be due to invalid IL or missing references)
					//IL_003c: 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_0043: 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_006a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0080: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ad: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
					//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
					//IL_010b: Expected O, but got Unknown
					//IL_0112: Unknown result type (might be due to invalid IL or missing references)
					//IL_011c: Expected O, but got Unknown
					IScreen obj = ((screen is DeckScreen) ? screen : null);
					((DeckScreen)obj).Setup(new Params
					{
						mode = (Mode)12,
						showCancel = true,
						rewardSource = grantParams.source,
						cardUpgradeMaskData = FilterMask,
						cardTypeFilter = (CardType)1,
						filterFunc = func,
						totalUses = grantParams.correspondingReward.TotalUses,
						sourceRewardState = grantParams.correspondingReward,
						forceExcludeCard = ((i > 0) ? cardsChosen[0] : null),
						numDeckScreensNeededAfterThis = numCardsToSelect - i - 1,
						titleKey = ((RewardData)this)._rewardTitleKey,
						overrideInstructionContent = instructionContent,
						cardUpgradeData = upgrade,
						ignoreUpgradeLimit = true
					});
					((DeckScreen)obj).AddDeckScreenCardStateChosenDelegate((CardStateChosenDelegate)delegate(CardState returnCardState)
					{
						if (returnCardState != null)
						{
							cardsChosen.Add(returnCardState);
							cardChosen = true;
						}
					});
				}, (RewardGrantedCallbackTiming)1);
				yield return (object)new WaitWhile((Func<bool>)(() => !interactionCompleted));
				if (!cardChosen)
				{
					break;
				}
			}
			CardUI_UpdateTextContent_ShowSynthesisEffectPatch.EnableShowingSynthesis = false;
			if (cardsChosen.Count == numCardsToSelect)
			{
				InfuseCards(grantParams.coreGameManagers.GetSaveManager());
				grantParams.rewardGrantedCallback?.Invoke(default(GrantResult));
				grantParams.correspondingReward.ClaimReward(false);
			}
		}

		private void InfuseCards(SaveManager saveManager)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			CardState val = cardsChosen[0];
			CardUpgradeData essence = EssenceExtensions.GetEssence(val.GetSpawnCharacterData());
			CardState val2 = cardsChosen[1];
			CardUpgradeState val3 = new CardUpgradeState();
			val3.Setup(essence, false, false);
			val2.ApplyPermanentUpgrade(val3, saveManager, true, (string)null);
			val3 = new CardUpgradeState();
			val3.Setup(fusedUpgrade, false, false);
			val2.ApplyPermanentUpgrade(val3, saveManager, true, (string)null);
			saveManager.RemoveCardFromDeck(val);
			saveManager.ShowCardAddedAnimation(val2, (Action)null);
		}

		private bool OnlyUnfusedMonstersWithEssences(CardState cardState)
		{
			if (!cardState.IsMonsterCard())
			{
				return true;
			}
			CharacterData spawnCharacterData = cardState.GetSpawnCharacterData();
			if ((Object)(object)spawnCharacterData == (Object)null)
			{
				return true;
			}
			return (Object)(object)EssenceExtensions.GetEssence(spawnCharacterData) == (Object)null;
		}
	}
}