Decompiled source of BetterTradeBook v1.0.0

BepInEx/plugins/BetterTradeBook/BetterTradeBook.dll

Decompiled 6 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using Crest;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("BetterTradeBook.Tests")]
[assembly: InternalsVisibleTo("BetterTradeBook.QA")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("BetterTradeBook")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BetterTradeBook")]
[assembly: AssemblyTitle("BetterTradeBook")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BetterTradeBook
{
	[BepInPlugin("DogEggz.BetterTradeBook", "Better Trade Book", "1.0.0")]
	[BepInIncompatibility("DogEggz.EconomyOverhaul")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "DogEggz.BetterTradeBook";

		public const string Version = "1.0.0";

		internal static ManualLogSource Log;

		private Harmony harmony;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			try
			{
				harmony = new Harmony("DogEggz.BetterTradeBook");
				harmony.PatchAll(typeof(Plugin).Assembly);
				TradeSaleCompatibility.Install(harmony);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Better Trade Book 1.0.0 loaded.");
			}
			catch (Exception ex)
			{
				Harmony obj = harmony;
				if (obj != null)
				{
					obj.UnpatchSelf();
				}
				TradeSaleCompatibility.Restore();
				((BaseUnityPlugin)this).Logger.LogError((object)("Better Trade Book could not initialize; no patch kept. " + ex));
				((Behaviour)this).enabled = false;
			}
		}

		private IEnumerator Start()
		{
			yield return null;
			yield return null;
			if (Object.op_Implicit((Object)(object)EconomyUI.instance))
			{
				BulkTradeUI.Attach(EconomyUI.instance);
			}
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			TradeSaleCompatibility.Restore();
		}
	}
	internal static class Fields
	{
		private static readonly Dictionary<string, FieldInfo> cache = new Dictionary<string, FieldInfo>();

		public static FieldInfo Find(Type type, string name)
		{
			string text = type.FullName + "." + name;
			if (!cache.TryGetValue(text, out var value))
			{
				Dictionary<string, FieldInfo> dictionary = cache;
				FieldInfo obj = AccessTools.Field(type, name) ?? throw new MissingFieldException(text);
				value = obj;
				dictionary[text] = obj;
			}
			return value;
		}

		public static T Get<T>(object obj, string name)
		{
			return (T)Find(obj.GetType(), name).GetValue(obj);
		}

		public static void Set(object obj, string name, object value)
		{
			Find(obj.GetType(), name).SetValue(obj, value);
		}

		public static object Call(object obj, string name, params object[] args)
		{
			return AccessTools.Method(obj.GetType(), name, (Type[])null, (Type[])null).Invoke(obj, args);
		}
	}
	internal static class BookLog
	{
		private static readonly Dictionary<string, float> last = new Dictionary<string, float>();

		internal static void Error(string where, Exception e)
		{
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (!last.TryGetValue(where, out var value) || !(realtimeSinceStartup - value < 60f))
			{
				last[where] = realtimeSinceStartup;
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)("Trade book error while " + where + ": " + e));
				}
			}
		}
	}
	internal static class Notice
	{
		internal static void Show(string text)
		{
			if (Object.op_Implicit((Object)(object)NotificationUi.instance))
			{
				NotificationUi.instance.ShowNotification(text);
			}
		}
	}
	internal static class TradeSaleCompatibility
	{
		internal const string DizzyGuid = "com.dizzy.sailwind.fixes";

		private static readonly MethodInfo Sale = AccessTools.Method(typeof(EconomyUI), "SellGood", (Type[])null, (Type[])null);

		private static Patch suspended;

		internal static void Install(Harmony harmony)
		{
			if (suspended == null)
			{
				Patch val = ((IEnumerable<Patch>)Harmony.GetPatchInfo((MethodBase)Sale)?.Prefixes).FirstOrDefault((Func<Patch, bool>)((Patch p) => p.owner == "com.dizzy.sailwind.fixes" && p.PatchMethod.DeclaringType?.FullName == "Dizzy.Fixes.EconomyUiSellGoodPatch" && p.PatchMethod.Name == "Prefix"));
				if (val != null)
				{
					suspended = val;
					harmony.Unpatch((MethodBase)Sale, val.PatchMethod);
					Plugin.Log.LogInfo((object)"Dizzy compatibility: Better Trade Book handles trade-book sales; only Dizzy's overlapping sale prefix is suspended.");
				}
			}
		}

		internal static void Restore()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_00a7: Expected O, but got Unknown
			Patch patch = suspended;
			if (patch != null)
			{
				Patches patchInfo = Harmony.GetPatchInfo((MethodBase)Sale);
				if (patchInfo == null || !patchInfo.Prefixes.Any((Patch p) => p.owner == patch.owner && p.PatchMethod == patch.PatchMethod))
				{
					new Harmony(patch.owner).Patch((MethodBase)Sale, new HarmonyMethod(patch.PatchMethod)
					{
						priority = patch.priority,
						before = patch.before,
						after = patch.after
					}, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				suspended = null;
			}
		}
	}
	internal enum TradeAction
	{
		Buy,
		Sell
	}
	internal sealed class TradeUnit
	{
		internal Good Cargo;

		internal int Price;
	}
	internal sealed class TradeBatch
	{
		internal TradeAction Action;

		internal IslandMarket Market;

		internal int Good;

		internal int Currency;

		internal int Count;

		internal string Error;

		internal CargoCarrier Carrier;

		internal int CartCurrency;

		internal int CartUnitFee;

		internal long SaleCartFee;

		internal long StorageFee;

		internal List<TradeUnit> Units = new List<TradeUnit>();

		internal long CartFee
		{
			get
			{
				if (Action != TradeAction.Sell)
				{
					return (long)CartUnitFee * (long)Count;
				}
				return SaleCartFee;
			}
		}

		internal long CartCharge => CartFee + StorageFee;

		internal bool Valid
		{
			get
			{
				if (Error == null)
				{
					return Units.Count == Count;
				}
				return false;
			}
		}

		internal long Total => ((IEnumerable<TradeUnit>)Units).Sum((Func<TradeUnit, long>)((TradeUnit u) => u.Price));

		internal long NetPayout => Total - ((Object.op_Implicit((Object)(object)Carrier) && CartCurrency == Currency) ? CartCharge : 0);

		internal string Breakdown()
		{
			if (!Valid)
			{
				return Error ?? "Cargo unavailable";
			}
			string currencyName = PlayerGold.GetCurrencyName(Currency);
			if (Action == TradeAction.Sell)
			{
				string text = "Sale value: " + Total.ToString("N0") + " " + currencyName;
				if (Object.op_Implicit((Object)(object)Carrier))
				{
					string currencyName2 = PlayerGold.GetCurrencyName(CartCurrency);
					text = text + "\nCart selling (20x): " + CartFee.ToString("N0") + " " + currencyName2 + "\nStorage: " + StorageFee.ToString("N0") + " " + currencyName2;
					text = text + "\nCart cash required upfront: " + CartCharge.ToString("N0") + " " + currencyName2;
				}
				text = text + "\nReceive: " + NetPayout.ToString("N0") + " " + currencyName;
				if (Object.op_Implicit((Object)(object)Carrier) && CartCurrency != Currency)
				{
					text = text + "\nSeparate cart debit: " + CartCharge.ToString("N0") + " " + PlayerGold.GetCurrencyName(CartCurrency);
				}
				return text;
			}
			string text2 = "Cargo cost: " + Total.ToString("N0") + " " + currencyName;
			if (Object.op_Implicit((Object)(object)Carrier))
			{
				text2 = text2 + "\nCart loading (10x): " + CartFee.ToString("N0") + " " + PlayerGold.GetCurrencyName(CartCurrency);
			}
			text2 = text2 + "\nCash required: " + (Total + ((Object.op_Implicit((Object)(object)Carrier) && CartCurrency == Currency) ? CartFee : 0)).ToString("N0") + " " + currencyName;
			if (Object.op_Implicit((Object)(object)Carrier) && CartCurrency != Currency)
			{
				text2 = text2 + " + " + CartFee.ToString("N0") + " " + PlayerGold.GetCurrencyName(CartCurrency);
			}
			return text2;
		}
	}
	internal static class BulkTrade
	{
		internal const int MaxBatch = 20;

		internal static bool Executing;

		internal static int KeyQuantity(bool alt, bool ctrl, bool shift)
		{
			if (!shift)
			{
				if (!ctrl)
				{
					if (!alt)
					{
						return 1;
					}
					return 5;
				}
				return 10;
			}
			return 20;
		}

		internal static int HeldQuantity()
		{
			return KeyQuantity(Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307), Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305), Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303));
		}

		internal static int Quantity(GoPointerButton button)
		{
			if (!ButtonHover.IsOver(button))
			{
				return 1;
			}
			return HeldQuantity();
		}

		internal static IEnumerable<Good> SaleGoods(IslandMarket market, int goodIndex, CargoCarrier carrier = null)
		{
			IslandMarketWarehouseArea area = market.GetWarehouseArea();
			if (!Object.op_Implicit((Object)(object)area))
			{
				return Enumerable.Empty<Good>();
			}
			return (Object.op_Implicit((Object)(object)carrier) ? (from item in carrier.cargo
				where Object.op_Implicit((Object)(object)item) && item.GetCurrentInventorySlot() == carrier.portIndex + 100
				select ((Component)item).GetComponent<Good>()) : (from g in Fields.Get<List<Good>>(area, "goodsInArea")
				where Object.op_Implicit((Object)(object)g) && ((Component)g).GetComponent<ShipItem>().GetCurrentInventorySlot() < 100
				select g)).Where((Good g) => Object.op_Implicit((Object)(object)g) && ((Component)g).GetComponent<ShipItem>().sold && g.GetMissionIndex() == -1 && PrefabsDirectory.ItemToGoodIndex(((Component)g).GetComponent<SaveablePrefab>().prefabIndex) == goodIndex && (bool)Fields.Call(area, "IsGoodValid", g)).Distinct();
		}

		internal static bool ConversionFee(IslandMarket m, int currency)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			return (int)m.GetPort().region != currency;
		}

		internal static TradeBatch Quote(EconomyUI ui, TradeAction action, int count)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected I4, but got Unknown
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Expected I4, but got Unknown
			TradeBatch tradeBatch = new TradeBatch
			{
				Action = action,
				Count = count,
				Market = Fields.Get<IslandMarket>(ui, "currentIsland"),
				Good = ui.currentSelectedGood
			};
			IslandMarket market = tradeBatch.Market;
			if (GameState.currentlyLoading || !Object.op_Implicit((Object)(object)market) || !Object.op_Implicit((Object)(object)CurrencyMarket.instance) || PlayerGold.currency == null || count < 1 || count > 20)
			{
				tradeBatch.Error = "Trade book unavailable";
				return tradeBatch;
			}
			tradeBatch.Currency = (int)Fields.Get<Currency>(ui, "currentPlayerCurrency");
			if (tradeBatch.Currency != market.GetPortRegion() && !market.allowCurrencyConversion)
			{
				tradeBatch.Error = "Wrong currency";
				return tradeBatch;
			}
			int good = tradeBatch.Good;
			ShipItem good2 = PrefabsDirectory.instance.GetGood(good);
			if (!Object.op_Implicit((Object)(object)good2) || good <= 0 || good == 45 || good == 51)
			{
				tradeBatch.Error = "Cargo unavailable";
				return tradeBatch;
			}
			bool flag = action == TradeAction.Buy;
			if (flag && !market.HasGood(good))
			{
				tradeBatch.Error = "Not enough stock";
				return tradeBatch;
			}
			long[] array = ((IEnumerable<int>)PlayerGold.currency).Select((Func<int, long>)((int x) => x)).ToArray();
			List<Good> list = new List<Good>();
			float num = market.currentSupply[good];
			try
			{
				if (Object.op_Implicit((Object)(object)((Component)ui).GetComponent<BulkTradeUI>()) && ((Component)ui).GetComponent<BulkTradeUI>().CartSelected)
				{
					tradeBatch.Carrier = CartDelivery.Hired(market, out tradeBatch.Error);
					if (!Object.op_Implicit((Object)(object)tradeBatch.Carrier))
					{
						return tradeBatch;
					}
					tradeBatch.CartCurrency = (int)tradeBatch.Carrier.currency;
				}
				if (!flag)
				{
					list = SaleGoods(market, good, tradeBatch.Carrier).Take(count).ToList();
					if (list.Count < count)
					{
						tradeBatch.Error = "Not enough " + (Object.op_Implicit((Object)(object)tradeBatch.Carrier) ? "cart" : "warehouse") + " cargo for the full batch";
						return tradeBatch;
					}
				}
				if (Object.op_Implicit((Object)(object)tradeBatch.Carrier))
				{
					if (!flag)
					{
						foreach (Good item in list)
						{
							ShipItem component = ((Component)item).GetComponent<ShipItem>();
							tradeBatch.SaleCartFee += CartDelivery.Fee(tradeBatch.Carrier, component, 20);
							int withdrawPrice = tradeBatch.Carrier.GetWithdrawPrice(tradeBatch.Carrier.cargo.IndexOf(component));
							if (withdrawPrice < 0)
							{
								throw new OverflowException("Storage fee exceeds wallet limit");
							}
							tradeBatch.StorageFee += withdrawPrice;
						}
					}
					else
					{
						tradeBatch.CartUnitFee = CartDelivery.Fee(tradeBatch.Carrier, ((Component)good2).GetComponent<ShipItem>());
					}
					if (tradeBatch.CartCharge > int.MaxValue)
					{
						throw new OverflowException("Cart fee exceeds wallet limit");
					}
					array[tradeBatch.CartCurrency] -= tradeBatch.CartCharge;
					if (array[tradeBatch.CartCurrency] < 0)
					{
						tradeBatch.Error = "Not enough cash for cart fees of the full order";
						return tradeBatch;
					}
				}
				bool flag2 = ConversionFee(market, tradeBatch.Currency);
				for (int num2 = 0; num2 < count; num2++)
				{
					market.currentSupply[good] = num + (float)(flag ? (-num2) : num2);
					if (flag && market.currentSupply[good] < market.supplyPurchaseLimit)
					{
						tradeBatch.Error = "Not enough stock for the full batch";
						return tradeBatch;
					}
					int num3 = (flag ? market.GetBuyPrice(good) : market.GetSellPrice(good));
					int num4 = (flag ? CurrencyMarket.instance.GetBuyPriceInCurrency((Currency)tradeBatch.Currency, (float)num3, flag2) : CurrencyMarket.instance.GetSellPriceInCurrency((Currency)tradeBatch.Currency, (float)num3, flag2));
					array[tradeBatch.Currency] += (flag ? (-num4) : num4);
					if (flag && array[tradeBatch.Currency] < 0)
					{
						tradeBatch.Error = "Not enough money for the full batch";
						return tradeBatch;
					}
					if (array.Any((long v) => v < int.MinValue || v > int.MaxValue))
					{
						tradeBatch.Error = "Wallet limit exceeded";
						return tradeBatch;
					}
					tradeBatch.Units.Add(new TradeUnit
					{
						Cargo = (flag ? null : list[num2]),
						Price = num4
					});
				}
			}
			catch (OverflowException)
			{
				tradeBatch.Error = "Price or wallet limit exceeded";
			}
			finally
			{
				market.currentSupply[good] = num;
			}
			return tradeBatch;
		}

		internal static void Execute(EconomyUI ui, TradeAction action, int count)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			TradeBatch tradeBatch = Quote(ui, action, count);
			if (!tradeBatch.Valid)
			{
				Notice.Show(tradeBatch.Error ?? "Cargo unavailable");
				ui.RefreshPage();
				return;
			}
			IslandMarket market = tradeBatch.Market;
			int good = tradeBatch.Good;
			int currency = tradeBatch.Currency;
			List<Good> list = new List<Good>();
			if (action == TradeAction.Buy)
			{
				try
				{
					for (int i = 0; i < count; i++)
					{
						GameObject obj = Object.Instantiate<GameObject>(((Component)PrefabsDirectory.instance.GetGood(good)).gameObject, ((Component)market).transform.position + Vector3.up, CargoPlacement.Frame(market));
						Good component = obj.GetComponent<Good>();
						list.Add(component);
						obj.GetComponent<ShipItem>().sold = true;
						obj.GetComponent<SaveablePrefab>().RegisterToSave();
						component.RegisterAsMissionless();
					}
					int found;
					if (Object.op_Implicit((Object)(object)tradeBatch.Carrier))
					{
						CartDelivery.Stage(tradeBatch, list);
					}
					else if (!CargoPlacement.Place(market, list, out found))
					{
						if (count > 1)
						{
							throw new CargoPlacement.NoRoom(found, count);
						}
						CargoPlacement.Drop(market, list[0]);
					}
				}
				catch (Exception ex)
				{
					foreach (Good item in list)
					{
						if (Object.op_Implicit((Object)(object)item))
						{
							((Component)item).GetComponent<ShipItem>().DestroyItem();
						}
					}
					ManualLogSource log = Plugin.Log;
					if (log != null)
					{
						log.LogWarning((object)ex);
					}
					Notice.Show((ex is CargoPlacement.NoRoom) ? "Not enough space for Bulk Trading. Please buy one by one" : (ex.Message + "; no trade was charged."));
					return;
				}
			}
			int[] array = (int[])PlayerGold.currency.Clone();
			float num = market.currentSupply[good];
			float debugTotalGoodsTraded = market.debugTotalGoodsTraded;
			Executing = true;
			try
			{
				if (Object.op_Implicit((Object)(object)tradeBatch.Carrier))
				{
					PlayerGold.currency[tradeBatch.CartCurrency] = checked(PlayerGold.currency[tradeBatch.CartCurrency] - (int)tradeBatch.CartCharge);
				}
				for (int j = 0; j < count; j++)
				{
					TradeUnit tradeUnit = tradeBatch.Units[j];
					if (action == TradeAction.Sell)
					{
						ShipItem component2 = ((Component)tradeUnit.Cargo).GetComponent<ShipItem>();
						if (Fields.Get<List<Good>>(market.GetWarehouseArea(), "goodsInArea").Remove(tradeUnit.Cargo))
						{
							market.currentPlayerGoods[good] = Math.Max(0, market.currentPlayerGoods[good] - 1);
						}
						if (Object.op_Implicit((Object)(object)tradeBatch.Carrier))
						{
							CartDelivery.Detach(component2);
						}
						component2.DestroyItem();
						market.SellGood(good);
						PlayerGold.currency[currency] = checked(PlayerGold.currency[currency] + tradeUnit.Price);
					}
					else
					{
						PlayerGold.currency[currency] = checked(PlayerGold.currency[currency] - tradeUnit.Price);
						market.PurchaseGood(good);
					}
				}
			}
			catch (Exception ex2)
			{
				if (action == TradeAction.Buy)
				{
					Array.Copy(array, PlayerGold.currency, array.Length);
					market.currentSupply[good] = num;
					market.debugTotalGoodsTraded = debugTotalGoodsTraded;
					market.UpdateSelfPriceReportForPlayer();
					foreach (Good item2 in list)
					{
						if (Object.op_Implicit((Object)(object)item2))
						{
							((Component)item2).GetComponent<ShipItem>().DestroyItem();
						}
					}
					ManualLogSource log2 = Plugin.Log;
					if (log2 != null)
					{
						log2.LogError((object)ex2);
					}
					Notice.Show("Order cancelled; no trade was charged.");
					return;
				}
				throw;
			}
			finally
			{
				Executing = false;
			}
			try
			{
				for (int k = 0; k < count; k++)
				{
					TradeUnit tradeUnit2 = tradeBatch.Units[k];
					bool flag = action == TradeAction.Sell;
					ShipItem component3 = ((Component)(flag ? tradeUnit2.Cargo : list[k])).GetComponent<ShipItem>();
					if (Object.op_Implicit((Object)(object)DayLogs.instance))
					{
						DayLogs.instance.dayLogs[currency].LogTransaction(flag ? tradeUnit2.Price : (-tradeUnit2.Price), component3);
					}
					if (Object.op_Implicit((Object)(object)EconomyUIReceiptScribe.instance))
					{
						EconomyUIReceiptScribe.instance.AddTransaction(good, (!flag) ? 1 : (-1), tradeUnit2.Price, currency);
					}
				}
			}
			catch (Exception ex3)
			{
				ManualLogSource log3 = Plugin.Log;
				if (log3 != null)
				{
					log3.LogError((object)("Trade completed, but receipt display failed: " + ex3));
				}
			}
			if (Object.op_Implicit((Object)(object)tradeBatch.Carrier))
			{
				if (action == TradeAction.Buy)
				{
					GameState.loadedCargoIntoCart = true;
				}
				if (Object.op_Implicit((Object)(object)DayLogs.instance))
				{
					DayLogs.instance.dayLogs[tradeBatch.CartCurrency].LogTransaction(-(int)tradeBatch.CartCharge, (TransactionCategory)13);
				}
			}
			if (Object.op_Implicit((Object)(object)UISoundPlayer.instance))
			{
				UISoundPlayer.instance.PlayGoldSound();
			}
			ui.RefreshPage();
		}
	}
	[HarmonyPatch(typeof(EconomyUI), "BuyGood")]
	internal static class BulkBuyPatch
	{
		private static bool Prefix(EconomyUI __instance)
		{
			BulkTrade.Execute(__instance, TradeAction.Buy, BulkTrade.Quantity((GoPointerButton)(object)Fields.Get<EconomyUIButton>(__instance, "buyButton")));
			return false;
		}
	}
	[HarmonyPatch(typeof(EconomyUI), "SellGood")]
	internal static class BulkSellPatch
	{
		private static bool Prefix(EconomyUI __instance)
		{
			BulkTrade.Execute(__instance, TradeAction.Sell, BulkTrade.Quantity((GoPointerButton)(object)Fields.Get<EconomyUIButton>(__instance, "sellButton")));
			return false;
		}
	}
	[HarmonyPatch(typeof(EconomyUI), "RefreshPage")]
	internal static class BatchedPagePatch
	{
		private static bool Prefix()
		{
			return !BulkTrade.Executing;
		}
	}
	[HarmonyPatch(typeof(PortDude), "ActivateMissionListUI")]
	internal static class BookFromZeroPatch
	{
		internal static IEnumerable<CodeInstruction> Lower(IEnumerable<CodeInstruction> instructions)
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(PlayerReputation), "GetRepLevel", new Type[1] { typeof(PortRegion) }, (Type[])null);
			List<CodeInstruction> list = instructions.ToList();
			int num = 0;
			for (int i = 0; i + 1 < list.Count; i++)
			{
				if (CodeInstructionExtensions.Calls(list[i], methodInfo) && list[i + 1].opcode == OpCodes.Ldc_I4_1)
				{
					list[i + 1].opcode = OpCodes.Ldc_I4_0;
					num++;
				}
			}
			if (num != 1)
			{
				throw new InvalidOperationException("Trade book reputation test changed (" + num + " found)");
			}
			return list;
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			return Lower(instructions);
		}
	}
	[DefaultExecutionOrder(1000)]
	public sealed class BulkTradeUI : MonoBehaviour
	{
		private EconomyUI ui;

		private EconomyUIButton buy;

		private EconomyUIButton sell;

		private float timer;

		private int previousKey = -1;

		private int previousHover = -1;

		private BookButton cart;

		private TextMesh cartMark;

		private TextMesh cartLabel;

		private TextMesh note;

		private GameObject cartRoot;

		private IslandMarket cartMarket;

		private bool cartSelected;

		private float buyTextSize;

		private float sellTextSize;

		private TextMesh storageLabel;

		private string storageLabelText;

		internal bool CartSelected
		{
			get
			{
				if (cartSelected && Object.op_Implicit((Object)(object)ui) && ui.uiActive && !GameState.currentlyLoading)
				{
					return (Object)(object)cartMarket == (Object)(object)Fields.Get<IslandMarket>(ui, "currentIsland");
				}
				return false;
			}
		}

		internal static void Attach(EconomyUI ui)
		{
			//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_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)((Component)ui).GetComponent<BulkTradeUI>()))
			{
				return;
			}
			try
			{
				BulkTradeUI bulkTradeUI = ((Component)ui).gameObject.AddComponent<BulkTradeUI>();
				bulkTradeUI.ui = ui;
				bulkTradeUI.buy = Fields.Get<EconomyUIButton>(ui, "buyButton");
				bulkTradeUI.sell = Fields.Get<EconomyUIButton>(ui, "sellButton");
				bulkTradeUI.buyTextSize = Fields.Get<TextMesh>(bulkTradeUI.buy, "text").characterSize;
				bulkTradeUI.sellTextSize = Fields.Get<TextMesh>(bulkTradeUI.sell, "text").characterSize;
				bulkTradeUI.storageLabel = ((IEnumerable<TextMesh>)((Component)ui).GetComponentsInChildren<TextMesh>(true)).FirstOrDefault((Func<TextMesh, bool>)((TextMesh t) => t.text.Contains("storage area")));
				if (Object.op_Implicit((Object)(object)bulkTradeUI.storageLabel))
				{
					bulkTradeUI.storageLabelText = bulkTradeUI.storageLabel.text;
				}
				bulkTradeUI.CreateCartControl();
				EconomyUIButton[] array = (EconomyUIButton[])(object)new EconomyUIButton[2] { bulkTradeUI.buy, bulkTradeUI.sell };
				foreach (EconomyUIButton val in array)
				{
					TextMesh val2 = Fields.Get<TextMesh>(val, "text");
					if (Object.op_Implicit((Object)(object)val2) && !Object.op_Implicit((Object)(object)((Component)val2).GetComponent<TextFit>()))
					{
						TextFit textFit = ((Component)val2).gameObject.AddComponent<TextFit>();
						textFit.originalScale = ((Component)val2).transform.localScale;
						MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
						Bounds val3 = BookUI.InFrameBounds(component, ((Component)val2).transform.parent);
						textFit.maxWidth = ((Bounds)(ref val3)).size.x * 0.92f;
					}
				}
			}
			catch (Exception e)
			{
				BookLog.Error("building the bulk and cart controls; the book works without them", e);
			}
		}

		private void LateUpdate()
		{
			try
			{
				Tick();
			}
			catch (Exception e)
			{
				BookLog.Error("updating the bulk and cart controls", e);
			}
		}

		private void Tick()
		{
			if (Object.op_Implicit((Object)(object)cartRoot))
			{
				cartRoot.SetActive(Object.op_Implicit((Object)(object)ui) && ui.uiActive);
			}
			if (!Object.op_Implicit((Object)(object)ui) || !ui.uiActive || GameState.currentlyLoading)
			{
				cartSelected = false;
				return;
			}
			int num = BulkTrade.HeldQuantity();
			int num2 = (ButtonHover.IsOver((GoPointerButton)(object)buy) ? 1 : (ButtonHover.IsOver((GoPointerButton)(object)sell) ? 2 : 0));
			timer -= Time.unscaledDeltaTime;
			if (num != previousKey || num2 != previousHover || timer <= 0f)
			{
				previousKey = num;
				previousHover = num2;
				timer = 0.15f;
				Refresh();
			}
		}

		internal void Refresh()
		{
			try
			{
				RefreshLabels();
			}
			catch (Exception e)
			{
				BookLog.Error("refreshing the bulk labels", e);
			}
		}

		private void RefreshLabels()
		{
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Expected I4, but got Unknown
			if (Object.op_Implicit((Object)(object)ui) && ui.uiActive && !GameState.currentlyLoading && !BulkTrade.Executing)
			{
				IslandMarket val = Fields.Get<IslandMarket>(ui, "currentIsland");
				if ((Object)(object)cartMarket != (Object)(object)val)
				{
					cartMarket = val;
					cartSelected = false;
				}
				string error;
				CargoCarrier val2 = CartDelivery.Hired(val, out error);
				((GoPointerButton)cart).unclickable = false;
				((GoPointerButton)cart).description = (cartSelected ? "Use warehouse cargo for purchases and sales instead" : (error ?? "Buy: load into your hired cart (10x normal transport fee). Sell: sell from that cart (20x normal transport fee plus storage). Cart fees require cash upfront."));
				cartMark.text = (cartSelected ? "x" : "");
				if (Object.op_Implicit((Object)(object)val) && CartSelected)
				{
					TextMesh val3 = Fields.Get<TextMesh>(ui, "textGoodAmounts");
					string[] array = val3.text.Split(new char[1] { '\n' });
					val3.text = array[0] + "\n" + (Object.op_Implicit((Object)(object)val2) ? BulkTrade.SaleGoods(val, ui.currentSelectedGood, val2).Count() : 0);
				}
				if (Object.op_Implicit((Object)(object)storageLabel))
				{
					storageLabel.text = (CartSelected ? storageLabelText.Replace("storage area", "hired cart") : storageLabelText);
				}
				Apply(buy, TradeAction.Buy, BulkTrade.Quantity((GoPointerButton)(object)buy));
				Apply(sell, TradeAction.Sell, BulkTrade.Quantity((GoPointerButton)(object)sell));
				if (Object.op_Implicit((Object)(object)val))
				{
					note.text = (BulkTrade.ConversionFee(val, (int)Fields.Get<Currency>(ui, "currentPlayerCurrency")) ? "Exchange fees included" : "");
				}
			}
		}

		internal void ResetCart()
		{
			cartSelected = false;
			cartMarket = (Object.op_Implicit((Object)(object)ui) ? Fields.Get<IslandMarket>(ui, "currentIsland") : null);
		}

		internal void ToggleCart()
		{
			if (!CartSelected && !Object.op_Implicit((Object)(object)CartDelivery.Hired(Fields.Get<IslandMarket>(ui, "currentIsland"), out var error)))
			{
				Notice.Show(error);
				Refresh();
			}
			else
			{
				cartSelected = !CartSelected;
				ui.RefreshPage();
			}
		}

		private void CreateCartControl()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Expected O, but got Unknown
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Expected O, but got Unknown
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			MeshRenderer component = ((Component)buy).GetComponent<MeshRenderer>();
			Transform parent = ((Component)component).transform.parent.parent.parent;
			cartRoot = new GameObject("Trade book cart delivery");
			cartRoot.layer = ((Component)component).gameObject.layer;
			cartRoot.transform.SetParent(parent, false);
			Font font = Fields.Get<TextMesh>(ui, "textBuyPrice").font;
			cartLabel = BookUI.Text(cartRoot.transform, font, "Load to/sell from cart", 0.311f, -0.032f, 0.012f, 0.122f, (TextAnchor)3);
			cartMark = BookUI.Text(cartRoot.transform, font, "", 0.299f, -0.032f, 0.014f, 0.009f, (TextAnchor)4);
			GameObject val = new GameObject("Cart delivery checkbox");
			val.layer = cartRoot.layer;
			val.transform.SetParent(cartRoot.transform, false);
			val.transform.localPosition = BookUI.Position(0.299f, -0.032f);
			List<Vector3> list = new List<Vector3>();
			List<int> list2 = new List<int>();
			AddRect(list, list2, -0.0055f, -0.0055f, 0.0055f, -0.0049f);
			AddRect(list, list2, -0.0055f, 0.0049f, 0.0055f, 0.0055f);
			AddRect(list, list2, -0.0055f, -0.0055f, -0.0049f, 0.0055f);
			AddRect(list, list2, 0.0049f, -0.0055f, 0.0055f, 0.0055f);
			Mesh val2 = new Mesh();
			val2.vertices = list.ToArray();
			val2.triangles = list2.ToArray();
			val2.RecalculateNormals();
			val2.RecalculateBounds();
			val.AddComponent<MeshFilter>().sharedMesh = val2;
			Material val3 = new Material(((Renderer)component).sharedMaterial);
			val3.color = Color.black;
			((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = val3;
			cart = val.AddComponent<BookButton>();
			cart.action = ToggleCart;
			cart.ownedMesh = val2;
			cart.ownedMaterial = val3;
			BoxCollider obj = val.AddComponent<BoxCollider>();
			obj.center = new Vector3(-0.064f, 0f, 0f);
			obj.size = new Vector3(0.142f, 0.008f, 0.019f);
			TextMesh val4 = Fields.Get<TextMesh>(ui, "textConversionInfo");
			((Component)val4).gameObject.SetActive(false);
			note = BookUI.Text(cartRoot.transform, val4.font, "", 0.205f, -0.032f, 0.011f, 0.083f, (TextAnchor)3);
			note.fontStyle = (FontStyle)2;
			cartRoot.SetActive(false);
		}

		private static void AddRect(List<Vector3> v, List<int> t, float x1, float z1, float x2, float z2)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			int count = v.Count;
			v.Add(new Vector3(x1, 0f, z1));
			v.Add(new Vector3(x2, 0f, z1));
			v.Add(new Vector3(x2, 0f, z2));
			v.Add(new Vector3(x1, 0f, z2));
			t.AddRange(new int[6]
			{
				count,
				count + 2,
				count + 1,
				count,
				count + 3,
				count + 2
			});
		}

		private void Apply(EconomyUIButton button, TradeAction action, int count)
		{
			TradeBatch tradeBatch = BulkTrade.Quote(ui, action, count);
			((GoPointerButton)button).unclickable = !tradeBatch.Valid;
			((GoPointerButton)button).description = tradeBatch.Breakdown();
			string text = action.ToString() + ((count > 1) ? (" " + count) : "");
			string text2 = ((!tradeBatch.Valid) ? (text + " unavailable") : (text + " (" + ((action == TradeAction.Sell) ? tradeBatch.NetPayout : tradeBatch.Total).ToString("N0") + ")"));
			if (tradeBatch.Valid && Object.op_Implicit((Object)(object)tradeBatch.Carrier))
			{
				text2 = text2 + "\nCart: " + tradeBatch.CartCharge.ToString("N0") + " " + PlayerGold.GetCurrencyName(tradeBatch.CartCurrency);
			}
			button.SetButtonText(text2);
			Fields.Get<TextMesh>(button, "text").characterSize = (((Object)(object)button == (Object)(object)buy) ? buyTextSize : sellTextSize) * (text2.Contains("\n") ? 0.78f : 1f);
			button.SetButtonMaterial(Fields.Get<Material[]>(ui, "buttonMaterials")[(!tradeBatch.Valid) ? 1u : 0u]);
		}
	}
	[HarmonyPatch(typeof(EconomyUI), "RefreshPage")]
	internal static class BulkRefreshPatch
	{
		private static void Postfix(EconomyUI __instance)
		{
			BulkTradeUI component = ((Component)__instance).GetComponent<BulkTradeUI>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.Refresh();
			}
		}
	}
	[HarmonyPatch(typeof(EconomyUI), "OpenUI")]
	internal static class CartSessionPatch
	{
		private static void Prefix(EconomyUI __instance)
		{
			BulkTradeUI.Attach(__instance);
			BulkTradeUI component = ((Component)__instance).GetComponent<BulkTradeUI>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.ResetCart();
			}
		}
	}
	public sealed class BookButton : GoPointerButton
	{
		internal Action action;

		internal Material ownedMaterial;

		internal Mesh ownedMesh;

		public override void OnActivate()
		{
			if (!base.unclickable)
			{
				action?.Invoke();
			}
		}

		private void OnDestroy()
		{
			if (Object.op_Implicit((Object)(object)ownedMaterial))
			{
				Object.Destroy((Object)(object)ownedMaterial);
			}
			if (Object.op_Implicit((Object)(object)ownedMesh))
			{
				Object.Destroy((Object)(object)ownedMesh);
			}
		}
	}
	internal static class BookUI
	{
		private const float TextScale = 0.8f;

		internal static Vector3 Position(float x, float y, float depth = 0.022f)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(0f - x, depth, 0f - y);
		}

		internal static TextMesh Text(Transform parent, Font font, string text, float x, float y, float size, float width = 0f, TextAnchor anchor = (TextAnchor)6)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_00a0: 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_00ab: Invalid comparison between Unknown and I4
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Better Trade Book text");
			val.layer = ((Component)parent).gameObject.layer;
			val.transform.SetParent(parent, false);
			val.transform.localPosition = Position(x, y);
			val.transform.localRotation = Quaternion.LookRotation(Vector3.down, Vector3.back);
			val.transform.localScale = Vector3.one * (size * 0.8f / 6.4f);
			TextMesh val2 = val.AddComponent<TextMesh>();
			val2.font = font;
			val2.fontSize = 64;
			val2.characterSize = 1f;
			val2.anchor = anchor;
			val2.alignment = (TextAlignment)(((int)anchor == 8) ? 2 : (((int)anchor == 4) ? 1 : 0));
			val2.color = Color.black;
			val2.richText = false;
			val2.lineSpacing = 0.58f;
			val2.text = text;
			((Renderer)val.GetComponent<MeshRenderer>()).sharedMaterial = val2.font.material;
			if (width > 0f)
			{
				TextFit textFit = val.AddComponent<TextFit>();
				textFit.maxWidth = width;
				textFit.originalScale = val.transform.localScale;
			}
			return val2;
		}

		internal static Bounds InFrameBounds(MeshRenderer renderer, Transform frame)
		{
			//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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_002b: 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_004b: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			Bounds bounds = ((Component)renderer).GetComponent<MeshFilter>().sharedMesh.bounds;
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(frame.InverseTransformPoint(((Component)renderer).transform.TransformPoint(((Bounds)(ref bounds)).center)), Vector3.zero);
			for (int i = 0; i < 8; i++)
			{
				((Bounds)(ref result)).Encapsulate(frame.InverseTransformPoint(((Component)renderer).transform.TransformPoint(((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((i & 1) != 0) ? 1 : (-1)), (float)(((i & 2) != 0) ? 1 : (-1)), (float)(((i & 4) != 0) ? 1 : (-1)))))));
			}
			return result;
		}
	}
	public sealed class TextFit : MonoBehaviour
	{
		internal float maxWidth;

		internal Vector3 originalScale;

		private string last;

		private TextMesh text;

		private void LateUpdate()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_014a: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)this.text))
			{
				this.text = ((Component)this).GetComponent<TextMesh>();
			}
			if (last == this.text.text)
			{
				return;
			}
			last = this.text.text;
			((Component)this).transform.localScale = originalScale;
			this.text.font.RequestCharactersInTexture(this.text.text, this.text.fontSize, this.text.fontStyle);
			float num = 0f;
			float num2 = 0f;
			string text = this.text.text;
			CharacterInfo val = default(CharacterInfo);
			foreach (char c in text)
			{
				if (c == '\n')
				{
					num = Mathf.Max(num, num2);
					num2 = 0f;
				}
				else if (this.text.font.GetCharacterInfo(c, ref val, this.text.fontSize, this.text.fontStyle))
				{
					num2 += (float)((CharacterInfo)(ref val)).advance * 0.1f * this.text.characterSize * originalScale.x;
				}
			}
			num = Mathf.Max(num, num2);
			if (num > maxWidth)
			{
				((Component)this).transform.localScale = originalScale * (maxWidth / num);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerCrouching), "Update")]
	internal static class BookCrouchPatch
	{
		internal static bool NotInBook(bool pressed)
		{
			if (pressed)
			{
				if (Object.op_Implicit((Object)(object)EconomyUI.instance))
				{
					return !EconomyUI.instance.uiActive;
				}
				return true;
			}
			return false;
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			MethodInfo keyDown = AccessTools.Method(AccessTools.TypeByName("GameInput"), "GetKeyDown", (Type[])null, (Type[])null);
			List<CodeInstruction> list = instructions.ToList();
			int num = ((keyDown == null) ? (-1) : list.FindIndex((CodeInstruction c) => CodeInstructionExtensions.Calls(c, keyDown)));
			if (num < 0 || list.Count((CodeInstruction c) => CodeInstructionExtensions.Calls(c, keyDown)) != 1)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogWarning((object)"Crouch key check not found; Ctrl in the trade book may still crouch.");
				}
				return list;
			}
			list.Insert(num + 1, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(BookCrouchPatch), "NotInBook", (Type[])null, (Type[])null)));
			return list;
		}
	}
	internal static class ButtonHover
	{
		internal static bool IsOver(GoPointerButton button)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_009a: 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_00b4: 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)
			if (!Object.op_Implicit((Object)(object)button) || !((Component)button).gameObject.activeInHierarchy)
			{
				return false;
			}
			if (!GameState.inCursorMenu)
			{
				return button.IsLookedAt();
			}
			MouseButtonPointer instance = MouseButtonPointer.instance;
			if (!Object.op_Implicit((Object)(object)instance))
			{
				return false;
			}
			Camera val = Fields.Get<Camera>(instance, "uiCam");
			Camera main = Camera.main;
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)main))
			{
				return false;
			}
			bool num = Fields.Get<bool>(instance, "trackMouse");
			Vector3 val2 = (num ? Input.mousePosition : val.WorldToScreenPoint(instance.controllerPointer.position));
			Vector3 val3 = (num ? Input.mousePosition : main.WorldToScreenPoint(instance.controllerPointer.position));
			RaycastHit val4 = default(RaycastHit);
			if (!Physics.Raycast(val.ScreenPointToRay(val2), ref val4, 160f, 32) && !Physics.Raycast(main.ScreenPointToRay(val3), ref val4, 160f, 8388608))
			{
				return false;
			}
			return (Object)(object)((Component)((RaycastHit)(ref val4)).collider).GetComponent<GoPointerButton>() == (Object)(object)button;
		}
	}
	internal static class CartDelivery
	{
		internal static CargoCarrier Hired(IslandMarket market, out string error)
		{
			//IL_0161: 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)
			error = "Hire this port's cargo transport first";
			CargoStorageUI instance = CargoStorageUI.instance;
			if (!Object.op_Implicit((Object)(object)market) || !Object.op_Implicit((Object)(object)instance))
			{
				return null;
			}
			CargoCarrier val = Fields.Get<CargoCarrier>(instance, "currentCarrier");
			Transform val2 = Fields.Get<Transform>(instance, "currentDude");
			Port component = ((Component)market).GetComponent<Port>();
			IslandHorizon val3 = ((Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.island)) ? ((Component)component.island).GetComponentInParent<IslandHorizon>() : ((Component)market).GetComponentInParent<IslandHorizon>());
			if (!Object.op_Implicit((Object)(object)val3))
			{
				error = "Cargo transport unavailable at this port";
				return null;
			}
			CargoTransportDude val4 = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponent<CargoTransportDude>() : null);
			IslandSceneryScene val5 = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponentInParent<IslandSceneryScene>() : null);
			int num = ((Object.op_Implicit((Object)(object)val5) && val5.parentIslandIndex == val3.islandIndex && Object.op_Implicit((Object)(object)val4)) ? val4.carrierIndex : val3.islandIndex);
			if (!Object.op_Implicit((Object)(object)val) || CargoCarrier.carriers == null || num < 0 || num >= CargoCarrier.carriers.Length || (Object)(object)val != (Object)(object)CargoCarrier.carriers[num] || val.portIndex != num || !Object.op_Implicit((Object)(object)val2) || (Object.op_Implicit((Object)(object)val5) && val5.parentIslandIndex != val3.islandIndex) || (Object.op_Implicit((Object)(object)val4) && val4.carrierIndex != num) || !Object.op_Implicit((Object)(object)Refs.observerMirror) || Vector3.Distance(((Component)Refs.observerMirror).transform.position, val2.position) > 180f)
			{
				return null;
			}
			error = null;
			return val;
		}

		internal static int Fee(CargoCarrier carrier, ShipItem item, int multiplier = 10)
		{
			int transportPrice = carrier.GetTransportPrice(item);
			if (transportPrice < 0)
			{
				throw new OverflowException("Cart fee exceeds wallet limit");
			}
			return checked(transportPrice * multiplier);
		}

		internal static void Stage(TradeBatch batch, List<Good> goods)
		{
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			string error;
			CargoCarrier val = Hired(batch.Market, out error);
			if (!Object.op_Implicit((Object)(object)val) || (Object)(object)val != (Object)(object)batch.Carrier)
			{
				throw new InvalidOperationException(error ?? "Cart service changed");
			}
			foreach (Good good in goods)
			{
				ShipItem component = ((Component)good).GetComponent<ShipItem>();
				if (!Object.op_Implicit((Object)(object)component.GetItemRigidbody()) || !Object.op_Implicit((Object)(object)((Component)component).GetComponent<Collider>()) || (component is ShipItemCrate && component.amount <= 0f) || Fee(val, component) != batch.CartUnitFee)
				{
					throw new InvalidOperationException("Cargo cannot be loaded into the cart");
				}
			}
			foreach (Good good2 in goods)
			{
				ShipItem component2 = ((Component)good2).GetComponent<ShipItem>();
				component2.GetItemRigidbody().EnterInventorySlot(((Component)val).transform);
				component2.InsertIntoCargoCarrier(val);
				((Component)component2).transform.localScale = Vector3.zero;
				component2.daysInStorage = 0;
				val.cargo.Add(component2);
			}
		}

		internal static void Detach(ShipItem item)
		{
			if (CargoCarrier.carriers == null)
			{
				return;
			}
			bool flag = false;
			CargoCarrier[] carriers = CargoCarrier.carriers;
			foreach (CargoCarrier val in carriers)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					flag |= val.cargo.Remove(item);
				}
			}
			if (flag && Object.op_Implicit((Object)(object)item.GetItemRigidbody()))
			{
				((MonoBehaviour)item.GetItemRigidbody()).StopAllCoroutines();
			}
		}
	}
	internal static class CargoPlacement
	{
		private sealed class Candidate
		{
			internal Vector3 Center;

			internal bool ReservedSupport;

			internal bool Stack;
		}

		private sealed class FloorMap
		{
			private const float Step = 0.35f;

			private const float Rise = 1.2f;

			private readonly float cell;

			private readonly float baseHeight;

			private readonly Vector3 origin;

			private readonly Vector3 min;

			private readonly Quaternion rotation;

			private readonly float[,] heights;

			private readonly HashSet<Collider> own;

			internal FloorMap(Vector3 origin, Quaternion rotation, Vector3 min, Vector3 max, Vector3 seed, HashSet<Collider> own)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: 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_003d: 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_004b: 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_006e: 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_008b: 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_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_0122: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b6: 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)
				this.origin = origin;
				this.rotation = rotation;
				this.min = min;
				this.own = own;
				baseHeight = seed.y;
				cell = Mathf.Max(0.25f, Mathf.Max(max.x - min.x, max.z - min.z) / 160f);
				int num = Mathf.CeilToInt((max.x - min.x) / cell) + 1;
				int num2 = Mathf.CeilToInt((max.z - min.z) / cell) + 1;
				heights = new float[num, num2];
				for (int i = 0; i < num; i++)
				{
					for (int j = 0; j < num2; j++)
					{
						heights[i, j] = float.NaN;
					}
				}
				Queue<Vector2Int> queue = new Queue<Vector2Int>();
				for (int k = 0; k < num; k++)
				{
					for (int l = 0; l < num2; l++)
					{
						if (Surface(Point(k, l), baseHeight, out var height))
						{
							heights[k, l] = height;
							queue.Enqueue(new Vector2Int(k, l));
						}
					}
				}
				int[] array = new int[4] { -1, 1, 0, 0 };
				int[] array2 = new int[4] { 0, 0, -1, 1 };
				while (queue.Count > 0)
				{
					Vector2Int val = queue.Dequeue();
					for (int m = 0; m < 4; m++)
					{
						int num3 = ((Vector2Int)(ref val)).x + array[m];
						int num4 = ((Vector2Int)(ref val)).y + array2[m];
						if (num3 >= 0 && num4 >= 0 && num3 < num && num4 < num2 && Surface(Point(num3, num4), heights[((Vector2Int)(ref val)).x, ((Vector2Int)(ref val)).y], out var height2) && (float.IsNaN(heights[num3, num4]) || height2 > heights[num3, num4] + 0.01f))
						{
							heights[num3, num4] = height2;
							queue.Enqueue(new Vector2Int(num3, num4));
						}
					}
				}
			}

			private Vector3 Point(int x, int z)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: 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)
				return origin + rotation * new Vector3(min.x + (float)x * cell, 0f, min.z + (float)z * cell);
			}

			private bool Surface(Vector3 point, float near, out float height)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c7: 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)
				point.y = near + 0.35f + 0.01f;
				height = 0f;
				foreach (RaycastHit item in from h in Physics.RaycastAll(point, Vector3.down, 0.71999997f, -1, (QueryTriggerInteraction)1)
					orderby ((RaycastHit)(ref h)).distance
					select h)
				{
					RaycastHit current = item;
					if (!Ignored(((RaycastHit)(ref current)).collider, own) && !Cargo(((RaycastHit)(ref current)).collider) && !Object.op_Implicit((Object)(object)((RaycastHit)(ref current)).collider.attachedRigidbody) && !(((RaycastHit)(ref current)).normal.y < 0.98f) && !(((RaycastHit)(ref current)).point.y > baseHeight + 1.2f) && !(Mathf.Abs(((RaycastHit)(ref current)).point.y - near) > 0.35f))
					{
						height = ((RaycastHit)(ref current)).point.y;
						return true;
					}
				}
				return false;
			}

			internal bool Height(Vector3 point, out float height)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//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)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: 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)
				Vector3 val = Quaternion.Inverse(rotation) * (point - origin);
				int num = Mathf.Clamp(Mathf.RoundToInt((val.x - min.x) / cell), 0, heights.GetLength(0) - 1);
				int num2 = Mathf.Clamp(Mathf.RoundToInt((val.z - min.z) / cell), 0, heights.GetLength(1) - 1);
				height = 0f;
				if (!float.IsNaN(heights[num, num2]))
				{
					return Surface(point, heights[num, num2], out height);
				}
				return false;
			}
		}

		internal sealed class NoRoom : InvalidOperationException
		{
			internal const string Notice = "Not enough space for Bulk Trading. Please buy one by one";

			internal NoRoom(int found, int count)
				: base("Found space for " + found + " of " + count + " cargo; full order needs more clear warehouse space")
			{
			}
		}

		internal const float Gap = 0.03f;

		internal static readonly HashSet<int> RoughPorts = new HashSet<int> { 1, 32 };

		internal static float MaxTilt = 3f;

		internal static float TipMargin = 4f;

		internal static float MaxStack = float.PositiveInfinity;

		internal static float MaxDip = 0.05f;

		private const float LevelTop = 0.99995f;

		private static float FloorNormal => Mathf.Cos(MaxTilt * (MathF.PI / 180f));

		internal static Bounds Footprint(Good good, Quaternion rotation)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_0037: 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_01b5: 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_0091: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: 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_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: 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_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: 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_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: 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)
			bool flag = false;
			Bounds result = default(Bounds);
			Quaternion val = Quaternion.Inverse(rotation);
			Collider[] componentsInChildren = ((Component)good).GetComponentsInChildren<Collider>();
			Bounds bounds = default(Bounds);
			foreach (Collider val2 in componentsInChildren)
			{
				BoxCollider val3 = (BoxCollider)(object)((val2 is BoxCollider) ? val2 : null);
				if (val3 != null)
				{
					((Bounds)(ref bounds))..ctor(val3.center, val3.size);
				}
				else
				{
					MeshCollider val4 = (MeshCollider)(object)((val2 is MeshCollider) ? val2 : null);
					if (val4 != null && Object.op_Implicit((Object)(object)val4.sharedMesh))
					{
						bounds = val4.sharedMesh.bounds;
					}
					else
					{
						SphereCollider val5 = (SphereCollider)(object)((val2 is SphereCollider) ? val2 : null);
						if (val5 != null)
						{
							((Bounds)(ref bounds))..ctor(val5.center, Vector3.one * val5.radius * 2f);
						}
						else
						{
							CapsuleCollider val6 = (CapsuleCollider)(object)((val2 is CapsuleCollider) ? val2 : null);
							if (val6 == null)
							{
								throw new InvalidOperationException("Unsupported cargo shape");
							}
							Vector3 val7 = Vector3.one * val6.radius * 2f;
							((Vector3)(ref val7))[val6.direction] = Mathf.Max(val6.height, ((Vector3)(ref val7))[val6.direction]);
							((Bounds)(ref bounds))..ctor(val6.center, val7);
						}
					}
				}
				for (int j = 0; j < 8; j++)
				{
					Vector3 val8 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, Corner(j));
					val8 = val * (((Component)val2).transform.TransformPoint(val8) - ((Component)good).transform.position);
					if (!flag)
					{
						((Bounds)(ref result))..ctor(val8, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref result)).Encapsulate(val8);
					}
				}
			}
			if (!flag)
			{
				throw new InvalidOperationException("Cargo shape unavailable");
			}
			return result;
		}

		private static Vector3 Corner(int i)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3((float)(((i & 1) != 0) ? 1 : (-1)), (float)(((i & 2) != 0) ? 1 : (-1)), (float)(((i & 4) != 0) ? 1 : (-1)));
		}

		internal static bool Inside(BoxCollider area, Vector3 center, Vector3 half, Quaternion rotation)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 8; i++)
			{
				Vector3 val = ((Component)area).transform.InverseTransformPoint(center + rotation * Vector3.Scale(half, Corner(i))) - area.center;
				if (Mathf.Abs(val.x) > area.size.x * 0.5f || Mathf.Abs(val.y) > area.size.y * 0.5f || Mathf.Abs(val.z) > area.size.z * 0.5f)
				{
					return false;
				}
			}
			return true;
		}

		private static bool Cargo(Collider c)
		{
			if (!Object.op_Implicit((Object)(object)((Component)c).GetComponentInParent<ShipItem>()))
			{
				return Object.op_Implicit((Object)(object)((Component)c).GetComponentInParent<ItemRigidbody>());
			}
			return true;
		}

		private static float AboveGround(Vector3 center, float halfHeight, HashSet<Collider> own)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0017: 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)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = center - Vector3.up * (halfHeight + 0.03f);
			foreach (RaycastHit item in from h in Physics.RaycastAll(val + Vector3.up * 0.01f, Vector3.down, 30f, -1, (QueryTriggerInteraction)1)
				orderby ((RaycastHit)(ref h)).distance
				select h)
			{
				RaycastHit current = item;
				if (!own.Contains(((RaycastHit)(ref current)).collider) && !Cargo(((RaycastHit)(ref current)).collider))
				{
					return val.y - ((RaycastHit)(ref current)).point.y;
				}
			}
			return float.PositiveInfinity;
		}

		private static bool Ignored(Collider c, HashSet<Collider> own)
		{
			if (!own.Contains(c))
			{
				if (c.isTrigger)
				{
					return !Cargo(c);
				}
				return false;
			}
			return true;
		}

		private static bool StableCargo(Collider c)
		{
			//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_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)
			if (!Cargo(c))
			{
				return false;
			}
			ShipItem val = ((Component)c).GetComponentInParent<ShipItem>();
			ItemRigidbody val2 = (Object.op_Implicit((Object)(object)val) ? val.GetItemRigidbody() : ((Component)c).GetComponentInParent<ItemRigidbody>());
			if (!Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val2))
			{
				val = val2.GetShipItem();
			}
			if (Object.op_Implicit((Object)(object)val) && (Object.op_Implicit((Object)(object)((PickupableItem)val).held) || val.GetCurrentInventorySlot() >= 100))
			{
				return false;
			}
			Rigidbody val3 = (Object.op_Implicit((Object)(object)val2) ? val2.GetBody() : c.attachedRigidbody);
			if (Object.op_Implicit((Object)(object)val3) && !val3.isKinematic)
			{
				Vector3 val4 = val3.velocity;
				if (((Vector3)(ref val4)).sqrMagnitude < 0.04f)
				{
					val4 = val3.angularVelocity;
					return ((Vector3)(ref val4)).sqrMagnitude < 0.04f;
				}
				return false;
			}
			return true;
		}

		private static bool Supported(Vector3 center, Vector3 half, Quaternion rotation, HashSet<Collider> own)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			float num = center.y - half.y - 0.03f;
			for (int i = 0; i < 5; i++)
			{
				Vector3 val = (Vector3)((i == 4) ? Vector3.zero : new Vector3(((i & 1) == 0) ? (0f - half.x + 0.005f) : (half.x - 0.005f), 0f, ((i & 2) == 0) ? (0f - half.z + 0.005f) : (half.z - 0.005f)));
				Vector3 val2 = center + rotation * val;
				val2.y = num + 0.06f;
				RaycastHit[] array = (from h in Physics.RaycastAll(val2, Vector3.down, 0.12f, -1, (QueryTriggerInteraction)2)
					where !Ignored(((RaycastHit)(ref h)).collider, own)
					orderby ((RaycastHit)(ref h)).distance
					select h).ToArray();
				if (array.Length == 0)
				{
					return false;
				}
				RaycastHit val3 = array[0];
				if (((RaycastHit)(ref val3)).normal.y < 0.98f || Mathf.Abs(((RaycastHit)(ref val3)).point.y - num) > 0.025f || (Cargo(((RaycastHit)(ref val3)).collider) ? (!StableCargo(((RaycastHit)(ref val3)).collider)) : ((Object)(object)((RaycastHit)(ref val3)).collider.attachedRigidbody != (Object)null)))
				{
					return false;
				}
			}
			return true;
		}

		internal static float TiltLimit(Vector3 size)
		{
			//IL_0005: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			return Mathf.Min(MaxTilt, Mathf.Atan2(Mathf.Min(size.x, size.z), size.y) * 57.29578f - TipMargin);
		}

		private static bool Rest(ref Vector3 center, ref Quaternion rotation, Vector3 half, HashSet<Collider> own, bool rough, out bool level)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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_0134: 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_013b: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0456: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_0490: Unknown result type (might be due to invalid IL or missing references)
			//IL_0495: Unknown result type (might be due to invalid IL or missing references)
			//IL_049a: Unknown result type (might be due to invalid IL or missing references)
			//IL_049f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			level = Supported(center, half, rotation, own);
			if (level || !rough)
			{
				return level;
			}
			float num = TiltLimit(half * 2f);
			if (num <= 0f)
			{
				return false;
			}
			float num2 = center.y - half.y - 0.03f;
			float num3 = 0.1f + 0.55f * Mathf.Max(half.x, half.z);
			int num4 = ((half.x > 1.2f) ? 5 : 4);
			int num5 = ((half.z > 1.2f) ? 5 : 4);
			List<Vector3> list = new List<Vector3>();
			Vector3 val = default(Vector3);
			for (int i = 0; i < num4; i++)
			{
				for (int j = 0; j < num5; j++)
				{
					((Vector3)(ref val))..ctor(Mathf.Lerp(0f - half.x + 0.02f, half.x - 0.02f, (float)i / ((float)num4 - 1f)), 0f, Mathf.Lerp(0f - half.z + 0.02f, half.z - 0.02f, (float)j / ((float)num5 - 1f)));
					Vector3 val2 = center + rotation * val;
					RaycastHit? val3 = ((IEnumerable<RaycastHit>)(from h in Physics.RaycastAll(new Vector3(val2.x, num2 + num3, val2.z), Vector3.down, num3 * 2f, -1, (QueryTriggerInteraction)2)
						where !Ignored(((RaycastHit)(ref h)).collider, own)
						orderby ((RaycastHit)(ref h)).distance
						select h)).Select((Func<RaycastHit, RaycastHit?>)((RaycastHit h) => h)).FirstOrDefault();
					if (!val3.HasValue)
					{
						return false;
					}
					RaycastHit value = val3.Value;
					Collider collider = ((RaycastHit)(ref value)).collider;
					if (Cargo(collider) ? (!StableCargo(collider)) : ((Object)(object)collider.attachedRigidbody != (Object)null))
					{
						return false;
					}
					float x = val.x;
					value = val3.Value;
					list.Add(new Vector3(x, ((RaycastHit)(ref value)).point.y, val.z));
				}
			}
			if (list.Count < 3)
			{
				return false;
			}
			for (int num6 = 0; num6 < list.Count; num6++)
			{
				for (int num7 = num6 + 1; num7 < list.Count; num7++)
				{
					for (int num8 = num7 + 1; num8 < list.Count; num8++)
					{
						Vector3 val4 = list[num6];
						Vector3 val5 = list[num7];
						Vector3 val6 = list[num8];
						Vector3 val7 = Vector3.Cross(val5 - val4, val6 - val4);
						if (Mathf.Abs(val7.y) < 1E-05f)
						{
							continue;
						}
						if (val7.y < 0f)
						{
							val7 = -val7;
						}
						float num9 = (val5.x - val4.x) * (val6.z - val4.z) - (val6.x - val4.x) * (val5.z - val4.z);
						if (Mathf.Abs(num9) < 1E-06f)
						{
							continue;
						}
						float num10 = (val5.x * val6.z - val6.x * val5.z) / num9;
						float num11 = (val6.x * val4.z - val4.x * val6.z) / num9;
						float num12 = 1f - num10 - num11;
						if (num10 < 0.1f || num11 < 0.1f || num12 < 0.1f)
						{
							continue;
						}
						((Vector3)(ref val7)).Normalize();
						bool flag = true;
						foreach (Vector3 item in list)
						{
							float num13 = Vector3.Dot(item - val4, val7);
							if (num13 > 0.002f || num13 < 0f - MaxDip)
							{
								flag = false;
								break;
							}
						}
						if (flag)
						{
							if (Vector3.Angle(val7, Vector3.up) > num)
							{
								return false;
							}
							float num14 = val4.y - (val7.x * (0f - val4.x) + val7.z * (0f - val4.z)) / val7.y;
							Vector3 val8 = rotation * new Vector3(val7.x, 0f, val7.z) + Vector3.up * val7.y;
							Vector3 normalized = ((Vector3)(ref val8)).normalized;
							rotation = Quaternion.FromToRotation(Vector3.up, normalized) * rotation;
							center = new Vector3(center.x, num14, center.z) + normalized * (0.03f + half.y);
							return true;
						}
					}
				}
			}
			return false;
		}

		private static Vector3 Extent(Quaternion rotation, Quaternion frame, Vector3 size)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			Quaternion val = Quaternion.Inverse(frame) * rotation;
			Vector3 val2 = Vector3.zero;
			for (int i = 0; i < 3; i++)
			{
				Vector3 val3 = val * new Vector3((float)((i == 0) ? 1 : 0), (float)((i == 1) ? 1 : 0), (float)((i == 2) ? 1 : 0)) * ((Vector3)(ref size))[i] * 0.5f;
				val2 += new Vector3(Mathf.Abs(val3.x), Mathf.Abs(val3.y), Mathf.Abs(val3.z));
			}
			return val2;
		}

		internal static Quaternion Frame(IslandMarket market)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)market).transform;
			if (Vector3.Dot(transform.up, Vector3.up) > 0.9999f)
			{
				return transform.rotation;
			}
			Vector3 val = Vector3.ProjectOnPlane(transform.forward, Vector3.up);
			if (((Vector3)(ref val)).sqrMagnitude < 0.25f)
			{
				val = Vector3.ProjectOnPlane(transform.up, Vector3.up);
			}
			return Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up);
		}

		internal static bool Place(IslandMarket market, List<Good> goods, out int found)
		{
			//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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//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_003d: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			Quaternion val = Frame(market);
			List<Good> list = new List<Good>(goods);
			found = 0;
			bool flag = true;
			Quaternion[] array = (Quaternion[])(object)new Quaternion[3]
			{
				val,
				val * Quaternion.Euler(0f, 90f, 0f),
				val * Quaternion.Euler(0f, -90f, 0f)
			};
			bool flag2 = RoughPorts.Contains(market.GetPortIndex());
			if (!flag2)
			{
				Quaternion[] array2 = array;
				foreach (Quaternion rotation in array2)
				{
					foreach (Good good in goods)
					{
						((Component)good).transform.rotation = rotation;
					}
					int num = Plan(market, goods, rotation, rough: false, partial: false);
					if (num == goods.Count)
					{
						found = num;
						return true;
					}
					found = Math.Max(found, num);
				}
				return false;
			}
			while (list.Count > 0 && flag)
			{
				flag = false;
				Quaternion[] array2 = array;
				foreach (Quaternion rotation2 in array2)
				{
					if (list.Count == 0)
					{
						break;
					}
					foreach (Good item in list)
					{
						((Component)item).transform.rotation = rotation2;
					}
					int num2 = Plan(market, list, rotation2, flag2, partial: true);
					if (num2 > 0)
					{
						found += num2;
						list.RemoveRange(0, num2);
						flag = true;
					}
				}
			}
			return list.Count == 0;
		}

		internal static void Drop(IslandMarket market, Good good)
		{
			//IL_000c: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			((Component)good).transform.SetPositionAndRotation(((Component)market).transform.position + Vector3.up, Frame(market));
			Physics.SyncTransforms();
		}

		private static int Plan(IslandMarket market, List<Good> goods, Quaternion rotation, bool rough, bool partial)
		{
			//IL_008f: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: 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_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: 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_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_050e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0513: Unknown result type (might be due to invalid IL or missing references)
			//IL_051d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0522: Unknown result type (might be due to invalid IL or missing references)
			//IL_0527: Unknown result type (might be due to invalid IL or missing references)
			//IL_053e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0543: Unknown result type (might be due to invalid IL or missing references)
			//IL_0547: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0593: Unknown result type (might be due to invalid IL or missing references)
			//IL_0598: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a97: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a9c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a9e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a9f: Unknown result type (might be due to invalid IL or missing references)
			//IL_063e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0643: Unknown result type (might be due to invalid IL or missing references)
			//IL_0644: Unknown result type (might be due to invalid IL or missing references)
			//IL_0646: Unknown result type (might be due to invalid IL or missing references)
			//IL_064a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0658: Unknown result type (might be due to invalid IL or missing references)
			//IL_065f: Unknown result type (might be due to invalid IL or missing references)
			//IL_066f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0676: Unknown result type (might be due to invalid IL or missing references)
			//IL_0686: Unknown result type (might be due to invalid IL or missing references)
			//IL_068d: Unknown result type (might be due to invalid IL or missing references)
			//IL_069d: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ae9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aeb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af8: Unknown resul