Decompiled source of Saekonungr Ships v0.7.32

plugins/Saekonungr/Saekonungr.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using Saekonungr.Art;
using Saekonungr.Busse;
using Saekonungr.Faering;
using Saekonungr.Ferje;
using Saekonungr.Jekte;
using Saekonungr.Karfi;
using Saekonungr.Knarr;
using Saekonungr.Naglfar;
using Saekonungr.Runtime;
using Saekonungr.Ships;
using Saekonungr.Skeide;
using Saekonungr.Skute;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: AssemblyCompany("BatBoys")]
[assembly: AssemblyProduct("Sækonungr Ships")]
[assembly: AssemblyTitle("Saekonungr")]
[assembly: AssemblyDescription("Valheim ships inspired by historical Viking ships.")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = "")]
[assembly: AssemblyFileVersion("0.7.32.0")]
[assembly: AssemblyInformationalVersion("0.7.32")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.7.32.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace Saekonungr
{
	internal static class ConfigMigration
	{
		internal sealed class Snapshot
		{
			public readonly string Release;

			public readonly Dictionary<string, Dictionary<string, object>> Values = new Dictionary<string, Dictionary<string, object>>();

			public Snapshot(string release, Snapshot from = null)
			{
				Release = release;
				if (from == null)
				{
					return;
				}
				foreach (KeyValuePair<string, Dictionary<string, object>> value in from.Values)
				{
					Values[value.Key] = new Dictionary<string, object>(value.Value);
				}
			}

			public Snapshot Ship(string key, bool enabled, float health, float sail, float fwdDrag, float sideDrag, float row, float steer, float steerVel, int cargoW, int cargoH, string recipe, string station = "piece_workbench")
			{
				Values["Ship." + key] = new Dictionary<string, object>
				{
					["Enabled"] = enabled,
					["Health"] = health,
					["SailForce"] = sail,
					["ForwardDrag"] = fwdDrag,
					["SidewaysDrag"] = sideDrag,
					["RowForce"] = row,
					["SteerForce"] = steer,
					["SteerVelocityFactor"] = steerVel,
					["CargoWidth"] = cargoW,
					["CargoHeight"] = cargoH,
					["Recipe"] = recipe,
					["CraftingStation"] = station
				};
				return this;
			}
		}

		public const string Section = "General";

		public const string Key = "ConfigVersion";

		internal static readonly List<Snapshot> History = BuildHistory();

		private static List<Snapshot> BuildHistory()
		{
			Snapshot snapshot = new Snapshot("0.1.0").Ship("Faering", enabled: true, 350f, 0.028f, 0.003f, 0.18f, 1.4f, 0.35f, 0.25f, 3, 2, "Wood:30,Resin:8,LeatherScraps:6").Ship("Karfi", enabled: false, 600f, 0.035f, 0.001f, 0.15f, 0.25f, 0.25f, 0.2f, 4, 2, "FineWood:30,Bronze:4,BronzeNails:80,DeerHide:10").Ship("Skeide", enabled: false, 900f, 0.055f, 0.0009f, 0.2f, 0.2f, 0.9f, 0.75f, 5, 2, "FineWood:40,ElderBark:40,IronNails:100,DeerHide:10")
				.Ship("Busse", enabled: false, 3500f, 0.085f, 0.002f, 0.5f, 0.25f, 1.9f, 1.05f, 8, 4, "Blackwood:60,FlametalNew:10,IronNails:120,AskHide:10")
				.Ship("Knarr", enabled: false, 1200f, 0.045f, 0.0012f, 0.25f, 0.15f, 0.8f, 0.7f, 7, 3, "FineWood:40,Iron:10,IronNails:100,WolfPelt:10")
				.Ship("Ferje", enabled: false, 700f, 0.02f, 0.002f, 0.25f, 0.3f, 0.3f, 0.2f, 2, 2, "Wood:60,RoundLog:20,BronzeNails:60")
				.Ship("Skute", enabled: false, 700f, 0.06f, 0.0008f, 0.18f, 0.3f, 0.35f, 0.3f, 2, 1, "YggdrasilWood:30,BlackMetal:10,IronNails:60,Carapace:6")
				.Ship("Jekte", enabled: false, 1500f, 0.05f, 0.0011f, 0.25f, 0.2f, 1f, 0.8f, 6, 3, "FineWood:50,Iron:20,IronNails:120,LinenThread:20");
			Snapshot snapshot2 = new Snapshot("0.2.0", snapshot).Ship("Faering", enabled: true, 350f, 0.028f, 0.003f, 0.18f, 0.35f, 0.175f, 0.125f, 3, 2, "Wood:30,Resin:8,LeatherScraps:6").Ship("Karfi", enabled: true, 600f, 0.035f, 0.001f, 0.15f, 0.2f, 0.4f, 0.3f, 4, 2, "FineWood:30,RoundLog:10,BronzeNails:80,DeerHide:10,Resin:20");
			Snapshot snapshot3 = new Snapshot("0.3.0", snapshot2).Ship("Skeide", enabled: true, 900f, 0.072f, 0.001f, 0.18f, 0.3f, 1f, 0.3f, 6, 2, "FineWood:40,ElderBark:40,IronNails:100,TrollHide:10");
			Snapshot snapshot4 = new Snapshot("0.4.0", snapshot3).Ship("Busse", enabled: true, 3500f, 0.096f, 0.002f, 0.5f, 0.25f, 1.7f, 0.33f, 8, 4, "Blackwood:40,YggdrasilWood:25,CeramicPlate:30,IronNails:120,AskHide:10");
			Snapshot snapshot5 = new Snapshot("0.4.1", snapshot4).Ship("Busse", enabled: true, 3500f, 0.096f, 0.002f, 0.5f, 0.25f, 1.7f, 0.33f, 8, 4, "YggdrasilWood:40,FineWood:40,CeramicPlate:30,IronNails:120,LoxPelt:10");
			Snapshot snapshot6 = new Snapshot("0.4.6", snapshot5).Ship("Skeide", enabled: true, 900f, 0.072f, 0.001f, 0.18f, 0.68f, 1f, 0.3f, 6, 2, "FineWood:40,ElderBark:40,IronNails:100,TrollHide:10");
			Snapshot snapshot7 = new Snapshot("0.5.0", snapshot6).Ship("Ferje", enabled: true, 1000f, 0.059f, 0.003f, 0.25f, 0.4f, 1f, 0.5f, 4, 2, "Wood:60,ElderBark:30,IronNails:80,DeerHide:10");
			Snapshot snapshot8 = new Snapshot("0.5.1", snapshot7);
			snapshot8.Values["Ferje"] = new Dictionary<string, object> { ["CalmPennedAnimals"] = true };
			Snapshot snapshot9 = new Snapshot("0.5.3", snapshot8).Ship("Ferje", enabled: true, 2000f, 0.059f, 0.003f, 0.25f, 0.4f, 1f, 0.5f, 4, 2, "Wood:120,ElderBark:60,IronNails:160,DeerHide:20");
			Snapshot snapshot10 = new Snapshot("0.6.0", snapshot9).Ship("Knarr", enabled: true, 1500f, 0.0568f, 0.0015f, 0.25f, 0.115f, 1f, 0.8f, 8, 5, "FineWood:60,ElderBark:40,IronNails:150,WolfPelt:10,LinenThread:20");
			snapshot10.Values["Knarr"] = new Dictionary<string, object>
			{
				["CargoAffectsHandling"] = true,
				["SailStyle"] = "Trader",
				["ShowTent"] = false
			};
			Snapshot snapshot11 = new Snapshot("0.6.1", snapshot10).Ship("Ferje", enabled: true, 2000f, 0.059f, 0.003f, 0.25f, 0.4f, 1.75f, 0.875f, 4, 2, "Wood:120,ElderBark:60,IronNails:160,DeerHide:20");
			Snapshot snapshot12 = new Snapshot("0.6.3", snapshot11).Ship("Knarr", enabled: true, 1500f, 0.0499f, 0.0015f, 0.25f, 0.115f, 1f, 0.8f, 8, 5, "FineWood:60,ElderBark:40,IronNails:150,WolfPelt:10,LinenThread:20");
			Snapshot snapshot13 = new Snapshot("0.7.5", snapshot12).Ship("Skute", enabled: true, 700f, 0.0925f, 0.001f, 0.18f, 0.266f, 1f, 0.6f, 3, 1, "YggdrasilWood:30,FineWood:20,IronNails:60,LinenThread:20,Carapace:10");
			snapshot13.Values["Skute"] = new Dictionary<string, object>
			{
				["CargoAffectsSpeed"] = true,
				["SpeedMultiplier"] = 1f,
				["ShowWindVane"] = true
			};
			Snapshot snapshot14 = new Snapshot("0.7.14", snapshot13).Ship("Jekte", enabled: true, 2200f, 0.0666f, 0.002f, 0.25f, 0.116f, 1f, 0.9f, 8, 4, "FineWood:60,IronNails:150,LinenThread:30,Tar:10,LoxPelt:6");
			Snapshot snapshot15 = new Snapshot("0.7.18", snapshot14).Ship("Jekte", enabled: true, 4000f, 0.0666f, 0.002f, 0.25f, 0.116f, 2f, 2f, 8, 8, "FineWood:60,Stone:250,IronNails:150,LinenThread:30,Tar:10,LoxPelt:6");
			Snapshot item = new Snapshot("0.7.23", snapshot15).Ship("Jekte", enabled: true, 4000f, 0.0666f, 0.002f, 0.25f, 0.116f, 2f, 2f, 8, 8, "FineWood:60,Stone:50,IronNails:150,LinenThread:30,Tar:10,LoxPelt:6");
			return new List<Snapshot>
			{
				snapshot, snapshot2, snapshot3, snapshot4, snapshot5, snapshot6, snapshot7, snapshot8, snapshot9, snapshot10,
				snapshot11, snapshot12, snapshot13, snapshot14, snapshot15, item
			};
		}

		public static int Run(ConfigFile cfg, string currentVersion, Action<string> log, Action<string> warn = null)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			ConfigEntry<string> val = cfg.Bind<string>("General", "ConfigVersion", "", new ConfigDescription("Release that last wrote this file. Used to upgrade settings still on an old default when a new release changes it. Do not edit.", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				Browsable = false
			} }));
			string text = (val.Value ?? "").Trim();
			List<Snapshot> list = Candidates(text);
			string text2 = ((text.Length == 0) ? "a pre-0.3.1 file (no ConfigVersion)" : ("ConfigVersion " + text));
			bool saveOnConfigSet = cfg.SaveOnConfigSet;
			cfg.SaveOnConfigSet = false;
			int num = 0;
			try
			{
				foreach (ConfigEntryBase item in Entries(cfg))
				{
					ConfigDefinition definition = item.Definition;
					if (definition.Section == "General" && definition.Key == "ConfigVersion")
					{
						continue;
					}
					foreach (Snapshot item2 in list)
					{
						if (item2.Values.TryGetValue(definition.Section, out var value) && value.TryGetValue(definition.Key, out var value2) && !Same(value2, item.DefaultValue) && Same(value2, item.BoxedValue))
						{
							string text3 = Show(item.BoxedValue);
							item.BoxedValue = item.DefaultValue;
							num++;
							log("Config upgrade: [" + definition.Section + "] " + definition.Key + " = " + text3 + " -> " + Show(item.DefaultValue) + " (old " + item2.Release + " default; " + text2 + ").");
							break;
						}
					}
				}
				CheckNewest(cfg, warn);
				if (val.Value != currentVersion)
				{
					val.Value = currentVersion;
				}
			}
			finally
			{
				cfg.SaveOnConfigSet = saveOnConfigSet;
			}
			cfg.Save();
			log((num == 0) ? ("Config defaults are current (" + text2 + ", now " + currentVersion + ").") : $"Config upgrade: {num} setting(s) moved from old defaults to the {currentVersion} defaults; changed settings were kept.");
			return num;
		}

		internal static List<Snapshot> Candidates(string saved)
		{
			if (saved.Length == 0 || !TryVersion(saved, out var v))
			{
				return History;
			}
			Snapshot snapshot = null;
			foreach (Snapshot item in History)
			{
				if (TryVersion(item.Release, out var v2) && v2 <= v)
				{
					snapshot = item;
				}
			}
			if (snapshot != null)
			{
				return new List<Snapshot> { snapshot };
			}
			return new List<Snapshot>();
		}

		private static void CheckNewest(ConfigFile cfg, Action<string> warn)
		{
			if (warn == null)
			{
				return;
			}
			Snapshot snapshot = History[History.Count - 1];
			foreach (ConfigEntryBase item in Entries(cfg))
			{
				ConfigDefinition definition = item.Definition;
				if (snapshot.Values.TryGetValue(definition.Section, out var value) && value.TryGetValue(definition.Key, out var value2) && !Same(value2, item.DefaultValue))
				{
					warn("ConfigMigration: newest snapshot " + snapshot.Release + " has [" + definition.Section + "] " + definition.Key + " = " + Show(value2) + " but the default is " + Show(item.DefaultValue) + "; add a snapshot for this release.");
				}
			}
		}

		private static List<ConfigEntryBase> Entries(ConfigFile cfg)
		{
			List<ConfigEntryBase> list = new List<ConfigEntryBase>();
			foreach (ConfigDefinition key in cfg.Keys)
			{
				list.Add(cfg[key]);
			}
			return list;
		}

		private static bool TryVersion(string s, out Version v)
		{
			v = null;
			int num = s.IndexOf('-');
			if (num >= 0)
			{
				s = s.Substring(0, num);
			}
			try
			{
				v = new Version(s);
				return true;
			}
			catch
			{
				return false;
			}
		}

		internal static bool Same(object a, object b)
		{
			if (a == null || b == null)
			{
				return a == b;
			}
			if (a is float num && b is float num2)
			{
				return Math.Abs(num - num2) <= 1E-06f * Math.Max(1f, Math.Abs(num2));
			}
			if (a is string s && b is string s2)
			{
				return Norm(s) == Norm(s2);
			}
			return a.Equals(b);
		}

		private static string Norm(string s)
		{
			return s.Replace(" ", "").Replace("\t", "").Trim()
				.ToLowerInvariant();
		}

		private static string Show(object o)
		{
			if (o is float num)
			{
				return num.ToString("R", CultureInfo.InvariantCulture);
			}
			if (o is bool)
			{
				if (!(bool)o)
				{
					return "false";
				}
				return "true";
			}
			if (o is string text)
			{
				if (text.Length != 0)
				{
					return text;
				}
				return "(empty)";
			}
			return Convert.ToString(o, CultureInfo.InvariantCulture);
		}
	}
	internal static class ModConfig
	{
		public static ConfigEntry<bool> HideVanillaShips;

		public static ConfigEntry<bool> ShowOars;

		public static readonly Dictionary<string, ConfigEntry<bool>> HideVanilla = new Dictionary<string, ConfigEntry<bool>>();

		public static bool OarsShown
		{
			get
			{
				if (ShowOars != null)
				{
					return ShowOars.Value;
				}
				return true;
			}
		}

		internal static ConfigDescription Synced(string text, AcceptableValueBase range = null)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			return new ConfigDescription(text + " Synced from the server.", range, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} });
		}

		public static void Bind(ConfigFile cfg)
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			HideVanillaShips = cfg.Bind<bool>("General", "HideVanillaShips", true, Synced("Master switch. When on, the vanilla ships selected in the VanillaShips section are removed from the hammer menu. Ships already built in the world are never deleted and keep working."));
			AddVanilla(cfg, "Raft", "HideRaft", "the Raft (the Færing replaces it)");
			AddVanilla(cfg, "Karve", "HideKarve", "the Karve (replaced by the Karfi)");
			AddVanilla(cfg, "VikingShip", "HideLongship", "the Longship (replaced by the Skeide)");
			AddVanilla(cfg, "VikingShip_Ashlands", "HideDrakkar", "the Drakkar (replaced by the Busse)");
			HideVanillaShips.SettingChanged += delegate
			{
				BuildMenu.Refresh();
			};
			ShowOars = cfg.Bind<bool>("General", "ShowOars", true, new ConfigDescription("Show the oars on every ship from this mod, and their rowing animation. Turn it off if you dislike the oars or use another rowing mod (for example Heave Ho) that draws its own: the oar holes are shown closed with their shutters. A looks-only setting that each player can choose for themselves: speed, handling, rowing force and every other stat are unchanged. It applies at once, also to ships already in the world.", (AcceptableValueBase)null, Array.Empty<object>()));
			ShowOars.SettingChanged += delegate
			{
				OarRower.ApplyAll();
			};
			FerjeConfig.Bind(cfg);
			KnarrConfig.Bind(cfg);
			SkuteConfig.Bind(cfg);
		}

		private static void AddVanilla(ConfigFile cfg, string prefab, string key, string what)
		{
			ConfigEntry<bool> val = cfg.Bind<bool>("VanillaShips", key, true, Synced("Hide " + what + " from the hammer menu while General.HideVanillaShips is on."));
			val.SettingChanged += delegate
			{
				BuildMenu.Refresh();
			};
			HideVanilla[prefab] = val;
		}

		public static bool ShouldHideVanilla(string prefab)
		{
			if (HideVanillaShips.Value && HideVanilla.TryGetValue(prefab, out var value))
			{
				return value.Value;
			}
			return false;
		}
	}
	internal static class ModInfo
	{
		public const string Guid = "batboys.saekonungr";

		public const string DisplayName = "Sækonungr Ships";

		public const string PackageName = "Saekonungr_Ships";

		public const string PluginFolder = "Saekonungr";

		public const string PrefabPrefix = "SK_";

		public const string TokenPrefix = "sk_";

		public const string ResourcePrefix = "Saekonungr.Assets.";

		public const string Version = "0.7.32";
	}
	[BepInPlugin("batboys.saekonungr", "Sækonungr Ships", "0.7.32")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[SynchronizationMode(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static Plugin Instance { get; private set; }

		internal static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			ModConfig.Bind(((BaseUnityPlugin)this).Config);
			ShipRegistry.BindConfigs(((BaseUnityPlugin)this).Config);
			ConfigMigration.Run(((BaseUnityPlugin)this).Config, "0.7.32", delegate(string m)
			{
				Log.LogInfo((object)m);
			}, delegate(string m)
			{
				Log.LogWarning((object)m);
			});
			new Harmony("batboys.saekonungr").PatchAll(typeof(Plugin).Assembly);
			PrefabManager.OnVanillaPrefabsAvailable += ShipFactory.RegisterAll;
			PieceManager.OnPiecesRegistered += OnPiecesRegistered;
			SynchronizationManager.OnConfigurationSynchronized += delegate(object sender, ConfigurationSynchronizationEventArgs args)
			{
				if (args.UpdatedPluginGUIDs == null || args.UpdatedPluginGUIDs.Contains("batboys.saekonungr"))
				{
					Log.LogInfo((object)(args.InitialSynchronization ? "Using the server's ship settings." : "The server changed the ship settings."));
					ApplyAll();
				}
			};
			Log.LogInfo((object)"Sækonungr Ships 0.7.32 loaded.");
		}

		private static void OnPiecesRegistered()
		{
			ApplyAll();
		}

		internal static void ApplyAll()
		{
			ShipFactory.ApplyConfigToAll();
			BuildMenu.Refresh();
		}
	}
}
namespace Saekonungr.Skute
{
	internal sealed class PennantCloth
	{
		private readonly Mesh m_mesh;

		private readonly Vector3[] m_rest;

		private readonly Vector3[] m_restN;

		private readonly Vector3[] m_pos;

		private readonly Vector3[] m_nrm;

		private readonly PennantWave.Bend m_bend = new PennantWave.Bend();

		private PennantCloth(Mesh mesh)
		{
			m_mesh = mesh;
			m_rest = mesh.vertices;
			m_restN = mesh.normals;
			m_pos = (Vector3[])(object)new Vector3[m_rest.Length];
			m_nrm = (Vector3[])(object)new Vector3[m_rest.Length];
		}

		public static PennantCloth Create(MeshFilter filter)
		{
			//IL_0068: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = (Object.op_Implicit((Object)(object)filter) ? filter.sharedMesh : null);
			if (!Object.op_Implicit((Object)(object)val) || val.vertexCount < 4 || val.normals.Length != val.vertexCount)
			{
				return null;
			}
			Mesh val2 = Object.Instantiate<Mesh>(val);
			((Object)val2).name = ((Object)val).name + "_cloth";
			val2.MarkDynamic();
			val2.bounds = new Bounds(new Vector3(0f, -0.45f, 0.62f), new Vector3(0.5f, 1.8f, 1.5f));
			filter.sharedMesh = val2;
			return new PennantCloth(val2);
		}

		public void Step(float t, float streaming, float droopDeg)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_004b: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			m_bend.Set(droopDeg);
			for (int i = 0; i < m_rest.Length; i++)
			{
				Vector3 val = m_rest[i];
				Vector3 val2 = m_restN[i];
				PennantWave.Eval(val.x, val.y, val.z, val2.x, val2.y, val2.z, t, streaming, m_bend, out var ox, out var oy, out var oz, out var onx, out var ony, out var onz);
				m_pos[i] = new Vector3(ox, oy, oz);
				m_nrm[i] = new Vector3(onx, ony, onz);
			}
			m_mesh.SetVertices(m_pos, 0, m_pos.Length, (MeshUpdateFlags)8);
			m_mesh.SetNormals(m_nrm, 0, m_nrm.Length, (MeshUpdateFlags)8);
		}

		public void Dispose()
		{
			if (Object.op_Implicit((Object)(object)m_mesh))
			{
				Object.Destroy((Object)(object)m_mesh);
			}
		}
	}
	internal static class PennantWave
	{
		public sealed class Bend
		{
			public const int N = 40;

			public readonly float[] Ca = new float[41];

			public readonly float[] Sa = new float[41];

			public readonly float[] Cz = new float[41];

			public readonly float[] Cy = new float[41];

			public float Droop;

			public void Set(float droopDeg)
			{
				Droop = droopDeg;
				float num = 0.0275f;
				for (int i = 0; i <= 40; i++)
				{
					float num2 = (float)i / 40f;
					float num3 = num2 * num2 * (3f - 2f * num2);
					float num4 = droopDeg * num3 * ((float)Math.PI / 180f);
					Ca[i] = (float)Math.Cos(num4);
					Sa[i] = (float)Math.Sin(num4);
					if (i == 0)
					{
						Cz[0] = 0f;
						Cy[0] = 0f;
					}
					else
					{
						Cz[i] = Cz[i - 1] + num * 0.5f * (Ca[i - 1] + Ca[i]);
						Cy[i] = Cy[i - 1] - num * 0.5f * (Sa[i - 1] + Sa[i]);
					}
				}
			}
		}

		public const float Hoist = 0.06f;

		public const float Length = 1.1f;

		public const float Wave1Amp = 0.03f;

		public const float Wave1Len = 0.6f;

		public const float Wave1Speed = 6.2f;

		public const float Wave1Diag = 4f;

		public const float Wave2Amp = 0.01f;

		public const float Wave2Len = 0.32f;

		public const float Wave2Speed = 9.4f;

		public const float Wave2Diag = -3f;

		public const float SwayAmp = 0.055f;

		public const float CalmRipple = 0.2f;

		public const float CalmSway = 0.25f;

		public const float MaxOffset = 0.1f;

		public static void Eval(float x, float y, float z, float nx, float ny, float nz, float t, float streaming, Bend bend, out float ox, out float oy, out float oz, out float onx, out float ony, out float onz)
		{
			float num = z - 0.06f;
			float num2 = num / 1.1f;
			if (num2 < 0f)
			{
				num2 = 0f;
			}
			float num3 = ((num2 < 1f) ? num2 : 1f);
			float num4 = num3 * num3;
			float num5 = ((num2 < 1f) ? (2f * num2 / 1.1f) : 0f);
			float num6 = 0.2f + 0.8f * streaming;
			float num7 = 10.471975f;
			float num8 = 19.634954f;
			float num9 = num7 * num - 6.2f * t + 4f * y;
			float num10 = num8 * num - 9.4f * t + -3f * y + 1.3f;
			float num11 = (float)Math.Sin(num9);
			float num12 = (float)Math.Cos(num9);
			float num13 = (float)Math.Sin(num10);
			float num14 = (float)Math.Cos(num10);
			float num15 = 0.055f * (0.25f + 0.75f * streaming);
			float num16 = (float)(Math.Sin(2.9f * t) * Math.Cos(1.3f * t));
			float num17 = num6 * (0.03f * num4 * num11 + 0.01f * num4 * num13) + num15 * num4 * num16;
			float num18 = num6 * (0.03f * (num5 * num11 + num4 * num7 * num12) + 0.01f * (num5 * num13 + num4 * num8 * num14)) + num15 * num5 * num16;
			float num19 = num6 * num4 * (0.12f * num12 + -0.03f * num14);
			if (num17 > 0.1f)
			{
				num17 = 0.1f;
			}
			else if (num17 < -0.1f)
			{
				num17 = -0.1f;
			}
			float num20 = ((nx >= 0f) ? 1f : (-1f));
			float num21 = nx;
			float num22 = ny - num20 * num19;
			float num23 = nz - num20 * num18;
			float num24 = (float)Math.Sqrt(num21 * num21 + num22 * num22 + num23 * num23);
			if (num24 > 1E-06f)
			{
				num21 /= num24;
				num22 /= num24;
				num23 /= num24;
			}
			float num25 = ((num < 0f) ? 0f : num);
			float num26 = 0f;
			if (num25 > 1.1f)
			{
				num26 = num25 - 1.1f;
				num25 = 1.1f;
			}
			float num27 = num25 * 36.363636f;
			int num28 = (int)num27;
			if (num28 >= 40)
			{
				num28 = 39;
			}
			float num29 = num27 - (float)num28;
			float num30 = bend.Ca[num28] + (bend.Ca[num28 + 1] - bend.Ca[num28]) * num29;
			float num31 = bend.Sa[num28] + (bend.Sa[num28 + 1] - bend.Sa[num28]) * num29;
			float num32 = bend.Cz[num28] + (bend.Cz[num28 + 1] - bend.Cz[num28]) * num29 + num26 * num30;
			float num33 = bend.Cy[num28] + (bend.Cy[num28 + 1] - bend.Cy[num28]) * num29 - num26 * num31;
			ox = x + num17;
			oy = num33 + y * num30;
			oz = 0.06f + num32 + y * num31;
			onx = num21;
			ony = num22 * num30 - num23 * num31;
			onz = num22 * num31 + num23 * num30;
		}
	}
	internal static class SkuteBuilder
	{
		public static readonly HullPhysics Physics = new HullPhysics
		{
			WaterLevelOffset = 0.6f,
			Force = 1f,
			ForceDistance = 2f,
			SailForceOffset = 0.07f,
			SteerForceOffset = -4.5f,
			RudderSpeed = 1f,
			AngularDamping = 0.3f,
			CenterOfMass = new Vector3(0f, -0.15f, 0f)
		};

		private const float MastScale = 0.75f;

		private const float MastFootSink = 0.03f;

		private const float StoolTop = 0.42f;

		private const int OarPairs = 3;

		private static readonly Vector3 HelmUseBox = new Vector3(1.4f, 1.1f, 1.2f);

		public const string SailFile = "skute_sail.png";

		private const float YardAxisX = -0.215f;

		private const float YardAxisY = 3.475f;

		private const float YardEndZ = 1.99f;

		private const float VaneSeat = 0.296f;

		internal static readonly Vector3 CleatLift = new Vector3(0f, 0.08f, 0f);

		public static void Build(GameObject go, ShipDefinition def)
		{
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0442: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_052d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0532: Unknown result type (might be due to invalid IL or missing references)
			//IL_0543: Unknown result type (might be due to invalid IL or missing references)
			//IL_0559: Unknown result type (might be due to invalid IL or missing references)
			//IL_055e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0575: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0602: Unknown result type (might be due to invalid IL or missing references)
			//IL_0619: Unknown result type (might be due to invalid IL or missing references)
			//IL_064f: Unknown result type (might be due to invalid IL or missing references)
			//IL_065b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0676: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0743: Unknown result type (might be due to invalid IL or missing references)
			//IL_0745: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0707: Unknown result type (might be due to invalid IL or missing references)
			//IL_070e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0713: Unknown result type (might be due to invalid IL or missing references)
			//IL_0719: Unknown result type (might be due to invalid IL or missing references)
			//IL_071b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0720: Unknown result type (might be due to invalid IL or missing references)
			//IL_0725: Unknown result type (might be due to invalid IL or missing references)
			//IL_0942: Unknown result type (might be due to invalid IL or missing references)
			//IL_0947: Unknown result type (might be due to invalid IL or missing references)
			//IL_0751: Unknown result type (might be due to invalid IL or missing references)
			//IL_0756: Unknown result type (might be due to invalid IL or missing references)
			//IL_0758: Unknown result type (might be due to invalid IL or missing references)
			//IL_075d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0965: Unknown result type (might be due to invalid IL or missing references)
			//IL_096c: Unknown result type (might be due to invalid IL or missing references)
			//IL_097f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0986: Unknown result type (might be due to invalid IL or missing references)
			//IL_098b: Unknown result type (might be due to invalid IL or missing references)
			//IL_099d: Unknown result type (might be due to invalid IL or missing references)
			//IL_09a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0778: Unknown result type (might be due to invalid IL or missing references)
			//IL_077d: Unknown result type (might be due to invalid IL or missing references)
			//IL_077f: Unknown result type (might be due to invalid IL or missing references)
			//IL_09dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_09f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_089a: Unknown result type (might be due to invalid IL or missing references)
			//IL_089f: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_08cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_08fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0901: Unknown result type (might be due to invalid IL or missing references)
			//IL_091e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0923: Unknown result type (might be due to invalid IL or missing references)
			//IL_0928: Unknown result type (might be due to invalid IL or missing references)
			//IL_092d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a27: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a33: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a65: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a6a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a7c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a88: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c44: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c55: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c76: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c7b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c7f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c86: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c93: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c9a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c9f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ddb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0de0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0df1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0df6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e11: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e37: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e3c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e4d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e52: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e6d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d16: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d18: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d3f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cd0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ceb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b48: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b01: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b0d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b19: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e9f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0eb1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ec9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ece: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f2d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f38: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b94: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba4: Unknown result type (might be due to invalid IL or missing references)
			//IL_10f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_10f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_10fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_110a: Unknown result type (might be due to invalid IL or missing references)
			//IL_1117: Unknown result type (might be due to invalid IL or missing references)
			//IL_111c: Unknown result type (might be due to invalid IL or missing references)
			//IL_1162: Unknown result type (might be due to invalid IL or missing references)
			//IL_116a: Unknown result type (might be due to invalid IL or missing references)
			//IL_1174: Unknown result type (might be due to invalid IL or missing references)
			//IL_1179: Unknown result type (might be due to invalid IL or missing references)
			//IL_118b: Unknown result type (might be due to invalid IL or missing references)
			//IL_11ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_12cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_12d0: Unknown result type (might be due to invalid IL or missing references)
			Transform root = go.transform;
			Rig rig = Rig.Load("skute_rig.txt");
			Transform val = FaeringBuilder.Need(root, "ship");
			Transform val2 = FaeringBuilder.Need(val, "visual");
			Transform val3 = FaeringBuilder.Need(root, "interactive");
			MeshRenderer val4 = FaeringBuilder.Find<MeshRenderer>(val2, "hull_new");
			MeshRenderer val5 = FaeringBuilder.Find<MeshRenderer>(val2, "watermask");
			Transform obj = val.Find("colliders");
			Collider val6 = ((obj != null) ? ((Component)obj).GetComponentInChildren<Collider>(true) : null);
			Material val7 = (Object.op_Implicit((Object)(object)val4) ? ((Renderer)val4).sharedMaterial : null);
			Material val8 = (Object.op_Implicit((Object)(object)val5) ? ((Renderer)val5).sharedMaterial : null);
			PhysicsMaterial val9 = (Object.op_Implicit((Object)(object)val6) ? val6.sharedMaterial : null);
			if (!Object.op_Implicit((Object)(object)val7))
			{
				Plugin.Log.LogWarning((object)"Skute: Longship hull material not found, using Standard.");
				val7 = new Material(Shader.Find("Standard"));
			}
			Material matNew = Textures.CloneWood(val7, Textures.Load("skute_albedo.png"), "sk_skute_new");
			Material item = Textures.CloneWood(val7, Textures.Weathered("skute_albedo.png", 0.86f, 0.25f), "sk_skute_worn");
			Material item2 = Textures.CloneWood(val7, Textures.Weathered("skute_albedo.png", 0.7f, 0.45f), "sk_skute_broken");
			Mesh mesh = MeshAsset.Load("skute_hull.skm");
			Mesh mesh2 = MeshAsset.Load("skute_watermask.skm");
			Mesh mesh3 = MeshAsset.Load("skute_bulkhead.skm");
			Mesh mesh4 = MeshAsset.Load("skute_bowbox.skm");
			Mesh mesh5 = MeshAsset.Load("skute_ruff.skm");
			Mesh mesh6 = MeshAsset.Load("skute_stem.skm");
			Mesh mesh7 = MeshAsset.Load("skute_eyes.skm");
			Material mat = SkuteEyes.Make(val7);
			Mesh mesh8 = MeshAsset.Load("skute_wolf.skm");
			Mesh closedMesh = MeshAsset.Load("skute_hatch.skm");
			Mesh openMesh = MeshAsset.Load("skute_hatch_open.skm");
			Mesh[] array = StoolVariants.Load("skute");
			List<Renderer> renderers = new List<Renderer>();
			string[] array2 = new string[3] { "Customize", "unused", "watermask" };
			foreach (string text in array2)
			{
				Kill(val2.Find(text));
			}
			Kill(val.Find("colliders"));
			Kill(val3.Find("front"));
			Kill(val3.Find("sit_box (4)"));
			Kill(val3.Find("sit_box (3)"));
			Kill(val3.Find("sit_box (2)"));
			Metal51Mats mats = Metal51.Make(val7, "skute");
			List<Renderer> list = new List<Renderer>();
			Mesh mesh9 = MeshAsset.Load("skute_portcaps.skm");
			int num = 0;
			(string, Material)[] array3 = new(string, Material)[3]
			{
				("hull_new", matNew),
				("hull_worn", item),
				("hull_broken", item2)
			};
			for (int i = 0; i < array3.Length; i++)
			{
				(string, Material) tuple = array3[i];
				string item3 = tuple.Item1;
				Material item4 = tuple.Item2;
				Transform val10 = val2.Find(item3);
				if (!Object.op_Implicit((Object)(object)val10))
				{
					Plugin.Log.LogWarning((object)("Skute: missing " + item3));
					continue;
				}
				FaeringBuilder.ClearChildren(val10);
				StripRenderer(val10);
				Transform val11 = Compensated(val10, "sk_" + item3, root);
				renderers.Add((Renderer)(object)FaeringBuilder.AddMesh(val11, "sk_hull", mesh, item4, Vector3.zero));
				MeshRenderer val12 = FaeringBuilder.AddMesh(val11, "sk_portcaps", mesh9, item4, Vector3.zero);
				((Renderer)val12).enabled = false;
				list.Add((Renderer)(object)val12);
				renderers.Add((Renderer)(object)val12);
				renderers.Add((Renderer)(object)FaeringBuilder.AddMesh(val11, "sk_wolf", mesh8, item4, Vector3.zero));
				renderers.Add((Renderer)(object)FaeringBuilder.AddMesh(val11, "sk_bulkhead", mesh3, item4, Vector3.zero));
				renderers.Add((Renderer)(object)FaeringBuilder.AddMesh(val11, "sk_bowbox", mesh4, item4, Vector3.zero));
				renderers.Add((Renderer)(object)FaeringBuilder.AddMesh(val11, "sk_ruff", mesh5, item4, Vector3.zero));
				renderers.Add((Renderer)(object)FaeringBuilder.AddMesh(val11, "sk_stem", mesh6, item4, Vector3.zero));
				MeshRenderer val13 = FaeringBuilder.AddMesh(val11, "sk_eyes", mesh7, mat, Vector3.zero);
				((Renderer)val13).shadowCastingMode = (ShadowCastingMode)0;
				renderers.Add((Renderer)(object)val13);
				Metal51.AddHull(val11, "skute", mats, num++, renderers);
				if (Object.op_Implicit((Object)(object)val8))
				{
					MeshRenderer obj2 = FaeringBuilder.AddMesh(val11, "sk_watermask", mesh2, val8, Vector3.zero);
					((Renderer)obj2).shadowCastingMode = (ShadowCastingMode)0;
					((Renderer)obj2).receiveShadows = false;
				}
			}
			Transform val14 = FaeringBuilder.NewChild(root, "sk_colliders");
			((Component)val14).gameObject.layer = 28;
			foreach (Rig.Box box in rig.Boxes)
			{
				Transform obj3 = FaeringBuilder.NewChild(val14, "col_" + box.Name);
				obj3.position = W(box.Center);
				obj3.rotation = root.rotation * Quaternion.Euler(0f, box.Yaw, 0f);
				BoxCollider obj4 = ((Component)obj3).gameObject.AddComponent<BoxCollider>();
				obj4.size = box.Size;
				((Collider)obj4).sharedMaterial = val9;
			}
			HullColliders.Build(root, root, rig, val9, 28);
			Transform obj5 = FaeringBuilder.Need(root, "FloatCollider");
			BoxCollider component = ((Component)obj5).GetComponent<BoxCollider>();
			obj5.localPosition = Vector3.zero;
			obj5.localRotation = Quaternion.identity;
			obj5.localScale = Vector3.one;
			component.size = rig.Point("float_size");
			component.center = rig.Point("float_center");
			Transform val15 = root.Find("OnboardTrigger");
			if (Object.op_Implicit((Object)(object)val15))
			{
				val15.localPosition = new Vector3(0f, 1.2f, 0f);
				val15.localRotation = Quaternion.identity;
				val15.localScale = new Vector3(3.2f, 3.4f, 12.4f);
			}
			Transform val16 = val2.Find("Mast");
			SkinnedMeshRenderer[] sails = (SkinnedMeshRenderer[])(object)new SkinnedMeshRenderer[0];
			if (Object.op_Implicit((Object)(object)val16))
			{
				val16.localScale = Vector3.one * 0.75f;
				ReplaceMastMesh(val16);
				Vector3 val17 = rig.Point("mast_step");
				Vector3 position = val16.position;
				if (MastFoot(val16, root, out var foot))
				{
					val16.position += W(new Vector3(val17.x, val17.y - 0.03f, val17.z)) - W(foot);
				}
				else
				{
					Plugin.Log.LogWarning((object)"Skute: mast mesh not found; stepping the Mast transform on the deck.");
					val16.position = W(val17);
				}
				Vector3 val18 = val16.position - position;
				Transform val19 = val3.Find("mast");
				if (Object.op_Implicit((Object)(object)val19))
				{
					val19.position += val18;
					float num2 = Holdfast.SeatOnDeck(root, val19, rig, 0.026f, "Skute");
					Plugin.Log.LogInfo((object)("Skute: mast holdfast seated on the deck, moved " + num2.ToString("+0.000;-0.000") + " m."));
				}
				Textures.Load("skute_sail.png", pointFilter: false);
				FaeringBuilder.ApplySail(val16, "skute_sail.png", "sk_skute_sail");
				sails = ((Component)val16).GetComponentsInChildren<SkinnedMeshRenderer>(true);
				Metal51.AddMast(val16, "skute", mats, renderers);
			}
			else
			{
				Plugin.Log.LogWarning((object)"Skute: Longship mast not found.");
			}
			Transform val20 = val2.Find("ropes");
			if (Object.op_Implicit((Object)(object)val20))
			{
				array2 = new string[3] { "mastrope", "left", "right" };
				foreach (string text2 in array2)
				{
					Transform obj6 = val20.Find(text2);
					if (obj6 != null)
					{
						((Component)obj6).gameObject.SetActive(false);
					}
				}
				PlaceSheetPoint(val20, "RopeAttachLeft_bottom_front", W(rig.Point("rope_L_front") + CleatLift));
				PlaceSheetPoint(val20, "RopeAttachLeft_bottom_back", W(rig.Point("rope_L_back") + CleatLift));
				PlaceSheetPoint(val20, "RopeAttachRight_bottom_front", W(rig.Point("rope_R_front") + CleatLift));
				PlaceSheetPoint(val20, "RopeAttachRight_bottom_back", W(rig.Point("rope_R_back") + CleatLift));
			}
			Vector3 val21 = rig.Point("helm_seat");
			Transform val22 = val3.Find("controlls");
			if (Object.op_Implicit((Object)(object)val22))
			{
				val22.position = W(new Vector3(val21.x, val21.y - 0.42f - 0.169f, val21.z));
				val22.rotation = root.rotation;
				val22.localScale = Vector3.one;
				Kill(val22.Find("box"));
				Transform val23 = val22.Find("rudder_button");
				if (Object.op_Implicit((Object)(object)val23))
				{
					val23.localPosition = Vector3.zero;
					val23.localRotation = Quaternion.identity;
					val23.localScale = Vector3.one;
				}
				Transform val24 = val22.Find("attachpoint");
				if (Object.op_Implicit((Object)(object)val24))
				{
					val24.localPosition = new Vector3(0f, 0.169f, 0f);
					val24.localScale = Vector3.one;
				}
				Transform val25 = val22.Find("rudder");
				if (Object.op_Implicit((Object)(object)val25))
				{
					val25.position = W(rig.Point("rudder_pivot"));
					val25.rotation = root.rotation;
					val25.localScale = Vector3.one;
					Transform val26 = val25.Find("Rudder");
					for (int num3 = val25.childCount - 1; num3 >= 0; num3--)
					{
						if ((Object)(object)val25.GetChild(num3) != (Object)(object)val26)
						{
							Object.DestroyImmediate((Object)(object)((Component)val25.GetChild(num3)).gameObject);
						}
					}
					StripRenderer(val25);
					Transform val27 = val25;
					if (Object.op_Implicit((Object)(object)val26))
					{
						FaeringBuilder.ClearChildren(val26);
						StripRenderer(val26);
						val26.localPosition = Vector3.zero;
						val26.localRotation = Quaternion.identity;
						val26.localScale = Vector3.one;
						val27 = val26;
					}
					Mesh val28 = MeshAsset.Load("skute_rudder.skm");
					renderers.Add((Renderer)(object)FaeringBuilder.AddMesh(val27, "sk_rudder", val28, matNew, Vector3.zero));
					Metal51.AddRudder(val27, "skute", mats, renderers);
					FaeringBuilder.FitHelm(root, Object.op_Implicit((Object)(object)val23) ? val23 : val22, val27, val28, root.Find("ControlGui"), HelmUseBox, trigger: true, 0.2f);
				}
			}
			Transform fit = FaeringBuilder.NewChild(root, "sk_fittings");
			FaeringBuilder.SetLayer(fit, 28);
			List<Transform> list2 = new List<Transform>();
			array2 = new string[2] { "sit_box", "sit_box (1)" };
			foreach (string text3 in array2)
			{
				Transform val29 = val3.Find(text3);
				if (Object.op_Implicit((Object)(object)val29))
				{
					list2.Add(val29);
				}
			}
			for (int j = 0; j < list2.Count; j++)
			{
				if (!rig.Points.ContainsKey("stool" + j))
				{
					break;
				}
				Transform obj7 = list2[j];
				Kill(obj7.Find("box"));
				obj7.localScale = Vector3.one;
				obj7.rotation = root.rotation;
				Vector3 val30 = rig.Point("stool" + j);
				FaeringBuilder.PlaceChair(obj7, W(new Vector3(val30.x, val30.y + 0.42f, val30.z)), root);
				BoxCollider component2 = ((Component)obj7).GetComponent<BoxCollider>();
				if (Object.op_Implicit((Object)(object)component2))
				{
					component2.center = new Vector3(0f, 0.334f, 0f);
					component2.size = new Vector3(0.62f, 0.16f, 0.42f);
				}
				Transform val31 = FaeringBuilder.NewChild(fit, "sk_stool_" + j);
				val31.position = W(val30);
				renderers.Add((Renderer)(object)FaeringBuilder.AddMesh(val31, "mesh", array[StoolVariants.Pick(j)], matNew, Vector3.zero));
			}
			array2 = new string[2] { "ladder_right", "ladder_left" };
			foreach (string text4 in array2)
			{
				StripLadderVisual(val3.Find(text4));
			}
			PlaceLadder(val3.Find("ladder_right"), W(rig.Point("ladder_R")), W(rig.Point("ladder_target_R")), root, 90f, rig.Point("ladder_pitch").x);
			PlaceLadder(val3.Find("ladder_left"), W(rig.Point("ladder_L")), W(rig.Point("ladder_target_L")), root, -90f, rig.Point("ladder_pitch").x);
			Container container = null;
			Transform val32 = root.Find("piece_chest");
			if (Object.op_Implicit((Object)(object)val32))
			{
				val32.localScale = Vector3.one;
				val32.rotation = root.rotation;
				val32.position = W(rig.Point("chest0"));
				Transform val33 = val32.Find("visual");
				if (Object.op_Implicit((Object)(object)val33))
				{
					Renderer[] componentsInChildren = ((Component)val33).GetComponentsInChildren<Renderer>(true);
					for (int i = 0; i < componentsInChildren.Length; i++)
					{
						componentsInChildren[i].enabled = false;
					}
				}
				container = ((Component)val32).GetComponent<Container>();
				HoldHatch.Install(fit, "sk_hatch", val32.position, root.rotation, closedMesh, openMesh, matNew, container, (Collider)(object)((Component)val32).GetComponent<BoxCollider>(), renderers, driveLid: true);
			}
			Mesh[] oarMeshes = OarVariants.Load("skute");
			go.AddComponent<SailGuard>();
			OarRower oarRower = go.AddComponent<OarRower>();
			oarRower.m_portCaps = list.ToArray();
			oarRower.m_right = Oar("oar_R_0", left: false, 0);
			oarRower.m_left = Oar("oar_L_0", left: true, 0);
			Transform[] array4 = (Transform[])(object)new Transform[2];
			Transform[] array5 = (Transform[])(object)new Transform[2];
			for (int k = 1; k < 3; k++)
			{
				array4[k - 1] = Oar("oar_R_" + k, left: false, k);
				array5[k - 1] = Oar("oar_L_" + k, left: true, k);
			}
			oarRower.m_extraRight = array4;
			oarRower.m_extraLeft = array5;
			oarRower.m_phaseSpeed = 6.5f;
			oarRower.m_sweep = 24f;
			oarRower.m_dip = 46f;
			oarRower.m_lift = 12f;
			oarRower.m_restAlpha = -50f;
			oarRower.m_restBeta = -6f;
			FaeringBuilder.ScaleEffects(root.Find("watereffects"), 0.6f, 0.62f);
			FaeringBuilder.ScaleEffects(root.Find("ashdamageeffects"), 0.6f, 0.62f);
			FaeringBuilder.FitWaterEffects(root, "watereffects", rig, W);
			Transform val34 = root.Find("watereffects/SpeedWake/rudder");
			if (Object.op_Implicit((Object)(object)val34))
			{
				Vector3 val35 = rig.Point("rudder_pivot");
				val34.position = W(new Vector3(val35.x, -0.15f, val35.z - 0.2f));
			}
			Transform val36 = null;
			Transform val37 = null;
			Renderer val38 = null;
			if (Object.op_Implicit((Object)(object)val16) && Metal51.MastCapTop(val16, "skute", out var worldTop))
			{
				val36 = FaeringBuilder.NewChild(fit, "sk_vane");
				val36.position = worldTop + root.up * 0.296f;
				val36.rotation = root.rotation;
				Metal51.AddVane(val36, "skute", mats, renderers);
				val37 = FaeringBuilder.NewChild(val36, "sk_vane_cloth");
				val38 = (Renderer)(object)FaeringBuilder.AddMesh(val37, "mesh", MeshAsset.Load("skute_pennant.skm"), matNew, Vector3.zero);
				renderers.Add(val38);
				val38.shadowCastingMode = (ShadowCastingMode)0;
			}
			else
			{
				Plugin.Log.LogWarning((object)"Skute: mast top not found; no wind vane.");
			}
			SkuteShip skuteShip = go.AddComponent<SkuteShip>();
			skuteShip.m_container = container;
			skuteShip.m_sails = sails;
			skuteShip.m_vane = val36;
			skuteShip.m_vaneCloth = val37;
			skuteShip.m_vaneRenderers = (Renderer[])(Object.op_Implicit((Object)(object)val36) ? ((Array)((Component)val36).GetComponentsInChildren<Renderer>(true)) : ((Array)new Renderer[0]));
			skuteShip.m_clothRenderer = val38;
			LODGroup component3 = go.GetComponent<LODGroup>();
			if (Object.op_Implicit((Object)(object)component3))
			{
				Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val39 in componentsInChildren)
				{
					if (!(val39 is ParticleSystemRenderer) && !(val39 is LineRenderer) && !renderers.Contains(val39))
					{
						renderers.Add(val39);
					}
				}
				component3.SetLODs((LOD[])(object)new LOD[1]
				{
					new LOD(0.02f, renderers.ToArray())
				});
				component3.RecalculateBounds();
			}
			FaeringBuilder.SetLayer(val14, 28);
			Rigidbody component4 = go.GetComponent<Rigidbody>();
			if (Object.op_Implicit((Object)(object)component4))
			{
				component4.mass = 1000f;
			}
			Ship component5 = go.GetComponent<Ship>();
			if (Object.op_Implicit((Object)(object)component5))
			{
				component5.m_minWaterImpactForce = 8f;
			}
			Transform Oar(string pt, bool left, int pair)
			{
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				Transform val40 = FaeringBuilder.NewChild(fit, "sk_oar_" + pt);
				val40.position = W(rig.Point(pt));
				if (left)
				{
					val40.localRotation = Quaternion.Euler(0f, 180f, 0f);
				}
				renderers.Add((Renderer)(object)FaeringBuilder.AddMesh(val40, "mesh", oarMeshes[OarVariants.Pick(pair, left)], matNew, Vector3.zero));
				FaeringBuilder.SetLayer(val40, 28);
				return val40;
			}
			Vector3 W(Vector3 local)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				return root.TransformPoint(local);
			}
		}

		private static void ReplaceMastMesh(Transform mast)
		{
			//IL_0069: 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)
			Transform val = mast.Find("mast");
			MeshFilter val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponentInChildren<MeshFilter>(true) : null);
			MeshRenderer val3 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponentInChildren<MeshRenderer>(true) : null);
			if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val3))
			{
				Plugin.Log.LogWarning((object)"Skute: Longship mast mesh not found; keeping it.");
				return;
			}
			Material baseMat = (Material)(Object.op_Implicit((Object)(object)((Renderer)val3).sharedMaterial) ? ((object)((Renderer)val3).sharedMaterial) : ((object)new Material(Shader.Find("Standard"))));
			val2.sharedMesh = MeshAsset.Load("skute_mast.skm");
			((Renderer)val3).sharedMaterial = Textures.CloneWood(baseMat, Textures.Load("skute_mast.png"), "sk_skute_mast");
			string[] array = new string[2] { "RopeAttachLeft", "RopeAttachRight" };
			foreach (string text in array)
			{
				Transform val4 = DeepFindChild(mast, text);
				if (Object.op_Implicit((Object)(object)val4))
				{
					val4.localPosition = new Vector3(-0.215f, 3.475f, (text == "RopeAttachLeft") ? (-1.99f) : 1.99f);
				}
			}
		}

		private static Transform DeepFindChild(Transform t, string name)
		{
			if (((Object)t).name == name)
			{
				return t;
			}
			for (int i = 0; i < t.childCount; i++)
			{
				Transform val = DeepFindChild(t.GetChild(i), name);
				if (Object.op_Implicit((Object)(object)val))
				{
					return val;
				}
			}
			return null;
		}

		private static bool MastFoot(Transform mast, Transform root, out Vector3 foot)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			foot = Vector3.zero;
			Transform val = mast.Find("mast");
			MeshFilter val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponentInChildren<MeshFilter>(true) : null);
			if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val2.sharedMesh))
			{
				return false;
			}
			Bounds bounds = val2.sharedMesh.bounds;
			float num = float.MaxValue;
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(float.MaxValue, 0f, float.MaxValue);
			Vector3 val4 = default(Vector3);
			((Vector3)(ref val4))..ctor(float.MinValue, 0f, float.MinValue);
			Vector3 val5 = default(Vector3);
			for (int i = 0; i < 8; i++)
			{
				((Vector3)(ref val5))..ctor(((i & 1) == 0) ? ((Bounds)(ref bounds)).min.x : ((Bounds)(ref bounds)).max.x, ((i & 2) == 0) ? ((Bounds)(ref bounds)).min.y : ((Bounds)(ref bounds)).max.y, ((i & 4) == 0) ? ((Bounds)(ref bounds)).min.z : ((Bounds)(ref bounds)).max.z);
				Vector3 val6 = root.InverseTransformPoint(((Component)val2).transform.TransformPoint(val5));
				num = Mathf.Min(num, val6.y);
				val3 = Vector3.Min(val3, val6);
				val4 = Vector3.Max(val4, val6);
			}
			foot = new Vector3((val3.x + val4.x) * 0.5f, num, (val3.z + val4.z) * 0.5f);
			return true;
		}

		private static Transform Compensated(Transform parent, string name, Transform root)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			Transform obj = FaeringBuilder.NewChild(parent, name);
			obj.rotation = root.rotation;
			Vector3 lossyScale = parent.lossyScale;
			obj.localScale = new Vector3(1f / lossyScale.x, 1f / lossyScale.y, 1f / lossyScale.z);
			obj.position = root.position;
			return obj;
		}

		private static void StripLadderVisual(Transform ladder)
		{
			if (!Object.op_Implicit((Object)(object)ladder))
			{
				return;
			}
			StripRenderer(ladder);
			for (int num = ladder.childCount - 1; num >= 0; num--)
			{
				Transform child = ladder.GetChild(num);
				if (((Object)child).name != "ladder_TargetPoint" && Object.op_Implicit((Object)(object)((Component)child).GetComponentInChildren<Renderer>(true)))
				{
					Kill(child);
				}
			}
		}

		private static void PlaceLadder(Transform ladder, Vector3 pos, Vector3 target, Transform root, float yaw, float pitch = 0f)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)ladder))
			{
				Transform val = ladder.Find("ladder_TargetPoint");
				Quaternion val2 = (ladder.rotation = root.rotation * Quaternion.Euler(0f, yaw, 0f));
				ladder.position = pos;
				Quaternion rotation = (Object.op_Implicit((Object)(object)val) ? val.rotation : Quaternion.identity);
				if (Mathf.Abs(pitch) > 0.01f)
				{
					ladder.rotation = val2 * Quaternion.Euler(pitch, 0f, 0f);
				}
				if (Object.op_Implicit((Object)(object)val))
				{
					val.rotation = rotation;
					val.position = target + root.up * 0.1f;
				}
			}
		}

		private static void PlaceSheetPoint(Transform ropes, string namePrefix, Vector3 world)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			Transform val = FaeringBuilder.FindPrefix(ropes, namePrefix);
			if (Object.op_Implicit((Object)(object)val))
			{
				val.position = world;
			}
			else
			{
				Plugin.Log.LogWarning((object)("Skute: sheet attach point '" + namePrefix + "' not found."));
			}
		}

		private static void StripRenderer(Transform t)
		{
			MeshRenderer component = ((Component)t).GetComponent<MeshRenderer>();
			if (Object.op_Implicit((Object)(object)component))
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			MeshFilter component2 = ((Component)t).GetComponent<MeshFilter>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				Object.DestroyImmediate((Object)(object)component2);
			}
		}

		private static void Kill(Transform t)
		{
			if (Object.op_Implicit((Object)(object)t))
			{
				Object.DestroyImmediate((Object)(object)((Component)t).gameObject);
			}
		}
	}
	internal static class SkuteConfig
	{
		public static ConfigEntry<bool> CargoAffectsSpeed;

		public static ConfigEntry<float> SpeedMultiplier;

		public static ConfigEntry<bool> ShowWindVane;

		public static void Bind(ConfigFile cfg)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			CargoAffectsSpeed = cfg.Bind<bool>("Skute", "CargoAffectsSpeed", true, ModConfig.Synced("The Skute is built to travel light: every slot of its dispatch chest that holds something costs about 2 % of top speed (up to 6 % with all 3 slots in use). Turn it off for a ship that is just as fast loaded as empty. Skute only."));
			SpeedMultiplier = cfg.Bind<float>("Skute", "SpeedMultiplier", 1f, ModConfig.Synced("A single dial for how fast the Skute is, from 0.5 (half speed) to 1.0 (the normal 12.5 m/s under sail, 3.0 m/s rowing). Scales sailing and rowing together. For servers that find the Skute too quick. Skute only.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 1f)));
			ShowWindVane = cfg.Bind<bool>("Skute", "ShowWindVane", true, new ConfigDescription("Show the small iron wind vane and swallow-tail pennant at the masthead. It points where the wind is blowing and hangs limp in a calm. A looks-only setting that each player can choose for themselves.", (AcceptableValueBase)null, Array.Empty<object>()));
		}
	}
	internal static class SkuteEyes
	{
		public const string AlbedoFile = "skute_eyes.png";

		public const string GlowFile = "skute_eyes_glow.png";

		public const float EmissionLevel = 0.65f;

		public static Material Make(Material hullBase)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(hullBase)
			{
				name = "sk_skute_eyes"
			};
			val.shaderKeywords = new string[0];
			Texture2D val2 = Textures.Load("skute_eyes.png");
			if (val.HasProperty("_MainTex"))
			{
				val.SetTexture("_MainTex", (Texture)(object)val2);
			}
			val.mainTexture = (Texture)(object)val2;
			val.mainTextureScale = Vector2.one;
			val.mainTextureOffset = Vector2.zero;
			string[] array = new string[6] { "_BumpMap", "_MetallicGlossMap", "_EmissionMap", "_OcclusionMap", "_DetailAlbedoMap", "_DetailNormalMap" };
			foreach (string text in array)
			{
				if (val.HasProperty(text))
				{
					val.SetTexture(text, (Texture)null);
				}
			}
			if (val.HasProperty("_Color"))
			{
				val.SetColor("_Color", Color.white);
			}
			if (val.HasProperty("_EmissionMap"))
			{
				val.SetTexture("_EmissionMap", (Texture)(object)Textures.Load("skute_eyes_glow.png"));
			}
			if (val.HasProperty("_EmissionColor"))
			{
				val.SetColor("_EmissionColor", new Color(0.65f, 0.65f, 0.65f, 1f));
			}
			if (val.HasProperty("_Metallic"))
			{
				val.SetFloat("_Metallic", 0f);
			}
			if (val.HasProperty("_Glossiness"))
			{
				val.SetFloat("_Glossiness", 0.25f);
			}
			if (val.HasProperty("_ValueNoise"))
			{
				val.SetFloat("_ValueNoise", 0f);
			}
			if (val.HasProperty("_ValueNoiseVertex"))
			{
				val.SetFloat("_ValueNoiseVertex", 0f);
			}
			if (val.HasProperty("_TriplanarMap"))
			{
				val.SetFloat("_TriplanarMap", 0f);
			}
			return val;
		}
	}
	public class SkuteShip : MonoBehaviour
	{
		public Container m_container;

		public SkinnedMeshRenderer[] m_sails;

		public Transform m_vane;

		public Transform m_vaneCloth;

		public Renderer m_clothRenderer;

		public Renderer[] m_vaneRenderers;

		public const float SlowdownPerSlot = 0.02f;

		public const float MaxSlowdown = 0.06f;

		private const float DroopDegrees = 62f;

		private const float NearSqr = 900f;

		private const float FarSqr = 10000f;

		private const float NearInterval = 1f / 30f;

		private const float MidInterval = 1f / 12f;

		private const float HiddenInterval = 0.2f;

		private const float FarInterval = 0.4f;

		private const float YawWriteStep = 0.05f;

		private Ship m_ship;

		private float m_yaw;

		private float m_droop = 62f;

		private float m_phase;

		private float m_nextTick;

		private float m_lastTick;

		private float m_yawWritten = float.NaN;

		private Quaternion m_baseLocal = Quaternion.identity;

		private PennantCloth m_cloth;

		private bool m_clothTried;

		private bool m_hooked;

		private ShipDefinition m_def;

		private void Awake()
		{
			m_ship = ((Component)this).GetComponent<Ship>();
			m_phase = Random.value * 10f;
		}

		private void Start()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_002c: 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)
			Hook();
			if (Object.op_Implicit((Object)(object)m_vane))
			{
				m_baseLocal = (Object.op_Implicit((Object)(object)m_vane.parent) ? (Quaternion.Inverse(m_vane.parent.rotation) * ((Component)this).transform.rotation) : ((Component)this).transform.rotation);
			}
			Refresh();
			((MonoBehaviour)this).InvokeRepeating("Refresh", 1f + Random.value, 1f);
		}

		private void OnDestroy()
		{
			if (m_cloth != null)
			{
				m_cloth.Dispose();
				m_cloth = null;
			}
			if (m_hooked && (Object)(object)m_container != (Object)null)
			{
				Inventory inventory = m_container.GetInventory();
				if (inventory != null)
				{
					inventory.m_onChanged = (Action)Delegate.Remove(inventory.m_onChanged, new Action(Refresh));
				}
			}
		}

		private void Hook()
		{
			if (!m_hooked && Object.op_Implicit((Object)(object)m_container))
			{
				Inventory inventory = m_container.GetInventory();
				if (inventory != null)
				{
					inventory.m_onChanged = (Action)Delegate.Combine(inventory.m_onChanged, new Action(Refresh));
					m_hooked = true;
				}
			}
		}

		public static float CargoFactor(int usedSlots)
		{
			return 1f - Mathf.Min(0.06f, 0.02f * (float)Mathf.Max(0, usedSlots));
		}

		private void Refresh()
		{
			if (!Object.op_Implicit((Object)(object)this))
			{
				return;
			}
			Hook();
			int usedSlots = 0;
			if (Object.op_Implicit((Object)(object)m_container) && m_container.GetInventory() != null)
			{
				usedSlots = m_container.GetInventory().GetAllItems().Count;
			}
			if (Object.op_Implicit((Object)(object)m_ship))
			{
				ShipDefinition shipDefinition = m_def ?? (m_def = ShipRegistry.For(((Component)this).gameObject));
				if (shipDefinition != null)
				{
					float num = (SkuteConfig.CargoAffectsSpeed.Value ? CargoFactor(usedSlots) : 1f) * Mathf.Clamp(SkuteConfig.SpeedMultiplier.Value, 0.5f, 1f);
					ShipStats stats = shipDefinition.Config.Stats;
					float num2 = stats.SailForce * num * num;
					float num3 = stats.RowForce * num * num;
					if (Mathf.Abs(m_ship.m_sailForceFactor - num2) > 1E-06f)
					{
						m_ship.m_sailForceFactor = num2;
					}
					if (Mathf.Abs(m_ship.m_backwardForce - num3) > 1E-06f)
					{
						m_ship.m_backwardForce = num3;
					}
				}
			}
			bool value = SkuteConfig.ShowWindVane.Value;
			if (m_vaneRenderers == null)
			{
				return;
			}
			Renderer[] vaneRenderers = m_vaneRenderers;
			foreach (Renderer val in vaneRenderers)
			{
				if (Object.op_Implicit((Object)(object)val) && val.enabled != value)
				{
					val.enabled = value;
				}
			}
		}

		private void LateUpdate()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			float time = Time.time;
			if (time < m_nextTick)
			{
				return;
			}
			if (!Object.op_Implicit((Object)(object)m_vane) || !Object.op_Implicit((Object)(object)m_clothRenderer) || !m_clothRenderer.enabled || (Object)(object)EnvMan.instance == (Object)null)
			{
				m_nextTick = time + 0.2f;
				return;
			}
			if (!m_clothRenderer.isVisible)
			{
				m_nextTick = time + 0.2f;
				return;
			}
			Camera mainCamera = Utils.GetMainCamera();
			float num;
			if (!Object.op_Implicit((Object)(object)mainCamera))
			{
				num = 0f;
			}
			else
			{
				Vector3 val = ((Component)mainCamera).transform.position - m_vane.position;
				num = ((Vector3)(ref val)).sqrMagnitude;
			}
			float num2 = num;
			if (num2 > 10000f)
			{
				m_nextTick = time + 0.4f;
				return;
			}
			m_nextTick = time + ((num2 < 900f) ? (1f / 30f) : (1f / 12f));
			float num3 = Mathf.Clamp(time - m_lastTick, 0.001f, 0.25f);
			m_lastTick = time;
			if (!m_clothTried)
			{
				m_clothTried = true;
				m_cloth = PennantCloth.Create(((Component)m_clothRenderer).GetComponent<MeshFilter>());
			}
			Vector3 val2 = ((Component)this).transform.InverseTransformDirection(EnvMan.instance.GetWindDir());
			val2.y = 0f;
			float num4 = Mathf.Clamp01(EnvMan.instance.GetWindIntensity());
			if (((Vector3)(ref val2)).sqrMagnitude > 0.0001f)
			{
				float num5 = Mathf.Atan2(val2.x, val2.z) * 57.29578f;
				m_yaw = Mathf.LerpAngle(m_yaw, num5, 1f - Mathf.Exp(-2.5f * num3));
			}
			float num6 = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.1f, 0.45f, num4));
			m_droop = Mathf.Lerp(m_droop, 62f * (1f - num6), 1f - Mathf.Exp(-3f * num3));
			if (float.IsNaN(m_yawWritten) || Mathf.Abs(Mathf.DeltaAngle(m_yawWritten, m_yaw)) > 0.05f)
			{
				m_yawWritten = m_yaw;
				m_vane.localRotation = m_baseLocal * Quaternion.Euler(0f, m_yaw, 0f);
			}
			if (m_cloth != null)
			{
				m_cloth.Step(time + m_phase, num6, m_droop);
			}
		}
	}
}
namespace Saekonungr.Skeide
{
	internal static class SkeideBuilder
	{
		public static readonly HullPhysics Physics = new HullPhysics
		{
			WaterLevelOffset = 0.6f,
			Force = 1f,
			ForceDistance = 2f,
			SailForceOffset = 0.6f,
			SteerForceOffset = -8f,
			RudderSpeed = 1f,
			AngularDamping = 0.2f,
			CenterOfMass = new Vector3(0f, -0.15f, 0f)
		};

		public const float DeckHeight = 0.2f;

		private const float MastFootBelowOrigin = 0.11f;

		private const float ChestSeatTop = 0.42f;

		private const float HatchX = 0f;

		private const float HatchZ = 6.2f;

		private const int Rowers = 5;

		public static void Build(GameObject go, ShipDefinition def)
		{
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0512: Unknown result type (might be due to invalid IL or missing references)
			//IL_052d: Unknown result type (might be due to invalid IL or missing references)
			//IL_055b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0560: Unknown result type (might be due to invalid IL or missing references)
			//IL_0564: Unknown result type (might be due to invalid IL or missing references)
			//IL_0569: Unknown result type (might be due to invalid IL or missing references)
			//IL_056e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0575: Unknown result type (might be due to invalid IL or missing references)
			//IL_0582: Unknown result type (might be due to invalid IL or missing references)
			//IL_0589: Unknown result type (might be due to invalid IL or missing references)
			//IL_058e: Unknown result type (might be due to invalid IL or missing references)
			//IL_059a: Unknown result type (might be due to invalid IL or missing references)
			//IL_059f: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0712: Unknown result type (might be due to invalid IL or missing references)
			//IL_0717: Unknown result type (might be due to invalid IL or missing references)
			//IL_0735: Unknown result type (might be due to invalid IL or missing references)
			//IL_073c: Unknown result type (might be due to invalid IL or missing references)
			//IL_074f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0756: Unknown result type (might be due to invalid IL or missing references)
			//IL_075b: Unknown result type (might be due to invalid IL or missing references)
			//IL_076d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0779: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b9: 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_06a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0803: Unknown result type (might be due to invalid IL or missing references)
			//IL_0835: Unknown result type (might be due to invalid IL or missing references)
			//IL_083a: Unknown result type (might be due to invalid IL or missing references)
			//IL_084c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0858: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a85: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a96: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ab7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0abc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ac0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ac7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0adb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ae0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0918: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_08dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bbc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bc1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bdc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c02: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c07: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c18: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c1d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c38: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b11: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b2c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c67: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c79: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c8e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ca9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0964: Unknown result type (might be due to invalid IL or missing references)
			//IL_0974: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d0d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d18: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d7a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d7f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0da6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f58: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f5d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f62: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f6e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f7b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f80: Unknown result type (might be due to invalid IL or missing references)
			//IL_1009: Unknown result type (might be due to invalid IL or missing references)
			//IL_100e: Unknown result type (might be due to invalid IL or missing references)
			Transform root = go.transform;
			Rig rig = Rig.Load("skeide_rig.txt");
			Transform val = FaeringBuilder.Need(root, "ship");
			Transform val2 = FaeringBuilder.Need(val, "visual");
			Transform val3 = FaeringBuilder.Need(root, "interactive");
			MeshRenderer val4 = FaeringBuilder.Find<MeshRenderer>(val2, "hull_new");
			MeshRenderer val5 = FaeringBuilder.Find<MeshRenderer>(val2, "watermask");
			Transform obj = val.Find("colliders");
			Collider val6 = ((obj != null) ? ((Component)obj).GetComponentInChildren<Collider>(true) : null);
			Material val7 = (Object.op_Implicit((Object)(object)val4) ? ((Renderer)val4).sharedMaterial : null);
			Material val8 = (Object.op_Implicit((Object)(object)val5) ? ((Renderer)val5).sharedMaterial : null);
			PhysicsMaterial val9 = (Object.op_Implicit((Object)(object)val6) ? val6.sharedMaterial : null);
			if (!Object.op_Implicit((Object)(object)val7))
			{
				Plugin.Log.LogWarning((object)"Skeide: Longship hull material not found, using Standard.");
				val7 = new Material(Shader.Find("Standard"));
			}
			Material matNew = Textures.CloneWood(val7, Textures.Load("skeide_albedo.png"), "sk_skeide_new");
			Material item = Textures.CloneWood(val7, Textures.Weathered("skeide_albedo.png", 0.86f, 0.25f), "sk_skeide_worn");
			Material item2 = Textures.CloneWood(val7, Textures.Weathered("skeide_albedo.png", 0.7f, 0.45f), "sk_skeide_broken");
			Mesh mesh = MeshAsset.Load("skeide_hull.skm");
			Mesh mesh2 = MeshAsset.Load("skeide_watermask.skm");
			Mesh closedMesh = MeshAsset.Load("skeide_hatch.skm");
			Mesh openMesh = MeshAsset.Load("skeide_hatch_open.skm");
			Mesh[] array = StoolVariants.Load("skeide");
			List<Renderer> renderers = new List<Renderer>();
			string[] array2 = new string[3] { "Customize", "unused", "watermask" };
			foreach (string text in array2)
			{
				Kill(val2.Find(text));
			}
			Kill(val.Find("colliders"));
			Kill(val3.Find("front"));
			Kill(val3.Find("sit_box (4)"));
			Metal51Mats mats = Metal51.Make(val7, "skeide");
			List<Renderer> list = new List<Renderer>();
			Mesh mesh3 = MeshAsset.Load("skeide_portcaps.skm");
			int num = 0;
			(string, Material)[] array3 = new(string, Material)[3]
			{
				("hull_new", matNew),
				("hull_worn", item),
				("hull_broken", item2)
			};
			for (int i = 0; i < array3.Length; i++)
			{
				(string, Material) tuple = array3[i];
				string item3 = tuple.Item1;
				Material item4 = tuple.Item2;
				Transform val10 = val2.Find(item3);
				if (!Object.op_Implicit((Object)(object)val10))
				{
					Plugin.Log.LogWarning((object)("Skeide: missing " + item3));
					continue;
				}
				FaeringBuilder.ClearChildren(val10);
				StripRenderer(val10);
				Transform val11 = Compensated(val10, "sk_" + item3, root);
				renderers.Add((Renderer)(object)FaeringBuilder.AddMesh(val11, "sk_hull", mesh, item4, Vector3.zero));
				MeshRenderer val12 = FaeringBuilder.AddMesh(val11, "sk_portcaps", mesh3, item4, Vector3.zero);
				((Renderer)val12).enabled = false;
				list.Add((Renderer)(object)val12);
				renderers.Add((Renderer)(object)val12);
				Metal51.AddHull(val11, "skeide", mats, num++, renderers);
				if (Object.op_Implicit((Object)(object)val8))
				{
					MeshRenderer obj2 = FaeringBuilder.AddMesh(val11, "sk_watermask", mesh2, val8, Vector3.zero);
					((Renderer)obj2).shadowCastingMode = (ShadowCastingMode)0;
					((Renderer)obj2).receiveShadows = false;
				}
			}
			Transform val13 = FaeringBuilder.NewChild(root, "sk_colliders");
			((Component)val13).gameObject.layer = 28;
			foreach (Rig.Box box in rig.Boxes)
			{
				Transform obj3 = FaeringBuilder.NewChild(val13, "col_" + box.Name);
				obj3.position = W(box.Center);
				obj3.rotation = root.rotation * Quaternion.Euler(0f, box.Yaw, 0f);
				BoxCollider obj4 = ((Component)obj3).gameObject.AddComponent<BoxCollider>();
				obj4.size = box.Size;
				((Collider)obj4).sharedMaterial = val9;
			}
			HullColliders.Build(root, root, rig, val9, 28);
			Transform obj5 = FaeringBuilder.Need(root, "FloatCollider");
			BoxCollider component = ((Component)obj5).GetComponent<BoxCollider>();
			obj5.localPosition = Vector3.zero;
			obj5.localRotation = Quaternion.identity;
			obj5.localScale = Vector3.one;
			component.size = rig.Point("float_size");
			component.center = rig.Point("float_center");
			Transform val14 = root.Find("OnboardTrigger");
			if (Object.op_Implicit((Object)(object)val14))
			{
				val14.localPosition = new Vector3(0f, 1.1f, 0f);
				val14.localScale = new Vector3(4.4f, 3.2f, 20.5f);
			}
			Transform val15 = val2.Find("Mast");
			if (Object.op_Implicit((Object)(object)val15))
			{
				Vector3 val16 = rig.Point("mast_step");
				Vector3 position = val15.position;
				val15.position = W(new Vector3(val16.x, val16.y + 0.11f, val16.z));
				Vector3 val17 = val15.position - position;
				Transform val18 = val3.Find("mast");
				if (Object.op_Implicit((Object)(object)val18))
				{
					val18.position += val17;
					float num2 = Holdfast.SeatOnDeck(root, val18, rig, 0.026f, "Skeide");
					Plugin.Log.LogInfo((object)("Skeide: mast holdfast seated on the deck, moved " + num2.ToString("+0.000;-0.000") + " m."));
				}
				FaeringBuilder.ApplySail(val15, "skeide_sail.png", "sk_skeide_sail");
				Metal51.AddMast(val15, "skeide", mats, renderers);
			}
			else
			{
				Plugin.Log.LogWarning((object)"Skeide: Longship mast not found.");
			}
			Transform val19 = val2.Find("ropes");
			if (Object.op_Implicit((Object)(object)val19))
			{
				Transform obj6 = val19.Find("mastrope");
				if (obj6 != null)
				{
					((Component)obj6).gameObject.SetActive(false);
				}
				FaeringBuilder.SetupRope(val19, "left", "RopeAttachLeft_bottom_front", "RopeAttachLeft_bottom_back", W(rig.Point("rope_L_front")), W(rig.Point("rope_L_back")));
				FaeringBuilder.SetupRope(val19, "right", "RopeAttachRight_bottom_front", "RopeAttachRight_bottom_back", W(rig.Point("rope_R_front")), W(rig.Point("rope_R_back")));
			}
			Vector3 val20 = rig.Point("helm_seat");
			Transform val21 = val3.Find("controlls");
			if (Object.op_Implicit((Object)(object)val21))
			{
				val21.position = W(new Vector3(val20.x, val20.y - 0.42f - 0.169f, val20.z));
				val21.rotation = root.rotation;
				val21.localScale = Vector3.one;
				Kill(val21.Find("box"));
				Transform val22 = val21.Find("rudder_button");
				if (Object.op_Implicit((Object)(object)val22))
				{
					val22.localPosition = Vector3.zero;
					val22.localRotation = Quaternion.identity;
					val22.localScale = Vector3.one;
				}
				Transform val23 = val21.Find("attachpoint");
				if (Object.op_Implicit((Object)(object)val23))
				{
					val23.localPosition = new Vector3(0f, 0.169f, 0f);
					val23.localScale = Vector3.one;
				}
				Transform val24 = val21.Find("rudder");
				if (Object.op_Implicit((Object)(object)val24))
				{
					val24.position = W(rig.Point("rudder_pivot"));
					val24.rotation = root.rotation;
					val24.localScale = Vector3.one;
					Transform val25 = val24.Find("Rudder");
					for (int num3 = val24.childCount - 1; num3 >= 0; num3--)
					{
						if ((Object)(object)val24.GetChild(num3) != (Object)(object)val25)
						{
							Object.DestroyImmediate((Object)(object)((Component)val24.GetChild(num3)).gameObject);
						}
					}
					StripRenderer(val24);
					Transform val26 = val24;
					if (Object.op_Implicit((Object)(object)val25))
					{
						FaeringBuilder.ClearChildren(val25);
						StripRenderer(val25);
						val25.localPosition = Vector3.zero;
						val25.localRotation = Quaternion.identity;
						val25.localScale = Vector3.one;
						val26 = val25;
					}
					Mesh val27 = MeshAsset.Load("skeide_rudder.skm");
					renderers.Add((Renderer)(object)FaeringBuilder.AddMesh(val26, "sk_rudder", val27, matNew, Vector3.zero));
					Metal51.AddRudder(val26, "skeide", mats, renderers);
					FaeringBuilder.FitHelm(root, Object.op_Implicit((Object)(object)val22) ? val22 : val21, val26, val27, root.Find("ControlGui"), FaeringBuilder.HelmUseBox, trigger: true);
				}
			}
			Transform fit = FaeringBuilder.NewChild(root, "sk_fittings");
			FaeringBuilder.SetLayer(fit, 28);
			List<Transform> list2 = new List<Transform>();
			array2 = new string[4] { "sit_box", "sit_box (1)", "sit_box (2)", "sit_box (3)" };
			foreach (string text2 in array2)
			{
				Transform val28 = val3.Find(text2);
				if (Object.op_Implicit((Object)(object)val28))
				{
					list2.Add(val28);
				}
			}
			if (list2.Count > 0)
			{
				Transform val29 = list2[0];
				for (int j = list2.Count; j < 10; j++)
				{
					GameObject val30 = Object.Instantiate<GameObject>(((Component)val29).gameObject, val3, true);
					((Object)val30).name = "sk_sit_box_" + j;
					list2.Add(val30.transform);
				}
			}
			for (int k = 0; k < list2.Count && k < 10; k++)
			{
				Transform obj7 = list2[k];
				Kill(obj7.Find("box"));
				obj7.localScale = Vector3.one;
				obj7.rotation = root.rotation;
				Vector3 val31 = rig.Point("chest" + k);
				FaeringBuilder.PlaceChair(obj7, W(new Vector3(val31.x, val31.y + 0.42f, val31.z)), root);
				BoxCollider component2 = ((Component)obj7).GetComponent<BoxCollider>();
				if (Object.op_Implicit((Object)(object)component2))
				{
					component2.center = new Vector3(0f, 0.334f, 0f);
					component2.size = new Vector3(0.62f, 0.16f, 0.42f);
				}
			}
			array2 = new string[2] { "ladder_right", "ladder_left" };
			foreach (string text3 in array2)
			{
				StripLadderVisual(val3.Find(text3));
			}
			PlaceLadder(val3.Find("ladder_right"), W(rig.Point("ladder_R")), W(rig.Point("ladder_target_R")), root, 90f, rig.Point("ladder_pitch").x);
			PlaceLadder(val3.Find("ladder_left"), W(rig.Point("ladder_L")), W(rig.Point("ladder_target_L")), root, -90f, rig.Point("ladder_pitch").x);
			Transform val32 = root.Find("piece_chest");
			if (Object.op_Implicit((Object)(object)val32))
			{
				val32.localScale = Vector3.one;
				val32.rotation = root.rotation;
				float y = rig.Point("deck").y;
				val32.position = W(new Vector3(0f, y, 6.2f));
				Transform val33 = val32.Find("visual");
				if (Object.op_Implicit((Object)(object)val33))
				{
					Renderer[] componentsInChildren = ((Component)val33).GetComponentsInChildren<Renderer>(true);
					for (int i = 0; i < componentsInChildren.Length; i++)
					{
						componentsInChildren[i].enabled = false;
					}
				}
				Container component3 = ((Component)val32).GetComponent<Container>();
				HoldHatch.Install(fit, "sk_hatch", val32.position, root.rotation, closedMesh, openMesh, matNew, component3, (Collider)(object)((Component)val32).GetComponent<BoxCollider>(), renderers, driveLid: true);
			}
			for (int l = 0; l < 10; l++)
			{
				Transform val34 = FaeringBuilder.NewChild(fit, "sk_chest_" + l);
				val34.position = W(rig.Point("chest" + l));
				renderers.Add((Renderer)(object)FaeringBuilder.AddMesh(val34, "mesh", array[StoolVariants.Pick(l)], matNew, Vector3.zero));
			}
			Mesh[] oarMeshes = OarVariants.Load("skeide");
			go.AddComponent<SailGuard>();
			OarRower oarRower = go.AddComponent<OarRower>();
			oarRower.m_portCaps = list.ToArray();
			oarRower.m_right = Oar("oar_R_0", left: false, 0);
			oarRower.m_left = Oar("oar_L_0", left: true, 0);
			Transform[] array4 = (Transform[])(object)new Transform[4];
			Transform[] array5 = (Transform[])(object)new Transform[4];
			for (int m = 1; m < 5; m++)
			{
				array4[m - 1] = Oar("oar_R_" + m, left: false, m);
				array5[m - 1] = Oar("oar_L_" + m, left: true, m);
			}
			oarRower.m_extraRight = array4;
			oarRower.m_extraLeft = array5;
			oarRower.m_phaseSpeed = 7.5f;
			oarRower.m_sweep = 24f;
			oarRower.m_dip = 30f;
			oarRower.m_lift = 10f;
			oarRower.m_restAlpha = -48f;
			oarRower.m_restBeta = -4f;
			FaeringBuilder.ScaleEffects(root.Find("watereffects"), 0.8f, 1f);
			FaeringBuilder.ScaleEffects(root.Find("ashdamageeffects"), 0.8f, 1f);
			FaeringBuilder.FitWaterEffects(root, "watereffects", rig, W);
			Transform val35 = root.Find("watereffects/SpeedWake/rudder");
			if (Object.op_Implicit((Object)(object)val35))
			{
				Vector3 val36 = rig.Point("rudder_pivot");
				val35.position = W(new Vector3(val36.x, -0.15f, val36.z - 0.2f));
			}
			LODGroup component4 = go.GetComponent<LODGroup>();
			if (Object.op_Implicit((Object)(object)component4))
			{
				Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val37 in componentsInChildren)
				{
					if (!(val37 is ParticleSystemRenderer) && !(val37 is LineRenderer) && !renderers.Contains(val37))
					{
						renderers.Add(val37);
					}
				}
				component4.SetLODs((LOD[])(object)new LOD[1]
				{
					new LOD(0.02f, renderers.ToArray())
				});
				component4.RecalculateBounds();
			}
			FaeringBuilder.SetLayer(val13, 28);
			Rigidbody component5 = go.GetComponent<Rigidbody>();
			if (Object.op_Implicit((Object)(object)component5))
			{
				component5.mass = 2000f;
			}
			Ship component6 = go.GetComponent<Ship>();
			if (Object.op_Implicit((Object)(object)component6))
			{
				component6.m_minWaterImpactForce = 4f;
			}
			Transform Oar(string pt, bool left, int pair)
			{
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				Transform val38 = FaeringBuilder.NewChild(fit, "sk_oar_" + pt);
				val38.position = W(rig.Point(pt));
				if (left)
				{
					val38.localRotation = Quaternion.Euler(0f, 180f, 0f);
				}
				renderers.Add((Renderer)(object)FaeringBuilder.AddMesh(val38, "mesh", oarMeshes[OarVariants.Pick(pair, left)], matNew, Vector3.zero));
				FaeringBuilder.SetLayer(val38, 28);
				return val38;
			}
			Vector3 W(Vector3 local)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				return root.TransformPoint(local);
			}
		}

		private static Transform Compensated(Transform parent, string name, Transform root)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			Transform obj = FaeringBuilder.NewChild(parent, name);
			obj.rotation = root.rotation;
			Vector3 lossyScale = parent.lossyScale;
			obj.localScale = new Vector3(1f / lossyScale.x, 1f / lossyScale.y, 1f / lossyScale.z);
			obj.position = root.position;
			return obj;
		}

		private static void StripLadderVisual(Transform ladder)
		{
			if (!Object.op_Implicit((Object)(object)ladder))
			{
				return;
			}
			StripRenderer(ladder);
			for (int num = ladder.childCount - 1; num >= 0; num--)
			{
				Transform child = ladder.GetChild(num);
				if (((Object)child).name != "ladder_TargetPoint" && Object.op_Implicit((Object)(object)((Component)child).GetComponentInChildren<Renderer>(true)))
				{
					Kill(child);
				}
			}
		}

		private static void PlaceLadder(Transform ladder, Vector3 pos, Vector3 target, Transform root, float yaw, float pitch = 0f)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing