Decompiled source of TentandPlank v1.0.0

BepInEx/plugins/TentandPlank/TentandPlank.dll

Decompiled 12 hours 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.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
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.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TentandPlank")]
[assembly: AssemblyTitle("TentandPlank")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TentandPlank
{
	public static class Rules
	{
		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 PoleKgPerMetre = 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 float TarpFullHealth = 100f;

		public const float TarpWearPerDay = 10f;

		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 static float PoleBundleMass => PoleMass(2.0) * 4f;

		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 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 double PoleGrain(double d)
		{
			double num = 6.8;
			double num2 = (d % num + num) % num;
			if (!(num2 <= 3.4))
			{
				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 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 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 int WaterHintPercent(float health)
		{
			return Mathf.RoundToInt(100f - Mathf.Clamp(health, 0f, 100f));
		}

		public static bool FragileGood(int good)
		{
			if (good != 20 && good != 34)
			{
				return good == 55;
			}
			return true;
		}

		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 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)
		{
			if (!PriceCurves.TryProfile(good, out var profile) || profile != PriceProfile.Luxury)
			{
				return 80f;
			}
			return 50f;
		}

		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 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)
		{
			gameHours = Math.Max(0.0, gameHours);
			double num = (damagingWater ? 12.5 : 0.0) + (coverKnown ? RainDamagePerHour(rain, exposed) : 0.0);
			if (num > 0.0)
			{
				return (float)Math.Max(0.0, (double)health - gameHours * num);
			}
			if (waterContact || rain > 0.0 || noDry || !coverKnown || Ruined(health) || health >= ceiling)
			{
				return health;
			}
			return (float)Math.Min(ceiling, (double)health + gameHours * DryingPerHour(exposed, clouds, hour));
		}

		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;
		}
	}
	internal static class WoodPlanks
	{
		private sealed class Job
		{
			internal ShipItemHammer hammer;

			internal ShipItem plank;

			internal float startOffset;

			internal bool back;

			internal int frame;
		}

		internal const int BundleIndex = 640;

		internal const int PlankIndex = 641;

		internal const int LumberIndex = 217;

		internal const int PaintingIndex = 120;

		internal const int LumberGood = 47;

		internal const int KiciaScene = 27;

		internal const float PlankSeconds = 20f;

		internal const float SwingSpeed = 275f;

		internal const float BundleLumber = 0.0625f;

		internal const float SurfaceTolerance = 0.01f;

		internal const int BundleLooks = 8;

		internal const int Looks = 24;

		internal static GameObject BundleTemplate;

		internal static GameObject PlankTemplate;

		internal static Mesh[] PlankMeshes;

		private static Mesh bundleMesh;

		internal static readonly float[] StockAcross = new float[2] { -0.16063f, -0.11537f };

		internal static readonly float[] StockHeight = new float[4] { -0.30504f, -0.27711f, -0.24918f, -0.22125f };

		internal const float StockAlong = 0.0153f;

		internal const string StallName = "shop area (15)";

		internal static ShipItem Pending;

		private static Vector3 popupOffset;

		private static int popupFrame;

		private static TextMesh title;

		private static TextMesh body;

		private static TextMesh button;

		private static string titleText;

		private static string bodyText;

		private static string buttonText;

		private static Func<bool> activateDown;

		internal static int Spawning;

		private static readonly MethodInfo enterBoat = AccessTools.Method(typeof(ShipItem), "EnterBoat", (Type[])null, (Type[])null);

		private static Job job;

		internal static bool Registered
		{
			get
			{
				if (Object.op_Implicit((Object)(object)BundleTemplate))
				{
					return Object.op_Implicit((Object)(object)PlankTemplate);
				}
				return false;
			}
		}

		internal static int LumberValue
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)PrefabsDirectory.instance) || PrefabsDirectory.instance.directory.Length <= 217 || !Object.op_Implicit((Object)(object)PrefabsDirectory.instance.directory[217]))
				{
					return 6000;
				}
				return PrefabsDirectory.instance.directory[217].GetComponent<ShipItem>().value;
			}
		}

		internal static bool Hammering => job != null;

		internal static int Index(ShipItem item)
		{
			SaveablePrefab val = (Object.op_Implicit((Object)(object)item) ? ((Component)item).GetComponent<SaveablePrefab>() : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return -1;
			}
			return val.prefabIndex;
		}

		internal static bool IsBundle(ShipItem item)
		{
			if (Registered)
			{
				return Index(item) == 640;
			}
			return false;
		}

		internal static bool IsPlank(ShipItem item)
		{
			if (Registered)
			{
				return Index(item) == 641;
			}
			return false;
		}

		internal static void Register(PrefabsDirectory directory)
		{
			//IL_0111: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Expected O, but got Unknown
			if (Registered || !Object.op_Implicit((Object)(object)directory) || directory.directory == null)
			{
				return;
			}
			GameObject[] array = directory.directory;
			if (array.Length > 641 && (Object.op_Implicit((Object)(object)array[640]) || Object.op_Implicit((Object)(object)array[641])))
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)"Prefab slots 640/641 are used by another mod; wood plank bundles and planks are disabled.");
				}
				return;
			}
			if (array.Length <= 217 || !Object.op_Implicit((Object)(object)array[217]) || !Object.op_Implicit((Object)(object)array[120]))
			{
				ManualLogSource log2 = Plugin.Log;
				if (log2 != null)
				{
					log2.LogError((object)"Lumber or painting prefab missing; wood plank bundles and planks are disabled.");
				}
				return;
			}
			try
			{
				bundleMesh = ObjMesh.Load("TentandPlank.Data.wood_planks_bundle.obj", "wood plank bundle");
				List<Mesh> list = ObjMesh.LoadAll("TentandPlank.Data.wood_plank_variants.obj", "wood plank");
				if (list.Count != 24)
				{
					throw new InvalidDataException("Expected " + 24 + " wood plank looks, found " + list.Count);
				}
				foreach (Mesh item in list)
				{
					Bounds bounds = item.bounds;
					ObjMesh.Shift(item, new Vector3(0f, 0f, 0f - ((Bounds)(ref bounds)).max.z));
				}
				GameObject val = new GameObject("TentandPlank item templates");
				val.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)val);
				Material sharedMaterial = ((Renderer)array[217].GetComponent<MeshRenderer>()).sharedMaterial;
				GameObject val2 = Template(array[217], val.transform, "640 wood plank bundle", bundleMesh, sharedMaterial, 640, "wood plank bundle", 375, 75f, big: true);
				Object.DestroyImmediate((Object)(object)val2.GetComponent<Good>());
				GameObject val3 = Template(array[120], val.transform, "641 wood plank", list[0], sharedMaterial, 641, "wood plank", 46, 9.375f, big: false);
				ShipItem component = val3.GetComponent<ShipItem>();
				component.health = 0f;
				component.amount = 0f;
				if (array.Length <= 641)
				{
					GameObject[] array2 = (GameObject[])(object)new GameObject[642];
					Array.Copy(array, array2, array.Length);
					array = (directory.directory = array2);
				}
				array[640] = val2;
				array[641] = val3;
				BundleTemplate = val2;
				PlankTemplate = val3;
				PlankMeshes = list.ToArray();
				ManualLogSource log3 = Plugin.Log;
				if (log3 != null)
				{
					log3.LogInfo((object)("Registered wood plank bundle (640) and wood plank (641, " + 24 + " looks)."));
				}
			}
			catch (Exception ex)
			{
				BundleTemplate = (PlankTemplate = null);
				PlankMeshes = null;
				ManualLogSource log4 = Plugin.Log;
				if (log4 != null)
				{
					log4.LogError((object)("Wood plank registration failed; bundles and planks are disabled. " + ex));
				}
			}
		}

		internal static GameObject Template(GameObject source, Transform holder, string objectName, Mesh mesh, Material material, int index, string itemName, int value, float mass, bool big)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0085: 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)
			GameObject val = Object.Instantiate<GameObject>(source, holder, false);
			((Object)val).name = objectName;
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			val.transform.localScale = Vector3.one;
			val.GetComponent<MeshFilter>().sharedMesh = mesh;
			((Renderer)val.GetComponent<MeshRenderer>()).sharedMaterials = (Material[])(object)new Material[1] { material };
			BoxCollider component = val.GetComponent<BoxCollider>();
			Bounds bounds = mesh.bounds;
			component.size = ((Bounds)(ref bounds)).size;
			bounds = mesh.bounds;
			component.center = ((Bounds)(ref bounds)).center;
			ShipItem component2 = val.GetComponent<ShipItem>();
			component2.name = itemName;
			component2.value = value;
			component2.mass = mass;
			((PickupableItem)component2).big = big;
			component2.category = (TransactionCategory)3;
			component2.sold = false;
			((GoPointerButton)component2).lookText = "";
			((GoPointerButton)component2).description = "";
			val.GetComponent<SaveablePrefab>().prefabIndex = index;
			return val;
		}

		internal static int Look(ShipItem plank)
		{
			if (!Object.op_Implicit((Object)(object)plank) || !(plank.health >= 0f) || !(plank.health <= 23f))
			{
				return 0;
			}
			return Mathf.RoundToInt(plank.health);
		}

		internal static void SetLook(ShipItem plank, int look)
		{
			plank.health = ((look >= 0 && look < 24) ? look : 0);
			ApplyLook(plank);
		}

		internal static void ApplyLook(ShipItem plank)
		{
			MeshFilter val = ((Object.op_Implicit((Object)(object)plank) && PlankMeshes != null) ? ((Component)plank).GetComponent<MeshFilter>() : null);
			if (Object.op_Implicit((Object)(object)val))
			{
				val.sharedMesh = PlankMeshes[Look(plank)];
			}
		}

		internal static void AddStock(ShopArea area)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			if (!Registered || !Object.op_Implicit((Object)(object)area) || ((Object)area).name != "shop area (15)")
			{
				return;
			}
			Scene scene = ((Component)area).gameObject.scene;
			if (((Scene)(ref scene)).buildIndex != 27)
			{
				return;
			}
			Transform transform = ((Component)area).transform;
			Vector3 val = Vector3.ProjectOnPlane(transform.forward, Vector3.up);
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			Quaternion val2 = Quaternion.LookRotation(Vector3.up, normalized);
			float[] stockAcross = StockAcross;
			foreach (float num in stockAcross)
			{
				float[] stockHeight = StockHeight;
				foreach (float num2 in stockHeight)
				{
					GameObject val3 = new GameObject("TentandPlank wood plank bundle stock");
					val3.transform.SetParent(transform.parent, false);
					Transform transform2 = val3.transform;
					Vector3 val4 = transform.TransformPoint(new Vector3(num, num2, 0.0153f));
					Bounds bounds = bundleMesh.bounds;
					transform2.SetPositionAndRotation(val4 - val2 * ((Bounds)(ref bounds)).center, val2);
					ShopItemSpawner obj = val3.AddComponent<ShopItemSpawner>();
					obj.itemPrefab = BundleTemplate;
					obj.availableAtNight = false;
					obj.priceMult = 1f;
				}
			}
		}

		internal static bool Unbundleable(ShipItem item)
		{
			if (Object.op_Implicit((Object)(object)item) && item.sold && !Object.op_Implicit((Object)(object)((PickupableItem)item).held))
			{
				if (!Registered || (Index(item) != 640 && Index(item) != 217))
				{
					return WoodPoles.IsBundle(item);
				}
				return true;
			}
			return false;
		}

		internal static string BlockReason(ShipItem item)
		{
			if (!Unbundleable(item) || item.GetCurrentInventorySlot() != -1)
			{
				return "";
			}
			Good component = ((Component)item).GetComponent<Good>();
			if (Object.op_Implicit((Object)(object)component) && component.GetMissionIndex() != -1)
			{
				return "Mission cargo cannot be unbundled";
			}
			CargoState cargoState = CargoRecords.Of(item);
			if (cargoState != null && cargoState.loan)
			{
				return "Repay or sell the financed lumber first";
			}
			if (cargoState != null && Rules.Ruined(cargoState.health))
			{
				return "Ruined lumber cannot be unbundled";
			}
			return null;
		}

		internal static int PlankCount(ShipItem item)
		{
			return Rules.Round((float)((Index(item) == 217) ? 128 : 8) * CargoCondition.Factor(item));
		}

		internal static void Ask(ShipItem item)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			string text = BlockReason(item);
			if (text != null)
			{
				if (text.Length > 0)
				{
					Notice.Show(text);
				}
				return;
			}
			CrateSealUI instance = CrateSealUI.instance;
			Camera main = Camera.main;
			if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)main))
			{
				Unbundle(item);
				return;
			}
			if (instance.showingUI)
			{
				instance.HideUI(false);
			}
			Transform transform = ((Component)instance).transform;
			Transform child = transform.GetChild(0);
			((Component)child).gameObject.SetActive(true);
			instance.showingUI = true;
			instance.currentCrate = null;
			transform.position = ((Component)main).transform.position + ((Component)main).transform.forward;
			transform.LookAt(((Component)main).transform);
			for (int i = 0; i < 20; i++)
			{
				if (!(Vector3.Distance(transform.position, ((Component)item).transform.position) < 0.7f))
				{
					break;
				}
				transform.Translate(Vector3.forward * 0.2f, (Space)1);
			}
			popupOffset = transform.position - ((Component)item).transform.position;
			popupFrame = Time.frameCount;
			if (!Object.op_Implicit((Object)(object)title))
			{
				title = Text(child, "text (1)");
				body = Text(child, "text (2)");
				button = Text(child, "break seal button/text");
			}
			if (Object.op_Implicit((Object)(object)title))
			{
				titleText = title.text;
				title.text = "BUNDLED\n";
			}
			if (Object.op_Implicit((Object)(object)body))
			{
				bodyText = body.text;
				body.text = (WoodPoles.IsBundle(item) ? ("Unbundling removes the ropes.\n\nYou get " + 4 + " wood poles.") : ("Unbundling removes the ropes.\n\nYou get " + PlankCount(item) + " wood planks.\nPlanks cannot be sold\nin the trade book."));
			}
			if (Object.op_Implicit((Object)(object)button))
			{
				buttonText = button.text;
				button.text = "Unbundle\n(remove ropes)";
			}
			TextMesh[] componentsInChildren = ((Component)instance).GetComponentsInChildren<TextMesh>(true);
			foreach (TextMesh val in componentsInChildren)
			{
				if (((Object)val).name == "Respondentia repayment prompt")
				{
					((Component)val).gameObject.SetActive(false);
				}
			}
			Pending = item;
			if (Object.op_Implicit((Object)(object)UISoundPlayer.instance))
			{
				UISoundPlayer.instance.PlayUISound((UISounds)7, 1f, 1f);
			}
		}

		private static TextMesh Text(Transform panel, string path)
		{
			Transform val = panel.Find(path);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			return ((Component)val).GetComponent<TextMesh>();
		}

		internal static bool PopupUpdate(CrateSealUI ui)
		{
			//IL_004d: 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_0057: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			if (Pending == null)
			{
				return true;
			}
			Camera main = Camera.main;
			if (!Object.op_Implicit((Object)(object)Pending) || !Object.op_Implicit((Object)(object)main) || Object.op_Implicit((Object)(object)((PickupableItem)Pending).held))
			{
				ui.HideUI(false);
				return false;
			}
			((Component)ui).transform.position = ((Component)Pending).transform.position + popupOffset;
			((Component)ui).transform.LookAt(((Component)main).transform);
			if ((Time.frameCount != popupFrame && ActivateDown()) || Vector3.Distance(((Component)ui).transform.position, ((Component)main).transform.position) > 2.25f)
			{
				ui.HideUI(true);
			}
			return false;
		}

		internal static bool PopupConfirm(CrateSealUI ui)
		{
			if (Pending == null)
			{
				return true;
			}
			ShipItem pending = Pending;
			ui.HideUI(false);
			if (Object.op_Implicit((Object)(object)pending))
			{
				Unbundle(pending);
			}
			return false;
		}

		internal static void PopupClosed()
		{
			if (Pending != null)
			{
				if (Object.op_Implicit((Object)(object)title))
				{
					title.text = titleText;
				}
				if (Object.op_Implicit((Object)(object)body))
				{
					body.text = bodyText;
				}
				if (Object.op_Implicit((Object)(object)button))
				{
					button.text = buttonText;
				}
				Pending = null;
			}
		}

		private static bool ActivateDown()
		{
			if (activateDown == null)
			{
				Type type = AccessTools.TypeByName("GameInput");
				Type type2 = AccessTools.TypeByName("InputName");
				MethodInfo method = ((type != null && type2 != null) ? AccessTools.Method(type, "GetKeyDown", new Type[1] { type2 }, (Type[])null) : null);
				object activate = ((method != null) ? Enum.Parse(type2, "Activate") : null);
				activateDown = ((method != null) ? ((Func<bool>)(() => (bool)method.Invoke(null, new object[1] { activate }))) : ((Func<bool>)(() => false)));
			}
			return activateDown();
		}

		internal static List<KeyValuePair<Pose, int>> Layout(ShipItem item)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_0114: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			bool flag = Index(item) == 217;
			int num = (flag ? 4 : 2);
			int num2 = (flag ? 8 : 2);
			int num3 = (flag ? 4 : 2);
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(0.155f, 0.8745f, 0.048f);
			MeshFilter component = ((Component)item).GetComponent<MeshFilter>();
			Vector3 val2;
			Bounds bounds;
			if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.sharedMesh))
			{
				val2 = Vector3.zero;
			}
			else
			{
				bounds = component.sharedMesh.bounds;
				val2 = ((Bounds)(ref bounds)).center;
			}
			Vector3 val3 = val2;
			Mesh val4 = (Object.op_Implicit((Object)(object)PlankTemplate) ? PlankTemplate.GetComponent<MeshFilter>().sharedMesh : null);
			Vector3 val5;
			if (!Object.op_Implicit((Object)(object)val4))
			{
				val5 = Vector3.zero;
			}
			else
			{
				bounds = val4.bounds;
				val5 = ((Bounds)(ref bounds)).center;
			}
			Vector3 val6 = val5;
			? val7;
			if (!Object.op_Implicit((Object)(object)val4))
			{
				val7 = new Vector3(0.872f, 0.152f, 0.045f);
			}
			else
			{
				bounds = val4.bounds;
				val7 = ((Bounds)(ref bounds)).size;
			}
			Vector3 val8 = (Vector3)val7;
			Vector3 val9 = default(Vector3);
			((Vector3)(ref val9))..ctor(((float)(num - 1) * val.x + val8.y) / 2f, ((float)(num3 - 1) * val.y + val8.x) / 2f, ((float)(num2 - 1) * val.z + val8.z) / 2f);
			Vector3 val10 = ((Component)item).transform.InverseTransformDirection(Vector3.down);
			int num4 = ((!(Mathf.Abs(val10.x) >= Mathf.Abs(val10.y)) || !(Mathf.Abs(val10.x) >= Mathf.Abs(val10.z))) ? ((Mathf.Abs(val10.y) >= Mathf.Abs(val10.z)) ? 1 : 2) : 0);
			float num5 = ((!(((Vector3)(ref val10))[num4] < 0f)) ? 1 : (-1));
			BoxCollider component2 = ((Component)item).GetComponent<BoxCollider>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				Vector3 val11 = component2.center;
				float num6 = ((Vector3)(ref val11))[num4];
				val11 = component2.size;
				float num7 = num5 * (num6 + num5 * ((Vector3)(ref val11))[num4] / 2f - (((Vector3)(ref val3))[num4] + num5 * ((Vector3)(ref val9))[num4]));
				if (num7 > 0f)
				{
					int num8 = num4;
					((Vector3)(ref val3))[num8] = ((Vector3)(ref val3))[num8] + num5 * num7;
				}
			}
			Quaternion val12 = ((Component)item).transform.rotation * ((num4 == 2 && num5 > 0f) ? Quaternion.LookRotation(Vector3.forward, Vector3.left) : Quaternion.LookRotation(Vector3.back, Vector3.right));
			List<KeyValuePair<Pose, int>> list = new List<KeyValuePair<Pose, int>>();
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num2; j++)
				{
					for (int k = 0; k < num3; k++)
					{
						list.Add(new KeyValuePair<Pose, int>(new Pose(((Component)item).transform.TransformPoint(val3 + new Vector3(((float)i - (float)(num - 1) / 2f) * val.x, ((float)k - (float)(num3 - 1) / 2f) * val.y, ((float)j - (float)(num2 - 1) / 2f) * val.z)) - val12 * val6, val12), Rules.PlankLook(flag, i, j, k)));
					}
				}
			}
			return list;
		}

		internal static void Unbundle(ShipItem item)
		{
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			string text = BlockReason(item);
			if (text != null)
			{
				if (text.Length > 0)
				{
					Notice.Show(text);
				}
				return;
			}
			bool flag = WoodPoles.IsBundle(item);
			List<KeyValuePair<Pose, int>> list = (flag ? (from x in WoodPoles.BundleLayout(item)
				select new KeyValuePair<Pose, int>(x, 0)).ToList() : (from p in Layout(item)
				orderby p.Key.position.y
				select p).Take(PlankCount(item)).ToList());
			Transform currentActualBoat = item.currentActualBoat;
			Collider val = null;
			if (Object.op_Implicit((Object)(object)currentActualBoat))
			{
				try
				{
					val = Fields.Get<Collider>(item, "currentBoatCollider");
				}
				catch (MissingFieldException)
				{
				}
			}
			Transform val2 = (Object.op_Implicit((Object)(object)((Component)item).transform.parent) ? ((Component)item).transform.parent : (Object.op_Implicit((Object)(object)FloatingOriginManager.instance) ? ((Component)FloatingOriginManager.instance).transform : null));
			if (Object.op_Implicit((Object)(object)UISoundPlayer.instance))
			{
				UISoundPlayer.instance.PlayUISound((UISounds)9, 1f, 1f);
			}
			Retire(item);
			List<ShipItem> list2 = new List<ShipItem>(list.Count);
			List<Pose> list3 = new List<Pose>(list.Count);
			foreach (KeyValuePair<Pose, int> item2 in list)
			{
				GameObject val3 = Object.Instantiate<GameObject>(flag ? WoodPoles.Template : PlankTemplate, item2.Key.position, item2.Key.rotation, val2);
				ShipItem component = val3.GetComponent<ShipItem>();
				component.sold = true;
				component.amount = 0f;
				if (flag)
				{
					WoodPoles.SetLength(component, 2f);
				}
				else
				{
					SetLook(component, item2.Value);
				}
				val3.GetComponent<SaveablePrefab>().RegisterToSave();
				list2.Add(component);
				if (Object.op_Implicit((Object)(object)currentActualBoat))
				{
					list3.Add(new Pose(currentActualBoat.InverseTransformPoint(item2.Key.position), Quaternion.Inverse(currentActualBoat.rotation) * item2.Key.rotation));
				}
			}
			if (Object.op_Implicit((Object)(object)currentActualBoat) && Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)Plugin.Instance))
			{
				((MonoBehaviour)Plugin.Instance).StartCoroutine(Board(item, list2, list3, currentActualBoat, val));
			}
			else
			{
				item.DestroyItem();
			}
		}

		private static void Retire(ShipItem item)
		{
			SaveablePrefab component = ((Component)item).GetComponent<SaveablePrefab>();
			if (Object.op_Implicit((Object)(object)component) && World.Ready && !World.Loading && !GameState.currentlyLoading && !World.SaveBlocked && component.GetParentObject() != -2 && component.GetParentObject() != -3)
			{
				CargoRecords.Destroyed(component.instanceId);
			}
			if (Object.op_Implicit((Object)(object)component))
			{
				component.Unregister();
			}
			if (Object.op_Implicit((Object)(object)item.itemRigidbodyC))
			{
				((Component)item.itemRigidbodyC).gameObject.SetActive(false);
			}
			Renderer[] componentsInChildren = ((Component)item).GetComponentsInChildren<Renderer>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
			Collider[] componentsInChildren2 = ((Component)item).GetComponentsInChildren<Collider>();
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				componentsInChildren2[i].enabled = false;
			}
		}

		private static IEnumerator Board(ShipItem old, List<ShipItem> planks, List<Pose> onBoat, Transform boat, Collider embark)
		{
			Spawning++;
			try
			{
				yield return (object)new WaitForFixedUpdate();
				for (int i = 0; i < planks.Count; i++)
				{
					ShipItem val = planks[i];
					if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)boat) || !Object.op_Implicit((Object)(object)embark) || Object.op_Implicit((Object)(object)((PickupableItem)val).held) || !Object.op_Implicit((Object)(object)val.itemRigidbodyC))
					{
						continue;
					}
					if (!Object.op_Implicit((Object)(object)val.currentActualBoat))
					{
						try
						{
							enterBoat.Invoke(val, new object[1] { embark });
						}
						catch (Exception ex)
						{
							ManualLogSource log = Plugin.Log;
							if (log != null)
							{
								log.LogWarning((object)("A wood plank could not board its boat: " + (ex.InnerException ?? ex).Message));
							}
							continue;
						}
					}
					if (!((Object)(object)val.currentActualBoat != (Object)(object)boat))
					{
						((Component)val).transform.SetPositionAndRotation(boat.TransformPoint(onBoat[i].position), boat.rotation * onBoat[i].rotation);
						val.itemRigidbodyC.ForceRigidbodyToWalkCol();
					}
				}
			}
			finally
			{
				Spawning--;
				if (Object.op_Implicit((Object)(object)old))
				{
					old.DestroyItem();
				}
			}
		}

		internal static BoatDamage Hull(ShipItem plank)
		{
			//IL_0092: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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)
			if (!IsPlank(plank) || !plank.sold || Object.op_Implicit((Object)(object)((PickupableItem)plank).held) || !Object.op_Implicit((Object)(object)plank.currentActualBoat) || !Object.op_Implicit((Object)(object)plank.currentWalkCol))
			{
				return null;
			}
			ItemRigidbody itemRigidbodyC = plank.itemRigidbodyC;
			Transform currentWalkCol = plank.currentWalkCol;
			if (!Object.op_Implicit((Object)(object)itemRigidbodyC) || !itemRigidbodyC.attached || !((Component)itemRigidbodyC).transform.IsChildOf(currentWalkCol))
			{
				return null;
			}
			BoatDamage componentInParent = ((Component)plank.currentActualBoat).GetComponentInParent<BoatDamage>();
			if (!Object.op_Implicit((Object)(object)componentInParent) || componentInParent.durabilityDays <= 0f)
			{
				return null;
			}
			Transform transform = ((Component)itemRigidbodyC).transform;
			RaycastHit[] array = Physics.RaycastAll(transform.position - transform.forward * 0.1f, transform.forward, 0.25f, -1, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val = array[i];
				if (Mathf.Abs(((RaycastHit)(ref val)).distance - 0.1f) <= 0.01f && ((Component)((RaycastHit)(ref val)).collider).transform.IsChildOf(currentWalkCol) && !Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<ItemRigidbody>()) && !Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<ShipItem>()))
				{
					return componentInParent;
				}
			}
			return null;
		}

		internal static int PlanksPerPercent(BoatDamage damage)
		{
			PurchasableBoat component = ((Component)damage).GetComponent<PurchasableBoat>();
			return Rules.PlanksPerPercent(Object.op_Implicit((Object)(object)component) ? component.price : 0, damage.waterUnitsCapacity, LumberValue);
		}

		internal static string HullHint(ShipItem plank)
		{
			BoatDamage val = (Object.op_Implicit((Object)(object)plank) ? Hull(plank) : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			return Rules.HullHint(Progress(plank), val.hullDamage, PlanksPerPercent(val));
		}

		internal static float Progress(ShipItem plank)
		{
			if (!Object.op_Implicit((Object)(object)plank) || !(plank.amount > 0f))
			{
				return 0f;
			}
			return Mathf.Min(1f, plank.amount);
		}

		internal static bool HammerStart(ShipItemHammer hammer)
		{
			if (!((ShipItem)hammer).sold || !Object.op_Implicit((Object)(object)((PickupableItem)hammer).held))
			{
				return true;
			}
			ShipItem pointedAtItem = ((PickupableItem)hammer).held.GetPointedAtItem();
			BoatDamage val = Hull(pointedAtItem);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return true;
			}
			if (val.hullDamage <= 0f)
			{
				Notice.Show("The hull needs no repair");
				return false;
			}
			if (job == null || (Object)(object)job.plank != (Object)(object)pointedAtItem)
			{
				EndJob();
				job = new Job
				{
					hammer = hammer,
					plank = pointedAtItem,
					startOffset = ((PickupableItem)hammer).heldRotationOffset
				};
			}
			job.frame = Time.frameCount;
			return false;
		}

		internal static bool HammerHeld(ShipItemHammer hammer)
		{
			if (job == null || (Object)(object)job.hammer != (Object)(object)hammer)
			{
				return true;
			}
			BoatDamage val = Hull(job.plank);
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)((PickupableItem)hammer).held) || (Object)(object)((PickupableItem)hammer).held.GetPointedAtItem() != (Object)(object)job.plank || val.hullDamage <= 0f)
			{
				EndJob();
				return true;
			}
			job.frame = Time.frameCount;
			float num = Mathf.Max(0f, val.waterUnitsCapacity);
			bool flag = Rules.Caulked(val.oakum, val.hullDamage, num);
			float num2 = Progress(job.plank) + Time.deltaTime / (flag ? 10f : 20f);
			if (((PickupableItem)hammer).heldRotationOffset < -95f)
			{
				job.back = true;
				if (Object.op_Implicit((Object)(object)UISoundPlayer.instance))
				{
					UISoundPlayer.instance.PlayUISound((UISounds)10, 1f, 0.7f);
				}
			}
			if (((PickupableItem)hammer).heldRotationOffset > -35f)
			{
				job.back = false;
			}
			((PickupableItem)hammer).heldRotationOffset = ((PickupableItem)hammer).heldRotationOffset + Time.deltaTime * 275f * (float)(job.back ? 1 : (-1));
			if (num2 < 1f)
			{
				job.plank.amount = num2;
				return false;
			}
			Finish(job.plank, val, flag);
			return false;
		}

		internal static void Finish(ShipItem plank, BoatDamage hull, bool caulked)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(0f, hull.waterUnitsCapacity);
			int num2 = PlanksPerPercent(hull);
			hull.hullDamage = Mathf.Max(0f, hull.hullDamage - 0.01f / (float)num2);
			if (caulked)
			{
				hull.oakum = Mathf.Max(0f, hull.oakum - 0.01f * num / (float)num2);
			}
			hull.oakum = Mathf.Min(hull.oakum, hull.hullDamage * num);
			if (job != null && (Object)(object)job.plank == (Object)(object)plank)
			{
				EndJob();
			}
			CoverEvents.RecheckBeneath(plank, CoverEvents.WorldBounds(plank));
			Retire(plank);
			plank.DestroyItem();
			if (Object.op_Implicit((Object)(object)UISoundPlayer.instance))
			{
				UISoundPlayer.instance.PlayUISound((UISounds)11, 1f, 0.6f);
			}
		}

		internal static void Tick()
		{
			if (job != null && (Time.frameCount - job.frame > 1 || !Object.op_Implicit((Object)(object)job.hammer) || !Object.op_Implicit((Object)(object)job.plank) || (Object)(object)((PickupableItem)job.hammer).held == (Object)null))
			{
				EndJob();
			}
		}

		private static void EndJob()
		{
			if (job != null && Object.op_Implicit((Object)(object)job.hammer))
			{
				((PickupableItem)job.hammer).heldRotationOffset = job.startOffset;
			}
			job = null;
		}
	}
	internal static class ObjMesh
	{
		internal static Mesh Load(string resource, string name)
		{
			return Read(resource, name, split: false)[0];
		}

		internal static List<Mesh> LoadAll(string resource, string name)
		{
			return Read(resource, name, split: true);
		}

		private static List<Mesh> Read(string resource, string name, bool split)
		{
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<Vector3> list3 = new List<Vector3>();
			List<Mesh> meshes = new List<Mesh>();
			List<Vector3> positions = null;
			List<Vector3> normals = null;
			List<Vector2> uvs = null;
			List<int> triangles = null;
			Dictionary<string, int> map = null;
			List<int> list4 = new List<int>();
			Begin();
			using (Stream stream = typeof(ObjMesh).Assembly.GetManifestResourceStream(resource))
			{
				using StreamReader streamReader = new StreamReader(stream ?? throw new InvalidDataException("Missing resource " + resource));
				string text;
				while ((text = streamReader.ReadLine()) != null)
				{
					string[] p = text.Trim().Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
					if (p.Length == 0 || p[0].StartsWith("#"))
					{
						continue;
					}
					if (p[0] == "o" && split)
					{
						End();
						Begin();
					}
					else if (p[0] == "v")
					{
						list.Add(new Vector3(0f - N(1), N(2), N(3)));
					}
					else if (p[0] == "vt")
					{
						list2.Add(new Vector2(N(1), N(2)));
					}
					else if (p[0] == "vn")
					{
						list3.Add(new Vector3(0f - N(1), N(2), N(3)));
					}
					else
					{
						if (!(p[0] == "f"))
						{
							continue;
						}
						list4.Clear();
						for (int i = 1; i < p.Length; i++)
						{
							string[] parts;
							if (!map.TryGetValue(p[i], out var value))
							{
								parts = p[i].Split(new char[1] { '/' });
								int index = Ix(0, list.Count);
								int num = Ix(1, list2.Count);
								int num2 = Ix(2, list3.Count);
								value = positions.Count;
								map[p[i]] = value;
								positions.Add(list[index]);
								uvs.Add((num >= 0) ? list2[num] : Vector2.zero);
								normals.Add((num2 >= 0) ? list3[num2] : Vector3.up);
							}
							list4.Add(value);
							int Ix(int k, int count)
							{
								if (k >= parts.Length || parts[k].Length == 0)
								{
									return -1;
								}
								int num3 = int.Parse(parts[k], CultureInfo.InvariantCulture);
								if (num3 <= 0)
								{
									return count + num3;
								}
								return num3 - 1;
							}
						}
						for (int j = 1; j + 1 < list4.Count; j++)
						{
							triangles.Add(list4[0]);
							triangles.Add(list4[j + 1]);
							triangles.Add(list4[j]);
						}
					}
					float N(int num3)
					{
						return float.Parse(p[num3], CultureInfo.InvariantCulture);
					}
				}
			}
			End();
			if (meshes.Count == 0)
			{
				throw new InvalidDataException("Empty mesh " + resource);
			}
			return meshes;
			void Begin()
			{
				positions = new List<Vector3>();
				uvs = new List<Vector2>();
				normals = new List<Vector3>();
				triangles = new List<int>();
				map = new Dictionary<string, int>();
			}
			void End()
			{
				//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_005a: Expected O, but got Unknown
				if (positions.Count != 0 && triangles.Count != 0)
				{
					Mesh val = new Mesh
					{
						name = (split ? (name + " " + meshes.Count) : name)
					};
					if (positions.Count > 65000)
					{
						val.indexFormat = (IndexFormat)1;
					}
					val.SetVertices(positions);
					val.SetUVs(0, uvs);
					val.SetNormals(normals);
					val.SetTriangles(triangles, 0);
					val.RecalculateBounds();
					meshes.Add(val);
				}
			}
		}

		internal static void Shift(Mesh mesh, Vector3 offset)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] vertices = mesh.vertices;
			for (int i = 0; i < vertices.Length; i++)
			{
				ref Vector3 reference = ref vertices[i];
				reference += offset;
			}
			mesh.vertices = vertices;
			mesh.RecalculateBounds();
		}
	}
	[HarmonyPatch(typeof(PrefabsDirectory), "Start")]
	internal static class PlankRegistrationPatch
	{
		private static void Prefix(PrefabsDirectory __instance)
		{
			WoodPlanks.Register(__instance);
			Tarps.Register(__instance);
			WoodPoles.Register(__instance);
		}
	}
	[HarmonyPatch(typeof(ShopArea), "Awake")]
	internal static class PlankStockPatch
	{
		private static void Postfix(ShopArea __instance)
		{
			WoodPlanks.AddStock(__instance);
			Tarps.AddStock(__instance);
		}
	}
	[HarmonyPatch(typeof(GoPointerButton), "OnAltActivate", new Type[] { typeof(GoPointer) })]
	internal static class UnbundlePatch
	{
		private static void Postfix(GoPointerButton __instance, GoPointer activatingPointer)
		{
			ShipItem val = (ShipItem)(object)((__instance is ShipItem) ? __instance : null);
			if (val != null && Object.op_Implicit((Object)(object)activatingPointer) && !Object.op_Implicit((Object)(object)activatingPointer.GetHeldItem()) && WoodPlanks.Unbundleable(val))
			{
				WoodPlanks.Ask(val);
			}
		}
	}
	[HarmonyPatch(typeof(CrateSealUI), "Update")]
	internal static class UnbundlePopupPatch
	{
		private static bool Prefix(CrateSealUI __instance)
		{
			return WoodPlanks.PopupUpdate(__instance);
		}
	}
	[HarmonyPatch(typeof(CrateSealUI), "Activate")]
	internal static class UnbundleConfirmPatch
	{
		private static bool Prefix(CrateSealUI __instance)
		{
			return WoodPlanks.PopupConfirm(__instance);
		}
	}
	[HarmonyPatch(typeof(CrateSealUI), "HideUI")]
	internal static class UnbundleClosePatch
	{
		private static void Postfix()
		{
			WoodPlanks.PopupClosed();
		}
	}
	[HarmonyPatch(typeof(CrateSealUI), "ShowUI")]
	internal static class UnbundleCratePatch
	{
		private static void Prefix()
		{
			WoodPlanks.PopupClosed();
		}
	}
	[HarmonyPatch(typeof(ShipItemHammer), "OnAltActivate", new Type[] { })]
	internal static class PlankHammerPatch
	{
		private static bool Prefix(ShipItemHammer __instance)
		{
			return WoodPlanks.HammerStart(__instance);
		}
	}
	[HarmonyPatch(typeof(ShipItemHammer), "OnAltHeld", new Type[] { })]
	internal static class PlankHammerHeldPatch
	{
		private static bool Prefix(ShipItemHammer __instance)
		{
			return WoodPlanks.HammerHeld(__instance);
		}
	}
	[HarmonyPatch(typeof(ShipItem), "OnPickup")]
	internal static class PlankPickupPatch
	{
		private static void Postfix(ShipItem __instance)
		{
			if (WoodPlanks.IsPlank(__instance))
			{
				__instance.amount = 0f;
			}
		}
	}
	[HarmonyPatch(typeof(SaveablePrefab), "Load")]
	internal static class PlankLoadPatch
	{
		private static void Postfix(SaveablePrefab __instance)
		{
			ShipItem component = ((Component)__instance).GetComponent<ShipItem>();
			if (WoodPlanks.IsPlank(component))
			{
				WoodPlanks.ApplyLook(component);
			}
			else if (WoodPoles.IsPole(component))
			{
				WoodPoles.ApplyLength(component);
			}
		}
	}
	[HarmonyPatch(typeof(ShipItem), "UpdateLookText")]
	internal static class PlankLookTextPatch
	{
		private static void Postfix(ShipItem __instance)
		{
			if (WoodPlanks.IsPlank(__instance))
			{
				string text = WoodPlanks.HullHint(__instance);
				if (text != null)
				{
					((GoPointerButton)__instance).lookText = text;
					((GoPointerButton)__instance).description = "";
				}
			}
		}
	}
	[HarmonyPatch(typeof(LookUI), "ShowLookText")]
	internal static class PlankLookUIPatch
	{
		private static readonly MethodInfo hideIcons = AccessTools.Method(typeof(LookUI), "HideIcons", (Type[])null, (Type[])null);

		private static readonly MethodInfo showL = AccessTools.Method(typeof(LookUI), "ShowLicon", (Type[])null, (Type[])null);

		private static readonly MethodInfo showR = AccessTools.Method(typeof(LookUI), "ShowRicon", (Type[])null, (Type[])null);

		private static void Postfix(LookUI __instance, GoPointerButton button)
		{
			ShipItem val = (ShipItem)(object)((button is ShipItem) ? button : null);
			if (val == null || !WoodPlanks.Registered)
			{
				return;
			}
			if (WoodPlanks.IsPlank(val) && WoodPlanks.HullHint(val) != null)
			{
				Fields.Get<TextMesh>(__instance, "controlsText").text = "";
				Fields.Get<TextMesh>(__instance, "hintText").text = "";
				hideIcons.Invoke(__instance, null);
				return;
			}
			GoPointer val2 = Fields.Get<GoPointer>(__instance, "pointer");
			if (Settings.controlsTextEnabled && WoodPlanks.Unbundleable(val) && Object.op_Implicit((Object)(object)val2) && !Object.op_Implicit((Object)(object)val2.GetHeldItem()) && WoodPlanks.BlockReason(val) == null)
			{
				showL.Invoke(__instance, null);
				showR.Invoke(__instance, null);
				Fields.Get<TextMesh>(__instance, "controlsText").text = (val.nailed ? "\nunbundle" : "pick up\nunbundle");
			}
		}
	}
	internal static class WoodPoles
	{
		internal const int PoleIndex = 643;

		internal const int BundleIndex = 644;

		internal const float Thickness = 0.08f;

		private const int Sides = 12;

		private const float UvPerMetre = 0.0925f;

		private const float U0 = 0.7645f;

		private const float UWidth = 0.012f;

		private const float V0 = 0.26f;

		internal static GameObject Template;

		internal static GameObject BundleTemplate;

		internal static readonly HashSet<ShipItem> Live = new HashSet<ShipItem>();

		private static readonly Dictionary<int, Mesh> meshes = new Dictionary<int, Mesh>();

		internal const float BundleBand = 0.1f;

		private static Mesh bundleMesh;

		internal const string HeldLookName = "wood pole held look";

		private static readonly Vector3 HeldAxis = new Vector3(0f, Mathf.Cos(MathF.PI / 12f), Mathf.Sin(MathF.PI / 12f));

		private static KeyCode repeating;

		private static float repeatAt;

		private static readonly FieldRef<ShipItem, bool> inRangeOfWall = AccessTools.FieldRefAccess<ShipItem, bool>("inRangeOfWall");

		private static readonly FieldRef<ShipItem, Vector3> attachPos = AccessTools.FieldRefAccess<ShipItem, Vector3>("attachPos");

		private static readonly FieldRef<ShipItem, Quaternion> attachRot = AccessTools.FieldRefAccess<ShipItem, Quaternion>("attachRot");

		internal const float AttachReach = 2.55f;

		internal static ShipItem AimedPole;

		internal static Pose AimedAt;

		private static ShipItem aimedBy;

		private static int aimedFrame;

		private static Transform aimedShip;

		private static Pose aimedLocal;

		private static readonly MethodInfo enterBoat = AccessTools.Method(typeof(ShipItem), "EnterBoat", (Type[])null, (Type[])null);

		internal static bool Registered => Object.op_Implicit((Object)(object)Template);

		internal static bool IsPole(ShipItem item)
		{
			if (Registered)
			{
				return WoodPlanks.Index(item) == 643;
			}
			return false;
		}

		internal static bool IsBundle(ShipItem item)
		{
			if (Object.op_Implicit((Object)(object)BundleTemplate))
			{
				return WoodPlanks.Index(item) == 644;
			}
			return false;
		}

		internal static float Length(ShipItem pole)
		{
			return Rules.PoleLength(pole.health);
		}

		internal static string Format(float metres)
		{
			return Rules.PoleLength(metres).ToString("F1", CultureInfo.InvariantCulture) + " m";
		}

		internal static void Register(PrefabsDirectory directory)
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			if (Registered || !Object.op_Implicit((Object)(object)directory) || directory.directory == null)
			{
				return;
			}
			GameObject[] array = directory.directory;
			if (array.Length > 643 && Object.op_Implicit((Object)(object)array[643]))
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)"Prefab slot 643 is used by another mod; wood poles are disabled.");
				}
				return;
			}
			if (array.Length <= 217 || !Object.op_Implicit((Object)(object)array[217]) || !Object.op_Implicit((Object)(object)array[120]))
			{
				ManualLogSource log2 = Plugin.Log;
				if (log2 != null)
				{
					log2.LogError((object)"Lumber or painting prefab missing; wood poles are disabled.");
				}
				return;
			}
			try
			{
				GameObject val = new GameObject("TentandPlank pole template");
				val.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)val);
				Material sharedMaterial = ((Renderer)array[217].GetComponent<MeshRenderer>()).sharedMaterial;
				GameObject val2 = WoodPlanks.Template(array[120], val.transform, "643 wood pole", Mesh(2f), sharedMaterial, 643, "wood pole", 60, Rules.PoleMass(2.0), big: false);
				ShipItem component = val2.GetComponent<ShipItem>();
				component.wallAttachment = true;
				component.health = 2f;
				component.amount = 0f;
				MeshRenderer component2 = val2.GetComponent<MeshRenderer>();
				GameObject val3 = new GameObject("wood pole held look");
				val3.transform.SetParent(val2.transform, false);
				val3.SetActive(false);
				val3.AddComponent<MeshFilter>().sharedMesh = Mesh(2f);
				MeshRenderer obj = val3.AddComponent<MeshRenderer>();
				((Renderer)obj).sharedMaterials = ((Renderer)component2).sharedMaterials;
				((Renderer)obj).shadowCastingMode = ((Renderer)component2).shadowCastingMode;
				((Renderer)obj).receiveShadows = ((Renderer)component2).receiveShadows;
				HeldPose(val3.transform, 2f);
				val2.AddComponent<PoleHeldLook>();
				if (array.Length <= 644)
				{
					GameObject[] array2 = (GameObject[])(object)new GameObject[645];
					Array.Copy(array, array2, array.Length);
					array = (directory.directory = array2);
				}
				array[643] = val2;
				Template = val2;
				ManualLogSource log3 = Plugin.Log;
				if (log3 != null)
				{
					log3.LogInfo((object)"Registered wood pole (643).");
				}
				if (Object.op_Implicit((Object)(object)array[644]))
				{
					ManualLogSource log4 = Plugin.Log;
					if (log4 != null)
					{
						log4.LogError((object)"Prefab slot 644 is used by another mod; wood pole bundles are disabled (no poles in shops).");
					}
					return;
				}
				GameObject val4 = WoodPlanks.Template(array[120], val.transform, "644 wood pole bundle", BundleMesh(), sharedMaterial, 644, "wood pole bundle", 240, Rules.PoleBundleMass, big: true);
				ShipItem component3 = val4.GetComponent<ShipItem>();
				component3.wallAttachment = false;
				component3.amount = 0f;
				array[644] = val4;
				BundleTemplate = val4;
				ManualLogSource log5 = Plugin.Log;
				if (log5 != null)
				{
					log5.LogInfo((object)"Registered wood pole bundle (644).");
				}
			}
			catch (Exception ex)
			{
				Template = null;
				ManualLogSource log6 = Plugin.Log;
				if (log6 != null)
				{
					log6.LogError((object)("Wood pole registration failed; wood poles are disabled. " + ex));
				}
			}
		}

		internal static Mesh Mesh(float metres)
		{
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: 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_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_0123: 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_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Expected O, but got Unknown
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			int num = Rules.PoleTenths(metres);
			if (meshes.TryGetValue(num, out var value) && Object.op_Implicit((Object)(object)value))
			{
				return value;
			}
			float num2 = (float)num / 10f;
			float num3 = 0.04f;
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<int> list4 = new List<int>();
			List<float> list5 = new List<float> { 0f };
			for (double num4 = 3.4; num4 < (double)num2 - 0.001; num4 += 3.4)
			{
				list5.Add((float)num4);
			}
			list5.Add(num2);
			Vector3 val = default(Vector3);
			for (int i = 0; i <= 12; i++)
			{
				float num5 = (float)(i * 2) * MathF.PI / 12f;
				((Vector3)(ref val))..ctor(Mathf.Cos(num5), Mathf.Sin(num5), 0f);
				float num6 = 0.7645f + 0.012f * (1f - Mathf.Abs(2f * (float)i / 12f - 1f));
				foreach (float item3 in list5)
				{
					list.Add(val * num3 + Vector3.back * item3);
					list2.Add(val);
					list3.Add(new Vector2(num6, 0.26f + (float)Rules.PoleGrain(item3) * 0.0925f));
				}
			}
			int count = list5.Count;
			for (int j = 0; j < 12; j++)
			{
				for (int k = 0; k < count - 1; k++)
				{
					int num7 = j * count + k;
					int num8 = num7 + count;
					list4.AddRange(new int[6]
					{
						num7,
						num7 + 1,
						num8,
						num8,
						num7 + 1,
						num8 + 1
					});
				}
			}
			(float, Vector3)[] array = new(float, Vector3)[2]
			{
				(0f, Vector3.forward),
				(0f - num2, Vector3.back)
			};
			for (int l = 0; l < array.Length; l++)
			{
				(float, Vector3) tuple = array[l];
				float item = tuple.Item1;
				Vector3 item2 = tuple.Item2;
				int count2 = list.Count;
				list.Add(new Vector3(0f, 0f, item));
				list2.Add(item2);
				list3.Add(new Vector2(0.7705f, 0.26f + num3 * 0.0925f));
				for (int m = 0; m < 12; m++)
				{
					float num9 = (float)(m * 2) * MathF.PI / 12f;
					list.Add(new Vector3(Mathf.Cos(num9) * num3, Mathf.Sin(num9) * num3, item));
					list2.Add(item2);
					list3.Add(new Vector2(0.7645f + (Mathf.Cos(num9) + 1f) / 2f * 0.012f, 0.26f + (Mathf.Sin(num9) + 1f) * num3 * 0.0925f));
				}
				for (int n = 0; n < 12; n++)
				{
					int num10 = count2 + 1 + n;
					int num11 = count2 + 1 + (n + 1) % 12;
					if (item == 0f)
					{
						list4.AddRange(new int[3] { count2, num10, num11 });
					}
					else
					{
						list4.AddRange(new int[3] { count2, num11, num10 });
					}
				}
			}
			Mesh val2 = new Mesh
			{
				name = "wood pole " + Format(num2)
			};
			val2.SetVertices(list);
			val2.SetNormals(list2);
			val2.SetUVs(0, list3);
			val2.SetTriangles(list4, 0);
			val2.RecalculateBounds();
			val2.RecalculateTangents();
			meshes[num] = val2;
			return val2;
		}

		internal static Mesh BundleMesh()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009b: 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_00b4: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: 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_018f: Expected O, but got Unknown
			//IL_0190: Expected O, but got Unknown
			if (Object.op_Implicit((Object)(object)bundleMesh))
			{
				return bundleMesh;
			}
			float r = 0.04f;
			float num = 2f;
			List<Vector3> v = new List<Vector3>();
			List<Vector3> n = new List<Vector3>();
			List<Vector2> uv = new List<Vector2>();
			List<int> t = new List<int>();
			Vector2[] array = (Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f - r, 0f - r),
				new Vector2(r, 0f - r),
				new Vector2(r, r),
				new Vector2(0f - r, r)
			};
			for (int i = 0; i < array.Length; i++)
			{
				Tube(array[i], r, 0f, 0f - num, wood: true);
			}
			float[] array2 = new float[2]
			{
				-0.4f,
				0f - num + 0.4f
			};
			foreach (float num2 in array2)
			{
				Tube(Vector2.zero, 0.1f, num2 + 0.025f, num2 - 0.025f, wood: false);
			}
			Mesh val = new Mesh
			{
				name = "wood pole bundle"
			};
			val.SetVertices(v);
			val.SetNormals(n);
			val.SetUVs(0, uv);
			val.SetTriangles(t, 0);
			val.RecalculateBounds();
			val.RecalculateTangents();
			bundleMesh = val;
			return val;
			void Tube(Vector2 at, float radius, float z0, float z1, bool wood)
			{
				//IL_0082: 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_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: Unknown result type (might be due to invalid IL or missing references)
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: 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_00b1: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00de: Unknown result type (might be due to invalid IL or missing references)
				//IL_00df: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: 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_0133: Unknown result type (might be due to invalid IL or missing references)
				//IL_011f: Unknown result type (might be due to invalid IL or missing references)
				//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0202: Unknown result type (might be due to invalid IL or missing references)
				//IL_0203: Unknown result type (might be due to invalid IL or missing references)
				//IL_0208: Unknown result type (might be due to invalid IL or missing references)
				//IL_020f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0214: Unknown result type (might be due to invalid IL or missing references)
				//IL_0225: Unknown result type (might be due to invalid IL or missing references)
				//IL_024b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0277: Unknown result type (might be due to invalid IL or missing references)
				//IL_0278: Unknown result type (might be due to invalid IL or missing references)
				//IL_0291: Unknown result type (might be due to invalid IL or missing references)
				//IL_0296: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_032a: Unknown result type (might be due to invalid IL or missing references)
				//IL_032c: Unknown result type (might be due to invalid IL or missing references)
				int count = v.Count;
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(0.01f, 0.01f);
				Vector3 val3 = default(Vector3);
				for (int j = 0; j <= 12; j++)
				{
					float num3 = (float)(j * 2) * MathF.PI / 12f;
					float num4 = 0.7645f + 0.012f * (1f - Mathf.Abs(2f * (float)j / 12f - 1f));
					((Vector3)(ref val3))..ctor(Mathf.Cos(num3), Mathf.Sin(num3), 0f);
					v.Add(Vector2.op_Implicit(at) + val3 * radius + Vector3.forward * z0);
					n.Add(val3);
					uv.Add((Vector2)(wood ? new Vector2(num4, 0.26f) : val2));
					v.Add(Vector2.op_Implicit(at) + val3 * radius + Vector3.forward * z1);
					n.Add(val3);
					uv.Add((Vector2)(wood ? new Vector2(num4, 0.26f + (z0 - z1) * 0.0925f) : val2));
				}
				for (int k = 0; k < 12; k++)
				{
					int num5 = count + 2 * k;
					t.AddRange(new int[6]
					{
						num5,
						num5 + 1,
						num5 + 2,
						num5 + 2,
						num5 + 1,
						num5 + 3
					});
				}
				if (wood)
				{
					(float, Vector3)[] array3 = new(float, Vector3)[2]
					{
						(z0, Vector3.forward),
						(z1, Vector3.back)
					};
					for (int l = 0; l < array3.Length; l++)
					{
						(float, Vector3) tuple = array3[l];
						float item = tuple.Item1;
						Vector3 item2 = tuple.Item2;
						int count2 = v.Count;
						v.Add(Vector2.op_Implicit(at) + Vector3.forward * item);
						n.Add(item2);
						uv.Add(new Vector2(0.7705f, 0.26f + r * 0.0925f));
						for (int m = 0; m < 12; m++)
						{
							float num6 = (float)(m * 2) * MathF.PI / 12f;
							v.Add(Vector2.op_Implicit(at) + new Vector3(Mathf.Cos(num6) * radius, Mathf.Sin(num6) * radius, item));
							n.Add(item2);
							uv.Add(new Vector2(0.7645f + (Mathf.Cos(num6) + 1f) / 2f * 0.012f, 0.26f + (Mathf.Sin(num6) + 1f) * r * 0.0925f));
						}
						for (int num7 = 0; num7 < 12; num7++)
						{
							int num8 = count2 + 1 + num7;
							int num9 = count2 + 1 + (num7 + 1) % 12;
							if (item2 == Vector3.forward)
							{
								t.AddRange(new int[3] { count2, num8, num9 });
							}
							else
							{
								t.AddRange(new int[3] { count2, num9, num8 });
							}
						}
					}
				}
			}
		}

		internal static List<Pose> BundleLayout(ShipItem bundle)
		{
			//IL_001f: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			float num = 0.04f;
			return ((IEnumerable<Vector2>)(object)new Vector2[4]
			{
				new Vector2(0f - num, 0f - num),
				new Vector2(num, 0f - num),
				new Vector2(num, num),
				new Vector2(0f - num, num)
			}).Select((Func<Vector2, Pose>)((Vector2 a) => new Pose(((Component)bundle).transform.TransformPoint(new Vector3(a.x, a.y, 0f)), ((Component)bundle).transform.rotation))).ToList();
		}

		internal static void SetLength(ShipItem pole, float metres)
		{
			//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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)pole))
			{
				float num = (pole.health = Rules.PoleLength(metres));
				Mesh val = Mesh(num);
				MeshFilter component = ((Component)pole).GetComponent<MeshFilter>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.sharedMesh = val;
				}
				Transform val2 = ((Component)pole).transform.Find("wood pole held look");
				if (Object.op_Implicit((Object)(object)val2))
				{
					((Component)val2).GetComponent<MeshFilter>().sharedMesh = val;
					HeldPose(val2, num);
				}
				BoxCollider component2 = ((Component)pole).GetComponent<BoxCollider>();
				Bounds bounds;
				if (Object.op_Implicit((Object)(object)component2))
				{
					bounds = val.bounds;
					component2.size = ((Bounds)(ref bounds)).size;
					bounds = val.bounds;
					component2.center = ((Bounds)(ref bounds)).center;
				}
				ItemRigidbody itemRigidbodyC = pole.itemRigidbodyC;
				BoxCollider val3 = (Object.op_Implicit((Object)(object)itemRigidbodyC) ? Fields.Get<BoxCollider>(itemRigidbodyC, "boxCol") : null);
				if (Object.op_Implicit((Object)(object)val3))
				{
					bounds = val.bounds;
					val3.size = ((Bounds)(ref bounds)).size;
					bounds = val.bounds;
					val3.center = ((Bounds)(ref bounds)).center;
				}
				pole.mass = Rules.PoleMass(num);
				if (Object.op_Implicit((Object)(object)itemRigidbodyC) && Object.op_Implicit((Object)(object)itemRigidbodyC.GetBody()))
				{
					itemRigidbodyC.UpdateMass();
				}
			}
		}

		internal static void ApplyLength(ShipItem pole)
		{
			SetLength(pole, pole.health);
		}

		internal static void HeldLocal(float length, out Vector3 at, out Quaternion turn)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			turn = Quaternion.FromToRotation(Vector3.back, HeldAxis);
			at = -HeldAxis * (length / 3f) + Vector3.right * 0.3f;
		}

		internal static void HeldPose(Transform look, float length)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			HeldLocal(length, out var at, out var turn);
			look.localRotation = turn;
			look.localPosition = at;
			look.localScale = Vector3.one;
		}

		internal static void AimAtPole(ShipItem held, Ray eye)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_00c3: 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_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_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			AimedPole = null;
			if (!Object.op_Implicit((Object)(object)((PickupableItem)held).held))
			{
				return;
			}
			ShipItem val = null;
			float num = 2.55f;
			Vector3 val2 = default(Vector3);
			foreach (ShipItem item in Live)
			{
				if (!Object.op_Implicit((Object)(object)item) || (Object)(object)item == (Object)(object)held || !item.sold || !item.nailed || PoleCarry.Riding(item))
				{
					continue;
				}
				BoxCollider component = ((Component)item).GetComponent<BoxCollider>();
				if (!Object.op_Implicit((Object)(object)component))
				{
					continue;
				}
				Transform transform = ((Component)item).transform;
				Vector3 val3 = transform.InverseTransformPoint(((Ray)(ref eye)).origin) - component.center;
				Vector3 val4 = transform.InverseTransformDirection(((Ray)(ref eye)).direction);
				Vector3 val5 = component.size / 2f;
				float num2 = 0f;
				float num3 = num;
				int num4 = -1;
				float num5 = 0f;
				bool flag = false;
				for (int i = 0; i < 3; i++)
				{
					if (flag)
					{
						break;
					}
					if (Mathf.Abs(((Vector3)(ref val4))[i]) < 1E-06f)
					{
						flag = Mathf.Abs(((Vector3)(ref val3))[i]) > ((Vector3)(ref val5))[i];
						continue;
					}
					float num6 = (0f - ((Vector3)(ref val5))[i] - ((Vector3)(ref val3))[i]) / ((Vector3)(ref val4))[i];
					float num7 = (((Vector3)(ref val5))[i] - ((Vector3)(ref val3))[i]) / ((Vector3)(ref val4))[i];
					if (num6 > num7)
					{
						float num8 = num6;
						num6 = num7;
						num7 = num8;
					}
					if (num6 > num2)
					{
						num2 = num6;
						num4 = i;
						num5 = ((!(((Vector3)(ref val4))[i] > 0f)) ? 1 : (-1));
					}
					num3 = Mathf.Min(num3, num7);
					flag = num2 > num3;
				}
				if (!flag && num4 >= 0 && !(num2 < 0.1f) && !(num2 >= num))
				{
					Vector3 zero = Vector3.zero;
					((Vector3)(ref zero))[num4] = num5;
					val = item;
					num = num2;
					Vector3 val6 = transform.TransformDirection(zero);
					val2 = ((Vector3)(ref val6)).normalized;
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			RaycastHit[] array = Physics.RaycastAll(eye, num - 0.05f, -1, (QueryTriggerInteraction)1);
			for (int j = 0; j < array.Length; j++)
			{
				RaycastHit val7 = array[j];
				Collider collider = ((RaycastHit)(ref val7)).collider;
				if (!(((RaycastHit)(ref val7)).distance < 0.1f) && !((Component)collider).transform.IsChildOf(((Component)held).transform) && (!Object.op_Implicit((Object)(object)held.itemRigidbodyC) || !((Component)collider).transform.IsChildOf(((Component)held.itemRigidbodyC).transform)) && !Object.op_Implicit((Object)(object)((Component)collider).GetComponentInParent<ItemRigidbody>()) && !Object.op_Implicit((Object)(object)((Component)collider).GetComponentInParent<ShipItem>()))
				{
					return;
				}
			}
			Vector3 point = ((Ray)(ref eye)).GetPoint(num);
			Quaternion val8 = ((Mathf.Abs(val2.y) > 0.8f) ? Quaternion.LookRotation(-val2, ((Component)held).transform.up) : Quaternion.LookRotation(-val2, Vector3.up));
			inRangeOfWall.Invoke(held) = true;
			attachPos.Invoke(held) = point;
			attachRot.Invoke(held) = val8;
			AimedPole = val;
			AimedAt = new Pose(point, val8);
			((PickupableItem)held).held.GetTargeter().DisplayTargeter(point, val8, ((Component)held).GetComponent<MeshFilter>().sharedMesh);
			aimedBy = held;
			aimedFrame = Time.frameCount;
			aimedShip = val.currentActualBoat;
			if (Object.op_Implicit((Object)(object)aimedShip))
			{
				aimedLocal = new Pose(aimedShip.InverseTransformPoint(point), Quaternion.Inverse(aimedShip.rotation) * val8);
			}
		}

		internal static void OnPoleDrop(ShipItem pole)
		{
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)pole != (Object)(object)aimedBy || Time.frameCount - aimedFrame > 1 || !Object.op_Implicit((Object)(object)aimedShip) || !Object.op_Implicit((Object)(object)pole.itemRigidbodyC))
			{
				return;
			}
			Transform val = aimedShip;
			aimedBy = null;
			if ((Object)(object)pole.currentActualBoat != (Object)(object)val)
			{
				BoatEmbarkCollider obj = Tarps.Link(val);
				Collider val2 = ((obj != null) ? ((Component)obj).GetComponent<Collider>() : null);
				if (Object.op_Implicit((Object)(object)val2))
				{
					try
					{
						enterBoat.Invoke(pole, new object[1] { val2 });
					}
					catch (Exception ex)
					{
						ManualLogSource log = Plugin.Log;
						if (log != null)
						{
							log.LogWarning((object)("A wood pole could not board her: " + (ex.InnerException ?? ex).Message));
						}
					}
				}
			}
			if (!((Object)(object)pole.currentActualBoat != (Object)(object)val))
			{
				((Component)pole).transform.SetPositionAndRotation(val.TransformPoint(aimedLocal.position), val.rotation * aimedLocal.rotation);
				pole.itemRigidbodyC.ForceRigidbodyToWalkCol();
				pole.itemRigidbodyC.attached = true;
			}
		}

		internal static string PickupNotice(ShipItem pole)
		{
			return "Wood pole " + Format(Length(pole)) + (PoleCarry.Carries(pole) ? " (things on it: length fixed)" : " (Q/E: length)");
		}

		internal static void Keys(GoPointer pointer)
		{
			//IL_003e: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			ShipItem val = (ShipItem)(Object.op_Implicit((Object)(object)pointer) ? /*isinst with value type is only supported in some contexts*/: null);
			PoleBrace.Keys(pointer, val);
			if (!GameState.playing || !IsPole(val) || !val.sold || val.nailed)
			{
				repeating = (KeyCode)0;
				return;
			}
			int num = 0;
			(KeyCode, int)[] array = new(KeyCode, int)[2]
			{
				((KeyCode)113, 1),
				((KeyCode)101, -1)
			};
			for (int i = 0; i < array.Length; i++)
			{
				var (val2, num2) = array[i];
				if (Input.GetKeyDown(val2))
				{
					num = num2;
					repeating = val2;
					repeatAt = Time.unscaledTime + 0.4f;
				}
				else if (repeating == val2 && Input.GetKey(val2) && Time.unscaledTime >= repeatAt)
				{
					num = num2;
					repeatAt = Time.unscaledTime + 0.08f;
				}
			}
			if ((int)repeating != 0 && !Input.GetKey(repeating))
			{
				repeating = (KeyCode)0;
			}
			if (num == 0)
			{
				return;
			}
			if (PoleCarry.Carries(val))
			{
				Notice.Show("Length fixed: things on the pole");
				return;
			}
			float num3 = Length(val);
			float num4 = Rules.PoleLength(num3 + (float)num * 0.1f);
			if (num4 != num3)
			{
				SetLength(val, num4);
			}
			if (num4 >= 8f || num4 <= 0.2f)
			{
				Notice.Show("Wood pole " + Format(num4) + ((num4 >= 8f) ? " (longest)" : " (shortest)"));
			}
		}
	}
	internal sealed class PoleHeldLook : MonoBehaviour
	{
		private ShipItem item;

		private MeshRenderer root;

		private GameObject look;

		private bool shown;

		private void Awake()
		{
			item = ((Component)this).GetComponent<ShipItem>();
			root = ((Component)this).GetComponent<MeshRenderer>();
			Transform val = ((Component)this).transform.Find("wood pole held look");
			look = (Object.op_Implicit((Object)(object)val) ? ((Component)val).gameObject : null);
			if (Object.op_Implicit((Object)(object)item))
			{
				WoodPoles.Live.Add(item);
			}
		}

		private void OnDestroy()
		{
			WoodPoles.Live.Remove(item);
		}

		private void LateUpdate()
		{
			bool flag = Object.op_Implicit((Object)(object)item) && Object.op_Implicit((Object)(object)((PickupableItem)item).held);
			if (flag != shown)
			{
				shown = flag;
				if (Object.op_Implicit((Object)(object)look))
				{
					look.SetActive(flag);
				}
				if (Object.op_Implicit((Object)(object)root))
				{
					((Renderer)root).enabled = !flag;
				}
			}
		}
	}
	internal static class PoleText
	{
		internal const float Ahead = 0.75f;

		internal const float Down = 0.25f;

		internal const float Below = 0.12f;

		internal static TextMesh Text;

		private static Transform root;

		private static GoPointer owner;

		private static readonly FieldRef<LookUI, TextMesh> hintText = AccessTools.FieldRefAccess<LookUI, TextMesh>("hintText");

		internal static void Update(GoPointer pointer)
		{
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: 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)
			ShipItem val = (ShipItem)(Object.op_Implicit((Object)(object)pointer) ? /*isinst with value type is only supported in some contexts*/: null);
			Camera main = Camera.main;
			if (!Object.op_Implicit((Object)(object)val) || !WoodPoles.IsPole(val) || !val.sold || !Object.op_Implicit((Object)(object)main) || !Object.op_Implicit((Object)(object)pointer.lookUI) || !GameState.playing || GameState.inCursorMenu || GameState.sleeping)
			{
				if ((Object)(object)pointer == (Object)(object)owner || !Object.op_Implicit((Object)(object)owner))
				{
					owner = null;
					if (Object.op_Implicit((Object)(object)root))
					{
						((Component)root).gameObject.SetActive(false);
					}
				}
			}
			else if ((Object.op_Implicit((Object)(object)root) && Object.op_Implicit((Object)(object)Text)) || Make(pointer.lookUI))
			{
				owner = pointer;
				Transform transform = ((Component)main).transform;
				root.position = transform.position + transform.forward * 0.75f - Vector3.up * 0.37f;
				root.LookAt(transform);
				string text = "wood pole " + WoodPoles.Format(WoodPoles.Length(val));
				if (Text.text != text)
				{
					Text.text = text;
				}
				if (!((Component)root).gameObject.activeSelf)
				{
					((Component)root).gameObject.SetActive(true);
				}
			}
		}

		private static bool Make(LookUI look)
		{
			//IL_0037: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			TextMesh val = hintText.Invoke(look);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)root))
			{
				Object.Destroy((Object)(object)((Component)root).gameObject);
			}
			root = new GameObject("TentandPlank pole length").transform;
			Object.DontDestroyOnLoad((Object)(object)((Component)root).gameObject);
			GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, root, false);
			foreach (Transform item in val2.transform)
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
			Component[] components = val2.GetComponents<Component>();
			foreach (Component val3 in components)
			{
				if (!(val3 is Transform) && !(val3 is TextMesh) && !(val3 is MeshRenderer) && !(val3 is MeshFilter))
				{
					Object.Destroy((Object)(object)val3);
				}
			}
			val2.transform.localPosition = Vector3.zero;
			val2.transform.localRotation = Quaternion.Inverse(((Component)look).transform.rotation) * ((Component)val).transform.rotation;
			val2.transform.localScale = ((Component)val).transform.lossyScale;
			Text = val2.GetComponent<TextMesh>();
			return Object.op_Implicit((Object)(object)Text);
		}
	}
	internal static class PoleBrace
	{
		internal const float GripRight = 0.3f;

		internal const float GripDown = 0.45f;

		internal const float GripAhead = 0.35f;