Decompiled source of BetterTradeBook v1.0.1
BepInEx/plugins/BetterTradeBook/BetterTradeBook.dll
Decompiled a month ago
The result has been truncated due to the large size, download it to view full contents!
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.1.0")] [assembly: AssemblyInformationalVersion("1.0.1")] [assembly: AssemblyProduct("BetterTradeBook")] [assembly: AssemblyTitle("BetterTradeBook")] [assembly: AssemblyVersion("1.0.1.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.1")] [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.1"; 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.1 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 WalkMap { internal const float Cell = 0.5f; internal const float Line = 1f; internal const float MaxRise = 1f; internal static readonly float WalkNormal = Mathf.Cos(0.87266463f); internal readonly List<Vector3> Points = new List<Vector3>(); internal readonly List<float> Heights = new List<float>(); internal readonly List<bool> Reached = new List<bool>(); internal string Sealed; internal int Start = -1; internal int ReachedCount; internal double BuildMs; private readonly Dictionary<long, List<int>> cells = new Dictionary<long, List<int>>(); private static readonly RaycastHit[] hits = (RaycastHit[])(object)new RaycastHit[64]; private static long Key(int x, int z) { return ((long)x << 32) ^ (uint)z; } private static bool Solid(Collider c) { if (!c.isTrigger && !Cargo(c) && !Object.op_Implicit((Object)(object)c.attachedRigidbody)) { return !(c is CharacterController); } return false; } internal static RaycastHit? First(Vector3 from, Vector3 direction, float distance) { //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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) int num = Physics.RaycastNonAlloc(from, direction, hits, distance, -1, (QueryTriggerInteraction)1); RaycastHit? result = null; for (int i = 0; i < num; i++) { if (!Solid(((RaycastHit)(ref hits[i])).collider)) { continue; } if (result.HasValue) { float distance2 = ((RaycastHit)(ref hits[i])).distance; RaycastHit value = result.Value; if (!(distance2 < ((RaycastHit)(ref value)).distance)) { continue; } } result = hits[i]; } return result; } internal static bool Clear(Vector3 a, Vector3 b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_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_001b: Unknown result type (might be due to invalid IL or missing references) Vector3 val = b - a; float magnitude = ((Vector3)(ref val)).magnitude; if (!(magnitude < 0.0001f)) { return !First(a, val / magnitude, magnitude).HasValue; } return true; } internal Vector3 World(int i, Vector3 origin, Quaternion frame) { //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_0009: 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_0013: Unknown result type (might be due to invalid IL or missing references) return origin + frame * Points[i]; } private WalkMap(string why) { Sealed = why; } internal static WalkMap Failed(string why) { return new WalkMap(why); } private void Add(int x, int z, float y) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) if (!cells.TryGetValue(Key(x, z), out var value)) { value = (cells[Key(x, z)] = new List<int>()); } value.Add(Points.Count); Points.Add(new Vector3((float)x * 0.5f, y, (float)z * 0.5f)); } internal WalkMap(IslandMarket market, BoxCollider area) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: 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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: 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_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: 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_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_025c: 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_0267: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: 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_02bc: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0145: 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_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_02f2: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_039c: Unknown result type (might be due to invalid IL or missing references) //IL_039d: 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_03a3: Unknown result type (might be due to invalid IL or missing references) //IL_03ad: Unknown result type (might be due to invalid IL or missing references) //IL_03b2: Unknown result type (might be due to invalid IL or missing references) //IL_03b7: Unknown result type (might be due to invalid IL or missing references) //IL_0442: Unknown result type (might be due to invalid IL or missing references) //IL_0443: Unknown result type (might be due to invalid IL or missing references) //IL_0444: Unknown result type (might be due to invalid IL or missing references) //IL_0449: Unknown result type (might be due to invalid IL or missing references) //IL_045f: Unknown result type (might be due to invalid IL or missing references) //IL_0464: Unknown result type (might be due to invalid IL or missing references) //IL_0469: Unknown result type (might be due to invalid IL or missing references) //IL_0476: Unknown result type (might be due to invalid IL or missing references) //IL_047b: Unknown result type (might be due to invalid IL or missing references) //IL_0482: Unknown result type (might be due to invalid IL or missing references) //IL_0483: Unknown result type (might be due to invalid IL or missing references) //IL_0488: Unknown result type (might be due to invalid IL or missing references) //IL_048d: Unknown result type (might be due to invalid IL or missing references) //IL_0494: 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_04a7: Unknown result type (might be due to invalid IL or missing references) //IL_04ac: Unknown result type (might be due to invalid IL or missing references) //IL_04b1: Unknown result type (might be due to invalid IL or missing references) //IL_04b8: Unknown result type (might be due to invalid IL or missing references) //IL_04b9: Unknown result type (might be due to invalid IL or missing references) //IL_04be: 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_032d: 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_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_03df: Unknown result type (might be due to invalid IL or missing references) //IL_03e4: 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_04d8: Unknown result type (might be due to invalid IL or missing references) //IL_04da: Unknown result type (might be due to invalid IL or missing references) //IL_04dc: 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_04fa: Unknown result type (might be due to invalid IL or missing references) //IL_04fe: Unknown result type (might be due to invalid IL or missing references) //IL_0503: Unknown result type (might be due to invalid IL or missing references) //IL_0595: Unknown result type (might be due to invalid IL or missing references) //IL_059a: Unknown result type (might be due to invalid IL or missing references) //IL_059c: Unknown result type (might be due to invalid IL or missing references) //IL_05b0: Unknown result type (might be due to invalid IL or missing references) //IL_05c7: Unknown result type (might be due to invalid IL or missing references) //IL_05c8: Unknown result type (might be due to invalid IL or missing references) //IL_05c9: Unknown result type (might be due to invalid IL or missing references) //IL_05ce: Unknown result type (might be due to invalid IL or missing references) //IL_05e0: Unknown result type (might be due to invalid IL or missing references) //IL_05e5: Unknown result type (might be due to invalid IL or missing references) //IL_05ea: Unknown result type (might be due to invalid IL or missing references) //IL_066d: Unknown result type (might be due to invalid IL or missing references) //IL_0677: Unknown result type (might be due to invalid IL or missing references) //IL_068b: Unknown result type (might be due to invalid IL or missing references) //IL_0690: Unknown result type (might be due to invalid IL or missing references) //IL_0691: Unknown result type (might be due to invalid IL or missing references) //IL_0692: Unknown result type (might be due to invalid IL or missing references) //IL_0697: Unknown result type (might be due to invalid IL or missing references) //IL_06a9: Unknown result type (might be due to invalid IL or missing references) //IL_06ae: Unknown result type (might be due to invalid IL or missing references) Stopwatch stopwatch = Stopwatch.StartNew(); Quaternion val = Frame(market); Quaternion val2 = Quaternion.Inverse(val); Vector3 position = ((Component)market).transform.position; Vector3 val3 = Vector3.zero; Vector3 val4 = Vector3.zero; for (int i = 0; i < 8; i++) { Vector3 val5 = val2 * (((Component)area).transform.TransformPoint(area.center + Vector3.Scale(area.size * 0.5f, Corner(i))) - position); val3 = Vector3.Min(val3, val5); val4 = Vector3.Max(val4, val5); } Bounds bounds = ((Collider)area).bounds; float y = ((Bounds)(ref bounds)).max.y + 0.1f; bounds = ((Collider)area).bounds; float num = ((Bounds)(ref bounds)).min.y - 1f; bool queriesHitBackfaces = Physics.queriesHitBackfaces; try { Physics.queriesHitBackfaces = false; RaycastHit value; for (int j = Mathf.CeilToInt(val3.x / 0.5f); j <= Mathf.FloorToInt(val4.x / 0.5f); j++) { for (int k = Mathf.CeilToInt(val3.z / 0.5f); k <= Mathf.FloorToInt(val4.z / 0.5f); k++) { Vector3 val6 = position + val * new Vector3((float)j * 0.5f, 0f, (float)k * 0.5f); val6.y = y; for (int l = 0; l < 16; l++) { if (!(val6.y > num)) { break; } RaycastHit? val7 = First(val6, Vector3.down, val6.y - num); if (!val7.HasValue) { break; } value = val7.Value; if (((RaycastHit)(ref value)).normal.y >= WalkNormal) { int x = j; int z = k; value = val7.Value; Add(x, z, ((RaycastHit)(ref value)).point.y - position.y); } value = val7.Value; val6.y = ((RaycastHit)(ref value)).point.y - 0.02f; } } } Vector3 val8 = position + Vector3.up * 0.1f; Vector3 down = Vector3.down; float y2 = position.y; bounds = ((Collider)area).bounds; RaycastHit? val9 = First(val8, down, Mathf.Max(4f, y2 - ((Bounds)(ref bounds)).min.y + 1f)); if (val9.HasValue) { value = val9.Value; if (!(((RaycastHit)(ref value)).normal.y < WalkNormal)) { value = val9.Value; float num2 = ((RaycastHit)(ref value)).point.y - position.y; if (cells.TryGetValue(Key(0, 0), out var value2)) { foreach (int item in value2) { if (Mathf.Abs(Points[item].y - num2) < 0.05f) { Start = item; } } } if (Start < 0) { Start = Points.Count; Add(0, 0, num2); } Physics.queriesHitBackfaces = true; for (int m = 0; m < Points.Count; m++) { RaycastHit? val10 = First(World(m, position, val) + Vector3.up * 0.02f, Vector3.up, 1.05f); float num3; if (!val10.HasValue) { num3 = 1f; } else { value = val10.Value; num3 = Mathf.Min(1f, ((RaycastHit)(ref value)).distance - 0.03f); } float num4 = num3; Heights.Add((num4 < 0.1f) ? 0f : num4); Reached.Add(item: false); } Vector3 val11 = World(Start, position, val) + Vector3.up * Heights[Start]; int num5 = 0; Vector3[] array = (Vector3[])(object)new Vector3[5] { Vector3.up, val * Vector3.right, val * Vector3.left, val * Vector3.forward, val * Vector3.back }; foreach (Vector3 val12 in array) { RaycastHit? val13 = First(val11, val12, 200f); if (val13.HasValue) { value = val13.Value; if (Vector3.Dot(((RaycastHit)(ref value)).normal, val12) > 0f) { num5++; } } } if (Heights[Start] <= 0f || num5 == 5) { Sealed = "the start is sealed inside a solid"; return; } Queue<int> queue = new Queue<int>(); Reached[Start] = true; queue.Enqueue(Start); ReachedCount = 1; while (queue.Count > 0) { int num6 = queue.Dequeue(); Vector3 val14 = Points[num6]; int num7 = Mathf.RoundToInt(val14.x / 0.5f); int num8 = Mathf.RoundToInt(val14.z / 0.5f); Vector3 a = World(num6, position, val) + Vector3.up * Heights[num6]; for (int num9 = -1; num9 <= 1; num9++) { for (int num10 = -1; num10 <= 1; num10++) { if ((num9 == 0 && num10 == 0) || !cells.TryGetValue(Key(num7 + num9, num8 + num10), out var value3)) { continue; } foreach (int item2 in value3) { if (!Reached[item2] && Heights[item2] > 0f && Mathf.Abs(Points[item2].y - val14.y) <= 1f && Clear(a, World(item2, position, val) + Vector3.up * Heights[item2])) { Reached[item2] = true; ReachedCount++; queue.Enqueue(item2); } } } } } if (ReachedCount < 2) { Sealed = "the walk reaches no neighbour of the start"; } return; } } Sealed = "no floor under the market's origin"; } finally { Physics.queriesHitBackfaces = queriesHitBackfaces; BuildMs = stopwatch.Elapsed.TotalMilliseconds; } } internal bool Steps(Vector3 floor, Vector3 origin, Quaternion frame) { //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_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_0012: 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_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: 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_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Quaternion.Inverse(frame) * (floor - origin); int num = Mathf.RoundToInt(val.x / 0.5f); int num2 = Mathf.RoundToInt(val.z / 0.5f); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (!cells.TryGetValue(Key(num + i, num2 + j), out var value)) { continue; } foreach (int item in value) { if (Reached[item] && Mathf.Abs(Points[item].y - val.y) <= 1f && Clear(floor + Vector3.up * Heights[item], World(item, origin, frame) + Vector3.up * Heights[item])) { return true; } } } } 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 readonly Dictionary<int, Rect[]> Hidden = new Dictionary<int, Rect[]> { { 1, (Rect[])(object)new Rect[3] { Rect.MinMaxRect(7.75f, 7.75f, 1000f, 1000f), Rect.MinMaxRect(4.75f, 8.75f, 1000f, 1000f), Rect.MinMaxRect(9.25f, 1f, 1000f, 7.75f) } } }; internal static float MaxTilt = 30f; internal static float TipMargin = 4f; internal static float MaxStack = float.PositiveInfinity; internal static float MaxDip = 1f; internal static readonly Dictionary<IslandMarket, WalkMap> Walks = new Dictionary<IslandMarket, WalkMap>(); 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 bool InHidden(IslandMarket market, Vector3 center) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) if (!Hidden.TryGetValue(market.GetPortIndex(), out var value)) { return false; } Vector3 local = Quaternion.Inverse(Frame(market)) * (center - ((Component)market).transform.position); return value.Any((Rect a) => ((Rect)(ref a)).Contains(new Vector2(local.x, local.z))); } 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_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: Unknown result type (might be due to invalid IL or missing references) //IL_02a8: Unknown result type (might be due to invalid IL or missing references) //IL_02aa: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: 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_0212: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_022e: 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_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02ee: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_0304: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references)