Decompiled source of LwfRavenQol v1.0.1

BepInEx/plugins/LwfRavenQol.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BaseSystem;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Cysharp.Threading.Tasks;
using Fams.EditIfFamAdd;
using Fams.ParamModification;
using Fams.Summon.Strategy;
using GameState;
using HarmonyLib;
using Input.PlayerAction;
using Items;
using Items.Equip;
using Items.Equip.EditIfEquipsAdd.Equips;
using Items.Equip.EditIfEquipsAdd.Equips.SummonCatalysts;
using Items.Inventory;
using Items.Tag;
using Items.ValueCountSettings;
using Map;
using Map.Directions;
using Map.GridManagerHelpers;
using Map.MapObjects.PureClass;
using Map.MapObjects.PureClass.FamObjects;
using Map.PlacerHelpers;
using TMPro;
using UI;
using UI.Cursor;
using UI.Cursor.Preview;
using UI.LandPurchaseUI;
using UI.ManualUI;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.Localization.Components;
using UnityEngine.UI;
using Utility.Localization;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace LwfRavenQol;

[BepInPlugin("kiyonakanata.lwfravenqol", "LWF Raven QoL", "1.0.1")]
public sealed class RavenQolPlugin : BaseUnityPlugin
{
	internal const string PluginGuid = "kiyonakanata.lwfravenqol";

	internal const string PluginName = "LWF Raven QoL";

	internal const string PluginVersion = "1.0.1";

	internal static ManualLogSource Log;

	private Harmony _harmony;

	internal static ConfigEntry<bool> ChainEnabled;

	internal static ConfigEntry<bool> RetargetEnabled;

	internal static ConfigEntry<bool> MapEnabled;

	internal static ConfigEntry<bool> KeepOldExit;

	internal static ConfigEntry<bool> MapHideManual;

	internal static ConfigEntry<bool> StockVisible;

	internal static ConfigEntry<bool> StockMapOverlay;

	private void Awake()
	{
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		ChainEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1. Relay Chain", "Enabled", true, "");
		RetargetEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Retarget", "Enabled", true, "");
		KeepOldExit = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Retarget", "Keep the old dispatch port", true, "");
		StockVisible = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Stock Display", "Enabled", true, "");
		StockMapOverlay = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Stock Display", "Show map-view stock on entry", false, "");
		MapEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("4. Map View", "Enabled", true, "");
		MapHideManual = ((BaseUnityPlugin)this).Config.Bind<bool>("4. Map View", "Hide control hints", true, "");
		Chain.Init();
		Trip.Init();
		HudTweaks.Init();
		_harmony = new Harmony("kiyonakanata.lwfravenqol");
		_harmony.PatchAll(Assembly.GetExecutingAssembly());
		int num = 0;
		foreach (MethodBase patchedMethod in _harmony.GetPatchedMethods())
		{
			num++;
			Log.LogInfo((object)("[boot] patch: " + patchedMethod.DeclaringType.Name + "." + patchedMethod.Name));
		}
		Log.LogInfo((object)("[boot] LWF Raven QoL 1.0.1  retarget=" + (RetargetEnabled.Value ? "on" : "off") + "  patches=" + num));
		if (num == 0)
		{
			Log.LogError((object)"[boot] no patches applied; the mod will do nothing.");
		}
	}

	private void Update()
	{
		try
		{
			Chain.UpdateRetarget();
		}
		catch (Exception ex)
		{
			Log.LogError((object)("[retarget] " + ex));
		}
		try
		{
			StockView.Update();
		}
		catch (Exception ex2)
		{
			Log.LogError((object)("[stock] " + ex2));
		}
		try
		{
			HudTweaks.Update();
		}
		catch (Exception ex3)
		{
			Log.LogError((object)("[hud] " + ex3));
		}
	}

	private void OnGUI()
	{
		try
		{
			StockView.Draw();
		}
		catch (Exception ex)
		{
			Log.LogError((object)("[stock] " + ex));
		}
	}

	private void OnDestroy()
	{
		try
		{
			HudTweaks.RestoreOnUnload();
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("[hud] " + ex));
		}
		if (_harmony != null)
		{
			try
			{
				_harmony.UnpatchSelf();
			}
			catch (Exception ex2)
			{
				Log.LogWarning((object)("[unpatch] " + ex2));
			}
			_harmony = null;
		}
	}
}
internal static class Patches
{
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class RavenEquipCtor
	{
		private static void Postfix(TransporterCatalystEquip __instance)
		{
			Chain.SetRavenEquip(__instance);
		}
	}

	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class ExitEquipCtor
	{
		private static void Postfix(TransporterExitCatalystEquip __instance)
		{
			Chain.SetExitEquip(__instance);
		}
	}

	[HarmonyPatch(typeof(TransporterExitCatalystEquip), "PerformHoldAction", new Type[] { typeof(float) })]
	internal static class ExitHold
	{
		private static bool Prefix(TransporterExitCatalystEquip __instance, float holdCounter, ref UniTask<MapObject> __result)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Chain.TrackHold(holdCounter);
				if (!Chain.ShouldChain())
				{
					return true;
				}
				__result = Chain.Step(__instance);
				return false;
			}
			catch (Exception ex)
			{
				RavenQolPlugin.Log.LogError((object)("[hold] " + ex));
				return true;
			}
		}
	}

	[HarmonyPatch(typeof(TransporterExitCatalystEquip), "PerformAction")]
	internal static class ExitClick
	{
		private static bool Prefix(ref UniTask<MapObject> __result)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!Chain.TrySwallowClick())
				{
					return true;
				}
				__result = UniTask.FromResult<MapObject>((MapObject)null);
				return false;
			}
			catch (Exception ex)
			{
				RavenQolPlugin.Log.LogError((object)("[click] " + ex));
				return true;
			}
		}
	}

	[HarmonyPatch(typeof(EquipActionHandler), "OnSwitchModePerformed")]
	internal static class SwitchModeRetarget
	{
		private static bool Prefix(EquipActionHandler __instance)
		{
			try
			{
				if (!Chain.UsesSwitchModeKey())
				{
					return true;
				}
				if (LWFTimeScale.IsPausing())
				{
					return true;
				}
				if (!Chain.IsHandlerUsable(__instance))
				{
					return true;
				}
				return !Chain.TryBeginRetarget();
			}
			catch (Exception ex)
			{
				RavenQolPlugin.Log.LogError((object)("[switch] " + ex));
				return true;
			}
		}
	}

	[HarmonyPatch(typeof(TransporterObject), "TrySetExit")]
	internal static class RestartOnRetarget
	{
		private static void Prefix(TransporterObject __instance, TransporterExitObject exit)
		{
			try
			{
				if (Chain.IsRetargetRaven(__instance) && exit != null && __instance.GetExitObject() != exit)
				{
					Trip.HandOver(__instance, exit);
				}
			}
			catch (Exception ex)
			{
				RavenQolPlugin.Log.LogError((object)("[restart] " + ex));
			}
		}
	}

	[HarmonyPatch(typeof(TransporterObject), "BeginGoing")]
	internal static class TopUpBeforeGoing
	{
		private static bool Prefix(TransporterObject __instance)
		{
			try
			{
				return !Trip.TryTopUp(__instance);
			}
			catch (Exception ex)
			{
				RavenQolPlugin.Log.LogError((object)("[topup] " + ex));
				return true;
			}
		}
	}

	[HarmonyPatch(typeof(TransporterExitObject), "ReleaseIfNoLinkedTransporter")]
	internal static class KeepOldExit
	{
		private static bool Prefix()
		{
			try
			{
				if (!RavenQolPlugin.KeepOldExit.Value)
				{
					return true;
				}
				if (!Chain.IsRetargetingNow())
				{
					return true;
				}
				RavenQolPlugin.Log.LogInfo((object)"[chain] kept the old dispatch port");
				return false;
			}
			catch (Exception ex)
			{
				RavenQolPlugin.Log.LogError((object)("[keep] " + ex));
				return true;
			}
		}
	}

	[HarmonyPatch(typeof(TransporterSummonProcessor), "CancelPutExitMode")]
	internal static class CancelKeepsRaven
	{
		private static bool Prefix(TransporterSummonProcessor __instance)
		{
			try
			{
				if (!Chain.IsRetargeting(__instance))
				{
					return true;
				}
				__instance.CompletePutExitMode();
				RavenQolPlugin.Log.LogInfo((object)"[chain] retarget cancelled (raven unchanged)");
				return false;
			}
			catch (Exception ex)
			{
				RavenQolPlugin.Log.LogError((object)("[cancel] " + ex));
				return true;
			}
		}
	}

	[HarmonyPatch(typeof(EquipActionHandler), "OnMainAction")]
	internal static class MainActionEnd
	{
		private static void Postfix(CallbackContext context)
		{
			try
			{
				if (((CallbackContext)(ref context)).canceled)
				{
					Chain.OnDragEnd();
				}
			}
			catch (Exception ex)
			{
				RavenQolPlugin.Log.LogError((object)("[end] " + ex));
			}
		}
	}
}
internal static class Trip
{
	private const int StateEvaluate = 0;

	private const int StatePickBeforeTransfer = 2;

	private const int StatePickAfterTransfer = 3;

	private const int StateGoingStart = 4;

	private const int StateReturningStart = 9;

	private static FieldInfo _fIsWorking;

	private static FieldInfo _fWorkState;

	private static FieldInfo _fRenderer;

	private static FieldInfo _fEntryPosition;

	private static FieldInfo _fTripExit;

	private static FieldInfo _fTripExitPosition;

	private static FieldInfo _fTripDistance;

	private static MethodInfo _mBeginReturning;

	private static bool _ready;

	private static Type _tWorkState;

	private static MethodInfo _mSetWorkState;

	private static FieldInfo _fAnimController;

	private static MethodInfo _mAnimWorkingStart;

	private static FieldInfo _fCarryingItemPreview;

	private static MethodInfo _mPreviewEnable;

	private static FieldInfo _fSourceBinding;

	private static FieldInfo _fPickSourceSnapshot;

	private static MethodInfo _mAnimGather;

	private static PropertyInfo _pBindingSource;

	private static MethodInfo _mIsValidSourceBinding;

	private static MethodInfo _mIsTargetHasAny;

	private static bool _topupReady;

	private static readonly HashSet<TransporterObject> TopUpPending = new HashSet<TransporterObject>();

	internal static void Init()
	{
		Type typeFromHandle = typeof(TransporterObject);
		BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
		_fIsWorking = typeFromHandle.GetField("_isWorking", bindingAttr);
		_fWorkState = typeFromHandle.GetField("_workState", bindingAttr);
		_fRenderer = typeFromHandle.GetField("_renderer", bindingAttr);
		_fEntryPosition = typeFromHandle.GetField("_entryPosition", bindingAttr);
		_fTripExit = typeFromHandle.GetField("_tripExit", bindingAttr);
		_fTripExitPosition = typeFromHandle.GetField("_tripExitPosition", bindingAttr);
		_fTripDistance = typeFromHandle.GetField("_tripDistance", bindingAttr);
		_mBeginReturning = typeFromHandle.GetMethod("BeginReturning", bindingAttr);
		_ready = _fIsWorking != null && _fWorkState != null && _fRenderer != null && _fEntryPosition != null && _fTripExit != null && _fTripExitPosition != null && _fTripDistance != null && _mBeginReturning != null;
		if (!_ready)
		{
			RavenQolPlugin.Log.LogWarning((object)"[trip] cannot read TransporterObject internals; mid-flight retarget will desync the visuals.");
		}
		_tWorkState = typeFromHandle.GetNestedType("WorkState", BindingFlags.NonPublic);
		_mSetWorkState = typeFromHandle.GetMethod("SetWorkState", bindingAttr);
		_fAnimController = typeFromHandle.GetField("_animController", bindingAttr);
		_mAnimWorkingStart = ((_fAnimController != null) ? _fAnimController.FieldType.GetMethod("SetAnimWorkingStart") : null);
		_fCarryingItemPreview = typeFromHandle.GetField("_carryingItemPreview", bindingAttr);
		_mPreviewEnable = ((_fCarryingItemPreview != null) ? _fCarryingItemPreview.FieldType.GetMethod("Enable", new Type[1] { typeof(bool) }) : null);
		_fSourceBinding = typeFromHandle.GetField("_sourceBinding", bindingAttr);
		_fPickSourceSnapshot = typeFromHandle.GetField("_pickSourceSnapshot", bindingAttr);
		_mAnimGather = ((_fAnimController != null) ? _fAnimController.FieldType.GetMethod("SetAnimGather") : null);
		Type nestedType = typeFromHandle.GetNestedType("SourceBinding", BindingFlags.NonPublic);
		_pBindingSource = ((nestedType != null) ? nestedType.GetProperty("Source") : null);
		_mIsValidSourceBinding = typeFromHandle.GetMethod("IsValidSourceBinding", bindingAttr);
		_mIsTargetHasAny = typeFromHandle.GetMethod("IsTargetHasAny", bindingAttr);
		_topupReady = _ready && _tWorkState != null && _mSetWorkState != null && _fSourceBinding != null && _fPickSourceSnapshot != null && _pBindingSource != null && _mIsValidSourceBinding != null && _mIsTargetHasAny != null;
		if (!_topupReady)
		{
			RavenQolPlugin.Log.LogWarning((object)"[trip] cannot read internals needed for top-up; forced-return trips head out partially loaded.");
		}
	}

	internal static bool TryTopUp(TransporterObject raven)
	{
		if (!_topupReady || raven == null)
		{
			return false;
		}
		if (!TopUpPending.Remove(raven))
		{
			return false;
		}
		if (Convert.ToInt32(_fWorkState.GetValue(raven)) != 0)
		{
			return false;
		}
		if (!HasFreeSlot(raven.GetDeliveryInventory().GetDB()))
		{
			return false;
		}
		object value = _fSourceBinding.GetValue(raven);
		bool item = ((FamObject)raven).GetInventory().GetDB().GetAnyContainsIndex()
			.Item1;
		bool flag = false;
		if (!item && value != null && (bool)_mIsValidSourceBinding.Invoke(raven, new object[1] { value }))
		{
			object value2 = _pBindingSource.GetValue(value, null);
			if (value2 != null)
			{
				flag = (bool)_mIsTargetHasAny.Invoke(raven, new object[1] { value2 });
			}
		}
		if (!item && !flag)
		{
			return false;
		}
		_fPickSourceSnapshot.SetValue(raven, value);
		CallAnim(raven, _mAnimGather);
		SetWorkState(raven, 2);
		RavenQolPlugin.Log.LogInfo((object)"[chain] topping up before heading out");
		return true;
	}

	private static bool HasFreeSlot(InventoryDB db)
	{
		if (db == null)
		{
			return false;
		}
		int getCellCapacity = db.GetCellCapacity;
		List<int> keys = db.GetKeys();
		for (int i = 0; i < keys.Count; i++)
		{
			if (db.ItemCount(keys[i]) < getCellCapacity)
			{
				return true;
			}
		}
		return false;
	}

	private static void SetWorkState(TransporterObject raven, int state)
	{
		_mSetWorkState.Invoke(raven, new object[1] { Enum.ToObject(_tWorkState, state) });
	}

	private static void CallAnim(TransporterObject raven, MethodInfo method)
	{
		if (!(_fAnimController == null) && !(method == null))
		{
			object value = _fAnimController.GetValue(raven);
			if (value != null)
			{
				method.Invoke(value, null);
			}
		}
	}

	private static void EnableCarryingPreview(TransporterObject raven)
	{
		if (!(_fCarryingItemPreview == null) && !(_mPreviewEnable == null))
		{
			object value = _fCarryingItemPreview.GetValue(raven);
			if (value != null)
			{
				_mPreviewEnable.Invoke(value, new object[1] { true });
			}
		}
	}

	internal static void HandOver(TransporterObject raven, TransporterExitObject newExit)
	{
		//IL_0063: 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_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: 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_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: 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_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: 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)
		if (!_ready || raven == null || newExit == null || !Object.op_Implicit((Object)(object)((MapObject)newExit).pivot))
		{
			return;
		}
		object value = _fIsWorking.GetValue(raven);
		if (!(value is bool) || !(bool)value)
		{
			return;
		}
		switch (Convert.ToInt32(_fWorkState.GetValue(raven)))
		{
		case 4:
		{
			Vector3 val3 = (Vector3)_fEntryPosition.GetValue(raven);
			Vector3 position2 = ((MapObject)newExit).pivot.transform.position;
			_fTripExit.SetValue(raven, newExit);
			_fTripExitPosition.SetValue(raven, position2);
			_fTripDistance.SetValue(raven, Vector3.Distance(val3, position2));
			RavenQolPlugin.Log.LogInfo((object)"[chain] refreshed the destination before takeoff");
			break;
		}
		case 5:
		case 6:
		case 7:
		case 8:
		{
			object? value2 = _fRenderer.GetValue(raven);
			GameObject val = (GameObject)((value2 is GameObject) ? value2 : null);
			if (!((Object)(object)val == (Object)null))
			{
				Vector3 position = val.transform.position;
				Vector3 val2 = (Vector3)_fEntryPosition.GetValue(raven);
				_fTripExitPosition.SetValue(raven, position);
				_fTripDistance.SetValue(raven, Vector3.Distance(position, val2));
				_mBeginReturning.Invoke(raven, null);
				TopUpPending.Add(raven);
				RavenQolPlugin.Log.LogInfo((object)"[chain] turning around mid-flight, heading home");
			}
			break;
		}
		}
	}
}
internal static class Chain
{
	private sealed class Hop
	{
		private readonly TransporterExitCatalystEquip _exitEquip;

		private readonly CursorHitChecker _hit;

		private readonly MapObjectPlacer _placer;

		private readonly TransporterSummonProcessor _proc;

		private readonly InventoryIndex _index;

		private readonly TransporterObject _raven;

		private readonly Vector2Int _exitAddr;

		private readonly Vector2Int _nextAddr;

		private readonly Direction4 _facing;

		private TransporterExitObject _placedExit;

		internal Hop(TransporterExitCatalystEquip exitEquip, CursorHitChecker hit, MapObjectPlacer placer, TransporterSummonProcessor proc, InventoryIndex index, TransporterObject raven, Vector2Int exitAddr, Vector2Int nextAddr, Direction4 dir)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			_exitEquip = exitEquip;
			_hit = hit;
			_placer = placer;
			_proc = proc;
			_index = index;
			_raven = raven;
			_exitAddr = exitAddr;
			_nextAddr = nextAddr;
			_facing = DirectionCalc.GetOpposite(dir);
		}

		internal UniTask<MapObject> Start()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			_hit.SetAdjustedChildGridGlobalAddress(_exitAddr);
			UniTask<FamObject> val = Summon(((SummonCatalystEquip)_exitEquip).summonStrategyDistributor, _placer.PutDirection, _hit, _facing);
			Func<FamObject, UniTask<MapObject>> func = OnExitPlaced;
			return UniTaskExtensions.ContinueWith<FamObject, MapObject>(val, func);
		}

		private UniTask<MapObject> OnExitPlaced(FamObject placed)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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)
			UniTask<MapObject> result = UniTask.FromResult<MapObject>((MapObject)null);
			TransporterExitObject val = (TransporterExitObject)(object)((placed is TransporterExitObject) ? placed : null);
			if (val == null)
			{
				_hit.ClearAdjustedChildGridGlobalAddress();
				Block("InvalidDestination");
				return result;
			}
			if (!_raven.TrySetExit(val))
			{
				((MapObject)val).DestroyPivot();
				_hit.ClearAdjustedChildGridGlobalAddress();
				Block("InvalidDestination");
				return result;
			}
			_placedExit = val;
			_proc.RecordAvailableExit(val);
			_proc.CompletePutExitMode();
			_hit.SetAdjustedChildGridGlobalAddress(_nextAddr);
			UniTask<FamObject> val2 = Summon(((SummonCatalystEquip)_ravenEquip).summonStrategyDistributor, _placer.PutDirection, _hit, _facing);
			Func<FamObject, MapObject> func = OnRavenPlaced;
			return UniTaskExtensions.ContinueWith<FamObject, MapObject>(val2, func);
		}

		private MapObject OnRavenPlaced(FamObject placed)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			_hit.ClearAdjustedChildGridGlobalAddress();
			TransporterObject val = (TransporterObject)(object)((placed is TransporterObject) ? placed : null);
			if (val == null)
			{
				Block("InvalidDestination");
				return (MapObject)(object)_placedExit;
			}
			UseOneCatalyst(_index);
			ChildGrid addressGrid = ((MapObject)val).GetAddressGrid();
			if (addressGrid == null)
			{
				Block(null);
				return (MapObject)(object)val;
			}
			if (!TryGetCarryingRange(out var carryingRange))
			{
				carryingRange = CurrentSpan();
			}
			_proc.CreateNewProcess(addressGrid.GlobalAddress, carryingRange, val);
			_hops++;
			RavenQolPlugin.Log.LogInfo((object)string.Concat("[chain] hop ", _hops, " exit=", _exitAddr, " raven=", addressGrid.GlobalAddress));
			return (MapObject)(object)val;
		}
	}

	private sealed class Finish
	{
		private readonly TransporterExitCatalystEquip _exitEquip;

		private readonly CursorHitChecker _hit;

		private readonly MapObjectPlacer _placer;

		private readonly TransporterSummonProcessor _proc;

		private readonly TransporterObject _raven;

		private readonly Direction4 _facing;

		internal Finish(TransporterExitCatalystEquip exitEquip, CursorHitChecker hit, MapObjectPlacer placer, TransporterSummonProcessor proc, TransporterObject raven, Direction4 facing)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			_exitEquip = exitEquip;
			_hit = hit;
			_placer = placer;
			_proc = proc;
			_raven = raven;
			_facing = facing;
		}

		internal void Start(Vector2Int address)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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)
			_hit.SetAdjustedChildGridGlobalAddress(address);
			UniTask<FamObject> val = Summon(((SummonCatalystEquip)_exitEquip).summonStrategyDistributor, _placer.PutDirection, _hit, _facing);
			Action<FamObject> action = OnPlaced;
			UniTaskExtensions.Forget(UniTaskExtensions.ContinueWith<FamObject>(val, action));
		}

		private void OnPlaced(FamObject placed)
		{
			_hit.ClearAdjustedChildGridGlobalAddress();
			TransporterExitObject val = (TransporterExitObject)(object)((placed is TransporterExitObject) ? placed : null);
			if (val != null)
			{
				if (!_raven.TrySetExit(val))
				{
					((MapObject)val).DestroyPivot();
					return;
				}
				_proc.RecordAvailableExit(val);
				_proc.CompletePutExitMode();
				RavenQolPlugin.Log.LogInfo((object)"[chain] placed the final dispatch port");
			}
		}
	}

	private const float EquipLookupInterval = 0.5f;

	private const float SkipMessageInterval = 1.5f;

	private static FieldInfo _fHit;

	private static FieldInfo _fGrid;

	private static FieldInfo _fIndex;

	private static TransporterCatalystEquip _ravenEquip;

	private static TransporterExitCatalystEquip _exitEquip;

	private static EquipActionHandler _handler;

	private static float _lastEquipLookup = float.NegativeInfinity;

	private static TransporterObject _retargetRaven;

	private static float _lastHold = -1f;

	private static bool _blocked;

	private static int _hops;

	private static bool _swallowedClick;

	private static string _lastSkipKey;

	private static float _lastSkipTime = float.NegativeInfinity;

	internal static void Init()
	{
		Type typeFromHandle = typeof(SummonCatalystEquip);
		BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
		_fHit = typeFromHandle.GetField("cursorHitChecker", bindingAttr);
		_fGrid = typeFromHandle.GetField("gridManager", bindingAttr);
		_fIndex = typeFromHandle.GetField("playerIndex", bindingAttr);
		if (_fHit == null || _fGrid == null || _fIndex == null)
		{
			RavenQolPlugin.Log.LogError((object)"[init] SummonCatalystEquip fields not found; game version mismatch?");
		}
	}

	internal static void SetRavenEquip(TransporterCatalystEquip e)
	{
		_ravenEquip = e;
	}

	internal static void SetExitEquip(TransporterExitCatalystEquip e)
	{
		_exitEquip = e;
	}

	private static void EnsureEquips()
	{
		if (_ravenEquip != null && _exitEquip != null && _handler != null)
		{
			return;
		}
		float unscaledTime = Time.unscaledTime;
		if (unscaledTime - _lastEquipLookup < 0.5f)
		{
			return;
		}
		_lastEquipLookup = unscaledTime;
		ClickActionManager val = Object.FindAnyObjectByType<ClickActionManager>();
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
		FieldInfo field = typeof(ClickActionManager).GetField("_equipActionHandler", bindingAttr);
		if (field == null)
		{
			return;
		}
		object? value = field.GetValue(val);
		EquipActionHandler val2 = (EquipActionHandler)((value is EquipActionHandler) ? value : null);
		if (val2 == null)
		{
			return;
		}
		_handler = val2;
		if (_exitEquip == null)
		{
			FieldInfo field2 = typeof(EquipActionHandler).GetField("_putExitEquip", bindingAttr);
			if (field2 != null)
			{
				object? value2 = field2.GetValue(val2);
				_exitEquip = (TransporterExitCatalystEquip)((value2 is TransporterExitCatalystEquip) ? value2 : null);
			}
		}
		if (_ravenEquip != null)
		{
			return;
		}
		FieldInfo field3 = typeof(EquipActionHandler).GetField("_equipTypeService", bindingAttr);
		if (field3 != null)
		{
			object? value3 = field3.GetValue(val2);
			EquipTypeService val3 = (EquipTypeService)((value3 is EquipTypeService) ? value3 : null);
			if (val3 != null)
			{
				IEquip obj = val3.FetchIEquip("Summon-Transporter");
				_ravenEquip = (TransporterCatalystEquip)(object)((obj is TransporterCatalystEquip) ? obj : null);
			}
		}
	}

	internal static void TrackHold(float holdCounter)
	{
		if (holdCounter <= _lastHold)
		{
			ResetSession();
		}
		_lastHold = holdCounter;
	}

	private static void ResetSession()
	{
		_lastHold = -1f;
		_blocked = false;
		_hops = 0;
		_swallowedClick = false;
		_lastSkipKey = null;
		_lastSkipTime = float.NegativeInfinity;
	}

	internal static bool TrySwallowClick()
	{
		if (!RavenQolPlugin.ChainEnabled.Value)
		{
			return false;
		}
		if (FindLinkingProcessor() == null)
		{
			return false;
		}
		_swallowedClick = true;
		RavenQolPlugin.Log.LogInfo((object)"[chain] swallowed the press (drag origin)");
		return true;
	}

	internal static bool ShouldChain()
	{
		if (!RavenQolPlugin.ChainEnabled.Value)
		{
			return false;
		}
		if (_blocked)
		{
			return false;
		}
		if (_hops >= 64)
		{
			return false;
		}
		return FindLinkingProcessor() != null;
	}

	internal static bool IsMapInteractive()
	{
		if (PointerOverFinder.IsPointerOverUI)
		{
			return false;
		}
		EnsureEquips();
		if (_handler == null)
		{
			return false;
		}
		if (!IsHandlerUsable(_handler))
		{
			return false;
		}
		PlayerActionMap instance = PlayerActionMap.Instance;
		if (instance == null)
		{
			return false;
		}
		InputAction mainAction = instance.GetMainAction();
		if (mainAction == null || !mainAction.enabled)
		{
			return false;
		}
		return true;
	}

	internal static CursorHitChecker CurrentCursorHitChecker()
	{
		EnsureEquips();
		if (_exitEquip == null || _fHit == null)
		{
			return null;
		}
		object? value = _fHit.GetValue(_exitEquip);
		return (CursorHitChecker)((value is CursorHitChecker) ? value : null);
	}

	private static TransporterSummonProcessor FindProcessor()
	{
		EnsureEquips();
		if (_exitEquip == null || _fGrid == null)
		{
			return null;
		}
		object? value = _fGrid.GetValue(_exitEquip);
		GridManager val = (GridManager)((value is GridManager) ? value : null);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		MapObjectPlacer mapObjectPlacer = val.MapObjectPlacer;
		if (mapObjectPlacer == null)
		{
			return null;
		}
		return mapObjectPlacer.TransporterSummonProcessor;
	}

	private static TransporterSummonProcessor FindLinkingProcessor()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Invalid comparison between Unknown and I4
		TransporterSummonProcessor val = FindProcessor();
		if (val == null)
		{
			return null;
		}
		if ((int)val.CurrentPutExitMode != 1)
		{
			return null;
		}
		if (val.GetEntryObject() == null)
		{
			return null;
		}
		return val;
	}

	internal static bool IsRetargetRaven(TransporterObject raven)
	{
		if (raven == null || _retargetRaven != raven)
		{
			return false;
		}
		return IsRetargetingNow();
	}

	internal static bool IsRetargetingNow()
	{
		if (_retargetRaven == null)
		{
			return false;
		}
		return IsRetargeting(FindProcessor());
	}

	internal static bool IsRetargeting(TransporterSummonProcessor proc)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Invalid comparison between Unknown and I4
		if (_retargetRaven == null || proc == null)
		{
			return false;
		}
		if ((int)proc.CurrentPutExitMode != 1)
		{
			return false;
		}
		return proc.GetEntryObject() == _retargetRaven;
	}

	internal static bool UsesSwitchModeKey()
	{
		return RavenQolPlugin.RetargetEnabled.Value;
	}

	internal static bool IsHandlerUsable(EquipActionHandler handler)
	{
		if (handler == null)
		{
			return false;
		}
		BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
		FieldInfo field = typeof(EquipActionHandler).GetField("_canUse", bindingAttr);
		if (field == null)
		{
			return true;
		}
		object value = field.GetValue(handler);
		if (value is bool)
		{
			return (bool)value;
		}
		return false;
	}

	internal static void UpdateRetarget()
	{
		if (_retargetRaven != null && !IsRetargeting(FindProcessor()))
		{
			_retargetRaven = null;
		}
	}

	internal static bool TryBeginRetarget()
	{
		//IL_003d: 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_008d: Unknown result type (might be due to invalid IL or missing references)
		TransporterSummonProcessor val = FindProcessor();
		if (val == null)
		{
			return false;
		}
		if (val.IsPutExitModeActive)
		{
			return false;
		}
		object? value = _fHit.GetValue(_exitEquip);
		CursorHitChecker val2 = (CursorHitChecker)((value is CursorHitChecker) ? value : null);
		if (val2 == null)
		{
			return false;
		}
		ChildGrid hitChildGrid = val2.HitChildGrid;
		if (hitChildGrid == null)
		{
			return false;
		}
		MapObject adjustedMapObject = val2.GetAdjustedMapObject(hitChildGrid.GlobalAddress);
		TransporterObject val3 = (TransporterObject)(object)((adjustedMapObject is TransporterObject) ? adjustedMapObject : null);
		if (val3 == null)
		{
			return false;
		}
		ChildGrid addressGrid = ((MapObject)val3).GetAddressGrid();
		if (addressGrid == null)
		{
			return false;
		}
		if (!TryGetCarryingRange(out var carryingRange))
		{
			return false;
		}
		val.CreateNewProcess(addressGrid.GlobalAddress, carryingRange, val3);
		_retargetRaven = val3;
		RavenQolPlugin.Log.LogInfo((object)("[chain] retarget started at " + addressGrid.GlobalAddress));
		return true;
	}

	internal static UniTask<MapObject> Step(TransporterExitCatalystEquip exitEquip)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: 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_0084: 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_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: 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_00cb: 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_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Invalid comparison between Unknown and I4
		//IL_00d8: 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_0142: 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_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: 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_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: 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_01c9: 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_01cd: 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_01be: Unknown result type (might be due to invalid IL or missing references)
		UniTask<MapObject> result = UniTask.FromResult<MapObject>((MapObject)null);
		object? value = _fHit.GetValue(exitEquip);
		CursorHitChecker val = (CursorHitChecker)((value is CursorHitChecker) ? value : null);
		object? value2 = _fGrid.GetValue(exitEquip);
		GridManager val2 = (GridManager)((value2 is GridManager) ? value2 : null);
		object? value3 = _fIndex.GetValue(exitEquip);
		InventoryIndex val3 = (InventoryIndex)((value3 is InventoryIndex) ? value3 : null);
		if (val == null || (Object)(object)val2 == (Object)null || val3 == null)
		{
			return result;
		}
		MapObjectPlacer mapObjectPlacer = val2.MapObjectPlacer;
		TransporterSummonProcessor transporterSummonProcessor = mapObjectPlacer.TransporterSummonProcessor;
		TransporterObject entryObject = transporterSummonProcessor.GetEntryObject();
		if (entryObject == null)
		{
			return result;
		}
		ChildGrid addressGrid = ((MapObject)entryObject).GetAddressGrid();
		ChildGrid hitChildGrid = val.HitChildGrid;
		if (addressGrid == null || hitChildGrid == null)
		{
			return result;
		}
		Vector2Int globalAddress = addressGrid.GlobalAddress;
		Vector2Int globalAddress2 = hitChildGrid.GlobalAddress;
		int num = CurrentSpan();
		if (num < 1)
		{
			return result;
		}
		Vector2Int delta = default(Vector2Int);
		((Vector2Int)(ref delta))..ctor(((Vector2Int)(ref globalAddress2)).x - ((Vector2Int)(ref globalAddress)).x, ((Vector2Int)(ref globalAddress2)).y - ((Vector2Int)(ref globalAddress)).y);
		if (Manhattan(delta) < num + 1)
		{
			return result;
		}
		Vector2Int val4 = ReachPoint(delta, num);
		Vector2Int val5 = default(Vector2Int);
		((Vector2Int)(ref val5))..ctor(((Vector2Int)(ref globalAddress)).x + ((Vector2Int)(ref val4)).x, ((Vector2Int)(ref globalAddress)).y + ((Vector2Int)(ref val4)).y);
		Direction4 val6 = DominantDirection(new Vector2Int(((Vector2Int)(ref globalAddress2)).x - ((Vector2Int)(ref val5)).x, ((Vector2Int)(ref globalAddress2)).y - ((Vector2Int)(ref val5)).y));
		if ((int)val6 == -1)
		{
			return result;
		}
		Vector2Int val7 = DirectionCalc.DIRECTION4_VECTOR2_INT[val6];
		Vector2Int val8 = default(Vector2Int);
		((Vector2Int)(ref val8))..ctor(((Vector2Int)(ref val5)).x + ((Vector2Int)(ref val7)).x, ((Vector2Int)(ref val5)).y + ((Vector2Int)(ref val7)).y);
		if (val3.GetCurrentItemCount() <= 0)
		{
			Skip(null);
			return result;
		}
		if (!CanPlace(val, val5))
		{
			Skip(BlockReason(val, val5));
			return result;
		}
		if (!CanPlace(val, val8))
		{
			Skip(BlockReason(val, val8));
			return result;
		}
		if (_ravenEquip == null)
		{
			Skip(null);
			return result;
		}
		Hop hop = new Hop(exitEquip, val, mapObjectPlacer, transporterSummonProcessor, val3, entryObject, val5, val8, val6);
		return hop.Start();
	}

	internal static void OnDragEnd()
	{
		//IL_0085: 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_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_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: 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_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: 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_01c0: 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_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Invalid comparison between Unknown and I4
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Invalid comparison between Unknown and I4
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: 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_01eb: 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_01f7: Unknown result type (might be due to invalid IL or missing references)
		int hops = _hops;
		bool swallowedClick = _swallowedClick;
		ResetSession();
		if (hops <= 0 && !swallowedClick)
		{
			return;
		}
		TransporterSummonProcessor val = FindLinkingProcessor();
		if (val == null)
		{
			return;
		}
		object? value = _fHit.GetValue(_exitEquip);
		CursorHitChecker val2 = (CursorHitChecker)((value is CursorHitChecker) ? value : null);
		object? value2 = _fGrid.GetValue(_exitEquip);
		GridManager val3 = (GridManager)((value2 is GridManager) ? value2 : null);
		if (val2 == null || (Object)(object)val3 == (Object)null)
		{
			return;
		}
		TransporterObject entryObject = val.GetEntryObject();
		if (entryObject == null)
		{
			return;
		}
		ChildGrid addressGrid = ((MapObject)entryObject).GetAddressGrid();
		ChildGrid hitChildGrid = val2.HitChildGrid;
		if (addressGrid == null || hitChildGrid == null)
		{
			return;
		}
		Vector2Int globalAddress = addressGrid.GlobalAddress;
		Vector2Int globalAddress2 = hitChildGrid.GlobalAddress;
		Vector2Int delta = default(Vector2Int);
		((Vector2Int)(ref delta))..ctor(((Vector2Int)(ref globalAddress2)).x - ((Vector2Int)(ref globalAddress)).x, ((Vector2Int)(ref globalAddress2)).y - ((Vector2Int)(ref globalAddress)).y);
		int num = MaxSpan();
		if (num < 1)
		{
			return;
		}
		MapObject adjustedMapObject = val2.GetAdjustedMapObject(globalAddress2);
		TransporterExitObject val4 = (TransporterExitObject)(object)((adjustedMapObject is TransporterExitObject) ? adjustedMapObject : null);
		if (val4 != null && val4.CanLinkTransporter() && Manhattan(delta) <= num && entryObject.TrySetExit(val4))
		{
			val.RecordAvailableExit(val4);
			val.CompletePutExitMode();
			RavenQolPlugin.Log.LogInfo((object)"[chain] connected to an existing dispatch port");
			return;
		}
		if (TryFindFeedSpot(val2, adjustedMapObject, globalAddress, globalAddress2, num, out var address, out var facing))
		{
			new Finish(_exitEquip, val2, val3.MapObjectPlacer, val, entryObject, facing).Start(address);
			return;
		}
		Vector2Int address2 = default(Vector2Int);
		for (int num2 = Mathf.Min(Manhattan(delta), num); num2 >= 1; num2--)
		{
			Vector2Int val5 = ReachPoint(delta, num2);
			((Vector2Int)(ref address2))..ctor(((Vector2Int)(ref globalAddress)).x + ((Vector2Int)(ref val5)).x, ((Vector2Int)(ref globalAddress)).y + ((Vector2Int)(ref val5)).y);
			if (CanPlace(val2, address2))
			{
				Direction4 val6 = DominantDirection(new Vector2Int(((Vector2Int)(ref globalAddress2)).x - ((Vector2Int)(ref address2)).x, ((Vector2Int)(ref globalAddress2)).y - ((Vector2Int)(ref address2)).y));
				if ((int)val6 == -1)
				{
					val6 = DominantDirection(delta);
				}
				if ((int)val6 != -1)
				{
					new Finish(_exitEquip, val2, val3.MapObjectPlacer, val, entryObject, DirectionCalc.GetOpposite(val6)).Start(address2);
				}
				break;
			}
		}
	}

	private static bool TryFindFeedSpot(CursorHitChecker hit, MapObject target, Vector2Int from, Vector2Int targetAddr, int maxSpan, out Vector2Int address, out Direction4 facing)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: 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_0035: Invalid comparison between Unknown and I4
		//IL_003f: 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_0045: 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_0094: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Expected I4, but got Unknown
		address = new Vector2Int(0, 0);
		facing = (Direction4)(-1);
		ConnectableObject val = (ConnectableObject)(object)((target is ConnectableObject) ? target : null);
		if (val == null)
		{
			return false;
		}
		int num = int.MaxValue;
		Vector2Int val4 = default(Vector2Int);
		for (int i = 0; i < 4; i++)
		{
			Direction4 val2 = (Direction4)i;
			if ((int)val.GetIOByDirection(val2) != 1)
			{
				continue;
			}
			Vector2Int val3 = DirectionCalc.DIRECTION4_VECTOR2_INT[val2];
			((Vector2Int)(ref val4))..ctor(((Vector2Int)(ref targetAddr)).x + ((Vector2Int)(ref val3)).x, ((Vector2Int)(ref targetAddr)).y + ((Vector2Int)(ref val3)).y);
			if (CanPlace(hit, val4))
			{
				int num2 = Manhattan(new Vector2Int(((Vector2Int)(ref val4)).x - ((Vector2Int)(ref from)).x, ((Vector2Int)(ref val4)).y - ((Vector2Int)(ref from)).y));
				if (num2 >= 1 && num2 <= maxSpan && num2 < num)
				{
					num = num2;
					address = val4;
					facing = (Direction4)(int)val2;
				}
			}
		}
		return (int)facing != -1;
	}

	private static int MaxSpan()
	{
		if (!TryGetCarryingRange(out var carryingRange))
		{
			return 0;
		}
		return (int)carryingRange;
	}

	private static int CurrentSpan()
	{
		return MaxSpan();
	}

	private static int Manhattan(Vector2Int delta)
	{
		return Mathf.Abs(((Vector2Int)(ref delta)).x) + Mathf.Abs(((Vector2Int)(ref delta)).y);
	}

	private static int Sign(int value)
	{
		if (value > 0)
		{
			return 1;
		}
		if (value < 0)
		{
			return -1;
		}
		return 0;
	}

	private static Vector2Int ReachPoint(Vector2Int delta, int dist)
	{
		//IL_0028: 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_0077: Unknown result type (might be due to invalid IL or missing references)
		int num = Mathf.Abs(((Vector2Int)(ref delta)).x);
		int num2 = Mathf.Abs(((Vector2Int)(ref delta)).y);
		int num3 = num + num2;
		if (num3 <= 0 || dist <= 0)
		{
			return new Vector2Int(0, 0);
		}
		if (dist >= num3)
		{
			return delta;
		}
		int num4 = Mathf.RoundToInt((float)dist * (float)num / (float)num3);
		if (num4 > num)
		{
			num4 = num;
		}
		int num5 = dist - num4;
		if (num5 > num2)
		{
			num5 = num2;
			num4 = dist - num5;
		}
		return new Vector2Int(num4 * Sign(((Vector2Int)(ref delta)).x), num5 * Sign(((Vector2Int)(ref delta)).y));
	}

	private static bool TryGetCarryingRange(out float carryingRange)
	{
		carryingRange = 0f;
		FamParamsManager instance = FamParamsManager.Instance;
		if (instance == null)
		{
			return false;
		}
		FamRuntimeParam val = default(FamRuntimeParam);
		if (!instance.TryGetParam((FamType)4, (FamParamName)5, ref val))
		{
			return false;
		}
		if (val == null)
		{
			return false;
		}
		carryingRange = val.GetCurrentValue();
		return true;
	}

	private static Direction4 DominantDirection(Vector2Int delta)
	{
		if (((Vector2Int)(ref delta)).x == 0 && ((Vector2Int)(ref delta)).y == 0)
		{
			return (Direction4)(-1);
		}
		if (Mathf.Abs(((Vector2Int)(ref delta)).x) >= Mathf.Abs(((Vector2Int)(ref delta)).y))
		{
			if (((Vector2Int)(ref delta)).x > 0)
			{
				return (Direction4)2;
			}
			return (Direction4)0;
		}
		if (((Vector2Int)(ref delta)).y > 0)
		{
			return (Direction4)1;
		}
		return (Direction4)3;
	}

	private static bool CanPlace(CursorHitChecker hit, Vector2Int address)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		ChildGrid childGridByGlobalAddress = hit.GetChildGridByGlobalAddress(address);
		if (childGridByGlobalAddress == null)
		{
			return false;
		}
		if (!childGridByGlobalAddress.IsOwn)
		{
			return false;
		}
		if (childGridByGlobalAddress.IsOccupied)
		{
			return false;
		}
		return true;
	}

	private static string BlockReason(CursorHitChecker hit, Vector2Int address)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		ChildGrid childGridByGlobalAddress = hit.GetChildGridByGlobalAddress(address);
		if (childGridByGlobalAddress == null)
		{
			return "HitGridNotOwn";
		}
		if (!childGridByGlobalAddress.IsOwn)
		{
			return "HitGridNotOwn";
		}
		return "HitGridOccupied";
	}

	private static UniTask<FamObject> Summon(SummonStrategyDistributor distributor, PutDirection putDirection, CursorHitChecker hit, Direction4 facing)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		putDirection.SetTemporaryOverride(facing);
		try
		{
			return distributor.CallStrategyWithCheckAsync(hit, 1, false);
		}
		finally
		{
			putDirection.ClearTemporaryOverride();
		}
	}

	private static void UseOneCatalyst(InventoryIndex index)
	{
		InventoryManager playerInventory = InventoryManager.playerInventory;
		if (playerInventory != null)
		{
			InventoryWithdrawer withdrawer = playerInventory.GetWithdrawer();
			if (withdrawer != null)
			{
				withdrawer.WithdrawSingleBox(1, index.GetCurrentSelectedID());
			}
		}
	}

	private static void Skip(string messageKey)
	{
		if (messageKey != null)
		{
			float unscaledTime = Time.unscaledTime;
			if (!(messageKey == _lastSkipKey) || !(unscaledTime - _lastSkipTime < 1.5f))
			{
				_lastSkipKey = messageKey;
				_lastSkipTime = unscaledTime;
				Tell(messageKey);
			}
		}
	}

	private static void Block(string messageKey)
	{
		_blocked = true;
		Tell(messageKey);
	}

	private static void Tell(string messageKey)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		if (messageKey != null)
		{
			MessageSpawner instance = MessageSpawner.Instance;
			if (!((Object)(object)instance == (Object)null))
			{
				UniTaskExtensions.Forget(instance.SpawnFailed(messageKey));
			}
		}
	}
}
internal static class StockView
{
	private struct Row
	{
		public string ItemID;

		public int Count;
	}

	private sealed class OverlayEntry
	{
		public Transform Anchor;

		public readonly List<Row> Rows = new List<Row>();

		public int HiddenKinds;
	}

	private const int MaxRows = 8;

	private const int MaxOverlayRows = 4;

	private const float OverlayScanInterval = 0.25f;

	private static readonly List<OverlayEntry> OverlayEntries = new List<OverlayEntry>();

	private static float _nextOverlayScan = float.NegativeInfinity;

	private static readonly List<Rect> UiBlockers = new List<Rect>();

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

	private static GUIStyle _overlayStyle;

	private static bool _overlayOn;

	private static readonly List<Row> Rows = new List<Row>();

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

	private static Vector3 _anchorWorld;

	private static bool _hasTarget;

	private static int _hiddenKinds;

	private static bool _visible = true;

	private static bool _initialized;

	private static GUIStyle _countStyle;

	private static Texture2D _panelTexture;

	private static readonly GUIContent Content = new GUIContent();

	private static readonly Color PanelColor = new Color(0.06f, 0.05f, 0.08f, 0.86f);

	private static readonly Color EdgeColor = new Color(1f, 1f, 1f, 0.16f);

	private static readonly Color TextColor = new Color(1f, 0.97f, 0.9f, 1f);

	private static readonly Color ShadowColor = new Color(0f, 0f, 0f, 0.9f);

	internal static bool MapOverlayOn
	{
		get
		{
			return _overlayOn;
		}
		set
		{
			if (_overlayOn != value)
			{
				_overlayOn = value;
				RavenQolPlugin.Log.LogInfo((object)("[stock] map-view stock overlay " + (value ? "on" : "off")));
			}
		}
	}

	internal static void Update()
	{
		if (!_initialized)
		{
			_overlayOn = RavenQolPlugin.StockMapOverlay.Value;
			_initialized = true;
		}
		_visible = RavenQolPlugin.StockVisible.Value;
		_hasTarget = false;
		Rows.Clear();
		_hiddenKinds = 0;
		if (!_visible)
		{
			OverlayEntries.Clear();
			return;
		}
		if (HudTweaks.IsMapViewActive() && _overlayOn)
		{
			ScanOverlay();
		}
		else
		{
			OverlayEntries.Clear();
		}
		Scan();
	}

	private static void ScanOverlay()
	{
		//IL_00d3: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
		float unscaledTime = Time.unscaledTime;
		if (unscaledTime < _nextOverlayScan)
		{
			return;
		}
		_nextOverlayScan = unscaledTime + 0.25f;
		OverlayEntries.Clear();
		RefreshUiBlockers();
		CursorHitChecker val = Chain.CurrentCursorHitChecker();
		if (val == null || (Object)(object)val.GridManager == (Object)null)
		{
			return;
		}
		MapObjectDictionary mapObjectDictionary = val.GridManager.GetMapObjectDictionary();
		if (mapObjectDictionary == null)
		{
			return;
		}
		Camera val2 = CurrentCamera();
		if ((Object)(object)val2 == (Object)null)
		{
			return;
		}
		foreach (KeyValuePair<Vector2Int, ConnectableObject> item2 in mapObjectDictionary.ConnectableDic)
		{
			ConnectableObject value = item2.Value;
			if (value == null || !Object.op_Implicit((Object)(object)((MapObject)value).pivot))
			{
				continue;
			}
			TransporterExitObject val3 = (TransporterExitObject)(object)((value is TransporterExitObject) ? value : null);
			TransporterObject val4 = (TransporterObject)(object)((val3 == null) ? ((value is TransporterObject) ? value : null) : null);
			if (val3 == null && val4 == null)
			{
				continue;
			}
			Transform transform = ((MapObject)value).pivot.transform;
			Vector3 val5 = val2.WorldToScreenPoint(transform.position);
			if (val5.z <= 0f || val5.x < -80f || val5.x > (float)Screen.width + 80f || val5.y < -80f || val5.y > (float)Screen.height + 80f)
			{
				continue;
			}
			Totals.Clear();
			if (val3 != null)
			{
				Gather(((FamObject)val3).GetInventory());
			}
			else
			{
				Gather(((FamObject)val4).GetInventory());
				Gather(val4.GetDeliveryInventory());
			}
			int num = 0;
			foreach (KeyValuePair<string, int> total in Totals)
			{
				num += total.Value;
			}
			if (num < 1)
			{
				continue;
			}
			OverlayEntry overlayEntry = new OverlayEntry();
			overlayEntry.Anchor = transform;
			foreach (KeyValuePair<string, int> total2 in Totals)
			{
				Row item = new Row
				{
					ItemID = total2.Key,
					Count = total2.Value
				};
				overlayEntry.Rows.Add(item);
			}
			overlayEntry.Rows.Sort(CompareByCountDescending);
			if (overlayEntry.Rows.Count > 4)
			{
				overlayEntry.HiddenKinds = overlayEntry.Rows.Count - 4;
				overlayEntry.Rows.RemoveRange(4, overlayEntry.HiddenKinds);
			}
			OverlayEntries.Add(overlayEntry);
		}
	}

	private static void Scan()
	{
		//IL_002e: 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_014a: Unknown result type (might be due to invalid IL or missing references)
		if (HudTweaks.IsMapViewActive())
		{
			if (PointerOverFinder.IsPointerOverUI)
			{
				return;
			}
		}
		else if (!Chain.IsMapInteractive())
		{
			return;
		}
		CursorHitChecker val = Chain.CurrentCursorHitChecker();
		if (val == null)
		{
			return;
		}
		ChildGrid hitChildGrid = val.HitChildGrid;
		if (hitChildGrid == null)
		{
			return;
		}
		MapObject adjustedMapObject = val.GetAdjustedMapObject(hitChildGrid.GlobalAddress);
		TransporterExitObject val2 = (TransporterExitObject)(object)((adjustedMapObject is TransporterExitObject) ? adjustedMapObject : null);
		TransporterObject val3 = (TransporterObject)(object)((val2 == null) ? ((adjustedMapObject is TransporterObject) ? adjustedMapObject : null) : null);
		if ((val2 == null && val3 == null) || !Object.op_Implicit((Object)(object)adjustedMapObject.pivot))
		{
			return;
		}
		Totals.Clear();
		if (val2 != null)
		{
			Gather(((FamObject)val2).GetInventory());
		}
		else
		{
			Gather(((FamObject)val3).GetInventory());
			Gather(val3.GetDeliveryInventory());
		}
		foreach (KeyValuePair<string, int> total in Totals)
		{
			Row item = new Row
			{
				ItemID = total.Key,
				Count = total.Value
			};
			Rows.Add(item);
		}
		Rows.Sort(CompareByCountDescending);
		if (Rows.Count > 8)
		{
			_hiddenKinds = Rows.Count - 8;
			Rows.RemoveRange(8, _hiddenKinds);
		}
		_anchorWorld = adjustedMapObject.pivot.transform.position;
		_hasTarget = true;
	}

	private static int CompareByCountDescending(Row a, Row b)
	{
		if (a.Count != b.Count)
		{
			return b.Count.CompareTo(a.Count);
		}
		return string.CompareOrdinal(a.ItemID, b.ItemID);
	}

	private static void Gather(InventoryManager inventory)
	{
		if (inventory == null)
		{
			return;
		}
		InventoryDB dB = inventory.GetDB();
		if (dB == null)
		{
			return;
		}
		foreach (KeyValuePair<int, ItemCount> storagedItem in dB.StoragedItems)
		{
			ItemCount value = storagedItem.Value;
			if (!(value == (ItemCount)null) && ((ValueCount)value).Count > 0)
			{
				string itemID = value.ItemID;
				if (!string.IsNullOrEmpty(itemID) && !(itemID == "None"))
				{
					Totals[itemID] = (Totals.TryGetValue(itemID, out var value2) ? value2 : 0) + ((ValueCount)value).Count;
				}
			}
		}
	}

	internal static void Draw()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Invalid comparison between Unknown and I4
		//IL_0041: 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_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: 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_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_028a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_0300: Unknown result type (might be due to invalid IL or missing references)
		//IL_031b: Unknown result type (might be due to invalid IL or missing references)
		if (!_visible || (int)Event.current.type != 7)
		{
			return;
		}
		if (OverlayEntries.Count > 0)
		{
			DrawOverlay();
		}
		if (!_hasTarget)
		{
			return;
		}
		Camera val = CurrentCamera();
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Vector3 val2 = val.WorldToScreenPoint(_anchorWorld);
		if (val2.z <= 0f)
		{
			return;
		}
		EnsureResources();
		float num = Mathf.Clamp((float)Screen.height * 0.026f, 16f, 40f);
		float num2 = Mathf.Round(num * 0.25f);
		float num3 = Mathf.Round(num * 0.3f);
		float num4 = num;
		float num5 = 0f;
		for (int i = 0; i < Rows.Count; i++)
		{
			GUIContent content = Content;
			int count = Rows[i].Count;
			content.text = count.ToString();
			num5 = Mathf.Max(num5, _countStyle.CalcSize(Content).x);
		}
		if (_hiddenKinds > 0)
		{
			Content.text = "+" + _hiddenKinds;
			num5 = Mathf.Max(num5, _countStyle.CalcSize(Content).x);
		}
		int num6 = Rows.Count + ((_hiddenKinds > 0) ? 1 : 0);
		if (num6 > 0)
		{
			float num7 = num3 * 2f + num + num2 + num5;
			float num8 = num3 * 2f + num4 * (float)num6;
			float num9 = val2.x - num7 * 0.5f;
			float num10 = (float)Screen.height - val2.y - num8 - (float)Screen.height * 0.035f;
			num9 = Mathf.Clamp(num9, 4f, Mathf.Max(4f, (float)Screen.width - num7 - 4f));
			num10 = Mathf.Clamp(num10, 4f, Mathf.Max(4f, (float)Screen.height - num8 - 4f));
			Rect panel = default(Rect);
			((Rect)(ref panel))..ctor(Mathf.Round(num9), Mathf.Round(num10), Mathf.Round(num7), Mathf.Round(num8));
			DrawPanel(panel);
			float num11 = ((Rect)(ref panel)).y + num3;
			Rect rect = default(Rect);
			Rect val3 = default(Rect);
			for (int j = 0; j < Rows.Count; j++)
			{
				((Rect)(ref rect))..ctor(((Rect)(ref panel)).x + num3, num11, num, num);
				DrawSprite(rect, ItemParamGetter.GetSprite(Rows[j].ItemID), Color.white);
				((Rect)(ref val3))..ctor(((Rect)(ref rect)).xMax + num2, num11, num5, num4);
				Rect rect2 = val3;
				GUIStyle countStyle = _countStyle;
				int count2 = Rows[j].Count;
				DrawShadowedText(rect2, countStyle, count2.ToString(), TextColor);
				num11 += num4;
			}
			if (_hiddenKinds > 0)
			{
				Rect rect3 = default(Rect);
				((Rect)(ref rect3))..ctor(((Rect)(ref panel)).x + num3, num11, ((Rect)(ref panel)).width - num3 * 2f, num4);
				DrawShadowedText(rect3, _countStyle, "+" + _hiddenKinds, TextColor);
			}
		}
	}

	private static void RefreshUiBlockers()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: 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_0187: Unknown result type (might be due to invalid IL or missing references)
		UiBlockers.Clear();
		Canvas val = HudTweaks.MainCanvas();
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Camera val2 = (((int)val.renderMode != 0) ? val.worldCamera : null);
		Graphic[] componentsInChildren = ((Component)val).GetComponentsInChildren<Graphic>(false);
		foreach (Graphic val3 in componentsInChildren)
		{
			if ((Object)(object)val3 == (Object)null || !((Behaviour)val3).enabled || (Object)(object)val3.canvasRenderer == (Object)null || val3.canvasRenderer.GetInheritedAlpha() < 0.05f || val3.color.a < 0.05f)
			{
				continue;
			}
			RectTransform rectTransform = val3.rectTransform;
			rectTransform.GetWorldCorners(CornerBuffer);
			float num = float.MaxValue;
			float num2 = float.MaxValue;
			float num3 = float.MinValue;
			float num4 = float.MinValue;
			for (int j = 0; j < 4; j++)
			{
				Vector2 val4 = RectTransformUtility.WorldToScreenPoint(val2, CornerBuffer[j]);
				num = Mathf.Min(num, val4.x);
				num3 = Mathf.Max(num3, val4.x);
				num2 = Mathf.Min(num2, val4.y);
				num4 = Mathf.Max(num4, val4.y);
			}
			if (!(num3 - num <= 1f) && !(num4 - num2 <= 1f))
			{
				float num5 = (num3 - num) * (num4 - num2);
				if (!(num5 > (float)Screen.width * (float)Screen.height * 0.2f))
				{
					UiBlockers.Add(new Rect(num, (float)Screen.height - num4, num3 - num, num4 - num2));
				}
			}
		}
	}

	private static bool IsCoveredByUi(Rect rect)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < UiBlockers.Count; i++)
		{
			if (((Rect)(ref rect)).Overlaps(UiBlockers[i]))
			{
				return true;
			}
		}
		return false;
	}

	private static void DrawOverlay()
	{
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: 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_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0305: Unknown result type (might be due to invalid IL or missing references)
		//IL_0325: Unknown result type (might be due to invalid IL or missing references)
		Camera val = CurrentCamera();
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		EnsureResources();
		float num = Mathf.Clamp((float)Screen.height * 0.02f, 12f, 30f);
		float num2 = Mathf.Round(num * 0.22f);
		float num3 = Mathf.Round(num * 0.22f);
		Rect val3 = default(Rect);
		for (int i = 0; i < OverlayEntries.Count; i++)
		{
			OverlayEntry overlayEntry = OverlayEntries[i];
			if ((Object)(object)overlayEntry.Anchor == (Object)null || !Object.op_Implicit((Object)(object)overlayEntry.Anchor) || overlayEntry.Rows.Count == 0)
			{
				continue;
			}
			Vector3 val2 = val.WorldToScreenPoint(overlayEntry.Anchor.position);
			if (val2.z <= 0f)
			{
				continue;
			}
			float num4 = 0f;
			for (int j = 0; j < overlayEntry.Rows.Count; j++)
			{
				GUIContent content = Content;
				int count = overlayEntry.Rows[j].Count;
				content.text = count.ToString();
				num4 = Mathf.Max(num4, _overlayStyle.CalcSize(Content).x);
			}
			if (overlayEntry.HiddenKinds > 0)
			{
				Content.text = "+" + overlayEntry.HiddenKinds;
				num4 = Mathf.Max(num4, _overlayStyle.CalcSize(Content).x);
			}
			int num5 = overlayEntry.Rows.Count + ((overlayEntry.HiddenKinds > 0) ? 1 : 0);
			float num6 = Mathf.Round(num3 * 2f + num + num2 + num4);
			float num7 = Mathf.Round(num3 * 2f + num * (float)num5);
			float num8 = Mathf.Round(val2.x - num6 * 0.5f);
			float num9 = Mathf.Round((float)Screen.height - val2.y - num7 - (float)Screen.height * 0.012f);
			if (num8 < 0f - num6 || num8 > (float)Screen.width || num9 < 0f - num7 || num9 > (float)Screen.height)
			{
				continue;
			}
			((Rect)(ref val3))..ctor(num8, num9, num6, num7);
			if (!IsCoveredByUi(val3))
			{
				DrawPanel(val3);
				float num10 = ((Rect)(ref val3)).y + num3;
				for (int k = 0; k < overlayEntry.Rows.Count; k++)
				{
					DrawSprite(new Rect(((Rect)(ref val3)).x + num3, num10, num, num), ItemParamGetter.GetSprite(overlayEntry.Rows[k].ItemID), Color.white);
					Rect rect = new Rect(((Rect)(ref val3)).x + num3 + num + num2, num10, num4, num);
					GUIStyle overlayStyle = _overlayStyle;
					int count2 = overlayEntry.Rows[k].Count;
					DrawShadowedText(rect, overlayStyle, count2.ToString(), TextColor);
					num10 += num;
				}
				if (overlayEntry.HiddenKinds > 0)
				{
					DrawShadowedText(new Rect(((Rect)(ref val3)).x + num3, num10, ((Rect)(ref val3)).width - num3 * 2f, num), _overlayStyle, "+" + overlayEntry.HiddenKinds, TextColor);
				}
			}
		}
	}

	private static void DrawPanel(Rect panel)
	{
		//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_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: 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_003f: 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_0097: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
		Color color = GUI.color;
		GUI.color = PanelColor;
		GUI.DrawTexture(panel, (Texture)(object)_panelTexture);
		GUI.color = EdgeColor;
		GUI.DrawTexture(new Rect(((Rect)(ref panel)).x, ((Rect)(ref panel)).y, ((Rect)(ref panel)).width, 1f), (Texture)(object)_panelTexture);
		GUI.DrawTexture(new Rect(((Rect)(ref panel)).x, ((Rect)(ref panel)).yMax - 1f, ((Rect)(ref panel)).width, 1f), (Texture)(object)_panelTexture);
		GUI.DrawTexture(new Rect(((Rect)(ref panel)).x, ((Rect)(ref panel)).y, 1f, ((Rect)(ref panel)).height), (Texture)(object)_panelTexture);
		GUI.DrawTexture(new Rect(((Rect)(ref panel)).xMax - 1f, ((Rect)(ref panel)).y, 1f, ((Rect)(ref panel)).height), (Texture)(object)_panelTexture);
		GUI.color = color;
	}

	private static void DrawShadowedText(Rect rect, GUIStyle style, string text, Color color)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: 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_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		Content.text = text;
		Color color2 = GUI.color;
		GUI.color = ShadowColor;
		style.Draw(new Rect(((Rect)(ref rect)).x + 1f, ((Rect)(ref rect)).y + 1f, ((Rect)(ref rect)).width, ((Rect)(ref rect)).height), Content, false, false, false, false);
		GUI.color = color;
		style.Draw(rect, Content, false, false, false, false);
		GUI.color = color2;
	}

	private static void DrawSprite(Rect rect, Sprite sprite, Color tint)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: 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_006c: 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_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: 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_013d: 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_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)
		if ((Object)(object)sprite == (Object)null || (Object)(object)sprite.texture == (Object)null)
		{
			return;
		}
		Rect textureRect = sprite.textureRect;
		float num = ((Texture)sprite.texture).width;
		float num2 = ((Texture)sprite.texture).height;
		if (!(num <= 0f) && !(num2 <= 0f) && !(((Rect)(ref textureRect)).width <= 0f) && !(((Rect)(ref textureRect)).height <= 0f))
		{
			Rect rect2 = sprite.rect;
			Rect val = rect;
			if (((Rect)(ref rect2)).width > 0.5f && ((Rect)(ref rect2)).height > 0.5f)
			{
				float num3 = ((Rect)(ref rect)).width / ((Rect)(ref rect2)).width;
				float num4 = ((Rect)(ref rect)).height / ((Rect)(ref rect2)).height;
				Vector2 textureRectOffset = sprite.textureRectOffset;
				((Rect)(ref val))..ctor(((Rect)(ref rect)).x + textureRectOffset.x * num3, ((Rect)(ref rect)).yMax - (textureRectOffset.y + ((Rect)(ref textureRect)).height) * num4, ((Rect)(ref textureRect)).width * num3, ((Rect)(ref textureRect)).height * num4);
			}
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(((Rect)(ref textureRect)).x / num, ((Rect)(ref textureRect)).y / num2, ((Rect)(ref textureRect)).width / num, ((Rect)(ref textureRect)).height / num2);
			Color color = GUI.color;
			GUI.color = tint;
			GUI.DrawTextureWithTexCoords(val, (Texture)(object)sprite.texture, val2, true);
			GUI.color = color;
		}
	}

	private static void EnsureResources()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		//IL_0022: 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_0078: Expected O, but got Unknown
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Expected O, but got Unknown
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Expected O, but got Unknown
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Expected O, but got Unknown
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Expected O, but got Unknown
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Expected O, but got Unknown
		if ((Object)(object)_panelTexture == (Object)null)
		{
			_panelTexture = new Texture2D(1, 1, (TextureFormat)4, false);
			_panelTexture.SetPixel(0, 0, Color.white);
			_panelTexture.Apply();
			((Object)_panelTexture).hideFlags = (HideFlags)61;
		}
		int num = Mathf.Clamp(Mathf.RoundToInt((float)Screen.height * 0.019f), 11, 30);
		if (_countStyle == null)
		{
			_countStyle = new GUIStyle(GUI.skin.label);
			_countStyle.alignment = (TextAnchor)3;
			_countStyle.fontStyle = (FontStyle)1;
			_countStyle.wordWrap = false;
			_countStyle.clipping = (TextClipping)0;
			_countStyle.normal.textColor = Color.white;
			_countStyle.padding = new RectOffset(0, 0, 0, 0);
			_countStyle.margin = new RectOffset(0, 0, 0, 0);
		}
		if (_countStyle.fontSize != num)
		{
			_countStyle.fontSize = num;
		}
		int num2 = Mathf.Clamp(Mathf.RoundToInt((float)Screen.height * 0.015f), 9, 22);
		if (_overlayStyle == null)
		{
			_overlayStyle = new GUIStyle(GUI.skin.label);
			_overlayStyle.alignment = (TextAnchor)3;
			_overlayStyle.fontStyle = (FontStyle)1;
			_overlayStyle.wordWrap = false;
			_overlayStyle.clipping = (TextClipping)0;
			_overlayStyle.normal.textColor = Color.white;
			_overlayStyle.padding = new RectOffset(0, 0, 0, 0);
			_overlayStyle.margin = new RectOffset(0, 0, 0, 0);
		}
		if (_overlayStyle.fontSize != num2)
		{
			_overlayStyle.fontSize = num2;
		}
	}

	private static Camera CurrentCamera()
	{
		CameraManager instance = CameraManager.Instance;
		if ((Object)(object)instance == (Object)null)
		{
			return null;
		}
		return instance.ActiveCamera;
	}
}
internal static class HudTweaks
{
	private const string StockLabelKey = "StatsColumnStock";

	private const float DropRefreshInterval = 0.25f;

	private const float LookupInterval = 1f;

	private static readonly string[] ManualFieldNames = new string[12]
	{
		"_tmpEquipName", "_famPatronInfo", "_descInfo", "_manualNull", "_manualVacuum", "_manualSummonCrafter", "_manualSummonConveyor", "_manualSummonTransporter", "_manualSummonWorker", "_manualWandSkill",
		"_manualCommonAction", "_manualCommonMovement"
	};

	private static FieldInfo _fDropMomokoUI;

	private static bool _ready;

	private static BirdsEyeCameraManagerMono _birdsEye;

	private static ManualUIManager _manual;

	private static readonly List<GameObject> ManualTargets = new List<GameObject>();

	private static bool _wasMapView;

	private static bool _wasEnabled = true;

	private static bool _manualHidden;

	private static GameObject _movedDropUI;

	private static GameObject _wiredDropUI;

	private static GameObject _patronsPanel;

	private static GameObject _stockButton;

	private static TextMeshProUGUI _stockButtonText;

	private static CanvasGroup _stockButtonGroup;

	private static GameObject _mineButton;

	private static TextMeshProUGUI _mineButtonText;

	private static CanvasGroup _mineButtonGroup;

	private static bool _minePointsVisible = true;

	private static bool _mineInitialized;

	private static GameObject _leftStack;

	private static bool _leftStackMoved;

	private static Vector3 _leftStackSavedPos;

	private static readonly List<Image> MineIcons = new List<Image>();

	private static bool _mineIconsResolved;

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

	private static float _nextSpriteProbe = float.NegativeInfinity;

	private static string _stockLabel;

	private static float _nextLabelFetch = float.NegativeInfinity;

	private static float _nextDropRefresh;

	private static float _nextLookup = float.NegativeInfinity;

	internal static void Init()
	{
		_fDropMomokoUI = typeof(BirdsEyeCameraManagerMono).GetField("_dropMomokoUI", BindingFlags.Instance | BindingFlags.NonPublic);
		_ready = _fDropMomokoUI != null;
		if (!_ready)
		{
			RavenQolPlugin.Log.LogWarning((object)"[hud] _dropMomokoUI not found; redeploy relocation disabled.");
		}
	}

	internal static Canvas MainCanvas()
	{
		if ((Object)(object)_manual != (Object)null && Object.op_Implicit((Object)(object)_manual))
		{
			return ((Component)_manual).GetComponentInParent<Canvas>();
		}
		return null;
	}

	internal static bool IsMapViewActive()
	{
		if ((Object)(object)_birdsEye == (Object)null || !Object.op_Implicit((Object)(object)_birdsEye))
		{
			return false;
		}
		if (!((Component)_birdsEye).gameObject.activeInHierarchy)
		{
			return false;
		}
		return _birdsEye.IsOnBirdsEyeView();
	}

	internal static void Update()
	{
		if (!RavenQolPlugin.MapEnabled.Value)
		{
			if (_wasEnabled)
			{
				RestoreOnUnload();
				_wasMapView = false;
			}
			_wasEnabled = false;
			return;
		}
		_wasEnabled = true;
		EnsureInstances();
		bool flag = IsMapViewActive();
		if (flag != _wasMapView)
		{
			_wasMapView = flag;
			if (flag)
			{
				if (RavenQolPlugin.MapHideManual.Value)
				{
					SetManualVisible(visible: false);
				}
				SetPatronsVisible(visible: false);
				if (!_mineInitialized)
				{
					_minePointsVisible = true;
					_mineInitialized = true;
				}
				SetLeftStackVisible(_minePointsVisible);
				_nextDropRefresh = float.NegativeInfinity;
			}
			else
			{
				SetManualVisible(visible: true);
				SetPatronsVisible(visible: true);
				RestoreLeftStackPlacement();
				SetLeftStackVisible(visible: true);
				HideMapButtons();
			}
		}
		if (!flag)
		{
			HideMapButtons();
		}
		if (!flag)
		{
			return;
		}
		float unscaledTime = Time.unscaledTime;
		if (unscaledTime >= _nextDropRefresh)
		{
			_nextDropRefresh = unscaledTime + 0.25f;
			MoveDropUI();
			if ((Object)(object)_birdsEye != (Object)null && Object.op_Implicit((Object)(object)_birdsEye))
			{
				_birdsEye.RefreshDropMomokoView();
			}
			UpdateMapButtons();
		}
	}

	private static void EnsureInstances()
	{
		if ((Object)(object)_birdsEye != (Object)null && Object.op_Implicit((Object)(object)_birdsEye) && (Object)(object)_manual != (Object)null && Object.op_Implicit((Object)(object)_manual))
		{
			return;
		}
		float unscaledTime = Time.unscaledTime;
		if (unscaledTime < _nextLookup)
		{
			return;
		}
		_nextLookup = unscaledTime + 1f;
		if ((Object)(object)_birdsEye == (Object)null || !Object.op_Implicit((Object)(object)_birdsEye))
		{
			_birdsEye = Object.FindAnyObjectByType<BirdsEyeCameraManagerMono>((FindObjectsInactive)1);
			_movedDropUI = null;
		}
		if (!((Object)(object)_manual == (Object)null) && Object.op_Implicit((Object)(object)_manual))
		{
			return;
		}
		ManualUIManager val = null;
		ManualUIManager[] array = Object.FindObjectsByType<ManualUIManager>((FindObjectsInactive)1, (FindObjectsSortMode)0);
		FieldInfo field = typeof(ManualUIManager).GetField("_manualCommonAction", BindingFlags.Instance | BindingFlags.NonPublic);
		for (int i = 0; i < array.Length; i++)
		{
			if (field == null)
			{
				val = array[i];
				break;
			}
			object? value = field.GetValue(array[i]);
			Component val2 = (Component)((value is Component) ? value : null);
			if ((Object)(object)val2 != (Object)null && Object.op_Implicit((Object)(object)val2))
			{
				val = array[i];
				break;
			}
		}
		if ((Object)(object)val != (Object)(object)_manual)
		{
			_manual = val;
			_manualHidden = false;
			CollectManualTargets();
			if (!IsMapViewActive())
			{
				SetManualVisible(visible: true);
			}
		}
	}

	private static void CollectManualTargets()
	{
		ManualTargets.Clear();
		if ((Object)(object)_manual == (Object)null)
		{
			return;
		}
		Transform transform = ((Component)_manual).transform;
		ManualTargets.Add(((Component)transform).gameObject);
		BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
		for (int i = 0; i < ManualFieldNames.Length; i++)
		{
			FieldInfo field = typeof(ManualUIManager).GetField(ManualFieldNames[i], bindingAttr);
			if (!(field == null))
			{
				object? value = field.GetValue(_manual);
				Component val = (Component)((value is Component) ? value : null);
				if (!((Object)(object)val == (Object)null) && Object.op_Implicit((Object)(object)val) && !val.transform.IsChildOf(transform) && !ManualTargets.Contains(val.gameObject))
				{
					ManualTargets.Add(val.gameObject);
				}
			}
		}
	}

	private static void SetManualVisible(bool visible)
	{
		_manualHidden = !visible;
		for (int i = 0; i < ManualTargets.Count; i++)
		{
			GameObject val = ManualTargets[i];
			if ((Object)(object)val == (Object)null || !Object.op_Implicit((Object)(object)val))
			{
				continue;
			}
			CanvasGroup val2 = val.GetComponent<CanvasGroup>();
			if ((Object)(object)val2 == (Object)null)
			{
				if (visible)
				{
					continue;
				}
				val2 = val.AddComponent<CanvasGroup>();
			}
			val2.alpha = (visible ? 1f : 0f);
			val2.interactable = visible;
			val2.blocksRaycasts = visible;
		}
	}

	private static void SetPatronsVisible(bool visible)
	{
		if ((Object)(object)_patronsPanel == (Object)null || !Object.op_Implicit((Object)(object)_patronsPanel))
		{
			Canvas val = MainCanvas();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Transform val2 = FindChildRecursive(((Component)val).transform, "PatronsList");
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			_patronsPanel = ((Component)val2).gameObject;
		}
		CanvasGroup val3 = _patronsPanel.GetComponent<CanvasGroup>();
		if ((Object)(object)val3 == (Object)null)
		{
			if (visible)
			{
				return;
			}
			val3 = _patronsPanel.AddComponent<CanvasGroup>();
		}
		val3.alpha = (visible ? 1f : 0f);
		val3.interactable = visible;
		val3.blocksRaycasts = visible;
	}

	private static Transform FindChildRecursive(Transform root, string name)
	{
		if ((Object)(object)root == (Object)null)
		{
			return null;
		}
		if (((Object)root).name == name)
		{
			return root;
		}
		for (int i = 0; i < root.childCount; i++)
		{
			Transform val = FindChildRecursive(root.GetChild(i), name);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
		}
		return null;
	}

	internal static void RestoreOnUnload()
	{
		SetManualVisible(visible: true);
		SetPatronsVisible(visible: true);
		RestoreLeftStackPlacement();
		SetLeftStackVisible(visible: true);
		if ((Object)(object)_stockButton != (Object)null && Object.op_Implicit((Object)(object)_stockButton))
		{
			Object.Destroy((Object)(object)_stockButton);
		}
		if ((Object)(object)_mineButton != (Object)null && Object.op_Implicit((Object)(object)_mineButton))
		{
			Object.Destroy((Object)(object)_mineButton);
		}
		_stockButton = null;
		_mineButton = null;
	}

	private static void UpdateMapButtons()
	{
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Expected O, but got Unknown
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Expected O, but got Unknown
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: 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_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		if (!_ready || (Object)(object)_birdsEye == (Object)null || !Object.op_Implicit((Object)(object)_birdsEye))
		{
			return;
		}
		object? value = _fDropMomokoUI.GetValue(_birdsEye);
		GameObject val = (GameObject)((value is GameObject) ? value : null);
		if ((Object)(object)val == (Object)null || !Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		Transform transform = val.transform;
		RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
		if ((Object)(object)val2 == (Object)null)
		{
			return;
		}
		RefreshLabels();
		if ((Object)(object)_stockButton == (Object)null || !Object.op_Implicit((Object)(object)_stockButton))
		{
			_stockButton = CloneTagButton(val2, "RavenQolStockButton", "Summon-TransporterExit", new UnityAction(OnStockButtonClicked), out _stockButtonText, out _stockButtonGroup);
		}
		if ((Object)(object)_mineButton == (Object)null || !Object.op_Implicit((Object)(object)_mineButton))
		{
			_mineButton = CloneTagButton(val2, "RavenQolMineButton", null, new UnityAction(OnMineButtonClicked), out _mineButtonText, out _mineButtonGroup);
			SetupMineButtonIcons(_mineButton);
		}
		if (!((Object)(object)_stockButton == (Object)null) && !((Object)(object)_mineButton == (Object)null))
		{
			_stockButton.SetActive(true);
			_mineButton.SetActive(true);
			Transform transform2 = _stockButton.transform;
			RectTransform val3 = (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null);
			Transform transform3 = _mineButton.transform;
			RectTransform val4 = (RectTransform)(object)((transform3 is RectTransform) ? transform3 : null);
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			val2.GetWorldCorners(array);
			float num = (array[1].y - array[0].y) * 0.15f;
			Vector3[] array2 = (Vector3[])(object)new Vector3[4];
			val3.GetWorldCorners(array2);
			((Transform)val3).position = ((Transform)val3).position + new Vector3(array[0].x - array2[0].x, array[0].y - num - array2[1].y, 0f);
			val3.GetWorldCorners(array2);
			Vector3[] array3 = (Vector3[])(object)new Vector3[4];
			val4.GetWorldCorners(array3);
			((Transform)val4).position = ((Transform)val4).position + new Vector3(array2[0].x - array3[0].x, array2[0].y - num - array3[1].y, 0f);
			if ((Object)(object)_stockButtonText != (Object)null && ((TMP_Text)_stockButtonText).text != _stockLabel)
			{
				((TMP_Text)_stockButtonText).SetText(_stockLabel);
			}
			if ((Object)(object)_mineButtonText != (Object)null && ((TMP_Text)_mineButtonText).text.Length != 0)
			{
				((TMP_Text)_mineButtonText).SetText("");
			}
			if (!_mineIconsResolved)
			{
				ApplyMineIcons();
			}
			CenterMineIcons();
			ApplyButtonStates();
			val4.GetWorldCorners(array3);
			PlaceLeftStackBelow(array3[0].y - num * 2f + PatronsSpaceHeight());
		}
	}

	private static float PatronsSpaceHeight()
	{
		if ((Object)(object)_patronsPanel == (Object)null || !Object.op_Implicit((Object)(object)_patronsPanel))
		{
			return 0f;
		}
		if (!_patronsPanel.activeInHierarchy)
		{
			return 0f;
		}
		Transform transform = _patronsPanel.transform;
		RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
		if ((Object)(object)val == (Object)null)
		{
			return 0f;
		}
		Vector3[] array = (Vector3[])(object)new Vector3[4];
		val.GetWorldCorners(array);
		return Mathf.Max(0f, array[1].y - array[0].y);
	}

	private static void PlaceLeftStackBelow(float worldTopY)
	{
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		if (!EnsureLeftStack())
		{
			return;
		}
		Transform transform = _leftStack.transform;
		RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
		if (!((Object)(object)val == (Object)null))
		{
			LayoutElement val2 = _leftStack.GetComponent<LayoutElement>();
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = _leftStack.AddComponent<LayoutElement>();
			}
			if (!_leftStackMoved)
			{
				_leftStackSavedPos = val.anchoredPosition3D;
				_leftStackMoved = true;
			}
			val2.ignoreLayout = true;
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			val.GetWorldCorners(array);
			((Transform)val).position = ((Transform)val).position + new Vector3(0f, worldTopY - array[1].y, 0f);
		}
	}

	private static void RestoreLeftStackPlacement()
	{
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		if (!_leftStackMoved)
		{
			return;
		}
		_leftStackMoved = false;
		if ((Object)(object)_leftStack == (Object)null || !Object.op_Implicit((Object)(object)_leftStack))
		{
			return;
		}
		Transform transform = _leftStack.transform;
		RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
		LayoutElement component = _leftStack.GetComponent<LayoutElement>();
		if ((Object)(object)component != (Object)null)
		{
			component.ignoreLayout = false;
		}
		if ((Object)(object)val != (Object)null)
		{
			val.anchoredPosition3D = _leftStackSavedPos;
			Transform parent = ((Transform)val).parent;
			RectTransform val2 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			if ((Object)(object)val2 != (Object)null)
			{
				LayoutRebuilder.MarkLayoutForRebuild(val2);
			}
		}
	}

	private static GameObject CloneTagButton(RectTransform dropRect, string name, string iconItemID, UnityAction onClick, out TextMeshProUGUI text, out CanvasGroup group)
	{
		text = null;
		group = null;
		Transform val = ((Transform)dropRect).parent.Find(name);
		while ((Object)(object)val != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)((Component)val).gameObject);
			val = ((Transform)dropRect).parent.Find(name);
		}
		GameObject val2 = Object.Instantiate<GameObject>(((Component)dropRect).gameObject, ((Transform)dropRect).parent);
		((Object)val2).name = name;
		LocalizeStringEvent[] componentsInChildren = val2.GetComponentsInChildren<LocalizeStringEvent>(true);
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			((Behaviour)componentsInChildren[i]).enabled = false;
		}
		text = val2.GetComponentInChildren<TextMeshProUGUI>(true);
		Component[] components = val2.GetComponents<Component>();
		for (int j = 0; j < components.Length; j++)
		{
			if ((Object)(object)components[j] != (Object)null && ((object)components[j]).GetType().Name == "CursorProximityCanvasGroupFader")
			{
				Object.Destroy((Object)(object)components[j]);
			}
		}
		Transform val3 = val2.transform.Find("icon");
		if ((Object)(object)val3 != (Object)null && iconItemID != null)
		{
			Image component = ((Component)val3).GetComponent<Image>();
			if ((Object)(object)component != (Object)null)
			{
				component.sprite = ItemParamGetter.GetSprite(iconItemID);
				component.preserveAspect = true;
			}
		}
		Button val4 = val2.GetComponent<Button>();
		if ((Object)(object)val4 == (Object)null)
		{
			val4 = val2.AddComponent<Button>();
		}
		Image componentInChildren = val2.GetComponentInChildren<Image>(true);
		if ((Object)(object)componentInChildren != (Object)null)
		{
			((Selectable)val4).targetGraphic = (Graphic)(object)componentInChildren;
		}
		((UnityEvent)val4.onClick).AddListener(onClick);
		group = val2.GetComponent<CanvasGroup>();
		if ((Object)(object)group == (Object)null)
		{
			group = val2.AddComponent<CanvasGroup>();
		}
		group.interactable = true;
		group.blocksRaycasts = true;
		val2.SetActive(true);
		RavenQolPlugin.Log.LogInfo((object)("[hud] built " + name + " from the redeploy tag"));
		return val2;
	}

	private static void SetupMineButtonIcons(GameObject button)
	{
		//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_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		MineIcons.Clear();
		_mineIconsResolved = false;
		if ((Object)(object)button == (Object)null)
		{
			return;
		}
		Transform val = button.transform.Find("icon");
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Image component = ((Component)val).GetComponent<Image>();
		if (!((Object)(object)component == (Object)null))
		{
			RectTransform val2 = (RectTransform)(object)((val is RectTransform) ? val : null);
			Rect rect = val2.rect;
			float num = ((Rect)(ref rect)).width * 1.15f;
			MineIcons.Add(component);
			for (int i = 1; i < 3; i++)
			{
				GameObject val3 = Object.Instantiate<GameObject>(((Component)val).gameObject, val.parent);
				((Object)val3).name = "icon" + i;
				Transform transform = val3.transform;
				RectTransform val4 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				val4.anchoredPosition = val2.anchoredPosition + new Vector2(num * (float)i, 0f);
				MineIcons.Add(val3.GetComponent<Image>());
			}
			ApplyMineIcons();
		}
	}

	private static void CenterMineIcons()
	{
		//IL_011b: 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 (MineIcons.Count < 3 || (Object)(object)_mineButton == (Object)null || !Object.op_Implicit((Object)(object)_mineButton))
		{
			return;
		}
		Transform transform = _mineButton.transform;
		RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Vector3[] array = (Vector3[])(object)new Vector3[4];
		val.GetWorldCorners(array);
		float num = (array[0].x + array[3].x) * 0.5f;
		float num2 = float.MaxValue;
		float num3 = float.MinValue;
		for (int i = 0; i < 3; i++)
		{
			Image val2 = MineIcons[i];
			if ((Object)(object)val2 == (Object)null || !Object.op_Implicit((Object)(object)val2))
			{
				return;
			}
			RectTransform rectTransform = ((Graphic)val2).rectTransform;
			rectTransform.GetWorldCorners(array);
			num2 = Mathf.Min(num2, array[0].x);
			num3 = Mathf.Max(num3, array[3].x);
		}
		float num4 = num - (num2 + num3) * 0.5f;
		if (!(Mathf.Abs(num4) < 0.0001f))
		{
			for (int j = 0; j < 3; j++)
			{
				RectTransform rectTransform2 = ((Graphic)MineIcons[j]).rectTransform;
				((Transform)rectTransform2).position = ((Transform)rectTransform2).position + new Vector3(num4, 0f, 0f);
			}
		}
	}

	private static void ApplyMineIcons()
	{
		if (MineIcons.Count < 3)
		{
			_mineIconsResolved = true;
			return;
		}
		bool mineIconsResolved = true;
		for (int i = 0; i < 3; i++)
		{
			Image val = MineIcons[i];
			if (!((Object)(object)val == (Object)null) && Object.op_Implicit((Object)(object)val))
			{
				Sprite val2 = ResolveMineIcon(i);
				if ((Object)(object)val2 == (Object)null)
				{
					mineIconsResolved = false;
				}
				else if ((Object)(object)val.sprite != (Object)(object)val2)
				{
					val.sprite = val2;
					val.preserveAspect = true;
				}
			}
		}
		_mineIconsResolved = mineIconsResolved;
	}

	private static Sprite ResolveMineIcon(int index)
	{
		return (Sprite)(index switch
		{
			0 => SafeItemSprite("Pickaxe"), 
			1 => FindSpriteByName("icon_Signboard"), 
			2 => SafeTagSprite("FasterOrder"), 
			_ => null, 
		});
	}

	private static Sprite SafeTagSprite(string tagID)
	{
		try
		{
			return TagParamGetter.GetSprite(tagID);
		}
		catch (Exception)
		{
			return null;
		}
	}

	private static Sprite SafeItemSprite(string itemID)
	{
		try
		{
			return ItemParamGetter.GetSprite(itemID);
		}
		catch (Exception)
		{
			return null;
		}
	}

	private static Sprite FindSpriteByName(string name)
	{
		if (SpriteByName.TryGetValue(name, out var value) && (Object)(object)value != (Object)null)
		{
			return value;
		}
		float unscaledTime = Time.unscaledTime;
		if (unscaledTime < _nextSpriteProbe)
		{
			return null;
		}
		_nextSpriteProbe = unscaledTime + 3f;
		Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
		for (int i = 0; i < array.Length; i++)
		{
			if ((Object)(object)array[i] != (Object)null && ((Object)array[i]).name == name)
			{
				SpriteByName[name] = array[i];
				break;
			}
		}
		if (SpriteByName.TryGetValue(name, out value))
		{
			return value;
		}
		return null;
	}

	private static void OnStockButtonClicked()
	{
		StockView.MapOverlayOn = !StockView.MapOverlayOn;
		ApplyButtonStates();
	}

	private static void OnMineButtonClicked()
	{
		_minePointsVisible = !_minePointsVisible;
		SetLeftStackVisible(_minePointsVisible);
		ApplyButtonStates();
		RavenQolPlugin.Log.LogInfo((object)("[hud] left panels " + (_minePointsVisible ? "shown" : "hidden")));
	}

	private static void ApplyButtonStates()
	{
		if ((Object)(object)_stockButtonGroup != (Object)null && Object.op_Implicit((Object)(object)_stockButtonGroup))
		{
			_stockButtonGroup.alpha = (StockView.MapOverlayOn ? 1f : 0.55f);
			_stockButtonGroup.interactable = true;
			_stockButtonGroup.blocksRaycasts = true;
		}
		if ((Object)(object)_mineButtonGroup != (Object)null && Object.op_Implicit((Object)(object)_mineButtonGroup))
		{
			_mineButtonGroup.alpha = (_minePointsVisible ? 1f : 0.55f);
			_mineButtonGroup.interactable = true;
			_mineButtonGroup.blocksRaycasts = true;
		}
	}

	private static void HideMapButtons()
	{
		if ((Object)(object)_stockButton != (Object)null && Object.op_Implicit((Object)(object)_stockButton) && _stockButton.activeSelf)
		{
			_stockButton.SetActive(false);
		}
		if ((Object)(object)_mineButton != (Object)null && Object.op_Implicit((Object)(object)_mineButton) && _mineButton.activeSelf)
		{
			_mineButton.SetActive(false);
		}
	}

	private static bool EnsureLeftStack()
	{
		if ((Object)(object)_leftStack != (Object)null && Object.op_Implicit((Object)(object)_leftStack))
		{
			return true;
		}
		Canvas val = MainCanvas();
		if ((Object)(object)val == (Object)null)
		{
			return false;
		}
		Transform val2 = FindChildRecursive(((Component)val).transform, "NormalGameUIList");
		if ((Object)(object)val2 == (Object)null)
		{
			return false;
		}
		_leftStack = ((Component)val2).gameObject;
		return true;
	}

	private static void SetLeftStackVisible(bool visible)
	{
		if (!EnsureLeftStack())
		{
			return;
		}
		CanvasGroup val = _leftStack.GetComponent<CanvasGroup>();
		if ((Object)(object)val == (Object)null)
		{
			if (visible)
			{
				return;
			}
			val = _leftStack.AddComponent<CanvasGroup>();
		}
		val.alpha = (visible ? 1f : 0f);
		val.interactable = visible;
		val.blocksRaycasts = visible;
	}

	private static void RefreshLabels()
	{
		float unscaledTime = Time.unscaledTime;
		if (_stockLabel == null || !(unscaledTime < _nextLabelFetch))
		{
			_nextLabelFetch = unscaledTime + 5f;
			_stockLabel = FetchMessage("StatsColumnStock", "Stock");
		}
	}

	private static string FetchMessage(string key, string fallback)
	{
		string text = null;
		try
		{
			text = LocalizedTextGetter.GetMessageData(key);
		}
		catch (Exception)
		{
		}
		if (!string.IsNullOrEmpty(text))
		{
			return text;
		}
		return fallback;
	}

	private static void MoveDropUI()
	{
		//IL_0106: 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_0135: Unknown result type (might be due to invalid IL or missing references)
		if (!_ready || (Object)(object)_birdsEye == (Object)null || !Object.op_Implicit((Object)(object)_birdsEye))
		{
			return;
		}
		object? value = _fDropMomokoUI.GetValue(_birdsEye);
		GameObject val = (GameObject)((value is GameObject) ? value : null);
		if ((Object)(object)val == (Object)null || !Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		Trans