Decompiled source of Valmod Man O War v3.0.24

plugins/RoyalFleet/RoyalFleet.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Rendering;
using ValheimVehicles.Components;
using ValheimVehicles.Controllers;
using ValheimVehicles.Propulsion.Rudder;
using ValheimVehicles.SharedScripts;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
[BepInPlugin("local.valheim.royalfleet", "Royal Fleet", "3.0.24")]
[BepInDependency("zolantris.ValheimRAFT", "5.1.3")]
public sealed class RoyalFleet : BaseUnityPlugin
{
	private sealed class AssetParts
	{
		public ValmodCollisionLayout CollisionLayout;

		public Mesh[] Meshes;

		public Material[] Materials;

		public int[] MaterialIndices;
	}

	private struct PlacementReachState
	{
		public bool Active;

		public float Original;
	}

	private struct ShipLadderState
	{
		public bool Active;

		public Vector3 Before;
	}

	private struct RaftTurnState
	{
		public bool Active;

		public float Rudder;

		public float Acceleration;
	}

	internal const string RaftName = "ValheimVehicles_WaterVehicleShip_Valmod";

	internal const string RaftHullName = "ValmodRAFTHull";

	private static RoyalFleet plugin;

	private static GameObject storage;

	private static Transform cameraShip;

	private static float orbitYaw;

	private static float orbitPitch;

	private static float previousLookYaw;

	private static float previousLookPitch;

	private static AssetParts cachedValmodAsset;

	private static ConfigEntry<float> shipBuildDistance;

	private static readonly FieldInfo PlacementDistanceField = AccessTools.Field(typeof(Player), "m_maxPlaceDistance");

	private ConfigEntry<bool> krakenWarnings;

	private ConfigEntry<float> krakenWarningRange;

	private float nextKrakenScan;

	private float nextKrakenNotice;

	private bool krakenWasNear;

	private static readonly FieldInfo FallAltitude = AccessTools.Field(typeof(Character), "m_maxAirAltitude");

	private static readonly FieldInfo FallTimer = AccessTools.Field(typeof(Character), "m_fallTimer");

	internal static readonly string RaftMastName = PrefabNames.Tier4RaftMastName + "_Valmod";

	internal static readonly int RaftHullHash = StringExtensionMethods.GetStableHashCode("ValmodRAFTHull");

	private static readonly Dictionary<string, Mesh> renderBatchMeshes = new Dictionary<string, Mesh>();

	private static readonly RaycastHit[] shelterHits = (RaycastHit[])(object)new RaycastHit[64];

	private static int shelterMask;

	private static float nextRainCheck;

	private static GameObject[] hiddenRainRoots;

	private static ParticleSystem[] hiddenRainSystems;

	private static readonly MethodInfo setWeatherParticles = AccessTools.Method(typeof(EnvMan), "SetParticleArrayEnabled", (Type[])null, (Type[])null);

	private void Awake()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Expected O, but got Unknown
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Expected O, but got Unknown
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Expected O, but got Unknown
		//IL_0109: Expected O, but got Unknown
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Expected O, but got Unknown
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Expected O, but got Unknown
		//IL_019b: Expected O, but got Unknown
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Expected O, but got Unknown
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Expected O, but got Unknown
		//IL_022d: Expected O, but got Unknown
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Expected O, but got Unknown
		//IL_0298: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Expected O, but got Unknown
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e1: Expected O, but got Unknown
		//IL_0310: Unknown result type (might be due to invalid IL or missing references)
		//IL_031d: Expected O, but got Unknown
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0359: Expected O, but got Unknown
		//IL_0388: Unknown result type (might be due to invalid IL or missing references)
		//IL_0395: Expected O, but got Unknown
		//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03eb: Expected O, but got Unknown
		//IL_03eb: Expected O, but got Unknown
		//IL_041a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0427: Expected O, but got Unknown
		//IL_0456: Unknown result type (might be due to invalid IL or missing references)
		//IL_0463: Expected O, but got Unknown
		//IL_047a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0480: Expected O, but got Unknown
		plugin = this;
		ConfigureKrakenWarnings();
		ConfigureShipBuildRange();
		Harmony val = new Harmony("local.valheim.royalfleet");
		val.Patch((MethodBase)AccessTools.Method(typeof(EnvMan), "SetEnv", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "UpdateValmodRain", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(Cover), "GetCoverForPoint", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "RecognizeValmodShelter", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo = AccessTools.Method(typeof(Player), "PieceRayTest", (Type[])null, (Type[])null);
		HarmonyMethod val2 = new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "BeforeValmodPlacementRay", (Type[])null, (Type[])null));
		HarmonyMethod val3 = new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "AfterValmodPlacementRay", (Type[])null, (Type[])null));
		val.Patch((MethodBase)methodInfo, val2, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "ExtendValmodPlacementRay", (Type[])null, (Type[])null)), val3, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(Player), "UpdatePlacementGhost", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "ExtendValmodPlacementRay", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(Ladder), "Interact", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "BeforeShipLadder", (Type[])null, (Type[])null)), new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "AfterShipLadder", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(ConvexHullAPI), "GenerateConvexHullMesh", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "LimitValmodNetworkHull", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(VehiclePiecesController), "SaveConvexHullColliderZdoData", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "BeforeValmodHullSave", (Type[])null, (Type[])null)), new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "AfterValmodHullSave", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(Player), "PieceRayTest", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "DeckRay", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(Piece), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "BuildingAwake", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(Piece), "SetCreator", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "BuildingPlaced", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(Player), "UpdatePlacementGhost", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "DeckPlacement", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(GameCamera), "UpdateCamera", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "DrivingCamera", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(VehiclePiecesController), "ComputePieceWeight", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "RaftHullWeight", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(VehicleMovementController), "ApplyRudderRotationForce", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "TuneRaftTurn", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "RestoreRaftTurn", (Type[])null, (Type[])null)), (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(VehicleMovementController), "UpdateWaterStats", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "TuneRaftWaterSteering", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.Patch((MethodBase)AccessTools.Method(typeof(VehicleMovementController), "UpdateShipWheelTurningSpeed", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "TuneRaftWheel", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		HarmonyMethod val4 = new HarmonyMethod(AccessTools.Method(typeof(RoyalFleet), "RegisterShip", (Type[])null, (Type[])null));
		val4.priority = 0;
		val4.after = new string[1] { "marlthon.OdinShip" };
		val.Patch((MethodBase)AccessTools.Method(typeof(ZNetScene), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, val4, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	private static void BuildingAwake(Piece __instance)
	{
		((Component)__instance).gameObject.AddComponent<OdinDeckAttachment>();
	}

	private static void BuildingPlaced(Piece __instance)
	{
		OdinDeckAttachment component = ((Component)__instance).GetComponent<OdinDeckAttachment>();
		if (Object.op_Implicit((Object)(object)component))
		{
			component.Attach();
		}
	}

	private static void DeckRay(Player __instance, ref bool __result, ref Vector3 __0, ref Vector3 __1, ref Piece __2, ref Heightmap __3, ref Collider __4, int ___m_placeRayMask, float ___m_maxPlaceDistance)
	{
		//IL_0028: 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_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_0095: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		if (__result || !Object.op_Implicit((Object)(object)GameCamera.instance))
		{
			return;
		}
		Transform transform = ((Component)GameCamera.instance).transform;
		RaycastHit val = default(RaycastHit);
		if (Physics.Raycast(transform.position, transform.forward, ref val, 50f, ___m_placeRayMask, (QueryTriggerInteraction)1))
		{
			Ship componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Ship>();
			if (Object.op_Implicit((Object)(object)componentInParent) && ((Object)componentInParent).name.StartsWith("ValmodShip", StringComparison.Ordinal) && !(Vector3.Distance(((Component)__instance).transform.position + Vector3.up * 1.6f, ((RaycastHit)(ref val)).point) > ___m_maxPlaceDistance))
			{
				__0 = ((RaycastHit)(ref val)).point;
				__1 = ((RaycastHit)(ref val)).normal;
				__2 = ((Component)componentInParent).GetComponent<Piece>();
				__3 = null;
				__4 = null;
				__result = true;
			}
		}
	}

	private static void DeckPlacement(Player __instance, GameObject ___m_placementGhost)
	{
		//IL_0085: 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_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)___m_placementGhost) || !___m_placementGhost.activeSelf || !Object.op_Implicit((Object)(object)GameCamera.instance))
		{
			return;
		}
		FieldInfo fieldInfo = AccessTools.Field(typeof(Player), "m_placementStatus");
		if (Convert.ToInt32(fieldInfo.GetValue(__instance)) != 1)
		{
			return;
		}
		Transform transform = ((Component)GameCamera.instance).transform;
		int num = (int)AccessTools.Field(typeof(Player), "m_placeRayMask").GetValue(__instance);
		RaycastHit val = default(RaycastHit);
		if (!Physics.Raycast(transform.position, transform.forward, ref val, 50f, num, (QueryTriggerInteraction)1))
		{
			return;
		}
		Ship componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Ship>();
		if (Object.op_Implicit((Object)(object)componentInParent) && ((Object)componentInParent).name.StartsWith("ValmodShip", StringComparison.Ordinal))
		{
			float num2 = (float)AccessTools.Field(typeof(Player), "m_maxPlaceDistance").GetValue(__instance);
			if (!(Vector3.Distance(((Component)__instance).transform.position + Vector3.up * 1.6f, ((RaycastHit)(ref val)).point) > num2))
			{
				fieldInfo.SetValue(__instance, Enum.ToObject(fieldInfo.FieldType, 0));
				AccessTools.Method(typeof(Player), "SetPlacementGhostValid", (Type[])null, (Type[])null).Invoke(__instance, new object[1] { true });
			}
		}
	}

	private static void DrivingCamera(GameCamera __instance)
	{
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: 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_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		Ship val = (Object.op_Implicit((Object)(object)localPlayer) ? localPlayer.GetControlledShip() : null);
		Transform val2 = ((Object.op_Implicit((Object)(object)val) && ((Object)val).name.StartsWith("ValmodShip", StringComparison.Ordinal)) ? ((Component)val).transform : null);
		SteeringWheelComponent val3 = (SteeringWheelComponent)(Object.op_Implicit((Object)(object)localPlayer) ? /*isinst with value type is only supported in some contexts*/: null);
		if (!Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)val3.Controls) && Object.op_Implicit((Object)(object)val3.Controls.Manager) && ((Object)val3.Controls.Manager).name.StartsWith("ValheimVehicles_WaterVehicleShip_Valmod", StringComparison.Ordinal))
		{
			val2 = ((Component)val3.Controls).transform;
		}
		if (!Object.op_Implicit((Object)(object)val2))
		{
			cameraShip = null;
			return;
		}
		Vector3 lookDir = ((Character)localPlayer).GetLookDir();
		Vector3 normalized = ((Vector3)(ref lookDir)).normalized;
		float num = Mathf.Atan2(normalized.x, normalized.z) * 57.29578f;
		float num2 = (0f - Mathf.Asin(Mathf.Clamp(normalized.y, -1f, 1f))) * 57.29578f;
		if ((Object)(object)cameraShip != (Object)(object)val2)
		{
			orbitYaw = val2.eulerAngles.y;
			orbitPitch = 65f;
			previousLookYaw = num;
			previousLookPitch = num2;
		}
		orbitYaw += Mathf.DeltaAngle(previousLookYaw, num);
		orbitPitch = Mathf.Clamp(orbitPitch + Mathf.DeltaAngle(previousLookPitch, num2), 15f, 85f);
		previousLookYaw = num;
		previousLookPitch = num2;
		Vector3 val4 = val2.TransformPoint(new Vector3(0f, 6f, 0f));
		Quaternion val5 = Quaternion.Euler(orbitPitch, orbitYaw, 0f);
		((Component)__instance).transform.SetPositionAndRotation(val4 - val5 * Vector3.forward * 32f, val5);
		cameraShip = val2;
	}

	private static void RegisterShip(ZNetScene __instance)
	{
		Register(__instance, "ValmodShip", "Valmod", 8.56f, 75.5f);
		RegisterRaft(__instance);
	}

	private static void Register(ZNetScene __instance, string PrefabName, string title, float deckHeight, float length)
	{
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Expected O, but got Unknown
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0318: Unknown result type (might be due to invalid IL or missing references)
		//IL_0325: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_065f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0669: Unknown result type (might be due to invalid IL or missing references)
		//IL_0694: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_070a: Unknown result type (might be due to invalid IL or missing references)
		//IL_070b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0715: Unknown result type (might be due to invalid IL or missing references)
		//IL_071a: Unknown result type (might be due to invalid IL or missing references)
		//IL_071f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0724: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f5: Expected O, but got Unknown
		//IL_076b: Unknown result type (might be due to invalid IL or missing references)
		//IL_076c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0776: Unknown result type (might be due to invalid IL or missing references)
		//IL_077b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0780: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_07cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_07d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_07d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_07de: Unknown result type (might be due to invalid IL or missing references)
		//IL_07e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0864: Unknown result type (might be due to invalid IL or missing references)
		//IL_0869: Unknown result type (might be due to invalid IL or missing references)
		//IL_086d: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_08c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_08c7: Expected O, but got Unknown
		//IL_0910: Unknown result type (might be due to invalid IL or missing references)
		//IL_0931: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(0f, deckHeight + 0.75f, -17.328f);
		if (__instance.m_prefabs.Any((GameObject p) => Object.op_Implicit((Object)(object)p) && ((Object)p).name == PrefabName))
		{
			return;
		}
		GameObject prefab = __instance.GetPrefab("VikingShip_Ashlands");
		if (!Object.op_Implicit((Object)(object)prefab))
		{
			((BaseUnityPlugin)plugin).Logger.LogError((object)"Vanilla Drakkar prefab is unavailable. Valmod registration deferred.");
			return;
		}
		GameObject val2 = null;
		try
		{
			if (!Object.op_Implicit((Object)(object)storage))
			{
				storage = new GameObject("Ship of the Line Prefab Storage");
				storage.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)storage);
			}
			Transform val3 = storage.transform.Find(PrefabName);
			if (Object.op_Implicit((Object)(object)val3))
			{
				__instance.m_prefabs.Add(((Component)val3).gameObject);
				Dictionary<int, GameObject> dictionary = (Dictionary<int, GameObject>)AccessTools.Field(typeof(ZNetScene), "m_namedPrefabs").GetValue(__instance);
				dictionary[StringExtensionMethods.GetStableHashCode(PrefabName)] = ((Component)val3).gameObject;
				return;
			}
			Rigidbody component = prefab.GetComponent<Rigidbody>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				throw new InvalidOperationException("Drakkar Rigidbody is unavailable.");
			}
			Vector3 centerOfMass = component.centerOfMass;
			Vector3 inertiaTensor = component.inertiaTensor;
			Quaternion inertiaTensorRotation = component.inertiaTensorRotation;
			AssetParts assetParts = LoadAsset(prefab, PrefabName);
			val2 = Object.Instantiate<GameObject>(prefab, storage.transform, false);
			((Object)val2).name = PrefabName;
			Ship component2 = val2.GetComponent<Ship>();
			ShipControlls componentInChildren = ((Component)component2).GetComponentInChildren<ShipControlls>(true);
			if (!Object.op_Implicit((Object)(object)componentInChildren) || (Object)(object)((Component)componentInChildren).transform == (Object)(object)((Component)component2).transform || !Object.op_Implicit((Object)(object)component2.m_floatCollider))
			{
				throw new InvalidOperationException("Unexpected longship hierarchy.");
			}
			Renderer[] componentsInChildren = val2.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val4 in componentsInChildren)
			{
				if (val4 is MeshRenderer || val4 is SkinnedMeshRenderer)
				{
					val4.enabled = false;
				}
			}
			int layer = val2.layer;
			Collider[] componentsInChildren2 = val2.GetComponentsInChildren<Collider>(true);
			foreach (Collider val5 in componentsInChildren2)
			{
				if (!((Object)(object)val5 == (Object)(object)component2.m_floatCollider) && !((Component)val5).transform.IsChildOf(((Component)componentInChildren).transform) && !val5.isTrigger && val5.enabled)
				{
					val5.enabled = false;
				}
			}
			layer = LayerMask.NameToLayer("piece");
			if (layer < 0)
			{
				layer = val2.layer;
			}
			Transform transform = new GameObject(title).transform;
			transform.SetParent(((Component)component2).transform, false);
			transform.localScale = Vector3.one;
			transform.localPosition = Vector3.up * 0.75f;
			((Component)transform).gameObject.AddComponent<ValmodClimbRoutes>();
			bool flag = assetParts.CollisionLayout != null || assetParts.Meshes.Any((Mesh mesh) => ((Object)mesh).name.Contains("COLLISION_"));
			if (assetParts.CollisionLayout != null)
			{
				assetParts.CollisionLayout.Create(transform, layer);
			}
			for (int num2 = 0; num2 < assetParts.Meshes.Length; num2++)
			{
				if (assetParts.CollisionLayout != null && ((Object)assetParts.Meshes[num2]).name.Contains("COLLISION_"))
				{
					continue;
				}
				GameObject val6 = new GameObject(((Object)assetParts.Meshes[num2]).name);
				val6.transform.SetParent(transform, false);
				if (((Object)val6).name.Contains("COLLISION_"))
				{
					val6.layer = layer;
					MeshCollider val7 = val6.AddComponent<MeshCollider>();
					val7.convex = true;
					val7.sharedMesh = assetParts.Meshes[num2];
					continue;
				}
				if (!flag && (((Object)val6).name.StartsWith("deck_02") || ((Object)val6).name.StartsWith("rail_wood") || ((Object)val6).name.StartsWith("board_wood_s") || ((Object)val6).name.StartsWith("masts_constructor") || ((Object)val6).name.StartsWith("_model_")))
				{
					AddDeckFaces(val6.transform, assetParts.Meshes[num2], layer);
				}
				else if (!flag && (((Object)val6).name.StartsWith("bort_coper") || ((Object)val6).name.StartsWith("z_bort_") || ((Object)val6).name.StartsWith("bort_inside") || ((Object)val6).name.StartsWith("bort_inner_sm") || ((Object)val6).name.StartsWith("board_wood_s") || (PrefabName == "HMSAgamemnon" && ((Object)val6).name.StartsWith("bort_inner_sm"))))
				{
					FitCollision(val6.transform, assetParts.Meshes[num2], layer);
				}
				val6.AddComponent<MeshFilter>().sharedMesh = assetParts.Meshes[num2];
				MeshRenderer val8 = val6.AddComponent<MeshRenderer>();
				((Renderer)val8).sharedMaterial = assetParts.Materials[assetParts.MaterialIndices[num2]];
				if (((Object)val6).name.StartsWith("rope") || ((Object)val6).name.StartsWith("net_"))
				{
					((Renderer)val8).shadowCastingMode = (ShadowCastingMode)0;
				}
			}
			Rigidbody component3 = val2.GetComponent<Rigidbody>();
			component3.mass = component.mass * 2f;
			component2.m_force *= 2f;
			component3.centerOfMass = centerOfMass;
			component3.inertiaTensorRotation = inertiaTensorRotation;
			component3.inertiaTensor = new Vector3(inertiaTensor.x * 2f, inertiaTensor.y, inertiaTensor.z * 2f);
			component3.angularDamping = component.angularDamping;
			component3.linearDamping = component.linearDamping;
			component3.maxAngularVelocity = component.maxAngularVelocity;
			component3.constraints = component.constraints;
			BatchStaticVisuals(transform);
			((Component)transform).gameObject.AddComponent<ValmodSailVisibility>();
			((Component)componentInChildren).transform.localPosition = ((Component)componentInChildren).transform.parent.InverseTransformPoint(((Component)component2).transform.TransformPoint(val + Vector3.up * 0.9f));
			if (Object.op_Implicit((Object)(object)componentInChildren.m_attachPoint) && (Object)(object)componentInChildren.m_attachPoint != (Object)(object)((Component)componentInChildren).transform)
			{
				componentInChildren.m_attachPoint.position = ((Component)component2).transform.TransformPoint(val + Vector3.back * 0.65f);
			}
			if (Object.op_Implicit((Object)(object)component2.m_controlGuiPos) && !component2.m_controlGuiPos.IsChildOf(((Component)componentInChildren).transform))
			{
				component2.m_controlGuiPos.position = ((Component)component2).transform.TransformPoint(val + Vector3.up * 0.9f + Vector3.up);
			}
			component2.m_shipControlls = componentInChildren;
			componentInChildren.m_ship = component2;
			componentInChildren.m_maxUseRange = 10f;
			componentInChildren.m_hoverText = "Valmod helm";
			BoxCollider val9 = ((Component)componentInChildren).GetComponent<BoxCollider>();
			if (!Object.op_Implicit((Object)(object)val9))
			{
				val9 = ((Component)componentInChildren).gameObject.AddComponent<BoxCollider>();
			}
			((Collider)val9).enabled = true;
			((Collider)val9).isTrigger = false;
			((Component)componentInChildren).gameObject.layer = layer;
			Vector3 lossyScale = ((Component)componentInChildren).transform.lossyScale;
			val9.center = Vector3.zero;
			val9.size = new Vector3(3f / Mathf.Abs(lossyScale.x), 3f / Mathf.Abs(lossyScale.y), 2f / Mathf.Abs(lossyScale.z));
			GameObject val10 = new GameObject("Deck occupancy");
			val10.layer = val2.layer;
			val10.transform.SetParent(transform, false);
			BoxCollider val11 = val10.AddComponent<BoxCollider>();
			((Collider)val11).isTrigger = true;
			val11.center = new Vector3(0f, deckHeight * 0.5f + 1f, 0f);
			val11.size = new Vector3(22f, deckHeight + 8f, length + 8f);
			Piece component4 = val2.GetComponent<Piece>();
			if (Object.op_Implicit((Object)(object)component4))
			{
				component4.m_name = title;
				component4.m_description = "A square-rigged sailing ship of the Royal Navy.";
			}
			component2.m_waterImpactDamage = 0f;
			component2.m_upsideDownDmg = 0f;
			WearNTear component5 = val2.GetComponent<WearNTear>();
			if (Object.op_Implicit((Object)(object)component5))
			{
				component5.m_health = 3000f;
				component5.m_supports = true;
				component5.m_noSupportWear = true;
				component5.m_noRoofWear = true;
				component5.m_burnable = false;
			}
			__instance.m_prefabs.Add(val2);
			Dictionary<int, GameObject> dictionary2 = (Dictionary<int, GameObject>)AccessTools.Field(typeof(ZNetScene), "m_namedPrefabs").GetValue(__instance);
			dictionary2[StringExtensionMethods.GetStableHashCode(PrefabName)] = val2;
			((BaseUnityPlugin)plugin).Logger.LogInfo((object)("Registered " + PrefabName + ((assetParts.CollisionLayout != null) ? (" with " + assetParts.CollisionLayout.Shapes.Length + " offline collision shapes; vanilla Drakkar handling.") : ".")));
		}
		catch (Exception ex)
		{
			if (Object.op_Implicit((Object)(object)val2))
			{
				((Object)val2).name = "Failed ship prefab";
				Object.Destroy((Object)(object)val2);
			}
			((BaseUnityPlugin)plugin).Logger.LogError((object)ex);
		}
	}

	private static void AddDeckFaces(Transform parent, Mesh mesh, int layer)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//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_005c: 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_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: 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_00eb: Expected O, but got Unknown
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		Vector3[] vertices = mesh.vertices;
		int[] triangles = mesh.triangles;
		List<Vector3> list = new List<Vector3>();
		for (int i = 0; i < triangles.Length / 2; i += 3)
		{
			Vector3 val = vertices[triangles[i]];
			Vector3 val2 = vertices[triangles[i + 1]];
			Vector3 val3 = vertices[triangles[i + 2]];
			Vector3 val4 = Vector3.Cross(val2 - val, val3 - val);
			if (!(((Vector3)(ref val4)).sqrMagnitude < 1E-06f) && !(Mathf.Abs(((Vector3)(ref val4)).normalized.y) < 0.25f))
			{
				list.Add(val);
				list.Add(val2);
				list.Add(val3);
			}
		}
		if (list.Count != 0)
		{
			Mesh val5 = new Mesh();
			val5.indexFormat = (IndexFormat)1;
			Mesh val6 = val5;
			val6.SetVertices(list);
			val6.SetTriangles(Enumerable.Range(0, list.Count).ToArray(), 0);
			FitCollision(parent, val6, layer, doubleSided: false);
			Object.Destroy((Object)(object)val6);
		}
	}

	private static List<Vector3> Clip(List<Vector3> input, float z, bool keepAbove)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: 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_00cf: 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)
		List<Vector3> list = new List<Vector3>();
		if (input.Count == 0)
		{
			return list;
		}
		Vector3 val = input[input.Count - 1];
		foreach (Vector3 item in input)
		{
			bool flag = (keepAbove ? (item.z >= z) : (item.z <= z));
			bool flag2 = (keepAbove ? (val.z >= z) : (val.z <= z));
			if (flag != flag2)
			{
				list.Add(Vector3.Lerp(val, item, (z - val.z) / (item.z - val.z)));
			}
			if (flag)
			{
				list.Add(item);
			}
			val = item;
		}
		return list;
	}

	private static void FitCollision(Transform parent, Mesh original, int layer, bool doubleSided = true)
	{
		//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_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: 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_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: 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_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c8: Expected O, but got Unknown
		//IL_030e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0315: Expected O, but got Unknown
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: 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_01c5: 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_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: 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_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		Vector3[] vertices = original.vertices;
		int[] array = original.triangles.Take(doubleSided ? (original.triangles.Length / 2) : original.triangles.Length).ToArray();
		Dictionary<Vector3Int, List<Vector3>> dictionary = new Dictionary<Vector3Int, List<Vector3>>();
		Vector3Int key = default(Vector3Int);
		for (int i = 0; i < array.Length; i += 3)
		{
			Vector3 val = vertices[array[i]];
			Vector3 val2 = vertices[array[i + 1]];
			Vector3 val3 = vertices[array[i + 2]];
			Vector3 val4 = (val + val2 + val3) / 3f;
			int num = Mathf.FloorToInt(Mathf.Min(val.z, Mathf.Min(val2.z, val3.z)) / 3f);
			int num2 = Mathf.FloorToInt(Mathf.Max(val.z, Mathf.Max(val2.z, val3.z)) / 3f);
			for (int j = num; j <= num2; j++)
			{
				List<Vector3> list = new List<Vector3>();
				list.Add(val);
				list.Add(val2);
				list.Add(val3);
				List<Vector3> list2 = Clip(Clip(list, (float)j * 3f, keepAbove: true), (float)(j + 1) * 3f, keepAbove: false);
				((Vector3Int)(ref key))..ctor(j, Mathf.FloorToInt(val4.x / 3f), Mathf.FloorToInt(val4.y));
				if (!dictionary.TryGetValue(key, out var value))
				{
					value = (dictionary[key] = new List<Vector3>());
				}
				for (int k = 2; k < list2.Count; k++)
				{
					Vector3 val5 = list2[0];
					Vector3 val6 = list2[k - 1];
					Vector3 val7 = list2[k];
					Vector3 val8 = Vector3.Cross(val6 - val5, val7 - val5);
					if (!(((Vector3)(ref val8)).sqrMagnitude < 1E-12f))
					{
						value.Add(val5);
						value.Add(val6);
						value.Add(val7);
						Vector3 val9 = ((Vector3)(ref val8)).normalized * 0.012f;
						value.Add(val7 - val9);
						value.Add(val6 - val9);
						value.Add(val5 - val9);
					}
				}
			}
		}
		foreach (List<Vector3> value2 in dictionary.Values)
		{
			if (value2.Count >= 6)
			{
				Mesh val10 = new Mesh();
				((Object)val10).name = "Ship collision section";
				val10.indexFormat = (IndexFormat)1;
				Mesh val11 = val10;
				val11.SetVertices(value2);
				val11.SetTriangles(Enumerable.Range(0, value2.Count).ToArray(), 0);
				GameObject val12 = new GameObject(((Object)val11).name);
				val12.layer = layer;
				val12.transform.SetParent(parent, false);
				MeshCollider val13 = val12.AddComponent<MeshCollider>();
				val13.convex = true;
				val13.sharedMesh = val11;
			}
		}
	}

	private static AssetParts LoadAsset(GameObject longship, string prefabName)
	{
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Expected O, but got Unknown
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Expected O, but got Unknown
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0384: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fa: Expected O, but got Unknown
		if (prefabName == "ValmodShip" && cachedValmodAsset != null)
		{
			return cachedValmodAsset;
		}
		string directoryName = Path.GetDirectoryName(typeof(RoyalFleet).Assembly.Location);
		Shader[] source = (from material in longship.GetComponentsInChildren<MeshRenderer>(true).SelectMany((MeshRenderer renderer) => ((Renderer)renderer).sharedMaterials)
			where Object.op_Implicit((Object)(object)material) && Object.op_Implicit((Object)(object)material.shader) && material.HasProperty("_MainTex")
			select material.shader).ToArray();
		Shader val = ((IEnumerable<Shader>)source).FirstOrDefault((Func<Shader, bool>)((Shader candidate) => ((Object)candidate).name == "Standard")) ?? ((IEnumerable<Shader>)source).FirstOrDefault((Func<Shader, bool>)((Shader candidate) => ((Object)candidate).name == "Custom/Piece")) ?? source.FirstOrDefault();
		if (!Object.op_Implicit((Object)(object)val))
		{
			throw new InvalidOperationException("A ship material shader could not be found.");
		}
		AssetParts assetParts = new AssetParts();
		using (BinaryReader binaryReader = new BinaryReader(File.OpenRead(Path.Combine(directoryName, prefabName + ".bin"))))
		{
			Texture2D[] array = (Texture2D[])(object)new Texture2D[binaryReader.ReadInt32()];
			for (int num = 0; num < array.Length; num++)
			{
				Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, true);
				if (!ImageConversion.LoadImage(val2, binaryReader.ReadBytes(binaryReader.ReadInt32()), true))
				{
					throw new InvalidDataException("A Cordy ship texture could not be decoded.");
				}
				((Texture)val2).anisoLevel = 8;
				array[num] = val2;
			}
			assetParts.Materials = (Material[])(object)new Material[binaryReader.ReadInt32()];
			Color color = default(Color);
			for (int num = 0; num < assetParts.Materials.Length; num++)
			{
				int num2 = binaryReader.ReadInt32();
				Material val3 = new Material(val);
				((Color)(ref color))..ctor(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				val3.color = color;
				if (num2 >= 0)
				{
					val3.mainTexture = (Texture)(object)array[num2];
				}
				val3.SetFloat("_Glossiness", 0.13f);
				if (val3.HasProperty("_Metallic"))
				{
					val3.SetFloat("_Metallic", 0f);
				}
				if (val3.HasProperty("_Cull"))
				{
					val3.SetFloat("_Cull", 0f);
				}
				assetParts.Materials[num] = val3;
			}
			assetParts.Meshes = (Mesh[])(object)new Mesh[binaryReader.ReadInt32()];
			assetParts.MaterialIndices = new int[assetParts.Meshes.Length];
			for (int num = 0; num < assetParts.Meshes.Length; num++)
			{
				string text = Encoding.UTF8.GetString(binaryReader.ReadBytes(binaryReader.ReadInt32()));
				assetParts.MaterialIndices[num] = binaryReader.ReadInt32();
				int num3 = binaryReader.ReadInt32();
				Vector3[] array2 = (Vector3[])(object)new Vector3[num3];
				Vector3[] array3 = (Vector3[])(object)new Vector3[num3];
				Vector2[] array4 = (Vector2[])(object)new Vector2[num3];
				for (int num4 = 0; num4 < num3; num4++)
				{
					ref Vector3 reference = ref array2[num4];
					reference = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
					ref Vector3 reference2 = ref array3[num4];
					reference2 = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
					ref Vector2 reference3 = ref array4[num4];
					reference3 = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
				}
				int[] array5 = new int[binaryReader.ReadInt32()];
				for (int num5 = 0; num5 < array5.Length; num5++)
				{
					array5[num5] = binaryReader.ReadInt32();
				}
				Mesh val4 = new Mesh();
				((Object)val4).name = text;
				val4.indexFormat = (IndexFormat)(num3 > 65535);
				Mesh val5 = val4;
				val5.vertices = array2;
				val5.normals = array3;
				val5.uv = array4;
				if (text.Contains("COLLISION_"))
				{
					val5.triangles = array5;
					val5.UploadMeshData(false);
					assetParts.Meshes[num] = val5;
					continue;
				}
				int[] array6 = new int[array5.Length * 2];
				Array.Copy(array5, array6, array5.Length);
				for (int num6 = 0; num6 < array5.Length; num6 += 3)
				{
					array6[array5.Length + num6] = array5[num6];
					array6[array5.Length + num6 + 1] = array5[num6 + 2];
					array6[array5.Length + num6 + 2] = array5[num6 + 1];
				}
				val5.triangles = array6;
				val5.UploadMeshData(false);
				assetParts.Meshes[num] = val5;
			}
		}
		assetParts.CollisionLayout = ValmodCollisionLayout.Load(directoryName, Path.Combine(directoryName, prefabName + ".bin"));
		if (prefabName == "ValmodShip")
		{
			cachedValmodAsset = assetParts;
		}
		return assetParts;
	}

	private static void RegisterValmodBuildPiece(GameObject core, ZNetScene scene)
	{
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Expected O, but got Unknown
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Expected O, but got Unknown
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Expected O, but got Unknown
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Expected O, but got Unknown
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Expected O, but got Unknown
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Expected O, but got Unknown
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Expected O, but got Unknown
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Expected O, but got Unknown
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Expected O, but got Unknown
		if (PieceManager.Instance.GetPiece("ValheimVehicles_WaterVehicleShip_Valmod") == null)
		{
			Piece component = core.GetComponent<Piece>();
			component.m_waterPiece = true;
			component.m_groundPiece = false;
			component.m_groundOnly = false;
			component.m_noInWater = false;
			component.m_noClipping = true;
			component.m_canRotate = true;
			GameObject prefab = scene.GetPrefab("VikingShip_Ashlands");
			if (Object.op_Implicit((Object)(object)prefab) && Object.op_Implicit((Object)(object)prefab.GetComponent<Piece>()))
			{
				component.m_icon = prefab.GetComponent<Piece>().m_icon;
			}
			PieceConfig val = new PieceConfig();
			val.Name = "Valmod Man-o'-War";
			val.Description = "A large ship of the line. Launch in open water. Hull and sails included; place a steering wheel separately with the Vehicle Hammer.";
			val.PieceTable = "Hammer";
			val.Category = "Valmod";
			val.CraftingStation = "piece_workbench";
			val.Enabled = true;
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[7]
			{
				new RequirementConfig("Wood", 400, 0, true),
				new RequirementConfig("FineWood", 200, 0, true),
				new RequirementConfig("BronzeNails", 200, 0, true),
				new RequirementConfig("Bronze", 30, 0, true),
				new RequirementConfig("DeerHide", 100, 0, true),
				new RequirementConfig("LeatherScraps", 100, 0, true),
				new RequirementConfig("Tar", 40, 0, true)
			};
			PieceConfig val2 = val;
			if (PieceManager.Instance.AddPiece(new CustomPiece(core, false, val2)))
			{
				ReportRaft("Build recipe registered: Hammer > Valmod, workbench, Wood 400 / FineWood 200 / BronzeNails 200 / Bronze 30 / DeerHide 100 / LeatherScraps 100 / Tar 40.");
			}
			else
			{
				((BaseUnityPlugin)plugin).Logger.LogError((object)"Valmod build recipe could not be registered. The ship prefab remains available for saved worlds.");
			}
		}
	}

	private void ConfigureShipBuildRange()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		shipBuildDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Construction", "Ship placement distance", 80f, new ConfigDescription("Placement reach in metres, only while selecting Valmod Man-o'-War. Keep the builder near the required workbench.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 150f), new object[0]));
	}

	private static bool IsSelectingValmod(Player player)
	{
		Piece val = (Object.op_Implicit((Object)(object)player) ? player.GetSelectedPiece() : null);
		return Object.op_Implicit((Object)(object)val) && ((Object)val).name.StartsWith("ValheimVehicles_WaterVehicleShip_Valmod", StringComparison.Ordinal);
	}

	private static void BeforeValmodPlacementRay(Player __instance, ref float ___m_maxPlaceDistance, out PlacementReachState __state)
	{
		__state = default(PlacementReachState);
		if (IsSelectingValmod(__instance))
		{
			__state.Active = true;
			__state.Original = ___m_maxPlaceDistance;
			___m_maxPlaceDistance = Mathf.Max(___m_maxPlaceDistance, shipBuildDistance.Value);
		}
	}

	private static Exception AfterValmodPlacementRay(ref float ___m_maxPlaceDistance, PlacementReachState __state, Exception __exception)
	{
		if (__state.Active)
		{
			___m_maxPlaceDistance = __state.Original;
		}
		return __exception;
	}

	private static float ValmodPlacementRayDistance(Player player)
	{
		//IL_0050: 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 (!IsSelectingValmod(player))
		{
			return 50f;
		}
		float num = Mathf.Max(shipBuildDistance.Value, (float)PlacementDistanceField.GetValue(player));
		float num2 = (Object.op_Implicit((Object)(object)GameCamera.instance) ? Vector3.Distance(((Component)GameCamera.instance).transform.position, ((Component)player).transform.position) : 10f);
		return Mathf.Max(50f, num + num2 + 2f);
	}

	private static IEnumerable<CodeInstruction> ExtendValmodPlacementRay(IEnumerable<CodeInstruction> instructions)
	{
		foreach (CodeInstruction instruction in instructions)
		{
			if (instruction.opcode == OpCodes.Ldc_R4 && instruction.operand is float && (float)instruction.operand == 50f)
			{
				CodeInstruction loadPlayer = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
				loadPlayer.labels.AddRange(instruction.labels);
				loadPlayer.blocks.AddRange(instruction.blocks);
				yield return loadPlayer;
				yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(RoyalFleet), "ValmodPlacementRayDistance", (Type[])null, (Type[])null));
			}
			else
			{
				yield return instruction;
			}
		}
	}

	private void ConfigureKrakenWarnings()
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Expected O, but got Unknown
		krakenWarnings = ((BaseUnityPlugin)this).Config.Bind<bool>("Kraken warning", "Enabled", true, "Show a local warning for loaded living Kraken creatures while aboard Valmod. No creature mod is required.");
		krakenWarningRange = ((BaseUnityPlugin)this).Config.Bind<float>("Kraken warning", "Range", 250f, new ConfigDescription("Detection range in metres. Only loaded creatures can be detected.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(25f, 500f), new object[0]));
	}

	private static bool IsAboardValmod(Player player)
	{
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		IDoodadController doodadController = player.GetDoodadController();
		SteeringWheelComponent val = (SteeringWheelComponent)(object)((doodadController is SteeringWheelComponent) ? doodadController : null);
		if (Object.op_Implicit((Object)(object)val) && IsValmodRaft(val.Controls))
		{
			return true;
		}
		Ship controlledShip = player.GetControlledShip();
		if (Object.op_Implicit((Object)(object)controlledShip) && ((Object)controlledShip).name.StartsWith("ValmodShip", StringComparison.Ordinal))
		{
			return true;
		}
		RaycastHit val2 = default(RaycastHit);
		if (!Physics.Raycast(((Component)player).transform.position + Vector3.up * 0.5f, Vector3.down, ref val2, 3f, LayerMask.GetMask(new string[1] { "piece" }), (QueryTriggerInteraction)1))
		{
			return false;
		}
		if (Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<ValmodRaftVisuals>()))
		{
			return true;
		}
		controlledShip = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<Ship>();
		return Object.op_Implicit((Object)(object)controlledShip) && ((Object)controlledShip).name.StartsWith("ValmodShip", StringComparison.Ordinal);
	}

	private void Update()
	{
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		if (Time.unscaledTime < nextKrakenScan)
		{
			return;
		}
		nextKrakenScan = Time.unscaledTime + 3f;
		Player localPlayer = Player.m_localPlayer;
		if (!krakenWarnings.Value || !Object.op_Implicit((Object)(object)localPlayer) || ((Character)localPlayer).IsDead() || !IsAboardValmod(localPlayer))
		{
			krakenWasNear = false;
			return;
		}
		float num = krakenWarningRange.Value * krakenWarningRange.Value;
		bool flag = false;
		foreach (Character allCharacter in Character.GetAllCharacters())
		{
			if (Object.op_Implicit((Object)(object)allCharacter) && !(allCharacter is Player) && !allCharacter.IsDead() && ((Object)allCharacter).name.IndexOf("kraken", StringComparison.OrdinalIgnoreCase) >= 0 && ((Object)allCharacter).name.IndexOf("tentacle", StringComparison.OrdinalIgnoreCase) < 0)
			{
				Vector3 val = ((Component)allCharacter).transform.position - ((Component)localPlayer).transform.position;
				float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
				if (!(sqrMagnitude > num))
				{
					num = sqrMagnitude;
					flag = true;
				}
			}
		}
		if (flag && (!krakenWasNear || Time.unscaledTime >= nextKrakenNotice))
		{
			((Character)localPlayer).Message((MessageType)2, "Kraken nearby - " + Mathf.RoundToInt(Mathf.Sqrt(num)) + " m", 0, (Sprite)null, false);
			nextKrakenNotice = Time.unscaledTime + 30f;
		}
		krakenWasNear = flag;
	}

	private static void BeforeShipLadder(Ladder __instance, Humanoid __0, out ShipLadderState __state)
	{
		//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)
		__state = default(ShipLadderState);
		if (Object.op_Implicit((Object)(object)__0) && Object.op_Implicit((Object)(object)__instance) && Object.op_Implicit((Object)(object)__instance.m_targetPos) && Object.op_Implicit((Object)(object)((Component)__instance).GetComponentInParent<ValmodClimbRoutes>()))
		{
			__state.Active = true;
			__state.Before = ((Component)__0).transform.position;
		}
	}

	private static void AfterShipLadder(Ladder __instance, Humanoid __0, ShipLadderState __state)
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		if (!__state.Active || !Object.op_Implicit((Object)(object)__0) || !Object.op_Implicit((Object)(object)__instance) || !Object.op_Implicit((Object)(object)__instance.m_targetPos))
		{
			return;
		}
		Vector3 position = ((Component)__0).transform.position;
		Vector3 val = position - __state.Before;
		if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
		{
			return;
		}
		val = position - __instance.m_targetPos.position;
		if (!(((Vector3)(ref val)).sqrMagnitude > 0.01f))
		{
			FallAltitude.SetValue(__0, position.y);
			FallTimer.SetValue(__0, 0f);
			Rigidbody component = ((Component)__0).GetComponent<Rigidbody>();
			Collider component2 = ((Component)__instance).GetComponent<Collider>();
			Rigidbody val2 = (Object.op_Implicit((Object)(object)component2) ? component2.attachedRigidbody : null);
			if (Object.op_Implicit((Object)(object)component))
			{
				component.linearVelocity = ((Object.op_Implicit((Object)(object)val2) && (Object)(object)val2 != (Object)(object)component) ? val2.GetPointVelocity(position) : Vector3.zero);
			}
		}
	}

	private static bool IsValmodPieces(VehiclePiecesController pieces)
	{
		return Object.op_Implicit((Object)(object)pieces) && Object.op_Implicit((Object)(object)pieces.Manager) && ((Object)pieces.Manager).name.StartsWith("ValheimVehicles_WaterVehicleShip_Valmod", StringComparison.Ordinal);
	}

	private static void LimitValmodNetworkHull(ConvexHullAPI __instance, ref List<Vector3> __0)
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)__instance) || !IsValmodPieces(((Component)__instance).GetComponent<VehiclePiecesController>()) || __0 == null || __0.Count <= 96)
		{
			return;
		}
		HashSet<Vector3> hashSet = new HashSet<Vector3>();
		AddSupport(__0, Vector3.right, hashSet);
		AddSupport(__0, Vector3.left, hashSet);
		AddSupport(__0, Vector3.up, hashSet);
		AddSupport(__0, Vector3.down, hashSet);
		AddSupport(__0, Vector3.forward, hashSet);
		AddSupport(__0, Vector3.back, hashSet);
		for (int i = 0; i < 90; i++)
		{
			double num = 1.0 - 2.0 * ((double)i + 0.5) / 90.0;
			double num2 = Math.Sqrt(1.0 - num * num);
			double num3 = 2.3999632297286535 * (double)i;
			AddSupport(__0, new Vector3((float)(Math.Cos(num3) * num2), (float)num, (float)(Math.Sin(num3) * num2)), hashSet);
		}
		if (hashSet.Count < 4)
		{
			return;
		}
		int count = __0.Count;
		List<Vector3> list = new List<Vector3>(hashSet.Count);
		foreach (Vector3 item in __0)
		{
			if (hashSet.Remove(item))
			{
				list.Add(item);
			}
		}
		__0 = list;
		ReportRaft("Valmod RAFT hull reduced: " + count + " input points -> " + list.Count + " support points. Detailed walking collision is unchanged.");
	}

	private static void AddSupport(List<Vector3> points, Vector3 direction, HashSet<Vector3> output)
	{
		//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_0009: 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_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: 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_0037: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = points[0];
		float num = Vector3.Dot(val, direction);
		for (int i = 1; i < points.Count; i++)
		{
			float num2 = Vector3.Dot(points[i], direction);
			if (!(num2 <= num))
			{
				val = points[i];
				num = num2;
			}
		}
		output.Add(val);
	}

	private static void BeforeValmodHullSave(VehiclePiecesController __instance, out int __state)
	{
		__state = (IsValmodPieces(__instance) ? __instance.GetHullRevision() : (-1));
	}

	private static void AfterValmodHullSave(VehiclePiecesController __instance, int __state)
	{
		if (__state >= 0 && IsValmodPieces(__instance))
		{
			int hullRevision = __instance.GetHullRevision();
			if (hullRevision > __state)
			{
				ReportRaft("Valmod RAFT hull saved and sync requested successfully; revision " + hullRevision + ".");
			}
		}
	}

	private static void RaftHullWeight(Piece piece, ref float __result)
	{
		if (Object.op_Implicit((Object)(object)piece) && ((Object)piece).name.StartsWith("ValmodRAFTHull", StringComparison.Ordinal))
		{
			__result = 9000f;
		}
	}

	private static bool IsValmodRaft(VehicleMovementController controller)
	{
		return Object.op_Implicit((Object)(object)controller) && Object.op_Implicit((Object)(object)controller.Manager) && ((Object)controller.Manager).name.StartsWith("ValheimVehicles_WaterVehicleShip_Valmod", StringComparison.Ordinal);
	}

	private static void TuneRaftTurn(VehicleMovementController __instance, ref float ___m_rudderValue, ref float ___YawAccelPerError, out RaftTurnState __state)
	{
		__state = default(RaftTurnState);
		if (IsValmodRaft(__instance))
		{
			__state.Active = true;
			__state.Rudder = ___m_rudderValue;
			__state.Acceleration = ___YawAccelPerError;
			___m_rudderValue *= 0.05f;
			___YawAccelPerError *= 0.4f;
			if (Object.op_Implicit((Object)(object)((ValheimBaseGameShip)__instance).m_body))
			{
				((ValheimBaseGameShip)__instance).m_body.maxAngularVelocity = 0.12f;
			}
		}
	}

	private static Exception RestoreRaftTurn(ref float ___m_rudderValue, ref float ___YawAccelPerError, RaftTurnState __state, Exception __exception)
	{
		if (__state.Active)
		{
			___m_rudderValue = __state.Rudder;
			___YawAccelPerError = __state.Acceleration;
		}
		return __exception;
	}

	private static void TuneRaftWaterSteering(VehicleMovementController __instance)
	{
		if (IsValmodRaft(__instance))
		{
			((ValheimBaseGameShip)__instance).m_stearForce = ((ValheimBaseGameShip)__instance).m_stearForce * 0.35f;
		}
	}

	private static void TuneRaftWheel(VehicleMovementController __instance)
	{
		if (IsValmodRaft(__instance))
		{
			__instance.m_rudderSpeed *= 0.6f;
		}
	}

	private static void RegisterRaft(ZNetScene scene)
	{
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Expected O, but got Unknown
		if (Object.op_Implicit((Object)(object)scene.GetPrefab("ValheimVehicles_WaterVehicleShip_Valmod")))
		{
			return;
		}
		GameObject prefab = scene.GetPrefab(PrefabNames.WaterVehicleShip);
		GameObject prefab2 = scene.GetPrefab(PrefabNames.ShipHullCenterWoodPrefabName);
		GameObject prefab3 = scene.GetPrefab(PrefabNames.Tier4RaftMastName);
		if (!Object.op_Implicit((Object)(object)prefab) || !Object.op_Implicit((Object)(object)prefab2) || !Object.op_Implicit((Object)(object)prefab3))
		{
			((BaseUnityPlugin)plugin).Logger.LogError((object)"ValmodRAFT: native vehicle/hull prefabs were not registered.");
			return;
		}
		Dictionary<int, GameObject> names = (Dictionary<int, GameObject>)AccessTools.Field(typeof(ZNetScene), "m_namedPrefabs").GetValue(scene);
		Transform val = storage.transform.Find("ValheimVehicles_WaterVehicleShip_Valmod");
		Transform val2 = storage.transform.Find("ValmodRAFTHull");
		Transform val3 = storage.transform.Find(RaftMastName);
		if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val3))
		{
			RegisterValmodBuildPiece(((Component)val).gameObject, scene);
			AddRaftPrefab(scene, names, ((Component)val).gameObject);
			AddRaftPrefab(scene, names, ((Component)val2).gameObject);
			AddRaftPrefab(scene, names, ((Component)val3).gameObject);
			return;
		}
		GameObject val4 = null;
		GameObject val5 = null;
		GameObject val6 = null;
		try
		{
			AssetParts assetParts = LoadAsset(scene.GetPrefab("VikingShip_Ashlands"), "ValmodShip");
			val4 = Object.Instantiate<GameObject>(prefab2, storage.transform, false);
			((Object)val4).name = "ValmodRAFTHull";
			Collider[] componentsInChildren = val4.GetComponentsInChildren<Collider>(true);
			foreach (Collider val7 in componentsInChildren)
			{
				val7.enabled = false;
			}
			Renderer[] componentsInChildren2 = val4.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val8 in componentsInChildren2)
			{
				val8.enabled = false;
			}
			Transform transform = new GameObject("Valmod model").transform;
			transform.SetParent(val4.transform, false);
			transform.localPosition = Vector3.up * 0.75f;
			((Component)transform).gameObject.AddComponent<ValmodClimbRoutes>();
			int num = LayerMask.NameToLayer("piece");
			if (num < 0)
			{
				num = val4.layer;
			}
			if (assetParts.CollisionLayout == null)
			{
				throw new InvalidOperationException("Valmod optimized collision is required.");
			}
			assetParts.CollisionLayout.Create(transform, num);
			for (int j = 0; j < assetParts.Meshes.Length; j++)
			{
				GameObject val9 = new GameObject(((Object)assetParts.Meshes[j]).name);
				val9.transform.SetParent(transform, false);
				val9.AddComponent<MeshFilter>().sharedMesh = assetParts.Meshes[j];
				((Renderer)val9.AddComponent<MeshRenderer>()).sharedMaterial = assetParts.Materials[assetParts.MaterialIndices[j]];
			}
			BatchStaticVisuals(transform);
			((Component)transform).gameObject.AddComponent<ValmodRaftVisuals>();
			val4.GetComponent<Piece>().m_name = "Valmod hull";
			WearNTear component = val4.GetComponent<WearNTear>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.m_health = 3000f;
				component.m_noSupportWear = true;
				component.m_noRoofWear = true;
				component.m_supports = true;
			}
			val6 = Object.Instantiate<GameObject>(prefab3, storage.transform, false);
			((Object)val6).name = RaftMastName;
			val6.AddComponent<ValmodRaftMastProxy>();
			val5 = Object.Instantiate<GameObject>(prefab, storage.transform, false);
			((Object)val5).name = "ValheimVehicles_WaterVehicleShip_Valmod";
			val5.GetComponent<Piece>().m_name = "Valmod RAFT";
			val5.AddComponent<ValmodRaftSetup>();
			val5.AddComponent<ValmodBuildPreview>();
			RegisterValmodBuildPiece(val5, scene);
			AddRaftPrefab(scene, names, val4);
			AddRaftPrefab(scene, names, val6);
			AddRaftPrefab(scene, names, val5);
			((BaseUnityPlugin)plugin).Logger.LogInfo((object)"Registered ValmodRAFT using native vehicle, hull, steering and mast pieces.");
		}
		catch (Exception ex)
		{
			if (Object.op_Implicit((Object)(object)val5))
			{
				Object.Destroy((Object)(object)val5);
			}
			if (Object.op_Implicit((Object)(object)val6))
			{
				Object.Destroy((Object)(object)val6);
			}
			if (Object.op_Implicit((Object)(object)val4))
			{
				Object.Destroy((Object)(object)val4);
			}
			((BaseUnityPlugin)plugin).Logger.LogError((object)("ValmodRAFT registration failed: " + ex));
		}
	}

	private static void AddRaftPrefab(ZNetScene scene, Dictionary<int, GameObject> names, GameObject prefab)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		if (!Object.op_Implicit((Object)(object)PrefabManager.Instance.GetPrefab(((Object)prefab).name)))
		{
			PrefabManager.Instance.AddPrefab(new CustomPrefab(prefab, false));
		}
		if (!scene.m_prefabs.Contains(prefab))
		{
			scene.m_prefabs.Add(prefab);
		}
		names[StringExtensionMethods.GetStableHashCode(((Object)prefab).name)] = prefab;
		if (((Object)prefab).name == "ValheimVehicles_WaterVehicleShip_Valmod")
		{
			names[StringExtensionMethods.GetStableHashCode("ValmodRAFT")] = prefab;
		}
	}

	internal static void ReportRaft(string message)
	{
		((BaseUnityPlugin)plugin).Logger.LogInfo((object)message);
	}

	private static void BatchStaticVisuals(Transform visual)
	{
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Expected I4, but got Unknown
		//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: Expected O, but got Unknown
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: 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_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Expected O, but got Unknown
		Dictionary<string, List<MeshRenderer>> dictionary = new Dictionary<string, List<MeshRenderer>>();
		MeshRenderer[] componentsInChildren = ((Component)visual).GetComponentsInChildren<MeshRenderer>(true);
		foreach (MeshRenderer val in componentsInChildren)
		{
			if (!((Renderer)val).enabled || ((Object)val).name.StartsWith("sail_", StringComparison.OrdinalIgnoreCase))
			{
				continue;
			}
			MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.sharedMesh) && Object.op_Implicit((Object)(object)((Renderer)val).sharedMaterial))
			{
				string key = ((Object)((Renderer)val).sharedMaterial).GetInstanceID() + ":" + (int)((Renderer)val).shadowCastingMode + ":" + ((Renderer)val).receiveShadows;
				if (!dictionary.TryGetValue(key, out var value))
				{
					value = (dictionary[key] = new List<MeshRenderer>());
				}
				value.Add(val);
			}
		}
		int num = 0;
		int num2 = 0;
		foreach (KeyValuePair<string, List<MeshRenderer>> item in dictionary)
		{
			List<MeshRenderer> value = item.Value;
			num += value.Count;
			num2++;
			if (value.Count < 2)
			{
				continue;
			}
			StringBuilder stringBuilder = new StringBuilder(item.Key);
			foreach (MeshRenderer item2 in value)
			{
				stringBuilder.Append(':').Append(((Object)((Component)item2).GetComponent<MeshFilter>().sharedMesh).GetInstanceID());
			}
			string key = stringBuilder.ToString();
			if (!renderBatchMeshes.TryGetValue(key, out var value2))
			{
				CombineInstance[] array = (CombineInstance[])(object)new CombineInstance[value.Count];
				for (int j = 0; j < value.Count; j++)
				{
					((CombineInstance)(ref array[j])).mesh = ((Component)value[j]).GetComponent<MeshFilter>().sharedMesh;
					((CombineInstance)(ref array[j])).transform = visual.worldToLocalMatrix * ((Component)value[j]).transform.localToWorldMatrix;
				}
				Mesh val2 = new Mesh();
				((Object)val2).name = "Valmod shared render batch";
				val2.indexFormat = (IndexFormat)1;
				value2 = val2;
				value2.CombineMeshes(array, true, true);
				value2.RecalculateBounds();
				renderBatchMeshes[key] = value2;
			}
			GameObject val3 = new GameObject("Valmod render batch " + num2);
			val3.transform.SetParent(visual, false);
			val3.AddComponent<MeshFilter>().sharedMesh = value2;
			MeshRenderer val4 = val3.AddComponent<MeshRenderer>();
			((Renderer)val4).sharedMaterial = ((Renderer)value[0]).sharedMaterial;
			((Renderer)val4).shadowCastingMode = ((Renderer)value[0]).shadowCastingMode;
			((Renderer)val4).receiveShadows = ((Renderer)value[0]).receiveShadows;
			foreach (MeshRenderer item3 in value)
			{
				((Renderer)item3).enabled = false;
			}
		}
		ReportRaft("Static render groups: " + num + " renderers -> " + num2 + " material batches. Sail panels remain independent.");
	}

	internal static bool HasValmodRainCover(Vector3 point)
	{
		//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_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_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		RaycastHit result;
		ValmodClimbRoutes ship;
		RaycastHit result2;
		ValmodClimbRoutes ship2;
		return FindShipSurface(point + Vector3.up * 0.05f, Vector3.up, 8f, null, deck: true, out result, out ship) && FindShipSurface(point, -((Component)ship).transform.up, 3f, ship, deck: true, out result2, out ship2);
	}

	private static void UpdateValmodRain(EnvMan __instance, EnvSetup __0, ref GameObject[] ___m_currentPSystems)
	{
		//IL_004d: 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)
		if (Time.unscaledTime < nextRainCheck)
		{
			return;
		}
		nextRainCheck = Time.unscaledTime + 0.25f;
		Player localPlayer = Player.m_localPlayer;
		if (Object.op_Implicit((Object)(object)localPlayer) && __0 != null && __0.m_isWet && __0.m_psystems != null && HasValmodRainCover(((Character)localPlayer).GetCenterPoint()))
		{
			bool flag = !object.ReferenceEquals(hiddenRainRoots, __0.m_psystems);
			hiddenRainRoots = __0.m_psystems;
			ParticleSystem[] array2;
			if (flag)
			{
				setWeatherParticles.Invoke(__instance, new object[2] { hiddenRainRoots, false });
				List<ParticleSystem> list = new List<ParticleSystem>();
				GameObject[] array = hiddenRainRoots;
				foreach (GameObject val in array)
				{
					if (Object.op_Implicit((Object)(object)val))
					{
						list.AddRange(val.GetComponentsInChildren<ParticleSystem>(true));
					}
				}
				hiddenRainSystems = list.ToArray();
				array2 = hiddenRainSystems;
				foreach (ParticleSystem val2 in array2)
				{
					val2.Clear(false);
				}
			}
			array2 = hiddenRainSystems;
			foreach (ParticleSystem val2 in array2)
			{
				if (Object.op_Implicit((Object)(object)val2))
				{
					EmissionModule emission = val2.emission;
					if (((EmissionModule)(ref emission)).enabled)
					{
						((EmissionModule)(ref emission)).enabled = false;
					}
				}
			}
		}
		else if (hiddenRainRoots != null)
		{
			if (__0 != null && object.ReferenceEquals(hiddenRainRoots, __0.m_psystems) && (!__0.m_psystemsOutsideOnly || (Object.op_Implicit((Object)(object)localPlayer) && !localPlayer.InShelter())))
			{
				setWeatherParticles.Invoke(__instance, new object[2] { hiddenRainRoots, true });
				___m_currentPSystems = hiddenRainRoots;
			}
			hiddenRainRoots = null;
			hiddenRainSystems = null;
		}
	}

	private static bool IsSolidShipDeck(string name)
	{
		return name.StartsWith("Deck_", StringComparison.Ordinal) || name.StartsWith("ClosedHatch_", StringComparison.Ordinal) || name.StartsWith("AftHatchBox_", StringComparison.Ordinal) || name.StartsWith("FloorBox_", StringComparison.Ordinal);
	}

	private static bool IsShipWall(string name)
	{
		return name.StartsWith("Hull_", StringComparison.Ordinal) || name.StartsWith("Sides_", StringComparison.Ordinal) || name.StartsWith("CabinWall_", StringComparison.Ordinal) || name.StartsWith("EndInterior_", StringComparison.Ordinal) || name.StartsWith("ProbedEndWall_", StringComparison.Ordinal);
	}

	private static bool FindShipSurface(Vector3 origin, Vector3 direction, float distance, ValmodClimbRoutes expected, bool deck, out RaycastHit result, out ValmodClimbRoutes ship)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: 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)
		result = default(RaycastHit);
		ship = null;
		if (shelterMask == 0)
		{
			shelterMask = LayerMask.GetMask(new string[2] { "piece", "vehicle" });
		}
		int num = Physics.RaycastNonAlloc(origin, direction, shelterHits, distance, shelterMask, (QueryTriggerInteraction)1);
		float num2 = float.PositiveInfinity;
		for (int i = 0; i < num; i++)
		{
			RaycastHit val = shelterHits[i];
			Collider collider = ((RaycastHit)(ref val)).collider;
			if (Object.op_Implicit((Object)(object)collider) && !(deck ? (!IsSolidShipDeck(((Object)collider).name)) : (!IsShipWall(((Object)collider).name))))
			{
				ValmodClimbRoutes componentInParent = ((Component)collider).GetComponentInParent<ValmodClimbRoutes>();
				if (Object.op_Implicit((Object)(object)componentInParent) && (!Object.op_Implicit((Object)(object)expected) || !((Object)(object)componentInParent != (Object)(object)expected)) && !(((RaycastHit)(ref val)).distance >= num2) && (!deck || !((Component)collider).gameObject.CompareTag("leaky")))
				{
					num2 = ((RaycastHit)(ref val)).distance;
					result = val;
					ship = componentInParent;
				}
			}
		}
		return Object.op_Implicit((Object)(object)ship);
	}

	private static void RecognizeValmodShelter(Vector3 __0, ref float __1, ref bool __2)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: 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_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: 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)
		if ((!__2 || !(__1 >= 0.8f)) && FindShipSurface(__0 + Vector3.up * 0.05f, Vector3.up, 8f, null, deck: true, out var _, out var ship) && FindShipSurface(__0, -((Component)ship).transform.up, 3f, ship, deck: true, out var result2, out var _))
		{
			Vector3 origin = ((RaycastHit)(ref result2)).point + ((Component)ship).transform.up * 0.2f;
			if (FindShipSurface(origin, ((Component)ship).transform.right, 24f, ship, deck: false, out var result3, out var ship3) && FindShipSurface(origin, -((Component)ship).transform.right, 24f, ship, deck: false, out result3, out ship3))
			{
				__2 = true;
				__1 = Mathf.Max(__1, 0.85f);
			}
		}
	}
}
public sealed class ValmodSailVisibility : MonoBehaviour
{
	private Renderer[] sails;

	private Ship ship;

	private bool hidden;

	private Vector3[] originalPositions;

	private Vector3[] originalScales;

	private float[] sailTops;

	private float unfurled = 1f;

	private void Awake()
	{
		ship = ((Component)this).GetComponentInParent<Ship>();
		sails = (from renderer in ((Component)this).GetComponentsInChildren<MeshRenderer>(true)
			where ((Object)((Component)renderer).gameObject).name.StartsWith("sail_", StringComparison.OrdinalIgnoreCase)
			select renderer).Cast<Renderer>().ToArray();
		originalPositions = sails.Select((Renderer sail) => ((Component)sail).transform.localPosition).ToArray();
		originalScales = sails.Select((Renderer sail) => ((Component)sail).transform.localScale).ToArray();
		sailTops = sails.Select(delegate(Renderer sail)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			Bounds bounds = ((Component)sail).GetComponent<MeshFilter>().sharedMesh.bounds;
			return ((Bounds)(ref bounds)).max.y;
		}).ToArray();
	}

	private void LateUpdate()
	{
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		bool flag = Object.op_Implicit((Object)(object)Player.m_localPlayer) && (Object)(object)Player.m_localPlayer.GetControlledShip() == (Object)(object)ship;
		float num = ((Object.op_Implicit((Object)(object)ship) && ship.IsSailUp()) ? 1f : 0.06f);
		float num2 = unfurled;
		unfurled = Mathf.MoveTowards(unfurled, num, Time.deltaTime * 0.4f);
		for (int i = 0; i < sails.Length; i++)
		{
			if (num2 == unfurled)
			{
				break;
			}
			if (Object.op_Implicit((Object)(object)sails[i]))
			{
				Vector3 localScale = originalScales[i];
				localScale.y *= unfurled;
				((Component)sails[i]).transform.localScale = localScale;
				((Component)sails[i]).transform.localPosition = originalPositions[i] + Vector3.up * sailTops[i] * originalScales[i].y * (1f - unfurled);
			}
		}
		if (flag == hidden)
		{
			return;
		}
		Renderer[] array = sails;
		foreach (Renderer val in array)
		{
			if (Object.op_Implicit((Object)(object)val))
			{
				val.enabled = !flag;
			}
		}
		hidden = flag;
	}

	private void OnDisable()
	{
		if (sails == null)
		{
			return;
		}
		Renderer[] array = sails;
		foreach (Renderer val in array)
		{
			if (Object.op_Implicit((Object)(object)val))
			{
				val.enabled = true;
			}
		}
		hidden = false;
	}
}
public sealed class OdinDeckAttachment : MonoBehaviour
{
	private ZNetView view;

	private Transform vessel;

	private Vector3 offset;

	private Quaternion rotation;

	private float timer;

	private void Start()
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		view = ((Component)this).GetComponent<ZNetView>();
		if (Object.op_Implicit((Object)(object)view) && view.IsValid())
		{
			ZDOID zDOID = view.GetZDO().GetZDOID("valmod_parent");
			if (!((ZDOID)(ref zDOID)).Equals(default(ZDOID)))
			{
				return;
			}
		}
		((Behaviour)this).enabled = false;
	}

	public void Attach()
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: 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_00af: 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_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: 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_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_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		view = ((Component)this).GetComponent<ZNetView>();
		if (!Object.op_Implicit((Object)(object)view) || !view.IsValid() || !view.IsOwner() || Object.op_Implicit((Object)(object)((Component)this).GetComponent<Ship>()))
		{
			return;
		}
		foreach (RaycastHit item in from hit in Physics.RaycastAll(((Component)this).transform.position + Vector3.up, Vector3.down, 8f, -1, (QueryTriggerInteraction)1)
			orderby ((RaycastHit)(ref hit)).distance
			select hit)
		{
			RaycastHit current = item;
			if (!((Component)((RaycastHit)(ref current)).collider).transform.IsChildOf(((Component)this).transform))
			{
				Ship val = ((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<Ship>();
				OdinDeckAttachment componentInParent = ((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<OdinDeckAttachment>();
				if (!Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)componentInParent) && Object.op_Implicit((Object)(object)componentInParent.vessel))
				{
					val = ((Component)componentInParent.vessel).GetComponent<Ship>();
				}
				if (Object.op_Implicit((Object)(object)val) && ((Object)val).name.StartsWith("ValmodShip", StringComparison.Ordinal))
				{
					vessel = ((Component)val).transform;
					offset = vessel.InverseTransformPoint(((Component)this).transform.position);
					rotation = Quaternion.Inverse(vessel.rotation) * ((Component)this).transform.rotation;
					ZDO zDO = view.GetZDO();
					zDO.Set("valmod_parent", ((Component)val).GetComponent<ZNetView>().GetZDO().m_uid);
					zDO.Set("valmod_position", offset);
					zDO.Set("valmod_rotation", rotation);
					((Behaviour)this).enabled = true;
					Configure();
					break;
				}
			}
		}
	}

	private void Configure()
	{
		WearNTear component = ((Component)this).GetComponent<WearNTear>();
		if (Object.op_Implicit((Object)(object)component))
		{
			component.m_noSupportWear = true;
			component.m_noRoofWear = true;
		}
		ValmodCollisionCache valmodCollisionCache = ((Component)vessel).GetComponent<ValmodCollisionCache>();
		if (!Object.op_Implicit((Object)(object)valmodCollisionCache))
		{
			valmodCollisionCache = ((Component)vessel).gameObject.AddComponent<ValmodCollisionCache>();
		}
		Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>();
		foreach (Collider val in componentsInChildren)
		{
			Collider[] colliders = valmodCollisionCache.Colliders;
			foreach (Collider val2 in colliders)
			{
				Physics.IgnoreCollision(val, val2, true);
			}
		}
	}

	private void LateUpdate()
	{
		//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_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)view) || !view.IsValid())
		{
			return;
		}
		timer -= Time.deltaTime;
		if (!Object.op_Implicit((Object)(object)vessel))
		{
			if (timer > 0f || !Object.op_Implicit((Object)(object)ZNetScene.instance))
			{
				return;
			}
			timer = 1f;
			GameObject val = ZNetScene.instance.FindInstance(view.GetZDO().GetZDOID("valmod_parent"));
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			vessel = val.transform;
			offset = view.GetZDO().GetVec3("valmod_position", Vector3.zero);
			rotation = view.GetZDO().GetQuaternion("valmod_rotation", Quaternion.identity);
			Configure();
		}
		Vector3 val2 = vessel.TransformPoint(offset);
		Quaternion val3 = vessel.rotation * rotation;
		Vector3 val4 = ((Component)this).transform.position - val2;
		if (((Vector3)(ref val4)).sqrMagnitude > 1E-06f || Quaternion.Angle(((Component)this).transform.rotation, val3) > 0.01f)
		{
			((Component)this).transform.SetPositionAndRotation(val2, val3);
		}
		if (timer <= 0f && view.IsOwner())
		{
			timer = 0.5f;
			view.GetZDO().SetPosition(val2);
			view.GetZDO().SetRotation(val3);
		}
	}
}
public sealed class ValmodBuildPreview : MonoBehaviour
{
	private Material outlineMaterial;

	private void Start()
	{
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Expected O, but got Unknown
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Expected O, but got Unknown
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: 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_01bb: 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_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		ZNetView component = ((Component)this).GetComponent<ZNetView>();
		if (!Object.op_Implicit((Object)(object)component) || component.IsValid())
		{
			return;
		}
		FieldInfo fieldInfo = AccessTools.Field(typeof(ZNetView), "m_ghost");
		if (!(fieldInfo == null) && (bool)fieldInfo.GetValue(component))
		{
			Shader val = Shader.Find("Sprites/Default");
			if (Object.op_Implicit((Object)(object)val))
			{
				GameObject val2 = new GameObject("Valmod placement footprint");
				val2.transform.SetParent(((Component)this).transform, false);
				LineRenderer val3 = val2.AddComponent<LineRenderer>();
				val3.useWorldSpace = false;
				val3.loop = true;
				val3.startWidth = 0.16f;
				val3.endWidth = 0.16f;
				outlineMaterial = new Material(val);
				((Renderer)val3).sharedMaterial = outlineMaterial;
				Color startColor = (val3.endColor = new Color(0.3f, 1f, 0.6f, 0.8f));
				val3.startColor = startColor;
				Vector3[] array = (Vector3[])(object)new Vector3[9]
				{
					new Vector3(-5f, 0.2f, -37f),
					new Vector3(-8.5f, 0.2f, -25f),
					new Vector3(-9.5f, 0.2f, 15f),
					new Vector3(-6f, 0.2f, 32f),
					new Vector3(0f, 0.2f, 42f),
					new Vector3(6f, 0.2f, 32f),
					new Vector3(9.5f, 0.2f, 15f),
					new Vector3(8.5f, 0.2f, -25f),
					new Vector3(5f, 0.2f, -37f)
				};
				val3.positionCount = array.Length;
				val3.SetPositions(array);
			}
		}
	}

	private void OnDestroy()
	{
		if (Object.op_Implicit((Object)(object)outlineMaterial))
		{
			Object.Destroy((Object)(object)outlineMaterial);
		}
	}
}
public sealed class ValmodClimbRoutes : MonoBehaviour
{
	private void Start()
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: 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_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)((Component)this).transform.Find("Valmod climb routes")))
		{
			Transform transform = new GameObject("Valmod climb routes").transform;
			transform.SetParent(((Component)this).transform, false);
			float[] array = new float[2] { -1f, 1f }