Decompiled source of Beastferry v0.1.12

BepInEx/plugins/Zephyrfit-Beastferry/Beastferry.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Beastferry")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.12.0")]
[assembly: AssemblyInformationalVersion("0.1.12+cd28f7fc33bcaa0e1b7bc7e2727b81ef1238230a")]
[assembly: AssemblyProduct("Beastferry")]
[assembly: AssemblyTitle("Beastferry")]
[assembly: AssemblyVersion("0.1.12.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 Zephyrfit.Beastferry
{
	internal static class BerthEnvelope
	{
		internal static Bounds Measure(Character animal, string style)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0470: Unknown result type (might be due to invalid IL or missing references)
			//IL_0471: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			//IL_00c9: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: 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_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: 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_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: 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_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: 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)
			Bounds val = Native.VisualBounds(animal);
			bool flag = Utils.GetPrefabName(((Component)animal).gameObject) == "Greydwarf" || style == "asksvin" || style == "moose";
			if (style != "bear" && !flag)
			{
				return val;
			}
			Transform val2 = Native.Presentation(animal);
			Animator val3 = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponentInChildren<Animator>() : null);
			RuntimeAnimatorController val4 = (Object.op_Implicit((Object)(object)val3) ? val3.runtimeAnimatorController : null);
			if (!Object.op_Implicit((Object)(object)val4))
			{
				return val;
			}
			AnimationClip[] array = val4.animationClips.Where((AnimationClip c) => Object.op_Implicit((Object)(object)c) && !new string[11]
			{
				"death", "dead", "attack", "jump", "swim", "run", "walk", "turn", "canter", "gallop",
				"trot"
			}.Any((string s) => ((Object)c).name.IndexOf(s, StringComparison.OrdinalIgnoreCase) >= 0) && new string[3] { "idle", "eat", "consume" }.Any((string s) => ((Object)c).name.IndexOf(s, StringComparison.OrdinalIgnoreCase) >= 0)).Distinct().Take(12)
				.ToArray();
			if (array.Length == 0)
			{
				return val;
			}
			GameObject val5 = new GameObject("Beastferry inactive berth measurement");
			val5.SetActive(false);
			Mesh val6 = new Mesh();
			List<Vector3> list = new List<Vector3>();
			try
			{
				GameObject val7 = Object.Instantiate<GameObject>(((Component)val2).gameObject, val5.transform, false);
				Transform transform = ((Component)val7.GetComponentInChildren<Animator>(true)).transform;
				Vector3 localPosition = ((Component)val3).transform.localPosition;
				Quaternion localRotation = ((Component)val3).transform.localRotation;
				Vector3 localScale = ((Component)val3).transform.localScale;
				Renderer[] array2 = (from r in val7.GetComponentsInChildren<Renderer>(true)
					where r.enabled && (r is SkinnedMeshRenderer || r is MeshRenderer)
					select r).ToArray();
				Bounds result = (Bounds)(flag ? default(Bounds) : val);
				bool flag2 = flag;
				int num = ((style == "asksvin" || style == "moose") ? 48 : 12);
				AnimationClip[] array3 = array;
				foreach (AnimationClip val8 in array3)
				{
					for (int num3 = 0; num3 <= num; num3++)
					{
						val8.SampleAnimation(((Component)transform).gameObject, val8.length * (float)num3 / (float)num);
						val7.transform.localPosition = val2.localPosition;
						val7.transform.localRotation = val2.localRotation;
						val7.transform.localScale = val2.localScale;
						transform.localPosition = localPosition;
						transform.localRotation = localRotation;
						transform.localScale = localScale;
						Renderer[] array4 = array2;
						foreach (Renderer val9 in array4)
						{
							if (!Active(((Component)val9).transform, val7.transform))
							{
								continue;
							}
							Mesh val10 = null;
							SkinnedMeshRenderer val11 = (SkinnedMeshRenderer)(object)((val9 is SkinnedMeshRenderer) ? val9 : null);
							if (val11 != null)
							{
								val11.BakeMesh(val6, true);
								val10 = val6;
							}
							else
							{
								MeshFilter component = ((Component)val9).GetComponent<MeshFilter>();
								val10 = ((component != null) ? component.sharedMesh : null);
							}
							if (!Object.op_Implicit((Object)(object)val10) || !val10.isReadable)
							{
								continue;
							}
							list.Clear();
							val10.GetVertices(list);
							Matrix4x4 val12 = val5.transform.worldToLocalMatrix * ((Component)val9).transform.localToWorldMatrix;
							foreach (Vector3 item in list)
							{
								Vector3 val13 = ((Matrix4x4)(ref val12)).MultiplyPoint3x4(item);
								if (flag2)
								{
									result = new Bounds(val13, Vector3.zero);
									flag2 = false;
								}
								else
								{
									((Bounds)(ref result)).Encapsulate(val13);
								}
							}
						}
					}
				}
				if (flag2)
				{
					return val;
				}
				Plugin.Instance.Logger.LogInfo((object)("Fixed " + Utils.GetPrefabName(((Component)animal).gameObject) + " envelope current=" + ((object)((Bounds)(ref val)).size/*cast due to .constrained prefix*/).ToString() + " reference=" + ((object)((Bounds)(ref result)).size/*cast due to .constrained prefix*/).ToString() + " center=" + ((object)((Bounds)(ref result)).center/*cast due to .constrained prefix*/).ToString() + " clips=" + string.Join(",", array.Select((AnimationClip c) => ((Object)c).name))));
				return result;
			}
			catch (Exception ex)
			{
				Plugin.Instance.Logger.LogWarning((object)("Idle envelope retained current pose: " + ex.GetType().Name + " " + ex.Message));
				return val;
			}
			finally
			{
				Object.Destroy((Object)(object)val5);
				Object.Destroy((Object)(object)val6);
			}
		}

		private static bool Active(Transform child, Transform root)
		{
			Transform val = child;
			while (Object.op_Implicit((Object)(object)val) && (Object)(object)val != (Object)(object)root)
			{
				if (!((Component)val).gameObject.activeSelf)
				{
					return false;
				}
				val = val.parent;
			}
			return true;
		}
	}
	internal static class Commands
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static ConsoleEvent <>9__1_0;

			public static ConsoleEvent <>9__1_1;

			public static Func<Character, bool> <>9__1_4;

			public static ConsoleEvent <>9__1_2;

			public static ConsoleEvent <>9__1_3;

			internal void <Register>b__1_0(ConsoleEventArgs args)
			{
				if (!Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsServer())
				{
					args.Context.AddString(Text.Get("denied"));
					return;
				}
				((BaseUnityPlugin)Plugin.Instance).Config.Reload();
				Plugin.LoadProfiles();
				args.Context.AddString(Text.Get((Plugin.Profiles == null) ? "profile" : "changed"));
			}

			internal void <Register>b__1_1(ConsoleEventArgs args)
			{
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsServer())
				{
					args.Context.AddString(Text.Get("denied"));
					return;
				}
				try
				{
					string text = File.ReadAllText(Path.Combine(Paths.ConfigPath, "Beastferry", "profiles.json"));
					if (text.Length > 65536)
					{
						throw new ArgumentException("Profile file exceeds 64K");
					}
					using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(text)))
					{
						((Profiles)((XmlObjectSerializer)new DataContractJsonSerializer(typeof(Profiles))).ReadObject((Stream)memoryStream)).Validate();
					}
					Plugin.ProfileJson.Value = text;
					((BaseUnityPlugin)Plugin.Instance).Config.Save();
					Plugin.LoadProfiles();
					args.Context.AddString(Text.Get("changed"));
				}
				catch (Exception ex)
				{
					args.Context.AddString(Text.Get("profile") + " " + ex.Message);
				}
			}

			internal void <Register>b__1_2(ConsoleEventArgs args)
			{
				//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0113: Unknown result type (might be due to invalid IL or missing references)
				args.Context.AddString("Beastferry 0.1.12 · " + Text.T("Passagers chargés : ", "Loaded passengers: ") + Transport.Passengers.Count);
				if (!Object.op_Implicit((Object)(object)Player.m_localPlayer) || !Plugin.Ready)
				{
					return;
				}
				foreach (Character item in from c in Character.GetAllCharacters()
					where Object.op_Implicit((Object)(object)c) && !c.IsPlayer() && c.IsTamed() && Recovery.Stuck(c) && Vector3.Distance(((Component)c).transform.position, ((Component)Player.m_localPlayer).transform.position) <= Plugin.RescueRange.Value
					select c)
				{
					ZDO zDO = ((Component)item).GetComponent<ZNetView>().GetZDO();
					PassengerRecord passengerRecord = State.Read(zDO);
					Rigidbody val = Native.Body.Invoke(item);
					Terminal context = args.Context;
					string[] obj = new string[13]
					{
						((object)item.GetZDOID()/*cast due to .constrained prefix*/).ToString(),
						" ",
						item.GetHoverName(),
						" aboard=",
						State.Aboard((Component)(object)item).ToString(),
						" boat=",
						(passengerRecord?.Boat).ToString(),
						" owner=",
						zDO.GetOwner().ToString(),
						" gravity=",
						(Object.op_Implicit((Object)(object)val) && val.useGravity).ToString(),
						" sleeping=",
						null
					};
					BaseAI component = ((Component)item).GetComponent<BaseAI>();
					obj[12] = ((component != null) ? new bool?(component.IsSleeping()) : ((bool?)null)).ToString();
					context.AddString(string.Concat(obj));
				}
			}

			internal bool <Register>b__1_4(Character c)
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)c) && !c.IsPlayer() && c.IsTamed() && Recovery.Stuck(c))
				{
					return Vector3.Distance(((Component)c).transform.position, ((Component)Player.m_localPlayer).transform.position) <= Plugin.RescueRange.Value;
				}
				return false;
			}

			internal void <Register>b__1_3(ConsoleEventArgs args)
			{
				//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
				<>c__DisplayClass1_0 CS$<>8__locals10 = new <>c__DisplayClass1_0
				{
					args = args,
					actor = Player.m_localPlayer
				};
				if (!Object.op_Implicit((Object)(object)CS$<>8__locals10.actor) || !Plugin.Ready)
				{
					CS$<>8__locals10.args.Context.AddString(Text.Get("missing"));
					return;
				}
				if (CS$<>8__locals10.args.Args.Length > 2)
				{
					CS$<>8__locals10.args.Context.AddString("bf_rescue [UID] — bf_status");
					return;
				}
				IEnumerable<Character> source = from c in Character.GetAllCharacters()
					where Object.op_Implicit((Object)(object)c) && !c.IsPlayer() && c.IsTamed() && !c.IsDead() && Vector3.Distance(((Component)c).transform.position, ((Component)CS$<>8__locals10.actor).transform.position) <= Plugin.RescueRange.Value
					select c;
				Character val = ((CS$<>8__locals10.args.Args.Length == 2) ? source.FirstOrDefault((Func<Character, bool>)((Character c) => ((object)c.GetZDOID()/*cast due to .constrained prefix*/).ToString() == CS$<>8__locals10.args.Args[1])) : Recovery.Nearest(CS$<>8__locals10.actor));
				if (!Object.op_Implicit((Object)(object)val))
				{
					CS$<>8__locals10.args.Context.AddString(Text.Get("missing"));
					return;
				}
				CS$<>8__locals10.args.Context.AddString("bf_rescue " + ((object)val.GetZDOID()/*cast due to .constrained prefix*/).ToString() + " " + val.GetHoverName());
				Network.Send(null, val, ActionKind.Rescue);
			}
		}

		[CompilerGenerated]
		private sealed class <>c__DisplayClass1_0
		{
			public Player actor;

			public ConsoleEventArgs args;

			internal bool <Register>b__5(Character c)
			{
				//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)
				if (Object.op_Implicit((Object)(object)c) && !c.IsPlayer() && c.IsTamed() && !c.IsDead())
				{
					return Vector3.Distance(((Component)c).transform.position, ((Component)actor).transform.position) <= Plugin.RescueRange.Value;
				}
				return false;
			}

			internal bool <Register>b__6(Character c)
			{
				//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)
				return ((object)c.GetZDOID()/*cast due to .constrained prefix*/).ToString() == args.Args[1];
			}
		}

		private static bool registered;

		internal static void Register()
		{
			//IL_004b: 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_0041: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			if (registered)
			{
				return;
			}
			registered = true;
			string text = Text.T("Serveur : recharger la configuration Beastferry.", "Server: reload Beastferry configuration.");
			object obj = <>c.<>9__1_0;
			if (obj == null)
			{
				ConsoleEvent val = delegate(ConsoleEventArgs args)
				{
					if (!Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsServer())
					{
						args.Context.AddString(Text.Get("denied"));
					}
					else
					{
						((BaseUnityPlugin)Plugin.Instance).Config.Reload();
						Plugin.LoadProfiles();
						args.Context.AddString(Text.Get((Plugin.Profiles == null) ? "profile" : "changed"));
					}
				};
				<>c.<>9__1_0 = val;
				obj = (object)val;
			}
			new ConsoleCommand("bf_reload", text, (ConsoleEvent)obj, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			string text2 = Text.T("Serveur : importer BepInEx/config/Beastferry/profiles.json.", "Server: import BepInEx/config/Beastferry/profiles.json.");
			object obj2 = <>c.<>9__1_1;
			if (obj2 == null)
			{
				ConsoleEvent val2 = delegate(ConsoleEventArgs args)
				{
					//IL_007c: Unknown result type (might be due to invalid IL or missing references)
					if (!Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsServer())
					{
						args.Context.AddString(Text.Get("denied"));
						return;
					}
					try
					{
						string text5 = File.ReadAllText(Path.Combine(Paths.ConfigPath, "Beastferry", "profiles.json"));
						if (text5.Length > 65536)
						{
							throw new ArgumentException("Profile file exceeds 64K");
						}
						using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(text5)))
						{
							((Profiles)((XmlObjectSerializer)new DataContractJsonSerializer(typeof(Profiles))).ReadObject((Stream)memoryStream)).Validate();
						}
						Plugin.ProfileJson.Value = text5;
						((BaseUnityPlugin)Plugin.Instance).Config.Save();
						Plugin.LoadProfiles();
						args.Context.AddString(Text.Get("changed"));
					}
					catch (Exception ex)
					{
						args.Context.AddString(Text.Get("profile") + " " + ex.Message);
					}
				};
				<>c.<>9__1_1 = val2;
				obj2 = (object)val2;
			}
			new ConsoleCommand("bf_profiles", text2, (ConsoleEvent)obj2, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			string text3 = Text.T("État du transport, lecture seule.", "Read-only transport status.");
			object obj3 = <>c.<>9__1_2;
			if (obj3 == null)
			{
				ConsoleEvent val3 = delegate(ConsoleEventArgs args)
				{
					//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
					//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
					//IL_0113: Unknown result type (might be due to invalid IL or missing references)
					args.Context.AddString("Beastferry 0.1.12 · " + Text.T("Passagers chargés : ", "Loaded passengers: ") + Transport.Passengers.Count);
					if (!Object.op_Implicit((Object)(object)Player.m_localPlayer) || !Plugin.Ready)
					{
						return;
					}
					foreach (Character item in from c in Character.GetAllCharacters()
						where Object.op_Implicit((Object)(object)c) && !c.IsPlayer() && c.IsTamed() && Recovery.Stuck(c) && Vector3.Distance(((Component)c).transform.position, ((Component)Player.m_localPlayer).transform.position) <= Plugin.RescueRange.Value
						select c)
					{
						ZDO zDO = ((Component)item).GetComponent<ZNetView>().GetZDO();
						PassengerRecord passengerRecord = State.Read(zDO);
						Rigidbody val5 = Native.Body.Invoke(item);
						Terminal context = args.Context;
						string[] obj5 = new string[13]
						{
							((object)item.GetZDOID()/*cast due to .constrained prefix*/).ToString(),
							" ",
							item.GetHoverName(),
							" aboard=",
							State.Aboard((Component)(object)item).ToString(),
							" boat=",
							(passengerRecord?.Boat).ToString(),
							" owner=",
							zDO.GetOwner().ToString(),
							" gravity=",
							(Object.op_Implicit((Object)(object)val5) && val5.useGravity).ToString(),
							" sleeping=",
							null
						};
						BaseAI component = ((Component)item).GetComponent<BaseAI>();
						obj5[12] = ((component != null) ? new bool?(component.IsSleeping()) : ((bool?)null)).ToString();
						context.AddString(string.Concat(obj5));
					}
				};
				<>c.<>9__1_2 = val3;
				obj3 = (object)val3;
			}
			new ConsoleCommand("bf_status", text3, (ConsoleEvent)obj3, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			string text4 = Text.T("bf_rescue [UID] : libérer un animal bloqué proche (sans UID : le plus proche).", "bf_rescue [UID]: release a nearby stuck animal (no UID: nearest).");
			object obj4 = <>c.<>9__1_3;
			if (obj4 == null)
			{
				ConsoleEvent val4 = delegate(ConsoleEventArgs args)
				{
					//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
					Player actor = Player.m_localPlayer;
					if (!Object.op_Implicit((Object)(object)actor) || !Plugin.Ready)
					{
						args.Context.AddString(Text.Get("missing"));
					}
					else if (args.Args.Length > 2)
					{
						args.Context.AddString("bf_rescue [UID] — bf_status");
					}
					else
					{
						IEnumerable<Character> source = from c in Character.GetAllCharacters()
							where Object.op_Implicit((Object)(object)c) && !c.IsPlayer() && c.IsTamed() && !c.IsDead() && Vector3.Distance(((Component)c).transform.position, ((Component)actor).transform.position) <= Plugin.RescueRange.Value
							select c;
						Character val5 = ((args.Args.Length == 2) ? source.FirstOrDefault((Func<Character, bool>)((Character c) => ((object)c.GetZDOID()/*cast due to .constrained prefix*/).ToString() == args.Args[1])) : Recovery.Nearest(actor));
						if (!Object.op_Implicit((Object)(object)val5))
						{
							args.Context.AddString(Text.Get("missing"));
						}
						else
						{
							args.Context.AddString("bf_rescue " + ((object)val5.GetZDOID()/*cast due to .constrained prefix*/).ToString() + " " + val5.GetHoverName());
							Network.Send(null, val5, ActionKind.Rescue);
						}
					}
				};
				<>c.<>9__1_3 = val4;
				obj4 = (object)val4;
			}
			new ConsoleCommand("bf_rescue", text4, (ConsoleEvent)obj4, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		}
	}
	[HarmonyPatch(typeof(Terminal), "InitTerminal")]
	internal static class RegisterCommands
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			Commands.Register();
		}
	}
	internal static class Deck
	{
		internal static float Distance(Ship ship, Vector3 point)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_004c: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			IEnumerable<Collider> enumerable = from c in ((Component)ship).GetComponentsInChildren<Collider>(true)
				where c.enabled && !c.isTrigger && !Generated(((Component)c).transform, ((Component)ship).transform) && !Object.op_Implicit((Object)(object)((Component)c).GetComponentInParent<Character>())
				select c;
			float num = float.PositiveInfinity;
			foreach (Collider item in enumerable)
			{
				float num2 = num;
				Bounds bounds = item.bounds;
				num = Mathf.Min(num2, Vector3.Distance(point, ((Bounds)(ref bounds)).ClosestPoint(point)));
			}
			if (!float.IsInfinity(num))
			{
				return num;
			}
			return Vector3.Distance(point, ((Component)ship).transform.position);
		}

		internal static bool Generated(Transform child, Transform root)
		{
			Transform val = child;
			while (Object.op_Implicit((Object)(object)val) && (Object)(object)val != (Object)(object)root)
			{
				if (((Object)val).name.StartsWith("Beastferry", StringComparison.Ordinal))
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}

		internal static Vector3 Surface(Ship ship, Vector3 proposed)
		{
			//IL_0044: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			HullSurface hullSurface = ((Component)ship).GetComponent<HullSurface>();
			if (!Object.op_Implicit((Object)(object)hullSurface))
			{
				hullSurface = ((Component)ship).gameObject.AddComponent<HullSurface>();
				hullSurface.Prepare(((Component)ship).transform);
			}
			if (hullSurface.Try(proposed, out var surface))
			{
				return surface;
			}
			IEnumerable<Collider> colliders = from c in ((Component)ship).GetComponentsInChildren<Collider>(true)
				where !Generated(((Component)c).transform, ((Component)ship).transform) && !Object.op_Implicit((Object)(object)((Component)c).GetComponentInParent<Character>()) && !Object.op_Implicit((Object)(object)((Component)c).GetComponentInParent<Container>())
				select c;
			Vector3 surface2;
			Vector3 proposed2 = (TrySurface(((Component)ship).transform, colliders, proposed, out surface2) ? surface2 : proposed);
			return VisibleSurface(((Component)ship).transform, proposed2);
		}

		internal static Vector3 VisibleSurface(Transform boat, Vector3 proposed)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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_00f6: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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_0144: 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_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: 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_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: 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_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			float num = 0.5f;
			Vector3 result = proposed;
			MeshFilter[] componentsInChildren = ((Component)boat).GetComponentsInChildren<MeshFilter>();
			foreach (MeshFilter val in componentsInChildren)
			{
				MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
				Mesh sharedMesh = val.sharedMesh;
				if (!Object.op_Implicit((Object)(object)component) || !((Renderer)component).enabled || !Object.op_Implicit((Object)(object)sharedMesh) || !sharedMesh.isReadable || Generated(((Component)val).transform, boat) || Object.op_Implicit((Object)(object)((Component)val).GetComponentInParent<Container>()))
				{
					continue;
				}
				Vector3[] vertices = sharedMesh.vertices;
				int[] triangles = sharedMesh.triangles;
				Matrix4x4 val2 = boat.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix;
				for (int j = 0; j + 2 < triangles.Length; j += 3)
				{
					Vector3 val3 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(vertices[triangles[j]]);
					Vector3 val4 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(vertices[triangles[j + 1]]);
					Vector3 val5 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(vertices[triangles[j + 2]]);
					Vector3 val6 = Vector3.Cross(val4 - val3, val5 - val3);
					if (((Vector3)(ref val6)).normalized.y < 0.6f)
					{
						continue;
					}
					float num2 = (val4.z - val5.z) * (val3.x - val5.x) + (val5.x - val4.x) * (val3.z - val5.z);
					if (Mathf.Abs(num2) < 1E-07f)
					{
						continue;
					}
					float num3 = ((val4.z - val5.z) * (proposed.x - val5.x) + (val5.x - val4.x) * (proposed.z - val5.z)) / num2;
					float num4 = ((val5.z - val3.z) * (proposed.x - val5.x) + (val3.x - val5.x) * (proposed.z - val5.z)) / num2;
					if (!(num3 < 0f) && !(num4 < 0f) && !(num3 + num4 > 1f))
					{
						float num5 = num3 * val3.y + num4 * val4.y + (1f - num3 - num4) * val5.y + 0.005f;
						float num6 = Mathf.Abs(num5 - proposed.y);
						if (!(num6 >= num))
						{
							num = num6;
							result.y = num5;
						}
					}
				}
			}
			return result;
		}

		internal static bool TrySurface(Transform boat, IEnumerable<Collider> colliders, Vector3 proposed, out Vector3 surface)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_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_00db: 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)
			surface = proposed;
			float num = float.PositiveInfinity;
			bool result = false;
			Ray val = default(Ray);
			((Ray)(ref val))..ctor(boat.TransformPoint(proposed + Vector3.up * 6f), -boat.up);
			RaycastHit val2 = default(RaycastHit);
			foreach (Collider collider in colliders)
			{
				if (Object.op_Implicit((Object)(object)collider) && collider.enabled && !collider.isTrigger && collider.Raycast(val, ref val2, 12f) && !(Vector3.Dot(((RaycastHit)(ref val2)).normal, boat.up) < 0.6f))
				{
					Vector3 val3 = boat.InverseTransformPoint(((RaycastHit)(ref val2)).point);
					float num2 = Mathf.Abs(val3.y - proposed.y);
					if (!(num2 >= num))
					{
						num = num2;
						surface = new Vector3(proposed.x, val3.y + 0.005f, proposed.z);
						result = true;
					}
				}
			}
			return result;
		}
	}
	internal static class Decoration
	{
		private static bool missingMaterialReported;

		internal static MeshFilter? WoodSource(string name = "wood_pole")
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab(name);
			WearNTear val = (Object.op_Implicit((Object)(object)prefab) ? prefab.GetComponent<WearNTear>() : null);
			GameObject val2 = ((Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.m_new)) ? val.m_new : prefab);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				return null;
			}
			return ((IEnumerable<MeshFilter>)val2.GetComponentsInChildren<MeshFilter>(true)).FirstOrDefault((Func<MeshFilter, bool>)delegate(MeshFilter f)
			{
				//IL_0067: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0086: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_008e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)f.sharedMesh) && Object.op_Implicit((Object)(object)((Component)f).GetComponent<MeshRenderer>()) && ((Renderer)((Component)f).GetComponent<MeshRenderer>()).enabled && ((Renderer)((Component)f).GetComponent<MeshRenderer>()).sharedMaterials.All((Material m) => Object.op_Implicit((Object)(object)m) && Object.op_Implicit((Object)(object)m.shader) && ((Object)m.shader).name != "Valheim/Snow Mesh"))
				{
					Bounds bounds = f.sharedMesh.bounds;
					if (((Bounds)(ref bounds)).size.x > 0.001f)
					{
						bounds = f.sharedMesh.bounds;
						if (((Bounds)(ref bounds)).size.y > 0.001f)
						{
							bounds = f.sharedMesh.bounds;
							return ((Bounds)(ref bounds)).size.z > 0.001f;
						}
					}
				}
				return false;
			});
		}

		internal static Material? NativeMaterial(Transform parent, string kind)
		{
			if (kind == "iron")
			{
				GameObject prefab = PrefabManager.Instance.GetPrefab("iron_wall_1x1");
				WearNTear val = (Object.op_Implicit((Object)(object)prefab) ? prefab.GetComponent<WearNTear>() : null);
				MeshRenderer val2 = ((Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.m_new)) ? ((IEnumerable<MeshRenderer>)val.m_new.GetComponentsInChildren<MeshRenderer>(true)).FirstOrDefault((Func<MeshRenderer, bool>)((MeshRenderer r) => ((Renderer)r).sharedMaterials.Any((Material m) => Object.op_Implicit((Object)(object)m) && ((Object)m).name == "metalwall"))) : null);
				Material val3 = (Object.op_Implicit((Object)(object)val2) ? ((IEnumerable<Material>)((Renderer)val2).sharedMaterials).FirstOrDefault((Func<Material, bool>)((Material m) => Object.op_Implicit((Object)(object)m) && ((Object)m).name == "metalwall" && Object.op_Implicit((Object)(object)m.shader) && m.shader.isSupported)) : null);
				if (Object.op_Implicit((Object)(object)val3))
				{
					return val3;
				}
			}
			else
			{
				MeshFilter val4 = WoodSource();
				if (Object.op_Implicit((Object)(object)val4))
				{
					return ((Renderer)((Component)val4).GetComponent<MeshRenderer>()).sharedMaterial;
				}
			}
			Ship componentInParent = ((Component)parent).GetComponentInParent<Ship>();
			List<Material> list = new List<Material>();
			if (Object.op_Implicit((Object)(object)componentInParent))
			{
				Renderer[] componentsInChildren = ((Component)componentInParent).GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val5 in componentsInChildren)
				{
					bool flag = false;
					Transform val6 = ((Component)val5).transform;
					while (Object.op_Implicit((Object)(object)val6) && (Object)(object)val6 != (Object)(object)((Component)componentInParent).transform)
					{
						if (((Object)val6).name.StartsWith("Beastferry", StringComparison.Ordinal))
						{
							flag = true;
							break;
						}
						val6 = val6.parent;
					}
					if (!flag)
					{
						list.AddRange(val5.sharedMaterials);
					}
				}
			}
			string[] array = ((!(kind == "iron")) ? new string[3] { "piece_chest_wood", "piece_chest", "wood_floor" } : new string[2] { "forge", "piece_chest" });
			foreach (string text in array)
			{
				GameObject prefab2 = PrefabManager.Instance.GetPrefab(text);
				if (Object.op_Implicit((Object)(object)prefab2))
				{
					list.AddRange(prefab2.GetComponentsInChildren<Renderer>(true).SelectMany((Renderer x) => x.sharedMaterials));
				}
			}
			Material[] source = list.Where((Material m) => Object.op_Implicit((Object)(object)m) && Object.op_Implicit((Object)(object)m.shader) && m.shader.isSupported && ((Object)m.shader).name != "Hidden/InternalErrorShader").Distinct().ToArray();
			return ((IEnumerable<Material>)source).FirstOrDefault((Func<Material, bool>)((Material m) => ((Object)m).name.IndexOf(kind, StringComparison.OrdinalIgnoreCase) >= 0)) ?? ((IEnumerable<Material>)source).FirstOrDefault((Func<Material, bool>)((Material m) => ((Object)m).name.IndexOf("wood", StringComparison.OrdinalIgnoreCase) >= 0)) ?? source.FirstOrDefault();
		}

		private static void Material(Renderer renderer, Transform parent, string kind)
		{
			Material val = NativeMaterial(parent, kind);
			if (Object.op_Implicit((Object)(object)val))
			{
				renderer.sharedMaterial = val;
				return;
			}
			renderer.enabled = false;
			if (!missingMaterialReported)
			{
				missingMaterialReported = true;
				Plugin.Instance.Logger.LogWarning((object)"No supported native decoration material; affected cosmetic hidden, transport remains available.");
			}
		}

		internal static GameObject Box(Transform parent, string name, Vector3 position, Vector3 size, Color color, bool collision = false)
		{
			//IL_0020: 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_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_0257: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			bool flag = Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsDedicated();
			if (!flag && Mathf.Abs(color.r - color.g) > 0.04f)
			{
				MeshFilter val = WoodSource();
				if (Object.op_Implicit((Object)(object)val))
				{
					GameObject val2 = Root(parent, name, position, Quaternion.identity);
					GameObject obj = Root(val2.transform, "Native wood beam", Vector3.zero, Quaternion.identity);
					Bounds bounds = val.sharedMesh.bounds;
					Vector3 size2 = ((Bounds)(ref bounds)).size;
					Vector3 val3 = ((size2.x > size2.y && size2.x > size2.z) ? Vector3.right : ((size2.y > size2.z) ? Vector3.up : Vector3.forward));
					Vector3 val4 = ((size.x > size.y && size.x > size.z) ? Vector3.right : ((size.y > size.z) ? Vector3.up : Vector3.forward));
					Quaternion val5 = Quaternion.FromToRotation(val3, val4);
					Vector3 val6 = Quaternion.Inverse(val5) * size;
					Vector3 val7 = default(Vector3);
					((Vector3)(ref val7))..ctor(Mathf.Abs(val6.x) / size2.x, Mathf.Abs(val6.y) / size2.y, Mathf.Abs(val6.z) / size2.z);
					obj.transform.localRotation = val5;
					obj.transform.localScale = val7;
					obj.transform.localPosition = -(val5 * Vector3.Scale(((Bounds)(ref bounds)).center, val7));
					obj.AddComponent<MeshFilter>().sharedMesh = val.sharedMesh;
					((Renderer)obj.AddComponent<MeshRenderer>()).sharedMaterials = ((Renderer)((Component)val).GetComponent<MeshRenderer>()).sharedMaterials;
					if (collision)
					{
						val2.AddComponent<BoxCollider>().size = size;
					}
					return val2;
				}
			}
			GameObject val8 = (GameObject)((!flag) ? ((object)GameObject.CreatePrimitive((PrimitiveType)3)) : ((object)new GameObject(name)));
			((Object)val8).name = name;
			val8.transform.SetParent(parent, false);
			val8.transform.localPosition = position;
			val8.transform.localScale = size;
			if (flag)
			{
				if (collision)
				{
					val8.AddComponent<BoxCollider>();
				}
				return val8;
			}
			Collider component = val8.GetComponent<Collider>();
			if (!collision)
			{
				component.enabled = false;
				Object.Destroy((Object)(object)component);
			}
			Material(val8.GetComponent<Renderer>(), parent, (Mathf.Abs(color.r - color.g) < 0.04f) ? "iron" : "wood");
			return val8;
		}

		internal static GameObject Root(Transform parent, string name, Vector3 position, Quaternion rotation)
		{
			//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_0013: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = position;
			val.transform.localRotation = rotation;
			return val;
		}

		internal static GameObject Ring(Transform parent, Vector3 position)
		{
			//IL_0006: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Root(parent, "Beastferry mooring ring", position, Quaternion.Euler(0f, 0f, 90f));
			Mesh val2 = new Mesh();
			List<Vector3> list = new List<Vector3>();
			List<int> list2 = new List<int>();
			for (int i = 0; i < 16; i++)
			{
				for (int j = 0; j < 6; j++)
				{
					float num = (float)i * (float)Math.PI * 2f / 16f;
					float num2 = (float)j * (float)Math.PI * 2f / 6f;
					float num3 = 0.15f + 0.025f * Mathf.Cos(num2);
					list.Add(new Vector3(num3 * Mathf.Cos(num), 0.025f * Mathf.Sin(num2), num3 * Mathf.Sin(num)));
				}
			}
			for (int k = 0; k < 16; k++)
			{
				for (int l = 0; l < 6; l++)
				{
					int num4 = k * 6 + l;
					int num5 = (k + 1) % 16 * 6 + l;
					int num6 = k * 6 + (l + 1) % 6;
					int num7 = (k + 1) % 16 * 6 + (l + 1) % 6;
					list2.AddRange(new int[6] { num4, num5, num6, num6, num5, num7 });
				}
			}
			val2.SetVertices(list);
			val2.SetTriangles(list2, 0);
			val2.RecalculateNormals();
			val.AddComponent<MeshFilter>().mesh = val2;
			val2.SetUVs(0, Enumerable.Range(0, list.Count).Select((Func<int, Vector2>)((int num8) => new Vector2((float)(num8 / 6) / 16f, (float)(num8 % 6) / 6f))).ToList());
			Material((Renderer)(object)val.AddComponent<MeshRenderer>(), parent, "iron");
			val.AddComponent<GeneratedResources>().Owned.Add((Object)(object)val2);
			return val;
		}

		internal static GameObject Passenger(Ship ship, PassengerRecord r)
		{
			return Passenger(((Component)ship).transform, r);
		}

		internal static GameObject Passenger(Transform parent, PassengerRecord r, bool? cageOverride = null, Vector3? volume = null, Vector3? position = null)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_0493: Unknown result type (might be due to invalid IL or missing references)
			//IL_0498: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04db: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			//IL_051a: Unknown result type (might be due to invalid IL or missing references)
			//IL_051f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: 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_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: 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_0273: 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_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_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_0442: Unknown result type (might be due to invalid IL or missing references)
			//IL_0451: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0460: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Root(parent, "Beastferry " + r.CageStyle, (Vector3)(((??)position) ?? r.Position), Quaternion.Euler(0f, r.Yaw, 0f));
			try
			{
				Color color = default(Color);
				((Color)(ref color))..ctor(0.25f, 0.14f, 0.075f);
				Color color2 = default(Color);
				((Color)(ref color2))..ctor(0.18f, 0.19f, 0.2f);
				Vector3 val2 = (Vector3)(((??)volume) ?? r.Volume);
				Ring(val.transform, new Vector3(0f, 0.15f, (0f - val2.z) * 0.45f));
				if (cageOverride ?? r.Cage)
				{
					float num = ((r.CageStyle == "lox") ? 0.12f : ((r.CageStyle == "bear") ? 0.09f : 0.06f));
					float[] array = new float[2]
					{
						(0f - val2.x) * 0.5f,
						val2.x * 0.5f
					};
					foreach (float num2 in array)
					{
						float[] array2 = new float[2]
						{
							(0f - val2.z) * 0.5f,
							val2.z * 0.5f
						};
						foreach (float num3 in array2)
						{
							Box(val.transform, "corner", new Vector3(num2, val2.y * 0.5f, num3), new Vector3(num, val2.y, num), color);
						}
					}
					array = new float[3]
					{
						val2.y * 0.3f,
						val2.y * 0.7f,
						val2.y
					};
					foreach (float num4 in array)
					{
						float[] array2 = new float[2]
						{
							(0f - val2.x) * 0.5f,
							val2.x * 0.5f
						};
						foreach (float num5 in array2)
						{
							Box(val.transform, "side rail", new Vector3(num5, num4, 0f), new Vector3(num, num, val2.z - num), color);
						}
						array2 = new float[2]
						{
							(0f - val2.z) * 0.5f,
							val2.z * 0.5f
						};
						foreach (float num6 in array2)
						{
							Box(val.transform, "end rail", new Vector3(0f, num4, num6), new Vector3(val2.x - num, num, num), color);
						}
					}
					if (r.CageStyle != "lox")
					{
						int num7 = Mathf.CeilToInt(val2.z / 0.45f);
						for (int k = 1; k < num7; k++)
						{
							array = new float[2]
							{
								(0f - val2.x) * 0.5f,
								val2.x * 0.5f
							};
							foreach (float num8 in array)
							{
								Box(val.transform, "iron bar", new Vector3(num8, val2.y * 0.5f, (0f - val2.z) * 0.5f + val2.z * (float)k / (float)num7), new Vector3(0.03f, val2.y, 0.03f), color2);
							}
						}
						array = new float[3]
						{
							(0f - val2.x) * 0.25f,
							0f,
							val2.x * 0.25f
						};
						foreach (float num9 in array)
						{
							Box(val.transform, "roof rail", new Vector3(num9, val2.y, 0f), new Vector3(0.055f, 0.055f, val2.z - num), color);
						}
					}
					AddCageWalls(val.transform, val2);
				}
				else
				{
					LineRenderer val3 = Root(val.transform, "Rope", Vector3.zero, Quaternion.identity).AddComponent<LineRenderer>();
					val3.useWorldSpace = false;
					val3.positionCount = 3;
					val3.SetPositions((Vector3[])(object)new Vector3[3]
					{
						new Vector3(0f, 0.15f, (0f - val2.z) * 0.45f),
						new Vector3(0f, 0.5f, (0f - val2.z) * 0.15f),
						new Vector3(0f, 0.6f, 0f)
					});
					float startWidth = (val3.endWidth = 0.035f);
					val3.startWidth = startWidth;
					Material((Renderer)(object)val3, parent, "rope");
				}
				Combine(val);
				val.AddComponent<CameraFade>();
				return val;
			}
			catch
			{
				Object.Destroy((Object)(object)val);
				throw;
			}
		}

		internal static void Combine(GameObject root)
		{
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Expected O, but got Unknown
			//IL_00ac: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<Material, List<CombineInstance>> dictionary = new Dictionary<Material, List<CombineInstance>>();
			MeshFilter[] componentsInChildren = root.GetComponentsInChildren<MeshFilter>();
			HashSet<MeshFilter> hashSet = new HashSet<MeshFilter>();
			MeshFilter[] array = componentsInChildren;
			foreach (MeshFilter val in array)
			{
				MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
				if (!Object.op_Implicit((Object)(object)component) || !((Renderer)component).enabled || !Object.op_Implicit((Object)(object)val.sharedMesh) || !val.sharedMesh.isReadable)
				{
					continue;
				}
				hashSet.Add(val);
				Material[] sharedMaterials = ((Renderer)component).sharedMaterials;
				for (int j = 0; j < val.sharedMesh.subMeshCount && j < sharedMaterials.Length; j++)
				{
					Material val2 = sharedMaterials[j];
					if (Object.op_Implicit((Object)(object)val2))
					{
						if (!dictionary.TryGetValue(val2, out var value))
						{
							value = (dictionary[val2] = new List<CombineInstance>());
						}
						List<CombineInstance> list2 = value;
						CombineInstance item = default(CombineInstance);
						((CombineInstance)(ref item)).mesh = val.sharedMesh;
						((CombineInstance)(ref item)).subMeshIndex = j;
						((CombineInstance)(ref item)).transform = root.transform.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix;
						list2.Add(item);
					}
				}
			}
			GeneratedResources generatedResources = root.GetComponent<GeneratedResources>();
			if (!Object.op_Implicit((Object)(object)generatedResources))
			{
				generatedResources = root.AddComponent<GeneratedResources>();
			}
			foreach (KeyValuePair<Material, List<CombineInstance>> item2 in dictionary)
			{
				GameObject obj = Root(root.transform, "Beastferry combined " + ((Object)item2.Key).name, Vector3.zero, Quaternion.identity);
				Mesh val3 = new Mesh();
				val3.CombineMeshes(item2.Value.ToArray(), true, true);
				obj.AddComponent<MeshFilter>().sharedMesh = val3;
				((Renderer)obj.AddComponent<MeshRenderer>()).sharedMaterial = item2.Key;
				generatedResources.Owned.Add((Object)(object)val3);
			}
			foreach (MeshFilter item3 in hashSet)
			{
				MeshRenderer component2 = ((Component)item3).GetComponent<MeshRenderer>();
				if (Object.op_Implicit((Object)(object)component2))
				{
					((Renderer)component2).enabled = false;
				}
			}
			StabilizeMaterials(root);
		}

		internal static void StabilizeMaterials(GameObject root)
		{
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Expected O, but got Unknown
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab = PrefabManager.Instance.GetPrefab("Carrot");
			Shader val = (Object.op_Implicit((Object)(object)prefab) ? (from m in prefab.GetComponentsInChildren<MeshRenderer>(true).SelectMany((MeshRenderer r) => ((Renderer)r).sharedMaterials)
				where Object.op_Implicit((Object)(object)m) && Object.op_Implicit((Object)(object)m.shader)
				select m.shader).FirstOrDefault((Func<Shader, bool>)((Shader s) => ((Object)s).name == "Standard" && s.isSupported)) : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			GeneratedResources generatedResources = root.GetComponent<GeneratedResources>();
			if (!Object.op_Implicit((Object)(object)generatedResources))
			{
				generatedResources = root.AddComponent<GeneratedResources>();
			}
			Dictionary<Material, Material> dictionary = new Dictionary<Material, Material>();
			foreach (MeshRenderer item in from r in root.GetComponentsInChildren<MeshRenderer>()
				where ((Renderer)r).enabled
				select r)
			{
				Material[] sharedMaterials = ((Renderer)item).sharedMaterials;
				for (int num = 0; num < sharedMaterials.Length; num++)
				{
					Material val2 = sharedMaterials[num];
					if (Object.op_Implicit((Object)(object)val2) && (!(((Object)val2.shader).name != "Custom/Piece") || !(((Object)val2.shader).name != "Standard")) && (!val2.HasProperty("_Mode") || val2.GetFloat("_Mode") == 0f))
					{
						if (!dictionary.TryGetValue(val2, out var value))
						{
							value = new Material(val2)
							{
								shader = val,
								enableInstancing = true,
								renderQueue = 2000
							};
							value.SetFloat("_Mode", 0f);
							value.SetFloat("_Glossiness", 0.08f);
							value.SetFloat("_Metallic", (((Object)val2).name.IndexOf("metal", StringComparison.OrdinalIgnoreCase) >= 0) ? 0.15f : 0f);
							value.SetFloat("_SpecularHighlights", 0f);
							value.SetFloat("_GlossyReflections", 0f);
							value.EnableKeyword("_SPECULARHIGHLIGHTS_OFF");
							value.EnableKeyword("_GLOSSYREFLECTIONS_OFF");
							value.DisableKeyword("_ALPHABLEND_ON");
							value.DisableKeyword("_ALPHATEST_ON");
							value.DisableKeyword("_EMISSION");
							value.SetColor("_EmissionColor", Color.black);
							value.SetInt("_SrcBlend", 1);
							value.SetInt("_DstBlend", 0);
							value.SetInt("_ZWrite", 1);
							value.SetOverrideTag("RenderType", "Opaque");
							dictionary[val2] = value;
							generatedResources.Owned.Add((Object)(object)value);
						}
						sharedMaterials[num] = value;
					}
				}
				((Renderer)item).sharedMaterials = sharedMaterials;
			}
		}

		internal static void AddCageWalls(Transform root, Vector3 size)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_0122: 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_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_0146: 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_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: 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_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			root = Root(root, "Beastferry cage collision", Vector3.zero, Quaternion.identity).transform;
			Rigidbody obj = ((Component)root).gameObject.AddComponent<Rigidbody>();
			obj.isKinematic = true;
			obj.useGravity = false;
			Wall("Cage left wall", new Vector3((0f - size.x) * 0.5f, size.y * 0.5f, 0f), new Vector3(0.1f, size.y, size.z));
			Wall("Cage right wall", new Vector3(size.x * 0.5f, size.y * 0.5f, 0f), new Vector3(0.1f, size.y, size.z));
			Wall("Cage front wall", new Vector3(0f, size.y * 0.5f, size.z * 0.5f), new Vector3(size.x, size.y, 0.1f));
			Wall("Cage rear wall", new Vector3(0f, size.y * 0.5f, (0f - size.z) * 0.5f), new Vector3(size.x, size.y, 0.1f));
			Wall("Cage floor", new Vector3(0f, -0.05f, 0f), new Vector3(size.x, 0.1f, size.z));
			Wall("Cage roof", new Vector3(0f, size.y, 0f), new Vector3(size.x, 0.1f, size.z));
			((Component)root).gameObject.AddComponent<CageContacts>();
			void Wall(string name, Vector3 center, Vector3 volume)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				GameObject obj2 = Root(root, name, center, Quaternion.identity);
				obj2.layer = LayerMask.NameToLayer("piece");
				obj2.AddComponent<BoxCollider>().size = volume;
			}
		}
	}
	internal sealed class CageContacts : MonoBehaviour
	{
		private float next;

		private void FixedUpdate()
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < next)
			{
				return;
			}
			next = Time.unscaledTime + 0.5f;
			Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(true);
			Ship componentInParent = ((Component)this).GetComponentInParent<Ship>();
			List<Collider> list = new List<Collider>();
			if (Object.op_Implicit((Object)(object)componentInParent))
			{
				list.AddRange(((Component)componentInParent).GetComponentsInChildren<Collider>(true));
			}
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				if (Object.op_Implicit((Object)(object)allCharacter) && (Object)(object)allCharacter != (Object)(object)Player.m_localPlayer)
				{
					Vector3 val = ((Component)allCharacter).transform.position - ((Component)this).transform.position;
					if (((Vector3)(ref val)).sqrMagnitude < 256f)
					{
						list.AddRange(((Component)allCharacter).GetComponentsInChildren<Collider>(true));
					}
				}
			}
			Collider[] array = componentsInChildren;
			foreach (Collider val2 in array)
			{
				foreach (Collider item in list)
				{
					if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)item) && (Object)(object)val2 != (Object)(object)item && !((Component)item).transform.IsChildOf(((Component)this).transform))
					{
						Physics.IgnoreCollision(val2, item, true);
					}
				}
			}
		}
	}
	internal sealed class BoatLayout : MonoBehaviour
	{
		internal Ship Ship;

		private GameObject? anchor;

		private void Awake()
		{
			Ship = ((Component)this).GetComponent<Ship>();
			Transport.Boats.Add(this);
			Piece component = ((Component)this).GetComponent<Piece>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.m_canBeRemoved = true;
			}
		}

		internal void Tick()
		{
			//IL_0143: 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_0096: 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_00ba: 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)
			if (!Object.op_Implicit((Object)(object)Ship) || !Object.op_Implicit((Object)(object)((Component)Ship).GetComponent<ZNetView>()) || !((Component)Ship).GetComponent<ZNetView>().IsValid())
			{
				return;
			}
			BoatProfile boatProfile = Native.BoatProfile(Ship);
			if (boatProfile == null)
			{
				return;
			}
			if (!ZNet.instance.IsDedicated() && !Object.op_Implicit((Object)(object)anchor))
			{
				SlotProfile slotProfile = boatProfile.slots[0];
				anchor = Decoration.Root(((Component)this).transform, "Beastferry passenger mooring", State.Vec(slotProfile.position) + new Vector3(0.3f, 0.1f, -0.5f), Quaternion.identity);
				Decoration.Ring(anchor.transform, Vector3.zero);
				BoxCollider obj = anchor.AddComponent<BoxCollider>();
				obj.size = new Vector3(0.4f, 0.35f, 0.4f);
				((Collider)obj).isTrigger = true;
				anchor.layer = LayerMask.NameToLayer("piece");
				anchor.AddComponent<Mooring>().Ship = Ship;
			}
			ZDO z = ((Component)Ship).GetComponent<ZNetView>().GetZDO();
			if ((!ZNet.instance.IsServer() || RemoteAuthority.Leased(z.m_uid)) && !RemoteAuthority.CanWrite(z))
			{
				return;
			}
			Transport.Clean(State.Occupants(z), z);
			if (z.GetBool("bf_gangway_v1", false))
			{
				State.Write(z, delegate
				{
					z.Set("bf_gangway_v1", false);
				});
			}
			if (Plugin.Manger.Value)
			{
				Food.EnsureManger(Ship);
			}
			Food.Auto(Ship);
		}

		private void OnDestroy()
		{
			if (Object.op_Implicit((Object)(object)anchor))
			{
				Object.Destroy((Object)(object)anchor);
			}
			Transport.Boats.Remove(this);
		}
	}
	internal sealed class Mooring : MonoBehaviour, Hoverable, Interactable
	{
		internal Ship Ship;

		public string GetHoverName()
		{
			return "Beastferry";
		}

		public float GetHoverOffset()
		{
			return 0f;
		}

		public string GetHoverText()
		{
			return "Beastferry\n[<color=yellow>$KEY_Use</color>] " + Text.T("Passagers", "Passengers");
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			if (hold || (Object)(object)user != (Object)(object)Player.m_localPlayer)
			{
				return false;
			}
			PassengerPanel.Open(Ship);
			return true;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			return false;
		}
	}
	internal sealed class GeneratedResources : MonoBehaviour
	{
		internal readonly List<Object> Owned = new List<Object>();

		private void OnDestroy()
		{
			foreach (Object item in Owned)
			{
				if (Object.op_Implicit(item))
				{
					Object.Destroy(item);
				}
			}
			Owned.Clear();
		}
	}
	internal sealed class CameraFade : MonoBehaviour
	{
		private sealed class Entry
		{
			internal Renderer Renderer;

			internal Material[] Original;

			internal Material[] Faded;

			internal bool Active;
		}

		private readonly List<Entry> entries = new List<Entry>();

		private float next;

		private float clearSince = -1f;

		private bool fading;

		private Renderer[] visible = Array.Empty<Renderer>();

		private void Awake()
		{
			visible = (from r in ((Component)this).GetComponentsInChildren<Renderer>()
				where r.enabled
				select r).ToArray();
		}

		private void Update()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: 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_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < next)
			{
				return;
			}
			next = Time.unscaledTime + 0.15f;
			Camera main = Camera.main;
			Player localPlayer = Player.m_localPlayer;
			if (Plugin.TransparencyLocal.Value && Object.op_Implicit((Object)(object)main) && Object.op_Implicit((Object)(object)localPlayer) && Obstructs(((Component)main).transform.position, ((Character)localPlayer).GetEyePoint()))
			{
				fading = true;
				clearSince = -1f;
			}
			else if (fading)
			{
				if (clearSince < 0f)
				{
					clearSince = Time.unscaledTime;
				}
				if (!Plugin.TransparencyLocal.Value || Time.unscaledTime - clearSince > 0.5f)
				{
					fading = false;
					clearSince = -1f;
				}
			}
			bool flag = fading;
			if (flag && entries.Count == 0)
			{
				List<Renderer> list = new List<Renderer>(visible);
				Ship componentInParent = ((Component)this).GetComponentInParent<Ship>();
				if (Object.op_Implicit((Object)(object)componentInParent))
				{
					foreach (Passenger passenger in Transport.Passengers)
					{
						if (Object.op_Implicit((Object)(object)passenger))
						{
							ZDOID? val = passenger.Record?.Boat;
							ZDOID uid = ((Component)componentInParent).GetComponent<ZNetView>().GetZDO().m_uid;
							if (val.HasValue && val.GetValueOrDefault() == uid && Vector3.Distance(((Component)passenger).transform.position, ((Component)this).transform.position) < 0.2f)
							{
								list.AddRange(((Component)passenger).GetComponentsInChildren<Renderer>());
							}
						}
					}
				}
				foreach (Renderer item in list.Distinct())
				{
					Entry entry = new Entry
					{
						Renderer = item,
						Original = item.sharedMaterials
					};
					entry.Faded = entry.Original.Select((Material m) => Make(m)).ToArray();
					entries.Add(entry);
				}
			}
			foreach (Entry entry2 in entries)
			{
				if (!Object.op_Implicit((Object)(object)entry2.Renderer))
				{
					continue;
				}
				if (entry2.Active && !entry2.Renderer.sharedMaterials.SequenceEqual(entry2.Faded))
				{
					Material[] faded = entry2.Faded;
					foreach (Material val2 in faded)
					{
						if (Object.op_Implicit((Object)(object)val2))
						{
							Object.Destroy((Object)(object)val2);
						}
					}
					entry2.Original = entry2.Renderer.sharedMaterials;
					entry2.Faded = entry2.Original.Select(Make).ToArray();
					entry2.Active = false;
				}
				if (entry2.Active != flag)
				{
					entry2.Renderer.sharedMaterials = (flag ? entry2.Faded : entry2.Original);
					entry2.Active = flag;
				}
			}
		}

		private bool Obstructs(Vector3 a, Vector3 b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = b - a;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude < 0.01f)
			{
				return false;
			}
			Ray val2 = default(Ray);
			((Ray)(ref val2))..ctor(a, val / magnitude);
			Renderer[] array = visible;
			float num = default(float);
			foreach (Renderer val3 in array)
			{
				if (Object.op_Implicit((Object)(object)val3))
				{
					Bounds bounds = val3.bounds;
					if (fading)
					{
						((Bounds)(ref bounds)).Expand(0.3f);
					}
					if (((Bounds)(ref bounds)).IntersectRay(val2, ref num) && num < magnitude)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static Material Make(Material source)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(source);
			if (val.HasProperty("_Color"))
			{
				Color color = val.color;
				color.a = 0.25f;
				val.color = color;
			}
			val.SetFloat("_Mode", 2f);
			val.SetOverrideTag("RenderType", "Transparent");
			val.DisableKeyword("_ALPHATEST_ON");
			val.DisableKeyword("_ALPHAPREMULTIPLY_ON");
			val.SetInt("_SrcBlend", 5);
			val.SetInt("_DstBlend", 10);
			val.SetInt("_ZWrite", 0);
			val.EnableKeyword("_ALPHABLEND_ON");
			val.renderQueue = 3000;
			return val;
		}

		private void OnDestroy()
		{
			foreach (Entry entry in entries)
			{
				if (Object.op_Implicit((Object)(object)entry.Renderer) && entry.Active && entry.Renderer.sharedMaterials.SequenceEqual(entry.Faded))
				{
					entry.Renderer.sharedMaterials = entry.Original;
				}
				Material[] faded = entry.Faded;
				foreach (Material val in faded)
				{
					if (Object.op_Implicit((Object)(object)val))
					{
						Object.Destroy((Object)(object)val);
					}
				}
			}
			entries.Clear();
		}
	}
	internal static class Food
	{
		internal const string Prefab = "Beastferry_Manger";

		internal const string Association = "bf_manger_boat_v1";

		internal const string MangerId = "bf_manger_id_v1";

		internal const string Token = "bf_feed_token_v1";

		internal const string Until = "bf_feed_until_v1";

		internal const string GrantRpc = "Beastferry_FoodGrant_v1";

		internal const string AckRpc = "Beastferry_FoodAck_v1";

		private static GameObject? template;

		private static ZRoutedRpc? routed;

		private static readonly Dictionary<string, (ZDOID animal, long peer, long owner, float until)> permits = new Dictionary<string, (ZDOID, long, long, float)>();

		private static readonly Queue<(string token, ZDOID animal, ZDOID boat, ZDOID source, float until)> grants = new Queue<(string, ZDOID, ZDOID, ZDOID, float)>();

		private static readonly HashSet<string> consumed = new HashSet<string>();

		private static readonly Dictionary<ZDOID, float> nextAuto = new Dictionary<ZDOID, float>();

		internal static void Register()
		{
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)template))
			{
				template = PrefabManager.Instance.CreateClonedPrefab("Beastferry_Manger", "piece_chest_wood");
				Container component = template.GetComponent<Container>();
				component.m_name = "$bf_manger";
				component.m_width = 3;
				component.m_height = 2;
				component.m_checkGuardStone = true;
				component.m_autoDestroyEmpty = false;
				Piece component2 = template.GetComponent<Piece>();
				if (Object.op_Implicit((Object)(object)component2))
				{
					component2.m_name = "$bf_manger";
					component2.m_description = "$bf_manger";
				}
				WearNTear component3 = template.GetComponent<WearNTear>();
				if (Object.op_Implicit((Object)(object)component3))
				{
					component3.m_noSupportWear = false;
					component3.m_noRoofWear = false;
					component3.m_supports = false;
				}
				template.AddComponent<MangerFollower>();
				template.AddComponent<MangerAppearance>();
				PrefabManager.Instance.AddPrefab(new CustomPrefab(template, false));
			}
		}

		internal static void EnsureManger(Ship ship)
		{
			//IL_0022: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			ZDO z = ((Component)ship).GetComponent<ZNetView>().GetZDO();
			ZDOID zDOID = z.GetZDOID("bf_manger_id_v1");
			ZDO stable = PersistentLinks.Trough(z.GetString("bf_boat_trough_guid_v1", ""));
			if (stable != null)
			{
				if (zDOID != stable.m_uid)
				{
					State.Write(z, delegate
					{
						//IL_0011: Unknown result type (might be due to invalid IL or missing references)
						z.Set("bf_manger_id_v1", stable.m_uid);
					});
				}
				return;
			}
			if (zDOID != ZDOID.None)
			{
				if (!Native.Destroyed(zDOID))
				{
					return;
				}
				State.Write(z, delegate
				{
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					z.Set("bf_manger_id_v1", ZDOID.None);
					z.Set("bf_boat_trough_guid_v1", "");
				});
			}
			if (!Object.op_Implicit((Object)(object)template) || Native.BoatProfile(ship) == null)
			{
				return;
			}
			GameObject val = Object.Instantiate<GameObject>(template, ((Component)ship).transform.TransformPoint(Position(ship)), ((Component)ship).transform.rotation);
			ZNetView view = val.GetComponent<ZNetView>();
			if (!Object.op_Implicit((Object)(object)view) || !view.IsValid())
			{
				Object.Destroy((Object)(object)val);
				return;
			}
			RemoteAuthority.Created(view.GetZDO());
			PersistentLinks.AttachTrough(view.GetZDO(), z);
			Piece component = val.GetComponent<Piece>();
			Piece component2 = ((Component)ship).GetComponent<Piece>();
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component2))
			{
				view.GetZDO().Set(ZDOVars.s_creator, component2.GetCreator());
				view.GetZDO().Set(ZDOVars.s_creatorIndex, component2.GetCreatorPlatformUserIdIndex(), false);
				AccessTools.Field(typeof(Piece), "m_creator").SetValue(component, component2.GetCreator());
				AccessTools.Field(typeof(Piece), "m_creatorPlatformUserIDIndex").SetValue(component, component2.GetCreatorPlatformUserIdIndex());
			}
			State.Write(z, delegate
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				z.Set("bf_manger_id_v1", view.GetZDO().m_uid);
			});
		}

		internal static Vector3 Position(Ship ship)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			string prefabName = Utils.GetPrefabName(((Component)ship).gameObject);
			Vector3 val = ((prefabName == "VikingShip_Ashlands") ? new Vector3(0f, 2f, -1f) : ((prefabName == "VikingShip") ? new Vector3(0f, 0.7f, 2f) : new Vector3(0f, 0.4f, -1f)));
			List<float> list = new List<float>();
			float[] array = new float[3] { -0.6f, 0f, 0.6f };
			foreach (float num in array)
			{
				float[] array2 = new float[3] { -0.3f, 0f, 0.3f };
				foreach (float num2 in array2)
				{
					list.Add(Deck.Surface(ship, val + new Vector3(num, 0f, num2)).y);
				}
			}
			list.Sort();
			val.y = list[list.Count / 2];
			GameObject val2 = (GameObject)(Object.op_Implicit((Object)(object)template) ? ((object)template) : ((object)PrefabManager.Instance.GetPrefab("Beastferry_Manger")));
			if (Object.op_Implicit((Object)(object)val2))
			{
				ref float y = ref val.y;
				float num3 = y;
				Bounds val3 = MangerAppearance.BodyBounds(val2);
				y = num3 - ((Bounds)(ref val3)).min.y;
			}
			return val;
		}

		internal static void DetachBoat(ZDOID boat)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			Container[] array = Object.FindObjectsByType<Container>((FindObjectsSortMode)0);
			foreach (Container val in array)
			{
				ZNetView component = ((Component)val).GetComponent<ZNetView>();
				if (Object.op_Implicit((Object)(object)((Component)val).GetComponent<MangerFollower>()) && Object.op_Implicit((Object)(object)component) && component.IsValid() && component.GetZDO().GetZDOID("bf_manger_boat_v1") == boat)
				{
					PersistentLinks.DetachTrough(component.GetZDO());
					((Component)val).GetComponent<MangerFollower>().Salvage();
				}
			}
		}

		internal static void DetachSavedTrough(ZDO boat)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			ZDO zDO = ZDOMan.instance.GetZDO(boat.GetZDOID("bf_manger_id_v1"));
			if (zDO != null && zDO.GetPrefab() == StringExtensionMethods.GetStableHashCode("Beastferry_Manger") && zDO.GetZDOID("bf_manger_boat_v1") == boat.m_uid)
			{
				PersistentLinks.DetachTrough(zDO);
			}
		}

		internal static Container? Manger(Ship ship)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Native.Find(((Component)ship).GetComponent<ZNetView>().GetZDO().GetZDOID("bf_manger_id_v1"));
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			return val.GetComponent<Container>();
		}

		internal unsafe static bool Visible(Ship ship)
		{
			//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)
			PersonalPreferences current = LocalPreferences.Current;
			string text = ZNet.instance.GetWorldUID().ToString();
			ZDOID uid = ((Component)ship).GetComponent<ZNetView>().GetZDO().m_uid;
			return current.TroughVisible(text + ":" + ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString());
		}

		internal unsafe static void Toggle(Ship ship)
		{
			//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)
			PersonalPreferences current = LocalPreferences.Current;
			string text = ZNet.instance.GetWorldUID().ToString();
			ZDOID uid = ((Component)ship).GetComponent<ZNetView>().GetZDO().m_uid;
			current.SetTroughVisible(text + ":" + ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString(), !Visible(ship));
			LocalPreferences.Save();
			Container val = Manger(ship);
			if (Object.op_Implicit((Object)(object)val))
			{
				((Component)val).GetComponent<MangerFollower>().ApplyVisibility(Visible(ship));
			}
		}

		internal static bool Busy(Character c)
		{
			return ((Component)c).GetComponent<ZNetView>().GetZDO().GetLong("bf_feed_until_v1", 0L) > ZNet.instance.GetTime().Ticks;
		}

		internal static bool AttachedManger(Component component)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)component.GetComponent<MangerFollower>()))
			{
				return false;
			}
			ZNetView component2 = component.GetComponent<ZNetView>();
			if (Object.op_Implicit((Object)(object)component2) && component2.IsValid())
			{
				return component2.GetZDO().GetZDOID("bf_manger_boat_v1") != ZDOID.None;
			}
			return false;
		}

		internal static IEnumerable<ItemDrop> Diet(Character c)
		{
			BaseAI component = ((Component)c).GetComponent<BaseAI>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return Array.Empty<ItemDrop>();
			}
			if (!(AccessTools.Field(((object)component).GetType(), "m_consumeItems")?.GetValue(component) is IEnumerable source))
			{
				return Array.Empty<ItemDrop>();
			}
			return (from x in source.Cast<object>().OfType<ItemDrop>()
				where Object.op_Implicit((Object)(object)x)
				select x).ToArray();
		}

		private static string Eat(Character c, Inventory inventory)
		{
			Tameable component = ((Component)c).GetComponent<Tameable>();
			ZNetView component2 = ((Component)c).GetComponent<ZNetView>();
			if (!c.IsTamed() || c.IsDead() || !component2.IsOwner())
			{
				return "missing";
			}
			if (!Object.op_Implicit((Object)(object)component))
			{
				return "diet";
			}
			if (!component.IsHungry())
			{
				return "fed";
			}
			ItemDrop[] diet = Diet(c).ToArray();
			if (diet.Length == 0)
			{
				return "diet";
			}
			ItemData[] array = (from x in inventory.GetAllItems()
				where Object.op_Implicit((Object)(object)x.m_dropPrefab) && diet.Any((ItemDrop d) => Utils.GetPrefabName(((Component)d).gameObject) == Utils.GetPrefabName(x.m_dropPrefab))
				orderby x.m_gridPos.y, x.m_gridPos.x
				select x).ToArray();
			if (array.Length == 0)
			{
				return "food";
			}
			ItemData val = array[0];
			ItemDrop component3 = val.m_dropPrefab.GetComponent<ItemDrop>();
			if (!Object.op_Implicit((Object)(object)component3))
			{
				return "diet";
			}
			if (!inventory.RemoveItem(val, 1))
			{
				return "food";
			}
			AccessTools.Method(typeof(Tameable), "OnConsumedItem", (Type[])null, (Type[])null).Invoke(component, new object[1] { component3 });
			return "ate";
		}

		internal static string FeedPlayer(Ship ship, Character c, Player actor)
		{
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ec: Unknown result type (might be due to invalid IL or missing references)
			if (State.Aboard((Component)(object)c))
			{
				ZDOID? val = State.Read(((Component)c).GetComponent<ZNetView>().GetZDO())?.Boat;
				ZDOID uid = ((Component)ship).GetComponent<ZNetView>().GetZDO().m_uid;
				if (val.HasValue && !(val.GetValueOrDefault() != uid))
				{
					if (Integrations.InventoryBusy(c) || Busy(c))
					{
						return "busy";
					}
					ZNetView component = ((Component)c).GetComponent<ZNetView>();
					long owner = ((Component)actor).GetComponent<ZNetView>().GetZDO().GetOwner();
					if (owner == ZDOMan.GetSessionID())
					{
						long owner2 = component.GetZDO().GetOwner();
						component.GetZDO().SetOwner(owner);
						try
						{
							return Eat(c, ((Humanoid)actor).GetInventory());
						}
						finally
						{
							component.GetZDO().SetOwner(owner2);
							if (owner2 != owner)
							{
								ZDOMan.instance.ForceSendZDO(owner2, c.GetZDOID());
							}
						}
					}
					return Permit(ship, c, owner, ZDOID.None);
				}
			}
			return "missing";
		}

		private static string Permit(Ship ship, Character c, long peer, ZDOID source)
		{
			//IL_006f: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			ZNetView v = ((Component)c).GetComponent<ZNetView>();