Decompiled source of ChestHelper v2.0.2

ChestHelper.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace ValheimChestHelper;

[BepInPlugin("com.awuushy.chesthelper", "ChestHelper", "2.0.2")]
public class ChestHelperPlugin : BaseUnityPlugin
{
	public const string ModGUID = "com.awuushy.chesthelper";

	public const string ModName = "ChestHelper";

	public const string ModVersion = "2.0.2";

	public static ConfigEntry<float> HighlightRadius;

	public static ConfigEntry<bool> CheckLineOfSight;

	public static ConfigEntry<int> MaxWallObstacles;

	public static ConfigEntry<string> HighlightColorHex;

	public static ConfigEntry<bool> EnableChestBeacon;

	public static ConfigEntry<bool> EnableChestLight;

	public static ConfigEntry<float> LightIntensity;

	public static ConfigEntry<float> LightRange;

	public static ConfigEntry<float> ChestSurfaceGlow;

	public static ConfigEntry<string> SortButtonText;

	public static ConfigEntry<bool> EnableSearchBar;

	public static ConfigEntry<bool> EnableDirectChestDeposit;

	public static ConfigEntry<float> DirectDepositMaxDistance;

	public static ConfigEntry<bool> DebugLogging;

	private Harmony m_harmony;

	public static ChestHelperPlugin Instance { get; private set; }

	private void Awake()
	{
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Expected O, but got Unknown
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Expected O, but got Unknown
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f8: Expected O, but got Unknown
		Instance = this;
		HighlightRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Highlight", "HighlightRadius", 25f, "Maximum distance (in meters) from player to highlight matching chests.");
		CheckLineOfSight = ((BaseUnityPlugin)this).Config.Bind<bool>("Highlight", "CheckLineOfSight", true, "If true, chests behind multiple walls, floors, or terrain will not be highlighted.");
		MaxWallObstacles = ((BaseUnityPlugin)this).Config.Bind<int>("Highlight", "MaxWallObstacles", 2, "Maximum number of walls/obstacles allowed between player and chest. 0 = strict direct line of sight only, 1 = allow through 1 thin wall, 2 = allow through beams, doorframes, shelves, or partitions (recommended).");
		HighlightColorHex = ((BaseUnityPlugin)this).Config.Bind<string>("Highlight", "HighlightColor", "#FFE600", "Color of the chest highlight in HEX format (e.g. #FFE600 for yellow, #FFD700 for gold).");
		EnableChestBeacon = ((BaseUnityPlugin)this).Config.Bind<bool>("Highlight", "EnableChestBeacon", true, "If true, spawns a glowing floating 3D beacon/crystal directly above matching chests.");
		EnableChestLight = ((BaseUnityPlugin)this).Config.Bind<bool>("Highlight", "EnableChestLight", true, "If true, a gentle pulsing point light illuminates the chest.");
		LightIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("Highlight", "LightIntensity", 1.8f, "Intensity of the chest glow light.");
		LightRange = ((BaseUnityPlugin)this).Config.Bind<float>("Highlight", "LightRange", 3.5f, "Range of the chest glow light in meters.");
		ChestSurfaceGlow = ((BaseUnityPlugin)this).Config.Bind<float>("Highlight", "ChestSurfaceGlow", 0.55f, "Strength of the chest surface glow (0.0 to 1.0, 0.55 by default for balanced soft glow).");
		SortButtonText = ((BaseUnityPlugin)this).Config.Bind<string>("Sorting", "SortButtonText", "Auto", "Text displayed on the chest sorting button. Set to 'Auto' to automatically match game language ('Sort' in English, 'Сортировать' in Russian).");
		EnableSearchBar = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "EnableSearchBar", true, "Enable text search bar in player inventory to highlight matching chests and items.");
		EnableDirectChestDeposit = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "EnableDirectChestDeposit", true, "Enable dragging items directly onto chests in the 3D world to deposit them.");
		DirectDepositMaxDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Features", "DirectDepositMaxDistance", 4.5f, "Maximum distance (in meters) to deposit items directly into a chest. Automatically respects player's maximum interaction distance.");
		DebugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "DebugLogging", false, "Enable diagnostic logging to BepInEx log.");
		m_harmony = new Harmony("com.awuushy.chesthelper");
		m_harmony.PatchAll();
		try
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(PlayerController), "TakeInput", (Type[])null, (Type[])null);
			if (methodInfo != null)
			{
				m_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(ChestSearchBar), "TakeInput_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			MethodInfo methodInfo2 = AccessTools.Method(typeof(Player), "TakeInput", new Type[2]
			{
				typeof(bool),
				typeof(bool)
			}, (Type[])null) ?? AccessTools.Method(typeof(Player), "TakeInput", new Type[1] { typeof(bool) }, (Type[])null) ?? AccessTools.Method(typeof(Player), "TakeInput", Type.EmptyTypes, (Type[])null);
			if (methodInfo2 != null)
			{
				m_harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(ChestSearchBar), "TakeInput_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Failed to patch TakeInput: " + ex.Message));
		}
		ChestMiragePreview.Init(((BaseUnityPlugin)this).Config);
		((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} v{1} initialized!", "ChestHelper", "2.0.2"));
	}

	private void Update()
	{
		ChestHighlightManager.UpdateHighlights();
		ChestSorter.UpdateSortButton();
		ChestSearchBar.UpdateSearchBar();
		ChestMiragePreview.Update();
	}

	private void OnDestroy()
	{
		if (m_harmony != null)
		{
			m_harmony.UnpatchSelf();
		}
	}

	public static void Log(string message)
	{
		if ((Object)(object)Instance != (Object)null && DebugLogging.Value)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)message);
		}
	}

	public static Color GetHighlightColor()
	{
		//IL_0029: 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)
		Color result = default(Color);
		if (ColorUtility.TryParseHtmlString(HighlightColorHex.Value, ref result))
		{
			return result;
		}
		return new Color(1f, 0.9f, 0f, 1f);
	}
}
public static class ChestHighlightManager
{
	public static readonly HashSet<Container> AllContainers = new HashSet<Container>();

	private static readonly HashSet<Container> s_highlightedContainers = new HashSet<Container>();

	private static readonly HashSet<Container> s_toHighlight = new HashSet<Container>();

	private static readonly List<Container> s_deadContainers = new List<Container>();

	private static readonly List<RaycastResult> s_uiRaycastResults = new List<RaycastResult>();

	private static readonly FieldInfo s_uiTooltipCurrentField = AccessTools.Field(typeof(UITooltip), "m_current");

	private static readonly FieldInfo s_inventoryGuiDragItemField = AccessTools.Field(typeof(InventoryGui), "m_dragItem");

	private static int s_viewBlockMask = -1;

	private static string s_lastHoveredItemName = null;

	private static readonly RaycastHit[] s_raycastHits = (RaycastHit[])(object)new RaycastHit[32];

	public static int GetViewBlockMask()
	{
		if (s_viewBlockMask == -1)
		{
			s_viewBlockMask = LayerMask.GetMask(new string[6] { "Default", "static_solid", "piece", "terrain", "viewblock", "vehicle" });
		}
		return s_viewBlockMask;
	}

	public static void Register(Container container)
	{
		if ((Object)(object)container != (Object)null)
		{
			AllContainers.Add(container);
		}
	}

	public static void Unregister(Container container)
	{
		if ((Object)(object)container != (Object)null)
		{
			AllContainers.Remove(container);
			Unhighlight(container);
			s_highlightedContainers.Remove(container);
		}
	}

	public static void ClearAllHighlights()
	{
		if (s_highlightedContainers.Count == 0 && s_lastHoveredItemName == null)
		{
			return;
		}
		foreach (Container s_highlightedContainer in s_highlightedContainers)
		{
			Unhighlight(s_highlightedContainer);
		}
		s_highlightedContainers.Clear();
		s_lastHoveredItemName = null;
	}

	public static void UpdateHighlights()
	{
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null || (Object)(object)InventoryGui.instance == (Object)null || !InventoryGui.IsVisible())
		{
			ClearAllHighlights();
			return;
		}
		if (AllContainers.Count == 0)
		{
			ScanContainers();
		}
		bool isSearchActive = ChestSearchBar.IsSearchActive;
		string text = (isSearchActive ? ChestSearchBar.CurrentQuery : null);
		string text2 = (isSearchActive ? null : GetCurrentHoveredItemName());
		if (!isSearchActive && string.IsNullOrEmpty(text2))
		{
			ClearAllHighlights();
			return;
		}
		if (isSearchActive)
		{
			if (text != s_lastHoveredItemName)
			{
				s_lastHoveredItemName = "SEARCH:" + text;
				ChestHelperPlugin.Log("Highlighting chests matching search: " + text);
			}
		}
		else if (text2 != s_lastHoveredItemName)
		{
			s_lastHoveredItemName = text2;
			ChestHelperPlugin.Log("Hovered item: " + text2);
		}
		float value = ChestHelperPlugin.HighlightRadius.Value;
		bool value2 = ChestHelperPlugin.CheckLineOfSight.Value;
		Vector3 eyePoint = ((Character)localPlayer).GetEyePoint();
		s_toHighlight.Clear();
		s_deadContainers.Clear();
		foreach (Container allContainer in AllContainers)
		{
			if ((Object)(object)allContainer == (Object)null || (Object)(object)((Component)allContainer).gameObject == (Object)null)
			{
				s_deadContainers.Add(allContainer);
			}
			else
			{
				if (!((Component)allContainer).gameObject.activeInHierarchy)
				{
					continue;
				}
				float num = Vector3.Distance(eyePoint, ((Component)allContainer).transform.position);
				if (num > value)
				{
					continue;
				}
				Inventory inventory = allContainer.GetInventory();
				if (inventory == null)
				{
					continue;
				}
				if (isSearchActive)
				{
					if (!ContainsItemMatchingSearch(inventory, text))
					{
						continue;
					}
				}
				else if (!inventory.ContainsItemByName(text2))
				{
					continue;
				}
				if (!value2 || IsContainerVisible(eyePoint, allContainer))
				{
					s_toHighlight.Add(allContainer);
				}
			}
		}
		if (s_deadContainers.Count > 0)
		{
			for (int i = 0; i < s_deadContainers.Count; i++)
			{
				AllContainers.Remove(s_deadContainers[i]);
				s_highlightedContainers.Remove(s_deadContainers[i]);
			}
			s_deadContainers.Clear();
		}
		foreach (Container s_highlightedContainer in s_highlightedContainers)
		{
			if (!s_toHighlight.Contains(s_highlightedContainer))
			{
				Unhighlight(s_highlightedContainer);
			}
		}
		foreach (Container item in s_toHighlight)
		{
			if (!s_highlightedContainers.Contains(item))
			{
				Highlight(item);
				ChestHelperPlugin.Log("Highlighted container: " + ((Object)item).name + " with " + text2);
			}
		}
		s_highlightedContainers.Clear();
		foreach (Container item2 in s_toHighlight)
		{
			s_highlightedContainers.Add(item2);
		}
	}

	private static void ScanContainers()
	{
		Container[] array = Object.FindObjectsOfType<Container>();
		if (array == null)
		{
			return;
		}
		for (int i = 0; i < array.Length; i++)
		{
			if ((Object)(object)array[i] != (Object)null && (Object)(object)((Component)array[i]).gameObject != (Object)null)
			{
				AllContainers.Add(array[i]);
			}
		}
	}

	public static string GetCurrentHoveredItemName()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)InventoryGui.instance == (Object)null)
		{
			return null;
		}
		if ((Object)(object)EventSystem.current != (Object)null)
		{
			PointerEventData val = new PointerEventData(EventSystem.current);
			Vector3 pointerPosition = ZInput.pointerPosition;
			val.position = ((pointerPosition != Vector3.zero) ? new Vector2(pointerPosition.x, pointerPosition.y) : new Vector2(Input.mousePosition.x, Input.mousePosition.y));
			s_uiRaycastResults.Clear();
			EventSystem.current.RaycastAll(val, s_uiRaycastResults);
			for (int i = 0; i < s_uiRaycastResults.Count; i++)
			{
				RaycastResult val2 = s_uiRaycastResults[i];
				GameObject gameObject = ((RaycastResult)(ref val2)).gameObject;
				if ((Object)(object)gameObject == (Object)null)
				{
					continue;
				}
				InventoryElement componentInParent = gameObject.GetComponentInParent<InventoryElement>();
				if (!((Object)(object)componentInParent != (Object)null))
				{
					continue;
				}
				InventoryGrid componentInParent2 = ((Component)componentInParent).GetComponentInParent<InventoryGrid>();
				if ((Object)(object)componentInParent2 != (Object)null && componentInParent2.GetInventory() != null)
				{
					ItemData itemAt = componentInParent2.GetInventory().GetItemAt(componentInParent.Position.x, componentInParent.Position.y);
					if (itemAt != null && itemAt.m_shared != null && !string.IsNullOrEmpty(itemAt.m_shared.m_name))
					{
						return itemAt.m_shared.m_name;
					}
				}
			}
		}
		if (s_uiTooltipCurrentField != null)
		{
			object? value = s_uiTooltipCurrentField.GetValue(null);
			UITooltip val3 = (UITooltip)((value is UITooltip) ? value : null);
			if ((Object)(object)val3 != (Object)null && !string.IsNullOrEmpty(val3.m_topic))
			{
				return val3.m_topic;
			}
		}
		if (s_inventoryGuiDragItemField != null)
		{
			object? value2 = s_inventoryGuiDragItemField.GetValue(InventoryGui.instance);
			ItemData val4 = (ItemData)((value2 is ItemData) ? value2 : null);
			if (val4 != null && val4.m_shared != null && !string.IsNullOrEmpty(val4.m_shared.m_name))
			{
				return val4.m_shared.m_name;
			}
		}
		if (ZInput.IsGamepadActive())
		{
			if ((Object)(object)InventoryGui.instance.m_playerGrid != (Object)null)
			{
				ItemData gamepadSelectedItem = InventoryGui.instance.m_playerGrid.GetGamepadSelectedItem();
				if (gamepadSelectedItem != null && gamepadSelectedItem.m_shared != null && !string.IsNullOrEmpty(gamepadSelectedItem.m_shared.m_name))
				{
					return gamepadSelectedItem.m_shared.m_name;
				}
			}
			if ((Object)(object)InventoryGui.instance.ContainerGrid != (Object)null)
			{
				ItemData gamepadSelectedItem2 = InventoryGui.instance.ContainerGrid.GetGamepadSelectedItem();
				if (gamepadSelectedItem2 != null && gamepadSelectedItem2.m_shared != null && !string.IsNullOrEmpty(gamepadSelectedItem2.m_shared.m_name))
				{
					return gamepadSelectedItem2.m_shared.m_name;
				}
			}
		}
		return null;
	}

	private static bool ContainsItemMatchingSearch(Inventory inv, string query)
	{
		if (inv == null || string.IsNullOrEmpty(query))
		{
			return false;
		}
		List<ItemData> allItems = inv.GetAllItems();
		if (allItems == null)
		{
			return false;
		}
		for (int i = 0; i < allItems.Count; i++)
		{
			if (ChestSearchBar.ItemMatches(allItems[i], query))
			{
				return true;
			}
		}
		return false;
	}

	public static ItemData GetHoveredInventoryItem()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)InventoryGui.instance == (Object)null)
		{
			return null;
		}
		if ((Object)(object)EventSystem.current != (Object)null)
		{
			PointerEventData val = new PointerEventData(EventSystem.current);
			Vector3 pointerPosition = ZInput.pointerPosition;
			val.position = ((pointerPosition != Vector3.zero) ? new Vector2(pointerPosition.x, pointerPosition.y) : new Vector2(Input.mousePosition.x, Input.mousePosition.y));
			s_uiRaycastResults.Clear();
			EventSystem.current.RaycastAll(val, s_uiRaycastResults);
			for (int i = 0; i < s_uiRaycastResults.Count; i++)
			{
				RaycastResult val2 = s_uiRaycastResults[i];
				GameObject gameObject = ((RaycastResult)(ref val2)).gameObject;
				if ((Object)(object)gameObject == (Object)null)
				{
					continue;
				}
				InventoryElement componentInParent = gameObject.GetComponentInParent<InventoryElement>();
				if (!((Object)(object)componentInParent != (Object)null))
				{
					continue;
				}
				InventoryGrid componentInParent2 = ((Component)componentInParent).GetComponentInParent<InventoryGrid>();
				if ((Object)(object)componentInParent2 != (Object)null && componentInParent2.GetInventory() != null)
				{
					ItemData itemAt = componentInParent2.GetInventory().GetItemAt(componentInParent.Position.x, componentInParent.Position.y);
					if (itemAt != null)
					{
						return itemAt;
					}
				}
			}
		}
		if (s_inventoryGuiDragItemField != null)
		{
			object? value = s_inventoryGuiDragItemField.GetValue(InventoryGui.instance);
			ItemData val3 = (ItemData)((value is ItemData) ? value : null);
			if (val3 != null)
			{
				return val3;
			}
		}
		if (ZInput.IsGamepadActive())
		{
			if ((Object)(object)InventoryGui.instance.m_playerGrid != (Object)null)
			{
				ItemData gamepadSelectedItem = InventoryGui.instance.m_playerGrid.GetGamepadSelectedItem();
				if (gamepadSelectedItem != null)
				{
					return gamepadSelectedItem;
				}
			}
			if ((Object)(object)InventoryGui.instance.ContainerGrid != (Object)null)
			{
				ItemData gamepadSelectedItem2 = InventoryGui.instance.ContainerGrid.GetGamepadSelectedItem();
				if (gamepadSelectedItem2 != null)
				{
					return gamepadSelectedItem2;
				}
			}
		}
		return null;
	}

	public static bool IsContainerVisible(Vector3 eyePos, Container container)
	{
		//IL_0032: 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_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: 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_0069: 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_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: 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_0125: 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_013a: 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_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: 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_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: 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_0190: 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_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: 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_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: 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)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		Collider componentInChildren = ((Component)container).GetComponentInChildren<Collider>();
		Vector3 val;
		if (!((Object)(object)componentInChildren != (Object)null))
		{
			val = ((Component)container).transform.position + Vector3.up * 0.5f;
		}
		else
		{
			Bounds bounds = componentInChildren.bounds;
			val = ((Bounds)(ref bounds)).center;
		}
		Vector3 val2 = val;
		float num = Vector3.Distance(eyePos, val2);
		if (num < 1.8f)
		{
			return true;
		}
		int num2 = ((ChestHelperPlugin.MaxWallObstacles != null) ? ChestHelperPlugin.MaxWallObstacles.Value : 2);
		Vector3 val3 = val2 - eyePos;
		Vector3 normalized = ((Vector3)(ref val3)).normalized;
		Vector3 start = eyePos + normalized * 0.35f;
		Vector3 up = Vector3.up;
		float num3;
		if (!((Object)(object)componentInChildren != (Object)null))
		{
			num3 = 0.25f;
		}
		else
		{
			Bounds bounds2 = componentInChildren.bounds;
			num3 = ((Bounds)(ref bounds2)).extents.y * 0.75f;
		}
		Vector3 val4 = up * num3;
		Vector3 right = ((Component)container).transform.right;
		float num4;
		if (!((Object)(object)componentInChildren != (Object)null))
		{
			num4 = 0.25f;
		}
		else
		{
			Bounds bounds3 = componentInChildren.bounds;
			num4 = ((Bounds)(ref bounds3)).extents.x * 0.65f;
		}
		Vector3 val5 = right * num4;
		Vector3 forward = ((Component)container).transform.forward;
		float num5;
		if (!((Object)(object)componentInChildren != (Object)null))
		{
			num5 = 0.25f;
		}
		else
		{
			Bounds bounds4 = componentInChildren.bounds;
			num5 = ((Bounds)(ref bounds4)).extents.z * 0.65f;
		}
		Vector3 val6 = forward * num5;
		float num6;
		if (!((Object)(object)componentInChildren != (Object)null))
		{
			num6 = 0.2f;
		}
		else
		{
			Bounds bounds5 = componentInChildren.bounds;
			float x = ((Bounds)(ref bounds5)).extents.x;
			Bounds bounds6 = componentInChildren.bounds;
			num6 = Mathf.Min(x, ((Bounds)(ref bounds6)).extents.z) * 0.5f;
		}
		Vector3 target = val2 - normalized * num6;
		if (CheckPointObstacles(start, val2, container) <= num2)
		{
			return true;
		}
		if (CheckPointObstacles(start, target, container) <= num2)
		{
			return true;
		}
		if (CheckPointObstacles(start, val2 + val4, container) <= num2)
		{
			return true;
		}
		if (CheckPointObstacles(start, val2 + val5, container) <= num2)
		{
			return true;
		}
		if (CheckPointObstacles(start, val2 - val5, container) <= num2)
		{
			return true;
		}
		if (CheckPointObstacles(start, val2 + val6, container) <= num2)
		{
			return true;
		}
		if (CheckPointObstacles(start, val2 - val6, container) <= num2)
		{
			return true;
		}
		return false;
	}

	private static int CheckPointObstacles(Vector3 start, Vector3 target, Container container)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = target - start;
		float magnitude = ((Vector3)(ref val)).magnitude;
		if (magnitude < 0.2f)
		{
			return 0;
		}
		int viewBlockMask = GetViewBlockMask();
		int num = Physics.RaycastNonAlloc(start, ((Vector3)(ref val)).normalized, s_raycastHits, magnitude - 0.05f, viewBlockMask);
		if (num <= 0)
		{
			return 0;
		}
		int num2 = 0;
		for (int i = 0; i < num; i++)
		{
			Collider collider = ((RaycastHit)(ref s_raycastHits[i])).collider;
			if (!((Object)(object)collider == (Object)null) && !collider.isTrigger && !((Object)(object)((Component)collider).GetComponentInParent<Player>() != (Object)null) && !((Object)(object)((Component)collider).GetComponentInParent<Character>() != (Object)null) && !((Object)(object)((Component)collider).GetComponentInParent<Container>() != (Object)null) && ((Component)collider).gameObject.layer != LayerMask.NameToLayer("Default_small"))
			{
				num2++;
			}
		}
		return num2;
	}

	private static void Highlight(Container container)
	{
		if (!((Object)(object)container == (Object)null) && !((Object)(object)((Component)container).gameObject == (Object)null))
		{
			ChestHighlightEffect component = ((Component)container).gameObject.GetComponent<ChestHighlightEffect>();
			if ((Object)(object)component == (Object)null)
			{
				component = ((Component)container).gameObject.AddComponent<ChestHighlightEffect>();
			}
			else
			{
				component.FadeIn();
			}
		}
	}

	private static void Unhighlight(Container container)
	{
		if (!((Object)(object)container == (Object)null) && !((Object)(object)((Component)container).gameObject == (Object)null))
		{
			ChestHighlightEffect component = ((Component)container).gameObject.GetComponent<ChestHighlightEffect>();
			if ((Object)(object)component != (Object)null)
			{
				component.FadeOut();
			}
		}
	}
}
public class ChestHighlightEffect : MonoBehaviour
{
	private const float TRANSITION_DURATION = 0.12f;

	private static Texture2D s_mistTexture;

	private static Texture2D s_wispTexture;

	private static Mesh s_quadMesh;

	private List<GameObject> m_auraObjects = new List<GameObject>();

	private List<Mesh> m_generatedMeshes = new List<Mesh>();

	private Material m_shroudMat1;

	private Material m_shroudMat2;

	private Color m_shroudColor;

	private GameObject m_wispRoot;

	private GameObject m_wispCore;

	private GameObject m_ember1;

	private GameObject m_ember2;

	private GameObject m_ember3;

	private Material m_wispMaterial;

	private Vector3 m_wispLocalPos;

	private Light m_light;

	private float m_baseIntensity;

	private float m_transition;

	private float m_targetTransition = 1f;

	private Color m_glowColor = Color.black;

	private float m_surfaceGlow;

	public static Texture2D GetOrCreateMistTexture()
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)s_mistTexture != (Object)null)
		{
			return s_mistTexture;
		}
		int num = 128;
		s_mistTexture = new Texture2D(num, num, (TextureFormat)4, false);
		((Texture)s_mistTexture).wrapMode = (TextureWrapMode)0;
		((Texture)s_mistTexture).filterMode = (FilterMode)1;
		Color[] array = (Color[])(object)new Color[num * num];
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				float num2 = (float)j / (float)num;
				float num3 = (float)i / (float)num;
				float num4 = Mathf.Clamp01(Mathf.Min(num3, 1f - num3) / 0.18f);
				float num5 = num4 * num4 * (3f - 2f * num4);
				float num6 = num2 * (float)Math.PI * 2f;
				float num7 = Mathf.Cos(num6) * 0.8f + 1.5f;
				float num8 = Mathf.Sin(num6) * 0.8f + 1.5f;
				float num9 = Mathf.PerlinNoise(num7 * 2f, num3 * 3.5f + num8 * 0.5f);
				float num10 = Mathf.PerlinNoise(num7 * 4f + 3.1f, num3 * 6f + num8 * 0.8f) * 0.4f;
				float num11 = (num9 + num10) / 1.4f;
				float num12 = Mathf.Clamp01(num11 * num5 * 0.7f);
				ref Color reference = ref array[i * num + j];
				reference = new Color(1f, 1f, 1f, num12);
			}
		}
		s_mistTexture.SetPixels(array);
		s_mistTexture.Apply();
		return s_mistTexture;
	}

	private static Mesh CreateExtrudedMesh(Mesh original, float offset)
	{
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Expected O, but got Unknown
		//IL_0061: 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_0073: 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_007d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)original == (Object)null)
		{
			return null;
		}
		Vector3[] vertices = original.vertices;
		if (vertices == null || vertices.Length == 0)
		{
			return null;
		}
		Vector3[] normals = original.normals;
		if (normals == null || normals.Length != vertices.Length)
		{
			original.RecalculateNormals();
			normals = original.normals;
		}
		Vector3[] array = (Vector3[])(object)new Vector3[vertices.Length];
		if (normals != null && normals.Length == vertices.Length)
		{
			for (int i = 0; i < vertices.Length; i++)
			{
				ref Vector3 reference = ref array[i];
				reference = vertices[i] + normals[i] * offset;
			}
		}
		else
		{
			for (int j = 0; j < vertices.Length; j++)
			{
				ref Vector3 reference2 = ref array[j];
				reference2 = vertices[j] * (1f + offset * 0.5f);
			}
		}
		Mesh val = new Mesh();
		((Object)val).name = ((Object)original).name + "_ExtrudedMisty";
		val.vertices = array;
		val.normals = normals;
		val.uv = original.uv;
		val.triangles = original.triangles;
		return val;
	}

	private static Mesh CreateShroudBoxMesh(Vector3 extents)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: 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_005a: 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_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: 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_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: 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_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: 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_0150: 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_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: 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_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: 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_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: 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_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_0298: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0308: Unknown result type (might be due to invalid IL or missing references)
		//IL_030d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0324: Unknown result type (might be due to invalid IL or missing references)
		//IL_0329: Unknown result type (might be due to invalid IL or missing references)
		//IL_0340: Unknown result type (might be due to invalid IL or missing references)
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0361: Unknown result type (might be due to invalid IL or missing references)
		//IL_0379: Unknown result type (might be due to invalid IL or missing references)
		//IL_037e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0396: Unknown result type (might be due to invalid IL or missing references)
		//IL_039b: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_040a: Unknown result type (might be due to invalid IL or missing references)
		//IL_040f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0427: Unknown result type (might be due to invalid IL or missing references)
		//IL_042c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0444: Unknown result type (might be due to invalid IL or missing references)
		//IL_0449: Unknown result type (might be due to invalid IL or missing references)
		//IL_0461: Unknown result type (might be due to invalid IL or missing references)
		//IL_0466: Unknown result type (might be due to invalid IL or missing references)
		//IL_047e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0483: Unknown result type (might be due to invalid IL or missing references)
		//IL_049b: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04da: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_050f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0514: Unknown result type (might be due to invalid IL or missing references)
		Mesh val = new Mesh();
		((Object)val).name = "ChestMistyFallbackMesh";
		float x = extents.x;
		float y = extents.y;
		float z = extents.z;
		Vector3[] vertices = (Vector3[])(object)new Vector3[24]
		{
			new Vector3(0f - x, 0f - y, z),
			new Vector3(x, 0f - y, z),
			new Vector3(x, y, z),
			new Vector3(0f - x, y, z),
			new Vector3(x, 0f - y, 0f - z),
			new Vector3(0f - x, 0f - y, 0f - z),
			new Vector3(0f - x, y, 0f - z),
			new Vector3(x, y, 0f - z),
			new Vector3(x, 0f - y, z),
			new Vector3(x, 0f - y, 0f - z),
			new Vector3(x, y, 0f - z),
			new Vector3(x, y, z),
			new Vector3(0f - x, 0f - y, 0f - z),
			new Vector3(0f - x, 0f - y, z),
			new Vector3(0f - x, y, z),
			new Vector3(0f - x, y, 0f - z),
			new Vector3(0f - x, y, 0f - z),
			new Vector3(x, y, 0f - z),
			new Vector3(x, y, z),
			new Vector3(0f - x, y, z),
			new Vector3(0f - x, 0f - y, z),
			new Vector3(x, 0f - y, z),
			new Vector3(x, 0f - y, 0f - z),
			new Vector3(0f - x, 0f - y, 0f - z)
		};
		Vector2[] uv = (Vector2[])(object)new Vector2[24]
		{
			new Vector2(0f, 0f),
			new Vector2(1f, 0f),
			new Vector2(1f, 1f),
			new Vector2(0f, 1f),
			new Vector2(0f, 0f),
			new Vector2(1f, 0f),
			new Vector2(1f, 1f),
			new Vector2(0f, 1f),
			new Vector2(0f, 0f),
			new Vector2(1f, 0f),
			new Vector2(1f, 1f),
			new Vector2(0f, 1f),
			new Vector2(0f, 0f),
			new Vector2(1f, 0f),
			new Vector2(1f, 1f),
			new Vector2(0f, 1f),
			new Vector2(0f, 0f),
			new Vector2(1f, 0f),
			new Vector2(1f, 1f),
			new Vector2(0f, 1f),
			new Vector2(0f, 0f),
			new Vector2(1f, 0f),
			new Vector2(1f, 1f),
			new Vector2(0f, 1f)
		};
		int[] triangles = new int[36]
		{
			0, 2, 1, 0, 3, 2, 4, 6, 5, 4,
			7, 6, 8, 10, 9, 8, 11, 10, 12, 14,
			13, 12, 15, 14, 16, 18, 17, 16, 19, 18,
			20, 22, 21, 20, 23, 22
		};
		val.vertices = vertices;
		val.uv = uv;
		val.triangles = triangles;
		val.RecalculateNormals();
		return val;
	}

	public static Texture2D GetOrCreateWispTexture()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)s_wispTexture != (Object)null)
		{
			return s_wispTexture;
		}
		int num = 64;
		s_wispTexture = new Texture2D(num, num, (TextureFormat)4, false);
		((Texture)s_wispTexture).wrapMode = (TextureWrapMode)1;
		((Texture)s_wispTexture).filterMode = (FilterMode)1;
		Color[] array = (Color[])(object)new Color[num * num];
		float num2 = (float)num * 0.5f;
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				float num3 = ((float)j - num2) / num2;
				float num4 = ((float)i - num2) / num2;
				float num5 = Mathf.Sqrt(num3 * num3 + num4 * num4);
				if (num5 >= 1f)
				{
					ref Color reference = ref array[i * num + j];
					reference = Color.clear;
					continue;
				}
				float num6 = 1f - num5;
				float num7 = num6 * num6 * (3f - 2f * num6);
				float num8 = Mathf.PerlinNoise(num3 * 3f + 1.5f, num4 * 3f + 1.5f) * 0.18f;
				float num9 = Mathf.Clamp01(num7 + (1f - num5) * num8);
				float num10 = ((num5 < 0.28f) ? 1f : Mathf.Lerp(1f, 0.88f, (num5 - 0.28f) / 0.72f));
				ref Color reference2 = ref array[i * num + j];
				reference2 = new Color(num10, num10, 1f, num9);
			}
		}
		s_wispTexture.SetPixels(array);
		s_wispTexture.Apply();
		return s_wispTexture;
	}

	private static Mesh GetOrCreateQuadMesh()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: 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_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)s_quadMesh != (Object)null)
		{
			return s_quadMesh;
		}
		s_quadMesh = new Mesh();
		((Object)s_quadMesh).name = "WispSharedQuad";
		s_quadMesh.vertices = (Vector3[])(object)new Vector3[4]
		{
			new Vector3(-0.5f, -0.5f, 0f),
			new Vector3(0.5f, -0.5f, 0f),
			new Vector3(0.5f, 0.5f, 0f),
			new Vector3(-0.5f, 0.5f, 0f)
		};
		s_quadMesh.uv = (Vector2[])(object)new Vector2[4]
		{
			new Vector2(0f, 0f),
			new Vector2(1f, 0f),
			new Vector2(1f, 1f),
			new Vector2(0f, 1f)
		};
		s_quadMesh.triangles = new int[6] { 0, 2, 1, 0, 3, 2 };
		s_quadMesh.RecalculateNormals();
		return s_quadMesh;
	}

	public void FadeIn()
	{
		m_targetTransition = 1f;
	}

	public void FadeOut()
	{
		m_targetTransition = 0f;
	}

	private void Awake()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: 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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: 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_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Expected O, but got Unknown
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Expected O, but got Unknown
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_0549: Unknown result type (might be due to invalid IL or missing references)
		//IL_054a: Unknown result type (might be due to invalid IL or missing references)
		//IL_055c: 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_0566: Unknown result type (might be due to invalid IL or missing references)
		//IL_048b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0492: Expected O, but got Unknown
		//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0580: Unknown result type (might be due to invalid IL or missing references)
		//IL_058a: Expected O, but got Unknown
		//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_05dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e7: Expected O, but got Unknown
		//IL_0608: Unknown result type (might be due to invalid IL or missing references)
		//IL_0627: Unknown result type (might be due to invalid IL or missing references)
		//IL_0631: 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_063e: Unknown result type (might be due to invalid IL or missing references)
		//IL_064b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0655: Expected O, but got Unknown
		//IL_067c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0691: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_06eb: Expected O, but got Unknown
		//IL_0712: Unknown result type (might be due to invalid IL or missing references)
		//IL_0762: Unknown result type (might be due to invalid IL or missing references)
		//IL_076c: Expected O, but got Unknown
		//IL_0793: Unknown result type (might be due to invalid IL or missing references)
		//IL_07e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ed: Expected O, but got Unknown
		//IL_0814: Unknown result type (might be due to invalid IL or missing references)
		//IL_0880: Unknown result type (might be due to invalid IL or missing references)
		//IL_08f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_08f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_08fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_030d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0314: Expected O, but got Unknown
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0340: Unknown result type (might be due to invalid IL or missing references)
		//IL_0351: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d9: Expected O, but got Unknown
		//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0405: Unknown result type (might be due to invalid IL or missing references)
		//IL_0416: Unknown result type (might be due to invalid IL or missing references)
		Color highlightColor = ChestHelperPlugin.GetHighlightColor();
		Container component = ((Component)this).GetComponent<Container>();
		Bounds val = (Bounds)(((Object)(object)component != (Object)null) ? ChestMiragePreview.CalculateLocalBounds(component) : new Bounds(Vector3.up * 0.4f, new Vector3(1f, 0.8f, 0.6f)));
		Vector3 center = ((Bounds)(ref val)).center;
		Vector3 extents = ((Bounds)(ref val)).extents;
		m_surfaceGlow = Mathf.Clamp(ChestHelperPlugin.ChestSurfaceGlow.Value, 0f, 2f);
		if (m_surfaceGlow > 0f)
		{
			m_glowColor = Color.Lerp(new Color(0.85f, 0.92f, 1f), highlightColor, 0.25f) * (m_surfaceGlow * 0.45f);
		}
		Shader val2 = Shader.Find("Sprites/Default") ?? Shader.Find("GUI/Text Shader") ?? Shader.Find("Particles/Standard Unlit") ?? Shader.Find("Unlit/Transparent");
		Texture2D orCreateMistTexture = GetOrCreateMistTexture();
		m_shroudColor = Color.Lerp(new Color(0.92f, 0.96f, 1f, 0.45f), new Color(highlightColor.r, highlightColor.g, highlightColor.b, 0.45f), 0.25f);
		m_shroudMat1 = new Material(val2);
		m_shroudMat1.mainTexture = (Texture)(object)orCreateMistTexture;
		m_shroudMat1.mainTextureScale = new Vector2(2.5f, 2.5f);
		m_shroudMat1.color = new Color(m_shroudColor.r, m_shroudColor.g, m_shroudColor.b, 0f);
		m_shroudMat2 = new Material(val2);
		m_shroudMat2.mainTexture = (Texture)(object)orCreateMistTexture;
		m_shroudMat2.mainTextureScale = new Vector2(2f, 2f);
		m_shroudMat2.color = new Color(m_shroudColor.r, m_shroudColor.g, m_shroudColor.b, 0f);
		MeshFilter[] array = (((Object)(object)component != (Object)null) ? ((Component)component).GetComponentsInChildren<MeshFilter>() : null);
		if (array != null && array.Length > 0)
		{
			foreach (MeshFilter val3 in array)
			{
				if (!((Object)(object)val3 == (Object)null) && ((Component)val3).gameObject.activeInHierarchy && !((Object)(object)val3.sharedMesh == (Object)null) && !((Object)val3).name.StartsWith("ChestMeshAura") && !((Object)val3).name.StartsWith("ChestHighlight") && ((Component)val3).GetComponent<Renderer>() is MeshRenderer && val3.sharedMesh.vertexCount != 0 && val3.sharedMesh.vertexCount <= 15000)
				{
					Mesh val4 = CreateExtrudedMesh(val3.sharedMesh, 0.018f);
					if ((Object)(object)val4 != (Object)null)
					{
						m_generatedMeshes.Add(val4);
						GameObject val5 = new GameObject("ChestMeshAura1");
						val5.transform.SetParent(((Component)val3).transform, false);
						val5.transform.localPosition = Vector3.zero;
						val5.transform.localRotation = Quaternion.identity;
						val5.transform.localScale = Vector3.one;
						MeshFilter val6 = val5.AddComponent<MeshFilter>();
						val6.sharedMesh = val4;
						MeshRenderer val7 = val5.AddComponent<MeshRenderer>();
						((Renderer)val7).material = m_shroudMat1;
						((Renderer)val7).shadowCastingMode = (ShadowCastingMode)0;
						((Renderer)val7).receiveShadows = false;
						m_auraObjects.Add(val5);
					}
					Mesh val8 = CreateExtrudedMesh(val3.sharedMesh, 0.038f);
					if ((Object)(object)val8 != (Object)null)
					{
						m_generatedMeshes.Add(val8);
						GameObject val9 = new GameObject("ChestMeshAura2");
						val9.transform.SetParent(((Component)val3).transform, false);
						val9.transform.localPosition = Vector3.zero;
						val9.transform.localRotation = Quaternion.identity;
						val9.transform.localScale = Vector3.one;
						MeshFilter val10 = val9.AddComponent<MeshFilter>();
						val10.sharedMesh = val8;
						MeshRenderer val11 = val9.AddComponent<MeshRenderer>();
						((Renderer)val11).material = m_shroudMat2;
						((Renderer)val11).shadowCastingMode = (ShadowCastingMode)0;
						((Renderer)val11).receiveShadows = false;
						m_auraObjects.Add(val9);
					}
				}
			}
		}
		if (m_auraObjects.Count == 0)
		{
			GameObject val12 = new GameObject("ChestMeshAuraFallback");
			val12.transform.SetParent(((Component)this).transform, false);
			val12.transform.localPosition = center;
			val12.transform.localRotation = Quaternion.identity;
			val12.transform.localScale = Vector3.one;
			Mesh val13 = CreateShroudBoxMesh(extents + new Vector3(0.02f, 0.02f, 0.02f));
			m_generatedMeshes.Add(val13);
			MeshFilter val14 = val12.AddComponent<MeshFilter>();
			val14.sharedMesh = val13;
			MeshRenderer val15 = val12.AddComponent<MeshRenderer>();
			((Renderer)val15).material = m_shroudMat1;
			((Renderer)val15).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val15).receiveShadows = false;
			m_auraObjects.Add(val12);
		}
		m_wispLocalPos = center + Vector3.up * (extents.y + 0.22f);
		if (ChestHelperPlugin.EnableChestBeacon.Value)
		{
			m_wispRoot = new GameObject("ChestHighlightWisp");
			m_wispRoot.transform.SetParent(((Component)this).transform, false);
			m_wispRoot.transform.localPosition = m_wispLocalPos;
			m_wispRoot.transform.localRotation = Quaternion.identity;
			Mesh orCreateQuadMesh = GetOrCreateQuadMesh();
			Texture2D orCreateWispTexture = GetOrCreateWispTexture();
			m_wispMaterial = new Material(val2);
			m_wispMaterial.mainTexture = (Texture)(object)orCreateWispTexture;
			Color color = Color.Lerp(new Color(0.92f, 0.96f, 1f, 0.95f), new Color(highlightColor.r, highlightColor.g, highlightColor.b, 0.95f), 0.35f);
			m_wispMaterial.color = color;
			m_wispCore = new GameObject("WispCore");
			m_wispCore.transform.SetParent(m_wispRoot.transform, false);
			m_wispCore.transform.localPosition = Vector3.zero;
			m_wispCore.transform.localScale = Vector3.zero;
			MeshFilter val16 = m_wispCore.AddComponent<MeshFilter>();
			val16.sharedMesh = orCreateQuadMesh;
			MeshRenderer val17 = m_wispCore.AddComponent<MeshRenderer>();
			((Renderer)val17).material = m_wispMaterial;
			((Renderer)val17).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val17).receiveShadows = false;
			m_ember1 = new GameObject("WispEmber1");
			m_ember1.transform.SetParent(m_wispRoot.transform, false);
			m_ember1.transform.localScale = Vector3.zero;
			MeshFilter val18 = m_ember1.AddComponent<MeshFilter>();
			val18.sharedMesh = orCreateQuadMesh;
			MeshRenderer val19 = m_ember1.AddComponent<MeshRenderer>();
			((Renderer)val19).material = m_wispMaterial;
			((Renderer)val19).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val19).receiveShadows = false;
			m_ember2 = new GameObject("WispEmber2");
			m_ember2.transform.SetParent(m_wispRoot.transform, false);
			m_ember2.transform.localScale = Vector3.zero;
			MeshFilter val20 = m_ember2.AddComponent<MeshFilter>();
			val20.sharedMesh = orCreateQuadMesh;
			MeshRenderer val21 = m_ember2.AddComponent<MeshRenderer>();
			((Renderer)val21).material = m_wispMaterial;
			((Renderer)val21).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val21).receiveShadows = false;
			m_ember3 = new GameObject("WispEmber3");
			m_ember3.transform.SetParent(m_wispRoot.transform, false);
			m_ember3.transform.localScale = Vector3.zero;
			MeshFilter val22 = m_ember3.AddComponent<MeshFilter>();
			val22.sharedMesh = orCreateQuadMesh;
			MeshRenderer val23 = m_ember3.AddComponent<MeshRenderer>();
			((Renderer)val23).material = m_wispMaterial;
			((Renderer)val23).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val23).receiveShadows = false;
		}
		if (ChestHelperPlugin.EnableChestLight.Value)
		{
			GameObject val24 = (GameObject)(((Object)(object)m_wispRoot != (Object)null) ? ((object)m_wispRoot) : ((object)new GameObject("ChestHighlightLight")));
			if ((Object)(object)m_wispRoot == (Object)null)
			{
				val24.transform.SetParent(((Component)this).transform, false);
				val24.transform.localPosition = m_wispLocalPos;
			}
			m_light = val24.AddComponent<Light>();
			m_light.type = (LightType)2;
			m_light.color = Color.Lerp(new Color(0.92f, 0.96f, 1f), highlightColor, 0.35f);
			m_light.range = ChestHelperPlugin.LightRange.Value;
			m_baseIntensity = ChestHelperPlugin.LightIntensity.Value;
			m_light.intensity = 0f;
			m_light.shadows = (LightShadows)0;
			if ((Object)(object)m_wispRoot == (Object)null)
			{
				m_wispRoot = val24;
			}
		}
	}

	private void Update()
	{
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: 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_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: 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_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_0273: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0304: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_031f: Unknown result type (might be due to invalid IL or missing references)
		//IL_032b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0340: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0441: Unknown result type (might be due to invalid IL or missing references)
		//IL_0447: Unknown result type (might be due to invalid IL or missing references)
		//IL_045c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0468: Unknown result type (might be due to invalid IL or missing references)
		//IL_047d: Unknown result type (might be due to invalid IL or missing references)
		float num = Time.unscaledDeltaTime / 0.12f;
		m_transition = Mathf.MoveTowards(m_transition, m_targetTransition, num);
		if (m_targetTransition <= 0f && m_transition <= 0f)
		{
			Object.Destroy((Object)(object)this);
			return;
		}
		float num2 = 1f - (1f - m_transition) * (1f - m_transition);
		if (m_surfaceGlow > 0f && (Object)(object)MaterialMan.instance != (Object)null)
		{
			MaterialMan.instance.SetValue<Color>(((Component)this).gameObject, ShaderProps._EmissionColor, m_glowColor * num2, false);
		}
		float time = Time.time;
		if ((Object)(object)m_shroudMat1 != (Object)null)
		{
			m_shroudMat1.mainTextureOffset = new Vector2(time * 0.035f, Mathf.Sin(time * 0.5f) * 0.015f);
			float num3 = 0.88f + 0.12f * Mathf.Sin(time * 2.2f);
			m_shroudMat1.color = new Color(m_shroudColor.r, m_shroudColor.g, m_shroudColor.b, m_shroudColor.a * num3 * num2);
		}
		if ((Object)(object)m_shroudMat2 != (Object)null)
		{
			m_shroudMat2.mainTextureOffset = new Vector2((0f - time) * 0.024f, Mathf.Cos(time * 0.7f) * 0.015f);
			float num4 = 0.8f + 0.2f * Mathf.Cos(time * 1.6f);
			m_shroudMat2.color = new Color(m_shroudColor.r, m_shroudColor.g, m_shroudColor.b, m_shroudColor.a * 0.6f * num4 * num2);
		}
		if ((Object)(object)m_wispRoot != (Object)null)
		{
			float num5 = Mathf.Sin(time * 2.2f) * 0.022f + Mathf.Sin(time * 4.3f) * 0.007f;
			m_wispRoot.transform.localPosition = m_wispLocalPos + Vector3.up * num5;
			Quaternion rotation = (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform.rotation : Quaternion.identity);
			if ((Object)(object)m_wispCore != (Object)null)
			{
				m_wispCore.transform.rotation = rotation;
				float num6 = (0.25f + 0.025f * Mathf.Sin(time * 3.2f)) * num2;
				m_wispCore.transform.localScale = Vector3.one * num6;
			}
			if ((Object)(object)m_ember1 != (Object)null)
			{
				float num7 = time * 2.8f;
				m_ember1.transform.localPosition = new Vector3(Mathf.Cos(num7) * 0.11f, Mathf.Sin(num7 * 1.4f) * 0.035f, Mathf.Sin(num7) * 0.09f) * num2;
				m_ember1.transform.localScale = Vector3.one * (0.065f * num2);
				m_ember1.transform.rotation = rotation;
			}
			if ((Object)(object)m_ember2 != (Object)null)
			{
				float num8 = (0f - time) * 2.2f + 1.6f;
				m_ember2.transform.localPosition = new Vector3(Mathf.Cos(num8) * 0.09f, Mathf.Sin(num8) * 0.06f, Mathf.Sin(num8 * 0.8f) * 0.12f) * num2;
				m_ember2.transform.localScale = Vector3.one * (0.052f * num2);
				m_ember2.transform.rotation = rotation;
			}
			if ((Object)(object)m_ember3 != (Object)null)
			{
				float num9 = time * 1.5f + 3.14f;
				m_ember3.transform.localPosition = new Vector3(Mathf.Sin(num9) * 0.13f, Mathf.Cos(num9 * 1.2f) * 0.045f - 0.015f, Mathf.Cos(num9) * 0.11f) * num2;
				m_ember3.transform.localScale = Vector3.one * (0.042f * num2);
				m_ember3.transform.rotation = rotation;
			}
			if ((Object)(object)m_light != (Object)null)
			{
				float num10 = 0.88f + 0.15f * Mathf.Sin(time * 4.5f);
				m_light.intensity = m_baseIntensity * num10 * num2;
			}
		}
	}

	private void OnDestroy()
	{
		if ((Object)(object)MaterialMan.instance != (Object)null)
		{
			MaterialMan.instance.ResetValue(((Component)this).gameObject, ShaderProps._Color);
			MaterialMan.instance.ResetValue(((Component)this).gameObject, ShaderProps._EmissionColor);
		}
		for (int i = 0; i < m_auraObjects.Count; i++)
		{
			if ((Object)(object)m_auraObjects[i] != (Object)null)
			{
				Object.Destroy((Object)(object)m_auraObjects[i]);
			}
		}
		m_auraObjects.Clear();
		for (int j = 0; j < m_generatedMeshes.Count; j++)
		{
			if ((Object)(object)m_generatedMeshes[j] != (Object)null)
			{
				Object.Destroy((Object)(object)m_generatedMeshes[j]);
			}
		}
		m_generatedMeshes.Clear();
		if ((Object)(object)m_shroudMat1 != (Object)null)
		{
			Object.Destroy((Object)(object)m_shroudMat1);
		}
		if ((Object)(object)m_shroudMat2 != (Object)null)
		{
			Object.Destroy((Object)(object)m_shroudMat2);
		}
		if ((Object)(object)m_wispRoot != (Object)null)
		{
			Object.Destroy((Object)(object)m_wispRoot);
		}
		if ((Object)(object)m_wispMaterial != (Object)null)
		{
			Object.Destroy((Object)(object)m_wispMaterial);
		}
	}
}
[HarmonyPatch(typeof(Container), "Awake")]
public static class Container_Awake_Patch
{
	public static void Postfix(Container __instance)
	{
		ChestHighlightManager.Register(__instance);
	}
}
[HarmonyPatch(typeof(Container), "OnDestroyed")]
public static class Container_OnDestroyed_Patch
{
	public static void Postfix(Container __instance)
	{
		ChestHighlightManager.Unregister(__instance);
	}
}
public static class ChestSorter
{
	private delegate bool CheckAccessDelegate(Container container, long playerID);

	private delegate void InventoryChangedDelegate(Inventory inv, bool success, bool cheated);

	private static GameObject s_sortButtonObject;

	private static readonly FieldInfo s_currentContainerField = AccessTools.Field(typeof(InventoryGui), "m_currentContainer");

	private static readonly FieldInfo s_dragItemField = AccessTools.Field(typeof(InventoryGui), "m_dragItem");

	private static readonly CheckAccessDelegate s_checkAccess = AccessTools.MethodDelegate<CheckAccessDelegate>(AccessTools.Method(typeof(Container), "CheckAccess", new Type[1] { typeof(long) }, (Type[])null), (object)null, true);

	private static readonly InventoryChangedDelegate s_inventoryChanged = AccessTools.MethodDelegate<InventoryChangedDelegate>(AccessTools.Method(typeof(Inventory), "Changed", new Type[2]
	{
		typeof(bool),
		typeof(bool)
	}, (Type[])null), (object)null, true);

	private static string s_lastLanguage = null;

	private static string s_currentAppliedText = null;

	public static string GetSortButtonText()
	{
		string text = ((ChestHelperPlugin.SortButtonText != null) ? ChestHelperPlugin.SortButtonText.Value : null);
		if (!string.IsNullOrEmpty(text) && !text.Equals("Auto", StringComparison.OrdinalIgnoreCase) && !text.Contains("?") && !text.Contains("Р\u00a0") && !text.Contains("вЂ") && text.Trim().Length > 0)
		{
			return text;
		}
		string text2 = null;
		try
		{
			if (Localization.instance != null)
			{
				text2 = Localization.instance.GetSelectedLanguage();
			}
		}
		catch
		{
		}
		if (!string.IsNullOrEmpty(text2) && (text2.Equals("Russian", StringComparison.OrdinalIgnoreCase) || text2.StartsWith("rus", StringComparison.OrdinalIgnoreCase)))
		{
			return "Сортировать";
		}
		return "Sort";
	}

	public static void RefreshButtonText()
	{
		if ((Object)(object)s_sortButtonObject == (Object)null)
		{
			return;
		}
		string text = null;
		try
		{
			if (Localization.instance != null)
			{
				text = Localization.instance.GetSelectedLanguage();
			}
		}
		catch
		{
		}
		if (text == s_lastLanguage && s_currentAppliedText != null)
		{
			return;
		}
		s_lastLanguage = text;
		string text2 = (s_currentAppliedText = GetSortButtonText());
		TMP_Text componentInChildren = s_sortButtonObject.GetComponentInChildren<TMP_Text>();
		if ((Object)(object)componentInChildren != (Object)null)
		{
			componentInChildren.text = text2;
			return;
		}
		Text componentInChildren2 = s_sortButtonObject.GetComponentInChildren<Text>();
		if ((Object)(object)componentInChildren2 != (Object)null)
		{
			componentInChildren2.text = text2;
		}
	}

	public static void UpdateSortButton()
	{
		if ((Object)(object)InventoryGui.instance == (Object)null || (Object)(object)InventoryGui.instance.m_container == (Object)null)
		{
			if ((Object)(object)s_sortButtonObject != (Object)null)
			{
				s_sortButtonObject.SetActive(false);
			}
		}
		else if (((Component)InventoryGui.instance.m_container).gameObject.activeInHierarchy)
		{
			if ((Object)(object)s_sortButtonObject == (Object)null)
			{
				CreateSortButton(InventoryGui.instance);
				return;
			}
			if (!s_sortButtonObject.activeSelf)
			{
				s_sortButtonObject.SetActive(true);
			}
			RefreshButtonText();
		}
		else if ((Object)(object)s_sortButtonObject != (Object)null && s_sortButtonObject.activeSelf)
		{
			s_sortButtonObject.SetActive(false);
		}
	}

	public static void CreateSortButton(InventoryGui gui)
	{
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Expected O, but got Unknown
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Expected O, but got Unknown
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: 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_0280: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)s_sortButtonObject != (Object)null || (Object)(object)gui == (Object)null || (Object)(object)gui.m_container == (Object)null)
		{
			return;
		}
		GameObject val = null;
		if ((Object)(object)gui.m_stackAllButton != (Object)null)
		{
			val = ((Component)gui.m_stackAllButton).gameObject;
		}
		else if ((Object)(object)gui.m_takeAllButton != (Object)null)
		{
			val = ((Component)gui.m_takeAllButton).gameObject;
		}
		if (!((Object)(object)val == (Object)null))
		{
			s_sortButtonObject = Object.Instantiate<GameObject>(val, val.transform.parent);
			((Object)s_sortButtonObject).name = "ChestSortButton";
			s_sortButtonObject.SetActive(true);
			Button component = s_sortButtonObject.GetComponent<Button>();
			if ((Object)(object)component != (Object)null)
			{
				component.onClick = new ButtonClickedEvent();
				((UnityEvent)component.onClick).AddListener(new UnityAction(OnSortChestClicked));
			}
			s_lastLanguage = null;
			s_currentAppliedText = null;
			RefreshButtonText();
			RectTransform component2 = s_sortButtonObject.GetComponent<RectTransform>();
			RectTransform val2 = (((Object)(object)gui.m_takeAllButton != (Object)null && ((Component)gui.m_takeAllButton).gameObject.activeSelf) ? ((Component)gui.m_takeAllButton).GetComponent<RectTransform>() : null);
			RectTransform val3 = (((Object)(object)gui.m_stackAllButton != (Object)null && ((Component)gui.m_stackAllButton).gameObject.activeSelf) ? ((Component)gui.m_stackAllButton).GetComponent<RectTransform>() : null);
			if ((Object)(object)val3 != (Object)null && (Object)(object)val2 != (Object)null)
			{
				float num = (val2.anchoredPosition.x + val3.anchoredPosition.x) * 0.5f;
				float num2 = Mathf.Min(val2.anchoredPosition.y, val3.anchoredPosition.y);
				Rect rect = val3.rect;
				float num3 = num2 - ((Rect)(ref rect)).height - 4f;
				component2.anchoredPosition = new Vector2(num, num3);
				component2.sizeDelta = val3.sizeDelta;
			}
			else if ((Object)(object)val3 != (Object)null)
			{
				float x = val3.anchoredPosition.x;
				float y = val3.anchoredPosition.y;
				Rect rect2 = val3.rect;
				component2.anchoredPosition = new Vector2(x, y - ((Rect)(ref rect2)).height - 4f);
				component2.sizeDelta = val3.sizeDelta;
			}
			else if ((Object)(object)val2 != (Object)null)
			{
				float x2 = val2.anchoredPosition.x;
				float y2 = val2.anchoredPosition.y;
				Rect rect3 = val2.rect;
				component2.anchoredPosition = new Vector2(x2, y2 - ((Rect)(ref rect3)).height - 4f);
				component2.sizeDelta = val2.sizeDelta;
			}
			else
			{
				component2.anchorMin = new Vector2(0.5f, 0f);
				component2.anchorMax = new Vector2(0.5f, 0f);
				component2.pivot = new Vector2(0.5f, 0f);
				component2.anchoredPosition = new Vector2(0f, 10f);
				component2.sizeDelta = new Vector2(140f, 36f);
			}
			ChestHelperPlugin.Log("Created ChestSortButton in UI.");
		}
	}

	public static void OnSortChestClicked()
	{
		if ((Object)(object)InventoryGui.instance == (Object)null || s_currentContainerField == null || (s_dragItemField != null && s_dragItemField.GetValue(InventoryGui.instance) != null))
		{
			return;
		}
		object? value = s_currentContainerField.GetValue(InventoryGui.instance);
		Container val = (Container)((value is Container) ? value : null);
		if (!((Object)(object)val == (Object)null) && (!((Object)(object)Player.m_localPlayer != (Object)null) || s_checkAccess == null || s_checkAccess(val, Player.m_localPlayer.GetPlayerID())))
		{
			Inventory inventory = val.GetInventory();
			if (inventory != null)
			{
				SortContainerInventory(inventory);
			}
		}
	}

	public static void SortContainerInventory(Inventory inventory)
	{
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_0267: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		List<ItemData> allItems = inventory.GetAllItems();
		if (allItems == null || allItems.Count <= 1)
		{
			return;
		}
		for (int i = 0; i < allItems.Count; i++)
		{
			ItemData val = allItems[i];
			if (val == null || val.m_shared == null || val.m_shared.m_maxStackSize <= 1 || val.m_stack >= val.m_shared.m_maxStackSize)
			{
				continue;
			}
			for (int j = i + 1; j < allItems.Count; j++)
			{
				ItemData val2 = allItems[j];
				if (val2 != null && val2.m_shared != null && val2.m_shared.m_name == val.m_shared.m_name && val2.m_quality == val.m_quality && val2.m_variant == val.m_variant && val2.m_crafterID == val.m_crafterID)
				{
					int num = val.m_shared.m_maxStackSize - val.m_stack;
					int num2 = Mathf.Min(num, val2.m_stack);
					val.m_stack += num2;
					val2.m_stack -= num2;
					if (val2.m_stack <= 0)
					{
						allItems.RemoveAt(j);
						j--;
					}
					if (val.m_stack >= val.m_shared.m_maxStackSize)
					{
						break;
					}
				}
			}
		}
		allItems.Sort(delegate(ItemData x, ItemData y)
		{
			//IL_0018: 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)
			if (x == null && y == null)
			{
				return 0;
			}
			if (x == null)
			{
				return 1;
			}
			if (y == null)
			{
				return -1;
			}
			int categoryPriority = GetCategoryPriority(x.m_shared.m_itemType);
			int categoryPriority2 = GetCategoryPriority(y.m_shared.m_itemType);
			int num5 = categoryPriority.CompareTo(categoryPriority2);
			if (num5 != 0)
			{
				return num5;
			}
			string strA = ((Localization.instance != null) ? Localization.instance.Localize(x.m_shared.m_name) : x.m_shared.m_name);
			string strB = ((Localization.instance != null) ? Localization.instance.Localize(y.m_shared.m_name) : y.m_shared.m_name);
			int num6 = string.Compare(strA, strB, StringComparison.CurrentCultureIgnoreCase);
			if (num6 != 0)
			{
				return num6;
			}
			int num7 = y.m_quality.CompareTo(x.m_quality);
			if (num7 != 0)
			{
				return num7;
			}
			int num8 = y.m_stack.CompareTo(x.m_stack);
			return (num8 != 0) ? num8 : y.m_durability.CompareTo(x.m_durability);
		});
		int num3 = inventory.GetWidth();
		if (num3 <= 0)
		{
			num3 = 8;
		}
		for (int num4 = 0; num4 < allItems.Count; num4++)
		{
			allItems[num4].m_gridPos = new Vector2i(num4 % num3, num4 / num3);
		}
		if (s_inventoryChanged != null)
		{
			s_inventoryChanged(inventory, success: false, cheated: false);
		}
		else if (inventory.m_onChanged != null)
		{
			inventory.m_onChanged();
		}
		if ((Object)(object)InventoryGui.instance != (Object)null && (Object)(object)InventoryGui.instance.ContainerGrid != (Object)null)
		{
			InventoryGui.instance.ContainerGrid.UpdateInventory(inventory, (Player)null, (ItemData)null);
		}
		if ((Object)(object)InventoryGui.instance != (Object)null && InventoryGui.instance.m_moveItemEffects != null && (Object)(object)Player.m_localPlayer != (Object)null)
		{
			InventoryGui.instance.m_moveItemEffects.Create(((Component)Player.m_localPlayer).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
		}
		ChestHelperPlugin.Log("Sorted container items (" + allItems.Count + " items).");
	}

	private static int GetCategoryPriority(ItemType type)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Expected I4, but got Unknown
		switch (type - 1)
		{
		case 2:
		case 3:
		case 4:
		case 13:
		case 14:
		case 19:
		case 21:
			return 0;
		case 18:
			return 1;
		case 5:
		case 6:
		case 10:
		case 11:
		case 16:
		case 17:
		case 23:
			return 2;
		case 8:
		case 22:
			return 3;
		case 1:
		case 20:
			return 4;
		case 0:
			return 5;
		case 12:
			return 6;
		default:
			return 7;
		}
	}
}
public static class ChestSearchBar
{
	private static GameObject s_searchBarObject;

	private static TMP_InputField s_inputField;

	private static TMP_Text s_placeholderText;

	private static string s_lastLanguage = null;

	private static readonly FieldInfo s_elementsField = AccessTools.Field(typeof(InventoryGrid), "m_elements");

	private static bool s_gridsDimmed = false;

	private static string s_lastAppliedQuery = null;

	private static int s_lastPlayerItemCount = -1;

	private static int s_lastContainerItemCount = -1;

	private static bool s_lastContainerOpenState = false;

	public static string CurrentQuery { get; private set; }

	public static bool IsSearchActive => !string.IsNullOrEmpty(CurrentQuery);

	public static bool IsFocused
	{
		get
		{
			if ((Object)(object)s_inputField != (Object)null)
			{
				return s_inputField.isFocused;
			}
			return false;
		}
	}

	public static void TakeInput_Postfix(ref bool __result)
	{
		if (IsFocused)
		{
			__result = false;
		}
	}

	public static void UpdateSearchBar()
	{
		if (!ChestHelperPlugin.EnableSearchBar.Value)
		{
			if ((Object)(object)s_searchBarObject != (Object)null && s_searchBarObject.activeSelf)
			{
				s_searchBarObject.SetActive(false);
			}
		}
		else if ((Object)(object)InventoryGui.instance == (Object)null || (Object)(object)InventoryGui.instance.m_player == (Object)null)
		{
			if ((Object)(object)s_searchBarObject != (Object)null && s_searchBarObject.activeSelf)
			{
				s_searchBarObject.SetActive(false);
			}
		}
		else if (((Component)InventoryGui.instance.m_player).gameObject.activeInHierarchy)
		{
			if ((Object)(object)s_searchBarObject == (Object)null)
			{
				CreateSearchBar(InventoryGui.instance);
			}
			else
			{
				if (!s_searchBarObject.activeSelf)
				{
					s_searchBarObject.SetActive(true);
				}
				RefreshPlaceholderLanguage();
			}
			if ((Object)(object)s_inputField != (Object)null && s_inputField.isFocused)
			{
				if (Input.GetKeyDown((KeyCode)13) || Input.GetKeyDown((KeyCode)271))
				{
					s_inputField.DeactivateInputField(false);
				}
				else if (Input.GetKeyDown((KeyCode)27))
				{
					ClearSearch();
					s_inputField.DeactivateInputField(false);
				}
			}
			UpdateGridsHighlight();
		}
		else
		{
			if ((Object)(object)s_searchBarObject != (Object)null && s_searchBarObject.activeSelf)
			{
				s_searchBarObject.SetActive(false);
			}
			if (IsSearchActive)
			{
				ClearSearch();
			}
		}
	}

	private static void CreateSearchBar(InventoryGui gui)
	{
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Expected O, but got Unknown
		//IL_0100: 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_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: 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_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Expected O, but got Unknown
		if ((Object)(object)s_searchBarObject != (Object)null || (Object)(object)gui == (Object)null || (Object)(object)gui.m_player == (Object)null)
		{
			return;
		}
		Transform transform = ((Component)gui.m_player).transform;
		GameObject val = null;
		if ((Object)(object)TextInput.instance != (Object)null)
		{
			TMP_InputField componentInChildren = ((Component)TextInput.instance).GetComponentInChildren<TMP_InputField>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				val = ((Component)componentInChildren).gameObject;
			}
		}
		if ((Object)(object)val != (Object)null)
		{
			s_searchBarObject = Object.Instantiate<GameObject>(val, transform);
		}
		else
		{
			s_searchBarObject = new GameObject("ChestSearchBar", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(TMP_InputField)
			});
			s_searchBarObject.transform.SetParent(transform, false);
		}
		((Object)s_searchBarObject).name = "ChestSearchBar";
		s_searchBarObject.SetActive(true);
		RectTransform component = s_searchBarObject.GetComponent<RectTransform>();
		if ((Object)(object)component != (Object)null)
		{
			component.anchorMin = new Vector2(1f, 1f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(1f, 0f);
			component.anchoredPosition = new Vector2(-15f, 6f);
			component.sizeDelta = new Vector2(220f, 30f);
		}
		Image component2 = s_searchBarObject.GetComponent<Image>();
		if ((Object)(object)component2 != (Object)null)
		{
			((Graphic)component2).color = new Color(0.12f, 0.12f, 0.15f, 0.95f);
		}
		s_inputField = s_searchBarObject.GetComponent<TMP_InputField>();
		if ((Object)(object)s_inputField != (Object)null)
		{
			s_inputField.text = "";
			s_inputField.characterLimit = 40;
			s_inputField.onValueChanged = new OnChangeEvent();
			((UnityEvent<string>)(object)s_inputField.onValueChanged).AddListener((UnityAction<string>)OnSearchValueChanged);
			s_placeholderText = null;
			if ((Object)(object)s_inputField.placeholder != (Object)null)
			{
				s_placeholderText = ((Component)s_inputField.placeholder).GetComponent<TMP_Text>();
			}
			if ((Object)(object)s_placeholderText == (Object)null)
			{
				s_placeholderText = s_searchBarObject.GetComponentInChildren<TMP_Text>();
			}
		}
		RefreshPlaceholderLanguage();
		CreateClearButton(s_searchBarObject.transform);
		ChestHelperPlugin.Log("Created ChestSearchBar in InventoryGui.");
	}

	private static void CreateClearButton(Transform parent)
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Expected O, but got Unknown
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: 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_0113: Expected O, but got Unknown
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Expected O, but got Unknown
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Expected O, but got Unknown
		GameObject val = new GameObject("ClearButton", new Type[3]
		{
			typeof(RectTransform),
			typeof(Image),
			typeof(Button)
		});
		val.transform.SetParent(parent, false);
		RectTransform component = val.GetComponent<RectTransform>();
		component.anchorMin = new Vector2(1f, 0.5f);
		component.anchorMax = new Vector2(1f, 0.5f);
		component.pivot = new Vector2(1f, 0.5f);
		component.anchoredPosition = new Vector2(-4f, 0f);
		component.sizeDelta = new Vector2(20f, 20f);
		Image component2 = val.GetComponent<Image>();
		((Graphic)component2).color = new Color(0.8f, 0.3f, 0.3f, 0.75f);
		GameObject val2 = new GameObject("Text", new Type[2]
		{
			typeof(RectTransform),
			typeof(TextMeshProUGUI)
		});
		val2.transform.SetParent(val.transform, false);
		RectTransform component3 = val2.GetComponent<RectTransform>();
		component3.anchorMin = Vector2.zero;
		component3.anchorMax = Vector2.one;
		component3.sizeDelta = Vector2.zero;
		TextMeshProUGUI component4 = val2.GetComponent<TextMeshProUGUI>();
		((TMP_Text)component4).text = "×";
		((TMP_Text)component4).fontSize = 16f;
		((TMP_Text)component4).alignment = (TextAlignmentOptions)514;
		((Graphic)component4).color = Color.white;
		Button component5 = val.GetComponent<Button>();
		component5.onClick = new ButtonClickedEvent();
		((UnityEvent)component5.onClick).AddListener(new UnityAction(ClearSearch));
	}

	private static void RefreshPlaceholderLanguage()
	{
		if ((Object)(object)s_placeholderText == (Object)null)
		{
			return;
		}
		string text = null;
		try
		{
			if (Localization.instance != null)
			{
				text = Localization.instance.GetSelectedLanguage();
			}
		}
		catch
		{
		}
		if (!(text == s_lastLanguage))
		{
			s_lastLanguage = text;
			if (!string.IsNullOrEmpty(text) && (text.Equals("Russian", StringComparison.OrdinalIgnoreCase) || text.StartsWith("rus", StringComparison.OrdinalIgnoreCase)))
			{
				s_placeholderText.text = "Поиск предметов...";
			}
			else
			{
				s_placeholderText.text = "Search items...";
			}
		}
	}

	private static void OnSearchValueChanged(string val)
	{
		if (val != null)
		{
			CurrentQuery = val.Trim();
		}
		else
		{
			CurrentQuery = "";
		}
	}

	public static void ClearSearch()
	{
		CurrentQuery = "";
		if ((Object)(object)s_inputField != (Object)null)
		{
			s_inputField.text = "";
			s_inputField.DeactivateInputField(false);
		}
		RestoreGridVisuals(((Object)(object)InventoryGui.instance != (Object)null) ? InventoryGui.instance.m_playerGrid : null);
		RestoreGridVisuals(((Object)(object)InventoryGui.instance != (Object)null) ? InventoryGui.instance.ContainerGrid : null);
		s_gridsDimmed = false;
		s_lastAppliedQuery = null;
		s_lastPlayerItemCount = -1;
		s_lastContainerItemCount = -1;
	}

	public static bool ItemMatches(ItemData item, string query)
	{
		if (item == null || item.m_shared == null || string.IsNullOrEmpty(query))
		{
			return false;
		}
		string text = ((Localization.instance != null) ? Localization.instance.Localize(item.m_shared.m_name) : item.m_shared.m_name);
		if (!string.IsNullOrEmpty(text) && text.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0)
		{
			return true;
		}
		if (!string.IsNullOrEmpty(item.m_shared.m_name) && item.m_shared.m_name.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0)
		{
			return true;
		}
		if ((Object)(object)item.m_dropPrefab != (Object)null && ((Object)item.m_dropPrefab).name.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0)
		{
			return true;
		}
		return false;
	}

	private static void UpdateGridsHighlight()
	{
		if ((Object)(object)InventoryGui.instance == (Object)null)
		{
			return;
		}
		if (!IsSearchActive)
		{
			if (s_gridsDimmed)
			{
				RestoreGridVisuals(InventoryGui.instance.m_playerGrid);
				RestoreGridVisuals(InventoryGui.instance.ContainerGrid);
				s_gridsDimmed = false;
				s_lastAppliedQuery = null;
			}
			return;
		}
		bool flag = InventoryGui.instance.IsContainerOpen();
		int num = (((Object)(object)InventoryGui.instance.m_playerGrid != (Object)null && InventoryGui.instance.m_playerGrid.GetInventory() != null) ? InventoryGui.instance.m_playerGrid.GetInventory().NrOfItems() : 0);
		int num2 = ((flag && (Object)(object)InventoryGui.instance.ContainerGrid != (Object)null && InventoryGui.instance.ContainerGrid.GetInventory() != null) ? InventoryGui.instance.ContainerGrid.GetInventory().NrOfItems() : 0);
		if (!s_gridsDimmed || CurrentQuery != s_lastAppliedQuery || flag != s_lastContainerOpenState || num != s_lastPlayerItemCount || num2 != s_lastContainerItemCount)
		{
			s_gridsDimmed = true;
			s_lastAppliedQuery = CurrentQuery;
			s_lastContainerOpenState = flag;
			s_lastPlayerItemCount = num;
			s_lastContainerItemCount = num2;
			ApplyGridSearchFilter(InventoryGui.instance.m_playerGrid, CurrentQuery);
			if (flag && (Object)(object)InventoryGui.instance.ContainerGrid != (Object)null)
			{
				ApplyGridSearchFilter(InventoryGui.instance.ContainerGrid, CurrentQuery);
			}
		}
	}

	private static void ApplyGridSearchFilter(InventoryGrid grid, string query)
	{
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)grid == (Object)null || s_elementsField == null || grid.GetInventory() == null || !(s_elementsField.GetValue(grid) is IList list))
		{
			return;
		}
		Inventory inventory = grid.GetInventory();
		for (int i = 0; i < list.Count; i++)
		{
			object obj = list[i];
			if (obj == null)
			{
				continue;
			}
			InventoryElement val = (InventoryElement)((obj is InventoryElement) ? obj : null);
			if ((Object)(object)val == (Object)null || (Object)(object)val.m_icon == (Object)null)
			{
				continue;
			}
			if (!val.m_used)
			{
				((Graphic)val.m_icon).color = Color.white;
				continue;
			}
			Vector2i position = val.Position;
			ItemData itemAt = inventory.GetItemAt(position.x, position.y);
			if (itemAt != null && ItemMatches(itemAt, query))
			{
				((Graphic)val.m_icon).color = Color.white;
			}
			else
			{
				((Graphic)val.m_icon).color = new Color(1f, 1f, 1f, 0.22f);
			}
		}
	}

	private static void RestoreGridVisuals(InventoryGrid grid)
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)grid == (Object)null || s_elementsField == null || !(s_elementsField.GetValue(grid) is IList list))
		{
			return;
		}
		for (int i = 0; i < list.Count; i++)
		{
			object obj = list[i];
			if (obj != null)
			{
				InventoryElement val = (InventoryElement)((obj is InventoryElement) ? obj : null);
				if ((Object)(object)val != (Object)null && (Object)(object)val.m_icon != (Object)null)
				{
					((Graphic)val.m_icon).color = Color.white;
				}
			}
		}
	}
}
[HarmonyPatch(typeof(ZInput), "GetButtonDown")]
public static class Patch_ZInput_GetButtonDown
{
	public static bool Prefix(ref bool __result)
	{
		if (ChestSearchBar.IsFocused)
		{
			__result = false;
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(ZInput), "GetButton")]
public static class Patch_ZInput_GetButton
{
	public static bool Prefix(ref bool __result)
	{
		if (ChestSearchBar.IsFocused)
		{
			__result = false;
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(ZInput), "GetButtonUp")]
public static class Patch_ZInput_GetButtonUp
{
	public static bool Prefix(ref bool __result)
	{
		if (ChestSearchBar.IsFocused)
		{
			__result = false;
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(ZInput), "GetKeyDown", new Type[]
{
	typeof(KeyCode),
	typeof(bool)
})]
public static class Patch_ZInput_GetKeyDown
{
	public static bool Prefix(ref bool __result)
	{
		if (ChestSearchBar.IsFocused)
		{
			__result = false;
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(ZInput), "GetKey", new Type[]
{
	typeof(KeyCode),
	typeof(bool)
})]
public static class Patch_ZInput_GetKey
{
	public static bool Prefix(ref bool __result)
	{
		if (ChestSearchBar.IsFocused)
		{
			__result = false;
			return false;
		}
		return true;
	}
}
public static class ChestDragDropHandler
{
	private delegate bool CheckAccessDelegate(Container container, long playerID);

	private delegate void ContainerSaveDelegate(Container container);

	private delegate bool ContainerLoadDelegate(Container container);

	private delegate void SetupDragItemDelegate(InventoryGui gui, ItemData item, Inventory inventory, int amount);

	private static Container s_hoveredContainer = null;

	private static GameObject s_promptObject = null;

	private static TextMeshProUGUI s_promptText = null;

	private static int s_raycastLayerMask = -1;

	private static readonly CheckAccessDelegate s_checkAccess = AccessTools.MethodDelegate<CheckAccessDelegate>(AccessTools.Method(typeof(Container), "CheckAccess", new Type[1] { typeof(long) }, (Type[])null), (object)null, true);

	private static readonly ContainerSaveDelegate s_containerSave = AccessTools.MethodDelegate<ContainerSaveDelegate>(AccessTools.Method(typeof(Container), "Save", (Type[])null, (Type[])null), (object)null, true);

	private static readonly ContainerLoadDelegate s_containerLoad = AccessTools.MethodDelegate<ContainerLoadDelegate>(AccessTools.Method(typeof(Container), "Load", (Ty