Decompiled source of JatifyTweaks v1.0.3

JatifyTweaks.dll

Decompiled 18 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("JatifyTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyProduct("JatifyTweaks")]
[assembly: AssemblyTitle("JatifyTweaks")]
[assembly: AssemblyVersion("1.0.3.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace JatifyTweaks
{
	[BepInPlugin("com.dreich.jatifytweaks", "Jatify Tweaks", "1.0.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class JatifyTweaksPlugin : BaseUnityPlugin
	{
		public enum FoodPlace
		{
			Default,
			BottomLeft
		}

		private const float DefaultWindowOpacity = 100f;

		private const float MinWindowOpacity = 0f;

		private const float MaxWindowOpacity = 300f;

		private const float DefaultPanelOpacity = 100f;

		private const float MinPanelOpacity = 0f;

		private const float MaxPanelOpacity = 300f;

		private const float DefaultBorderOpacity = 100f;

		private const float MinBorderOpacity = 0f;

		private const float MaxBorderOpacity = 300f;

		private const float DefaultFoodTimersGap = 8f;

		private const float DefaultPinGap = 8f;

		private const float DefaultSize = 8f;

		private const float MinSize = 3f;

		private const float MaxSize = 24f;

		private const float DefaultBalancedWithin = 25f;

		private const float MinBalancedWithin = 0f;

		private const float MaxBalancedWithin = 100f;

		public const string Guid = "com.dreich.jatifytweaks";

		public const string Name = "Jatify Tweaks";

		public const string Version = "1.0.3";

		internal const string JatifyGuid = "jatify.ui";

		internal static ManualLogSource Log;

		internal static ConfigEntry<float> WindowOpacity;

		internal static ConfigEntry<float> PanelOpacity;

		internal static ConfigEntry<float> BorderOpacity;

		internal static ConfigEntry<bool> GroupPins;

		internal static ConfigEntry<bool> ShowCompass;

		internal static ConfigEntry<FoodPlace> FoodPosition;

		internal static ConfigEntry<float> FoodGap;

		internal static ConfigEntry<bool> ShowLeftHints;

		internal static ConfigEntry<bool> ShowRightHints;

		internal static ConfigEntry<bool> PinTooltips;

		internal static ConfigEntry<KeyboardShortcut> PinKey;

		internal static ConfigEntry<float> PinGap;

		internal static ConfigEntry<bool> StoreTooltips;

		internal static ConfigEntry<bool> ConsoleTab;

		internal static ConfigEntry<bool> HideUnopened;

		internal static ConfigEntry<bool> FoodDots;

		internal static ConfigEntry<float> FoodDotSize;

		internal static ConfigEntry<float> FoodDotBalance;

		internal static ConfigEntry<Color> HealthDotColor;

		internal static ConfigEntry<Color> StaminaDotColor;

		internal static ConfigEntry<Color> EitrDotColor;

		internal static ConfigEntry<Color> BalancedDotColor;

		private void Awake()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Expected O, but got Unknown
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Expected O, but got Unknown
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Expected O, but got Unknown
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Expected O, but got Unknown
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Expected O, but got Unknown
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Expected O, but got Unknown
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Expected O, but got Unknown
			//IL_0463: Unknown result type (might be due to invalid IL or missing references)
			//IL_0469: Expected O, but got Unknown
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0480: Expected O, but got Unknown
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_0497: Expected O, but got Unknown
			//IL_04bb: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			WindowOpacity = ((BaseUnityPlugin)this).Config.Bind<float>("Opacity", "WindowOpacity", 100f, new ConfigDescription("Opacity of Jatify's windows and HUD panels, in percent of the theme's own opacity. Lower is more see-through; above 100 is more solid.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 300f), Array.Empty<object>()));
			PanelOpacity = ((BaseUnityPlugin)this).Config.Bind<float>("Opacity", "PanelOpacity", 100f, new ConfigDescription("Opacity of the cards, slots and inner panels inside Jatify's windows, in percent of the theme's own opacity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 300f), Array.Empty<object>()));
			BorderOpacity = ((BaseUnityPlugin)this).Config.Bind<float>("Opacity", "BorderOpacity", 100f, new ConfigDescription("Opacity of the thin borders around Jatify's windows and panels, in percent of the theme's own opacity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 300f), Array.Empty<object>()));
			GroupPins = ((BaseUnityPlugin)this).Config.Bind<bool>("Map", "GroupPins", true, "Let Jatify fold nearby map pins into one group when zoomed out. Turn off to always see every pin on its own.");
			ShowCompass = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "ShowCompass", true, "Show Jatify's compass at the top of the screen.");
			FoodPosition = ((BaseUnityPlugin)this).Config.Bind<FoodPlace>("HUD", "FoodTimersPosition", FoodPlace.Default, "Where Jatify's food timer icons sit. Default keeps them above the action bar; BottomLeft puts them in the bottom left corner, above the key hints.");
			FoodGap = ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "FoodTimersGap", 8f, "Space between the food timers and the key hints below them when FoodTimersPosition is BottomLeft.");
			ShowLeftHints = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "ShowLeftKeyHints", true, "Show Jatify's key hints in the bottom left corner (Inventory, Map, Tracker).");
			ShowRightHints = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "ShowRightKeyHints", true, "Show Jatify's key hints in the bottom right corner (Attack, Block, and the building hints).");
			PinTooltips = ((BaseUnityPlugin)this).Config.Bind<bool>("Tooltips", "PinToCompare", true, "Press PinKey while hovering an item to keep its tooltip open. Hover other items to see their tooltips beside it. Press PinKey again, or close the inventory, to let it go.");
			PinKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Tooltips", "PinKey", new KeyboardShortcut((KeyCode)101, Array.Empty<KeyCode>()), "Key that pins or unpins an item's tooltip.");
			PinGap = ((BaseUnityPlugin)this).Config.Bind<float>("Tooltips", "PinGap", 8f, "Space between the pinned tooltip and the one you're hovering.");
			HideUnopened = ((BaseUnityPlugin)this).Config.Bind<bool>("Chests", "HideUnopenedContents", true, "Jatify's chest peek shows \"Unknown\" instead of what's inside a chest you didn't build, until you've opened it yourself once, like dungeon and treasure chests.");
			ConsoleTab = ((BaseUnityPlugin)this).Config.Bind<bool>("Console", "ShowConsoleLabel", false, "Show Jatify's \"Console\" label at the top of the console. It's off by default because it covers the autocomplete hints.");
			StoreTooltips = ((BaseUnityPlugin)this).Config.Bind<bool>("Tooltips", "TraderTooltips", true, "Items in Haldor's and other traders' shops show Jatify's full item tooltip, with stats and a comparison to what you're wearing.");
			FoodDots = ((BaseUnityPlugin)this).Config.Bind<bool>("Food Dots", "Enabled", true, "Food items in your inventory and in chests get a small coloured dot in the bottom left of their icon, showing what kind of food it is.");
			FoodDotSize = ((BaseUnityPlugin)this).Config.Bind<float>("Food Dots", "Size", 8f, new ConfigDescription("Size of the dot.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(3f, 24f), Array.Empty<object>()));
			FoodDotBalance = ((BaseUnityPlugin)this).Config.Bind<float>("Food Dots", "BalancedWithin", 25f, new ConfigDescription("If the food's second biggest stat is within this many percent of its biggest, it counts as balanced and gets the balanced colour.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			HealthDotColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Food Dots", "HealthColor", new Color(0.9f, 0.2f, 0.2f, 1f), "Dot colour for health food.");
			StaminaDotColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Food Dots", "StaminaColor", new Color(0.3f, 0.85f, 0.3f, 1f), "Dot colour for stamina food.");
			EitrDotColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Food Dots", "EitrColor", new Color(0.3f, 0.5f, 1f, 1f), "Dot colour for eitr food.");
			BalancedDotColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Food Dots", "BalancedColor", Color.white, "Dot colour for food with a fairly even split.");
			new Harmony("com.dreich.jatifytweaks.fooddots").PatchAll(typeof(FoodDotPatch));
			if (!Chainloader.PluginInfos.ContainsKey("jatify.ui"))
			{
				return;
			}
			Harmony val = new Harmony("com.dreich.jatifytweaks");
			if (!PinGrouping.Setup(val))
			{
				Log.LogWarning((object)"Jatify UI has changed; GroupPins can't be turned off.");
			}
			if (!CompassToggle.Setup(val))
			{
				Log.LogWarning((object)"Jatify UI has changed; ShowCompass can't be turned off.");
			}
			if (!HudLayout.Setup(val))
			{
				Log.LogWarning((object)"Jatify UI has changed; the food timer and key hint settings can't be used.");
			}
			if (!UnopenedChests.Setup(val))
			{
				Log.LogWarning((object)"Jatify UI has changed; unopened chests will show their contents in the chest peek.");
			}
			if (!ConsoleLabel.Setup(val))
			{
				Log.LogWarning((object)"Jatify UI has changed; the console label can't be hidden.");
			}
			if (!StoreTips.Setup(val))
			{
				Log.LogWarning((object)"Jatify UI has changed; trader items keep the plain tooltip.");
			}
			if (!RossPortalsMap.Setup(val))
			{
				Log.LogWarning((object)"Jatify UI has changed; portals hidden from the map in RossPortals may still show on Jatify's map.");
			}
			if (TooltipPin.Setup(val))
			{
				((Component)this).gameObject.AddComponent<TooltipPinInput>();
			}
			else
			{
				Log.LogWarning((object)"Jatify UI has changed; tooltips can't be pinned.");
			}
			if (!ThemeOpacity.Setup(val))
			{
				Log.LogWarning((object)"Jatify UI has changed; opacity can't be adjusted.");
				return;
			}
			WindowOpacity.SettingChanged += delegate
			{
				ThemeOpacity.Reapply(notify: true);
			};
			PanelOpacity.SettingChanged += delegate
			{
				ThemeOpacity.Reapply(notify: true);
			};
			BorderOpacity.SettingChanged += delegate
			{
				ThemeOpacity.Reapply(notify: true);
			};
			ThemeOpacity.Reapply(notify: false);
		}
	}
	[HarmonyPatch(typeof(InventoryGrid), "UpdateGui")]
	internal static class FoodDotPatch
	{
		private const string DotName = "JatifyTweaks_FoodDot";

		private static Sprite dot;

		private static void Postfix(List<InventoryElement> ___m_elements, Inventory ___m_inventory)
		{
			//IL_0062: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			if (___m_elements == null)
			{
				return;
			}
			try
			{
				bool value = JatifyTweaksPlugin.FoodDots.Value;
				foreach (InventoryElement ___m_element in ___m_elements)
				{
					if ((Object)(object)___m_element == (Object)null || (Object)(object)___m_element.m_icon == (Object)null)
					{
						continue;
					}
					Transform val = ((Component)___m_element.m_icon).transform.Find("JatifyTweaks_FoodDot");
					ItemData val2 = ((value && ___m_inventory != null) ? ___m_inventory.GetItemAt(___m_element.Position.x, ___m_element.Position.y) : null);
					if (val2 == null || !IsFood(val2.m_shared))
					{
						if ((Object)(object)val != (Object)null && ((Component)val).gameObject.activeSelf)
						{
							((Component)val).gameObject.SetActive(false);
						}
						continue;
					}
					Image val3 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Image>() : Create(((Component)___m_element.m_icon).transform));
					if (!((Object)(object)val3 == (Object)null))
					{
						if (!((Component)val3).gameObject.activeSelf)
						{
							((Component)val3).gameObject.SetActive(true);
						}
						float value2 = JatifyTweaksPlugin.FoodDotSize.Value;
						RectTransform rectTransform = ((Graphic)val3).rectTransform;
						if (rectTransform.sizeDelta.x != value2)
						{
							rectTransform.sizeDelta = new Vector2(value2, value2);
						}
						Color val4 = ColourFor(val2.m_shared);
						if (((Graphic)val3).color != val4)
						{
							((Graphic)val3).color = val4;
						}
					}
				}
			}
			catch (Exception ex)
			{
				JatifyTweaksPlugin.Log.LogWarning((object)("Food dots failed: " + ex.Message));
			}
		}

		private static bool IsFood(SharedData shared)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)shared.m_itemType == 2)
			{
				if (!(shared.m_food > 0f) && !(shared.m_foodStamina > 0f))
				{
					return shared.m_foodEitr > 0f;
				}
				return true;
			}
			return false;
		}

		private static Color ColourFor(SharedData shared)
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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)
			float num = Mathf.Max(0f, shared.m_food);
			float num2 = Mathf.Max(0f, shared.m_foodStamina);
			float num3 = Mathf.Max(0f, shared.m_foodEitr);
			float num4 = Mathf.Max(num, Mathf.Max(num2, num3));
			float num5 = num + num2 + num3 - num4 - Mathf.Min(num, Mathf.Min(num2, num3));
			if (num4 > 0f && num5 >= num4 * (1f - JatifyTweaksPlugin.FoodDotBalance.Value / 100f))
			{
				return JatifyTweaksPlugin.BalancedDotColor.Value;
			}
			if (num4 == num3)
			{
				return JatifyTweaksPlugin.EitrDotColor.Value;
			}
			if (num4 == num)
			{
				return JatifyTweaksPlugin.HealthDotColor.Value;
			}
			return JatifyTweaksPlugin.StaminaDotColor.Value;
		}

		private static Image Create(Transform icon)
		{
			//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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("JatifyTweaks_FoodDot", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent(icon, false);
			RectTransform val2 = (RectTransform)val.transform;
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.zero;
			val2.pivot = Vector2.zero;
			val2.anchoredPosition = new Vector2(2f, 2f);
			Image component = val.GetComponent<Image>();
			component.sprite = Dot();
			((Graphic)component).raycastTarget = false;
			return component;
		}

		private static Sprite Dot()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_00d6: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)dot != (Object)null)
			{
				return dot;
			}
			Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false);
			float num = 16f;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(num, num);
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num2 = Vector2.Distance(new Vector2((float)j + 0.5f, (float)i + 0.5f), val2);
					float num3 = Mathf.Clamp01(num - num2);
					float num4 = ((num2 > num - 3f) ? 0.35f : 1f);
					val.SetPixel(j, i, new Color(num4, num4, num4, num3));
				}
			}
			val.Apply();
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			dot = Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), val3);
			return dot;
		}
	}
	internal static class UnopenedChests
	{
		private const string UsedLabelName = "Used";

		private const string UnknownText = "Unknown";

		private const string LockedOpenAction = "Open (needs access)";

		private const string OpenAction = "Open";

		private static FieldInfo rootField;

		internal static bool Setup(Harmony harmony)
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			//IL_00ad: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			Type type = AccessTools.TypeByName("Jatify.UI.ChestPeek");
			MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "Fill", (Type[])null, (Type[])null) : null);
			rootField = ((type != null) ? AccessTools.Field(type, "_root") : null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(Container), "RPC_OpenResponse", (Type[])null, (Type[])null);
			if (methodInfo == null || rootField == null || methodInfo2 == null)
			{
				return false;
			}
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(UnopenedChests), "BeforeFill", (Type[])null), new HarmonyMethod(typeof(UnopenedChests), "AfterFill", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(UnopenedChests), "AfterOpen", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			return true;
		}

		private static int Key(Player player)
		{
			return StringExtensionMethods.GetStableHashCode("JatifyTweaks_Opened_" + player.GetPlayerID());
		}

		private static void AfterOpen(Container __instance, bool granted, ZNetView ___m_nview)
		{
			Player localPlayer = Player.m_localPlayer;
			ZDO val = (((Object)(object)___m_nview != (Object)null && ___m_nview.IsValid()) ? ___m_nview.GetZDO() : null);
			if (granted && !((Object)(object)localPlayer == (Object)null) && val != null && !val.GetBool(Key(localPlayer), false))
			{
				val.Set(Key(localPlayer), true);
			}
		}

		internal static bool Hidden(Container container)
		{
			if (!JatifyTweaksPlugin.HideUnopened.Value || (Object)(object)container == (Object)null)
			{
				return false;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return false;
			}
			Piece componentInParent = ((Component)container).GetComponentInParent<Piece>();
			if ((Object)(object)componentInParent != (Object)null && componentInParent.GetCreator() != 0L)
			{
				return false;
			}
			ZNetView componentInParent2 = ((Component)container).GetComponentInParent<ZNetView>();
			ZDO val = (((Object)(object)componentInParent2 != (Object)null && componentInParent2.IsValid()) ? componentInParent2.GetZDO() : null);
			if (val != null)
			{
				return !val.GetBool(Key(localPlayer), false);
			}
			return true;
		}

		private static void BeforeFill(Container __0, ref bool __2, out bool __state)
		{
			__state = Hidden(__0);
			if (__state)
			{
				__2 = false;
			}
		}

		private static void AfterFill(bool __state)
		{
			if (!__state)
			{
				return;
			}
			object? value = rootField.GetValue(null);
			Transform val = (Transform)((value is Transform) ? value : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			TMP_Text[] componentsInChildren = ((Component)val).GetComponentsInChildren<TMP_Text>(true);
			foreach (TMP_Text val2 in componentsInChildren)
			{
				if (((Object)val2).name == "Used")
				{
					val2.text = "Unknown";
				}
				else if (val2.text.Contains("Open (needs access)"))
				{
					val2.text = val2.text.Replace("Open (needs access)", "Open");
				}
			}
		}
	}
	internal static class ConsoleLabel
	{
		internal static bool Setup(Harmony harmony)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			Type type = AccessTools.TypeByName("Jatify.UI.Windows");
			MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "ConsoleWindow", (Type[])null, (Type[])null) : null);
			if (methodInfo == null)
			{
				return false;
			}
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(ConsoleLabel), "AfterConsole", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			JatifyTweaksPlugin.ConsoleTab.SettingChanged += delegate
			{
				Apply((Transform)(object)(((Object)(object)Console.instance != (Object)null) ? ((Terminal)Console.instance).m_chatWindow : null));
			};
			return true;
		}

		private static void AfterConsole(Transform __0)
		{
			Apply(__0);
		}

		private static void Apply(Transform window)
		{
			if (!((Object)(object)window == (Object)null))
			{
				Transform val = window.Find("jatify-tab");
				if ((Object)(object)val != (Object)null && ((Component)val).gameObject.activeSelf != JatifyTweaksPlugin.ConsoleTab.Value)
				{
					((Component)val).gameObject.SetActive(JatifyTweaksPlugin.ConsoleTab.Value);
				}
			}
		}
	}
	internal static class StoreTips
	{
		private static MethodInfo forMethod;

		internal static bool Setup(Harmony harmony)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			Type type = AccessTools.TypeByName("Jatify.UI.ItemTip");
			forMethod = ((type != null) ? AccessTools.Method(type, "For", new Type[6]
			{
				typeof(UITooltip),
				typeof(Func<ItemData>),
				typeof(int),
				typeof(bool),
				typeof(bool),
				typeof(string)
			}, (Type[])null) : null);
			MethodInfo methodInfo = AccessTools.Method(typeof(StoreGui), "FillList", (Type[])null, (Type[])null);
			if (forMethod == null || methodInfo == null)
			{
				return false;
			}
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(StoreTips), "AfterFill", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			return true;
		}

		private static void AfterFill(List<GameObject> ___m_itemList, Trader ___m_trader)
		{
			if (!JatifyTweaksPlugin.StoreTooltips.Value || ___m_itemList == null || (Object)(object)___m_trader == (Object)null)
			{
				return;
			}
			try
			{
				List<TradeItem> availableItems = ___m_trader.GetAvailableItems();
				int num = Mathf.Min(availableItems.Count, ___m_itemList.Count);
				for (int i = 0; i < num; i++)
				{
					ItemDrop prefab = availableItems[i].m_prefab;
					GameObject val = ___m_itemList[i];
					UITooltip val2 = (((Object)(object)val != (Object)null) ? val.GetComponentInChildren<UITooltip>(true) : null);
					if (!((Object)(object)prefab == (Object)null) && !((Object)(object)val2 == (Object)null))
					{
						ItemData data = prefab.m_itemData.Clone();
						data.m_dropPrefab = ((Component)prefab).gameObject;
						data.m_stack = Mathf.Max(1, availableItems[i].m_stack);
						Func<ItemData> func = () => data;
						forMethod.Invoke(null, new object[6] { val2, func, -1, false, false, null });
					}
				}
			}
			catch (Exception ex)
			{
				JatifyTweaksPlugin.Log.LogWarning((object)("Trader tooltips failed: " + ex.Message));
			}
		}
	}
	internal sealed class TooltipPinInput : MonoBehaviour
	{
		private void Update()
		{
			try
			{
				TooltipPin.Update();
			}
			catch (Exception ex)
			{
				JatifyTweaksPlugin.Log.LogWarning((object)("Tooltip pin failed: " + ex.Message));
			}
		}
	}
	internal static class TooltipPin
	{
		private static FieldInfo rootField;

		private static FieldInfo cardField;

		private static FieldInfo itemField;

		private static GameObject pinned;

		private static RectTransform pinnedCard;

		private static ItemData pinnedItem;

		private const int BottomLeft = 0;

		private const int TopLeft = 1;

		private const int TopRight = 2;

		private const float SmallestMoveSquared = 0.0001f;

		private static readonly Vector3[] live = (Vector3[])(object)new Vector3[4];

		private static readonly Vector3[] mine = (Vector3[])(object)new Vector3[4];

		private static readonly Vector3[] screen = (Vector3[])(object)new Vector3[4];

		private static bool blockUse;

		internal static bool Setup(Harmony harmony)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_0130: 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_0152: Expected O, but got Unknown
			//IL_0152: Expected O, but got Unknown
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Expected O, but got Unknown
			Type type = AccessTools.TypeByName("Jatify.UI.ItemTip");
			MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "Tick", (Type[])null, (Type[])null) : null);
			rootField = ((type != null) ? AccessTools.Field(type, "_root") : null);
			cardField = ((type != null) ? AccessTools.Field(type, "_card") : null);
			itemField = ((type != null) ? AccessTools.Field(type, "_item") : null);
			if (methodInfo == null || rootField == null || cardField == null || itemField == null)
			{
				return false;
			}
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(TooltipPin), "AfterTick", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(InventoryGui), "Update", (Type[])null, (Type[])null);
			MethodInfo methodInfo3 = AccessTools.Method(typeof(ZInput), "GetButtonDown", new Type[1] { typeof(string) }, (Type[])null);
			if (methodInfo2 != null && methodInfo3 != null)
			{
				harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(TooltipPin), "BeforeInventory", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(TooltipPin), "AfterInventory", (Type[])null), (HarmonyMethod)null);
				harmony.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(typeof(TooltipPin), "ButtonDown", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			return true;
		}

		private static void BeforeInventory()
		{
			//IL_0011: 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)
			int num;
			if (JatifyTweaksPlugin.PinTooltips.Value)
			{
				KeyboardShortcut value = JatifyTweaksPlugin.PinKey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					num = ((Hovering() || (Object)(object)pinned != (Object)null) ? 1 : 0);
					goto IL_0038;
				}
			}
			num = 0;
			goto IL_0038;
			IL_0038:
			blockUse = (byte)num != 0;
		}

		private static Exception AfterInventory(Exception __exception)
		{
			blockUse = false;
			return __exception;
		}

		private static void ButtonDown(string name, ref bool __result)
		{
			if ((blockUse & __result) && (name == "Use" || name == "JoyUse"))
			{
				__result = false;
			}
		}

		private static bool Hovering()
		{
			RectTransform val = LiveRoot();
			if ((Object)(object)val != (Object)null && ((Component)val).gameObject.activeInHierarchy)
			{
				return itemField.GetValue(null) != null;
			}
			return false;
		}

		private static RectTransform LiveRoot()
		{
			object? value = rootField.GetValue(null);
			return (RectTransform)((value is RectTransform) ? value : null);
		}

		internal static void Update()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!InventoryGui.IsVisible() || !JatifyTweaksPlugin.PinTooltips.Value)
			{
				Unpin();
				return;
			}
			KeyboardShortcut value = JatifyTweaksPlugin.PinKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				RectTransform val = LiveRoot();
				object? value2 = itemField.GetValue(null);
				ItemData val2 = (ItemData)((value2 is ItemData) ? value2 : null);
				if (!((Object)(object)val != (Object)null) || !((Component)val).gameObject.activeInHierarchy || val2 == null || ((Object)(object)pinned != (Object)null && val2 == pinnedItem))
				{
					Unpin();
				}
				else
				{
					Pin(val, val2);
				}
			}
		}

		private static void Pin(RectTransform root, ItemData item)
		{
			Unpin();
			pinned = Object.Instantiate<GameObject>(((Component)root).gameObject, ((Transform)root).parent);
			((Object)pinned).name = "JatifyTweaks_PinnedTip";
			pinned.SetActive(true);
			CanvasGroup val = pinned.GetComponent<CanvasGroup>() ?? pinned.AddComponent<CanvasGroup>();
			val.alpha = 1f;
			val.blocksRaycasts = false;
			val.interactable = false;
			CanvasGroup[] componentsInChildren = pinned.GetComponentsInChildren<CanvasGroup>(true);
			foreach (CanvasGroup val2 in componentsInChildren)
			{
				val2.blocksRaycasts = false;
				if ((Object)(object)val2 != (Object)(object)val && val2.alpha < 1f && ((Component)val2).gameObject.activeSelf)
				{
					val2.alpha = 1f;
				}
			}
			pinned.transform.SetSiblingIndex(((Transform)root).GetSiblingIndex());
			object? value = cardField.GetValue(null);
			pinnedCard = (RectTransform)(((object)FindCopy((Transform)(object)root, (RectTransform)((value is RectTransform) ? value : null), pinned.transform)) ?? ((object)/*isinst with value type is only supported in some contexts*/));
			pinnedItem = item;
		}

		private static RectTransform FindCopy(Transform root, RectTransform original, Transform copy)
		{
			if ((Object)(object)original == (Object)null)
			{
				return null;
			}
			List<int> list = new List<int>();
			Transform val = (Transform)(object)original;
			while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root)
			{
				list.Insert(0, val.GetSiblingIndex());
				val = val.parent;
			}
			Transform val2 = copy;
			foreach (int item in list)
			{
				if (item >= val2.childCount)
				{
					return null;
				}
				val2 = val2.GetChild(item);
			}
			return (RectTransform)(object)((val2 is RectTransform) ? val2 : null);
		}

		private static void Unpin()
		{
			if ((Object)(object)pinned != (Object)null)
			{
				Object.Destroy((Object)(object)pinned);
			}
			pinned = null;
			pinnedCard = null;
			pinnedItem = null;
		}

		private static void AfterTick()
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: 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_01ae: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)pinned == (Object)null || (Object)(object)pinnedCard == (Object)null)
			{
				return;
			}
			RectTransform val = LiveRoot();
			object? value = cardField.GetValue(null);
			RectTransform val2 = (RectTransform)((value is RectTransform) ? value : null);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || !((Component)val).gameObject.activeInHierarchy)
			{
				return;
			}
			val2.GetWorldCorners(live);
			pinnedCard.GetWorldCorners(mine);
			float num = (((Object)(object)((Transform)val).parent != (Object)null) ? ((Transform)val).parent.TransformVector(new Vector3(JatifyTweaksPlugin.PinGap.Value, 0f, 0f)).x : JatifyTweaksPlugin.PinGap.Value);
			float num2 = mine[2].x - mine[0].x;
			float num3 = live[0].x - num - num2;
			Canvas componentInParent = ((Component)val).GetComponentInParent<Canvas>();
			RectTransform val3 = (RectTransform)(((Object)(object)componentInParent != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val3 != (Object)null)
			{
				val3.GetWorldCorners(screen);
				if (num3 < screen[0].x)
				{
					num3 = live[2].x + num;
				}
			}
			Vector3 val4 = default(Vector3);
			((Vector3)(ref val4))..ctor(num3 - mine[0].x, live[1].y - mine[1].y, 0f);
			if (((Vector3)(ref val4)).sqrMagnitude > 0.0001f)
			{
				Transform transform = pinned.transform;
				transform.position += val4;
			}
		}
	}
	internal static class HudLayout
	{
		private static FieldInfo foodRowField;

		private static FieldInfo foodPoolField;

		private static FieldInfo buffRootField;

		private static FieldInfo hintsLeftField;

		private static FieldInfo hintsRightField;

		private static FieldInfo hintsPlaceField;

		private const int BottomLeft = 0;

		private const int TopLeft = 1;

		private const float SmallestMoveSquared = 0.0001f;

		private static readonly Vector3[] corners = (Vector3[])(object)new Vector3[4];

		private static readonly Vector3[] rowCorners = (Vector3[])(object)new Vector3[4];

		private static RectTransform movedRow;

		private static Vector2 rowPosition;

		private static Vector2 rowAnchorMin;

		private static Vector2 rowAnchorMax;

		internal static bool Setup(Harmony harmony)
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			Type type = AccessTools.TypeByName("Jatify.UI.HudView");
			Type type2 = AccessTools.TypeByName("Jatify.UI.HudView+Buff");
			MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "Tick", (Type[])null, (Type[])null) : null);
			if (methodInfo == null)
			{
				return false;
			}
			foodRowField = AccessTools.Field(type, "_foodRow");
			foodPoolField = AccessTools.Field(type, "_foodPool");
			buffRootField = ((type2 != null) ? AccessTools.Field(type2, "Root") : null);
			hintsLeftField = AccessTools.Field(type, "_hintsL");
			hintsRightField = AccessTools.Field(type, "_hintsR");
			hintsPlaceField = AccessTools.Field(type, "_hintsPlace");
			if (hintsLeftField == null || hintsRightField == null)
			{
				return false;
			}
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(HudLayout), "AfterHud", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			return true;
		}

		private static void AfterHud(object __instance)
		{
			try
			{
				object? value = hintsLeftField.GetValue(__instance);
				RectTransform val = (RectTransform)((value is RectTransform) ? value : null);
				object? value2 = hintsRightField.GetValue(__instance);
				RectTransform rect = (RectTransform)((value2 is RectTransform) ? value2 : null);
				object rect2 = (object)((hintsPlaceField != null) ? /*isinst with value type is only supported in some contexts*/: null);
				Hide(val, !JatifyTweaksPlugin.ShowLeftHints.Value);
				Hide(rect, !JatifyTweaksPlugin.ShowRightHints.Value);
				Hide((RectTransform)rect2, !JatifyTweaksPlugin.ShowRightHints.Value);
				PlaceFood(__instance, val);
			}
			catch (Exception ex)
			{
				JatifyTweaksPlugin.Log.LogWarning((object)("Jatify HUD tweak failed: " + ex.Message));
			}
		}

		private static void Hide(RectTransform rect, bool hide)
		{
			if (hide && (Object)(object)rect != (Object)null && ((Component)rect).gameObject.activeSelf)
			{
				((Component)rect).gameObject.SetActive(false);
			}
		}

		private static void PlaceFood(object hud, RectTransform hints)
		{
			//IL_004f: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: 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_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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)
			RectTransform val = (RectTransform)((foodRowField != null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			if (JatifyTweaksPlugin.FoodPosition.Value != JatifyTweaksPlugin.FoodPlace.BottomLeft || (Object)(object)hints == (Object)null)
			{
				if ((Object)(object)movedRow == (Object)(object)val)
				{
					val.anchorMin = rowAnchorMin;
					val.anchorMax = rowAnchorMax;
					val.anchoredPosition = rowPosition;
					movedRow = null;
				}
				return;
			}
			if ((Object)(object)movedRow != (Object)(object)val)
			{
				movedRow = val;
				rowPosition = val.anchoredPosition;
				rowAnchorMin = val.anchorMin;
				rowAnchorMax = val.anchorMax;
			}
			if (foodPoolField != null && buffRootField != null && foodPoolField.GetValue(hud) is IList list)
			{
				int num = 0;
				Vector2 val3 = default(Vector2);
				foreach (object item in list)
				{
					RectTransform val2 = (RectTransform)((item != null) ? /*isinst with value type is only supported in some contexts*/: null);
					if (!((Object)(object)val2 == (Object)null) && ((Component)val2).gameObject.activeSelf)
					{
						((Vector2)(ref val3))..ctor((float)num * 54f, 0f);
						if (val2.anchoredPosition != val3)
						{
							val2.anchoredPosition = val3;
						}
						num++;
					}
				}
			}
			hints.GetWorldCorners(corners);
			Vector3 val4 = (((Component)hints).gameObject.activeSelf ? corners[1] : corners[0]);
			Vector3 val5 = (((Object)(object)((Transform)val).parent != (Object)null) ? ((Transform)val).parent.TransformVector(new Vector3(0f, JatifyTweaksPlugin.FoodGap.Value, 0f)) : Vector3.zero);
			if (!((Component)hints).gameObject.activeSelf)
			{
				val5 = Vector3.zero;
			}
			Vector3 val6 = val4 + val5;
			val.GetWorldCorners(rowCorners);
			Vector3 val7 = val6 - rowCorners[0];
			val7.z = 0f;
			if (((Vector3)(ref val7)).sqrMagnitude > 0.0001f)
			{
				((Transform)val).position = ((Transform)val).position + val7;
			}
		}
	}
	internal static class CompassToggle
	{
		private static FieldInfo rootField;

		private static FieldInfo compassField;

		internal static bool Setup(Harmony harmony)
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			Type type = AccessTools.TypeByName("Jatify.UI.Compass");
			Type type2 = AccessTools.TypeByName("Jatify.UI.HudView");
			MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "Tick", (Type[])null, (Type[])null) : null);
			MethodInfo methodInfo2 = ((type2 != null) ? AccessTools.Method(type2, "Tick", (Type[])null, (Type[])null) : null);
			rootField = ((type != null) ? AccessTools.Field(type, "_root") : null);
			compassField = ((type2 != null) ? AccessTools.Field(type2, "_compass") : null);
			if (methodInfo == null || methodInfo2 == null || rootField == null || compassField == null)
			{
				return false;
			}
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(CompassToggle), "SkipTick", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(CompassToggle), "AfterHud", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			return true;
		}

		private static bool SkipTick()
		{
			return JatifyTweaksPlugin.ShowCompass.Value;
		}

		private static void AfterHud(object __instance)
		{
			if (!JatifyTweaksPlugin.ShowCompass.Value)
			{
				object value = compassField.GetValue(__instance);
				RectTransform val = (RectTransform)((value != null) ? /*isinst with value type is only supported in some contexts*/: null);
				if ((Object)(object)val != (Object)null && ((Component)val).gameObject.activeSelf)
				{
					((Component)val).gameObject.SetActive(false);
				}
			}
		}
	}
	internal static class RossPortalsMap
	{
		internal const string RossPortalsGuid = "com.rossdwest.rossportals";

		private static readonly int ShowOnMapKey = StringExtensionMethods.GetStableHashCode("RossPortals_ShowOnMap");

		private static bool? loaded;

		private static bool Loaded
		{
			get
			{
				if (!loaded.HasValue)
				{
					loaded = Chainloader.PluginInfos.ContainsKey("com.rossdwest.rossportals");
				}
				return loaded.Value;
			}
		}

		internal static bool Setup(Harmony harmony)
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			Type type = AccessTools.TypeByName("Jatify.UI.MapMarks");
			MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "Keep", (Type[])null, (Type[])null) : null);
			if (methodInfo == null)
			{
				return false;
			}
			ParameterInfo[] parameters = methodInfo.GetParameters();
			if (parameters.Length < 3 || parameters[1].ParameterType != typeof(ZDO) || parameters[1].Name != "z" || parameters[2].ParameterType != typeof(bool) || parameters[2].Name != "portal")
			{
				return false;
			}
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(RossPortalsMap), "BeforeKeep", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			return true;
		}

		private static bool BeforeKeep(ZDO z, bool portal)
		{
			if (!portal || z == null || !Loaded)
			{
				return true;
			}
			return z.GetBool(ShowOnMapKey, true);
		}
	}
	internal static class PinGrouping
	{
		internal static bool Setup(Harmony harmony)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			Type type = AccessTools.TypeByName("Jatify.UI.MapClusters");
			MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "Groupable", (Type[])null, (Type[])null) : null);
			if (methodInfo == null || methodInfo.ReturnType != typeof(bool))
			{
				return false;
			}
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(PinGrouping), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			return true;
		}

		private static bool Prefix(ref bool __result)
		{
			if (JatifyTweaksPlugin.GroupPins.Value)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	internal static class ThemeOpacity
	{
		private static readonly string[] Windows = new string[1] { "glass" };

		private static readonly string[] Panels = new string[2] { "raised", "raised2" };

		private static readonly string[] Borders = new string[2] { "glassLine", "line2" };

		private static Type themeType;

		private static MethodInfo getter;

		private static FieldInfo changedField;

		private static FieldInfo pluginInstance;

		private static FieldInfo pluginTheme;

		private static readonly Dictionary<string, FieldInfo> fields = new Dictionary<string, FieldInfo>();

		private static readonly Dictionary<string, string> originals = new Dictionary<string, string>();

		private static object scaledData;

		private const float Percent = 100f;

		internal static bool Setup(Harmony harmony)
		{
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Expected O, but got Unknown
			//IL_01a1: Expected O, but got Unknown
			themeType = AccessTools.TypeByName("Jatify.UI.Theme");
			Type type = AccessTools.TypeByName("Jatify.UI.ThemeData");
			Type type2 = AccessTools.TypeByName("Jatify.UI.Plugin");
			if (themeType == null || type == null || type2 == null)
			{
				return false;
			}
			foreach (string item in AllNames())
			{
				FieldInfo fieldInfo = AccessTools.Field(type, item);
				if (fieldInfo != null && fieldInfo.FieldType == typeof(string))
				{
					fields[item] = fieldInfo;
				}
			}
			getter = AccessTools.PropertyGetter(themeType, "D");
			changedField = AccessTools.Field(themeType, "Changed");
			pluginInstance = AccessTools.Field(type2, "Instance");
			pluginTheme = AccessTools.Field(type2, "_theme");
			MethodInfo methodInfo = AccessTools.Method(themeType, "Read", (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(themeType, "Migrate", (Type[])null, (Type[])null);
			if (getter == null || methodInfo == null || !fields.ContainsKey("glass"))
			{
				return false;
			}
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(ThemeOpacity), "AfterLoad", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			if (methodInfo2 != null)
			{
				harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(ThemeOpacity), "BeforeSave", (Type[])null), new HarmonyMethod(typeof(ThemeOpacity), "AfterLoad", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			return true;
		}

		private static IEnumerable<string> AllNames()
		{
			string[] windows = Windows;
			for (int i = 0; i < windows.Length; i++)
			{
				yield return windows[i];
			}
			windows = Panels;
			for (int i = 0; i < windows.Length; i++)
			{
				yield return windows[i];
			}
			windows = Borders;
			for (int i = 0; i < windows.Length; i++)
			{
				yield return windows[i];
			}
		}

		private static void AfterLoad(object __instance)
		{
			try
			{
				object obj = getter.Invoke(__instance, null);
				if (obj != null)
				{
					Remember(obj);
					Scale(obj);
				}
			}
			catch (Exception ex)
			{
				JatifyTweaksPlugin.Log.LogWarning((object)("Could not adjust Jatify's opacity: " + ex.Message));
			}
		}

		private static void BeforeSave(object __instance)
		{
			try
			{
				object obj = getter.Invoke(__instance, null);
				if (obj != null)
				{
					Restore(obj);
				}
			}
			catch (Exception ex)
			{
				JatifyTweaksPlugin.Log.LogWarning((object)("Could not restore Jatify's theme before saving: " + ex.Message));
			}
		}

		private static void Remember(object data)
		{
			originals.Clear();
			foreach (KeyValuePair<string, FieldInfo> field in fields)
			{
				originals[field.Key] = field.Value.GetValue(data) as string;
			}
			scaledData = data;
		}

		private static void Restore(object data)
		{
			if (data != scaledData)
			{
				return;
			}
			foreach (KeyValuePair<string, string> original in originals)
			{
				if (fields.TryGetValue(original.Key, out var value))
				{
					value.SetValue(data, original.Value);
				}
			}
			scaledData = null;
		}

		private static void Scale(object data)
		{
			ScaleAll(data, Windows, JatifyTweaksPlugin.WindowOpacity.Value / 100f);
			ScaleAll(data, Panels, JatifyTweaksPlugin.PanelOpacity.Value / 100f);
			ScaleAll(data, Borders, JatifyTweaksPlugin.BorderOpacity.Value / 100f);
		}

		private static void ScaleAll(object data, string[] names, float factor)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			Color val = default(Color);
			foreach (string key in names)
			{
				if (fields.TryGetValue(key, out var value) && originals.TryGetValue(key, out var value2) && !string.IsNullOrEmpty(value2) && ColorUtility.TryParseHtmlString(value2.StartsWith("#") ? value2 : ("#" + value2), ref val))
				{
					val.a = Mathf.Clamp01(val.a * factor);
					value.SetValue(data, "#" + ColorUtility.ToHtmlStringRGBA(val));
				}
			}
		}

		private static object Theme()
		{
			object obj = ((pluginInstance != null) ? pluginInstance.GetValue(null) : null);
			if (obj == null || !(pluginTheme != null))
			{
				return null;
			}
			return pluginTheme.GetValue(obj);
		}

		internal static void Reapply(bool notify)
		{
			try
			{
				object obj = Theme();
				object obj2 = ((obj != null) ? getter.Invoke(obj, null) : null);
				if (obj2 != null)
				{
					if (obj2 == scaledData)
					{
						Restore(obj2);
					}
					Remember(obj2);
					Scale(obj2);
					if (notify && !(changedField == null) && changedField.GetValue(obj) is Delegate obj3)
					{
						obj3.DynamicInvoke(obj2);
					}
				}
			}
			catch (Exception ex)
			{
				JatifyTweaksPlugin.Log.LogWarning((object)("Could not refresh Jatify's look: " + ex.Message));
			}
		}
	}
}