Decompiled source of TentandPlank v1.1.8

BepInEx/plugins/TentandPlank/TentandPlank.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Crest;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using cakeslice;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("TentandPlank.Tests")]
[assembly: InternalsVisibleTo("TentandPlank.QA")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("TentandPlank")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.8.0")]
[assembly: AssemblyInformationalVersion("1.1.8")]
[assembly: AssemblyProduct("TentandPlank")]
[assembly: AssemblyTitle("TentandPlank")]
[assembly: AssemblyVersion("1.1.8.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 TentandPlank
{
	[BepInPlugin("DogEggz.TentandPlank", "Tent and Plank", "1.1.8")]
	[BepInIncompatibility("DogEggz.EconomyOverhaul")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "DogEggz.TentandPlank";

		public const string Version = "1.1.8";

		internal const string Namespace = "TentandPlank";

		internal static ManualLogSource Log;

		internal static Plugin Instance;

		private Harmony harmony;

		private void Awake()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			try
			{
				Settings.Bind(((BaseUnityPlugin)this).Config);
				CargoStainMaterial.Load();
				harmony = new Harmony("DogEggz.TentandPlank");
				harmony.PatchAll(typeof(Plugin).Assembly);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Tent and Plank 1.1.8 loaded.");
			}
			catch (Exception ex)
			{
				Harmony obj = harmony;
				if (obj != null)
				{
					obj.UnpatchSelf();
				}
				((BaseUnityPlugin)this).Logger.LogError((object)("Tent and Plank could not initialize. No partial patch set retained. " + ex));
				((Behaviour)this).enabled = false;
			}
		}

		private void Update()
		{
			WoodPlanks.Tick();
		}

		private IEnumerator Start()
		{
			yield return null;
			yield return null;
			BoatDamageWater[] array = Object.FindObjectsOfType<BoatDamageWater>();
			for (int i = 0; i < array.Length; i++)
			{
				BoatWater.Register(array[i]);
			}
			WetOutline.Hook();
		}

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

		private static readonly Dictionary<(Type, string), MethodInfo> methods = new Dictionary<(Type, string), MethodInfo>();

		public static FieldInfo Find(Type type, string name)
		{
			(Type, string) key = (type, name);
			if (!cache.TryGetValue(key, out var value))
			{
				Dictionary<(Type, string), FieldInfo> dictionary = cache;
				FieldInfo obj = AccessTools.Field(type, name) ?? throw new MissingFieldException(type.FullName + "." + name);
				value = obj;
				dictionary[key] = 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)
		{
			(Type, string) key = (obj.GetType(), name);
			if (!methods.TryGetValue(key, out var value))
			{
				value = (methods[key] = AccessTools.Method(obj.GetType(), name, (Type[])null, (Type[])null));
			}
			return value.Invoke(obj, args);
		}
	}
	internal static class Embedded
	{
		internal static IEnumerable<string[]> Csv(string name, bool header = true)
		{
			using StreamReader reader = new StreamReader(typeof(Embedded).Assembly.GetManifestResourceStream("TentandPlank.Data." + name));
			if (header)
			{
				reader.ReadLine();
			}
			string text;
			while ((text = reader.ReadLine()) != null)
			{
				yield return text.Split(new char[1] { ',' });
			}
		}
	}
	internal static class Settings
	{
		internal enum PlankCount
		{
			FeeEquivalent,
			FixedHalfPercent
		}

		internal enum WaterSpeed
		{
			Quarter,
			Half,
			ThreeQuarters,
			Normal
		}

		internal enum DryingSpeedChoice
		{
			AsWaterDamage,
			Normal,
			OneAndHalf,
			Double,
			TwoAndHalf,
			Triple
		}

		internal static ConfigEntry<bool> WaterDamage;

		internal static ConfigEntry<bool> WaterDamageHint;

		internal static ConfigEntry<bool> CoverHint;

		internal static ConfigEntry<bool> TarpWear;

		internal static ConfigEntry<bool> CargoDamageHint;

		internal static ConfigEntry<bool> FragileCargo;

		internal static ConfigEntry<string> TarpColour;

		internal static ConfigEntry<string> TarpColourCode;

		internal static ConfigEntry<KeyboardShortcut> BraceKey;

		internal static ConfigEntry<KeyboardShortcut> PoleLongerKey;

		internal static ConfigEntry<KeyboardShortcut> PoleShorterKey;

		internal static ConfigEntry<KeyboardShortcut> PoleThickerKey;

		internal static ConfigEntry<KeyboardShortcut> PoleThinnerKey;

		internal static ConfigEntry<KeyboardShortcut> PlankLongerKey;

		internal static ConfigEntry<KeyboardShortcut> PlankShorterKey;

		internal static ConfigEntry<KeyboardShortcut> PlankWiderKey;

		internal static ConfigEntry<KeyboardShortcut> PlankNarrowerKey;

		internal static ConfigEntry<KeyboardShortcut> PlankThickerKey;

		internal static ConfigEntry<KeyboardShortcut> PlankThinnerKey;

		internal static ConfigEntry<bool> ShowRodWeight;

		internal static ConfigEntry<int> HammerTime;

		internal static ConfigEntry<PlankCount> PlanksNeeded;

		internal static ConfigEntry<float> PlankRepairPercent;

		internal static ConfigEntry<WaterSpeed> WaterDamageSpeedOption;

		internal static ConfigEntry<DryingSpeedChoice> DryingSpeedOption;

		internal static ConfigEntry<int> LanternCoverOption;

		private static readonly string[] WaterSpeedNames = new string[4] { "0.25x", "0.5x", "0.75x", "1x" };

		private static readonly string[] DryingSpeedNames = new string[5] { "1x", "1.5x", "2x", "2.5x", "3x" };

		private static bool tarpWearWas = false;

		internal static ConfigEntry<bool> WetOutlineOption;

		internal static ConfigEntry<bool> DryingOutlineOption;

		internal static bool RodWeightShown => ShowRodWeight?.Value ?? false;

		internal static float HammerSeconds => HammerTime?.Value ?? 20;

		internal static bool FixedPlanks
		{
			get
			{
				if (PlanksNeeded != null)
				{
					return PlanksNeeded.Value == PlankCount.FixedHalfPercent;
				}
				return false;
			}
		}

		internal static double FixedRepairPercent => Rules.PlankRepairPercent(((double?)PlankRepairPercent?.Value) ?? 0.5);

		internal static double WaterDamageSpeed => Rules.WaterDamageSpeed((int)((WaterDamageSpeedOption != null) ? WaterDamageSpeedOption.Value : WaterSpeed.Normal));

		internal static double DryingSpeed => Rules.DryingSpeed((int)((DryingSpeedOption != null) ? DryingSpeedOption.Value : DryingSpeedChoice.AsWaterDamage), WaterDamageSpeed);

		internal static int LanternCover => LanternCoverOption?.Value ?? 70;

		internal static bool WaterEnabled => WaterDamage?.Value ?? false;

		internal static bool FragileEnabled => FragileCargo?.Value ?? false;

		internal static bool WaterHintEnabled => WaterDamageHint?.Value ?? true;

		internal static bool CoverHintEnabled => CoverHint?.Value ?? false;

		internal static bool CargoDamageHintEnabled => CargoDamageHint?.Value ?? true;

		internal static bool TarpWearing => TarpWear?.Value ?? false;

		internal static bool WetOutlineEnabled => WetOutlineOption?.Value ?? true;

		internal static bool DryingOutlineEnabled => DryingOutlineOption?.Value ?? true;

		private static void PlankCountButtons(ConfigEntryBase entry)
		{
			bool fixedPlanks = FixedPlanks;
			float num = (float)FixedRepairPercent;
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			bool flag = GUILayout.Toggle(!fixedPlanks, "Fixing fee equivalent", GUIStyle.op_Implicit("Button"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			bool flag2 = GUILayout.Toggle(fixedPlanks, "Fixed " + Rules.PercentText(num) + "% per plank", GUIStyle.op_Implicit("Button"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(160f) });
			float num2 = (float)Rules.PlankRepairPercent(GUILayout.HorizontalSlider(num, 0.5f, 10f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }));
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
			if (num2 != num)
			{
				PlankRepairPercent.Value = num2;
				PlanksNeeded.Value = PlankCount.FixedHalfPercent;
			}
			else if (flag2 && !fixedPlanks)
			{
				PlanksNeeded.Value = PlankCount.FixedHalfPercent;
			}
			else if (flag && fixedPlanks)
			{
				PlanksNeeded.Value = PlankCount.FeeEquivalent;
			}
		}

		private static void WaterSpeedButtons(ConfigEntryBase entry)
		{
			int value = (int)WaterDamageSpeedOption.Value;
			int num = GUILayout.Toolbar(value, WaterSpeedNames, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			if (num != value)
			{
				WaterDamageSpeedOption.Value = (WaterSpeed)num;
			}
		}

		private static void DryingSpeedButtons(ConfigEntryBase entry)
		{
			int value = (int)DryingSpeedOption.Value;
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			bool flag = GUILayout.Toggle(value == 0, "As water damage speed", GUIStyle.op_Implicit("Button"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			int num = GUILayout.Toolbar((value == 0) ? (-1) : (value - 1), DryingSpeedNames, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUILayout.EndVertical();
			if (flag && value != 0)
			{
				DryingSpeedOption.Value = DryingSpeedChoice.AsWaterDamage;
			}
			else if (num >= 0 && num != value - 1)
			{
				DryingSpeedOption.Value = (DryingSpeedChoice)(num + 1);
			}
		}

		internal static void Bind(ConfigFile config)
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Expected O, but got Unknown
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Expected O, but got Unknown
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Expected O, but got Unknown
			//IL_05e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ee: Expected O, but got Unknown
			//IL_0633: Unknown result type (might be due to invalid IL or missing references)
			//IL_063d: Expected O, but got Unknown
			WaterDamage = config.Bind<bool>("Cargo", "Enable water damage", false, "Cargo gets wet and loses value. Off: damage pauses, cargo at full value.");
			WaterDamageHint = config.Bind<bool>("Cargo", "Show water damage percentage", true, "Show cargo's water condition (100% to 0%) in its hint.");
			WaterDamageSpeedOption = config.Bind<WaterSpeed>("Cargo", "Water damage speed", WaterSpeed.Normal, new ConfigDescription("How fast cargo takes water damage.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					CustomDrawer = WaterSpeedButtons
				}
			}));
			DryingSpeedOption = config.Bind<DryingSpeedChoice>("Cargo", "Drying speed", DryingSpeedChoice.AsWaterDamage, new ConfigDescription("How fast wet cargo dries.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					CustomDrawer = DryingSpeedButtons
				}
			}));
			LanternCoverOption = config.Bind<int>("Cargo", "Lantern drying as % covered", 70, new ConfigDescription("Near a lit lantern, cargo dries as if this % covered. Big lantern: 20% less.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(20, 90), Array.Empty<object>()));
			LanternCoverOption.SettingChanged += delegate
			{
				Lanterns.Changed();
			};
			CoverHint = config.Bind<bool>("Cargo", "Show cover percentage", false, "Show how much of the cargo's top is covered, in its hint.");
			WetOutlineOption = config.Bind<bool>("Cargo", "Deep blue outline on wet cargo", true, "Outline cargo deep blue while it is getting wet.");
			DryingOutlineOption = config.Bind<bool>("Cargo", "Yellow outline for drying cargo", true, "Outline cargo yellow while it is drying.");
			FragileCargo = config.Bind<bool>("Cargo", "Enable fragile cargo", false, "Hull impacts damage fragile cargo. Off: damage pauses.");
			CargoDamageHint = config.Bind<bool>("Cargo", "Show cargo damage percentage", true, "Show fragile cargo's damage (0% to 100%) in its hint.");
			BraceKey = Key("Wood pole", "Brace key", (KeyCode)104, "Brace key", 6, "Brace a held pole; with the pick-up key it pushes boats, docks or the sea bed.");
			PoleLongerKey = Key("Wood pole", "Longer key", (KeyCode)113, "Increase length", 5, "Lengthen a held or attached (not nailed) pole by 0.1 m. With the mouse wheel: lean it.");
			PoleShorterKey = Key("Wood pole", "Shorter key", (KeyCode)101, "Decrease length", 4, "Shorten a held or attached (not nailed) pole by 0.1 m.");
			PoleThickerKey = Key("Wood pole", "Thicker key", (KeyCode)111, "Increase thickness", 3, "Thicken a held or attached (not nailed) pole.");
			PoleThinnerKey = Key("Wood pole", "Thinner key", (KeyCode)108, "Decrease thickness", 2, "Thin a held or attached (not nailed) pole.");
			PlankLongerKey = Key("Wood plank", "Longer key", (KeyCode)113, "Increase length", 6, "Lengthen a plank being placed or attached (not nailed) by 0.1 m.");
			PlankShorterKey = Key("Wood plank", "Shorter key", (KeyCode)101, "Decrease length", 5, "Shorten a plank being placed or attached (not nailed) by 0.1 m.");
			PlankWiderKey = Key("Wood plank", "Wider key", (KeyCode)111, "Increase width", 4, "Widen a plank being placed or attached (not nailed) by 0.05 m.");
			PlankNarrowerKey = Key("Wood plank", "Narrower key", (KeyCode)108, "Decrease width", 3, "Narrow a plank being placed or attached (not nailed) by 0.05 m.");
			PlankThickerKey = Key("Wood plank", "Thicker key", (KeyCode)105, "Increase thickness", 2, "Thicken a plank being placed or attached (not nailed) by 0.05 m.");
			PlankThinnerKey = Key("Wood plank", "Thinner key", (KeyCode)107, "Decrease thickness", 1, "Thin a plank being placed or attached (not nailed) by 0.05 m.");
			ShowRodWeight = config.Bind<bool>("Wood pole", "Show pole and plank weight", false, "Show a held pole's or plank's weight.");
			HammerTime = config.Bind<int>("Wood plank", "Hammering time", 20, new ConfigDescription("Seconds to hammer in one plank. Halved on a caulked hull.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 20), Array.Empty<object>()));
			PlanksNeeded = config.Bind<PlankCount>("Wood plank", "Planks needed", PlankCount.FeeEquivalent, new ConfigDescription("Planks per 1% of hull: as the shipyard's fee, or a fixed % per plank.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					CustomDrawer = PlankCountButtons
				}
			}));
			PlankRepairPercent = config.Bind<float>("Wood plank", "Hull repaired per plank", 0.5f, new ConfigDescription("Hull % one plank repairs on Fixed.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 10f), new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Browsable = false
				}
			}));
			TarpWear = config.Bind<bool>("Canvas", "Tarp wearing", false, "Tied tarps lose 10 health a day and tear at 0. Off: wear pauses.");
			WaterDamage.SettingChanged += delegate
			{
				foreach (CargoCondition item in CargoCondition.Active)
				{
					item.RefreshSettings();
				}
			};
			WaterDamageHint.SettingChanged += delegate
			{
				foreach (CargoCondition item2 in CargoCondition.Active)
				{
					item2.RefreshHint();
				}
			};
			CoverHint.SettingChanged += delegate
			{
				foreach (CargoCondition item3 in CargoCondition.Active)
				{
					item3.RefreshHint();
				}
			};
			CargoDamageHint.SettingChanged += delegate
			{
				foreach (CargoCondition item4 in CargoCondition.Active)
				{
					item4.RefreshHint();
				}
			};
			FragileCargo.SettingChanged += delegate
			{
				foreach (CargoCondition item5 in CargoCondition.Active)
				{
					item5.RefreshHint();
					item5.RefreshAppearance();
				}
			};
			TarpWear.SettingChanged += delegate
			{
				tarpWearWas = TarpCloth.Rebase(tarpWearWas);
			};
			tarpWearWas = TarpWear.Value;
			TarpColour = config.Bind<string>("Canvas", "Tarp colour", "Default gray", new ConfigDescription("Color new tarps are tied in. R on a tarp's knot gives it this color, then the next.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					DispName = "Tarp color",
					CustomDrawer = TarpColours.Draw
				}
			}));
			TarpColourCode = config.Bind<string>("Canvas", "Tarp colour code", "#FFFFFF", new ConfigDescription("Custom Color as #RRGGBB.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					DispName = "Tarp color code",
					Browsable = false
				}
			}));
			TarpColours.ReadOld();
			ConfigEntry<KeyboardShortcut> Key(string section, string key, KeyCode code, string shown, int order, string tip)
			{
				//IL_0009: 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_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Expected O, but got Unknown
				return config.Bind<KeyboardShortcut>(section, key, new KeyboardShortcut(code, Array.Empty<KeyCode>()), new ConfigDescription(tip, (AcceptableValueBase)null, new object[1]
				{
					new ConfigurationManagerAttributes
					{
						DispName = shown,
						Order = order
					}
				}));
			}
		}
	}
	internal sealed class ConfigurationManagerAttributes
	{
		public Action<ConfigEntryBase> CustomDrawer;

		public bool? HideDefaultButton;

		public bool? Browsable;

		public string DispName;

		public int? Order;
	}
	internal static class Notice
	{
		internal const float Fill = 0.92f;

		private static float width;

		internal static void Show(string text)
		{
			if (Object.op_Implicit((Object)(object)NotificationUi.instance))
			{
				NotificationUi.instance.ShowNotification(Wrap(text));
			}
		}

		internal static string Wrap(string text)
		{
			NotificationUi instance = NotificationUi.instance;
			TextMesh mesh = (Object.op_Implicit((Object)(object)instance) ? Fields.Get<TextMesh>(instance, "text") : null);
			if (!Object.op_Implicit((Object)(object)mesh) || !Object.op_Implicit((Object)(object)mesh.font) || string.IsNullOrEmpty(text))
			{
				return text;
			}
			if (width <= 0f)
			{
				width = BoxWidth(instance, mesh) * 0.92f;
			}
			if (width <= 0f)
			{
				return text;
			}
			return string.Join("\n", (from line in text.Split(new char[1] { '\n' })
				select WrapLine(mesh, line)).ToArray());
		}

		private static float Measure(TextMesh mesh, string line)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			mesh.font.RequestCharactersInTexture(line, mesh.fontSize, mesh.fontStyle);
			float num = 0f;
			CharacterInfo val = default(CharacterInfo);
			foreach (char c in line)
			{
				if (mesh.font.GetCharacterInfo(c, ref val, mesh.fontSize, mesh.fontStyle))
				{
					num += (float)((CharacterInfo)(ref val)).advance * 0.1f * mesh.characterSize;
				}
			}
			return num;
		}

		private static string WrapLine(TextMesh mesh, string line)
		{
			List<string> list = new List<string>();
			string text = "";
			string[] array = line.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
			foreach (string text2 in array)
			{
				string text3 = ((text.Length == 0) ? text2 : (text + " " + text2));
				if (text.Length > 0 && Measure(mesh, text3) > width)
				{
					list.Add(text);
					text = text2;
				}
				else
				{
					text = text3;
				}
			}
			if (text.Length > 0)
			{
				list.Add(text);
			}
			return string.Join("\n", list.ToArray());
		}

		private static float BoxWidth(NotificationUi ui, TextMesh mesh)
		{
			//IL_005f: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Fields.Get<GameObject>(ui, "UI");
			if (!Object.op_Implicit((Object)(object)val))
			{
				return 0f;
			}
			float num = 0f;
			MeshFilter[] componentsInChildren = val.GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val2 in componentsInChildren)
			{
				if ((Object)(object)((Component)val2).gameObject != (Object)(object)((Component)mesh).gameObject && Object.op_Implicit((Object)(object)val2.sharedMesh))
				{
					Bounds bounds = val2.sharedMesh.bounds;
					if (((Bounds)(ref bounds)).size.x * Scale(((Component)val2).transform, val.transform) > num)
					{
						bounds = val2.sharedMesh.bounds;
						num = ((Bounds)(ref bounds)).size.x * Scale(((Component)val2).transform, val.transform);
					}
				}
			}
			float num2 = Scale(((Component)mesh).transform, val.transform);
			if (!(num2 > 0f))
			{
				return 0f;
			}
			return num / num2;
		}

		private static float Scale(Transform t, Transform root)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			float num = 1f;
			while (Object.op_Implicit((Object)(object)t) && (Object)(object)t != (Object)(object)root)
			{
				num *= Mathf.Abs(t.localScale.x);
				t = t.parent;
			}
			return num;
		}
	}
	public static class Rules
	{
		public struct PlankShape
		{
			public int look;

			public int length;

			public int width;

			public int grid;

			public int thick;

			public bool end;
		}

		public enum PalletLoad
		{
			None,
			LargeCrate,
			StandardCrate,
			SmallCrate,
			LargePackage,
			MediumPackage,
			StandardPackage,
			SmallPackage
		}

		private static readonly float[] CrackCuts = new float[11]
		{
			0.8471f, 0.5725f, 0.4824f, 0.3804f, 0.2941f, 0.2275f, 0.1647f, 0.1098f, 0.0745f, 0.0471f,
			0.0353f
		};

		public const double ImmersionPerHour = 12.5;

		public const double RainAtImmersionRate = 8.0;

		public const float RainThreshold = 0.1f;

		public const float RuinedCondition = 19.5f;

		public const float DryingCeiling = 80f;

		public const float LuxuryDryingCeiling = 50f;

		public const double ClearDayDryingPerHour = 1.4457831325301205;

		public const double ImmersionStart = 0.14;

		public const double HalfLight = 0.2;

		public const int LanternCoverLeast = 20;

		public const int LanternCoverMost = 90;

		public const int LanternCoverDefault = 70;

		public const int BigLanternCoverLess = 20;

		public const int BigLanternPrefab = 133;

		public static readonly double[] WaterDamageSpeeds = new double[4] { 0.25, 0.5, 0.75, 1.0 };

		public static readonly double[] DryingSpeeds = new double[6] { 0.0, 1.0, 1.5, 2.0, 2.5, 3.0 };

		public const float WaterHoldSeconds = 10f;

		public const int OpenedBarrelPrice = 25;

		public static readonly Color WetOutlineColor = new Color(0.05f, 0.15f, 0.75f);

		public static readonly Color DryingOutlineColor = new Color(1f, 0.75f, 0.1f);

		public const float TarpFullHealth = 100f;

		public const float TarpWearPerDay = 10f;

		public const float TarpRainPerArea = 0.006281407f;

		public const float TarpRainShipCap = 0.2f;

		public const string TarpDefault = "Default gray";

		public const string TarpCustom = "Custom Color";

		public const string TarpWeathered = "Weathered grey";

		public const string TarpCode = "Colour code";

		public static readonly string[] SailColourNames = new string[24]
		{
			"Grey", "Brick red", "Terracotta", "Umber", "Plum", "Dark red", "Ochre", "Sand", "Light blue", "Blue",
			"Navy", "Light grey", "Pale rose", "Sage", "Slate", "Dusty brown", "Charcoal", "White", "Grey teal", "Sky blue",
			"Turquoise", "Green", "Pink", "Lavender"
		};

		public static readonly string[] TarpColourChoices = new string[1] { "Default gray" }.Concat(SailColourNames.Select((string n, int i) => "Sail colour " + (i + 1) + ": " + n)).Concat(new string[1] { "Custom Color" }).ToArray();

		public const float TarpTie = 0.01f;

		public const double PlankRepairLeast = 0.5;

		public const double PlankRepairMost = 10.0;

		public const double PlankRepairStep = 0.5;

		public const int PlankLooks = 24;

		public const int PlankLengthCodes = 37;

		public const int PlankWidthCodes = 15;

		public const int PlankMinWidthSteps = -2;

		public const int PlankMaxWidthSteps = 12;

		public const int PlankGridSizes = 20;

		public const float PlankLength0 = 0.872f;

		public const float PlankWidth0 = 0.152f;

		public const float PlankThickness = 0.045f;

		public const float PlankMass0 = 5f;

		public const int PlankBundleCount = 8;

		public const float PlankBundleMass = 40f;

		public const float FloatPerLb = 1.25f;

		public const float SurfaceFloat = 2.15f;

		public const float PlankMinLength = 0.5f;

		public const float PlankMaxLength = 4f;

		public const float PlankLengthStep = 0.1f;

		public const float PlankWidthStep = 0.25f;

		public const float PlankGridStep = 0.05f;

		public const int PlankMaxThickSteps = 20;

		public const int PlankGridCodes = 21;

		public const int PlankCodeSpan = 26640;

		public const int PlankTopCode = 11748239;

		public const float PoleMin = 0.2f;

		public const float PoleMax = 8f;

		public const float PoleStep = 0.1f;

		public const float PoleShopLength = 2f;

		public const float PoleLbPerMetre = 2f;

		public const float PolePush = 1.25f;

		public const float PoleFender = 1.908f;

		public const double PoleStrip = 3.4;

		public const int PoleValue = 60;

		public const int PoleBundleCount = 4;

		public const int PoleBundleValue = 240;

		public const int PoleMaxDiameterSteps = 45;

		public const float PoleDiameterStep = 0.2f;

		public const float PoleCodeSpan = 10f;

		public const int BundleHundredthsKicia = 10;

		public const int BundleHundredthsElsewhere = 12;

		public const int PalletHundredthsKicia = 20;

		public const int PalletHundredthsElsewhere = 24;

		public const int KiciaPort = 22;

		public const float PalletWidth = 1.45f;

		public const float PalletDepth = 1.28f;

		public const float PalletHeight = 0.25f;

		public const float PalletMass = 45f;

		public const float PalletLumber = 0.125f;

		public const int PalletValue = 750;

		public const float HalfDepth = 0.64f;

		public const float HalfMass = 22.5f;

		public const float HalfMark = -645f;

		public const int HalfValue = 375;

		public const int HalfPlanks = 5;

		public const float PalletTopBoards = 0.04f;

		public const float PalletShade = 0.85f;

		public const float RopeHalf = 0.0125f;

		public const float RopeOpening = 0.295f;

		public const float RopeBand = 0.55f;

		public const float HalfRopeOpening = 0.025f;

		public const int VendorPallets = 8;

		public const int VendorPlankBundles = 12;

		public const int VendorPoleBundles = 9;

		public const int KiciaPoleBundles = 6;

		public const float PalletStep = 0.252f;

		public const float PlankBundleStep = 0.119f;

		public const float PlankBundleAcross = 0.34f;

		public const float PoleBundleStep = 0.2f;

		public const float PlankRowsZ = 1.77f;

		public const float PoleRowsZ = 2.51f;

		public static float PoleBundleMass => PoleMass(2.0) * 4f;

		public static double Clamp(double x, double lo, double hi)
		{
			return Math.Max(lo, Math.Min(hi, x));
		}

		public static int Round(double x)
		{
			return checked((int)Math.Round(x, MidpointRounding.ToEven));
		}

		public static bool StaleSave(double savedHour, double gameHour)
		{
			if (savedHour > 0.0)
			{
				return Math.Abs(savedHour - gameHour) > 0.01;
			}
			return false;
		}

		public static float CrackCut(int damagePercent)
		{
			if (damagePercent <= 0)
			{
				return 2f;
			}
			float num = (float)Math.Min(100, damagePercent) / 100f;
			if (num <= 0.1f)
			{
				return CrackCuts[0] + (CrackCuts[1] - CrackCuts[0]) * (num - 0.01f) / 0.09f;
			}
			float num2 = num * 10f;
			int num3 = Math.Min(9, (int)num2);
			return CrackCuts[num3] + (CrackCuts[num3 + 1] - CrackCuts[num3]) * (num2 - (float)num3);
		}

		public static int CrackGrain(string mesh)
		{
			switch (mesh)
			{
			default:
				return -1;
			case "huge_crate":
			case "very_big_crate":
				return 51;
			case "crate":
				return 0;
			}
		}

		public static double ConditionFactor(double health, bool alcohol, bool exempt = false)
		{
			health = Clamp(health, 0.0, 100.0);
			if (!exempt && !(alcohol ? (health > 0.0) : (health >= 90.0)))
			{
				if (!alcohol)
				{
					return 0.1 + health / 100.0;
				}
				return 0.1;
			}
			return 1.0;
		}

		public static bool Ruined(double health)
		{
			return health < 19.5;
		}

		public static float Ceiling(int good)
		{
			GoodRow goodRow = Content.Good(good);
			if (goodRow == null || goodRow.Profile != PriceProfile.Luxury)
			{
				return 80f;
			}
			return 50f;
		}

		public static bool CargoGood(int good)
		{
			return Content.Good(good)?.Cargo ?? false;
		}

		public static float EffectiveRain(float raw)
		{
			if (!float.IsNaN(raw) && !float.IsInfinity(raw) && !(raw < 0.1f))
			{
				return raw;
			}
			return 0f;
		}

		public static bool DamagingImmersion(double depth, double cargoHeight)
		{
			if (cargoHeight > 0.0 && depth > 0.0)
			{
				return depth >= cargoHeight * 0.14;
			}
			return false;
		}

		public static double RainDamagePerHour(double rain, double exposed)
		{
			return 12.5 * Math.Max(0.0, rain) / 8.0 * Clamp(exposed, 0.0, 1.0);
		}

		public static double OpenDryingPerHour(double clouds, double hour)
		{
			bool flag = hour >= 6.0 && hour < 17.0;
			bool flag2 = clouds > 2.0;
			return 1.4457831325301205 * ((!flag) ? (flag2 ? 0.5 : 0.75) : (flag2 ? 0.75 : 1.0));
		}

		public static double DryingPerHour(double exposed, double clouds, double hour)
		{
			return Clamp(exposed, 0.0, 1.0) * OpenDryingPerHour(clouds, hour);
		}

		public static int LanternCover(int option, bool big)
		{
			return Math.Min(90, Math.Max(20, option)) - (big ? 20 : 0);
		}

		public static double LanternDrying(int cover, double distance, double range)
		{
			if (!(range > 0.0) || !(distance <= 0.2 * range))
			{
				return 0.0;
			}
			return 1.0 - (double)Clamp(cover, 0, 100) / 100.0;
		}

		public static double WaterDamageSpeed(int choice)
		{
			return WaterDamageSpeeds[Math.Max(0, Math.Min(WaterDamageSpeeds.Length - 1, choice))];
		}

		public static double DryingSpeed(int choice, double waterDamageSpeed)
		{
			double num = DryingSpeeds[Math.Max(0, Math.Min(DryingSpeeds.Length - 1, choice))];
			if (!(num > 0.0))
			{
				return waterDamageSpeed;
			}
			return num;
		}

		public static float AdvanceCondition(float health, double gameHours, bool noDry, bool waterContact, bool damagingWater, double rain, bool coverKnown, double exposed, double clouds, double hour, float ceiling = 80f, double damageSpeed = 1.0, double dryingSpeed = 1.0, double lantern = 0.0)
		{
			gameHours = Math.Max(0.0, gameHours);
			double num = ((damagingWater ? 12.5 : 0.0) + (coverKnown ? RainDamagePerHour(rain, exposed) : 0.0)) * Math.Max(0.0, damageSpeed);
			if (num > 0.0)
			{
				return (float)Math.Max(0.0, (double)health - gameHours * num);
			}
			if (damagingWater || (coverKnown && RainDamagePerHour(rain, exposed) > 0.0))
			{
				return health;
			}
			if (waterContact || rain > 0.0 || noDry || !coverKnown || Ruined(health) || health >= ceiling)
			{
				return health;
			}
			return (float)Math.Min(ceiling, (double)health + gameHours * DryingPerHour(Math.Max(exposed, lantern), clouds, hour) * Math.Max(0.0, dryingSpeed));
		}

		public static bool WettingNow(bool damagingWater, double rain, bool coverKnown, double exposed)
		{
			if (!damagingWater)
			{
				if (coverKnown && rain > 0.0)
				{
					return exposed > 0.0;
				}
				return false;
			}
			return true;
		}

		public static bool Opened(float units, float full)
		{
			if (full > 0f)
			{
				return units < full;
			}
			return false;
		}

		public static bool OutOfTrade(bool opened, float health)
		{
			if (opened)
			{
				return health <= 0f;
			}
			return false;
		}

		public static string HintSuffix(string description, string lookText, int percent, bool loan, int cover = -1, int damage = -1)
		{
			List<string> list = new List<string>(3);
			if (percent >= 0)
			{
				list.Add("Water Damage: " + percent.ToString(CultureInfo.InvariantCulture) + "%");
			}
			if (cover >= 0)
			{
				list.Add("Cover: " + cover.ToString(CultureInfo.InvariantCulture) + "%");
			}
			if (damage >= 0)
			{
				list.Add("Cargo Damage: " + damage.ToString(CultureInfo.InvariantCulture) + "%");
			}
			if (loan)
			{
				list.Add("Respondentia");
			}
			if (list.Count == 0)
			{
				return "";
			}
			int num = TextLines(lookText);
			int num2 = TextLines(description);
			int num3 = Math.Max(1, num - num2 + 1) + Math.Max(0, list.Count - 2);
			if (num >= 2)
			{
				num3 = Math.Max(num3, 3 + (list.Count - 1) + ((num - 2) * 10 + 2) / 3 - Math.Max(1, num2) + 1);
			}
			return new string('\n', num3) + string.Join("\n", list);
		}

		private static int TextLines(string text)
		{
			if (string.IsNullOrEmpty(text))
			{
				return 0;
			}
			int num = 1;
			for (int i = 0; i < text.Length; i++)
			{
				if (text[i] == '\n')
				{
					num++;
				}
			}
			return num;
		}

		public static float RepairedHealth(float tarp, float pack)
		{
			return Math.Min(100f, Math.Max(0f, Finite(tarp)) + Math.Max(0f, Finite(pack)));
		}

		public static float TarpHealth(float startHealth, double startClock, double now, bool wearing)
		{
			return (float)Clamp(wearing ? ((double)Finite(startHealth) - 10.0 * Math.Max(0.0, now - startClock)) : ((double)Finite(startHealth)), 0.0, 100.0);
		}

		private static float Finite(float x)
		{
			if (!float.IsNaN(x) && !float.IsInfinity(x))
			{
				return x;
			}
			return 0f;
		}

		public static float TarpRain(float topArea, float sky)
		{
			return 0.006281407f * Math.Max(0f, Finite(topArea)) * Math.Max(0f, Math.Min(1f, Finite(sky)));
		}

		public static float ShipTarpRain(IEnumerable<float> cuts)
		{
			return Math.Min(0.2f, cuts.Sum((float c) => Math.Max(0f, Finite(c))));
		}

		public static string TarpChoice(string value)
		{
			if (!(value == "Weathered grey"))
			{
				if (!(value == "Colour code"))
				{
					if (Array.IndexOf(TarpColourChoices, value) <= 0)
					{
						return "Default gray";
					}
					return value;
				}
				return "Custom Color";
			}
			return "Default gray";
		}

		public static int TarpSailColour(string choice)
		{
			int num = Array.IndexOf(TarpColourChoices, TarpChoice(choice));
			if (num > 0)
			{
				if (num != TarpColourChoices.Length - 1)
				{
					return num - 1;
				}
				return -2;
			}
			return -1;
		}

		public static string TarpCodeText(string code)
		{
			string text = (code ?? "").Trim();
			if (!text.StartsWith("#", StringComparison.Ordinal))
			{
				return "#" + text;
			}
			return text;
		}

		public static string TarpColourOf(string choice, string code)
		{
			int num = TarpSailColour(choice);
			return num switch
			{
				-2 => TarpCodeText(code).ToUpperInvariant(), 
				-1 => "", 
				_ => (num + 1).ToString(CultureInfo.InvariantCulture), 
			};
		}

		public static string NextTarpColour(string colour, string choice, string code, out string nextChoice)
		{
			nextChoice = TarpChoice(choice);
			string text = TarpColourOf(nextChoice, code);
			if (colour != text)
			{
				return text;
			}
			nextChoice = TarpColourChoices[(Array.IndexOf(TarpColourChoices, nextChoice) + 1) % TarpColourChoices.Length];
			return TarpColourOf(nextChoice, code);
		}

		public static int TearSeed(float[] sides)
		{
			int num = 17;
			foreach (int item in from x in sides
				select (int)Math.Round(x * 10f) into x
				orderby x
				select x)
			{
				num = num * 31 + item;
			}
			return num;
		}

		public static int TarpClaim(IList<(float h, bool end, float dist)> c)
		{
			if (c == null || c.Count == 0)
			{
				return -1;
			}
			float num = c.Max(((float h, bool end, float dist) x) => x.h);
			int num2 = -1;
			for (int num3 = 0; num3 < c.Count; num3++)
			{
				if (!(c[num3].h < num - 0.01f) && (num2 < 0 || (c[num3].end && !c[num2].end) || (c[num3].end == c[num2].end && c[num3].dist < c[num2].dist)))
				{
					num2 = num3;
				}
			}
			return num2;
		}

		public static int WaterHintPercent(float health)
		{
			return Mathf.RoundToInt(100f - Mathf.Clamp(health, 0f, 100f));
		}

		public static bool FragileGood(int good)
		{
			return Content.Good(good)?.Fragile ?? false;
		}

		public static float FragileDamage(float impact, float hullAdded)
		{
			return Math.Min(100f, Math.Max(0f, impact) + Math.Max(0f, hullAdded) * 250f);
		}

		public static int DamagePercent(float impact)
		{
			return Mathf.RoundToInt(Mathf.Clamp(impact, 0f, 100f));
		}

		public static float IntactFactor(float impact)
		{
			return (100f - Mathf.Clamp(impact, 0f, 100f)) / 100f;
		}

		public static int PlanksPerPercent(int boatPrice, double capacity, double lumberValue)
		{
			double num = ((boatPrice > 0 && lumberValue > 0.0) ? ((double)boatPrice * 3.5 * 0.01 * capacity * 0.1 / (lumberValue / 128.0)) : (capacity / 120.0));
			if (!double.IsNaN(num) && !(num < 1.5))
			{
				return (int)Math.Min(1000000.0, Math.Round(num, MidpointRounding.AwayFromZero));
			}
			return 1;
		}

		public static double PlankRepairPercent(double percent)
		{
			if (!double.IsNaN(percent))
			{
				return Math.Max(0.5, Math.Min(10.0, Math.Round(percent / 0.5, MidpointRounding.AwayFromZero) * 0.5));
			}
			return 0.5;
		}

		public static string PercentText(double percent)
		{
			return percent.ToString("0.#", CultureInfo.InvariantCulture);
		}

		public static string HullHintFixed(double progress, double damage, double percent)
		{
			string[] array = HullHint(progress, damage, 1).Split(new char[1] { '\n' });
			return array[0] + "\n" + array[1] + "\nHull repaired per plank: " + PercentText(PlankRepairPercent(percent)) + "%";
		}

		public static bool Caulked(double oakum, double damage, double capacity)
		{
			if (capacity > 0.0 && damage > 0.0)
			{
				return oakum + 0.01 >= Math.Min(0.01, damage) * capacity;
			}
			return false;
		}

		public static string HullHint(double progress, double damage, int planks)
		{
			int num = ((progress >= 1.0) ? 100 : ((progress > 0.0) ? Math.Min(99, (int)Math.Floor(progress * 100.0 + 0.0001)) : 0));
			return num + "%\nShip hull damage: " + (damage * 100.0).ToString("0.00", CultureInfo.InvariantCulture) + "%\nPlanks required to fix 1%: " + planks;
		}

		public static int PlankLook(bool lumber, int i, int k, int j)
		{
			if (!lumber)
			{
				return 4 * i + 2 * k + j;
			}
			return 8 + 4 * i + j;
		}

		public static bool PlankTable(bool sold, bool nailed, bool placement, bool wallItemHeld)
		{
			if (sold && nailed && placement)
			{
				return !wallItemHeld;
			}
			return false;
		}

		public static float PlankCode(PlankShape s)
		{
			int num = Clamp(s.grid, 0, 20);
			int num2 = ((num <= 0) ? ((Clamp(s.width, -2, 12) + 15) % 15) : 0);
			return (float)(Clamp(s.look, 0, 23) + 24 * (Clamp(s.length, 0, 36) + 37 * (num2 + 15 * (s.end ? 1 : 0)))) + 26640f * (float)(Clamp(s.thick, 0, 20) + 21 * num);
		}

		public static PlankShape PlankDecode(double health)
		{
			if (double.IsNaN(health) || double.IsInfinity(health) || health < 0.0 || health > 11748239.0)
			{
				return default(PlankShape);
			}
			int num = (int)Math.Round(health);
			int look = num % 24;
			num /= 24;
			int length = num % 37;
			num /= 37;
			int num2 = num % 15;
			num /= 15;
			int num3 = num / 2;
			int num4 = num3 / 21;
			return new PlankShape
			{
				look = look,
				length = length,
				width = ((num4 <= 0) ? ((num2 <= 12) ? num2 : (num2 - 15)) : 0),
				grid = num4,
				end = (num % 2 == 1),
				thick = num3 % 21
			};
		}

		private static int Clamp(int x, int lo, int hi)
		{
			if (x >= lo)
			{
				if (x <= hi)
				{
					return x;
				}
				return hi;
			}
			return lo;
		}

		public static float PlankLength(int code)
		{
			if (code > 0 && code < 37)
			{
				return (float)Math.Round(0.5f + (float)(code - 1) * 0.1f, 1);
			}
			return 0.872f;
		}

		public static int PlankLengthStepped(int code, int step)
		{
			if (step == 0)
			{
				return code;
			}
			if (code <= 0 || code >= 37)
			{
				return (int)Math.Round((((step > 0) ? (Math.Ceiling(8.720000313354491) / 10.0) : (Math.Floor(8.719998313354493) / 10.0)) - 0.5) / 0.10000000149011612) + 1;
			}
			return Clamp(code + step, 1, 36);
		}

		public static float PlankWidth(int steps)
		{
			return 0.152f * (1f + 0.25f * (float)Clamp(steps, -2, 12));
		}

		public static float PlankGrid(int size)
		{
			return 0.05f * (float)Clamp(size, 1, 20);
		}

		public static float PlankWidth(PlankShape s)
		{
			if (s.grid <= 0)
			{
				return PlankWidth(s.width);
			}
			return PlankGrid(s.grid);
		}

		public static float PlankThick(int thick)
		{
			if (thick > 0)
			{
				return PlankGrid(thick);
			}
			return 0.045f;
		}

		public static float PlankThickScale(int thick)
		{
			return PlankThick(thick) / 0.045f;
		}

		public static PlankShape PlankWider(PlankShape s, int step)
		{
			if (step == 0)
			{
				return s;
			}
			double num = (double)PlankWidth(s) / 0.05000000074505806;
			int x = ((step > 0) ? ((int)Math.Floor(num + 0.0001) + 1) : ((int)Math.Ceiling(num - 0.0001) - 1));
			s.grid = Clamp(x, 1, 20);
			s.width = 0;
			return s;
		}

		public static float PlankMass(PlankShape s)
		{
			return 5f * PlankLength(s.length) * PlankWidth(s) / 0.132544f * PlankThickScale(s.thick);
		}

		public static bool PlankPlain(PlankShape s)
		{
			if (s.length == 0 && s.width == 0 && s.grid == 0 && s.thick == 0)
			{
				return !s.end;
			}
			return false;
		}

		public static string WeightText(float lb)
		{
			return ", " + ((lb < 99.95f) ? lb.ToString("F1", CultureInfo.InvariantCulture) : Math.Round(lb).ToString("F0", CultureInfo.InvariantCulture)) + " lb";
		}

		public static float RestLift(float side, float up, float halfSide, float halfUp, bool round)
		{
			if (!round)
			{
				return halfSide * Math.Abs(side) + halfUp * Math.Abs(up);
			}
			return halfSide * (float)Math.Sqrt(side * side + up * up);
		}

		public static double PoleGrain(double d)
		{
			return Mirrored(d, 3.4);
		}

		public static double Mirrored(double d, double strip)
		{
			double num = 2.0 * strip;
			double num2 = (d % num + num) % num;
			if (!(num2 <= strip))
			{
				return num - num2;
			}
			return num2;
		}

		public static double Eased(double t)
		{
			t = Clamp(t, 0.0, 1.0);
			return t * t * (3.0 - 2.0 * t);
		}

		public static int PoleTenths(double metres)
		{
			if (!double.IsNaN(metres) && !double.IsInfinity(metres))
			{
				return (int)Math.Round(Clamp(metres, 0.20000000298023224, 8.0) * 10.0);
			}
			return (int)Math.Round(20.0);
		}

		public static float PoleLength(double metres)
		{
			return (float)PoleTenths(metres) / 10f;
		}

		public static float PoleMass(double metres)
		{
			return PoleLength(metres) * 2f;
		}

		public static int PoleDiameterSteps(double health)
		{
			if (!double.IsNaN(health) && !double.IsInfinity(health) && !(health < 10.0))
			{
				return Clamp((int)Math.Floor(health / 10.0), 0, 45);
			}
			return 0;
		}

		public static float PoleLengthOf(double health)
		{
			return PoleLength(health - (double)(10f * (float)PoleDiameterSteps(health)));
		}

		public static float PoleCode(double metres, int steps)
		{
			return PoleLength(metres) + 10f * (float)Clamp(steps, 0, 45);
		}

		public static float PoleDiameterScale(int steps)
		{
			return 1f + 0.2f * (float)Clamp(steps, 0, 45);
		}

		public static float PoleMass(double metres, int steps)
		{
			float num = PoleDiameterScale(steps);
			return PoleMass(metres) * num * num;
		}

		public static int WoodHundredths(bool pallet, int port)
		{
			if (!pallet)
			{
				if (port != 22)
				{
					return 12;
				}
				return 10;
			}
			if (port != 22)
			{
				return 24;
			}
			return 20;
		}

		public static int WoodShare(int lumber, int hundredths)
		{
			return (int)Math.Ceiling((double)((long)lumber * (long)hundredths) / 100.0);
		}

		public static bool IsHalfMark(float health)
		{
			return health == -645f;
		}

		public static List<(string key, string what)> RodHintLines(bool pole, bool endMode, bool sizeFixed, string brace, string length = "Q/E", string width = "O/L", string thick = "I/K")
		{
			List<(string, string)> list = new List<(string, string)>();
			if (pole || endMode)
			{
				if (!sizeFixed)
				{
					list.AddRange(RodSizeLines(pole, length, width, thick));
				}
				list.Add((brace, pole ? "brace" : "repair mode"));
			}
			else
			{
				list.Add((brace, "placement mode"));
			}
			return list;
		}

		public static List<(string key, string what)> RodSizeLines(bool pole, string length = "Q/E", string width = "O/L", string thick = "I/K")
		{
			List<(string, string)> list = new List<(string, string)>
			{
				(length, "length"),
				(width, pole ? "diameter" : "width")
			};
			if (!pole)
			{
				list.Add((thick, "thickness"));
			}
			return list;
		}

		public static List<string> PointedControlLines(string game, List<(string key, string what)> sizes, out int sizeLines)
		{
			string[] array = (game ?? "").Split(new char[1] { '\n' });
			List<string> list = sizes.Select(((string key, string what) s) => s.what).ToList();
			sizeLines = list.Count;
			for (int num = ((array.Length >= 2 && array[0].Length == 0) ? 1 : 0); num < array.Length; num++)
			{
				list.Add(array[num]);
			}
			return list;
		}

		public static bool Roped(int slots, int loaded, int nailed)
		{
			if (slots > 0 && loaded == slots)
			{
				return nailed == slots;
			}
			return false;
		}

		public static (Vector3 min, Vector3 max) LoadBox(PalletLoad load, bool half = false)
		{
			//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_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_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)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = LoadSize(load, half);
			Vector3 val2 = Vector3.positiveInfinity;
			Vector3 val3 = Vector3.negativeInfinity;
			Vector3[] array = LoadSlots(load, half);
			for (int i = 0; i < array.Length; i++)
			{
				Vector3 val4 = array[i] + new Vector3(0f, 0.25f + val.y / 2f, 0f);
				val2 = Vector3.Min(val2, val4 - val / 2f);
				val3 = Vector3.Max(val3, val4 + val / 2f);
			}
			return (min: val2, max: val3);
		}

		public static List<Vector3[]> RopeLoops(PalletLoad load, bool half = false)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3[]> list = new List<Vector3[]>();
			if (LoadSlots(load, half).Length == 0)
			{
				return list;
			}
			(Vector3 min, Vector3 max) tuple = LoadBox(load, half);
			Vector3 item = tuple.min;
			Vector3 item2 = tuple.max;
			float num = 0.0125f;
			float num2 = Math.Max(Math.Max(0f - item.x, item2.x), 0.725f) + num;
			float num3 = item2.y + num;
			float num4 = 0.21000001f - num;
			float[] array = ((!half) ? new float[2] { -0.295f, 0.295f } : new float[1] { 0.025f });
			foreach (float num5 in array)
			{
				list.Add((Vector3[])(object)new Vector3[4]
				{
					new Vector3(0f - num2, num4, num5),
					new Vector3(0f - num2, num3, num5),
					new Vector3(num2, num3, num5),
					new Vector3(num2, num4, num5)
				});
			}
			float num6 = 0.25f + (item2.y - 0.25f) * 0.55f;
			float num7 = Math.Max(0f - item.x, item2.x) + num;
			float num8 = Math.Max(0f - item.z, item2.z) + num;
			list.Add((Vector3[])(object)new Vector3[4]
			{
				new Vector3(0f - num7, num6, 0f - num8),
				new Vector3(0f - num7, num6, num8),
				new Vector3(num7, num6, num8),
				new Vector3(num7, num6, 0f - num8)
			});
			return list;
		}

		public static PalletLoad LoadOf(string sizeDescription)
		{
			return (sizeDescription ?? "").Trim().ToLowerInvariant() switch
			{
				"large crate" => PalletLoad.LargeCrate, 
				"standard crate" => PalletLoad.StandardCrate, 
				"small crate" => PalletLoad.SmallCrate, 
				"large package" => PalletLoad.LargePackage, 
				"medium package" => PalletLoad.MediumPackage, 
				"standard package" => PalletLoad.StandardPackage, 
				"small package" => PalletLoad.SmallPackage, 
				_ => PalletLoad.None, 
			};
		}

		public static Vector3 LoadSize(PalletLoad load, bool half = false)
		{
			//IL_0016: 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_0085: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			if (half && load == PalletLoad.StandardCrate)
			{
				return new Vector3(1.27f, 1.029f, 0.71f);
			}
			if (half && load == PalletLoad.MediumPackage)
			{
				return new Vector3(1.216f, 1.016f, 0.698f);
			}
			return (Vector3)(load switch
			{
				PalletLoad.LargeCrate => new Vector3(1.27f, 1.093f, 1.229f), 
				PalletLoad.StandardCrate => new Vector3(0.71f, 1.029f, 1.27f), 
				PalletLoad.SmallCrate => new Vector3(0.462f, 1.056f, 0.626f), 
				PalletLoad.LargePackage => new Vector3(1.436f, 0.968f, 1.46f), 
				PalletLoad.MediumPackage => new Vector3(0.698f, 1.016f, 1.216f), 
				PalletLoad.StandardPackage => new Vector3(1.866f, 1.066f, 0.606f), 
				PalletLoad.SmallPackage => new Vector3(1.466f, 1.066f, 0.406f), 
				_ => Vector3.zero, 
			});
		}

		public static Vector3[] LoadSlots(PalletLoad load, bool half)
		{
			//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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_0067: 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)
			if (!half)
			{
				return LoadSlots(load);
			}
			switch (load)
			{
			case PalletLoad.StandardCrate:
			case PalletLoad.MediumPackage:
			case PalletLoad.StandardPackage:
			case PalletLoad.SmallPackage:
				return (Vector3[])(object)new Vector3[1] { Vector3.zero };
			case PalletLoad.SmallCrate:
				return (Vector3[])(object)new Vector3[3]
				{
					new Vector3(-0.478f, 0f, 0f),
					Vector3.zero,
					new Vector3(0.478f, 0f, 0f)
				};
			default:
				return (Vector3[])(object)new Vector3[0];
			}
		}

		public static Vector3[] LoadSlots(PalletLoad load)
		{
			//IL_0031: 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_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_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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: 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_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_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			switch (load)
			{
			case PalletLoad.LargeCrate:
			case PalletLoad.LargePackage:
				return (Vector3[])(object)new Vector3[1] { Vector3.zero };
			case PalletLoad.StandardCrate:
				return (Vector3[])(object)new Vector3[2]
				{
					new Vector3(-0.36f, 0f, 0f),
					new Vector3(0.36f, 0f, 0f)
				};
			case PalletLoad.SmallCrate:
				return new float[3] { -0.478f, 0f, 0.478f }.SelectMany((float x) => (IEnumerable<Vector3>)(object)new Vector3[2]
				{
					new Vector3(x, 0f, -0.32f),
					new Vector3(x, 0f, 0.32f)
				}).ToArray();
			case PalletLoad.MediumPackage:
				return (Vector3[])(object)new Vector3[2]
				{
					new Vector3(-0.352f, 0f, 0f),
					new Vector3(0.352f, 0f, 0f)
				};
			case PalletLoad.StandardPackage:
				return (Vector3[])(object)new Vector3[2]
				{
					new Vector3(0f, 0f, -0.31f),
					new Vector3(0f, 0f, 0.31f)
				};
			case PalletLoad.SmallPackage:
				return (Vector3[])(object)new Vector3[3]
				{
					new Vector3(0f, 0f, -0.42f),
					Vector3.zero,
					new Vector3(0f, 0f, 0.42f)
				};
			default:
				return (Vector3[])(object)new Vector3[0];
			}
		}

		public static (int z, int y) LoadAxes(Vector3 size, Vector3 want)
		{
			//IL_0089: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			int[] array = null;
			float num = float.MaxValue;
			int[][] array2 = new int[6][]
			{
				new int[3] { 0, 1, 2 },
				new int[3] { 0, 2, 1 },
				new int[3] { 1, 0, 2 },
				new int[3] { 1, 2, 0 },
				new int[3] { 2, 0, 1 },
				new int[3] { 2, 1, 0 }
			};
			foreach (int[] array3 in array2)
			{
				float num2 = Math.Abs(((Vector3)(ref size))[array3[0]] - want.x) + Math.Abs(((Vector3)(ref size))[array3[1]] - want.y) + Math.Abs(((Vector3)(ref size))[array3[2]] - want.z);
				if (num2 < num)
				{
					num = num2;
					array = array3;
				}
			}
			return (z: Array.IndexOf(array, 2), y: Array.IndexOf(array, 1));
		}

		public static int PoleBundlesAt(bool shared)
		{
			if (!shared)
			{
				return 9;
			}
			return 6;
		}

		public static int PoleColumnsAt(bool shared)
		{
			return 3;
		}
	}
	public enum PriceProfile
	{
		Staple,
		ConsumerGoods,
		Industrial,
		Precious,
		Luxury
	}
	internal sealed class GoodRow
	{
		internal int Good;

		internal PriceProfile? Profile;

		internal bool WaterProof;

		internal bool Liquid;

		internal bool Fragile;

		internal bool Cargo;
	}
	internal static class Content
	{
		private static GoodRow[] goods;

		private static GoodRow[] Goods => goods ?? (goods = Read());

		private static GoodRow[] Read()
		{
			List<string[]> list = Embedded.Csv("goods.csv", header: false).ToList();
			string[] head = list[0];
			int good = Column("good");
			int profile = Column("profile");
			int waterproof = Column("waterproof");
			int liquid = Column("liquid");
			int fragile = Column("fragile");
			int cargo = Column("cargo");
			List<GoodRow> list2 = (from c in list.Skip(1)
				select new GoodRow
				{
					Good = int.Parse(c[good]),
					Profile = ((c[profile].Length > 0) ? new PriceProfile?((PriceProfile)Enum.Parse(typeof(PriceProfile), c[profile])) : ((PriceProfile?)null)),
					WaterProof = (c[waterproof] == "1"),
					Liquid = (c[liquid] == "1"),
					Fragile = (c[fragile].Length > 0 && float.Parse(c[fragile], CultureInfo.InvariantCulture) >= 1f),
					Cargo = (c[cargo] == "1")
				}).ToList();
			GoodRow[] array = new GoodRow[list2.Max((GoodRow g) => g.Good) + 1];
			foreach (GoodRow item in list2)
			{
				array[item.Good] = item;
			}
			return array;
			int Column(string name)
			{
				int num = Array.IndexOf(head, name);
				if (num < 0)
				{
					throw new InvalidDataException("goods.csv has no column " + name);
				}
				return num;
			}
		}

		internal static GoodRow Good(int good)
		{
			if ((uint)good >= (uint)Goods.Length)
			{
				return null;
			}
			return Goods[good];
		}

		internal static HashSet<int> GoodSet(Func<GoodRow, bool> test)
		{
			return new HashSet<int>(from g in Goods
				where g != null && test(g)
				select g.Good);
		}
	}
	internal static class Uninstall
	{
		internal static bool Prepared => false;
	}
	internal static class Startup
	{
		internal static bool BlocksGameplay => false;
	}
	public sealed class CargoCondition : MonoBehaviour
	{
		private sealed class AppearanceBinding
		{
			internal MeshRenderer renderer;

			internal Mesh mesh;

			internal Material[] originals;

			internal Material[] owned;
		}

		private struct CoverFrame
		{
			internal Vector3 a;

			internal Vector3 b;

			internal Vector3 up;

			internal float minA;

			internal float maxA;

			internal float minB;

			internal float maxB;

			internal float top;

			internal static CoverFrame Of(Matrix4x4 m, Bounds local, Vector3 up)
			{
				//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_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				//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_00ab: 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_00b6: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d2: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_010d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0112: Unknown result type (might be due to invalid IL or missing references)
				//IL_0117: Unknown result type (might be due to invalid IL or missing references)
				//IL_011c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0121: Unknown result type (might be due to invalid IL or missing references)
				//IL_0123: Unknown result type (might be due to invalid IL or missing references)
				//IL_0126: Unknown result type (might be due to invalid IL or missing references)
				//IL_0132: Unknown result type (might be due to invalid IL or missing references)
				//IL_0135: Unknown result type (might be due to invalid IL or missing references)
				//IL_0199: Unknown result type (might be due to invalid IL or missing references)
				//IL_019b: Unknown result type (might be due to invalid IL or missing references)
				CoverFrame result = new CoverFrame
				{
					up = up,
					minA = float.MaxValue,
					maxA = float.MinValue,
					minB = float.MaxValue,
					maxB = float.MinValue,
					top = float.MinValue
				};
				int num = 0;
				Vector3 val;
				for (int i = 1; i < 3; i++)
				{
					val = Vector4.op_Implicit(((Matrix4x4)(ref m)).GetColumn(i));
					float num2 = Mathf.Abs(Vector3.Dot(((Vector3)(ref val)).normalized, up));
					val = Vector4.op_Implicit(((Matrix4x4)(ref m)).GetColumn(num));
					if (num2 > Mathf.Abs(Vector3.Dot(((Vector3)(ref val)).normalized, up)))
					{
						num = i;
					}
				}
				val = Vector3.ProjectOnPlane(Vector4.op_Implicit(((Matrix4x4)(ref m)).GetColumn((num + 1) % 3)), up);
				result.a = ((Vector3)(ref val)).normalized;
				result.b = Vector3.Cross(up, result.a);
				for (int j = -1; j <= 1; j += 2)
				{
					for (int k = -1; k <= 1; k += 2)
					{
						for (int l = -1; l <= 1; l += 2)
						{
							Vector3 val2 = ((Matrix4x4)(ref m)).MultiplyPoint3x4(((Bounds)(ref local)).center + Vector3.Scale(((Bounds)(ref local)).extents, new Vector3((float)j, (float)k, (float)l)));
							float num3 = Vector3.Dot(val2, result.a);
							float num4 = Vector3.Dot(val2, result.b);
							result.minA = Mathf.Min(result.minA, num3);
							result.maxA = Mathf.Max(result.maxA, num3);
							result.minB = Mathf.Min(result.minB, num4);
							result.maxB = Mathf.Max(result.maxB, num4);
							result.top = Mathf.Max(result.top, Vector3.Dot(val2, up));
						}
					}
				}
				return result;
			}

			internal Vector3 Point(int i, int j, int grid)
			{
				//IL_0001: 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_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: 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_006a: Unknown result type (might be due to invalid IL or missing references)
				return a * Mathf.Lerp(minA, maxA, ((float)i + 0.5f) / (float)grid) + b * Mathf.Lerp(minB, maxB, ((float)j + 0.5f) / (float)grid) + up * (top + 0.01f);
			}

			internal bool[] MapCells(bool[] rays, int grid, Bounds local, Matrix4x4 m)
			{
				//IL_0014: 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_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				bool[] array = new bool[1000];
				for (int i = 0; i < array.Length; i++)
				{
					Vector3 val = ((Matrix4x4)(ref m)).MultiplyPoint3x4(CargoStainHistory.CellPoint(local, i));
					int num = Mathf.Clamp((int)((Vector3.Dot(val, a) - minA) / Mathf.Max(0.0001f, maxA - minA) * (float)grid), 0, grid - 1);
					int num2 = Mathf.Clamp((int)((Vector3.Dot(val, b) - minB) / Mathf.Max(0.0001f, maxB - minB) * (float)grid), 0, grid - 1);
					array[i] = rays[num + grid * num2];
				}
				return array;
			}
		}

		internal static readonly HashSet<CargoCondition> Active = new HashSet<CargoCondition>();

		private static readonly HashSet<int> Immune = Content.GoodSet((GoodRow g) => g.WaterProof);

		internal static readonly HashSet<int> LiquidCargo = Content.GoodSet((GoodRow g) => g.Liquid);

		private const int CoverGrid = 5;

		private static readonly int[] CoverFirst = new int[5] { 0, 4, 20, 24, 12 };

		private const float CoverRayHeight = 15f;

		private const int PlayerOnlyLayers = 4096;

		private const float UpdateSeconds = 2f;

		private const float MoveRecheck = 100f;

		private float phase;

		private bool moveRecheck;

		private Vector3 moveFrom;

		private float coveredFraction;

		private bool[] coveredCells;

		private int coverRecheckAt;

		private bool settled;

		private bool resting;

		private bool moved;

		private bool leftRechecked;

		private List<CargoCondition> beneath;

		private List<CargoCondition> left;

		private float leftAt;

		private ShipItem item;

		private SaveablePrefab save;

		private CargoState state;

		private Renderer[] geometry;

		private CargoStainHistory history;

		private float stainTimer;

		private readonly List<CargoWetVolume> wetVolumes = new List<CargoWetVolume>(8);

		private float sampledSeaHeight;

		private bool seaSampleValid;

		private readonly List<AppearanceBinding> appearance = new List<AppearanceBinding>();

		private float timer;

		private float appearanceTimer;

		private float visualHealth = -1f;

		private double conditionHours;

		private readonly SampleHeightHelper seaHeight = new SampleHeightHelper();

		private Transform exposureBoat;

		private Vector3 exposurePosition;

		private Quaternion exposureRotation;

		private float exposureSettling;

		private bool exposurePoseKnown;

		private bool visualWaterEnabled = true;

		private string suffix;

		private double lanternShare;

		private int lanternsSeen = -1;

		private Bounds? localBox;

		private string hintDescription;

		private string hintLookText;

		private int hintPercent = -2;

		private int hintCover = -2;

		private int hintDamage = -2;

		private bool hintLoan;

		private ShipItemBottle bottle;

		private ShipItemCrate crate;

		private float fullUnits = -1f;

		private Good good;

		private HashSet<string> ownParts;

		internal const int WetQueue = 1999;

		internal bool Wetting { get; private set; }

		internal bool Drying { get; private set; }

		internal ShipItem Item => item;

		private bool WaterOff
		{
			get
			{
				if (state != null)
				{
					if (!Immune.Contains(state.good))
					{
						return state.opened;
					}
					return true;
				}
				return false;
			}
		}

		internal Bounds WorldBounds => Bounds();

		internal float CoveredFraction => coveredFraction;

		internal bool CoverRecheckPending => coverRecheckAt != 0;

		private bool Placed
		{
			get
			{
				if (Object.op_Implicit((Object)(object)item) && Object.op_Implicit((Object)(object)save) && item.sold && !Object.op_Implicit((Object)(object)((PickupableItem)item).held) && save.currentCrateId == 0 && item.GetCurrentInventorySlot() < 0 && Object.op_Implicit((Object)(object)item.itemRigidbodyC) && save.GetParentObject() != -2)
				{
					return save.GetParentObject() != -3;
				}
				return false;
			}
		}

		private double LanternShare()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (lanternsSeen == Lanterns.Version)
			{
				return lanternShare;
			}
			if (!localBox.HasValue)
			{
				localBox = LocalMeshBounds();
			}
			lanternShare = Lanterns.Drying(((Component)this).transform, localBox.Value);
			lanternsSeen = Lanterns.Version;
			return lanternShare;
		}

		private void Awake()
		{
			item = ((Component)this).GetComponent<ShipItem>();
			save = ((Component)this).GetComponent<SaveablePrefab>();
			ref ShipItemBottle reference = ref bottle;
			ShipItem obj = item;
			reference = (ShipItemBottle)(object)((obj is ShipItemBottle) ? obj : null);
			ref ShipItemCrate reference2 = ref crate;
			ShipItem obj2 = item;
			reference2 = (ShipItemCrate)(object)((obj2 is ShipItemCrate) ? obj2 : null);
		}

		private float FullUnits()
		{
			GameObject[] array = (Object.op_Implicit((Object)(object)PrefabsDirectory.instance) ? PrefabsDirectory.instance.directory : null);
			GameObject val = ((Object.op_Implicit((Object)(object)save) && array != null && save.prefabIndex >= 0 && save.prefabIndex < array.Length) ? array[save.prefabIndex] : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return 0f;
			}
			if (Object.op_Implicit((Object)(object)bottle))
			{
				ShipItemBottle component = val.GetComponent<ShipItemBottle>();
				if (!Object.op_Implicit((Object)(object)component))
				{
					return 0f;
				}
				return ((ShipItem)component).health;
			}
			if (Object.op_Implicit((Object)(object)crate))
			{
				ShipItemCrate component2 = val.GetComponent<ShipItemCrate>();
				if (!Object.op_Implicit((Object)(object)component2))
				{
					return 0f;
				}
				return ((ShipItem)component2).amount;
			}
			return 0f;
		}

		private void CheckOpened()
		{
			if (state != null && !state.opened && (Object.op_Implicit((Object)(object)bottle) || Object.op_Implicit((Object)(object)crate)))
			{
				if (fullUnits < 0f)
				{
					fullUnits = FullUnits();
				}
				if (Rules.Opened(Object.op_Implicit((Object)(object)bottle) ? ((ShipItem)bottle).health : ((ShipItem)crate).amount, fullUnits))
				{
					state.opened = true;
					bool wetting = (Drying = false);
					Wetting = wetting;
					visualHealth = -1f;
					RefreshAppearance();
					RefreshHint();
				}
			}
		}

		private void ResetConditionClock()
		{
			timer = 0f - phase;
			conditionHours = 0.0;
		}

		private void OnEnable()
		{
			uint num = (uint)(((Object)this).GetInstanceID() * -1640531535);
			phase = (float)(num % 2000) / 1000f;
			stainTimer = (float)(num % 3000) / 1000f;
			Active.Add(this);
			ResetConditionClock();
			appearanceTimer = 0.35f;
			visualHealth = -1f;
		}

		private static Vector3 Real(Vector3 p)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)FloatingOriginManager.instance))
			{
				return p;
			}
			return FloatingOriginManager.instance.ShiftingPosToRealPos(p);
		}

		private void OnDisable()
		{
			history?.Flush();
			Active.Remove(this);
			ResetConditionClock();
			RecheckLeft();
		}

		private void Start()
		{
			Restore();
		}

		internal static CargoState Track(ShipItem item)
		{
			if (!Object.op_Implicit((Object)(object)item) || !Object.op_Implicit((Object)(object)((Component)item).GetComponent<Good>()))
			{
				return null;
			}
			SaveablePrefab component = ((Component)item).GetComponent<SaveablePrefab>();
			if (!Object.op_Implicit((Object)(object)component) || component.instanceId == 0)
			{
				return null;
			}
			int num = PrefabsDirectory.ItemToGoodIndex(component.prefabIndex);
			if (!Rules.CargoGood(num))
			{
				return null;
			}
			CargoCondition cargoCondition = ((Component)item).GetComponent<CargoCondition>() ?? ((Component)item).gameObject.AddComponent<CargoCondition>();
			if (!World.Ready || World.Loading || World.Removed.Contains(component.instanceId))
			{
				return null;
			}
			if (!World.Cargo.TryGetValue(component.instanceId, out var value))
			{
				value = new CargoState
				{
					id = component.instanceId,
					prefab = component.prefabIndex,
					good = num,
					parent = component.GetParentObject(),
					name = item.name
				};
				World.Cargo.Add(value.id, value);
				World.State.cargo.Add(value);
			}
			cargoCondition.state = value;
			return value;
		}

		internal void Restore()
		{
			if (!World.Ready || World.Loading)
			{
				return;
			}
			CargoState cargoState = Track(item);
			if (cargoState != null)
			{
				if (history != null && !history.BelongsTo(cargoState))
				{
					history.Dispose();
					history = null;
				}
				state = cargoState;
				state.health = Mathf.Clamp(state.health, 0f, 100f);
				visualHealth = -1f;
				ClearExposure();
				CaptureParent();
				CheckOpened();
				RefreshAppearance();
			}
		}

		internal void CaptureParent()
		{
			if (state != null && Object.op_Implicit((Object)(object)save))
			{
				int parentObject = save.GetParentObject();
				if (parentObject != -2 && parentObject != -3)
				{
					state.parent = parentObject;
				}
			}
		}

		internal void PrepareSave()
		{
			history?.Flush();
			CaptureParent();
		}

		private Bounds LocalMeshBounds()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00b4: 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_00cc: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			Renderer[] array;
			if (geometry == null)
			{
				array = (Renderer[])(object)SourceRenderers();
				geometry = array;
			}
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(Vector3.zero, Vector3.zero);
			bool flag = false;
			array = geometry;
			foreach (Renderer val in array)
			{
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
				if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.sharedMesh))
				{
					continue;
				}
				Bounds bounds = component.sharedMesh.bounds;
				Matrix4x4 val2 = ((Component)this).transform.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix;
				for (int j = -1; j <= 1; j += 2)
				{
					for (int k = -1; k <= 1; k += 2)
					{
						for (int l = -1; l <= 1; l += 2)
						{
							Vector3 val3 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)j, (float)k, (float)l)));
							if (!flag)
							{
								((Bounds)(ref result))..ctor(val3, Vector3.zero);
								flag = true;
							}
							else
							{
								((Bounds)(ref result)).Encapsulate(val3);
							}
						}
					}
				}
			}
			if (!flag)
			{
				return new Bounds(Vector3.zero, Vector3.one);
			}
			return result;
		}

		private void EnsureHistory()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (history == null)
			{
				history = new CargoStainHistory(state, LocalMeshBounds());
			}
		}

		internal static bool WaterProof(int good)
		{
			return Immune.Contains(good);
		}

		internal static float Health(ShipItem item)
		{
			if (!Settings.WaterEnabled || !Object.op_Implicit((Object)(object)item))
			{
				return 100f;
			}
			SaveablePrefab component = ((Component)item).GetComponent<SaveablePrefab>();
			if (!Object.op_Implicit((Object)(object)component) || !World.Cargo.TryGetValue(component.instanceId, out var value))
			{
				return 100f;
			}
			return value.health;
		}

		internal static float Factor(ShipItem item)
		{
			Factors(item, out var water, out var intact);
			return water * intact;
		}

		internal static void Factors(ShipItem item, out float water, out float intact)
		{
			water = (intact = 1f);
			if (!Object.op_Implicit((Object)(object)item))
			{
				return;
			}
			SaveablePrefab component = ((Component)item).GetComponent<SaveablePrefab>();
			if (Object.op_Implicit((Object)(object)component) && World.Cargo.TryGetValue(component.instanceId, out var value))
			{
				if (Settings.WaterEnabled)
				{
					water = (float)Rules.ConditionFactor(value.health, LiquidCargo.Contains(value.good), Immune.Contains(value.good) || value.opened);
				}
				if (Fragile(item, value))
				{
					intact = Rules.IntactFactor(value.impact);
				}
			}
		}

		internal static bool OutOfTrade(ShipItem item)
		{
			if (!Settings.WaterEnabled || !Object.op_Implicit((Object)(object)item))
			{
				return false;
			}
			SaveablePrefab component = ((Component)item).GetComponent<SaveablePrefab>();
			if (Object.op_Implicit((Object)(object)component) && World.Cargo.TryGetValue(component.instanceId, out var value))
			{
				return Rules.OutOfTrade(value.opened, value.health);
			}
			return false;
		}

		internal static bool Fragile(ShipItem item, CargoState c)
		{
			if (c == null || !Settings.FragileEnabled)
			{
				return false;
			}
			if (Rules.FragileGood(c.good) || c.fragile)
			{
				return true;
			}
			return FragileMission(c, Object.op_Implicit((Object)(object)item) ? ((Component)item).GetComponent<Good>() : null);
		}

		private bool FragileNow()
		{
			if (state == null || !Settings.FragileEnabled)
			{
				return false;
			}
			if (Rules.FragileGood(state.good) || state.fragile)
			{
				return true;
			}
			if (!Object.op_Implicit((Object)(object)item))
			{
				return FragileMission(state, null);
			}
			if (!Object.op_Implicit((Object)(object)good))
			{
				good = ((Component)item).GetComponent<Good>();
			}
			return FragileMission(state, good);
		}

		private static bool FragileMission(CargoState c, Good g)
		{
			return false;
		}

		internal static bool Delivered(int id)
		{
			return false;
		}

		internal static float Impact(ShipItem item)
		{
			SaveablePrefab val = (Object.op_Implicit((Object)(object)item) ? ((Component)item).GetComponent<SaveablePrefab>() : null);
			if (!Object.op_Implicit((Object)(object)val) || !World.Cargo.TryGetValue(val.instanceId, out var value) || !Fragile(item, value))
			{
				return 0f;
			}
			return value.impact;
		}

		internal static void HullHit(BoatDamage hull, float added)
		{
			foreach (CargoCondition item in Active)
			{
				if (Object.op_Implicit((Object)(object)item) && Object.op_Implicit((Object)(object)item.item) && item.state != null && Object.op_Implicit((Object)(object)item.item.currentActualBoat) && !((Object)(object)((Component)item.item.currentActualBoat).GetComponentInParent<BoatDamage>() != (Object)(object)hull) && Fragile(item.item, item.state))
				{
					item.state.impact = Rules.FragileDamage(item.state.impact, added);
					item.RefreshHint();
					item.RefreshAppearance();
				}
			}
		}

		private Bounds Bounds()
		{
			//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_009a: 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_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)
			Renderer[] array;
			if (geometry == null)
			{
				array = (Renderer[])(object)SourceRenderers();
				geometry = array;
			}
			Bounds bounds = default(Bounds);
			((Bounds)(ref bounds))..ctor(((Component)this).transform.position, Vector3.zero);
			bool flag = false;
			array = geometry;
			foreach (Renderer val in array)
			{
				if (Object.op_Implicit((Object)(object)val) && val.enabled && ((Component)val).gameObject.activeInHierarchy && !((Object)(object)((Component)val).GetComponentInParent<ShipItem>() != (Object)(object)item))
				{
					if (!flag)
					{
						bounds = val.bounds;
						flag = true;
					}
					else
					{
						((Bounds)(ref bounds)).Encapsulate(val.bounds);
					}
				}
			}
			return bounds;
		}

		internal void ClearExposure()
		{
			if (state != null)
			{
				state.exposure = 0;
			}
			exposurePoseKnown = false;
			exposureSettling = 0f;
			coveredFraction = 0f;
			coveredCells = null;
			coverRecheckAt = 0;
			moveRecheck = false;
			RecheckLeft();
			settled = (resting = false);
			beneath = null;
		}

		private void RecheckLeft()
		{
			if (moved)
			{
				CoverEvents.Recheck(left);
			}
			moved = false;
			left = null;
		}

		private void UpdateExposure()
		{
			//IL_0062: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: 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)
			//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_00cf: 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_01a0: Unknown result type (might be due to invalid IL or missing references)
			if (moved && !leftRechecked && Time.time - leftAt > 2f)
			{
				leftRechecked = true;
				CoverEvents.Recheck(left);
			}
			Transform currentActualBoat = item.currentActualBoat;
			Vector3 val = (Object.op_Implicit((Object)(object)currentActualBoat) ? currentActualBoat.InverseTransformPoint(((Component)this).transform.position) : Real(((Component)this).transform.position));
			Quaternion val2 = (Object.op_Implicit((Object)(object)currentActualBoat) ? (Quaternion.Inverse(currentActualBoat.rotation) * ((Component)this).transform.rotation) : ((Component)this).transform.rotation);
			if (exposurePoseKnown && !((Object)(object)currentActualBoat != (Object)(object)exposureBoat))
			{
				Vector3 val3 = val - exposurePosition;
				if (!(((Vector3)(ref val3)).sqrMagnitude > 0.0025f) && !(Quaternion.Angle(val2, exposureRotation) > 2f))
				{
					if (!settled && !((exposureSettling += Time.deltaTime) < 0.35f))
					{
						settled = (resting = true);
						lanternsSeen = -1;
						beneath = CoverEvents.Beneath(item, Bounds());
						if (moved)
						{
							RecheckLeft();
							CoverEvents.Recheck(beneath);
						}
						Placement();
					}
					return;
				}
			}
			state.exposure = 0;
			exposureSettling = 0f;
			exposurePoseKnown = true;
			settled = false;
			exposureBoat = currentActualBoat;
			exposurePosition = val;
			exposureRotation = val2;
			if (resting)
			{
				resting = false;
				moved = true;
				leftRechecked = false;
				left = beneath;
				beneath = null;
				leftAt = Time.time;
			}
		}

		internal void RefreshSettings()
		{
			ResetConditionClock();
			appearanceTimer = 0f;
			visualHealth = -1f;
			ClearExposure();
			RefreshAppearance();
			RefreshHint();
		}

		internal void Placement()
		{
			if (Settings.WaterEnabled && state != null && !WaterOff && Placed)
			{
				ScanCover(full: false);
			}
		}

		internal void RequestCoverRecheck()
		{
			if (state != null && state.exposure != 0)
			{
				coverRecheckAt = Time.frameCount + 1;
			}
		}

		private void ScanCover(bool full, bool afterMove = false)
		{
			TarpCover.BeginScan();
			try
			{
				ScanCoverOnce(full, afterMove);
			}
			finally
			{
				TarpCover.EndScan();
			}
		}

		private void ScanCoverOnce(bool full, bool afterMove)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b6: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			Transform boat = item.currentActualBoat;
			Transform walk = item.currentWalkCol;
			Vector3 up = ((Object.op_Implicit((Object)(object)boat) && boat.up.y > 0.7f) ? boat.up : Vector3.up);
			moveRecheck = Object.op_Implicit((Object)(object)boat) && !afterMove;
			if (moveRecheck)
			{
				moveFrom = Real(boat.position);
			}
			Bounds local = LocalMeshBounds();
			Matrix4x4 localToWorldMatrix = ((Component)this).transform.localToWorldMatrix;
			CoverFrame frame = CoverFrame.Of(localToWorldMatrix, local, up);
			Physics.SyncTransforms();
			Vector3 val;
			if (!Object.op_Implicit((Object)(object)boat) || !Object.op_Implicit((Object)(object)walk))
			{
				val = up;
			}
			else
			{
				Vector3 val2 = walk.TransformDirection(boat.InverseTransformDirection(up));
				val = ((Vector3)(ref val2)).normalized;
			}
			Vector3 walkUp = val;
			Vector3?[] ends = OwnTops(frame, up, boat, walk, walkUp);
			bool[] rays = new bool[25];
			int[] first = CoverFirst.Where((int n) => ends[n].HasValue).ToArray();
			int[] array = first;
			foreach (int num2 in array)
			{
				rays[num2] = Blocked(num2);
			}
			bool flag = first.Length >= 2 && first.All((int n) => rays[n] == rays[first[0]]);
			int num3 = 0;
			int num4 = 0;
			for (int num5 = 0; num5 < rays.Length; num5++)
			{
				if (ends[num5].HasValue)
				{
					if (Array.IndexOf(first, num5) < 0)
					{
						rays[num5] = ((full || !flag) ? Blocked(num5) : rays[first[0]]);
					}
					num3++;
					if (rays[num5])
					{
						num4++;
					}
				}
			}
			coveredFraction = (float)num4 / (float)Mathf.Max(1, num3);
			bool flag2 = (ends[12].HasValue ? rays[12] : (coveredFraction >= 1f));
			for (int num6 = 0; num6 < rays.Length; num6++)
			{
				if (!ends[num6].HasValue)
				{
					rays[num6] = flag2;
				}
			}
			coveredCells = frame.MapCells(rays, 5, local, localToWorldMatrix);
			state.exposure = ((coveredFraction >= 1f) ? 1 : 2);
			bool Blocked(int n)
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: 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_0094: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_0070: 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_0076: 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)
				Vector3 value = ends[n].Value;
				if (!Covered(value, up, -232880437, null) && !Covered(value, up, 4, null, itemsOnly: true) && (!Object.op_Implicit((Object)(object)boat) || !Object.op_Implicit((Object)(object)walk) || !Covered(walk.TransformPoint(boat.InverseTransformPoint(value)), walkUp, -4097, walk)))
				{
					return TarpCover.CoverAbove(value, up, 15f);
				}
				return true;
			}
		}

		private Vector3?[] OwnTops(CoverFrame frame, Vector3 up, Transform boat, Transform walk, Vector3 walkUp)
		{
			//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)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d5: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			Vector3?[] array = new Vector3?[25];
			ItemRigidbody itemRigidbodyC = item.itemRigidbodyC;
			Collider[] array2 = (Collider[])(Object.op_Implicit((Object)(object)itemRigidbodyC) ? ((Array)(from c in ((Component)itemRigidbodyC).GetComponentsInChildren<Collider>()
				where Object.op_Implicit((Object)(object)c) && c.enabled && !c.isTrigger
				select c).ToArray()) : ((Array)new Collider[0]));
			bool flag = Object.op_Implicit((Object)(object)boat) && Object.op_Implicit((Object)(object)walk);
			bool flag2 = false;
			Ray val4 = default(Ray);
			RaycastHit val6 = default(RaycastHit);
			for (int num = 0; num < array.Length; num++)
			{
				Vector3 val = frame.Point(num % 5, num / 5, 5);
				if (array2.Length == 0)
				{
					array[num] = val;
					continue;
				}
				Vector3 val2 = (flag ? walk.TransformPoint(boat.InverseTransformPoint(val)) : val);
				Vector3 val3 = (flag ? walkUp : up);
				((Ray)(ref val4))..ctor(val2 + val3 * 15f, -val3);
				float num2 = float.MaxValue;
				Vector3 val5 = default(Vector3);
				Collider[] array3 = array2;
				for (int num3 = 0; num3 < array3.Length; num3++)
				{
					if (array3[num3].Raycast(val4, ref val6, 30f) && ((RaycastHit)(ref val6)).distance < num2)
					{
						num2 = ((RaycastHit)(ref val6)).distance;
						val5 = ((RaycastHit)(ref val6)).point;
					}
				}
				if (num2 != float.MaxValue)
				{
					array[num] = (flag ? boat.TransformPoint(walk.InverseTransformPoint(val5)) : val5) + up * 0.01f;
					flag2 = true;
				}
			}
			if (array2.Length != 0 && !flag2)
			{
				for