Decompiled source of BossSouls v1.0.0

BepInEx\plugins\BossSouls.dll

Decompiled 6 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BossSouls.Buildings;
using BossSouls.Data;
using BossSouls.Data.Souls;
using BossSouls.Effects;
using BossSouls.Effects.Souls;
using BossSouls.Patches;
using BossSouls.UI;
using HarmonyLib;
using LootClicker;
using LootClicker.BuildingUpgrades;
using LootClicker.Entities;
using LootClicker.Entities.Buffs;
using LootClicker.Entities.Characters;
using LootClicker.Entities.Monsters;
using LootClicker.Entities.Skills;
using LootClicker.Items;
using LootClicker.Services;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BossSouls")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BossSouls")]
[assembly: AssemblyTitle("BossSouls")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BossSouls
{
	[BepInPlugin("com.corga.bosssouls", "Boss Souls", "1.0.0")]
	public class BossSoulsPlugin : BaseUnityPlugin
	{
		private static ConfigEntry<bool> _debugLogging;

		private static Harmony harmony;

		private static SoulSelectionPanel selectionPanel;

		public static ManualLogSource Log { get; private set; }

		public static bool DebugLogging { get; private set; }

		private void Awake()
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			_debugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableDebugLogging", false, "Log all soul effect events (buff apply/remove/expire, hits, procs)");
			DebugLogging = _debugLogging.Value;
			_debugLogging.SettingChanged += delegate
			{
				DebugLogging = _debugLogging.Value;
			};
			Log.LogInfo((object)"Boss Souls plugin loading...");
			SoulRegistry.Init();
			Log.LogInfo((object)$"Registered {SoulRegistry.All.Count} boss souls across {SoulRegistry.ByTier.Count} tiers.");
			harmony = new Harmony("com.corga.bosssouls");
			ApplyPatchSafe("BossKillPatches", delegate
			{
				BossKillPatches.Apply(harmony);
			});
			ApplyPatchSafe("EquipmentUIPatches", delegate
			{
				EquipmentUIPatches.Apply(harmony);
			});
			ApplyPatchSafe("SavePatches", delegate
			{
				SavePatches.Apply(harmony);
			});
			ApplyPatchSafe("BuildingPatches", delegate
			{
				BuildingPatches.Apply(harmony);
			});
			ApplyPatchSafe("SoulEffectPatches", delegate
			{
				SoulEffectPatches.Apply(harmony);
			});
			foreach (MethodBase patchedMethod in harmony.GetPatchedMethods())
			{
				Log.LogInfo((object)("  Patched: " + patchedMethod.DeclaringType?.Name + "." + patchedMethod.Name));
			}
			Log.LogInfo((object)"Boss Souls plugin loaded.");
			SoulSaveManager.Load();
		}

		private static void ApplyPatchSafe(string name, Action apply)
		{
			try
			{
				apply();
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Failed to apply {name}: {arg}");
			}
		}

		public static SoulSelectionPanel GetOrCreateSelectionPanel()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)selectionPanel != (Object)null)
			{
				return selectionPanel;
			}
			try
			{
				GameObject val = GameData.GameController?.Canvas;
				if ((Object)(object)val != (Object)null)
				{
					GameObject val2 = new GameObject("BossSoulsSelectionPanel");
					val2.transform.SetParent(val.transform, false);
					selectionPanel = val2.AddComponent<SoulSelectionPanel>();
					selectionPanel.Init(val.transform);
					Log.LogInfo((object)"Boss Souls selection panel created.");
				}
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Failed to create selection panel: {arg}");
			}
			return selectionPanel;
		}

		public static void RefreshEquipmentSlot()
		{
			EquipmentUIPatches.RefreshSlot();
			Character currentCharacter = GameData.CurrentCharacter;
			if (currentCharacter != null)
			{
				SoulEffectSystem.LoadPrimaryEffect(currentCharacter);
			}
		}

		public static void DumpFlaskPanel()
		{
			GameObject val = GameData.GameController?.Canvas;
			if ((Object)(object)val == (Object)null)
			{
				Log.LogWarning((object)"DumpFlaskPanel: Canvas not found.");
				return;
			}
			SelectFlaskController val2 = null;
			SelectFlaskController[] componentsInChildren = val.GetComponentsInChildren<SelectFlaskController>(true);
			int num = 0;
			if (num < componentsInChildren.Length)
			{
				val2 = componentsInChildren[num];
			}
			if ((Object)(object)val2 == (Object)null)
			{
				Log.LogWarning((object)"DumpFlaskPanel: SelectFlaskController not found in canvas hierarchy.");
				return;
			}
			Log.LogInfo((object)"=== FLASK PANEL HIERARCHY DUMP ===");
			DumpTransform(((Component)val2).transform, 0);
			Log.LogInfo((object)"=== END FLASK PANEL DUMP ===");
		}

		private static void DumpTransform(Transform t, int depth)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			string arg = new string(' ', depth * 2);
			GameObject gameObject = ((Component)t).gameObject;
			string text = $"{arg}[{((Object)gameObject).name}] active={gameObject.activeSelf}";
			RectTransform component = gameObject.GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				text += $" anchMin={component.anchorMin} anchMax={component.anchorMax} pos={component.anchoredPosition} size={component.sizeDelta} pivot={component.pivot}";
			}
			Image component2 = gameObject.GetComponent<Image>();
			if ((Object)(object)component2 != (Object)null)
			{
				string text2 = text;
				Sprite sprite = component2.sprite;
				text = text2 + string.Format(" IMG(sprite={0} type={1} color={2})", ((sprite != null) ? ((Object)sprite).name : null) ?? "null", component2.type, ((Graphic)component2).color);
			}
			TMP_Text component3 = gameObject.GetComponent<TMP_Text>();
			if ((Object)(object)component3 != (Object)null)
			{
				text += $" TXT(\"{component3.text}\" size={component3.fontSize} align={component3.alignment})";
			}
			if ((Object)(object)gameObject.GetComponent<Button>() != (Object)null)
			{
				text += " BTN";
			}
			LayoutGroup component4 = gameObject.GetComponent<LayoutGroup>();
			if ((Object)(object)component4 != (Object)null)
			{
				text = text + " LAYOUT(" + ((object)component4).GetType().Name + ")";
			}
			LayoutElement component5 = gameObject.GetComponent<LayoutElement>();
			if ((Object)(object)component5 != (Object)null)
			{
				text += $" LE(pref={component5.preferredHeight} min={component5.minHeight} flex={component5.flexibleHeight})";
			}
			if ((Object)(object)gameObject.GetComponent<Mask>() != (Object)null)
			{
				text += " MASK";
			}
			if ((Object)(object)gameObject.GetComponent<ScrollRect>() != (Object)null)
			{
				text += " SCROLL";
			}
			CanvasGroup component6 = gameObject.GetComponent<CanvasGroup>();
			if ((Object)(object)component6 != (Object)null)
			{
				text += $" CG(alpha={component6.alpha})";
			}
			Log.LogInfo((object)text);
			for (int i = 0; i < t.childCount; i++)
			{
				DumpTransform(t.GetChild(i), depth + 1);
			}
		}
	}
	public static class SpriteHelper
	{
		private static readonly Dictionary<string, Sprite> _cache = new Dictionary<string, Sprite>();

		public static Sprite LoadEmbedded(string resourceName)
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			if (_cache.TryGetValue(resourceName, out var value))
			{
				return value;
			}
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string text = "BossSouls." + resourceName + ".png";
			using Stream stream = executingAssembly.GetManifestResourceStream(text);
			if (stream == null)
			{
				ManualLogSource log = BossSoulsPlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("[SpriteHelper] Embedded resource not found: " + text));
				}
				return null;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			((Texture)val).filterMode = (FilterMode)1;
			if (!ImageConversion.LoadImage(val, array))
			{
				ManualLogSource log2 = BossSoulsPlugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)("[SpriteHelper] Failed to decode image: " + text));
				}
				return null;
			}
			Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
			((Object)val2).name = resourceName;
			_cache[resourceName] = val2;
			return val2;
		}
	}
}
namespace BossSouls.UI
{
	public class BuildCardSoulController : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
	{
		private Image[] slotBgs = (Image[])(object)new Image[4];

		private Image[] slotIcons = (Image[])(object)new Image[4];

		private string characterName;

		private const float SlotSize = 38f;

		private const float IconSize = 32f;

		private const float Spacing = 4f;

		public void BuildSlots()
		{
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: 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_0153: Unknown result type (might be due to invalid IL or missing references)
			HorizontalLayoutGroup obj = ((Component)this).gameObject.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 4f;
			((LayoutGroup)obj).childAlignment = (TextAnchor)3;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = false;
			for (int i = 0; i < 4; i++)
			{
				GameObject val = new GameObject((i == 0) ? "PrimarySoul" : $"SecondarySoul{i}");
				val.transform.SetParent(((Component)this).transform, false);
				val.AddComponent<RectTransform>().sizeDelta = new Vector2(38f, 38f);
				Image val2 = val.AddComponent<Image>();
				val2.sprite = GameData.GameController.DefaultBackground;
				((Graphic)val2).color = ((i == 0) ? new Color(1f, 0.9f, 0.5f, 1f) : new Color(0.6f, 0.8f, 0.6f, 1f));
				slotBgs[i] = val2;
				GameObject val3 = new GameObject("Icon");
				val3.transform.SetParent(val.transform, false);
				RectTransform obj2 = val3.AddComponent<RectTransform>();
				obj2.sizeDelta = new Vector2(32f, 32f);
				obj2.anchoredPosition = Vector2.zero;
				obj2.anchorMin = new Vector2(0.5f, 0.5f);
				obj2.anchorMax = new Vector2(0.5f, 0.5f);
				Image val4 = val3.AddComponent<Image>();
				val4.preserveAspect = true;
				val3.SetActive(false);
				slotIcons[i] = val4;
			}
			RectTransform component = ((Component)this).GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				component.sizeDelta = new Vector2(164f, 38f);
			}
		}

		public void Refresh(Character character)
		{
			//IL_004b: 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)
			characterName = ((character != null) ? ((Entity)character).Name : null);
			if (string.IsNullOrEmpty(characterName))
			{
				ClearAll();
				return;
			}
			BossSoulsSaveData data = SoulSaveManager.Data;
			if (!data.PrimaryUnlocked)
			{
				ClearAll();
				return;
			}
			CharacterSoulEquip orCreateEquip = data.GetOrCreateEquip(characterName);
			SetSlot(0, orCreateEquip.Primary);
			for (int i = 0; i < 3; i++)
			{
				SetSlot(i + 1, orCreateEquip.GetSecondary(i));
			}
		}

		private void SetSlot(int idx, MonsterID bossId)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if ((int)bossId != 0 && SoulRegistry.All.TryGetValue(bossId, out var value) && MonsterStore.MonsterDatabase.TryGetValue(value.BossId, out var value2) && value2 != null)
			{
				slotIcons[idx].sprite = ((Entity)value2).Icon;
				((Component)slotIcons[idx]).gameObject.SetActive(true);
				slotBgs[idx].sprite = GameData.GameController.GoldBackground;
			}
			else
			{
				slotIcons[idx].sprite = null;
				((Component)slotIcons[idx]).gameObject.SetActive(false);
				slotBgs[idx].sprite = GameData.GameController.DefaultBackground;
			}
		}

		private void ClearAll()
		{
			for (int i = 0; i < 4; i++)
			{
				slotIcons[i].sprite = null;
				((Component)slotIcons[i]).gameObject.SetActive(false);
				slotBgs[i].sprite = GameData.GameController.DefaultBackground;
			}
		}

		public void OnPointerEnter(PointerEventData eventData)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(characterName))
			{
				return;
			}
			BossSoulsSaveData data = SoulSaveManager.Data;
			if (!data.PrimaryUnlocked)
			{
				return;
			}
			CharacterSoulEquip orCreateEquip = data.GetOrCreateEquip(characterName);
			if ((int)orCreateEquip.Primary == 0)
			{
				return;
			}
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine("<color=#FFE884><b>Boss Souls</b></color>");
			if (SoulRegistry.All.TryGetValue(orCreateEquip.Primary, out var value))
			{
				SoulState orCreate = data.GetOrCreate(orCreateEquip.Primary);
				stringBuilder.AppendLine();
				stringBuilder.AppendLine("<color=#FFE884>PRIMARY — " + value.PrimaryName + "</color>  <color=#888888>(" + value.Name + ")</color>");
				stringBuilder.AppendLine(value.GetPrimaryDesc(orCreate.MasteryLevel));
			}
			for (int i = 0; i < 3; i++)
			{
				MonsterID secondary = orCreateEquip.GetSecondary(i);
				if ((int)secondary != 0 && SoulRegistry.All.TryGetValue(secondary, out var value2))
				{
					SoulState orCreate2 = data.GetOrCreate(secondary);
					stringBuilder.AppendLine();
					stringBuilder.AppendLine("<color=#95FF6D>SECONDARY</color>  <color=#888888>(" + value2.Name + ")</color>");
					stringBuilder.AppendLine(value2.GetSecondaryDesc(orCreate2.MasteryLevel));
				}
			}
			GameData.GameController.Tooltip.Activate(stringBuilder.ToString(), false, true, false, false);
		}

		public void OnPointerExit(PointerEventData eventData)
		{
			GameData.GameController.Tooltip.Deactivate();
		}
	}
	public class SoulEquipSlot : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler, IPointerClickHandler
	{
		private int slotIndex;

		private SoulSelectionPanel panel;

		private Image background;

		private Image borderFrame;

		private Image icon;

		private GameObject lockOverlay;

		private bool unlocked;

		private bool highlighted;

		private MonsterID currentSoul;

		public void Init(int slotIndex, SoulSelectionPanel panel)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00ed: Expected O, but got Unknown
			//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_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Expected O, but got Unknown
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			this.slotIndex = slotIndex;
			this.panel = panel;
			background = ((Component)this).gameObject.AddComponent<Image>();
			background.sprite = GameData.GameController.DefaultBackground;
			background.type = (Type)1;
			((Graphic)background).color = Color.white;
			GameObject val = new GameObject("Icon");
			val.transform.SetParent(((Component)this).transform, false);
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.anchorMin = new Vector2(0.1f, 0.1f);
			obj.anchorMax = new Vector2(0.9f, 0.9f);
			obj.offsetMin = Vector2.zero;
			obj.offsetMax = Vector2.zero;
			val.AddComponent<CanvasRenderer>();
			icon = val.AddComponent<Image>();
			icon.preserveAspect = true;
			((Component)icon).gameObject.SetActive(false);
			GameObject val2 = new GameObject("Border");
			val2.transform.SetParent(((Component)this).transform, false);
			RectTransform obj2 = val2.AddComponent<RectTransform>();
			obj2.anchorMin = Vector2.zero;
			obj2.anchorMax = Vector2.one;
			obj2.offsetMin = Vector2.zero;
			obj2.offsetMax = Vector2.zero;
			val2.AddComponent<CanvasRenderer>();
			borderFrame = val2.AddComponent<Image>();
			borderFrame.sprite = GameData.GameController.UnlockedBorder;
			borderFrame.type = (Type)1;
			((Graphic)borderFrame).raycastTarget = false;
			lockOverlay = new GameObject("Lock");
			lockOverlay.transform.SetParent(((Component)this).transform, false);
			RectTransform obj3 = lockOverlay.AddComponent<RectTransform>();
			obj3.anchorMin = new Vector2(0.2f, 0.2f);
			obj3.anchorMax = new Vector2(0.8f, 0.8f);
			obj3.offsetMin = Vector2.zero;
			obj3.offsetMax = Vector2.zero;
			lockOverlay.AddComponent<CanvasRenderer>();
			Image obj4 = lockOverlay.AddComponent<Image>();
			obj4.sprite = GameData.GameController.Locked;
			obj4.preserveAspect = true;
			lockOverlay.SetActive(false);
		}

		public void Refresh(MonsterID soulId, bool isUnlocked)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: 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_00bb: 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)
			unlocked = isUnlocked;
			currentSoul = soulId;
			if (!unlocked)
			{
				((Component)icon).gameObject.SetActive(false);
				lockOverlay.SetActive(true);
				background.sprite = GameData.GameController.DefaultBackground;
				((Graphic)background).color = Color.white;
				borderFrame.sprite = GameData.GameController.LockedBorder;
				return;
			}
			lockOverlay.SetActive(false);
			borderFrame.sprite = GameData.GameController.UnlockedBorder;
			if ((int)soulId != 0 && MonsterStore.MonsterDatabase.TryGetValue(soulId, out var value) && value != null)
			{
				icon.sprite = ((Entity)value).Icon;
				((Graphic)icon).color = Color.white;
				((Component)icon).gameObject.SetActive(true);
				background.sprite = GameData.GameController.GoldBackground;
				((Graphic)background).color = Color.white;
			}
			else
			{
				icon.sprite = GameData.GameController.AddNew;
				((Graphic)icon).color = new Color(1f, 1f, 1f, 0.3f);
				((Component)icon).gameObject.SetActive(true);
				background.sprite = GameData.GameController.DefaultBackground;
				((Graphic)background).color = Color.white;
			}
		}

		public void SetHighlighted(bool hl)
		{
			//IL_003e: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			highlighted = hl;
			if (hl && unlocked)
			{
				background.sprite = (((int)currentSoul != 0) ? GameData.GameController.GoldMenuBackground : GameData.GameController.MenuBackground);
			}
			else if ((int)currentSoul != 0)
			{
				background.sprite = GameData.GameController.GoldBackground;
			}
			else
			{
				background.sprite = GameData.GameController.DefaultBackground;
			}
			((Graphic)background).color = Color.white;
		}

		public void OnPointerEnter(PointerEventData eventData)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: 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)
			if (!unlocked)
			{
				int num = ((slotIndex == 0) ? 1 : (slotIndex + 1));
				GameData.GameController.Tooltip.Activate($"Upgrade <color=#FFE884>Soul Altar</color> to rank {num} to unlock this slot.", false, false, false, false);
				return;
			}
			if ((int)currentSoul != 0 && SoulRegistry.All.TryGetValue(currentSoul, out var value))
			{
				SoulState orCreate = SoulSaveManager.Data.GetOrCreate(currentSoul);
				StringBuilder stringBuilder = new StringBuilder();
				string text = ((slotIndex == 0) ? "PRIMARY" : "SECONDARY");
				stringBuilder.AppendLine("<color=#FFE884><b>" + value.Name + "</b></color> (" + text + ")");
				if (slotIndex == 0)
				{
					stringBuilder.AppendLine("<color=#FFE884>" + value.PrimaryName + "</color>");
					stringBuilder.AppendLine(value.GetPrimaryDesc(orCreate.MasteryLevel));
				}
				else
				{
					stringBuilder.AppendLine(value.GetSecondaryDesc(orCreate.MasteryLevel));
				}
				stringBuilder.AppendLine();
				stringBuilder.Append("<color=#888888>Right-click to remove</color>");
				GameData.GameController.Tooltip.Activate(stringBuilder.ToString(), false, true, false, false);
			}
			else
			{
				string text2 = ((slotIndex == 0) ? "Primary" : "Secondary");
				GameData.GameController.Tooltip.Activate("<color=#888888>Empty " + text2 + " slot — click a soul below to equip it here.</color>", false, false, false, false);
			}
			if (unlocked)
			{
				background.sprite = (((int)currentSoul != 0) ? GameData.GameController.GoldMenuBackground : GameData.GameController.MenuBackground);
				((Graphic)background).color = Color.white;
			}
		}

		public void OnPointerExit(PointerEventData eventData)
		{
			GameData.GameController.Tooltip.Deactivate();
			SetHighlighted(highlighted);
		}

		public void OnPointerClick(PointerEventData eventData)
		{
			//IL_000a: 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)
			//IL_002a: Invalid comparison between Unknown and I4
			if (unlocked)
			{
				if ((int)eventData.button == 0)
				{
					panel.OnSlotClicked(slotIndex);
				}
				else if ((int)eventData.button == 1)
				{
					panel.OnSlotRightClicked(slotIndex);
				}
			}
		}
	}
	public class SoulGridIcon : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler, IPointerClickHandler
	{
		private SoulDef soul;

		private SoulSelectionPanel panel;

		private Image background;

		private Image borderFrame;

		private Image icon;

		private bool forged;

		private SoulState state;

		public void Init(SoulDef soul, SoulSelectionPanel panel)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_016c: Unknown result type (might be due to invalid IL or missing references)
			this.soul = soul;
			this.panel = panel;
			background = ((Component)this).gameObject.AddComponent<Image>();
			background.sprite = GameData.GameController.DefaultBackground;
			background.type = (Type)1;
			((Graphic)background).color = Color.white;
			GameObject val = new GameObject("Icon");
			val.transform.SetParent(((Component)this).transform, false);
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.anchorMin = new Vector2(0.1f, 0.1f);
			obj.anchorMax = new Vector2(0.9f, 0.9f);
			obj.offsetMin = Vector2.zero;
			obj.offsetMax = Vector2.zero;
			val.AddComponent<CanvasRenderer>();
			icon = val.AddComponent<Image>();
			icon.preserveAspect = true;
			GameObject val2 = new GameObject("Border");
			val2.transform.SetParent(((Component)this).transform, false);
			RectTransform obj2 = val2.AddComponent<RectTransform>();
			obj2.anchorMin = Vector2.zero;
			obj2.anchorMax = Vector2.one;
			obj2.offsetMin = Vector2.zero;
			obj2.offsetMax = Vector2.zero;
			val2.AddComponent<CanvasRenderer>();
			borderFrame = val2.AddComponent<Image>();
			borderFrame.sprite = GameData.GameController.UnlockedBorder;
			borderFrame.type = (Type)1;
			((Graphic)borderFrame).raycastTarget = false;
			if (MonsterStore.MonsterDatabase != null && MonsterStore.MonsterDatabase.TryGetValue(soul.BossId, out var value) && (Object)(object)((value != null) ? ((Entity)value).Icon : null) != (Object)null)
			{
				icon.sprite = ((Entity)value).Icon;
			}
		}

		public void Refresh(SoulState state)
		{
			//IL_00f0: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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)
			this.state = state;
			forged = state.Forged;
			if (forged)
			{
				if (MonsterStore.MonsterDatabase.TryGetValue(soul.BossId, out var value) && (Object)(object)((value != null) ? ((Entity)value).Icon : null) != (Object)null)
				{
					icon.sprite = ((Entity)value).Icon;
				}
				((Graphic)icon).color = Color.white;
				Character currentCharacter = GameData.CurrentCharacter;
				string text = ((currentCharacter != null) ? ((Entity)currentCharacter).Name : null);
				bool flag = text != null && SoulSaveManager.Data.GetOrCreateEquip(text).HasSoul(soul.BossId);
				background.sprite = (flag ? GameData.GameController.GoldBackground : GameData.GameController.DefaultBackground);
				((Graphic)background).color = Color.white;
			}
			else
			{
				icon.sprite = GameData.GameController.Unknown;
				((Graphic)icon).color = Color.white;
				background.sprite = GameData.GameController.DefaultBackground;
				((Graphic)background).color = Color.white;
			}
		}

		public void OnPointerEnter(PointerEventData eventData)
		{
			if (state == null)
			{
				return;
			}
			StringBuilder stringBuilder = new StringBuilder();
			if (forged)
			{
				int masteryLevel = state.MasteryLevel;
				if (SoulSaveManager.Data.MasteryUnlocked)
				{
					long killsForNextLevel = state.KillsForNextLevel;
					string text = ((masteryLevel == 0) ? "Base" : masteryLevel.ToString());
					stringBuilder.AppendLine("<color=#FFE884><b>" + soul.Name + "</b></color>  <color=#95FF6D>Mastery " + text + "</color>");
					stringBuilder.AppendLine($"<color=#888888>Next level: {state.MasteryKills:N0}/{killsForNextLevel:N0} kills</color>");
					if (state.MasteryBonusPermille > 0)
					{
						stringBuilder.AppendLine($"<color=#95FF6D>+{(double)state.MasteryBonusPermille / 10.0:0.#}% effect strength</color>");
					}
				}
				else
				{
					stringBuilder.AppendLine("<color=#FFE884><b>" + soul.Name + "</b></color>");
				}
				stringBuilder.AppendLine();
				stringBuilder.AppendLine("<color=#FFE884>PRIMARY — " + soul.PrimaryName + "</color>");
				stringBuilder.AppendLine(soul.GetPrimaryDesc(masteryLevel));
				stringBuilder.AppendLine();
				stringBuilder.AppendLine("<color=#95FF6D>SECONDARY</color>");
				stringBuilder.AppendLine(soul.GetSecondaryDesc(masteryLevel));
			}
			else
			{
				stringBuilder.AppendLine("<color=#888888><b>" + soul.Name + "</b></color>");
				stringBuilder.AppendLine($"<color=#FF6666>Not forged — {state.KillCount}/{soul.ForgeKills} kills</color>");
				stringBuilder.AppendLine();
				stringBuilder.Append($"<color=#888888>Kill this boss {soul.ForgeKills - state.KillCount} more times to forge this soul.</color>");
			}
			GameData.GameController.Tooltip.Activate(stringBuilder.ToString(), false, true, false, false);
			if (forged)
			{
				background.sprite = GameData.GameController.MenuBackground;
			}
		}

		public void OnPointerExit(PointerEventData eventData)
		{
			GameData.GameController.Tooltip.Deactivate();
			if (state != null)
			{
				Refresh(state);
			}
		}

		public void OnPointerClick(PointerEventData eventData)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if ((int)eventData.button == 0)
			{
				panel.OnSoulIconClicked(soul);
			}
		}
	}
	public class SoulSelectionPanel : MonoBehaviour
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__22_0;

			internal void <BuildPanel>b__22_0()
			{
			}
		}

		private GameObject panel;

		private RectTransform panelRect;

		private SoulEquipSlot primarySlot;

		private SoulEquipSlot[] secondarySlots = new SoulEquipSlot[3];

		private GameObject scrollContent;

		private ScrollRect scrollRect;

		private Dictionary<MonsterID, SoulGridIcon> gridIcons = new Dictionary<MonsterID, SoulGridIcon>();

		private bool isOpen;

		private int pendingSlotIndex = -1;

		private TextMeshProUGUI statusText;

		private float statusClearTime;

		private static Sprite borderBgSprite;

		private static Sprite textBgSprite;

		public static SoulSelectionPanel Instance { get; private set; }

		public void Init(Transform canvasTransform)
		{
			Instance = this;
			StealSprites(canvasTransform);
			try
			{
				BuildPanel(canvasTransform);
			}
			catch (Exception arg)
			{
				BossSoulsPlugin.Log.LogError((object)$"SoulSelectionPanel.BuildPanel failed: {arg}");
			}
			ManualLogSource log = BossSoulsPlugin.Log;
			object arg2 = gridIcons.Count;
			Sprite obj = borderBgSprite;
			string arg3 = ((obj != null) ? ((Object)obj).name : null);
			Sprite obj2 = textBgSprite;
			log.LogInfo((object)$"SoulSelectionPanel.Init: gridIcons={arg2} borderBg={arg3} textBg={((obj2 != null) ? ((Object)obj2).name : null)}");
			panel.SetActive(false);
		}

		public void Open()
		{
			if (GameData.CurrentCharacter != null)
			{
				pendingSlotIndex = -1;
				RefreshAll();
				panel.SetActive(true);
				isOpen = true;
			}
		}

		public void Close()
		{
			panel.SetActive(false);
			isOpen = false;
			pendingSlotIndex = -1;
		}

		private void Update()
		{
			if (isOpen && Input.GetKeyDown((KeyCode)27))
			{
				Close();
			}
			if ((Object)(object)statusText != (Object)null && statusClearTime > 0f && Time.time >= statusClearTime)
			{
				((TMP_Text)statusText).text = "";
				statusClearTime = 0f;
			}
		}

		private static void StealSprites(Transform canvasTransform)
		{
			if ((Object)(object)borderBgSprite != (Object)null && (Object)(object)textBgSprite != (Object)null)
			{
				return;
			}
			SelectFlaskController[] componentsInChildren = ((Component)canvasTransform).GetComponentsInChildren<SelectFlaskController>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Transform val = ((Component)componentsInChildren[i]).transform.Find("SelectionPanel");
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Transform val2 = val.Find("TitleGroup");
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Transform val3 = val2.Find("TitlePanel");
				if ((Object)(object)val3 != (Object)null)
				{
					Image component = ((Component)val3).GetComponent<Image>();
					if ((Object)(object)((component != null) ? component.sprite : null) != (Object)null && (Object)(object)borderBgSprite == (Object)null)
					{
						borderBgSprite = component.sprite;
					}
				}
				Transform val4 = val2.Find("TitlePanel/TitleBackground");
				if ((Object)(object)val4 != (Object)null)
				{
					Image component2 = ((Component)val4).GetComponent<Image>();
					if ((Object)(object)((component2 != null) ? component2.sprite : null) != (Object)null && (Object)(object)textBgSprite == (Object)null)
					{
						textBgSprite = component2.sprite;
					}
				}
				break;
			}
			ManualLogSource log = BossSoulsPlugin.Log;
			Sprite obj = borderBgSprite;
			string obj2 = ((obj != null) ? ((Object)obj).name : null) ?? "null";
			Sprite obj3 = textBgSprite;
			log.LogInfo((object)("StealSprites: borderBg=" + obj2 + " textBg=" + (((obj3 != null) ? ((Object)obj3).name : null) ?? "null")));
		}

		private void BuildPanel(Transform parent)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00b1: Expected O, but got Unknown
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: 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_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0417: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Expected O, but got Unknown
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_049c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_051e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0561: Unknown result type (might be due to invalid IL or missing references)
			//IL_0576: Unknown result type (might be due to invalid IL or missing references)
			//IL_058b: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0616: Unknown result type (might be due to invalid IL or missing references)
			//IL_0621: Unknown result type (might be due to invalid IL or missing references)
			//IL_0636: Unknown result type (might be due to invalid IL or missing references)
			//IL_064a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c6: Expected O, but got Unknown
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Expected O, but got Unknown
			//IL_0762: Unknown result type (might be due to invalid IL or missing references)
			//IL_076c: Expected O, but got Unknown
			//IL_07fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0812: Unknown result type (might be due to invalid IL or missing references)
			//IL_081d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0831: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_090e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0944: Unknown result type (might be due to invalid IL or missing references)
			//IL_094f: Unknown result type (might be due to invalid IL or missing references)
			//IL_095a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0964: Unknown result type (might be due to invalid IL or missing references)
			//IL_0989: Unknown result type (might be due to invalid IL or missing references)
			//IL_0995: Unknown result type (might be due to invalid IL or missing references)
			//IL_09a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a27: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a33: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a49: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a5f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a84: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b04: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b10: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b1c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b43: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b4d: Expected O, but got Unknown
			//IL_0c6c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c81: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cd2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e21: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dcf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0de4: Unknown result type (might be due to invalid IL or missing references)
			Sprite val = borderBgSprite ?? GameData.GameController.DefaultBackground;
			Sprite sprite = textBgSprite ?? val;
			GameObject val2 = new GameObject("BossSoulsOverlay");
			val2.transform.SetParent(parent, false);
			RectTransform val3 = val2.AddComponent<RectTransform>();
			val3.anchorMin = Vector2.zero;
			val3.anchorMax = Vector2.one;
			val3.offsetMin = Vector2.zero;
			val3.offsetMax = Vector2.zero;
			val2.AddComponent<CanvasRenderer>();
			((Graphic)val2.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.59f);
			((UnityEvent)val2.AddComponent<Button>().onClick).AddListener(new UnityAction(Close));
			panel = val2;
			panelRect = val3;
			GameObject val4 = MakeGO("SelectionPanel", val2.transform);
			RectTransform component = val4.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0.5f, 0.5f);
			component.anchorMax = new Vector2(0.5f, 0.5f);
			component.sizeDelta = new Vector2(560f, 620f);
			component.anchoredPosition = Vector2.zero;
			((Graphic)val4.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0f);
			Button obj = val4.AddComponent<Button>();
			((Selectable)obj).transition = (Transition)0;
			ButtonClickedEvent onClick = obj.onClick;
			object obj2 = <>c.<>9__22_0;
			if (obj2 == null)
			{
				UnityAction val5 = delegate
				{
				};
				<>c.<>9__22_0 = val5;
				obj2 = (object)val5;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj2);
			GameObject val6 = MakeGO("TitleGroup", val4.transform);
			RectTransform component2 = val6.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0f, 1f);
			component2.anchorMax = new Vector2(1f, 1f);
			component2.pivot = new Vector2(0.5f, 1f);
			component2.offsetMin = new Vector2(0f, -28f);
			component2.offsetMax = Vector2.zero;
			GameObject val7 = MakeGO("TitlePanel", val6.transform);
			RectTransform component3 = val7.GetComponent<RectTransform>();
			component3.anchorMin = Vector2.zero;
			component3.anchorMax = Vector2.one;
			component3.offsetMin = Vector2.zero;
			component3.offsetMax = new Vector2(-28f, 0f);
			Image obj3 = val7.AddComponent<Image>();
			obj3.sprite = val;
			obj3.type = (Type)1;
			GameObject obj4 = MakeGO("TitleBackground", val7.transform);
			RectTransform component4 = obj4.GetComponent<RectTransform>();
			component4.anchorMin = Vector2.zero;
			component4.anchorMax = Vector2.one;
			component4.offsetMin = new Vector2(3f, 3f);
			component4.offsetMax = new Vector2(-3f, -3f);
			Image obj5 = obj4.AddComponent<Image>();
			obj5.sprite = sprite;
			obj5.type = (Type)1;
			GameObject obj6 = MakeGO("Title", val7.transform);
			RectTransform component5 = obj6.GetComponent<RectTransform>();
			component5.anchorMin = Vector2.zero;
			component5.anchorMax = Vector2.one;
			component5.offsetMin = new Vector2(3f, 0f);
			component5.offsetMax = new Vector2(-3f, -3f);
			TextMeshProUGUI obj7 = obj6.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj7).text = "Boss Souls";
			((TMP_Text)obj7).fontSize = 14.4f;
			((TMP_Text)obj7).alignment = (TextAlignmentOptions)514;
			((Graphic)obj7).color = Color.white;
			GameObject val8 = MakeGO("ButtonExitSelection", val6.transform);
			RectTransform component6 = val8.GetComponent<RectTransform>();
			component6.anchorMin = new Vector2(1f, 0f);
			component6.anchorMax = Vector2.one;
			component6.offsetMin = new Vector2(-28f, 0f);
			component6.offsetMax = Vector2.zero;
			Image val9 = val8.AddComponent<Image>();
			val9.sprite = val;
			val9.type = (Type)1;
			Button obj8 = val8.AddComponent<Button>();
			((Selectable)obj8).targetGraphic = (Graphic)(object)val9;
			((Selectable)obj8).transition = (Transition)1;
			ColorBlock colors = ((Selectable)obj8).colors;
			((ColorBlock)(ref colors)).highlightedColor = new Color(0.85f, 0.55f, 0.55f, 1f);
			((ColorBlock)(ref colors)).pressedColor = new Color(1f, 0.4f, 0.4f, 1f);
			((Selectable)obj8).colors = colors;
			((UnityEvent)obj8.onClick).AddListener(new UnityAction(Close));
			GameObject obj9 = MakeGO("Text", val8.transform);
			RectTransform component7 = obj9.GetComponent<RectTransform>();
			component7.anchorMin = Vector2.zero;
			component7.anchorMax = Vector2.one;
			component7.offsetMin = Vector2.zero;
			component7.offsetMax = Vector2.zero;
			TextMeshProUGUI obj10 = obj9.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj10).text = "X";
			((TMP_Text)obj10).fontSize = 18f;
			((TMP_Text)obj10).alignment = (TextAlignmentOptions)514;
			((Graphic)obj10).color = Color.white;
			GameObject val10 = MakeGO("EquipPanel", val4.transform);
			RectTransform component8 = val10.GetComponent<RectTransform>();
			component8.anchorMin = new Vector2(0f, 1f);
			component8.anchorMax = new Vector2(1f, 1f);
			component8.pivot = new Vector2(0.5f, 1f);
			component8.offsetMin = new Vector2(0f, -144f);
			component8.offsetMax = new Vector2(0f, -30f);
			Image obj11 = val10.AddComponent<Image>();
			obj11.sprite = val;
			obj11.type = (Type)1;
			GameObject val11 = MakeGO("StatusText", val10.transform);
			RectTransform component9 = val11.GetComponent<RectTransform>();
			component9.anchorMin = new Vector2(0f, 1f);
			component9.anchorMax = new Vector2(1f, 1f);
			component9.pivot = new Vector2(0.5f, 1f);
			component9.offsetMin = new Vector2(8f, -18f);
			component9.offsetMax = new Vector2(-8f, -4f);
			statusText = val11.AddComponent<TextMeshProUGUI>();
			((TMP_Text)statusText).fontSize = 11f;
			((TMP_Text)statusText).alignment = (TextAlignmentOptions)514;
			((TMP_Text)statusText).text = "";
			GameObject val12 = MakeGO("SlotsRow", val10.transform);
			RectTransform component10 = val12.GetComponent<RectTransform>();
			component10.anchorMin = Vector2.zero;
			component10.anchorMax = Vector2.one;
			component10.offsetMin = new Vector2(6f, 4f);
			component10.offsetMax = new Vector2(-6f, -16f);
			HorizontalLayoutGroup obj12 = val12.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj12).spacing = 8f;
			((LayoutGroup)obj12).childAlignment = (TextAnchor)4;
			((HorizontalOrVerticalLayoutGroup)obj12).childControlWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj12).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj12).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj12).childForceExpandHeight = true;
			GameObject val13 = CreatePanel("PrimaryGroup", val12.transform, 60f, 60f);
			VerticalLayoutGroup obj13 = val13.AddComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj13).spacing = 0f;
			((LayoutGroup)obj13).padding = new RectOffset(0, 0, 2, 2);
			((LayoutGroup)obj13).childAlignment = (TextAnchor)1;
			((HorizontalOrVerticalLayoutGroup)obj13).childControlWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj13).childControlHeight = false;
			((Component)CreateText("Primary", val13.transform, 11, (TextAlignmentOptions)514, "#FFE884")).GetComponent<LayoutElement>().preferredHeight = 6f;
			primarySlot = CreateEquipSlot(val13.transform, 0);
			for (int i = 0; i < 3; i++)
			{
				GameObject val14 = CreatePanel($"SecondaryGroup{i}", val12.transform, 60f, 60f);
				VerticalLayoutGroup obj14 = val14.AddComponent<VerticalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)obj14).spacing = 0f;
				((LayoutGroup)obj14).padding = new RectOffset(0, 0, 2, 2);
				((LayoutGroup)obj14).childAlignment = (TextAnchor)1;
				((HorizontalOrVerticalLayoutGroup)obj14).childControlWidth = false;
				((HorizontalOrVerticalLayoutGroup)obj14).childControlHeight = false;
				((Component)CreateText($"Sec {i + 1}", val14.transform, 11, (TextAlignmentOptions)514, "#95FF6D")).GetComponent<LayoutElement>().preferredHeight = 6f;
				secondarySlots[i] = CreateEquipSlot(val14.transform, i + 1);
			}
			GameObject val15 = MakeGO("GridPanel", val4.transform);
			RectTransform component11 = val15.GetComponent<RectTransform>();
			component11.anchorMin = Vector2.zero;
			component11.anchorMax = new Vector2(1f, 1f);
			component11.offsetMin = Vector2.zero;
			component11.offsetMax = new Vector2(0f, -146f);
			Image obj15 = val15.AddComponent<Image>();
			obj15.sprite = val;
			obj15.type = (Type)1;
			scrollRect = val15.AddComponent<ScrollRect>();
			scrollRect.horizontal = false;
			scrollRect.vertical = true;
			scrollRect.movementType = (MovementType)2;
			scrollRect.scrollSensitivity = 30f;
			GameObject val16 = MakeGO("Scrollbar", val15.transform);
			RectTransform component12 = val16.GetComponent<RectTransform>();
			component12.anchorMin = new Vector2(1f, 0f);
			component12.anchorMax = Vector2.one;
			component12.offsetMin = new Vector2(-10f, 4f);
			component12.offsetMax = new Vector2(-3f, -4f);
			((Graphic)val16.AddComponent<Image>()).color = new Color(0.15f, 0.15f, 0.18f, 0.5f);
			Scrollbar val17 = val16.AddComponent<Scrollbar>();
			val17.direction = (Direction)2;
			GameObject val18 = MakeGO("HandleArea", val16.transform);
			RectTransform component13 = val18.GetComponent<RectTransform>();
			component13.anchorMin = Vector2.zero;
			component13.anchorMax = Vector2.one;
			component13.offsetMin = Vector2.zero;
			component13.offsetMax = Vector2.zero;
			GameObject obj16 = MakeGO("Handle", val18.transform);
			RectTransform component14 = obj16.GetComponent<RectTransform>();
			component14.anchorMin = Vector2.zero;
			component14.anchorMax = Vector2.one;
			component14.offsetMin = Vector2.zero;
			component14.offsetMax = Vector2.zero;
			Image val19 = obj16.AddComponent<Image>();
			((Graphic)val19).color = new Color(0.5f, 0.5f, 0.55f, 0.8f);
			val17.handleRect = component14;
			((Selectable)val17).targetGraphic = (Graphic)(object)val19;
			scrollRect.verticalScrollbar = val17;
			scrollRect.verticalScrollbarVisibility = (ScrollbarVisibility)1;
			GameObject val20 = MakeGO("Viewport", val15.transform);
			RectTransform component15 = val20.GetComponent<RectTransform>();
			component15.anchorMin = Vector2.zero;
			component15.anchorMax = Vector2.one;
			component15.offsetMin = new Vector2(8f, 8f);
			component15.offsetMax = new Vector2(-14f, -8f);
			((Graphic)val20.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.01f);
			val20.AddComponent<Mask>().showMaskGraphic = false;
			scrollRect.viewport = component15;
			scrollContent = MakeGO("ScrollContent", val20.transform);
			RectTransform component16 = scrollContent.GetComponent<RectTransform>();
			component16.anchorMin = new Vector2(0f, 1f);
			component16.anchorMax = new Vector2(1f, 1f);
			component16.pivot = new Vector2(0.5f, 1f);
			component16.offsetMin = Vector2.zero;
			component16.offsetMax = Vector2.zero;
			scrollRect.content = component16;
			VerticalLayoutGroup obj17 = scrollContent.AddComponent<VerticalLayoutGroup>();
			((LayoutGroup)obj17).padding = new RectOffset(8, 8, 8, 8);
			((HorizontalOrVerticalLayoutGroup)obj17).spacing = 4f;
			((LayoutGroup)obj17).childAlignment = (TextAnchor)1;
			((HorizontalOrVerticalLayoutGroup)obj17).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj17).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj17).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj17).childForceExpandHeight = false;
			scrollContent.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			foreach (SoulTier value4 in Enum.GetValues(typeof(SoulTier)))
			{
				if (!SoulRegistry.ByTier.TryGetValue(value4, out var value))
				{
					continue;
				}
				CreateText(SoulRegistry.GetTierName(value4), scrollContent.transform, 13, (TextAlignmentOptions)513, "#FFE884");
				bool flag = false;
				for (int j = 1; j < value.Count; j++)
				{
					if (value[j].SubGroup != value[0].SubGroup)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					GameObject val21 = CreatePanel($"Grid_{value4}", scrollContent.transform, 0f, 0f);
					GridLayoutGroup obj18 = val21.AddComponent<GridLayoutGroup>();
					obj18.cellSize = new Vector2(40f, 40f);
					obj18.spacing = new Vector2(4f, 4f);
					obj18.constraint = (Constraint)0;
					obj18.startAxis = (Axis)0;
					val21.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
					foreach (SoulDef item in value)
					{
						SoulGridIcon value2 = CreateSoulIcon(val21.transform, item);
						gridIcons[item.BossId] = value2;
					}
					continue;
				}
				int num = -1;
				GameObject val22 = null;
				foreach (SoulDef item2 in value)
				{
					if (item2.SubGroup != num)
					{
						if ((Object)(object)val22 != (Object)null)
						{
							LayoutElement obj19 = CreatePanel($"Spacer_{value4}_{item2.SubGroup}", scrollContent.transform, 0f, 0f).AddComponent<LayoutElement>();
							obj19.preferredHeight = 4f;
							obj19.minHeight = 4f;
						}
						num = item2.SubGroup;
						val22 = CreatePanel($"Grid_{value4}_{num}", scrollContent.transform, 0f, 0f);
						GridLayoutGroup obj20 = val22.AddComponent<GridLayoutGroup>();
						obj20.cellSize = new Vector2(40f, 40f);
						obj20.spacing = new Vector2(4f, 4f);
						obj20.constraint = (Constraint)0;
						obj20.startAxis = (Axis)0;
						val22.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
					}
					SoulGridIcon value3 = CreateSoulIcon(val22.transform, item2);
					gridIcons[item2.BossId] = value3;
				}
			}
		}

		private static GameObject MakeGO(string name, Transform parent)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.AddComponent<RectTransform>();
			val.AddComponent<CanvasRenderer>();
			return val;
		}

		private SoulGridIcon CreateSoulIcon(Transform parent, SoulDef soul)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			SoulGridIcon soulGridIcon = CreatePanel($"Soul_{soul.BossId}", parent, 40f, 40f).AddComponent<SoulGridIcon>();
			soulGridIcon.Init(soul, this);
			return soulGridIcon;
		}

		private SoulEquipSlot CreateEquipSlot(Transform parent, int slotIndex)
		{
			SoulEquipSlot soulEquipSlot = CreatePanel($"EquipSlot_{slotIndex}", parent, 40f, 40f).AddComponent<SoulEquipSlot>();
			soulEquipSlot.Init(slotIndex, this);
			return soulEquipSlot;
		}

		public void RefreshAll()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got I4
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got I4
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038->IL0038: Incompatible stack types: O vs I4
			//IL_0032->IL0038: Incompatible stack types: I4 vs O
			//IL_0032->IL0038: Incompatible stack types: O vs I4
			//IL_0067->IL0067: Incompatible stack types: O vs I4
			//IL_0060->IL0067: Incompatible stack types: I4 vs O
			//IL_0060->IL0067: Incompatible stack types: O vs I4
			BossSoulsSaveData data = SoulSaveManager.Data;
			Character currentCharacter = GameData.CurrentCharacter;
			string text = ((currentCharacter != null) ? ((Entity)currentCharacter).Name : null);
			CharacterSoulEquip characterSoulEquip = ((text != null) ? data.GetOrCreateEquip(text) : null);
			object obj = primarySlot;
			int num;
			if (characterSoulEquip != null)
			{
				obj = characterSoulEquip.Primary;
				num = (int)obj;
			}
			else
			{
				num = 0;
				obj = num;
				num = (int)obj;
			}
			((SoulEquipSlot)num).Refresh((MonsterID)obj, data.PrimaryUnlocked);
			for (int i = 0; i < 3; i++)
			{
				bool isUnlocked = i < data.SecondarySlotCount;
				object obj2 = secondarySlots[i];
				int num2;
				if (characterSoulEquip == null)
				{
					num2 = 0;
					obj2 = num2;
					num2 = (int)obj2;
				}
				else
				{
					obj2 = characterSoulEquip.GetSecondary(i);
					num2 = (int)obj2;
				}
				((SoulEquipSlot)num2).Refresh((MonsterID)obj2, isUnlocked);
			}
			foreach (KeyValuePair<MonsterID, SoulGridIcon> gridIcon in gridIcons)
			{
				SoulState orCreate = data.GetOrCreate(gridIcon.Key);
				gridIcon.Value.Refresh(orCreate);
			}
		}

		private static bool IsInCombat()
		{
			Character currentCharacter = GameData.CurrentCharacter;
			return ((currentCharacter != null) ? ((Entity)currentCharacter).ActiveEncounter : null) != null;
		}

		private void ShowCombatError()
		{
			if ((Object)(object)statusText != (Object)null)
			{
				((TMP_Text)statusText).text = "<color=#FF6666>Cannot change souls while in combat.</color>";
				statusClearTime = Time.time + 3f;
			}
		}

		public void OnSlotClicked(int slotIndex)
		{
			if (pendingSlotIndex == slotIndex)
			{
				pendingSlotIndex = -1;
				HighlightSlot(-1);
			}
			else
			{
				pendingSlotIndex = slotIndex;
				HighlightSlot(slotIndex);
			}
		}

		public void OnSlotRightClicked(int slotIndex)
		{
			if (IsInCombat())
			{
				ShowCombatError();
				return;
			}
			Character currentCharacter = GameData.CurrentCharacter;
			string text = ((currentCharacter != null) ? ((Entity)currentCharacter).Name : null);
			if (text != null)
			{
				CharacterSoulEquip orCreateEquip = SoulSaveManager.Data.GetOrCreateEquip(text);
				if (slotIndex == 0)
				{
					orCreateEquip.Primary = (MonsterID)0;
				}
				else
				{
					orCreateEquip.SetSecondary(slotIndex - 1, (MonsterID)0);
				}
				SoulSaveManager.Save();
				RefreshAll();
				BossSoulsPlugin.RefreshEquipmentSlot();
			}
		}

		public void OnSoulIconClicked(SoulDef soul)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			if (IsInCombat())
			{
				ShowCombatError();
				return;
			}
			BossSoulsSaveData data = SoulSaveManager.Data;
			if (!data.GetOrCreate(soul.BossId).Forged)
			{
				return;
			}
			Character currentCharacter = GameData.CurrentCharacter;
			string text = ((currentCharacter != null) ? ((Entity)currentCharacter).Name : null);
			if (text == null)
			{
				return;
			}
			if (pendingSlotIndex < 0)
			{
				pendingSlotIndex = FindFirstAvailableSlot(soul.BossId);
				if (pendingSlotIndex < 0)
				{
					return;
				}
			}
			CharacterSoulEquip orCreateEquip = data.GetOrCreateEquip(text);
			if (orCreateEquip.HasSoul(soul.BossId) && (pendingSlotIndex != 0 || orCreateEquip.Primary != soul.BossId) && (pendingSlotIndex <= 0 || orCreateEquip.GetSecondary(pendingSlotIndex - 1) != soul.BossId))
			{
				if (orCreateEquip.Primary == soul.BossId)
				{
					orCreateEquip.Primary = (MonsterID)0;
				}
				for (int i = 0; i < SoulSaveManager.Data.SecondarySlotCount; i++)
				{
					if (orCreateEquip.GetSecondary(i) == soul.BossId)
					{
						orCreateEquip.SetSecondary(i, (MonsterID)0);
					}
				}
			}
			if (pendingSlotIndex == 0)
			{
				foreach (KeyValuePair<string, CharacterSoulEquip> characterEquip in data.CharacterEquips)
				{
					if (characterEquip.Key != text && characterEquip.Value.Primary == soul.BossId)
					{
						characterEquip.Value.Primary = (MonsterID)0;
					}
				}
				orCreateEquip.Primary = soul.BossId;
			}
			else
			{
				orCreateEquip.SetSecondary(pendingSlotIndex - 1, soul.BossId);
			}
			pendingSlotIndex = -1;
			SoulSaveManager.Save();
			RefreshAll();
			HighlightSlot(-1);
			BossSoulsPlugin.RefreshEquipmentSlot();
		}

		private int FindFirstAvailableSlot(MonsterID soulId)
		{
			//IL_002e: 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)
			BossSoulsSaveData data = SoulSaveManager.Data;
			Character currentCharacter = GameData.CurrentCharacter;
			string text = ((currentCharacter != null) ? ((Entity)currentCharacter).Name : null);
			if (text == null)
			{
				return -1;
			}
			CharacterSoulEquip orCreateEquip = data.GetOrCreateEquip(text);
			if (data.PrimaryUnlocked && (int)orCreateEquip.Primary == 0)
			{
				return 0;
			}
			for (int i = 0; i < data.SecondarySlotCount; i++)
			{
				if ((int)orCreateEquip.GetSecondary(i) == 0)
				{
					return i + 1;
				}
			}
			return -1;
		}

		private void HighlightSlot(int index)
		{
			primarySlot.SetHighlighted(index == 0);
			for (int i = 0; i < 3; i++)
			{
				secondarySlots[i].SetHighlighted(index == i + 1);
			}
		}

		internal static GameObject CreatePanel(string name, Transform parent, float width, float height)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			RectTransform val2 = val.AddComponent<RectTransform>();
			if (width > 0f && height > 0f)
			{
				val2.sizeDelta = new Vector2(width, height);
			}
			val.AddComponent<CanvasRenderer>();
			return val;
		}

		internal static TMP_Text CreateText(string text, Transform parent, int fontSize, TextAlignmentOptions alignment, string color = "#FFFFFF")
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Text");
			val.transform.SetParent(parent, false);
			val.AddComponent<RectTransform>();
			val.AddComponent<CanvasRenderer>();
			TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val2).text = "<color=" + color + ">" + text + "</color>";
			((TMP_Text)val2).fontSize = fontSize;
			((TMP_Text)val2).alignment = alignment;
			((TMP_Text)val2).enableWordWrapping = true;
			((TMP_Text)val2).overflowMode = (TextOverflowModes)0;
			val.AddComponent<LayoutElement>().preferredHeight = fontSize + 8;
			return (TMP_Text)(object)val2;
		}
	}
	public class SoulSlotController : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler, IPointerClickHandler
	{
		public Image BackgroundImage;

		public Image ItemImage;

		public GameObject ShadowImage;

		public GameObject LockedImage;

		public GameObject RarityImage;

		private MonsterID CurrentSoulId;

		public void Setup(GameObject sourceSlot)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			BackgroundImage = sourceSlot.GetComponent<Image>();
			if ((Object)(object)BackgroundImage == (Object)null)
			{
				BackgroundImage = sourceSlot.GetComponentInChildren<Image>();
			}
			Image[] componentsInChildren = sourceSlot.GetComponentsInChildren<Image>(true);
			foreach (Image val in componentsInChildren)
			{
				if (((Object)((Component)val).gameObject).name.Contains("Item") || ((Object)((Component)val).gameObject).name.Contains("Icon"))
				{
					ItemImage = val;
				}
			}
			foreach (Transform item in sourceSlot.transform)
			{
				Transform val2 = item;
				if (((Object)val2).name.Contains("Shadow"))
				{
					ShadowImage = ((Component)val2).gameObject;
				}
				else if (((Object)val2).name.Contains("Lock"))
				{
					LockedImage = ((Component)val2).gameObject;
				}
				else if (((Object)val2).name.Contains("Rarity"))
				{
					RarityImage = ((Component)val2).gameObject;
				}
			}
			if ((Object)(object)BackgroundImage != (Object)null)
			{
				((Graphic)BackgroundImage).color = Color.white;
				ManualLogSource log = BossSoulsPlugin.Log;
				Sprite sprite = BackgroundImage.sprite;
				log.LogInfo((object)string.Format("SoulSlot Setup: BG sprite={0} color={1} enabled={2}", ((sprite != null) ? ((Object)sprite).name : null) ?? "null", ((Graphic)BackgroundImage).color, ((Behaviour)BackgroundImage).enabled));
			}
			else
			{
				BossSoulsPlugin.Log.LogWarning((object)"SoulSlot Setup: No BackgroundImage found!");
			}
			BossSoulsPlugin.Log.LogInfo((object)$"SoulSlot Setup: ItemImage={(Object)(object)ItemImage != (Object)null} Shadow={(Object)(object)ShadowImage != (Object)null} Lock={(Object)(object)LockedImage != (Object)null} Rarity={(Object)(object)RarityImage != (Object)null}");
		}

		public void Refresh()
		{
			//IL_00a5: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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)
			ManualLogSource log = BossSoulsPlugin.Log;
			object arg = ((Component)this).gameObject.activeSelf;
			Transform parent = ((Component)this).transform.parent;
			log.LogInfo((object)$"SoulSlot.Refresh() called. GO active={arg} parent active={((parent != null) ? new bool?(((Component)parent).gameObject.activeSelf) : null)}");
			BossSoulsSaveData data = SoulSaveManager.Data;
			if (!data.PrimaryUnlocked)
			{
				((Component)this).gameObject.SetActive(false);
				return;
			}
			((Component)this).gameObject.SetActive(true);
			Character currentCharacter = GameData.CurrentCharacter;
			string text = ((currentCharacter != null) ? ((Entity)currentCharacter).Name : null);
			if (string.IsNullOrEmpty(text))
			{
				ShowEmpty();
				return;
			}
			CharacterSoulEquip orCreateEquip = data.GetOrCreateEquip(text);
			CurrentSoulId = orCreateEquip.Primary;
			if ((int)CurrentSoulId != 0 && SoulRegistry.All.TryGetValue(CurrentSoulId, out var _))
			{
				ShowEquipped(CurrentSoulId);
			}
			else
			{
				ShowEmpty();
			}
		}

		private void ShowLocked()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			CurrentSoulId = (MonsterID)0;
			if ((Object)(object)ItemImage != (Object)null)
			{
				((Component)ItemImage).gameObject.SetActive(false);
			}
			if ((Object)(object)ShadowImage != (Object)null)
			{
				ShadowImage.SetActive(false);
			}
			if ((Object)(object)LockedImage != (Object)null)
			{
				LockedImage.SetActive(true);
			}
			if ((Object)(object)RarityImage != (Object)null)
			{
				RarityImage.SetActive(false);
			}
			if ((Object)(object)BackgroundImage != (Object)null)
			{
				BackgroundImage.sprite = GameData.GameController.DefaultBackground;
			}
		}

		private void ShowEmpty()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			CurrentSoulId = (MonsterID)0;
			if ((Object)(object)ItemImage != (Object)null)
			{
				((Component)ItemImage).gameObject.SetActive(false);
			}
			if ((Object)(object)ShadowImage != (Object)null)
			{
				ShadowImage.SetActive(true);
			}
			if ((Object)(object)LockedImage != (Object)null)
			{
				LockedImage.SetActive(false);
			}
			if ((Object)(object)RarityImage != (Object)null)
			{
				RarityImage.SetActive(false);
			}
			if ((Object)(object)BackgroundImage != (Object)null)
			{
				BackgroundImage.sprite = GameData.GameController.DefaultBackground;
			}
		}

		private void ShowEquipped(MonsterID bossId)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (MonsterStore.MonsterDatabase.TryGetValue(bossId, out var value) && value != null)
			{
				if ((Object)(object)ItemImage != (Object)null)
				{
					ItemImage.sprite = ((Entity)value).Icon;
					((Component)ItemImage).gameObject.SetActive(true);
				}
				if ((Object)(object)ShadowImage != (Object)null)
				{
					ShadowImage.SetActive(false);
				}
				if ((Object)(object)LockedImage != (Object)null)
				{
					LockedImage.SetActive(false);
				}
				if ((Object)(object)RarityImage != (Object)null)
				{
					RarityImage.SetActive(true);
				}
				if ((Object)(object)BackgroundImage != (Object)null)
				{
					BackgroundImage.sprite = GameData.GameController.GoldBackground;
				}
			}
			else
			{
				ShowEmpty();
			}
		}

		public void OnPointerEnter(PointerEventData eventData)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_0069: 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_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			BossSoulsSaveData data = SoulSaveManager.Data;
			if (!data.PrimaryUnlocked)
			{
				GameData.GameController.Tooltip.Activate("Build the <color=#FFE884>Soul Altar</color> to equip Boss Souls.", false, true, false, false);
				return;
			}
			Character currentCharacter = GameData.CurrentCharacter;
			string text = ((currentCharacter != null) ? ((Entity)currentCharacter).Name : null);
			CharacterSoulEquip characterSoulEquip = ((text != null) ? data.GetOrCreateEquip(text) : null);
			if (characterSoulEquip != null && ((int)characterSoulEquip.Primary != 0 || (int)characterSoulEquip.GetSecondary(0) != 0 || (int)characterSoulEquip.GetSecondary(1) != 0 || (int)characterSoulEquip.GetSecondary(2) != 0))
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("<color=#FFE884><b>Boss Souls</b></color>");
				if ((int)characterSoulEquip.Primary != 0 && SoulRegistry.All.TryGetValue(characterSoulEquip.Primary, out var value))
				{
					SoulState orCreate = data.GetOrCreate(characterSoulEquip.Primary);
					stringBuilder.AppendLine();
					stringBuilder.AppendLine("<color=#FFE884>PRIMARY — " + value.PrimaryName + "</color>  <color=#888888>(" + value.Name + ")</color>");
					stringBuilder.AppendLine(value.GetPrimaryDesc(orCreate.MasteryLevel));
				}
				for (int i = 0; i < 3; i++)
				{
					MonsterID secondary = characterSoulEquip.GetSecondary(i);
					if ((int)secondary != 0 && SoulRegistry.All.TryGetValue(secondary, out var value2))
					{
						SoulState orCreate2 = data.GetOrCreate(secondary);
						stringBuilder.AppendLine();
						stringBuilder.AppendLine("<color=#95FF6D>SECONDARY</color>  <color=#888888>(" + value2.Name + ")</color>");
						stringBuilder.AppendLine(value2.GetSecondaryDesc(orCreate2.MasteryLevel));
					}
				}
				stringBuilder.AppendLine();
				stringBuilder.Append("<color=#888888>Click to manage Boss Souls</color>");
				GameData.GameController.Tooltip.Activate(stringBuilder.ToString(), false, true, false, false);
				if ((Object)(object)BackgroundImage != (Object)null)
				{
					BackgroundImage.sprite = GameData.GameController.GoldMenuBackground;
				}
			}
			else
			{
				GameData.GameController.Tooltip.Activate("Click to manage <color=#FFE884>Boss Souls</color>", false, false, false, false);
				if ((Object)(object)BackgroundImage != (Object)null)
				{
					BackgroundImage.sprite = GameData.GameController.MenuBackground;
				}
			}
		}

		public void OnPointerExit(PointerEventData eventData)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			GameData.GameController.Tooltip.Deactivate();
			if ((int)CurrentSoulId != 0)
			{
				BackgroundImage.sprite = GameData.GameController.GoldBackground;
			}
			else
			{
				BackgroundImage.sprite = GameData.GameController.DefaultBackground;
			}
		}

		public void OnPointerClick(PointerEventData eventData)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (SoulSaveManager.Data.PrimaryUnlocked && (int)eventData.button == 0)
			{
				GameData.GameController.Tooltip.Deactivate();
				BossSoulsPlugin.GetOrCreateSelectionPanel()?.Open();
			}
		}
	}
}
namespace BossSouls.Patches
{
	public static class BossKillPatches
	{
		public static void Apply(Harmony harmony)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			MethodInfo method = typeof(Tasks).GetMethod("TriggerOnMonsterSlain", BindingFlags.Static | BindingFlags.Public);
			MethodInfo method2 = typeof(BossKillPatches).GetMethod("OnMonsterSlain", BindingFlags.Static | BindingFlags.Public);
			harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			BossSoulsPlugin.Log.LogInfo((object)"BossKillPatches: Patched Tasks.TriggerOnMonsterSlain");
		}

		public static void OnMonsterSlain(Monster monster)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			if (monster != null && ((int)monster.Type == 1 || (int)monster.Type == 2) && SoulRegistry.All.ContainsKey(monster.ID))
			{
				SoulState orCreate = SoulSaveManager.Data.GetOrCreate(monster.ID);
				orCreate.KillCount++;
				SoulDef soulDef = SoulRegistry.All[monster.ID];
				if (!orCreate.Forged && orCreate.KillCount >= soulDef.ForgeKills)
				{
					orCreate.Forged = true;
					BossSoulsPlugin.Log.LogInfo((object)("Soul forged: " + soulDef.Name + "!"));
				}
				if (SoulSaveManager.Data.MasteryUnlocked)
				{
					orCreate.MasteryKills++;
				}
				SoulSaveManager.Save();
			}
		}
	}
	public static class BuildingPatches
	{
		public static SoulAltar AltarInstance { get; private set; }

		public static void Apply(Harmony harmony)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Expected O, but got Unknown
			MethodInfo method = typeof(Upgrades).GetMethod("SetupUpgrades", BindingFlags.Static | BindingFlags.Public);
			harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(BuildingPatches).GetMethod("SetupUpgradesPostfix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			BossSoulsPlugin.Log.LogInfo((object)"BuildingPatches: Patched Upgrades.SetupUpgrades");
			MethodInfo method2 = typeof(UpgradeMenuController).GetMethod("Setup", BindingFlags.Instance | BindingFlags.NonPublic);
			if (method2 == null)
			{
				method2 = typeof(UpgradeMenuController).GetMethod("Setup", BindingFlags.Instance | BindingFlags.Public);
			}
			harmony.Patch((MethodBase)method2, new HarmonyMethod(typeof(BuildingPatches).GetMethod("UpgradeMenuSetupPrefix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			BossSoulsPlugin.Log.LogInfo((object)"BuildingPatches: Patched UpgradeMenuController.Setup");
			MethodInfo method3 = typeof(Upgrades).GetMethod("ResetUpgrades", BindingFlags.Static | BindingFlags.Public);
			harmony.Patch((MethodBase)method3, (HarmonyMethod)null, new HarmonyMethod(typeof(BuildingPatches).GetMethod("ResetUpgradesPostfix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			BossSoulsPlugin.Log.LogInfo((object)"BuildingPatches: Patched Upgrades.ResetUpgrades");
			MethodInfo method4 = typeof(GameData).GetMethod("UpdateMaxLevel", BindingFlags.Static | BindingFlags.Public);
			harmony.Patch((MethodBase)method4, (HarmonyMethod)null, new HarmonyMethod(typeof(BuildingPatches).GetMethod("UpdateMaxLevelPostfix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			BossSoulsPlugin.Log.LogInfo((object)"BuildingPatches: Patched GameData.UpdateMaxLevel");
		}

		public static void SetupUpgradesPostfix()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				AltarInstance = new SoulAltar();
				Upgrades.BuildingUpgrades.Add(SoulAltar.CustomType, (BuildingUpgrade)(object)AltarInstance);
				int soulAltarRank = SoulSaveManager.Data.SoulAltarRank;
				if (soulAltarRank > 0)
				{
					((BuildingUpgrade)AltarInstance).UpdateRank(soulAltarRank);
				}
				((BuildingUpgrade)AltarInstance).IsUnlocked = true;
				BossSoulsPlugin.Log.LogInfo((object)$"Soul Altar registered. Rank={((BuildingUpgrade)AltarInstance).CurrentRank}");
			}
			catch (Exception arg)
			{
				BossSoulsPlugin.Log.LogError((object)$"Failed to register Soul Altar: {arg}");
			}
		}

		public static void UpgradeMenuSetupPrefix(UpgradeMenuController __instance)
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				List<UpgradePreviewController> upgradePreviews = __instance.UpgradePreviews;
				if (upgradePreviews == null || upgradePreviews.Count == 0 || upgradePreviews.Count >= Upgrades.BuildingUpgrades.Count)
				{
					return;
				}
				UpgradePreviewController val = upgradePreviews[upgradePreviews.Count - 1];
				GameObject obj = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)val).transform.parent);
				((Object)obj).name = "SoulAltarPreview";
				UpgradePreviewController component = obj.GetComponent<UpgradePreviewController>();
				upgradePreviews.Add(component);
				int count = upgradePreviews.Count;
				int num = 4;
				if (count >= 5)
				{
					RectTransform component2 = ((Component)upgradePreviews[0]).GetComponent<RectTransform>();
					RectTransform component3 = ((Component)upgradePreviews[1]).GetComponent<RectTransform>();
					RectTransform component4 = ((Component)upgradePreviews[4]).GetComponent<RectTransform>();
					float num2 = component3.anchoredPosition.x - component2.anchoredPosition.x;
					float num3 = component4.anchoredPosition.y - component2.anchoredPosition.y;
					float x = component2.anchoredPosition.x;
					float y = component2.anchoredPosition.y;
					for (int i = (count - 1) / num * num; i < count; i++)
					{
						int num4 = i % num;
						int num5 = i / num;
						RectTransform component5 = ((Component)upgradePreviews[i]).GetComponent<RectTransform>();
						component5.anchoredPosition = new Vector2(x + (float)num4 * num2, y + (float)num5 * num3);
						BossSoulsPlugin.Log.LogInfo((object)$"Preview[{i}] repositioned to col={num4} row={num5} pos={component5.anchoredPosition}");
					}
				}
				BossSoulsPlugin.Log.LogInfo((object)$"Added Soul Altar preview slot. Total previews: {count}");
			}
			catch (Exception arg)
			{
				BossSoulsPlugin.Log.LogError((object)$"Failed to add preview slot: {arg}");
			}
		}

		public static void ResetUpgradesPostfix()
		{
			if (AltarInstance != null)
			{
				((BuildingUpgrade)AltarInstance).UnlockUpgrade(true);
				int soulAltarRank = SoulSaveManager.Data.SoulAltarRank;
				if (soulAltarRank > 0)
				{
					((BuildingUpgrade)AltarInstance).UpdateRank(soulAltarRank);
				}
				BossSoulsPlugin.Log.LogInfo((object)$"ResetUpgradesPostfix: Soul Altar re-unlocked. Rank={((BuildingUpgrade)AltarInstance).CurrentRank}");
			}
		}

		public static void UpdateMaxLevelPostfix()
		{
			if (AltarInstance != null && !((BuildingUpgrade)AltarInstance).IsUnlocked)
			{
				((BuildingUpgrade)AltarInstance).UnlockUpgrade(true);
			}
		}
	}
	public static class EquipmentUIPatches
	{
		private static Dictionary<EquipmentInventoryController, SoulSlotController> soulSlots = new Dictionary<EquipmentInventoryController, SoulSlotController>();

		private static BuildCardSoulController buildCardSoulCtrl;

		private static GameObject buildCardSoulGO;

		public static void Apply(Harmony harmony)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			Type typeFromHandle = typeof(EquipmentInventoryController);
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public;
			harmony.Patch((MethodBase)typeFromHandle.GetMethod("Setup", bindingAttr), (HarmonyMethod)null, new HarmonyMethod(typeof(EquipmentUIPatches).GetMethod("SetupPostfix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)typeFromHandle.GetMethod("LoadCharacter", bindingAttr), (HarmonyMethod)null, new HarmonyMethod(typeof(EquipmentUIPatches).GetMethod("LoadCharacterPostfix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)typeFromHandle.GetMethod("UnloadCharacter", bindingAttr), (HarmonyMethod)null, new HarmonyMethod(typeof(EquipmentUIPatches).GetMethod("UnloadCharacterPostfix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			BossSoulsPlugin.Log.LogInfo((object)"EquipmentUIPatches: Patched EquipmentInventoryController (3 methods)");
			Type typeFromHandle2 = typeof(BuildCardMenuController);
			harmony.Patch((MethodBase)typeFromHandle2.GetMethod("Setup", BindingFlags.Instance | BindingFlags.Public), (HarmonyMethod)null, new HarmonyMethod(typeof(EquipmentUIPatches).GetMethod("BuildCardSetupPostfix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)typeFromHandle2.GetMethod("LoadCharacter", BindingFlags.Instance | BindingFlags.Public), (HarmonyMethod)null, new HarmonyMethod(typeof(EquipmentUIPatches).GetMethod("BuildCardLoadCharPostfix", BindingFlags.Static | BindingFlags.Public)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			BossSoulsPlugin.Log.LogInfo((object)"EquipmentUIPatches: Patched BuildCardMenuController (2 methods)");
		}

		public static void SetupPostfix(EquipmentInventoryController __instance)
		{
			BossSoulsPlugin.Log.LogInfo((object)"EquipmentInventoryController.Setup() postfix fired.");
			TryCreateSlot(__instance);
		}

		public static void LoadCharacterPostfix(EquipmentInventoryController __instance, Character character)
		{
			BossSoulsPlugin.Log.LogInfo((object)("LoadCharacter postfix fired. char=" + (((character != null) ? ((Entity)character).Name : null) ?? "null")));
			TryCreateSlot(__instance);
			if (soulSlots.TryGetValue(__instance, out var value))
			{
				value.Refresh();
			}
		}

		public static void UnloadCharacterPostfix(EquipmentInventoryController __instance)
		{
			if (soulSlots.TryGetValue(__instance, out var value))
			{
				value.Refresh();
			}
		}

		public static void RefreshSlot()
		{
			foreach (SoulSlotController value in soulSlots.Values)
			{
				value?.Refresh();
			}
		}

		public static void BuildCardSetupPostfix(BuildCardMenuController __instance)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: 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_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)buildCardSoulGO != (Object)null)
			{
				return;
			}
			List<BuildCardGemController> gemCards = __instance.GemCards;
			if (gemCards == null || gemCards.Count == 0)
			{
				return;
			}
			Transform parent = ((Component)gemCards[0]).transform.parent.parent;
			Transform parent2 = parent.parent;
			Transform val = null;
			for (int i = 0; i < parent2.childCount; i++)
			{
				if (((Object)parent2.GetChild(i)).name == "FlaskPanel")
				{
					val = parent2.GetChild(i);
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			buildCardSoulGO = new GameObject("BossSoulPanel");
			buildCardSoulGO.transform.SetParent(parent2, false);
			Image component = ((Component)val).GetComponent<Image>();
			if ((Object)(object)component != (Object)null)
			{
				Image obj = buildCardSoulGO.AddComponent<Image>();
				obj.sprite = component.sprite;
				obj.type = component.type;
				((Graphic)obj).color = ((Graphic)component).color;
				((Graphic)obj).material = ((Graphic)component).material;
			}
			RectTransform component2 = ((Component)val).GetComponent<RectTransform>();
			float num = component2.anchoredPosition.y - component2.sizeDelta.y;
			RectTransform component3 = buildCardSoulGO.GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0f, 1f);
			component3.anchorMax = new Vector2(0f, 1f);
			component3.pivot = new Vector2(0f, 1f);
			component3.sizeDelta = new Vector2(240f, 66f);
			component3.anchoredPosition = new Vector2(0f, num);
			Transform val2 = val.Find("FlaskTitleText");
			if ((Object)(object)val2 != (Object)null)
			{
				GameObject val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject, buildCardSoulGO.transform);
				((Object)val3).name = "BossSoulTitleText";
				Component[] components = val3.GetComponents<Component>();
				foreach (Component val4 in components)
				{
					if ((Object)(object)val4 != (Object)null && !(val4 is RectTransform) && !(val4 is TextMeshProUGUI) && !(val4 is CanvasRenderer))
					{
						Object.DestroyImmediate((Object)(object)val4);
					}
				}
				TextMeshProUGUI component4 = val3.GetComponent<TextMeshProUGUI>();
				if ((Object)(object)component4 != (Object)null)
				{
					((TMP_Text)component4).text = "Boss Souls";
				}
			}
			GameObject val5 = new GameObject("SoulIconRow");
			val5.transform.SetParent(buildCardSoulGO.transform, false);
			RectTransform obj2 = val5.AddComponent<RectTransform>();
			obj2.anchorMin = new Vector2(0f, 0f);
			obj2.anchorMax = new Vector2(1f, 1f);
			obj2.offsetMin = new Vector2(4f, 4f);
			obj2.offsetMax = new Vector2(-4f, -22f);
			buildCardSoulCtrl = val5.AddComponent<BuildCardSoulController>();
			buildCardSoulCtrl.BuildSlots();
			RectTransform component5 = ((Component)parent).GetComponent<RectTransform>();
			component5.offsetMax = new Vector2(component5.offsetMax.x, component5.offsetMax.y - 66f);
			BossSoulsPlugin.Log.LogInfo((object)$"BossSoulPanel: built from scratch at y={num}, GemPanel.offsetMax.y={component5.offsetMax.y}");
		}

		public static void BuildCardLoadCharPostfix(BuildCardMenuController __instance, Character character)
		{
			if (character != null && !((Object)(object)buildCardSoulCtrl == (Object)null))
			{
				buildCardSoulCtrl.Refresh(character);
				if ((Object)(object)buildCardSoulGO != (Object)null)
				{
					buildCardSoulGO.SetActive(SoulSaveManager.Data.PrimaryUnlocked);
				}
			}
		}

		private static void TryCreateSlot(EquipmentInventoryController inventory)
		{
			if (soulSlots.ContainsKey(inventory))
			{
				return;
			}
			try
			{
				BuildSoulSlot(inventory);
			}
			catch (Exception arg)
			{
				BossSoulsPlugin.Log.LogError((object)$"Failed to create soul slot: {arg}");
			}
		}

		private static void BuildSoulSlot(EquipmentInventoryController inventory)
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			DivineAugmentSlotController value = Traverse.Create((object)inventory).Field("FatedAugment").GetValue<DivineAugmentSlotController>();
			if ((Object)(object)value == (Object)null)
			{
				BossSoulsPlugin.Log.LogWarning((object)"Could not find FatedAugment slot to clone.");
				return;
			}
			Transform parent = ((Component)value).transform.parent;
			BossSoulsPlugin.Log.LogInfo((object)$"=== Equipment Panel Dump: parent='{((Object)parent).name}' childCount={parent.childCount} ===");
			for (int i = 0; i < parent.childCount; i++)
			{
				Transform child = parent.GetChild(i);
				RectTransform component = ((Component)child).GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					BossSoulsPlugin.Log.LogInfo((object)$"  [{i}] '{((Object)child).name}' pos={component.anchoredPosition} size={component.sizeDelta} anchors=({component.anchorMin},{component.anchorMax}) pivot={component.pivot} active={((Component)child).gameObject.activeSelf}");
				}
				else
				{
					BossSoulsPlugin.Log.LogInfo((object)$"  [{i}] '{((Object)child).name}' (no RectTransform) active={((Component)child).gameObject.activeSelf}");
				}
			}
			RectTransform component2 = ((Component)parent).GetComponent<RectTransform>();
			if ((Object)(object)component2 != (Object)null)
			{
				BossSoulsPlugin.Log.LogInfo((object)$"  Parent RT: pos={component2.anchoredPosition} size={component2.sizeDelta} anchors=({component2.anchorMin},{component2.anchorMax})");
			}
			string[] array = new string[16]
			{
				"LeftWeaponSlot", "RightWeaponSlot", "HelmSlot", "ShoulderSlot", "ChestSlot", "BracerSlot", "GloveSlot", "BeltSlot", "PantsSlot", "BootSlot",
				"CloakSlot", "AmuletSlot", "LeftRingSlot", "RightRingSlot", "TrinketSlot", "RelicSlot"
			};
			foreach (string text in array)
			{
				EquipmentSlot value2 = Traverse.Create((object)inventory).Field(text).GetValue<EquipmentSlot>();
				if ((Object)(object)value2 != (Object)null)
				{
					RectTransform component3 = ((Component)value2).GetComponent<RectTransform>();
					BossSoulsPlugin.Log.LogInfo((object)$"  {text}: pos={component3.anchoredPosition} size={component3.sizeDelta}");
				}
			}
			BossSoulsPlugin.Log.LogInfo((object)"=== End Equipment Panel Dump ===");
			((Component)value).GetComponent<RectTransform>();
			Traverse.Create((object)inventory).Field("WeaponAugment").GetValue<DivineAugmentSlotController>();
			Traverse.Create((object)inventory).Field("ArmourAugment").GetValue<DivineAugmentSlotController>();
			Traverse.Create((object)inventory).Field("AccessoryAugmen