Decompiled source of ValheimRAFT v1.4.9

ValheimRAFT.dll

Decompiled a year ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.GUI;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.U2D;
using UnityEngine.UI;
using ValheimRAFT.UI;
using ValheimRAFT.Util;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 ValheimRAFT
{
	public class BoardingRampComponent : MonoBehaviour, Interactable, Hoverable
	{
		public enum BoardingRampState
		{
			Closed,
			Closing,
			Opening,
			Open
		}

		public BoardingRampState m_state = BoardingRampState.Closing;

		public float m_stateProgress = 0f;

		public float m_stateChangeDuration = 0.5f;

		public int m_segments = 8;

		public float m_segmentLength = 2f;

		public float m_segmentOverlap = 0.2f;

		public float m_segmentHeight = 0.05f;

		public float m_maxRampRotation;

		private GameObject m_segmentObject;

		private List<GameObject> m_segmentObjects = new List<GameObject>();

		private List<Transform> m_ropeAttach1 = new List<Transform>();

		private List<Transform> m_ropeAttach2 = new List<Transform>();

		private LineRenderer m_rope1;

		private LineRenderer m_rope2;

		private GameObject m_ramp;

		private Transform m_winch1;

		private Transform m_winch2;

		private Transform m_winch1Rope;

		private Transform m_winch2Rope;

		private bool m_lastHitRamp;

		private Vector3 m_hitPosition;

		private bool m_updateRamp;

		private Quaternion m_desiredRotation;

		private float m_rotSpeed;

		private Color m_hitColor;

		private float m_hitDistance;

		private ZNetView m_nview;

		private int m_groundRayMask;

		private static RaycastHit[] m_rayHits = (RaycastHit[])(object)new RaycastHit[30];

		private float m_lastBridgeProgress = -1f;

		private static EditRampComponent m_editPanel;

		private void Awake()
		{
			m_nview = ((Component)this).GetComponent<ZNetView>();
			m_groundRayMask = LayerMask.GetMask(new string[8] { "Default", "static_solid", "Default_small", "piece", "terrain", "blocker", "WaterVolume", "Water" });
			m_ramp = ((Component)((Component)this).transform.Find("Ramp")).gameObject;
			m_segmentObject = ((Component)((Component)this).transform.Find("Ramp/Segment")).gameObject;
			m_rope1 = ((Component)((Component)this).transform.Find("Rope1")).GetComponent<LineRenderer>();
			m_rope2 = ((Component)((Component)this).transform.Find("Rope2")).GetComponent<LineRenderer>();
			m_winch1 = ((Component)this).transform.Find("Winch1/Cylinder");
			m_winch2 = ((Component)this).transform.Find("Winch2/Cylinder");
			m_winch1Rope = ((Component)this).transform.Find("Winch1/Pole/RopeAttach");
			m_winch2Rope = ((Component)this).transform.Find("Winch2/Pole/RopeAttach");
			m_segmentObject.SetActive(ZNetView.m_forceDisableInit);
			if (ZNetView.m_forceDisableInit)
			{
				((Component)m_rope1).gameObject.SetActive(false);
				((Component)m_rope2).gameObject.SetActive(false);
				m_segmentObject.SetActive(true);
				((Behaviour)this).enabled = false;
			}
			else
			{
				m_nview.Register<byte>("RPC_SetState", (Action<long, byte>)RPC_SetState);
				m_nview.Register<byte>("RPC_SetSegmentCount", (Action<long, byte>)RPC_SetSegmentCount);
				m_updateRamp = true;
				LoadZDO();
			}
		}

		private void RPC_SetState(long sender, byte state)
		{
			if (m_nview.IsOwner())
			{
				SetState((BoardingRampState)state);
			}
		}

		private void LoadZDO()
		{
			if (Object.op_Implicit((Object)(object)m_nview) && m_nview.m_zdo != null)
			{
				m_state = (BoardingRampState)m_nview.m_zdo.GetInt("MB_m_state", 0);
				m_segments = m_nview.m_zdo.GetInt("MB_m_segments", 5);
			}
		}

		public void RPC_SetSegmentCount(long sender, byte segmentCount)
		{
			if (Object.op_Implicit((Object)(object)m_nview) && m_nview.IsOwner())
			{
				SetSegmentCount(segmentCount);
			}
		}

		public void SetSegmentCount(int segmentCount)
		{
			if (segmentCount != m_segments)
			{
				if (Object.op_Implicit((Object)(object)m_nview) && !m_nview.IsOwner())
				{
					m_nview.InvokeRPC("RPC_SetSegmentCount", new object[1] { (byte)segmentCount });
				}
				else
				{
					m_segments = segmentCount;
					m_nview.m_zdo.Set("MB_m_segments", m_segments);
				}
			}
		}

		private void CreateSegments()
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00eb: 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)
			while (m_segments < m_segmentObjects.Count)
			{
				int index = m_segmentObjects.Count - 1;
				Object.Destroy((Object)(object)m_segmentObjects[index]);
				Object.Destroy((Object)(object)m_ropeAttach1[index]);
				Object.Destroy((Object)(object)m_ropeAttach2[index]);
				m_segmentObjects.RemoveAt(index);
				m_ropeAttach1.RemoveAt(index);
				m_ropeAttach2.RemoveAt(index);
			}
			for (int i = m_segmentObjects.Count; i < m_segments; i++)
			{
				GameObject val = Object.Instantiate<GameObject>(m_segmentObject, ((Component)this).transform.position + new Vector3(0f, (0f - m_segmentHeight) * (float)i, m_segmentLength * (float)i), Quaternion.identity, m_ramp.transform);
				val.transform.localRotation = Quaternion.identity;
				val.transform.localScale = new Vector3(1f + (float)i * 0.0001f, 1f + (float)i * 0.0001f, 1f + (float)i * 0.0001f);
				m_segmentObjects.Add(val);
				m_ropeAttach1.Add(val.transform.Find("SegmentAnchor/Pole1/RopeAttach"));
				m_ropeAttach2.Add(val.transform.Find("SegmentAnchor/Pole2/RopeAttach"));
				val.SetActive(true);
			}
		}

		private void Update()
		{
			if (Object.op_Implicit((Object)(object)m_nview) && !m_nview.IsOwner())
			{
				BoardingRampState @int = (BoardingRampState)m_nview.m_zdo.GetInt("MB_m_state", 0);
				if (@int != m_state)
				{
					if (@int == BoardingRampState.Closed || @int == BoardingRampState.Closing)
					{
						m_state = BoardingRampState.Closing;
					}
					else if (@int == BoardingRampState.Open || @int == BoardingRampState.Opening)
					{
						m_state = BoardingRampState.Opening;
					}
				}
				m_segments = m_nview.m_zdo.GetInt("MB_m_segments", 5);
			}
			if (m_segmentObjects.Count != m_segments)
			{
				CreateSegments();
				ForceRampUpdate();
			}
			CheckRampFloor();
			if (m_state == BoardingRampState.Closing)
			{
				m_stateProgress = Mathf.Clamp01(m_stateProgress - Time.deltaTime / (m_stateChangeDuration * (float)m_segments));
				UpdateRamp();
				if (m_stateProgress <= 0f)
				{
					m_state = BoardingRampState.Closed;
				}
			}
			else if (m_state == BoardingRampState.Opening)
			{
				m_stateProgress = Mathf.Clamp01(m_stateProgress + Time.deltaTime / (m_stateChangeDuration * (float)m_segments));
				UpdateRamp();
				if (m_stateProgress >= 1f)
				{
					m_state = BoardingRampState.Open;
				}
			}
			else if (m_updateRamp)
			{
				UpdateRamp();
			}
		}

		private void SetState(BoardingRampState state)
		{
			if (m_state == state)
			{
				return;
			}
			m_state = state;
			if (Object.op_Implicit((Object)(object)m_nview) && m_nview.m_zdo != null)
			{
				if (m_nview.IsOwner())
				{
					m_nview.m_zdo.Set("MB_m_state", (int)state);
					return;
				}
				m_nview.InvokeRPC("RPC_SetState", new object[1] { (byte)state });
			}
		}

		private bool LinecastNonSelf(Vector3 start, Vector3 end, out RaycastHit hit)
		{
			//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_0003: 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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = end - start;
			return RaycastNonSelf(start, ((Vector3)(ref val)).normalized, ((Vector3)(ref val)).magnitude, out hit);
		}

		private bool RaycastNonSelf(Vector3 start, Vector3 dir, float dist, out RaycastHit hit)
		{
			//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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			int num = Physics.RaycastNonAlloc(start, dir, m_rayHits, dist, m_groundRayMask, (QueryTriggerInteraction)1);
			int num2 = 0;
			bool flag = false;
			for (int i = 0; i < num; i++)
			{
				if (!((RaycastHit)(ref m_rayHits[i])).transform.IsChildOf(((Component)this).transform.parent ?? ((Component)this).transform) && (!flag || ((RaycastHit)(ref m_rayHits[num2])).distance > ((RaycastHit)(ref m_rayHits[i])).distance))
				{
					num2 = i;
					flag = true;
				}
			}
			hit = m_rayHits[num2];
			return flag;
		}

		private void CheckRampFloor()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: 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_0109: 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_010e: 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_0127: 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_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: 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_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: 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_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: 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_0190: 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_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: 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_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			if (m_state == BoardingRampState.Closed || m_state == BoardingRampState.Closing)
			{
				m_updateRamp |= m_state == BoardingRampState.Closing || m_ramp.transform.eulerAngles.x != -90f;
			}
			else
			{
				if (m_state != BoardingRampState.Opening && m_state != BoardingRampState.Open)
				{
					return;
				}
				m_updateRamp = true;
				float num = m_segmentLength * (float)m_segments;
				float num2 = 1f * (m_segmentLength - m_segmentOverlap) * (float)m_segments;
				Vector3 val = m_ramp.transform.TransformPoint(new Vector3(0f, (0f - m_segmentHeight) * (float)m_segments, num2));
				Vector3 position = m_ramp.transform.position;
				Vector3 val2 = val - position;
				Vector3 normalized = ((Vector3)(ref val2)).normalized;
				Vector3 up = m_ramp.transform.up;
				if (LinecastNonSelf(position, val, out var hit))
				{
					m_hitColor = Color.green;
					m_hitDistance = ((RaycastHit)(ref hit)).distance / num2;
					if (num * 0.94f > ((RaycastHit)(ref hit)).distance)
					{
						m_hitColor = Color.black;
						LinecastNonSelf(((RaycastHit)(ref hit)).point + normalized * 0.1f + up, ((RaycastHit)(ref hit)).point + normalized * 0.1f - up, out hit);
					}
					if ((double)Vector3.Dot(((RaycastHit)(ref hit)).normal, Vector3.up) < 0.5)
					{
						m_hitColor = Color.white;
						LinecastNonSelf(((RaycastHit)(ref hit)).point + up, ((RaycastHit)(ref hit)).point - up, out hit);
					}
					m_lastHitRamp = true;
					m_hitPosition = ((RaycastHit)(ref hit)).point;
					m_updateRamp = true;
				}
				else if (m_lastHitRamp && LinecastNonSelf(position - up * 0.3f, val - up * 0.3f, out hit))
				{
					m_hitColor = Color.magenta;
				}
				else if (!m_lastHitRamp && RaycastNonSelf(val + new Vector3(0f, 5f, 0f), Vector3.down, 1000f, out hit))
				{
					m_hitColor = Color.blue;
					m_hitPosition = ((RaycastHit)(ref hit)).point;
					m_hitDistance = 1f;
					m_updateRamp = true;
					m_lastHitRamp = false;
				}
				else
				{
					m_lastHitRamp = false;
				}
			}
		}

		public void ForceRampUpdate()
		{
			m_updateRamp = true;
			m_lastBridgeProgress = -1f;
		}

		private void UpdateRamp()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: 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_006a: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			if (!m_updateRamp)
			{
				return;
			}
			m_updateRamp = false;
			if (m_state == BoardingRampState.Closed || m_state == BoardingRampState.Closing)
			{
				m_desiredRotation = ((m_stateProgress < 1f / (float)m_segments) ? Quaternion.Euler(-90f, 0f, 0f) : m_ramp.transform.localRotation);
				m_rotSpeed = 90f;
			}
			else
			{
				Vector3 val = m_hitPosition - (((Component)this).transform.position - new Vector3(0f, m_hitDistance * m_segmentHeight * (float)m_segments, 0f));
				m_desiredRotation = Quaternion.LookRotation(((Vector3)(ref val)).normalized);
				Quaternion val2 = Quaternion.Inverse(((Component)this).transform.rotation) * m_desiredRotation;
				m_desiredRotation = Quaternion.Euler(((Quaternion)(ref val2)).eulerAngles.x, 0f, 0f);
				m_rotSpeed = Mathf.Clamp(Quaternion.Angle(m_ramp.transform.localRotation, m_desiredRotation) * 5f, 0f, 90f);
			}
			m_ramp.transform.localRotation = Quaternion.RotateTowards(m_ramp.transform.localRotation, m_desiredRotation, Time.deltaTime * m_rotSpeed);
			((Component)m_winch1).transform.localRotation = Quaternion.Euler(m_stateProgress * 1000f * (float)m_segments, 0f, -90f);
			((Component)m_winch2).transform.localRotation = Quaternion.Euler(m_stateProgress * 1000f * (float)m_segments, 0f, -90f);
			float stateProgress = m_stateProgress;
			if (m_lastBridgeProgress != stateProgress)
			{
				m_lastBridgeProgress = stateProgress;
				for (int i = 1; i < m_segmentObjects.Count; i++)
				{
					float num = Mathf.Clamp01(stateProgress * (float)m_segmentObjects.Count / (float)i);
					m_segmentObjects[i].transform.position = m_ramp.transform.TransformPoint(new Vector3(0f, (0f - m_segmentHeight) * (float)i, num * (m_segmentLength - m_segmentOverlap) * (float)i));
				}
			}
			UpdateRopes();
		}

		private void UpdateRopes()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			m_rope1.positionCount = m_segmentObjects.Count + 1;
			m_rope2.positionCount = m_segmentObjects.Count + 1;
			m_rope1.SetPosition(m_segmentObjects.Count, ((Component)m_rope1).transform.InverseTransformPoint(m_winch1Rope.position));
			m_rope2.SetPosition(m_segmentObjects.Count, ((Component)m_rope2).transform.InverseTransformPoint(m_winch2Rope.position));
			for (int i = 0; i < m_segmentObjects.Count; i++)
			{
				m_rope1.SetPosition(m_segmentObjects.Count - (i + 1), ((Component)m_rope1).transform.InverseTransformPoint(m_ropeAttach1[i].position));
				m_rope2.SetPosition(m_segmentObjects.Count - (i + 1), ((Component)m_rope2).transform.InverseTransformPoint(m_ropeAttach2[i].position));
			}
		}

		private void OnDrawGizmos()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			Gizmos.color = m_hitColor;
			Gizmos.DrawSphere(m_hitPosition, 0.3f);
		}

		public string GetHoverName()
		{
			return "";
		}

		public string GetHoverText()
		{
			string text = ((m_state == BoardingRampState.Open || m_state == BoardingRampState.Opening) ? "$mb_boarding_ramp_retract" : "$mb_boarding_ramp_extend");
			return Localization.instance.Localize("[<color=yellow><b>$KEY_Use</b></color>] " + text) + Localization.instance.Localize("\n[<color=yellow><b>$KEY_AltPlace + $KEY_Use</b></color>] $mb_boarding_ramp_edit");
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			if (alt)
			{
				if (m_editPanel == null)
				{
					m_editPanel = new EditRampComponent();
				}
				m_editPanel.ShowPanel(this);
				return true;
			}
			if (!hold)
			{
				if (m_state == BoardingRampState.Open || m_state == BoardingRampState.Opening)
				{
					SetState(BoardingRampState.Closing);
				}
				else if (m_state == BoardingRampState.Closing || m_state == BoardingRampState.Closed)
				{
					SetState(BoardingRampState.Opening);
				}
			}
			return true;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			return false;
		}
	}
	internal class CreativeModeConsoleCommand : ConsoleCommand
	{
		public override string Name => "RaftCreative";

		public override string Help => "Sets the current raft you are standing on into creative mode.";

		public override void Run(string[] args)
		{
			//IL_0048: 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)
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer))
			{
				return;
			}
			Ship standingOnShip = ((Character)localPlayer).GetStandingOnShip();
			RaycastHit val = default(RaycastHit);
			if ((!Object.op_Implicit((Object)(object)standingOnShip) || !ToggleMode(localPlayer, standingOnShip)) && Physics.Raycast(((Component)GameCamera.instance).transform.position, ((Component)GameCamera.instance).transform.forward, ref val, 50f, LayerMask.GetMask(new string[1] { "piece" })))
			{
				MoveableBaseRootComponent componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<MoveableBaseRootComponent>();
				if (Object.op_Implicit((Object)(object)componentInParent))
				{
					ToggleMode(localPlayer, componentInParent.m_ship);
				}
			}
		}

		private static bool ToggleMode(Player player, Ship ship)
		{
			//IL_00ef: 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_010e: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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)
			MoveableBaseShipComponent component = ((Component)ship).GetComponent<MoveableBaseShipComponent>();
			if (Object.op_Implicit((Object)(object)component))
			{
				ZSyncTransform component2 = ((Component)ship).GetComponent<ZSyncTransform>();
				component.m_rigidbody.isKinematic = !component.m_rigidbody.isKinematic;
				component2.m_isKinematicBody = component.m_rigidbody.isKinematic;
				if (component.m_rigidbody.isKinematic)
				{
					if ((Object)(object)((Component)player).transform.parent == (Object)(object)((Component)component.m_baseRoot).transform)
					{
						((Character)player).m_body.position = new Vector3(((Component)((Character)player).m_body).transform.position.x, ((Component)((Character)player).m_body).transform.position.y + 34.5f - component.m_rigidbody.position.y, ((Component)((Character)player).m_body).transform.position.z);
					}
					component.m_rigidbody.position = new Vector3(((Component)component).transform.position.x, 35f, ((Component)component).transform.position.z);
					Rigidbody rigidbody = component.m_rigidbody;
					Quaternion rotation = component.m_rigidbody.rotation;
					rigidbody.rotation = Quaternion.Euler(0f, Mathf.Floor(((Quaternion)(ref rotation)).eulerAngles.y / 22.5f) * 22.5f, 0f);
				}
				return true;
			}
			return false;
		}
	}
	public class CultivatableComponent : MonoBehaviour
	{
		private ZNetView m_nview;

		private static Dictionary<int, List<int>> m_childObjects = new Dictionary<int, List<int>>();

		private static readonly int MBCultivatableParentIdHash = StringExtensionMethods.GetStableHashCode("MBCultivatableParentId");

		public static readonly KeyValuePair<int, int> MBCultivatableParentHash = ZDO.GetHashZDOID("MBCultivatableParent");

		private float textureScale = 8f;

		public bool isCultivatable { get; set; } = true;


		public void Awake()
		{
			m_nview = ((Component)this).GetComponent<ZNetView>();
			WearNTear component = ((Component)this).GetComponent<WearNTear>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.m_onDestroyed = (Action)Delegate.Combine(component.m_onDestroyed, new Action(OnDestroyed));
			}
		}

		public void Start()
		{
			UpdateMaterial();
		}

		public void UpdateMaterial()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_002a: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00b8: 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_00d7: 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_00e3: 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_0111: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = (Object.op_Implicit((Object)(object)((Component)this).transform.parent) ? new Vector2(0f - ((Component)this).transform.localPosition.x, 0f - ((Component)this).transform.localPosition.z) : new Vector2(0f - ((Component)this).transform.position.x, 0f - ((Component)this).transform.position.z));
			val /= textureScale;
			float num = (Object.op_Implicit((Object)(object)((Component)this).transform.parent) ? (0f - ((Component)this).transform.localEulerAngles.y) : (0f - ((Component)this).transform.eulerAngles.y));
			num /= 360f;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(((Component)this).transform.localScale.x, ((Component)this).transform.localScale.z);
			val2 /= textureScale;
			MeshRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<MeshRenderer>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Material material = ((Renderer)componentsInChildren[i]).material;
				material.SetTextureOffset("_MainTex", val);
				material.SetTextureScale("_MainTex", val2);
				material.SetTextureOffset("_MainNormal", val);
				material.SetTextureScale("_MainNormal", val2);
				material.SetFloat("_MainRotation", num);
			}
		}

		private void OnDestroyed()
		{
			int orCreatePersistantID = ZDOPersistantID.Instance.GetOrCreatePersistantID(m_nview.m_zdo);
			if (!m_childObjects.TryGetValue(orCreatePersistantID, out var value))
			{
				return;
			}
			for (int i = 0; i < value.Count; i++)
			{
				ZDO zDO = ZDOPersistantID.Instance.GetZDO(value[i]);
				if (zDO == null)
				{
					continue;
				}
				ZNetView val = ZNetScene.instance.FindInstance(zDO);
				if (Object.op_Implicit((Object)(object)val))
				{
					if ((Object)(object)((Component)this).gameObject == (Object)(object)val || ((Component)this).transform.IsChildOf(((Component)val).transform))
					{
						ZLog.LogWarning((object)$" gameObject == obj || transform.IsChildOf(obj.transform) {((Component)this).gameObject} == {val} || {((Component)this).transform.IsChildOf(((Component)val).transform)}");
						continue;
					}
					WearNTear component = ((Component)val).GetComponent<WearNTear>();
					if (Object.op_Implicit((Object)(object)component))
					{
						component.Destroy();
						continue;
					}
					ZNetView component2 = ((Component)val).GetComponent<ZNetView>();
					if (Object.op_Implicit((Object)(object)component2))
					{
						component2.Destroy();
					}
				}
				else
				{
					ZDOMan.instance.DestroyZDO(zDO);
				}
			}
			m_childObjects.Remove(orCreatePersistantID);
		}

		public string GetHoverName()
		{
			return "";
		}

		public string GetHoverText()
		{
			return "";
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			return true;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			return false;
		}

		public void AddNewChild(ZNetView child)
		{
			AddNewChild(ZDOPersistantID.Instance.GetOrCreatePersistantID(m_nview.m_zdo), child);
		}

		public static void InitPiece(ZNetView netview)
		{
			int parentID = GetParentID(netview);
			if (parentID != 0)
			{
				AddChild(parentID, netview);
			}
		}

		public static int GetParentID(ZNetView netview)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			int num = netview.m_zdo.GetInt(MBCultivatableParentIdHash, 0);
			if (num == 0)
			{
				ZDOID zDOID = netview.m_zdo.GetZDOID(MBCultivatableParentHash);
				if (zDOID != ZDOID.None)
				{
					ZDO zDO = ZDOMan.instance.GetZDO(zDOID);
					num = ((zDO == null) ? ZDOPersistantID.ZDOIDToId(zDOID) : ZDOPersistantID.Instance.GetOrCreatePersistantID(zDO));
					netview.m_zdo.Set(MBCultivatableParentIdHash, num, false);
				}
			}
			return num;
		}

		public static void AddNewChild(int parent, ZNetView child)
		{
			child.m_zdo.Set(MBCultivatableParentIdHash, parent, false);
			AddChild(parent, child);
		}

		public static void AddChild(int parent, ZNetView child)
		{
			StaticPhysics component = ((Component)child).GetComponent<StaticPhysics>();
			if (Object.op_Implicit((Object)(object)component))
			{
				Object.Destroy((Object)(object)component);
			}
			AddChild(parent, ZDOPersistantID.Instance.GetOrCreatePersistantID(child.m_zdo));
		}

		private static void AddChild(int parent, int child)
		{
			if (parent != 0)
			{
				if (!m_childObjects.TryGetValue(parent, out var value))
				{
					value = new List<int>();
					m_childObjects.Add(parent, value);
				}
				value.Add(child);
			}
		}
	}
	public class CustomMastComponent : MastComponent
	{
		public GameObject m_upperBeam;

		public GameObject m_lowerBeam;

		public float m_upperBeamLength;

		public float m_lowerBeamLength;

		public float m_upperBeamWidth;

		public float m_lowerBeamWidth;

		public bool m_upperBeamEnabled;

		public bool m_lowerBeamEnabled;

		public RopeAnchorComponent m_upperBeamLeftAnchor;

		public RopeAnchorComponent m_upperBeamRightAnchor;

		public RopeAnchorComponent m_lowerBeamLeftAnchor;

		public RopeAnchorComponent m_lowerBeamRightAnchor;

		public ZNetView m_nview;

		public SailComponent m_sailComponent;

		public void Awake()
		{
			m_sailCloth = ((Component)this).GetComponent<Cloth>();
			m_nview = ((Component)this).GetComponent<ZNetView>();
			m_sailComponent = ((Component)this).GetComponent<SailComponent>();
		}

		public void LoadZDO()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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)
			if (Object.op_Implicit((Object)(object)m_nview) && m_nview.m_zdo != null)
			{
				Vector3 vec = m_nview.m_zdo.GetVec3("MBMast_upperBeam", new Vector3(1f, 1f, 1f));
				m_upperBeamLength = vec.x;
				m_upperBeamWidth = vec.y;
				m_upperBeamEnabled = vec.z == 1f;
				Vector3 vec2 = m_nview.m_zdo.GetVec3("MBMast_lowerBeam", new Vector3(1f, 1f, 1f));
				m_lowerBeamLength = vec2.x;
				m_lowerBeamWidth = vec2.y;
				m_lowerBeamEnabled = vec2.z == 1f;
				m_upperBeam.transform.localScale = new Vector3(m_upperBeamLength, m_upperBeamWidth, m_upperBeamWidth);
				m_upperBeam.SetActive(m_upperBeamEnabled);
				m_lowerBeam.transform.localScale = new Vector3(m_lowerBeamLength, m_lowerBeamWidth, m_lowerBeamWidth);
				m_lowerBeam.SetActive(m_lowerBeamEnabled);
			}
		}
	}
	public class CustomTextureGroup
	{
		public class CustomTexture
		{
			public Texture Texture { get; internal set; } = null;


			public Texture Normal { get; internal set; } = null;


			public int Index { get; internal set; } = 0;

		}

		private static readonly string[] m_validExtensions = new string[3] { ".png", ".jpg", ".jpeg" };

		private static Dictionary<string, CustomTextureGroup> m_groups = new Dictionary<string, CustomTextureGroup>();

		private Dictionary<string, CustomTexture> m_textureLookUp = new Dictionary<string, CustomTexture>();

		private Dictionary<int, CustomTexture> m_textureHashLookUp = new Dictionary<int, CustomTexture>();

		private List<CustomTexture> m_textures = new List<CustomTexture>();

		public List<CustomTexture> Textures => m_textures;

		public CustomTexture GetTextureByHash(int hash)
		{
			CustomTexture value;
			return m_textureHashLookUp.TryGetValue(hash, out value) ? value : null;
		}

		public CustomTexture GetTextureByName(string name)
		{
			CustomTexture value;
			return m_textureLookUp.TryGetValue(name, out value) ? value : null;
		}

		public static CustomTextureGroup Get(string groupName)
		{
			if (m_groups.TryGetValue(groupName, out var value))
			{
				return value;
			}
			return null;
		}

		public static CustomTextureGroup Load(string groupName)
		{
			if (m_groups.TryGetValue(groupName, out var value))
			{
				return value;
			}
			value = new CustomTextureGroup();
			m_groups.Add(groupName, value);
			string path = Path.Combine(Paths.PluginPath, "ValheimRAFT", "Assets");
			string[] files = Directory.GetFiles(Path.Combine(path, groupName));
			foreach (string text in files)
			{
				string extension = Path.GetExtension(text);
				if (m_validExtensions.Contains<string>(extension, StringComparer.InvariantCultureIgnoreCase) && !Path.GetFileNameWithoutExtension(text).EndsWith("_normal", StringComparison.InvariantCultureIgnoreCase))
				{
					value.AddTexture(text);
				}
			}
			return value;
		}

		public void AddTexture(string file)
		{
			string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
			string extension = Path.GetExtension(file);
			string directoryName = Path.GetDirectoryName(file);
			CustomTexture customTexture = new CustomTexture();
			string text = Path.Combine(directoryName, fileNameWithoutExtension + "_normal" + extension);
			if (File.Exists(text))
			{
				customTexture.Normal = (Texture)(object)AssetUtils.LoadTexture(text, false);
			}
			customTexture.Texture = (Texture)(object)AssetUtils.LoadTexture(file, false);
			((Object)customTexture.Texture).name = fileNameWithoutExtension;
			AddTexture(customTexture);
		}

		public void AddTexture(CustomTexture texture)
		{
			string name = ((Object)texture.Texture).name;
			if (!m_textureLookUp.ContainsKey(name))
			{
				m_textureLookUp.Add(name, texture);
				m_textureHashLookUp.Add(StringExtensionMethods.GetStableHashCode(name), texture);
				texture.Index = m_textures.Count;
				m_textures.Add(texture);
			}
		}
	}
	public class DockComponent : MonoBehaviour
	{
		private enum DockState
		{
			None,
			EnteringDock,
			Docked,
			LeavingDock
		}

		private DockState m_dockState = DockState.None;

		private float m_dockingStrength = 1f;

		private GameObject m_dockedObject;

		private Rigidbody m_dockedRigidbody;

		private ZNetView m_nview;

		public Transform m_dockLocation;

		public Transform m_dockExit;

		public void Awake()
		{
			m_nview = ((Component)this).GetComponent<ZNetView>();
		}

		public void FixedUpdate()
		{
			if (Object.op_Implicit((Object)(object)m_dockedRigidbody))
			{
				if (m_dockState == DockState.EnteringDock)
				{
					PushToward(m_dockLocation);
				}
				else if (m_dockState == DockState.LeavingDock)
				{
					PushToward(m_dockExit);
				}
			}
		}

		private void PushToward(Transform target)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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)
			Vector3 val = ((Component)target).transform.position - ((Component)m_dockedRigidbody).transform.position;
			m_dockedRigidbody.AddForce(((Vector3)(ref val)).normalized * m_dockingStrength, (ForceMode)2);
		}

		public void OnTriggerEnter(Collider other)
		{
			if (Object.op_Implicit((Object)(object)m_dockedObject) && CanDock(other))
			{
				Dock(other);
			}
		}

		private void Dock(Collider other)
		{
			ZNetView componentInParent = ((Component)other).GetComponentInParent<ZNetView>();
			if (Object.op_Implicit((Object)(object)componentInParent) && componentInParent.IsOwner())
			{
				Rigidbody component = ((Component)componentInParent).GetComponent<Rigidbody>();
				if (Object.op_Implicit((Object)(object)component))
				{
					int orCreatePersistantID = ZDOPersistantID.Instance.GetOrCreatePersistantID(componentInParent.m_zdo);
					m_dockedObject = ((Component)componentInParent).gameObject;
					m_dockedRigidbody = component;
					m_nview.m_zdo.Set("MBDock_dockedObject", orCreatePersistantID);
					m_dockState = DockState.EnteringDock;
				}
			}
		}

		private bool CanDock(Collider other)
		{
			if (((Object)other).name.StartsWith("Karve"))
			{
				return true;
			}
			if (((Object)other).name.StartsWith("VikingShip"))
			{
				return true;
			}
			return false;
		}
	}
	internal class HideRaftConsoleCommand : ConsoleCommand
	{
		public override string Name => "RaftHide";

		public override string Help => "Toggles the base raft mesh";

		public override void Run(string[] args)
		{
			//IL_0094: 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)
			if (args.Length < 1)
			{
				Logger.LogInfo((object)"Missing arguments, arguments required: true\\false");
				return;
			}
			if (!bool.TryParse(args[0], out var result))
			{
				Logger.LogInfo((object)("Invalid arguments, " + args[0]));
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer))
			{
				return;
			}
			Ship standingOnShip = ((Character)localPlayer).GetStandingOnShip();
			RaycastHit val = default(RaycastHit);
			if ((!Object.op_Implicit((Object)(object)standingOnShip) || !HideRaft(localPlayer, standingOnShip, result)) && Physics.Raycast(((Component)GameCamera.instance).transform.position, ((Component)GameCamera.instance).transform.forward, ref val, 50f, LayerMask.GetMask(new string[1] { "piece" })))
			{
				MoveableBaseRootComponent componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<MoveableBaseRootComponent>();
				if (Object.op_Implicit((Object)(object)componentInParent))
				{
					HideRaft(localPlayer, componentInParent.m_ship, result);
				}
			}
		}

		private static bool HideRaft(Player player, Ship ship, bool hide)
		{
			MoveableBaseShipComponent component = ((Component)ship).GetComponent<MoveableBaseShipComponent>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.SetVisual(hide);
				return true;
			}
			return false;
		}
	}
	public class MastComponent : MonoBehaviour
	{
		public GameObject m_sailObject;

		public Cloth m_sailCloth;

		internal bool m_allowSailRotation;

		internal bool m_allowSailShrinking;

		internal bool m_disableCloth;
	}
	public class MeshHelper
	{
		private static List<Vector3> vertices;

		private static List<Vector3> normals;

		private static List<Vector2> uv;

		private static List<int> indices;

		private static Dictionary<uint, int> newVectices;

		private static int GetNewVertex(int i1, int i2)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			uint key = (uint)((i1 << 16) | i2);
			uint key2 = (uint)((i2 << 16) | i1);
			if (newVectices.ContainsKey(key2))
			{
				return newVectices[key2];
			}
			if (newVectices.ContainsKey(key))
			{
				return newVectices[key];
			}
			int count = vertices.Count;
			newVectices.Add(key, count);
			vertices.Add((vertices[i1] + vertices[i2]) * 0.5f);
			if (normals != null)
			{
				List<Vector3> list = normals;
				Vector3 val = normals[i1] + normals[i2];
				list.Add(((Vector3)(ref val)).normalized);
			}
			if (uv != null)
			{
				uv.Add((uv[i1] + uv[i2]) * 0.5f);
			}
			return count;
		}

		public static void Subdivide(Mesh mesh)
		{
			newVectices = new Dictionary<uint, int>();
			vertices = new List<Vector3>(mesh.vertices);
			normals = ((mesh.normals != null && mesh.normals.Length == mesh.vertices.Length) ? new List<Vector3>(mesh.normals) : null);
			uv = ((mesh.uv != null && mesh.uv.Length == mesh.vertices.Length) ? new List<Vector2>(mesh.uv) : null);
			indices = new List<int>();
			int[] triangles = mesh.triangles;
			for (int i = 0; i < triangles.Length; i += 3)
			{
				int num = triangles[i];
				int num2 = triangles[i + 1];
				int num3 = triangles[i + 2];
				int newVertex = GetNewVertex(num, num2);
				int newVertex2 = GetNewVertex(num2, num3);
				int newVertex3 = GetNewVertex(num3, num);
				indices.Add(num);
				indices.Add(newVertex);
				indices.Add(newVertex3);
				indices.Add(num2);
				indices.Add(newVertex2);
				indices.Add(newVertex);
				indices.Add(num3);
				indices.Add(newVertex3);
				indices.Add(newVertex2);
				indices.Add(newVertex);
				indices.Add(newVertex2);
				indices.Add(newVertex3);
			}
			mesh.vertices = vertices.ToArray();
			if (normals != null)
			{
				mesh.normals = normals.ToArray();
			}
			if (uv != null)
			{
				mesh.uv = uv.ToArray();
			}
			mesh.triangles = indices.ToArray();
			newVectices = null;
			vertices = null;
			normals = null;
			uv = null;
			indices = null;
		}
	}
	public class MoveableBaseRootComponent : MonoBehaviour
	{
		public static readonly KeyValuePair<int, int> MBParentHash = ZDO.GetHashZDOID("MBParent");

		public static readonly int MBCharacterParentHash = StringExtensionMethods.GetStableHashCode("MBCharacterParent");

		public static readonly int MBCharacterOffsetHash = StringExtensionMethods.GetStableHashCode("MBCharacterOFfset");

		public static readonly int MBParentIdHash = StringExtensionMethods.GetStableHashCode("MBParentId");

		public static readonly int MBPositionHash = StringExtensionMethods.GetStableHashCode("MBPosition");

		public static readonly int MBRotationHash = StringExtensionMethods.GetStableHashCode("MBRotation");

		public static readonly int MBRotationVecHash = StringExtensionMethods.GetStableHashCode("MBRotationVec");

		internal static Dictionary<int, List<ZNetView>> m_pendingPieces = new Dictionary<int, List<ZNetView>>();

		internal static Dictionary<int, List<ZDO>> m_allPieces = new Dictionary<int, List<ZDO>>();

		internal static Dictionary<int, List<ZDOID>> m_dynamicObjects = new Dictionary<int, List<ZDOID>>();

		internal MoveableBaseShipComponent m_moveableBaseShip;

		internal Rigidbody m_rigidbody;

		internal ZNetView m_nview;

		internal Rigidbody m_syncRigidbody;

		internal Ship m_ship;

		internal List<ZNetView> m_pieces = new List<ZNetView>();

		internal List<MastComponent> m_mastPieces = new List<MastComponent>();

		internal List<RudderComponent> m_rudderPieces = new List<RudderComponent>();

		internal List<ZNetView> m_portals = new List<ZNetView>();

		internal List<RopeLadderComponent> m_ladders = new List<RopeLadderComponent>();

		internal List<BoardingRampComponent> m_boardingRamps = new List<BoardingRampComponent>();

		private Vector2i m_sector;

		private Bounds m_bounds = default(Bounds);

		internal BoxCollider m_blockingcollider;

		internal BoxCollider m_floatcollider;

		internal BoxCollider m_onboardcollider;

		internal int m_id;

		public bool m_statsOverride;

		private static bool itemsRemovedDuringWait;

		public void Awake()
		{
			m_rigidbody = ((Component)this).gameObject.AddComponent<Rigidbody>();
			m_rigidbody.isKinematic = true;
			m_rigidbody.interpolation = (RigidbodyInterpolation)1;
			m_rigidbody.mass = 99999f;
			if (ZNet.instance.IsServer())
			{
				((MonoBehaviour)this).StartCoroutine("UpdatePieceSectors");
			}
		}

		public void CleanUp()
		{
			((MonoBehaviour)this).StopCoroutine("ActivatePendingPieces");
			if (!Object.op_Implicit((Object)(object)ZNetScene.instance) || m_id == 0)
			{
				return;
			}
			for (int i = 0; i < m_pieces.Count; i++)
			{
				ZNetView val = m_pieces[i];
				if (Object.op_Implicit((Object)(object)val))
				{
					((Component)val).transform.SetParent((Transform)null);
					AddInactivePiece(m_id, val);
				}
			}
			List<Player> allPlayers = Player.GetAllPlayers();
			for (int j = 0; j < allPlayers.Count; j++)
			{
				if (Object.op_Implicit((Object)(object)allPlayers[j]) && (Object)(object)((Component)allPlayers[j]).transform.parent == (Object)(object)((Component)this).transform)
				{
					((Component)allPlayers[j]).transform.SetParent((Transform)null);
				}
			}
		}

		private void Sync()
		{
			//IL_0026: 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)
			if (Object.op_Implicit((Object)(object)m_syncRigidbody))
			{
				m_rigidbody.MovePosition(((Component)m_syncRigidbody).transform.position);
				m_rigidbody.MoveRotation(((Component)m_syncRigidbody).transform.rotation);
			}
		}

		public void FixedUpdate()
		{
			Sync();
		}

		public void LateUpdate()
		{
			Sync();
			if (!ZNet.instance.IsServer())
			{
				UpdateAllPieces();
			}
		}

		public void UpdateAllPieces()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			Vector2i zone = ZoneSystem.instance.GetZone(((Component)this).transform.position);
			if (!(zone != m_sector))
			{
				return;
			}
			m_sector = zone;
			for (int i = 0; i < m_pieces.Count; i++)
			{
				ZNetView val = m_pieces[i];
				if (!Object.op_Implicit((Object)(object)val))
				{
					m_pieces.RemoveAt(i);
					i--;
				}
				else
				{
					val.m_zdo.SetPosition(((Component)this).transform.position);
				}
			}
		}

		public IEnumerator UpdatePieceSectors()
		{
			while (true)
			{
				if (!m_allPieces.TryGetValue(m_id, out var list))
				{
					yield return (object)new WaitForSeconds(5f);
					continue;
				}
				Vector3 pos = ((Component)this).transform.position;
				Vector2i sector = ZoneSystem.instance.GetZone(pos);
				float time = Time.realtimeSinceStartup;
				if (sector != m_sector)
				{
					m_sector = sector;
					for (int i = 0; i < list.Count; i++)
					{
						ZDO zdo = list[i];
						if (!(zdo.GetSector() != sector))
						{
							continue;
						}
						int id = zdo.GetInt(MBParentIdHash, 0);
						if (id != m_id)
						{
							Logger.LogWarning((object)"Invalid piece in piece list found, removing.");
							list.FastRemoveAt(i);
							i--;
							continue;
						}
						zdo.SetPosition(pos);
						if (Time.realtimeSinceStartup - time > 0.1f)
						{
							itemsRemovedDuringWait = false;
							yield return (object)new WaitForEndOfFrame();
							time = Time.realtimeSinceStartup;
							if (itemsRemovedDuringWait)
							{
								i = 0;
							}
						}
					}
				}
				yield return (object)new WaitForEndOfFrame();
				list = null;
			}
		}

		internal float GetColliderBottom()
		{
			//IL_000c: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			return ((Component)m_blockingcollider).transform.position.y + m_blockingcollider.center.y - m_blockingcollider.size.y / 2f;
		}

		public static void AddInactivePiece(int id, ZNetView netview)
		{
			if (!m_pendingPieces.TryGetValue(id, out var value))
			{
				value = new List<ZNetView>();
				m_pendingPieces.Add(id, value);
			}
			value.Add(netview);
			WearNTear component = ((Component)netview).GetComponent<WearNTear>();
			if (Object.op_Implicit((Object)(object)component))
			{
				((Behaviour)component).enabled = false;
			}
		}

		public void RemovePiece(ZNetView netview)
		{
			if (m_pieces.Remove(netview))
			{
				MastComponent component = ((Component)netview).GetComponent<MastComponent>();
				if (Object.op_Implicit((Object)(object)component))
				{
					m_mastPieces.Remove(component);
				}
				RudderComponent component2 = ((Component)netview).GetComponent<RudderComponent>();
				if (Object.op_Implicit((Object)(object)component2))
				{
					m_rudderPieces.Remove(component2);
				}
				BoardingRampComponent component3 = ((Component)netview).GetComponent<BoardingRampComponent>();
				if (Object.op_Implicit((Object)(object)component3))
				{
					m_boardingRamps.Remove(component3);
				}
				TeleportWorld component4 = ((Component)netview).GetComponent<TeleportWorld>();
				if (Object.op_Implicit((Object)(object)component4))
				{
					m_portals.Remove(netview);
				}
				RopeLadderComponent component5 = ((Component)netview).GetComponent<RopeLadderComponent>();
				if (Object.op_Implicit((Object)(object)component5))
				{
					m_ladders.Remove(component5);
					component5.m_mbroot = null;
				}
				UpdateStats();
			}
		}

		private void UpdateStats()
		{
		}

		public void DestroyPiece(WearNTear wnt)
		{
			ZNetView component = ((Component)wnt).GetComponent<ZNetView>();
			RemovePiece(component);
			UpdatePieceCount();
			if (GetPieceCount() == 0)
			{
				((Component)m_ship).GetComponent<WearNTear>().Destroy();
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		public void ActivatePendingPiecesCoroutine()
		{
			((MonoBehaviour)this).StartCoroutine("ActivatePendingPieces");
		}

		public IEnumerator ActivatePendingPieces()
		{
			if (!Object.op_Implicit((Object)(object)m_nview) || m_nview.m_zdo == null)
			{
				yield return null;
			}
			int id = ZDOPersistantID.Instance.GetOrCreatePersistantID(m_nview.m_zdo);
			if (m_pendingPieces.TryGetValue(id, out var list))
			{
				Stopwatch stopwatch = new Stopwatch();
				stopwatch.Start();
				for (int j = 0; j < list.Count; j++)
				{
					ZNetView obj = list[j];
					if (Object.op_Implicit((Object)(object)obj))
					{
						ActivatePiece(obj);
						if (!ZNetScene.instance.InLoadingScreen() && stopwatch.ElapsedMilliseconds >= 10)
						{
							yield return (object)new WaitForEndOfFrame();
							stopwatch.Restart();
						}
					}
				}
				list.Clear();
				m_pendingPieces.Remove(id);
			}
			if (m_dynamicObjects.TryGetValue(m_id, out var objectList))
			{
				Vector3 offset = default(Vector3);
				for (int i = 0; i < objectList.Count; i++)
				{
					GameObject go = ZNetScene.instance.FindInstance(objectList[i]);
					if (!Object.op_Implicit((Object)(object)go))
					{
						continue;
					}
					ZNetView nv = go.GetComponentInParent<ZNetView>();
					if (!Object.op_Implicit((Object)(object)nv) || nv.m_zdo == null)
					{
						continue;
					}
					if (ZDOExtraData.s_vec3.TryGetValue(nv.m_zdo.m_uid, out var dic))
					{
						if (dic.TryGetValue(MBCharacterOffsetHash, ref offset))
						{
							((Component)nv).transform.position = offset + ((Component)this).transform.position;
						}
						offset = default(Vector3);
					}
					ZDOExtraData.RemoveInt(nv.m_zdo.m_uid, MBCharacterParentHash);
					ZDOExtraData.RemoveVec3(nv.m_zdo.m_uid, MBCharacterOffsetHash);
					dic = null;
				}
				m_dynamicObjects.Remove(m_id);
			}
			yield return null;
		}

		public static void AddDynamicParent(ZNetView source, GameObject target)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			MoveableBaseRootComponent componentInParent = target.GetComponentInParent<MoveableBaseRootComponent>();
			if (Object.op_Implicit((Object)(object)componentInParent))
			{
				source.m_zdo.Set(MBCharacterParentHash, componentInParent.m_id, false);
				source.m_zdo.Set(MBCharacterOffsetHash, ((Component)source).transform.position - ((Component)componentInParent).transform.position);
			}
		}

		public static void AddDynamicParent(ZNetView source, GameObject target, Vector3 offset)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			MoveableBaseRootComponent componentInParent = target.GetComponentInParent<MoveableBaseRootComponent>();
			if (Object.op_Implicit((Object)(object)componentInParent))
			{
				source.m_zdo.Set(MBCharacterParentHash, componentInParent.m_id, false);
				source.m_zdo.Set(MBCharacterOffsetHash, offset);
			}
		}

		public static void InitZDO(ZDO zdo)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			if (zdo.m_prefab == StringExtensionMethods.GetStableHashCode("MBRaft"))
			{
			}
			int parentID = GetParentID(zdo);
			if (parentID != 0)
			{
				if (!m_allPieces.TryGetValue(parentID, out var value))
				{
					value = new List<ZDO>();
					m_allPieces.Add(parentID, value);
				}
				value.Add(zdo);
			}
			int @int = zdo.GetInt(MBCharacterParentHash, 0);
			if (@int != 0)
			{
				if (!m_dynamicObjects.TryGetValue(@int, out var value2))
				{
					value2 = new List<ZDOID>();
					m_dynamicObjects.Add(@int, value2);
				}
				value2.Add(zdo.m_uid);
			}
		}

		public static void RemoveZDO(ZDO zdo)
		{
			int parentID = GetParentID(zdo);
			if (parentID != 0 && m_allPieces.TryGetValue(parentID, out var value))
			{
				value.FastRemove(zdo);
				itemsRemovedDuringWait = true;
			}
		}

		private static int GetParentID(ZDO zdo)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_003e: 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)
			//IL_0085: 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_008f: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			int num = zdo.GetInt(MBParentIdHash, 0);
			if (num == 0)
			{
				ZDOID zDOID = zdo.GetZDOID(MBParentHash);
				if (zDOID != ZDOID.None)
				{
					ZDO zDO = ZDOMan.instance.GetZDO(zDOID);
					num = ((zDO == null) ? ZDOPersistantID.ZDOIDToId(zDOID) : ZDOPersistantID.Instance.GetOrCreatePersistantID(zDO));
					zdo.Set(MBParentIdHash, num, false);
					int mBRotationVecHash = MBRotationVecHash;
					Quaternion quaternion = zdo.GetQuaternion(MBRotationHash, Quaternion.identity);
					zdo.Set(mBRotationVecHash, ((Quaternion)(ref quaternion)).eulerAngles);
					zdo.RemoveZDOID(MBParentHash);
					ZDOHelper.Remove<Quaternion>(ZDOExtraData.s_quats, zDOID, MBRotationHash);
				}
			}
			return num;
		}

		public static void InitPiece(ZNetView netview)
		{
			Rigidbody componentInChildren = ((Component)netview).GetComponentInChildren<Rigidbody>();
			if (Object.op_Implicit((Object)(object)componentInChildren) && !componentInChildren.isKinematic)
			{
				return;
			}
			int parentID = GetParentID(netview.m_zdo);
			if (parentID == 0)
			{
				return;
			}
			GameObject gameObject = ZDOPersistantID.Instance.GetGameObject(parentID);
			if (Object.op_Implicit((Object)(object)gameObject))
			{
				MoveableBaseShipComponent component = gameObject.GetComponent<MoveableBaseShipComponent>();
				if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.m_baseRoot))
				{
					component.m_baseRoot.ActivatePiece(netview);
				}
			}
			else
			{
				AddInactivePiece(parentID, netview);
			}
		}

		public void ActivatePiece(ZNetView netview)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)netview))
			{
				((Component)netview).transform.SetParent(((Component)this).transform);
				((Component)netview).transform.localPosition = netview.m_zdo.GetVec3(MBPositionHash, Vector3.zero);
				((Component)netview).transform.localRotation = Quaternion.Euler(netview.m_zdo.GetVec3(MBRotationVecHash, Vector3.zero));
				WearNTear component = ((Component)netview).GetComponent<WearNTear>();
				if (Object.op_Implicit((Object)(object)component))
				{
					((Behaviour)component).enabled = true;
				}
				AddPiece(netview);
			}
		}

		public void AddTemporaryPiece(Piece piece)
		{
			((Component)piece).transform.SetParent(((Component)this).transform);
		}

		public void AddNewPiece(Piece piece)
		{
			if (Object.op_Implicit((Object)(object)piece) && Object.op_Implicit((Object)(object)piece.m_nview))
			{
				AddNewPiece(piece.m_nview);
			}
		}

		public void AddNewPiece(ZNetView netview)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			((Component)netview).transform.SetParent(((Component)this).transform);
			if (netview.m_zdo != null)
			{
				netview.m_zdo.Set(MBParentIdHash, ZDOPersistantID.Instance.GetOrCreatePersistantID(m_nview.m_zdo), false);
				netview.m_zdo.Set(MBPositionHash, ((Component)netview).transform.localPosition);
				ZDO zdo = netview.m_zdo;
				int mBRotationVecHash = MBRotationVecHash;
				Quaternion localRotation = ((Component)netview).transform.localRotation;
				zdo.Set(mBRotationVecHash, ((Quaternion)(ref localRotation)).eulerAngles);
			}
			AddPiece(netview);
			InitZDO(netview.m_zdo);
		}

		public void AddPiece(ZNetView netview)
		{
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Expected O, but got Unknown
			m_pieces.Add(netview);
			UpdatePieceCount();
			EncapsulateBounds(netview);
			WearNTear component = ((Component)netview).GetComponent<WearNTear>();
			if (Object.op_Implicit((Object)(object)component) && ValheimRAFT.Instance.MakeAllPiecesWaterProof.Value)
			{
				component.m_noRoofWear = false;
			}
			CultivatableComponent component2 = ((Component)netview).GetComponent<CultivatableComponent>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.UpdateMaterial();
			}
			MastComponent component3 = ((Component)netview).GetComponent<MastComponent>();
			if (Object.op_Implicit((Object)(object)component3))
			{
				m_mastPieces.Add(component3);
			}
			BoardingRampComponent component4 = ((Component)netview).GetComponent<BoardingRampComponent>();
			if (Object.op_Implicit((Object)(object)component4))
			{
				component4.ForceRampUpdate();
				m_boardingRamps.Add(component4);
			}
			RudderComponent component5 = ((Component)netview).GetComponent<RudderComponent>();
			if (Object.op_Implicit((Object)(object)component5))
			{
				if (!Object.op_Implicit((Object)(object)component5.m_controls))
				{
					component5.m_controls = ((Component)netview).GetComponentInChildren<ShipControlls>();
				}
				if (!Object.op_Implicit((Object)(object)component5.m_wheel))
				{
					component5.m_wheel = ((Component)netview).transform.Find("controls/wheel");
				}
				component5.m_controls.m_nview = m_nview;
				component5.m_controls.m_ship = ((Component)m_moveableBaseShip).GetComponent<Ship>();
				m_rudderPieces.Add(component5);
			}
			TeleportWorld component6 = ((Component)netview).GetComponent<TeleportWorld>();
			if (Object.op_Implicit((Object)(object)component6))
			{
				m_portals.Add(netview);
			}
			RopeLadderComponent component7 = ((Component)netview).GetComponent<RopeLadderComponent>();
			if (Object.op_Implicit((Object)(object)component7))
			{
				m_ladders.Add(component7);
				component7.m_mbroot = this;
			}
			MeshRenderer[] componentsInChildren = ((Component)netview).GetComponentsInChildren<MeshRenderer>(true);
			MeshRenderer[] array = componentsInChildren;
			foreach (MeshRenderer val in array)
			{
				if (Object.op_Implicit((Object)(object)((Renderer)val).sharedMaterial))
				{
					Material[] sharedMaterials = ((Renderer)val).sharedMaterials;
					for (int j = 0; j < sharedMaterials.Length; j++)
					{
						Material val2 = new Material(sharedMaterials[j]);
						val2.SetFloat("_RippleDistance", 0f);
						val2.SetFloat("_ValueNoise", 0f);
						sharedMaterials[j] = val2;
					}
					((Renderer)val).sharedMaterials = sharedMaterials;
				}
			}
			Rigidbody[] componentsInChildren2 = ((Component)netview).GetComponentsInChildren<Rigidbody>();
			for (int k = 0; k < componentsInChildren2.Length; k++)
			{
				if (componentsInChildren2[k].isKinematic)
				{
					Object.Destroy((Object)(object)componentsInChildren2[k]);
				}
			}
			UpdateStats();
		}

		private void UpdatePieceCount()
		{
			if (Object.op_Implicit((Object)(object)m_nview) && m_nview.m_zdo != null)
			{
				m_nview.m_zdo.Set("MBPieceCount", m_pieces.Count);
			}
		}

		public void EncapsulateBounds(ZNetView netview)
		{
			//IL_006a: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: 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_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			Piece component = ((Component)netview).GetComponent<Piece>();
			List<Collider> list = (Object.op_Implicit((Object)(object)component) ? ((StaticTarget)component).GetAllColliders() : new List<Collider>(((Component)netview).GetComponentsInChildren<Collider>()));
			Door componentInChildren = ((Component)netview).GetComponentInChildren<Door>();
			RopeLadderComponent component2 = ((Component)netview).GetComponent<RopeLadderComponent>();
			RopeAnchorComponent component3 = ((Component)netview).GetComponent<RopeAnchorComponent>();
			if (!Object.op_Implicit((Object)(object)componentInChildren) && !Object.op_Implicit((Object)(object)component2) && !Object.op_Implicit((Object)(object)component3))
			{
				((Bounds)(ref m_bounds)).Encapsulate(((Component)netview).transform.localPosition);
			}
			for (int i = 0; i < list.Count; i++)
			{
				Physics.IgnoreCollision(list[i], (Collider)(object)m_blockingcollider, true);
				Physics.IgnoreCollision(list[i], (Collider)(object)m_floatcollider, true);
				Physics.IgnoreCollision(list[i], (Collider)(object)m_onboardcollider, true);
			}
			m_blockingcollider.size = new Vector3(((Bounds)(ref m_bounds)).size.x, 3f, ((Bounds)(ref m_bounds)).size.z);
			m_blockingcollider.center = new Vector3(((Bounds)(ref m_bounds)).center.x, -0.2f, ((Bounds)(ref m_bounds)).center.z);
			m_floatcollider.size = new Vector3(((Bounds)(ref m_bounds)).size.x, 3f, ((Bounds)(ref m_bounds)).size.z);
			m_floatcollider.center = new Vector3(((Bounds)(ref m_bounds)).center.x, -0.2f, ((Bounds)(ref m_bounds)).center.z);
			m_onboardcollider.size = ((Bounds)(ref m_bounds)).size;
			m_onboardcollider.center = ((Bounds)(ref m_bounds)).center;
		}

		internal int GetPieceCount()
		{
			if (!Object.op_Implicit((Object)(object)m_nview) || m_nview.m_zdo == null)
			{
				return m_pieces.Count;
			}
			return m_nview.m_zdo.GetInt("MBPieceCount", m_pieces.Count);
		}
	}
	public class MoveableBaseShipComponent : MonoBehaviour
	{
		[Flags]
		public enum MBFlags
		{
			None = 0,
			IsAnchored = 1,
			HideMesh = 2
		}

		internal MoveableBaseRootComponent m_baseRoot;

		internal Rigidbody m_rigidbody;

		internal Ship m_ship;

		internal ZNetView m_nview;

		internal GameObject m_baseRootObject;

		internal ZSyncTransform m_zsync;

		public float m_targetHeight;

		public float m_balanceForce = 0.03f;

		public float m_liftForce = 20f;

		public MBFlags m_flags;

		public void Awake()
		{
			//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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: 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)
			Ship component = ((Component)this).GetComponent<Ship>();
			m_nview = ((Component)this).GetComponent<ZNetView>();
			m_zsync = ((Component)this).GetComponent<ZSyncTransform>();
			m_ship = ((Component)this).GetComponent<Ship>();
			m_baseRootObject = new GameObject
			{
				name = "MoveableBase",
				layer = 0
			};
			m_baseRoot = m_baseRootObject.AddComponent<MoveableBaseRootComponent>();
			m_nview.Register<bool>("SetAnchor", (Action<long, bool>)delegate(long sender, bool state)
			{
				RPC_SetAnchor(sender, state);
			});
			m_nview.Register<bool>("SetVisual", (Action<long, bool>)delegate(long sender, bool state)
			{
				RPC_SetVisual(sender, state);
			});
			m_baseRoot.m_moveableBaseShip = this;
			m_baseRoot.m_nview = m_nview;
			m_baseRoot.m_ship = component;
			m_baseRoot.m_id = ZDOPersistantID.Instance.GetOrCreatePersistantID(m_nview.m_zdo);
			m_rigidbody = ((Component)this).GetComponent<Rigidbody>();
			m_baseRoot.m_syncRigidbody = m_rigidbody;
			m_rigidbody.mass = 1000f;
			m_baseRootObject.transform.SetParent((Transform)null);
			m_baseRootObject.transform.position = ((Component)this).transform.position;
			m_baseRootObject.transform.rotation = ((Component)this).transform.rotation;
			Transform val = ((Component)component).transform.Find("ship/visual/mast");
			if (val != null)
			{
				((Component)val).gameObject.SetActive(false);
			}
			Transform val2 = ((Component)component).transform.Find("ship/colliders/log");
			if (val2 != null)
			{
				((Component)val2).gameObject.SetActive(false);
			}
			Transform val3 = ((Component)component).transform.Find("ship/colliders/log (1)");
			if (val3 != null)
			{
				((Component)val3).gameObject.SetActive(false);
			}
			Transform val4 = ((Component)component).transform.Find("ship/colliders/log (2)");
			if (val4 != null)
			{
				((Component)val4).gameObject.SetActive(false);
			}
			Transform val5 = ((Component)component).transform.Find("ship/colliders/log (3)");
			if (val5 != null)
			{
				((Component)val5).gameObject.SetActive(false);
			}
			UpdateVisual();
			BoxCollider[] componentsInChildren = ((Component)((Component)this).transform).GetComponentsInChildren<BoxCollider>();
			m_baseRoot.m_onboardcollider = ((IEnumerable<BoxCollider>)componentsInChildren).FirstOrDefault((Func<BoxCollider, bool>)((BoxCollider k) => ((Object)((Component)k).gameObject).name == "OnboardTrigger"));
			((Component)m_baseRoot.m_onboardcollider).transform.localScale = new Vector3(1f, 1f, 1f);
			m_baseRoot.m_floatcollider = component.m_floatCollider;
			((Component)m_baseRoot.m_floatcollider).transform.localScale = new Vector3(1f, 1f, 1f);
			m_baseRoot.m_blockingcollider = ((Component)((Component)component).transform.Find("ship/colliders/Cube")).GetComponentInChildren<BoxCollider>();
			((Component)m_baseRoot.m_blockingcollider).transform.localScale = new Vector3(1f, 1f, 1f);
			((Component)m_baseRoot.m_blockingcollider).gameObject.layer = ValheimRAFT.CustomRaftLayer;
			((Component)((Component)m_baseRoot.m_blockingcollider).transform.parent).gameObject.layer = ValheimRAFT.CustomRaftLayer;
			ZLog.Log((object)$"Activating MBRoot: {m_baseRoot.m_id}");
			m_baseRoot.ActivatePendingPiecesCoroutine();
			FirstTimeCreation();
		}

		public void UpdateVisual()
		{
			if (m_nview.m_zdo != null)
			{
				m_flags = (MBFlags)m_nview.m_zdo.GetInt("MBFlags", (int)m_flags);
				((Component)((Component)this).transform.Find("ship/visual")).gameObject.SetActive(!m_flags.HasFlag(MBFlags.HideMesh));
				((Component)((Component)this).transform.Find("interactive")).gameObject.SetActive(!m_flags.HasFlag(MBFlags.HideMesh));
			}
		}

		public void OnDestroy()
		{
			if (Object.op_Implicit((Object)(object)m_baseRoot))
			{
				m_baseRoot.CleanUp();
				Object.Destroy((Object)(object)((Component)m_baseRoot).gameObject);
			}
		}

		private void FirstTimeCreation()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if (m_baseRoot.GetPieceCount() != 0)
			{
				return;
			}
			GameObject prefab = ZNetScene.instance.GetPrefab("wood_floor");
			for (float num = -1f; num < 1.01f; num += 2f)
			{
				for (float num2 = -2f; num2 < 2.01f; num2 += 2f)
				{
					Vector3 val = ((Component)this).transform.TransformPoint(new Vector3(num, 0.45f, num2));
					GameObject val2 = Object.Instantiate<GameObject>(prefab, val, ((Component)this).transform.rotation);
					ZNetView component = val2.GetComponent<ZNetView>();
					m_baseRoot.AddNewPiece(component);
				}
			}
		}

		internal void Accend()
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			if (m_flags.HasFlag(MBFlags.IsAnchored))
			{
				SetAnchor(state: false);
			}
			if (!ValheimRAFT.Instance.AllowFlight.Value)
			{
				m_targetHeight = 0f;
			}
			else
			{
				if (!Object.op_Implicit((Object)(object)m_baseRoot) || !Object.op_Implicit((Object)(object)m_baseRoot.m_floatcollider))
				{
					return;
				}
				m_targetHeight = Mathf.Clamp(((Component)m_baseRoot.m_floatcollider).transform.position.y + 1f, ZoneSystem.instance.m_waterLevel, 200f);
			}
			m_nview.m_zdo.Set("MBTargetHeight", m_targetHeight);
		}

		internal void Descent()
		{
			//IL_0092: 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)
			if (m_flags.HasFlag(MBFlags.IsAnchored))
			{
				SetAnchor(state: false);
			}
			float targetHeight = m_targetHeight;
			if (!ValheimRAFT.Instance.AllowFlight.Value)
			{
				m_targetHeight = 0f;
			}
			else
			{
				if (!Object.op_Implicit((Object)(object)m_baseRoot) || !Object.op_Implicit((Object)(object)m_baseRoot.m_floatcollider))
				{
					return;
				}
				m_targetHeight = Mathf.Clamp(((Component)m_baseRoot.m_floatcollider).transform.position.y - 1f, ZoneSystem.instance.m_waterLevel, 200f);
				if (((Component)m_baseRoot.m_floatcollider).transform.position.y - 1f <= ZoneSystem.instance.m_waterLevel)
				{
					m_targetHeight = 0f;
				}
			}
			m_nview.m_zdo.Set("MBTargetHeight", m_targetHeight);
		}

		internal void UpdateStats(bool flight)
		{
			if (!Object.op_Implicit((Object)(object)m_rigidbody) || !Object.op_Implicit((Object)(object)m_baseRoot) || m_baseRoot.m_statsOverride)
			{
				return;
			}
			m_rigidbody.mass = 3000f;
			m_rigidbody.angularDrag = (flight ? 1f : 0f);
			m_rigidbody.drag = (flight ? 1f : 0f);
			if (Object.op_Implicit((Object)(object)m_ship))
			{
				m_ship.m_angularDamping = (flight ? 5f : 0.8f);
				m_ship.m_backwardForce = 1f;
				m_ship.m_damping = (flight ? 5f : 0.35f);
				m_ship.m_dampingSideway = (flight ? 3f : 0.3f);
				m_ship.m_force = 3f;
				m_ship.m_forceDistance = 5f;
				m_ship.m_sailForceFactor = (flight ? 0.2f : 0.05f);
				m_ship.m_stearForce = (flight ? 0.2f : 1f);
				m_ship.m_stearVelForceFactor = 1.3f;
				m_ship.m_waterImpactDamage = 0f;
				ImpactEffect component = ((Component)m_ship).GetComponent<ImpactEffect>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.m_interval = 0.1f;
					component.m_minVelocity = 0.1f;
					component.m_damages.m_damage = 100f;
				}
			}
		}

		internal void SetAnchor(bool state)
		{
			m_nview.InvokeRPC("SetAnchor", new object[1] { state });
		}

		public void RPC_SetAnchor(long sender, bool state)
		{
			m_flags = (state ? (m_flags | MBFlags.IsAnchored) : (m_flags & ~MBFlags.IsAnchored));
			m_nview.m_zdo.Set("MBFlags", (int)m_flags);
		}

		internal void SetVisual(bool state)
		{
			m_nview.InvokeRPC("SetVisual", new object[1] { state });
		}

		public void RPC_SetVisual(long sender, bool state)
		{
			m_flags = (state ? (m_flags | MBFlags.HideMesh) : (m_flags & ~MBFlags.HideMesh));
			m_nview.m_zdo.Set("MBFlags", (int)m_flags);
			UpdateVisual();
		}
	}
	internal class MoveRaftConsoleCommand : ConsoleCommand
	{
		public override string Name => "RaftOffset";

		public override string Help => "Offsets the raft by the given coordinates (X Y Z). Note: it's intended use is so you can slightly offset the pieces relative to the raft center. The actual center of the raft will NOT move.";

		public override void Run(string[] args)
		{
			//IL_00fd: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			if (args.Length < 3)
			{
				Logger.LogInfo((object)"Missing arguments, arguments required: X Y Z");
				return;
			}
			if (!float.TryParse(args[0], out var result))
			{
				Logger.LogInfo((object)("Invalid argument X: " + args[0]));
				return;
			}
			if (!float.TryParse(args[1], out var result2))
			{
				Logger.LogInfo((object)("Invalid argument Y: " + args[1]));
				return;
			}
			if (!float.TryParse(args[2], out var result3))
			{
				Logger.LogInfo((object)("Invalid argument Z: " + args[2]));
				return;
			}
			Vector3 offset = default(Vector3);
			((Vector3)(ref offset))..ctor(result, result2, result3);
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer))
			{
				return;
			}
			Ship standingOnShip = ((Character)localPlayer).GetStandingOnShip();
			RaycastHit val = default(RaycastHit);
			if ((!Object.op_Implicit((Object)(object)standingOnShip) || !MoveRaft(localPlayer, standingOnShip, offset)) && Physics.Raycast(((Component)GameCamera.instance).transform.position, ((Component)GameCamera.instance).transform.forward, ref val, 50f, LayerMask.GetMask(new string[1] { "piece" })))
			{
				MoveableBaseRootComponent componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<MoveableBaseRootComponent>();
				if (Object.op_Implicit((Object)(object)componentInParent))
				{
					MoveRaft(localPlayer, componentInParent.m_ship, offset);
				}
			}
		}

		private static bool MoveRaft(Player player, Ship ship, Vector3 offset)
		{
			//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_00a2: 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_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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			MoveableBaseShipComponent component = ((Component)ship).GetComponent<MoveableBaseShipComponent>();
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.m_baseRoot))
			{
				Stopwatch stopwatch = new Stopwatch();
				stopwatch.Start();
				int orCreatePersistantID = ZDOPersistantID.Instance.GetOrCreatePersistantID(component.m_baseRoot.m_nview.m_zdo);
				foreach (ZDO value in ZDOMan.instance.m_objectsByID.Values)
				{
					int @int = value.GetInt(MoveableBaseRootComponent.MBParentIdHash, 0);
					if (@int == orCreatePersistantID)
					{
						Vector3 vec = value.GetVec3(MoveableBaseRootComponent.MBPositionHash, Vector3.zero);
						Vector3 val = vec + offset;
						value.Set(MoveableBaseRootComponent.MBPositionHash, val);
						value.SetPosition(((Component)ship).transform.position);
						ZNetView val2 = ZNetScene.instance.FindInstance(value);
						if (Object.op_Implicit((Object)(object)val2))
						{
							((Component)val2).transform.localPosition = val;
						}
					}
				}
				Logger.LogInfo((object)$"Completed MoveRaft in {stopwatch.ElapsedMilliseconds}ms");
				return true;
			}
			return false;
		}
	}
	public class PierComponent : MonoBehaviour
	{
		public ZNetView m_nview;

		public GameObject m_segmentObject;

		public float m_segmentHeight;

		public float m_baseOffset;

		private int m_terrainLayer;

		private List<GameObject> m_segmentObjects = new List<GameObject>();

		public void Awake()
		{
			m_terrainLayer = LayerMask.GetMask(new string[1] { "terrain" });
			if (ZNetView.m_forceDisableInit)
			{
				WearNTear component = ((Component)this).GetComponent<WearNTear>();
				if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.m_new))
				{
					component.m_new.SetActive(false);
				}
				m_segmentObject.SetActive(false);
				Collider[] componentsInChildren = m_segmentObject.GetComponentsInChildren<Collider>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].enabled = false;
				}
				m_segmentObject.layer = LayerMask.NameToLayer("ghost");
				Transform[] components = m_segmentObject.GetComponents<Transform>();
				for (int j = 0; j < components.Length; j++)
				{
					((Component)components[j]).gameObject.layer = m_segmentObject.layer;
				}
				((MonoBehaviour)this).InvokeRepeating("UpdateSegments", 0.5f, 0.1f);
			}
			UpdateSegments();
		}

		private void UpdateSegments()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: 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)
			((Component)this).transform.position = new Vector3(((Component)this).transform.position.x, ZoneSystem.instance.m_waterLevel + m_baseOffset, ((Component)this).transform.position.z);
			RaycastHit[] array = Physics.RaycastAll(((Component)this).transform.position, Vector3.down, 100f, m_terrainLayer);
			float num = 0f;
			for (int i = 0; i < array.Length; i++)
			{
				if (num < ((RaycastHit)(ref array[i])).distance)
				{
					num = ((RaycastHit)(ref array[i])).distance;
				}
			}
			int num2 = Mathf.CeilToInt(num / m_segmentHeight);
			for (int j = m_segmentObjects.Count; j < num2; j++)
			{
				GameObject item = Object.Instantiate<GameObject>(m_segmentObject, ((Component)this).transform.position, Quaternion.identity, ((Component)this).transform);
				m_segmentObjects.Add(item);
			}
			while (m_segmentObjects.Count > num2)
			{
				GameObject val = m_segmentObjects[m_segmentObjects.Count - 1];
				Object.Destroy((Object)(object)val);
				m_segmentObjects.RemoveAt(m_segmentObjects.Count - 1);
			}
			for (int k = 0; k < m_segmentObjects.Count; k++)
			{
				GameObject val2 = m_segmentObjects[k];
				val2.SetActive(true);
				val2.transform.localPosition = new Vector3(0f, (0f - m_segmentHeight) * (float)(k + 1), 0f);
				val2.transform.localRotation = Quaternion.identity;
			}
		}
	}
	internal class RecoverRaftConsoleCommand : ConsoleCommand
	{
		public override string Name => "RaftRecover";

		public override string Help => "Attempts to recover unattached rafts.";

		public override void Run(string[] args)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: 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_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: 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_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			Collider[] array = Physics.OverlapSphere(((Component)GameCamera.instance).transform.position, 1000f);
			Dictionary<ZDOID, List<ZNetView>> dictionary = new Dictionary<ZDOID, List<ZNetView>>();
			ZLog.Log((object)$"Searching {((Component)GameCamera.instance).transform.position}");
			Collider[] array2 = array;
			foreach (Collider val in array2)
			{
				ZNetView component = ((Component)val).GetComponent<ZNetView>();
				if (!((Object)(object)component != (Object)null) || component.m_zdo == null || Object.op_Implicit((Object)(object)((Component)component).GetComponentInParent<MoveableBaseRootComponent>()))
				{
					continue;
				}
				ZDOID zDOID = component.m_zdo.GetZDOID(MoveableBaseRootComponent.MBParentHash);
				if (zDOID != ZDOID.None)
				{
					GameObject val2 = ZNetScene.instance.FindInstance(zDOID);
					if (!((Object)(object)val2 != (Object)null))
					{
						if (!dictionary.TryGetValue(zDOID, out var value))
						{
							value = new List<ZNetView>();
							dictionary.Add(zDOID, value);
						}
						value.Add(component);
					}
				}
				else
				{
					Vector3 vec = component.m_zdo.GetVec3(MoveableBaseRootComponent.MBPositionHash, Vector3.zero);
				}
			}
			ZLog.Log((object)$"Found {dictionary.Count} potential ships to recover.");
			if (args.Length != 0 && args[0] == "confirm")
			{
				foreach (ZDOID key in dictionary.Keys)
				{
					List<ZNetView> list = dictionary[key];
					GameObject prefab = ZNetScene.instance.GetPrefab("MBRaft");
					GameObject val3 = Object.Instantiate<GameObject>(prefab, ((Component)list[0]).transform.position, ((Component)list[0]).transform.rotation);
					MoveableBaseShipComponent component2 = val3.GetComponent<MoveableBaseShipComponent>();
					foreach (ZNetView item in list)
					{
						((Component)item).transform.SetParent(((Component)component2.m_baseRoot).transform);
						((Component)item).transform.localPosition = item.m_zdo.GetVec3(MoveableBaseRootComponent.MBPositionHash, Vector3.zero);
						((Component)item).transform.localRotation = item.m_zdo.GetQuaternion(MoveableBaseRootComponent.MBRotationHash, Quaternion.identity);
						component2.m_baseRoot.AddNewPiece(item);
					}
				}
				return;
			}
			if (dictionary.Count > 0)
			{
				ZLog.Log((object)"Use \"RaftRecover confirm\" to complete the recover.");
			}
		}
	}
	public class RopeAnchorComponent : MonoBehaviour, Interactable, Hoverable
	{
		private class Rope
		{
			internal GameObject m_ropeTarget;

			internal RopeAttachmentTarget m_ropeAnchorTarget;

			internal GameObject m_ropeObject;

			internal LineRenderer m_rope;

			internal BoxCollider m_collider;

			internal float m_ropeAttachDistance;

			internal RopeComponent m_ropeComponent;

			internal Transform m_targetTransform;
		}

		private struct RopeAttachmentTarget
		{
			public int Id { get; }

			public byte Index { get; }

			public RopeAttachmentTarget(int id, byte index)
			{
				this = default(RopeAttachmentTarget);
				Id = id;
				Index = index;
			}

			public override int GetHashCode()
			{
				return (Id << 1) & Index;
			}

			public override bool Equals(object obj)
			{
				return obj is RopeAttachmentTarget ropeAttachmentTarget && ropeAttachmentTarget.Index == Index && ropeAttachmentTarget.Id == Id;
			}

			public static bool operator ==(RopeAttachmentTarget a, RopeAttachmentTarget b)
			{
				return a.Index == b.Index && a.Id == b.Id;
			}

			public static bool operator !=(RopeAttachmentTarget a, RopeAttachmentTarget b)
			{
				return a.Index != b.Index || a.Id != b.Id;
			}
		}

		public float m_maxRopeDistance = 64f;

		internal LineRenderer m_rope;

		internal ZNetView m_nview;

		internal Rigidbody m_rigidbody;

		public static RopeAnchorComponent m_draggingRopeFrom;

		private List<Rope> m_ropes = new List<Rope>();

		private List<Rope> m_updatingRopes = new List<Rope>();

		private uint m_zdoDataRevision;

		private float m_lastRopeCheckTime;

		internal static GameObject m_draggingRopeTo;

		private static readonly Dictionary<string, string[]> m_attachmentPoints = GetAttachmentPoints();

		public void Awake()
		{
			m_rigidbody = ((Component)this).GetComponentInParent<Rigidbody>();
			m_rope = ((Component)this).GetComponent<LineRenderer>();
			m_nview = ((Component)this).GetComponent<ZNetView>();
			WearNTear component = ((Component)this).GetComponent<WearNTear>();
			component.m_onDestroyed = (Action)Delegate.Combine(component.m_onDestroyed, new Action(DestroyAllRopes));
			LoadFromZDO();
		}

		private void DestroyAllRopes()
		{
			while (m_ropes.Count > 0)
			{
				RemoveRopeAt(0);
			}
		}

		public string GetHoverName()
		{
			return "";
		}

		public string GetHoverText()
		{
			if ((Object)(object)m_draggingRopeTo != (Object)(object)this)
			{
				return Localization.instance.Localize("[<color=yellow><b>$KEY_Use</b></color>] $mb_rope_anchor_attach_to");
			}
			return Localization.instance.Localize("[<color=yellow><b>$KEY_Use</b></color>] $mb_rope_anchor_attach");
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			if (!Object.op_Implicit((Object)(object)m_draggingRopeFrom))
			{
				m_draggingRopeFrom = this;
				((Renderer)m_rope).enabled = true;
			}
			else if ((Object)(object)m_draggingRopeFrom == (Object)(object)this)
			{
				if ((Object)(object)m_draggingRopeTo != (Object)(object)this)
				{
					AttachRope(m_draggingRopeTo, GetIndexAtLocation(m_draggingRopeTo));
				}
				m_draggingRopeFrom = null;
				((Renderer)m_rope).enabled = false;
			}
			else
			{
				m_draggingRopeFrom.AttachRope(this);
				((Renderer)m_draggingRopeFrom.m_rope).enabled = false;
				m_draggingRopeFrom = null;
				((Renderer)m_rope).enabled = false;
			}
			return true;
		}

		private static Dictionary<string, string[]> GetAttachmentPoints()
		{
			Dictionary<string, string[]> dictionary = new Dictionary<string, string[]>();
			dictionary.Add("Karve(Clone)", new string[5] { "ship/ropes/mastrope", "ship/ropes/RopeAttachLeft_bottom_front", "ship/ropes/RopeAttachLeft_bottom_back", "ship/ropes/RopeAttachRight_bottom_front (1)", "ship/ropes/RopeAttachRight_bottom_back (1)" });
			dictionary.Add("VikingShip(Clone)", new string[8] { "interactive/front", "interactive/mast", "interactive/ladder_right", "interactive/ladder_left", "ship/visual/ropes/RopeAttachLeft_bottom_front", "ship/visual/ropes/RopeAttachLeft_bottom_back", "ship/visual/ropes/RopeAttachRight_bottom_front (1)", "ship/visual/ropes/RopeAttachRight_bottom_back (1)" });
			dictionary.Add("Deer(Clone)", new string[1] { "Visual/CG/Pelvis/Spine/Spine1/Spine2/Neck" });
			dictionary.Add("Boar(Clone)", new string[1] { "Visual/CG/Pelvis/Spine/Spine1/Spine2/Neck" });
			dictionary.Add("Boar_piggy(Clone)", new string[1] { "Visual/CG/Pelvis/Spine/Spine1/Spine2/Neck" });
			dictionary.Add("Neck(Clone)", new string[1] { "Visual/Armature/Hips/Spine/Spine1/Neck" });
			return dictionary;
		}

		private Transform GetAttachmentTransform(GameObject go, RopeAttachmentTarget target)
		{
			if (m_attachmentPoints.TryGetValue(((Object)go).name, out var value) && target.Index >= 0 && value.Length > target.Index)
			{
				Transform val = go.transform.Find(value[target.Index]);
				if (Object.op_Implicit((Object)(object)val))
				{
					return val;
				}
			}
			return go.transform;
		}

		private byte GetIndexAtLocation(GameObject go)
		{
			//IL_0048: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			ZNetView componentInParent = go.GetComponentInParent<ZNetView>();
			if (!Object.op_Implicit((Object)(object)componentInParent))
			{
				return 0;
			}
			if (m_attachmentPoints.TryGetValue(((Object)((Component)componentInParent).gameObject).name, out var value))
			{
				Vector3 position = ((Component)Player.m_localPlayer).transform.position;
				byte result = 0;
				float num = float.MaxValue;
				for (int i = 0; i < value.Length; i++)
				{
					string text = value[i];
					Transform val = ((Component)componentInParent).transform.Find(text);
					if (Object.op_Implicit((Object)(object)val))
					{
						Vector3 val2 = position - val.position;
						float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
						if (sqrMagnitude < num)
						{
							result = (byte)i;
							num = sqrMagnitude;
						}
					}
				}
				return result;
			}
			return 0;
		}

		private void AttachRope(GameObject gameObject, byte index)
		{
			ZNetView componentInParent = gameObject.GetComponentInParent<ZNetView>();
			if (Object.op_Implicit((Object)(object)componentInParent) && componentInParent.m_zdo != null)
			{
				ZLog.Log((object)$"AttachRope {index}");
				RopeAttachmentTarget target = new RopeAttachmentTarget(ZDOPersistantID.Instance.GetOrCreatePersistantID(componentInParent.m_zdo), index);
				if (!RemoveRopeWithID(target))
				{
					CreateNewRope(target);
					SaveToZDO();
					CheckRopes();
				}
			}
		}

		private void