Decompiled source of Warship v1.0.0

plugins/Drakenschip.dll

Decompiled 5 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
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 Unity.Collections;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Drakenschip")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Drakenschip")]
[assembly: AssemblyTitle("Drakenschip")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Drakenschip
{
	[BepInPlugin("optiekuniek.drakenschip", "Warship", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	internal class DrakenschipPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "optiekuniek.drakenschip";

		public const string PluginName = "Warship";

		public const string PluginVersion = "1.0.0";

		private const string BasisSchip = "VikingShip";

		private const string BundelNaam = "drakenschip";

		internal const string ModelNaam = "DrakenschipModel";

		private const string ZeilTexture = "zeil";

		private const float MastTegels = 14f;

		private const float MastBovenRa = 0.6f;

		private const float OntwerpWaterlijn = 0.35f;

		private const float ZitDiepte = 0.42f;

		private ConfigEntry<float> snelheid;

		private ConfigEntry<int> opslagBreedte;

		private ConfigEntry<int> opslagHoogte;

		private ConfigEntry<float> levenspunten;

		private ConfigEntry<bool> eigenModel;

		private ConfigEntry<float> modelSchaal;

		private ConfigEntry<float> modelHoogte;

		private ConfigEntry<float> modelVooruit;

		private ConfigEntry<bool> kapiteinZit;

		private ConfigEntry<bool> kernhoutMast;

		private ConfigEntry<float> zitHoogte;

		private static readonly string[] Groepen = new string[6] { "Drakenschip", "Interieur", "Vellen", "Ladders", "Draak", "Schilden" };

		private readonly Dictionary<string, ConfigEntry<bool>> verberg = new Dictionary<string, ConfigEntry<bool>>();

		private ConfigEntry<bool> verbergRoeispanen;

		private ConfigEntry<bool> testEigenMasker;

		private ConfigEntry<bool> testSchaduwen;

		private ConfigEntry<bool> testValheimShader;

		private ConfigEntry<bool> testRelief;

		internal static DrakenschipPlugin Instance;

		internal static ManualLogSource Log;

		private void Awake()
		{
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new AllesCommando());
			CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new TestCommando());
			CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new FilmCommando());
			snelheid = ((BaseUnityPlugin)this).Config.Bind<float>("Ship", "Speed", 1.4f, "Multiplier for the sail force (1 = as fast as the Longship)");
			opslagBreedte = ((BaseUnityPlugin)this).Config.Bind<int>("Ship", "StorageWidth", 8, "Number of columns in the cargo chest (Longship: 6, max 8)");
			opslagHoogte = ((BaseUnityPlugin)this).Config.Bind<int>("Ship", "StorageHeight", 4, "Number of rows in the cargo chest (Longship: 3)");
			levenspunten = ((BaseUnityPlugin)this).Config.Bind<float>("Ship", "Health", 1750f, "How much damage the ship can take (Longship: 1000)");
			eigenModel = ((BaseUnityPlugin)this).Config.Bind<bool>("Model", "CustomModel", true, "Use our own 3D model (false = the regular Longship look)");
			modelSchaal = ((BaseUnityPlugin)this).Config.Bind<float>("Model", "Scale", 1f, "Size of the model (1 = as designed in Blender)");
			modelHoogte = ((BaseUnityPlugin)this).Config.Bind<float>("Model", "Height", 0f, "Move the model up (+) or down (-), in meters");
			modelVooruit = ((BaseUnityPlugin)this).Config.Bind<float>("Model", "Forward", 0f, "Move the model forward (+) or backward (-), in meters");
			kernhoutMast = ((BaseUnityPlugin)this).Config.Bind<bool>("Model", "CorewoodMast", true, "Slim mast and yard made of Corewood (false = the regular Longship mast)");
			kapiteinZit = ((BaseUnityPlugin)this).Config.Bind<bool>("Seating", "CaptainSits", true, "The captain sits on the captain's bench while steering (false = steer standing up)");
			zitHoogte = ((BaseUnityPlugin)this).Config.Bind<float>("Seating", "SeatHeight", 0f, "Move seated players up (+) or down (-), in meters");
			string[] groepen = Groepen;
			foreach (string text in groepen)
			{
				string text2 = EngelseGroep(text);
				verberg[text] = ((BaseUnityPlugin)this).Config.Bind<bool>("Test", "Hide" + text2, false, "Test: make the group '" + text2 + "' invisible (restart the game after changing)");
			}
			verbergRoeispanen = ((BaseUnityPlugin)this).Config.Bind<bool>("Test", "HideOars", false, "Test: make the oars invisible");
			testEigenMasker = ((BaseUnityPlugin)this).Config.Bind<bool>("Test", "CustomWaterMask", true, "Test: use our water mask (false = the Longship's)");
			testSchaduwen = ((BaseUnityPlugin)this).Config.Bind<bool>("Test", "Shadows", true, "Test: ship shadows on (false = no shadows, test for shadow flickering)");
			testValheimShader = ((BaseUnityPlugin)this).Config.Bind<bool>("Test", "ValheimShader", true, "Test: use Valheim's building shader (false = the plain Unity shader)");
			testRelief = ((BaseUnityPlugin)this).Config.Bind<bool>("Test", "NormalMaps", true, "Test: normal maps (grain, nails) on");
			PrefabManager.OnVanillaPrefabsAvailable += VoegSchipToe;
		}

		internal static string EngelseGroep(string groep)
		{
			return groep switch
			{
				"Drakenschip" => "Hull", 
				"Interieur" => "Interior", 
				"Vellen" => "Furs", 
				"Draak" => "Dragon", 
				"Schilden" => "Shields", 
				_ => groep, 
			};
		}

		private void VoegSchipToe()
		{
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Expected O, but got Unknown
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Expected O, but got Unknown
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Expected O, but got Unknown
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Expected O, but got Unknown
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Expected O, but got Unknown
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Expected O, but got Unknown
			GameObject val = PrefabManager.Instance.CreateClonedPrefab("Drakenschip", "VikingShip");
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Base ship 'VikingShip' not found");
				return;
			}
			Ship component = val.GetComponent<Ship>();
			if ((Object)(object)component != (Object)null)
			{
				component.m_sailForceFactor *= snelheid.Value;
			}
			Container componentInChildren = val.GetComponentInChildren<Container>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.m_name = "Warship hold";
				componentInChildren.m_width = opslagBreedte.Value;
				componentInChildren.m_height = opslagHoogte.Value;
			}
			WearNTear component2 = val.GetComponent<WearNTear>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.m_health = levenspunten.Value;
			}
			bool flag = eigenModel.Value && VervangUiterlijk(val);
			PieceConfig val2 = new PieceConfig();
			val2.Name = "Warship";
			val2.Description = "A larger, faster ship with a spacious cargo hold.";
			val2.PieceTable = PieceTables.Hammer;
			val2.Category = PieceCategories.Misc;
			val2.CraftingStation = CraftingStations.Workbench;
			val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[7]
			{
				new RequirementConfig("FineWood", 50, 0, true),
				new RequirementConfig("ElderBark", 40, 0, true),
				new RequirementConfig("IronNails", 120, 0, true),
				new RequirementConfig("TrollHide", 12, 0, true),
				new RequirementConfig("DeerHide", 16, 0, true),
				new RequirementConfig("Coal", 10, 0, true),
				new RequirementConfig("RoundLog", 10, 0, true)
			};
			PieceConfig val3 = val2;
			PieceManager.Instance.AddPiece(new CustomPiece(val, true, val3));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Warship added to the hammer build menu");
			if (flag)
			{
				MaakIcoon(val);
			}
			PrefabManager.OnVanillaPrefabsAvailable -= VoegSchipToe;
		}

		private void MaakIcoon(GameObject schip)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			Piece component = schip.GetComponent<Piece>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			List<Renderer> list = new List<Renderer>();
			Renderer[] componentsInChildren = schip.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				bool flag = val is MeshRenderer || val is SkinnedMeshRenderer || val is LineRenderer;
				if (val.enabled && (!flag || IsWaterMasker(val)))
				{
					val.enabled = false;
					list.Add(val);
				}
			}
			RenderRequest val2 = new RenderRequest(schip)
			{
				Rotation = Quaternion.Euler(18f, 0f, 0f) * Quaternion.Euler(0f, 125f, 0f),
				Width = 256,
				Height = 256,
				UseCache = false
			};
			Sprite val3 = null;
			try
			{
				val3 = RenderManager.Instance.Render(val2);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)ex);
			}
			finally
			{
				foreach (Renderer item in list)
				{
					item.enabled = true;
				}
			}
			if ((Object)(object)val3 == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Could not render the build menu icon, keeping the Longship icon");
				return;
			}
			component.m_icon = val3;
			try
			{
				File.WriteAllBytes(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "buildmenu_icon.png"), ImageConversion.EncodeToPNG(val3.texture));
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not save buildmenu_icon.png: " + ex2.Message));
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Build menu icon rendered from our own model");
		}

		private bool VervangUiterlijk(GameObject schip)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "drakenschip");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			GameObject val2 = (((Object)(object)val != (Object)null) ? val.LoadAsset<GameObject>("DrakenschipModel") : null);
			if ((Object)(object)val2 == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Model 'DrakenschipModel' not found in " + text + ", keeping the Longship look"));
				return false;
			}
			Bounds val3 = MeetModel(schip.transform, schip, alleenZichtbaar: true);
			Ship component = schip.GetComponent<Ship>();
			Texture2D val4 = val.LoadAsset<Texture2D>("zeil");
			Transform[] array = new Transform[3];
			GameObject sailObject = component.m_sailObject;
			array[0] = ((sailObject != null) ? sailObject.transform : null);
			GameObject mastObject = component.m_mastObject;
			array[1] = ((mastObject != null) ? mastObject.transform : null);
			GameObject rudderObject = component.m_rudderObject;
			array[2] = ((rudderObject != null) ? rudderObject.transform : null);
			Transform[] delen = (Transform[])(object)array;
			Shader val5 = null;
			Material val6 = null;
			Renderer oudMasker = null;
			Renderer[] componentsInChildren = schip.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val7 in componentsInChildren)
			{
				if (!(val7 is MeshRenderer) && !(val7 is SkinnedMeshRenderer))
				{
					continue;
				}
				if (IsWaterMasker(val7))
				{
					oudMasker = val7;
					continue;
				}
				int num;
				if (!((Object)(object)component.m_sailObject != (Object)null) || !((Component)val7).transform.IsChildOf(component.m_sailObject.transform))
				{
					num = (Pad(((Component)val7).transform, schip.transform).ToLower().Contains("sail") ? 1 : 0);
					if (num == 0)
					{
						goto IL_018b;
					}
				}
				else
				{
					num = 1;
				}
				if ((Object)(object)val4 != (Object)null)
				{
					GeefZeilTexture(val7, val4, Pad(((Component)val7).transform, schip.transform));
				}
				goto IL_018b;
				IL_018b:
				if (num != 0 || HoortBij(((Component)val7).transform, delen))
				{
					ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
					string[] obj = new string[5]
					{
						"Stays visible: ",
						Pad(((Component)val7).transform, schip.transform),
						" [",
						null,
						null
					};
					Material sharedMaterial = val7.sharedMaterial;
					obj[3] = ((sharedMaterial != null) ? ((Object)sharedMaterial.shader).name : null);
					obj[4] = "]";
					logger.LogInfo((object)string.Concat(obj));
				}
				else
				{
					if ((Object)(object)val7.sharedMaterial != (Object)null && ((Object)(object)val5 == (Object)null || ((Object)val7.sharedMaterial.shader).name == "Custom/Piece"))
					{
						val5 = val7.sharedMaterial.shader;
						val6 = val7.sharedMaterial;
					}
					val7.enabled = false;
				}
			}
			GameObject val8 = Object.Instantiate<GameObject>(val2, schip.transform, false);
			((Object)val8).name = "DrakenschipModel";
			schip.AddComponent<Roeiers>();
			Bounds val9 = MeetModel(schip.transform, val8, alleenZichtbaar: false);
			float num2 = ((modelSchaal.Value > 0f) ? modelSchaal.Value : 1f);
			val8.transform.localScale = Vector3.one * num2;
			float num3 = (((Object)(object)component.m_floatCollider != (Object)null) ? schip.transform.InverseTransformPoint(((Component)component.m_floatCollider).transform.position).y : (((Bounds)(ref val3)).min.y + 1f));
			Transform val10 = Zoek(val8.transform, "Waterlijn");
			float num4 = (((Object)(object)val10 != (Object)null) ? val10.localPosition.y : 0.35f);
			val8.transform.localPosition = new Vector3(0f, num3 - num4 * num2 + modelHoogte.Value, ((Bounds)(ref val3)).center.z - ((Bounds)(ref val9)).center.z * num2 + modelVooruit.Value);
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Longship waterline at height {num3:0.00}");
			if ((Object)(object)val6 != (Object)null && testValheimShader.Value)
			{
				LogMateriaal(val6);
				Dictionary<Material, Material> dictionary = new Dictionary<Material, Material>();
				componentsInChildren = val8.GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val11 in componentsInChildren)
				{
					if (((Object)val11).name == "Watermasker" || ((Object)val11).name.StartsWith("Botsing_"))
					{
						continue;
					}
					Material[] sharedMaterials = val11.sharedMaterials;
					for (int j = 0; j < sharedMaterials.Length; j++)
					{
						Material val12 = sharedMaterials[j];
						if (!((Object)(object)val12 == (Object)null))
						{
							if (!dictionary.TryGetValue(val12, out var value))
							{
								value = (dictionary[val12] = MaakValheimMateriaal(val6, val12));
							}
							sharedMaterials[j] = value;
						}
					}
					val11.sharedMaterials = sharedMaterials;
				}
			}
			RichtIn(schip, component, val8, num2, oudMasker);
			PasTestToe(val8, oudMasker);
			VerlegTouwen(schip, val8.transform);
			((BaseUnityPlugin)this).Logger.LogInfo((object)($"Custom model placed: Longship {((Bounds)(ref val3)).size} (bottom {((Bounds)(ref val3)).min.y:0.00}), " + $"model {((Bounds)(ref val9)).size}, scale {num2:0.00}, shader {((val5 != null) ? ((Object)val5).name : null)}"));
			return true;
		}

		private void RichtIn(GameObject schip, Ship ship, GameObject nieuw, float schaal, Renderer oudMasker)
		{
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			//IL_050e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0513: Unknown result type (might be due to invalid IL or missing references)
			//IL_052e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0594: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bf: 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_054a: Unknown result type (might be due to invalid IL or missing references)
			//IL_054f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0554: 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_0565: 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_0578: Unknown result type (might be due to invalid IL or missing references)
			//IL_057d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0682: Unknown result type (might be due to invalid IL or missing references)
			//IL_0687: Unknown result type (might be due to invalid IL or missing references)
			//IL_068c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0696: 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_06b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e9: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = nieuw.transform;
			int num = LayerMask.NameToLayer("piece_nonsolid");
			int layer = LayerMask.NameToLayer("vehicle");
			Collider[] componentsInChildren = schip.GetComponentsInChildren<Collider>(true);
			foreach (Collider val in componentsInChildren)
			{
				if (!val.isTrigger && (Object)(object)val != (Object)(object)ship.m_floatCollider && !((Component)val).transform.IsChildOf(transform))
				{
					layer = ((Component)val).gameObject.layer;
					break;
				}
			}
			int num2 = 0;
			MeshFilter[] componentsInChildren2 = nieuw.GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val2 in componentsInChildren2)
			{
				if (((Object)val2).name.StartsWith("Botsing_") && !((Object)(object)val2.sharedMesh == (Object)null))
				{
					GameObject gameObject = ((Component)val2).gameObject;
					Bounds bounds = val2.sharedMesh.bounds;
					Object.DestroyImmediate((Object)(object)gameObject.GetComponent<MeshRenderer>());
					Object.DestroyImmediate((Object)(object)val2);
					BoxCollider obj = gameObject.AddComponent<BoxCollider>();
					obj.center = ((Bounds)(ref bounds)).center;
					obj.size = ((Bounds)(ref bounds)).size;
					((Collider)obj).enabled = false;
					gameObject.layer = layer;
					num2++;
				}
			}
			schip.AddComponent<Botsingen>();
			int num3 = 0;
			Transform[] componentsInChildren3 = ((Component)transform).GetComponentsInChildren<Transform>(true);
			foreach (Transform val3 in componentsInChildren3)
			{
				if (((Object)val3).name.StartsWith("Zitplek"))
				{
					MaakStoel(((Component)val3).gameObject, "Rowing bench", schip.transform.rotation * Quaternion.Euler(0f, 180f, 0f), num);
					num3++;
				}
			}
			ShipControlls componentInChildren = schip.GetComponentInChildren<ShipControlls>(true);
			Transform val4 = Zoek(transform, "Stuurplek");
			if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.m_attachPoint != (Object)null && (Object)(object)val4 != (Object)null && kapiteinZit.Value)
			{
				componentInChildren.m_attachPoint.position = val4.position + Vector3.up * (zitHoogte.Value - 0.42f);
				componentInChildren.m_attachPoint.rotation = schip.transform.rotation;
				componentInChildren.m_attachAnimation = "attach_chair";
				((Component)val4).gameObject.layer = num;
				BoxCollider obj2 = ((Component)val4).gameObject.AddComponent<BoxCollider>();
				obj2.size = new Vector3(1.4f, 0.5f, 0.5f);
				obj2.center = new Vector3(0f, 0.1f, 0f);
				((Component)val4).gameObject.AddComponent<StuurGreep>();
			}
			Container componentInChildren2 = schip.GetComponentInChildren<Container>(true);
			Transform val5 = Zoek(transform, "Kist");
			if ((Object)(object)componentInChildren2 != (Object)null && (Object)(object)val5 != (Object)null)
			{
				if ((Object)(object)((Component)componentInChildren2).gameObject != (Object)(object)schip)
				{
					((Component)componentInChildren2).transform.position = val5.position;
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Storage " + (((Object)(object)((Component)componentInChildren2).gameObject != (Object)(object)schip) ? "moved into the sea chest" : "is on the ship itself and could not be moved") + " (" + Pad(((Component)componentInChildren2).transform, schip.transform) + ")"));
				((Component)val5).gameObject.layer = num;
				((Component)val5).gameObject.AddComponent<BoxCollider>().size = new Vector3(1.1f, 0.5f, 0.7f);
				((Component)val5).gameObject.AddComponent<KistGreep>();
			}
			Transform val6 = Zoek(transform, "Kistdeksel");
			if ((Object)(object)val6 != (Object)null)
			{
				((Component)val6).gameObject.AddComponent<KistDeksel>();
			}
			Transform val7 = Zoek(transform, "Boegplek");
			if ((Object)(object)val7 != (Object)null)
			{
				Chair obj3 = MaakStoel(((Component)val7).gameObject, "Hold the dragon head", schip.transform.rotation, num, "", 0f);
				BoxCollider component = ((Component)val7).GetComponent<BoxCollider>();
				component.size = new Vector3(1.2f, 2f, 1.4f);
				component.center = new Vector3(0f, 0.6f, 0.7f);
				obj3.m_useDistance = 3f;
			}
			Transform val8 = Zoek(transform, "Mastvoet");
			Transform val9 = Zoek(transform, "Mastbalk");
			MeshFilter val10 = (((Object)(object)ship.m_mastObject != (Object)null) ? ZoekMesh(ship.m_mastObject.transform, "mast") : null);
			if ((Object)(object)val8 != (Object)null && (Object)(object)val10 != (Object)null)
			{
				Bounds mast = MeetModel(schip.transform, ((Component)val10).gameObject, alleenZichtbaar: false);
				Vector3 val11 = schip.transform.InverseTransformPoint(val8.position);
				float num4 = Mathf.Max(0.3f, ((Bounds)(ref mast)).min.y + 0.4f - val11.y);
				val8.position = schip.transform.TransformPoint(new Vector3(((Bounds)(ref mast)).center.x, val11.y, ((Bounds)(ref mast)).center.z));
				val8.localScale = new Vector3(1f, num4 / schaal, 1f);
				if ((Object)(object)val9 != (Object)null)
				{
					Vector3 val12 = schip.transform.InverseTransformPoint(val9.position);
					val9.position = schip.transform.TransformPoint(new Vector3(val12.x, val12.y, ((Bounds)(ref mast)).center.z));
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Mast step placed under the mast: mast bottom {((Bounds)(ref mast)).min.y:0.00}, deck {val11.y:0.00}");
				ZetKernhoutMast(schip, ship, transform, val10, mast, val11.y, schaal);
			}
			Ladder[] componentsInChildren4 = schip.GetComponentsInChildren<Ladder>(true);
			foreach (Ladder val13 in componentsInChildren4)
			{
				if (!((Component)val13).transform.IsChildOf(transform))
				{
					((Component)val13).gameObject.SetActive(false);
				}
			}
			int num5 = 0;
			string[] array = new string[2] { "S", "B" };
			foreach (string text in array)
			{
				Transform val14 = Zoek(transform, "Ladder_" + text);
				Transform val15 = Zoek(transform, "LadderDoel_" + text);
				if (!((Object)(object)val14 == (Object)null) && !((Object)(object)val15 == (Object)null))
				{
					Vector3 val16 = schip.transform.InverseTransformPoint(val15.position);
					val15.rotation = Quaternion.LookRotation(schip.transform.TransformDirection(new Vector3(0f - Mathf.Sign(val16.x), 0f, 0f)));
					((Component)val14).gameObject.layer = num;
					((Component)val14).gameObject.AddComponent<BoxCollider>().size = new Vector3(0.3f, 1.8f, 0.8f);
					Ladder obj4 = ((Component)val14).gameObject.AddComponent<Ladder>();
					obj4.m_targetPos = val15;
					obj4.m_name = "Ladder";
					obj4.m_useDistance = 2.5f;
					num5++;
				}
			}
			Transform val17 = Zoek(transform, "Watermasker");
			if ((Object)(object)val17 != (Object)null && (Object)(object)oudMasker != (Object)null)
			{
				((Component)val17).GetComponent<Renderer>().sharedMaterial = oudMasker.sharedMaterial;
				oudMasker.enabled = false;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)($"Fit-out: {num2} collision blocks, {num3} seats, {num5} ladders, " + "helm bench " + (((Object)(object)val4 != (Object)null) ? "yes" : "no") + ", chest " + (((Object)(object)componentInChildren2 != (Object)null && (Object)(object)val5 != (Object)null) ? "yes" : "no") + ", water mask " + (((Object)(object)val17 != (Object)null && (Object)(object)oudMasker != (Object)null) ? "replaced" : "not replaced")));
		}

		private Material MaakValheimMateriaal(Material valheim, Material eigen)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(valheim)
			{
				name = ((Object)eigen).name
			};
			Texture mainTexture = eigen.mainTexture;
			Texture val2 = (eigen.HasProperty("_BumpMap") ? eigen.GetTexture("_BumpMap") : null);
			string[] texturePropertyNames = val.GetTexturePropertyNames();
			foreach (string text in texturePropertyNames)
			{
				if ((Object)(object)val.GetTexture(text) != (Object)null && text != "_MainTex" && text != "_BumpMap" && text != "_NoiseTex")
				{
					val.SetTexture(text, (Texture)null);
				}
			}
			val.mainTexture = (Texture)(((Object)(object)mainTexture != (Object)null) ? ((object)mainTexture) : ((object)Texture2D.whiteTexture));
			val.mainTextureScale = Vector2.one;
			val.mainTextureOffset = Vector2.zero;
			if (val.HasProperty("_BumpMap"))
			{
				val.SetTextureScale("_BumpMap", Vector2.one);
				val.SetTextureOffset("_BumpMap", Vector2.zero);
			}
			if (val.HasProperty("_MoveableObject"))
			{
				val.SetFloat("_MoveableObject", 1f);
			}
			if (val.HasProperty("_BumpMap"))
			{
				val.SetTexture("_BumpMap", val2);
			}
			if (val.HasProperty("_Color"))
			{
				val.color = (((Object)(object)mainTexture != (Object)null) ? Color.white : eigen.color);
			}
			return val;
		}

		private void LogMateriaal(Material m)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			List<string> list = new List<string>();
			string[] texturePropertyNames = m.GetTexturePropertyNames();
			foreach (string text in texturePropertyNames)
			{
				list.Add(text + "=" + (((Object)(object)m.GetTexture(text) != (Object)null) ? ((Object)m.GetTexture(text)).name : "-"));
			}
			texturePropertyNames = m.GetPropertyNames((MaterialPropertyType)0);
			foreach (string text2 in texturePropertyNames)
			{
				list.Add($"{text2}={m.GetFloat(text2):0.###}");
			}
			texturePropertyNames = m.GetPropertyNames((MaterialPropertyType)2);
			foreach (string text3 in texturePropertyNames)
			{
				list.Add($"{text3}={m.GetVector(text3)}");
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Longship material " + ((Object)m).name + " [" + ((Object)m.shader).name + "]: " + string.Join(", ", list.ToArray())));
		}

		private void PasTestToe(GameObject nieuw, Renderer oudMasker)
		{
			List<string> list = new List<string>();
			string[] groepen = Groepen;
			Renderer[] componentsInChildren;
			foreach (string text in groepen)
			{
				Transform val = Zoek(nieuw.transform, text);
				if (verberg[text].Value && (Object)(object)val != (Object)null)
				{
					componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>(true);
					for (int j = 0; j < componentsInChildren.Length; j++)
					{
						componentsInChildren[j].enabled = false;
					}
					list.Add("hide " + EngelseGroep(text));
				}
			}
			if (verbergRoeispanen.Value)
			{
				componentsInChildren = nieuw.GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val2 in componentsInChildren)
				{
					if (((Object)val2).name.StartsWith("Roeispaan_"))
					{
						val2.enabled = false;
					}
				}
				list.Add("hide Oars");
			}
			if (!testEigenMasker.Value)
			{
				Transform val3 = Zoek(nieuw.transform, "Watermasker");
				if ((Object)(object)val3 != (Object)null)
				{
					((Component)val3).GetComponent<Renderer>().enabled = false;
				}
				if ((Object)(object)oudMasker != (Object)null)
				{
					oudMasker.enabled = true;
				}
				list.Add("Longship water mask");
			}
			componentsInChildren = nieuw.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val4 in componentsInChildren)
			{
				if (!testSchaduwen.Value)
				{
					val4.shadowCastingMode = (ShadowCastingMode)0;
					val4.receiveShadows = false;
				}
				if (testRelief.Value)
				{
					continue;
				}
				Material[] sharedMaterials = val4.sharedMaterials;
				foreach (Material val5 in sharedMaterials)
				{
					if ((Object)(object)val5 != (Object)null && val5.HasProperty("_BumpMap"))
					{
						val5.SetTexture("_BumpMap", (Texture)null);
						val5.DisableKeyword("_NORMALMAP");
					}
				}
			}
			if (!testSchaduwen.Value)
			{
				list.Add("no shadows");
			}
			if (!testValheimShader.Value)
			{
				list.Add("Unity shader");
			}
			if (!testRelief.Value)
			{
				list.Add("no normal maps");
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Test switches: " + ((list.Count == 0) ? "all normal" : string.Join(", ", list.ToArray()))));
		}

		private void ZetKernhoutMast(GameObject schip, Ship ship, Transform model, MeshFilter oudeMast, Bounds mast, float dekY, float schaal)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Expected O, but got Unknown
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: 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_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			Transform val = Zoek(model, "Kernhoutmast");
			Transform val2 = Zoek(model, "Kernhoutra");
			if (!kernhoutMast.Value || (Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				if (val != null)
				{
					((Component)val).gameObject.SetActive(false);
				}
				if (val2 != null)
				{
					((Component)val2).gameObject.SetActive(false);
				}
				return;
			}
			float num = ((Bounds)(ref mast)).size.x;
			if ((Object)(object)ship.m_sailObject != (Object)null)
			{
				SkinnedMeshRenderer[] componentsInChildren = ship.m_sailObject.GetComponentsInChildren<SkinnedMeshRenderer>(true);
				foreach (SkinnedMeshRenderer val3 in componentsInChildren)
				{
					if ((Object)(object)val3.sharedMesh != (Object)null)
					{
						Bounds bounds = val3.sharedMesh.bounds;
						Vector3 val4 = schip.transform.InverseTransformPoint(((Component)val3).transform.TransformPoint(new Vector3(((Bounds)(ref bounds)).min.x, ((Bounds)(ref bounds)).center.y, ((Bounds)(ref bounds)).center.z)));
						Vector3 val5 = schip.transform.InverseTransformPoint(((Component)val3).transform.TransformPoint(new Vector3(((Bounds)(ref bounds)).max.x, ((Bounds)(ref bounds)).center.y, ((Bounds)(ref bounds)).center.z)));
						num = Mathf.Max(Vector3.Distance(val4, val5), 2f);
						break;
					}
				}
			}
			Transform val6 = (((Object)(object)ship.m_mastObject != (Object)null) ? Zoek(ship.m_mastObject.transform, "Sail_Top") : null);
			float num2 = (((Object)(object)val6 != (Object)null) ? schip.transform.InverseTransformPoint(val6.position).y : (((Bounds)(ref mast)).max.y - 2.4f));
			float num3 = Mathf.Min(((Bounds)(ref mast)).max.y, num2 + 0.6f);
			((Component)oudeMast).GetComponent<Renderer>().enabled = false;
			val.position = schip.transform.TransformPoint(new Vector3(((Bounds)(ref mast)).center.x, dekY, ((Bounds)(ref mast)).center.z));
			val.localScale = new Vector3(1f, (num3 - dekY) / schaal, 1f);
			val2.position = schip.transform.TransformPoint(new Vector3(((Bounds)(ref mast)).center.x, num2, ((Bounds)(ref mast)).center.z + 0.15f));
			val2.localScale = new Vector3((num + 0.5f) / schaal, 1f, 1f);
			if ((Object)(object)ship.m_mastObject != (Object)null)
			{
				val2.SetParent(ship.m_mastObject.transform, true);
			}
			Renderer component = ((Component)val).GetComponent<Renderer>();
			Renderer val7 = ZoekKernhoutRenderer("RoundLog", "wood_pole_log", "wood_pole_log_4", "wood_wall_log");
			if ((Object)(object)component != (Object)null && (Object)(object)component.sharedMaterial != (Object)null)
			{
				Material val8 = new Material(component.sharedMaterial)
				{
					name = "Kernhout"
				};
				Vector2 mainTextureScale = val8.mainTextureScale;
				val8.mainTextureScale = new Vector2(mainTextureScale.x, mainTextureScale.y * 14f);
				string[] array = new string[2] { "_Glossiness", "_Metallic" };
				foreach (string text in array)
				{
					if ((Object)(object)val7 != (Object)null && val8.HasProperty(text) && val7.sharedMaterial.HasProperty(text))
					{
						val8.SetFloat(text, val7.sharedMaterial.GetFloat(text));
					}
				}
				component.sharedMaterial = val8;
				((Component)val2).GetComponent<Renderer>().sharedMaterial = val8;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)($"Corewood mast: top {num3:0.00} (Valheim {((Bounds)(ref mast)).max.y:0.00}), yard at {num2:0.00} " + string.Format("({0}), yard {1:0.0} m, ", ((Object)(object)val6 != (Object)null) ? "Sail_Top" : "Sail_Top not found, estimate", num + 0.5f) + "gloss from " + (((Object)(object)val7 != (Object)null) ? ((Object)val7).name : "not found")));
		}

		private void VerlegTouwen(GameObject schip, Transform model)
		{
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: 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_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			Transform val = model.Find("Draak");
			List<Vector3> list = new List<Vector3>();
			if ((Object)(object)val != (Object)null)
			{
				MeshFilter[] componentsInChildren = ((Component)val).GetComponentsInChildren<MeshFilter>(true);
				foreach (MeshFilter mf in componentsInChildren)
				{
					if ((Object)(object)mf.sharedMesh != (Object)null && mf.sharedMesh.isReadable)
					{
						list.AddRange(mf.sharedMesh.vertices.Select((Vector3 v) => schip.transform.InverseTransformPoint(((Component)mf).transform.TransformPoint(v))));
					}
				}
			}
			if (list.Count == 0)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Ropes not moved: stem shape not readable");
				return;
			}
			Transform val2 = Zoek(model, "Kernhoutmast");
			Vector3? val3 = (((Object)(object)val2 != (Object)null && ((Component)val2).gameObject.activeSelf) ? new Vector3?(schip.transform.InverseTransformPoint(val2.TransformPoint(Vector3.up))) : ((Vector3?)null));
			LineRenderer[] componentsInChildren2 = schip.GetComponentsInChildren<LineRenderer>(true);
			foreach (LineRenderer val4 in componentsInChildren2)
			{
				if (((Component)val4).transform.IsChildOf(model))
				{
					continue;
				}
				Vector3[] array = (Vector3[])(object)new Vector3[val4.positionCount];
				val4.GetPositions(array);
				int num = 0;
				for (int num2 = 0; num2 < array.Length; num2++)
				{
					Vector3 val5 = (val4.useWorldSpace ? schip.transform.InverseTransformPoint(array[num2]) : schip.transform.InverseTransformPoint(((Component)val4).transform.TransformPoint(array[num2])));
					if (val3.HasValue && val5.y > val3.Value.y)
					{
						Vector2 val6 = new Vector2(val5.x - val3.Value.x, val5.z - val3.Value.z);
						if (((Vector2)(ref val6)).magnitude < 0.6f)
						{
							val5 = val3.Value + Vector3.down * 0.05f;
							array[num2] = (val4.useWorldSpace ? schip.transform.TransformPoint(val5) : ((Component)val4).transform.InverseTransformPoint(schip.transform.TransformPoint(val5)));
							num++;
							continue;
						}
					}
					float num3 = Mathf.Sign(val5.z);
					float num4 = float.NaN;
					foreach (Vector3 item in list)
					{
						if (Mathf.Sign(item.z) == num3 && Mathf.Abs(item.y - val5.y) < 0.2f && (float.IsNaN(num4) || Mathf.Abs(item.z) < Mathf.Abs(num4)))
						{
							num4 = item.z;
						}
					}
					if (!float.IsNaN(num4) && !(Mathf.Abs(val5.z) <= Mathf.Abs(num4) + 0.05f))
					{
						((Vector3)(ref val5))..ctor(0f, val5.y, num4 + num3 * 0.05f);
						array[num2] = (val4.useWorldSpace ? schip.transform.TransformPoint(val5) : ((Component)val4).transform.InverseTransformPoint(schip.transform.TransformPoint(val5)));
						num++;
					}
				}
				val4.SetPositions(array);
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Rope {Pad(((Component)val4).transform, schip.transform)}: {array.Length} points, {num} moved to stem or mast");
			}
		}

		private static Renderer ZoekKernhoutRenderer(params string[] prefabs)
		{
			foreach (string text in prefabs)
			{
				GameObject prefab = PrefabManager.Instance.GetPrefab(text);
				if ((Object)(object)prefab == (Object)null)
				{
					continue;
				}
				MeshRenderer[] componentsInChildren = prefab.GetComponentsInChildren<MeshRenderer>(true);
				foreach (MeshRenderer val in componentsInChildren)
				{
					Material sharedMaterial = ((Renderer)val).sharedMaterial;
					if ((Object)(object)sharedMaterial != (Object)null && (Object)(object)sharedMaterial.mainTexture != (Object)null && !((Object)sharedMaterial.mainTexture).name.ToLower().Contains("spark"))
					{
						return (Renderer)(object)val;
					}
				}
			}
			return null;
		}

		internal static Transform Zoek(Transform model, string naam)
		{
			Transform[] componentsInChildren = ((Component)model).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (((Object)val).name == naam)
				{
					return val;
				}
			}
			return null;
		}

		private static MeshFilter ZoekMesh(Transform deel, string naam)
		{
			MeshFilter[] componentsInChildren = ((Component)deel).GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val in componentsInChildren)
			{
				if (((Object)val).name.ToLower() == naam)
				{
					return val;
				}
			}
			return null;
		}

		private Chair MaakStoel(GameObject plek, string naam, Quaternion richting, int laag, string houding = "attach_chair", float voetenOnderZitvlak = 0.42f)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0080: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			plek.layer = laag;
			plek.transform.rotation = richting;
			plek.transform.localScale = Vector3.one;
			BoxCollider obj = plek.AddComponent<BoxCollider>();
			obj.size = new Vector3(0.7f, 0.3f, 0.5f);
			obj.center = new Vector3(0f, -0.1f, 0f);
			GameObject val = new GameObject("attach");
			val.transform.SetParent(plek.transform, false);
			val.transform.localPosition = Vector3.up * (zitHoogte.Value - voetenOnderZitvlak);
			Chair obj2 = plek.AddComponent<Chair>();
			obj2.m_name = naam;
			obj2.m_useDistance = 2f;
			obj2.m_attachPoint = val.transform;
			obj2.m_detachOffset = new Vector3(0f, 0.5f, 0f);
			obj2.m_attachAnimation = houding;
			obj2.m_inShip = true;
			return obj2;
		}

		private void GeefZeilTexture(Renderer r, Texture2D zeil, string pad)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			Material[] sharedMaterials = r.sharedMaterials;
			for (int i = 0; i < sharedMaterials.Length; i++)
			{
				if ((Object)(object)sharedMaterials[i] == (Object)null)
				{
					continue;
				}
				Material val = new Material(sharedMaterials[i]);
				List<string> list = new List<string>();
				string[] texturePropertyNames = val.GetTexturePropertyNames();
				foreach (string text in texturePropertyNames)
				{
					Texture texture = val.GetTexture(text);
					if (text == "_MainTex" || text == "_BaseMap" || text == "_Albedo")
					{
						val.SetTexture(text, (Texture)(object)zeil);
						list.Add(text + " (" + (((Object)(object)texture != (Object)null) ? ((Object)texture).name : "empty") + ")");
					}
				}
				if (val.HasProperty("_Color"))
				{
					val.color = Color.white;
				}
				sharedMaterials[i] = val;
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Sail " + pad + " [" + ((Object)val.shader).name + "]: replaced " + string.Join(", ", list.ToArray())));
			}
			r.sharedMaterials = sharedMaterials;
		}

		private static string Pad(Transform t, Transform schip)
		{
			string text = ((Object)t).name;
			t = t.parent;
			while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)schip)
			{
				text = ((Object)t).name + "/" + text;
				t = t.parent;
			}
			return text;
		}

		private static bool HoortBij(Transform t, Transform[] delen)
		{
			foreach (Transform val in delen)
			{
				if ((Object)(object)val != (Object)null && t.IsChildOf(val))
				{
					return true;
				}
			}
			return false;
		}

		private static bool IsWaterMasker(Renderer r)
		{
			if ((Object)(object)r.sharedMaterial != (Object)null)
			{
				return ((Object)r.sharedMaterial.shader).name.Contains("WaterMask");
			}
			return false;
		}

		private static bool IsZichtbaar(Transform t, Transform schip)
		{
			while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)schip)
			{
				if (!((Component)t).gameObject.activeSelf)
				{
					return false;
				}
				t = t.parent;
			}
			return true;
		}

		private static Bounds MeetModel(Transform schip, GameObject deel, bool alleenZichtbaar)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			bool flag = true;
			Bounds result = default(Bounds);
			MeshFilter[] componentsInChildren = deel.GetComponentsInChildren<MeshFilter>(true);
			Vector3 val2 = default(Vector3);
			foreach (MeshFilter val in componentsInChildren)
			{
				if ((Object)(object)val.sharedMesh == (Object)null)
				{
					continue;
				}
				if (alleenZichtbaar)
				{
					Renderer component = ((Component)val).GetComponent<Renderer>();
					if ((Object)(object)component == (Object)null || !component.enabled || IsWaterMasker(component) || !IsZichtbaar(((Component)val).transform, schip))
					{
						continue;
					}
				}
				Bounds bounds = val.sharedMesh.bounds;
				for (int j = 0; j < 8; j++)
				{
					((Vector3)(ref val2))..ctor(((j & 1) == 0) ? ((Bounds)(ref bounds)).min.x : ((Bounds)(ref bounds)).max.x, ((j & 2) == 0) ? ((Bounds)(ref bounds)).min.y : ((Bounds)(ref bounds)).max.y, ((j & 4) == 0) ? ((Bounds)(ref bounds)).min.z : ((Bounds)(ref bounds)).max.z);
					Vector3 val3 = schip.InverseTransformPoint(((Component)val).transform.TransformPoint(val2));
					if (flag)
					{
						((Bounds)(ref result))..ctor(val3, Vector3.zero);
						flag = false;
					}
					else
					{
						((Bounds)(ref result)).Encapsulate(val3);
					}
				}
			}
			return result;
		}
	}
	internal class Botsingen : MonoBehaviour
	{
		private void Awake()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)this).transform.Find("DrakenschipModel");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Rigidbody component = ((Component)this).GetComponent<Rigidbody>();
			Ship component2 = ((Component)this).GetComponent<Ship>();
			Vector3 centerOfMass = Vector3.zero;
			Vector3 inertiaTensor = Vector3.zero;
			Quaternion inertiaTensorRotation = Quaternion.identity;
			if ((Object)(object)component != (Object)null)
			{
				centerOfMass = component.centerOfMass;
				inertiaTensor = component.inertiaTensor;
				inertiaTensorRotation = component.inertiaTensorRotation;
			}
			Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(true);
			foreach (Collider val2 in componentsInChildren)
			{
				if (((Component)val2).transform.IsChildOf(val))
				{
					if (((Object)val2).name.StartsWith("Botsing_"))
					{
						val2.enabled = true;
					}
				}
				else if (!val2.isTrigger && (!((Object)(object)component2 != (Object)null) || !((Object)(object)val2 == (Object)(object)component2.m_floatCollider)) && !HeeftFunctie(val2))
				{
					val2.enabled = false;
				}
			}
			if ((Object)(object)component != (Object)null)
			{
				component.centerOfMass = centerOfMass;
				component.inertiaTensor = inertiaTensor;
				component.inertiaTensorRotation = inertiaTensorRotation;
			}
		}

		private bool HeeftFunctie(Collider c)
		{
			if (!Eigen((Component)(object)((Component)c).GetComponentInParent<ShipControlls>()) && !Eigen((Component)(object)((Component)c).GetComponentInParent<Container>()) && !Eigen((Component)(object)((Component)c).GetComponentInParent<Ladder>()))
			{
				return Eigen((Component)(object)((Component)c).GetComponentInParent<Chair>());
			}
			return true;
		}

		private bool Eigen(Component functie)
		{
			if ((Object)(object)functie != (Object)null)
			{
				return (Object)(object)functie.gameObject != (Object)(object)((Component)this).gameObject;
			}
			return false;
		}
	}
	internal class StuurGreep : MonoBehaviour, Hoverable, Interactable
	{
		private ShipControlls stuur;

		private void Awake()
		{
			Ship componentInParent = ((Component)this).GetComponentInParent<Ship>();
			stuur = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).GetComponentInChildren<ShipControlls>(true) : null);
		}

		public string GetHoverText()
		{
			if (!((Object)(object)stuur != (Object)null))
			{
				return "";
			}
			return stuur.GetHoverText();
		}

		public string GetHoverName()
		{
			if (!((Object)(object)stuur != (Object)null))
			{
				return "";
			}
			return stuur.GetHoverName();
		}

		public float GetHoverOffset()
		{
			return 0f;
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			if ((Object)(object)stuur != (Object)null)
			{
				return stuur.Interact(user, hold, alt);
			}
			return false;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			return false;
		}
	}
	internal class KistDeksel : MonoBehaviour
	{
		public static float OpenHoek = 105f;

		public static float Snelheid = 220f;

		private Container kist;

		private Quaternion dicht;

		private Vector3 as_;

		private float hoek;

		private void Awake()
		{
			//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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			Ship componentInParent = ((Component)this).GetComponentInParent<Ship>();
			kist = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).GetComponentInChildren<Container>(true) : null);
			dicht = ((Component)this).transform.localRotation;
			MeshFilter component = ((Component)this).GetComponent<MeshFilter>();
			Vector3 val;
			if (!((Object)(object)component != (Object)null) || !((Object)(object)component.sharedMesh != (Object)null))
			{
				val = Vector3.forward;
			}
			else
			{
				Quaternion localRotation = ((Component)this).transform.localRotation;
				Bounds bounds = component.sharedMesh.bounds;
				val = localRotation * Vector3.Scale(((Bounds)(ref bounds)).center, ((Component)this).transform.localScale);
			}
			Vector3 val2 = val;
			val2.y = 0f;
			as_ = Vector3.Cross(((Vector3)(ref val2)).normalized, Vector3.up);
		}

		private void Update()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)kist == (Object)null))
			{
				float num = (kist.IsInUse() ? OpenHoek : 0f);
				hoek = Mathf.MoveTowards(hoek, num, Snelheid * Time.deltaTime);
				((Component)this).transform.localRotation = Quaternion.AngleAxis(hoek, as_) * dicht;
			}
		}
	}
	internal class KistGreep : MonoBehaviour, Hoverable, Interactable
	{
		private Container kist;

		private void Awake()
		{
			Ship componentInParent = ((Component)this).GetComponentInParent<Ship>();
			kist = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).GetComponentInChildren<Container>(true) : null);
		}

		public string GetHoverText()
		{
			if (!((Object)(object)kist != (Object)null))
			{
				return "";
			}
			return kist.GetHoverText();
		}

		public string GetHoverName()
		{
			if (!((Object)(object)kist != (Object)null))
			{
				return "";
			}
			return kist.GetHoverName();
		}

		public float GetHoverOffset()
		{
			return 0f;
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			if ((Object)(object)kist != (Object)null)
			{
				return kist.Interact(user, hold, alt);
			}
			return false;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			if ((Object)(object)kist != (Object)null)
			{
				return kist.UseItem(user, item);
			}
			return false;
		}
	}
	internal class Roeiers : MonoBehaviour
	{
		private class Roeispaan
		{
			public Transform T;

			public Quaternion Rust;

			public float Kant;

			public float Gewicht;
		}

		public static float SlagenPerSeconde = 0.6f;

		public static float Zwaai = 28f;

		public static float Optillen = 9f;

		private readonly List<Roeispaan> roeispanen = new List<Roeispaan>();

		private Ship ship;

		private float fase;

		private void Awake()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			ship = ((Component)this).GetComponent<Ship>();
			Transform[] componentsInChildren = ((Component)this).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (((Object)val).name.StartsWith("Roeispaan"))
				{
					roeispanen.Add(new Roeispaan
					{
						T = val,
						Rust = val.localRotation,
						Kant = ((val.localPosition.x >= 0f) ? 1f : (-1f))
					});
				}
			}
		}

		private void Update()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ship == (Object)null || roeispanen.Count == 0)
			{
				return;
			}
			Speed speedSetting = ship.GetSpeedSetting();
			float num = (((int)speedSetting == 2) ? 1f : (((int)speedSetting == 1) ? (-1f) : 0f));
			fase += Time.deltaTime * SlagenPerSeconde * 2f * (float)Math.PI;
			float num2 = Mathf.Sin(fase) * Zwaai;
			float num3 = (0f - Mathf.Cos(fase)) * num * Optillen;
			foreach (Roeispaan item in roeispanen)
			{
				item.Gewicht = Mathf.MoveTowards(item.Gewicht, (num != 0f) ? 1f : 0f, Time.deltaTime * 1.5f);
				Quaternion val = Quaternion.AngleAxis(num2 * item.Kant * item.Gewicht, Vector3.up) * Quaternion.AngleAxis(num3 * item.Kant * item.Gewicht, Vector3.forward);
				item.T.localRotation = val * item.Rust;
			}
		}
	}
	internal class AllesCommando : ConsoleCommand
	{
		public override string Name => "warship_all";

		public override string Help => "Puts a Warship in the water, takes photos, sails around and films – all in one go (\"keep\" = leave the ship)";

		public override void Run(string[] args)
		{
			if (SchipTest.Bezig)
			{
				SchipTest.Meld("A test is already running.");
			}
			else
			{
				((MonoBehaviour)DrakenschipPlugin.Instance).StartCoroutine(SchipTest.Alles(args));
			}
		}
	}
	internal class TestCommando : ConsoleCommand
	{
		public override string Name => "warship_test";

		public override string Help => "Puts a Warship in the water and takes test images automatically (to track down flickering)";

		public override void Run(string[] args)
		{
			if (SchipTest.Bezig)
			{
				SchipTest.Meld("The test is already running.");
			}
			else
			{
				((MonoBehaviour)DrakenschipPlugin.Instance).StartCoroutine(SchipTest.Voer(args));
			}
		}
	}
	internal class FilmCommando : ConsoleCommand
	{
		public override string Name => "warship_film";

		public override string Help => "Sails a Warship and films it frame by frame (to track down flickering)";

		public override void Run(string[] args)
		{
			if (SchipTest.Bezig)
			{
				SchipTest.Meld("A test is already running.");
			}
			else
			{
				((MonoBehaviour)DrakenschipPlugin.Instance).StartCoroutine(SchipTest.Film());
			}
		}
	}
	internal static class SchipTest
	{
		private sealed class CameraOvername
		{
			private readonly GameCamera gc = GameCamera.instance;

			private readonly GameObject hud = (((Object)(object)Hud.instance != (Object)null) ? Hud.instance.m_rootObject : null);

			private readonly bool hudWasAan;

			private readonly Vector3 pos;

			private readonly Quaternion rot;

			public Transform Camera => ((Component)gc).transform;

			public CameraOvername()
			{
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				hudWasAan = (Object)(object)hud != (Object)null && hud.activeSelf;
				pos = ((Component)gc).transform.position;
				rot = ((Component)gc).transform.rotation;
				((Behaviour)gc).enabled = false;
				if ((Object)(object)hud != (Object)null)
				{
					hud.SetActive(false);
				}
			}

			public void Herstel()
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				((Component)gc).transform.position = pos;
				((Component)gc).transform.rotation = rot;
				((Behaviour)gc).enabled = true;
				if ((Object)(object)hud != (Object)null)
				{
					hud.SetActive(hudWasAan);
				}
			}
		}

		private class Variant
		{
			public string Naam;

			public Action Aan = delegate
			{
			};

			public Action Uit = delegate
			{
			};
		}

		private static readonly (string naam, Vector3 camera, Vector3 doel)[] FotoHoeken = new(string, Vector3, Vector3)[14]
		{
			("side_starboard", new Vector3(16f, 3f, 0f), new Vector3(0f, 3f, 0f)),
			("side_port", new Vector3(-16f, 3f, 0f), new Vector3(0f, 3f, 0f)),
			("angled_front", new Vector3(11f, 7f, 15f), new Vector3(0f, 2f, 0f)),
			("angled_rear", new Vector3(-11f, 7f, -15f), new Vector3(0f, 2f, 0f)),
			("top", new Vector3(0f, 24f, -8f), new Vector3(0f, 0f, 0f)),
			("deck", new Vector3(0f, 5f, -12f), new Vector3(0f, 1f, 4f)),
			("mast_full", new Vector3(20f, 6f, 3f), new Vector3(0f, 6f, 0f)),
			("mast_top_and_yard", new Vector3(5f, 8f, -6f), new Vector3(0f, 10f, 0f)),
			("mast_step", new Vector3(2.5f, 2.8f, -3f), new Vector3(0f, 1f, 0f)),
			("dragon_head", new Vector3(4f, 3f, 13f), new Vector3(0f, 3f, 9f)),
			("lookout_platform", new Vector3(0f, 4f, 2f), new Vector3(0f, 2f, 8f)),
			("sternpost", new Vector3(5f, 3f, -12.5f), new Vector3(0f, 3f, -10f)),
			("aft_deck_chest", new Vector3(2.5f, 3.5f, -4f), new Vector3(0f, 1.5f, -7.5f)),
			("waterline", new Vector3(6f, 0.6f, -4f), new Vector3(0f, 0.5f, 0f))
		};

		private const float SecondenPerShot = 5f;

		private static readonly (string naam, Func<float, Vector3> camera, Func<float, Vector3> doel)[] Shots = new(string, Func<float, Vector3>, Func<float, Vector3>)[5]
		{
			("orbit", (float t) => Quaternion.Euler(0f, t * 360f, 0f) * new Vector3(0f, 4f, 14f), (float t) => new Vector3(0f, 1.5f, 0f)),
			("follow", (float t) => new Vector3(Mathf.Sin(t * 6f) * 1.5f, 4f, -13f), (float t) => new Vector3(0f, 1.5f, 4f)),
			("along_hull", (float t) => new Vector3(5f, 1.3f, Mathf.Lerp(-11f, 11f, t)), (float t) => new Vector3(0f, 1f, Mathf.Lerp(-9f, 9f, t))),
			("deck", (float t) => new Vector3(Mathf.Sin(t * 4f) * 0.8f, 3.2f, -7f), (float t) => new Vector3(0f, 1.2f, 5f)),
			("far_away", (float t) => Quaternion.Euler(0f, 40f + t * 60f, 0f) * new Vector3(0f, 8f, 45f), (float t) => new Vector3(0f, 2f, 0f))
		};

		public static bool Bezig;

		private const int BeeldenPerHoek = 4;

		private static readonly (string naam, Vector3 camera, Vector3 doel)[] Hoeken = new(string, Vector3, Vector3)[4]
		{
			("side", new Vector3(14f, 2.5f, 0f), new Vector3(0f, 1.5f, 0f)),
			("angled", new Vector3(10f, 7f, 12f), new Vector3(0f, 1f, 0f)),
			("deck", new Vector3(0f, 5f, -12f), new Vector3(0f, 1f, 4f)),
			("waterline", new Vector3(6f, 0.6f, -4f), new Vector3(0f, 0.5f, 0f))
		};

		public static IEnumerator Alles(string[] args)
		{
			GameObject schip = ZetSchipNeer(vanOeverWeg: true);
			if ((Object)(object)schip == (Object)null)
			{
				yield break;
			}
			Bezig = true;
			Meld("Placing the ship. Close the console (F5) and don't touch anything; this takes about 1 minute.");
			EnvMan env = EnvMan.instance;
			object oudDag = Lees(env, "m_debugTimeOfDay");
			object oudTijd = Lees(env, "m_debugTime");
			object oudWeer = Lees(env, "m_debugEnv");
			bool daglicht = Zet(env, "m_debugTimeOfDay", true);
			Zet(env, "m_debugTime", 0.5f);
			Zet(env, "m_debugEnv", "Clear");
			Ship ship = schip.GetComponent<Ship>();
			Rigidbody body = schip.GetComponent<Rigidbody>();
			string map = MaakMap("all");
			CameraOvername cam = null;
			int fotos = 0;
			int[] frames = new int[1];
			try
			{
				float start = Time.time;
				while (Time.time - start < 8f)
				{
					Stuur(ship, body, 0f, 0f);
					yield return (object)new WaitForFixedUpdate();
				}
				cam = new CameraOvername();
				(string naam, Vector3 camera, Vector3 doel)[] fotoHoeken = FotoHoeken;
				for (int i = 0; i < fotoHoeken.Length; i++)
				{
					(string naam, Vector3 camera, Vector3 doel) hoek = fotoHoeken[i];
					for (int j = 0; j < 3; j++)
					{
						Stuur(ship, body, 0f, 0f);
						Transform transform = schip.transform;
						cam.Camera.position = transform.TransformPoint(hoek.camera);
						cam.Camera.rotation = Quaternion.LookRotation(transform.TransformPoint(hoek.doel) - cam.Camera.position);
						yield return (object)((j < 2) ? ((WaitForEndOfFrame)null) : new WaitForEndOfFrame());
					}
					Texture2D val = ScreenCapture.CaptureScreenshotAsTexture();
					int num = fotos + 1;
					fotos = num;
					File.WriteAllBytes(Path.Combine(map, $"photo_{num:00}_{hoek.naam}.jpg"), ImageConversion.EncodeToJPG(val, 90));
					Object.Destroy((Object)(object)val);
				}
				List<string> tuig;
				try
				{
					tuig = BewaarVormen(schip, Path.Combine(map, "shapes.obj"));
				}
				catch (Exception ex)
				{
					tuig = new List<string> { "Saving shapes failed: " + ex.Message };
					DrakenschipPlugin.Log.LogWarning((object)ex);
				}
				Meld($"{fotos} photos taken, now sailing around and filming...");
				yield return Filmen(schip, cam.Camera, Path.Combine(map, "film"), bochten: true, frames);
				List<string> list = new List<string>();
				list.Add($"Time: {DateTime.Now}");
				list.Add($"Ship at {schip.transform.position}, water {ZoneSystem.instance.m_waterLevel}");
				list.Add("Daylight locked: " + (daglicht ? "yes" : "no (field not found)"));
				list.Add($"Photos: {fotos}, film frames: {frames[0]} ({Shots.Length} shots of {5f} s, S-turn)");
				list.Add($"Recorded with {QualitySettings.names[QualitySettings.GetQualityLevel()]}, shadow distance {QualitySettings.shadowDistance}");
				list.Add("");
				List<string> list2 = list;
				list2.AddRange(Beschrijf(schip));
				list2.Add("");
				list2.Add("Shapes in shapes.obj (ship space: x = starboard, y = up, z = bow):");
				list2.AddRange(tuig);
				File.WriteAllLines(Path.Combine(map, "report.txt"), list2.ToArray());
			}
			finally
			{
				cam?.Herstel();
				Zet(env, "m_debugTimeOfDay", oudDag);
				Zet(env, "m_debugTime", oudTijd);
				Zet(env, "m_debugEnv", oudWeer);
				if (Array.IndexOf(args, "keep") < 0 && (Object)(object)schip != (Object)null)
				{
					ZNetScene.instance.Destroy(schip);
				}
				Bezig = false;
			}
			Meld($"Done! {fotos} photos and {frames[0]} film frames in {map}");
		}

		private static IEnumerable<string> Beschrijf(GameObject schip)
		{
			schip.transform.Find("DrakenschipModel");
			float y = schip.transform.position.y;
			string[] array = new string[2] { "Kernhoutmast", "Kernhoutra" };
			foreach (string text in array)
			{
				Transform val = DrakenschipPlugin.Zoek(schip.transform, text);
				Renderer val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Renderer>() : null);
				if ((Object)(object)val2 == (Object)null)
				{
					yield return text + ": not found";
					continue;
				}
				Bounds bounds = val2.bounds;
				string[] obj = new string[7]
				{
					$"{text}: active {((Component)val).gameObject.activeInHierarchy}, visible {val2.enabled}, ",
					"material ",
					null,
					null,
					null,
					null,
					null
				};
				Material sharedMaterial = val2.sharedMaterial;
				obj[2] = ((sharedMaterial != null) ? ((Object)sharedMaterial).name : null);
				obj[3] = ", texture ";
				Material sharedMaterial2 = val2.sharedMaterial;
				object obj2;
				if (sharedMaterial2 == null)
				{
					obj2 = null;
				}
				else
				{
					Texture mainTexture = sharedMaterial2.mainTexture;
					obj2 = ((mainTexture != null) ? ((Object)mainTexture).name : null);
				}
				obj[4] = (string)obj2;
				obj[5] = ", ";
				obj[6] = $"from {((Bounds)(ref bounds)).min.y - y:0.00} to {((Bounds)(ref bounds)).max.y - y:0.00} m above the ship, size {((Bounds)(ref bounds)).size.x:0.00} x {((Bounds)(ref bounds)).size.z:0.00} m";
				yield return string.Concat(obj);
			}
			Ship ship = schip.GetComponent<Ship>();
			Transform val3 = (((Object)(object)ship.m_mastObject != (Object)null) ? DrakenschipPlugin.Zoek(ship.m_mastObject.transform, "Sail_Top") : null);
			if ((Object)(object)val3 != (Object)null)
			{
				yield return $"Sail_Top (top of the sail cloth) at {schip.transform.InverseTransformPoint(val3.position).y:0.00} m above the ship";
			}
			if ((Object)(object)ship.m_mastObject != (Object)null)
			{
				float num = Vector3.SignedAngle(schip.transform.forward, ship.m_mastObject.transform.forward, schip.transform.up);
				yield return $"Valheim mast rotated: {num:0} degrees relative to the ship";
			}
			if ((Object)(object)ship.m_sailObject != (Object)null)
			{
				SkinnedMeshRenderer[] componentsInChildren = ship.m_sailObject.GetComponentsInChildren<SkinnedMeshRenderer>(true);
				foreach (SkinnedMeshRenderer val4 in componentsInChildren)
				{
					Bounds bounds2 = ((Renderer)val4).bounds;
					yield return $"Sail {((Object)val4).name}: active {((Component)val4).gameObject.activeInHierarchy}, visible {((Renderer)val4).enabled}, " + $"from {((Bounds)(ref bounds2)).min.y - y:0.00} to {((Bounds)(ref bounds2)).max.y - y:0.00} m above the ship";
				}
			}
		}

		private static List<string> BewaarVormen(GameObject schip, string pad)
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			//IL_05cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0610: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: 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_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
			Transform s = schip.transform;
			Transform val = s.Find("DrakenschipModel");
			Transform val2 = (((Object)(object)val != (Object)null) ? val.Find("Draak") : null);
			List<string> list = new List<string>();
			StringBuilder stringBuilder = new StringBuilder();
			int num = 1;
			Renderer[] componentsInChildren = schip.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer r in componentsInChildren)
			{
				bool flag = (Object)(object)val == (Object)null || !((Component)r).transform.IsChildOf(val);
				bool flag2 = (Object)(object)val2 != (Object)null && ((Component)r).transform.IsChildOf(val2);
				Mesh val3 = null;
				Renderer obj = r;
				SkinnedMeshRenderer val4 = (SkinnedMeshRenderer)(object)((obj is SkinnedMeshRenderer) ? obj : null);
				Mesh val5;
				Vector3[] punten;
				if (val4 != null && (Object)(object)val4.sharedMesh != (Object)null && flag)
				{
					val3 = new Mesh();
					val4.BakeMesh(val3, true);
					val5 = val3;
					punten = val3.vertices.Select((Vector3 p) => s.InverseTransformPoint(((Component)r).transform.position + ((Component)r).transform.rotation * p)).ToArray();
					list.Add($"{((Object)r).name} (skinned): {val5.vertexCount} vertices, bones: " + string.Join(", ", val4.bones.Select((Transform b) => (!((Object)(object)b != (Object)null)) ? "-" : ((Object)b).name)));
				}
				else
				{
					if (!(r is MeshRenderer) || (!flag2 && (!flag || !r.enabled)))
					{
						continue;
					}
					MeshFilter component = ((Component)r).GetComponent<MeshFilter>();
					val5 = (((Object)(object)component != (Object)null) ? component.sharedMesh : null);
					if ((Object)(object)val5 == (Object)null || !val5.isReadable)
					{
						list.Add(((Object)r).name + ": shape not readable");
						continue;
					}
					punten = val5.vertices.Select((Vector3 p) => s.InverseTransformPoint(((Component)r).transform.TransformPoint(p))).ToArray();
				}
				Vector3[] array = punten;
				foreach (Vector3 val6 in array)
				{
					stringBuilder.Append("v ").Append(Getal(val6.x)).Append(' ')
						.Append(Getal(val6.y))
						.Append(' ')
						.Append(Getal(val6.z))
						.Append('\n');
				}
				for (int num3 = 0; num3 < val5.subMeshCount; num3++)
				{
					string text = ((num3 < r.sharedMaterials.Length && (Object)(object)r.sharedMaterials[num3] != (Object)null) ? ((Object)r.sharedMaterials[num3]).name : "none");
					int[] triangles = val5.GetTriangles(num3);
					Vector3[] array2 = (from k in triangles.Distinct()
						select punten[k]).ToArray();
					if (array2.Length != 0)
					{
						Vector3 val7 = ((IEnumerable<Vector3>)array2).Aggregate((Func<Vector3, Vector3, Vector3>)Vector3.Min);
						Vector3 val8 = ((IEnumerable<Vector3>)array2).Aggregate((Func<Vector3, Vector3, Vector3>)Vector3.Max);
						list.Add($"  {((Object)r).name} part {num3} [{text}]: {triangles.Length / 3} triangles, from {val7} to {val8}");
						stringBuilder.Append($"g {((Object)r).name.Replace(' ', '_')}_{num3}_{text.Replace(' ', '_')}\n");
						for (int num4 = 0; num4 < triangles.Length; num4 += 3)
						{
							stringBuilder.Append($"f {num + triangles[num4]} {num + triangles[num4 + 1]} {num + triangles[num4 + 2]}\n");
						}
					}
				}
				num += punten.Length;
				if ((Object)(object)val3 != (Object)null)
				{
					Object.Destroy((Object)(object)val3);
				}
			}
			LineRenderer[] componentsInChildren2 = schip.GetComponentsInChildren<LineRenderer>(true);
			foreach (LineRenderer lijn in componentsInChildren2)
			{
				Vector3[] array3 = (Vector3[])(object)new Vector3[lijn.positionCount];
				lijn.GetPositions(array3);
				Vector3[] array4 = array3.Select((Vector3 p) => s.InverseTransformPoint(lijn.useWorldSpace ? p : ((Component)lijn).transform.TransformPoint(p))).ToArray();
				string name = ((Object)lijn).name;
				Transform parent = ((Component)lijn).transform.parent;
				list.Add($"Rope {name} (under {((parent != null) ? ((Object)parent).name : null)}, visible {((Renderer)lijn).enabled && ((Component)lijn).gameObject.activeInHierarchy}): " + string.Join(" -> ", array4.Select((Vector3 p) => $"({p.x:0.00}; {p.y:0.00}; {p.z:0.00})")));
				if (array4.Length >= 2)
				{
					Vector3[] array = array4;
					foreach (Vector3 val9 in array)
					{
						stringBuilder.Append("v ").Append(Getal(val9.x)).Append(' ')
							.Append(Getal(val9.y))
							.Append(' ')
							.Append(Getal(val9.z))
							.Append('\n');
					}
					stringBuilder.Append("g rope_" + ((Object)lijn).name.Replace(' ', '_') + "\nl");
					for (int num5 = 0; num5 < array4.Length; num5++)
					{
						stringBuilder.Append(' ').Append(num + num5);
					}
					stringBuilder.Append('\n');
					num += array4.Length;
				}
			}
			File.WriteAllText(pad, stringBuilder.ToString());
			return list;
			static string Getal(float f)
			{
				return f.ToString("0.####", CultureInfo.InvariantCulture);
			}
		}

		private static void Stuur(Ship ship, Rigidbody body, float vooruit, float draai)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			Traverse val = Traverse.Create((object)ship).Field("m_speed");
			if (val.FieldExists())
			{
				val.SetValue(Enum.Parse(val.GetValueType(), "Full"));
			}
			if (!((Object)(object)body == (Object)null))
			{
				Vector3 forward = ((Component)ship).transform.forward;
				forward.y = 0f;
				body.linearVelocity = new Vector3(0f, body.linearVelocity.y, 0f) + ((Vector3)(ref forward)).normalized * vooruit;
				body.angularVelocity = new Vector3(body.angularVelocity.x, draai, body.angularVelocity.z);
			}
		}

		private static object Lees(object doel, string veld)
		{
			Traverse val = Traverse.Create(doel).Field(veld);
			if (!val.FieldExists())
			{
				return null;
			}
			return val.GetValue();
		}

		private static bool Zet(object doel, string veld, object waarde)
		{
			Traverse val = Traverse.Create(doel).Field(veld);
			if (!val.FieldExists() || waarde == null)
			{
				return false;
			}
			val.SetValue(waarde);
			return true;
		}

		public static IEnumerator Film()
		{
			GameObject schip = ZetSchipNeer(vanOeverWeg: true);
			if ((Object)(object)schip == (Object)null)
			{
				yield break;
			}
			Bezig = true;
			Meld("Placing the ship. Close the console (F5) and don't touch anything; filming takes about 40 seconds.");
			yield return (object)new WaitForSeconds(6f);
			string map = MaakMap("film");
			CameraOvername cam = new CameraOvername();
			int[] frames = new int[1];
			try
			{
				yield return Filmen(schip, cam.Camera, map, bochten: false, frames);
				File.WriteAllLines(Path.Combine(map, "info.txt"), new string[4]
				{
					$"Time: {DateTime.Now}",
					$"Frames: {frames[0]}, {5f} s per shot",
					"Shots: " + string.Join(", ", Array.ConvertAll(Shots, ((string naam, Func<float, Vector3> camera, Func<float, Vector3> doel) s) => s.naam)),
					$"Recorded with {QualitySettings.names[QualitySettings.GetQualityLevel()]}, shadow distance {QualitySettings.shadowDistance}"
				});
			}
			finally
			{
				cam.Herstel();
				if ((Object)(object)schip != (Object)null)
				{
					ZNetScene.instance.Destroy(schip);
				}
				Bezig = false;
			}
			Meld($"Done! {frames[0]} frames filmed in {map}");
		}

		private static IEnumerator Filmen(GameObject schip, Transform cam, string map, bool bochten, int[] frames)
		{
			Directory.CreateDirectory(map);
			Ship ship = schip.GetComponent<Ship>();
			Rigidbody body = schip.GetComponent<Rigidbody>();
			int breed = Screen.width / 2;
			int hoog = Screen.height / 2;
			RenderTexture vol = new RenderTexture(Screen.width, Screen.height, 0);
			RenderTexture half = new RenderTexture(breed, hoog, 0);
			float filmStart = Time.time;
			float duur = (float)Shots.Length * 5f;
			try
			{
				(string naam, Func<float, Vector3> camera, Func<float, Vector3> doel)[] shots = Shots;
				for (int i = 0; i < shots.Length; i++)
				{
					(string naam, Func<float, Vector3> camera, Func<float, Vector3> doel) shot = shots[i];
					float start = Time.time;
					int nummer = 0;
					while (Time.time - start < 5f)
					{
						float arg = (Time.time - start) / 5f;
						float draai = 0f;
						if (bochten)
						{
							float num = (Time.time - filmStart) / duur;
							draai = ((num < 0.15f) ? 0f : (Mathf.Sin((num - 0.15f) / 0.85f * (float)Math.PI * 2f) * 0.2f));
							Vector3 val = schip.transform.position + schip.transform.forward * 15f;
							if (ZoneSystem.instance.m_waterLevel - ZoneSystem.instance.GetGroundHeight(val) < 2f)
							{
								draai = 0.6f;
							}
						}
						Stuur(ship, body, 6f, draai);
						Transform transform = schip.transform;
						cam.position = transform.TransformPoint(shot.camera(arg));
						cam.rotation = Quaternion.LookRotation(transform.TransformPoint(shot.doel(arg)) - cam.position);
						yield return (object)new WaitForEndOfFrame();
						ScreenCapture.CaptureScreenshotIntoRenderTexture(vol);
						Graphics.Blit((Texture)(object)vol, half);
						string pad = Path.Combine(map, $"{shot.naam}_{nummer:0000}.jpg");
						AsyncGPUReadback.Request((Texture)(object)half, 0, (TextureFormat)4, (Action<AsyncGPUReadbackRequest>)delegate(AsyncGPUReadbackRequest verzoek)
						{
							//IL_000d: 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)
							if (((AsyncGPUReadbackRequest)(ref verzoek)).hasError)
							{
								return;
							}
							NativeArray<byte> val2 = ImageConversion.EncodeNativeArrayToJPG<byte>(((AsyncGPUReadbackRequest)(ref verzoek)).GetData<byte>(0), (GraphicsFormat)4, (uint)breed, (uint)hoog, 0u, 85);
							try
							{
								File.WriteAllBytes(pad, val2.ToArray());
							}
							finally
							{
								((IDisposable)val2/*cast due to .constrained prefix*/).Dispose();
							}
						});
						nummer++;
						frames[0]++;
					}
				}
				AsyncGPUReadback.WaitAllRequests();
			}
			finally
			{
				vol.Release();
				half.Release();
			}
		}

		public static void Meld(string tekst)
		{
			Console instance = Console.instance;
			if (instance != null)
			{
				instance.Print("[Warship] " + tekst);
			}
			DrakenschipPlugin.Log.LogInfo((object)("Test: " + tekst));
		}

		public static IEnumerator Voer(string[] args)
		{
			GameObject schip = ZetSchipNeer(vanOeverWeg: false);
			if ((Object)(object)schip == (Object)null)
			{
				yield break;
			}
			Bezig = true;
			Meld("Placing the ship. Close the console (F5) and don't touch anything; the test takes about 1 minute.");
			yield return (object)new WaitForSeconds(8f);
			string map = MaakMap("test");
			CameraOvername cam = new CameraOvername();
			int beelden = 0;
			List<string> verslag = new List<string>();
			try
			{
				foreach (Variant variant in MaakVarianten(schip))
				{
					variant.Aan();
					yield return (object)new WaitForSeconds(0.4f);
					(string naam, Vector3 camera, Vector3 doel)[] hoeken = Hoeken;
					for (int i = 0; i < hoeken.Length; i++)
					{
						(string naam, Vector3 camera, Vector3 doel) hoek = hoeken[i];
						for (int j = 0; j < 4; j++)
						{
							Quaternion val = Quaternion.Euler(0f, (float)j * 0.5f, 0f);
							Transform transform = schip.transform;
							cam.Camera.position = transform.TransformPoint(val * hoek.camera);
							cam.Camera.rotation = Quaternion.LookRotation(transform.TransformPoint(hoek.doel) - cam.Camera.position);
							yield return (object)new WaitForEndOfFrame();
							Texture2D val2 = ScreenCapture.CaptureScreenshotAsTexture();
							File.WriteAllBytes(Path.Combine(map, $"{variant.Naam}_{hoek.naam}_{j}.jpg"), ImageConversion.EncodeToJPG(val2, 80));
							Object.Destroy((Object)(object)val2);
							beelden++;
						}
					}
					variant.Uit();
					verslag.Add(variant.Naam);
				}
				File.WriteAllLines(Path.Combine(map, "info.txt"), new string[3]
				{
					$"Time: {DateTime.Now}",
					$"Ship at {schip.transform.position}, water {ZoneSystem.instance.m_waterLevel}",
					"Variants: " + string.Join(", ", verslag.ToArray())
				});
			}
			finally
			{
				cam.Herstel();
				if (Array.IndexOf(args, "keep") < 0 && (Object)(object)schip != (Object)null)
				{
					ZNetScene.instance.Destroy(schip);
				}
				Bezig = false;
			}
			Meld($"Done! {beelden} images saved in {map}");
		}

		private static GameObject ZetSchipNeer(bool vanOeverWeg)
		{
			//IL_0021: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				Meld("Load a world first.");
				return null;
			}
			Vector3? val = ZoekWater(((Component)localPlayer).transform.position);
			if (!val.HasValue)
			{
				Meld("No deep water found within 60 m. Stand at the edge of a lake or the sea.");
				return null;
			}
			Vector3 val2 = val.Value - ((Component)localPlayer).transform.position;
			val2.y = 0f;
			Quaternion val3 = (vanOeverWeg ? Quaternion.LookRotation(((Vector3)(ref val2)).normalized) : Quaternion.Euler(0f, Random.Range(0f, 360f), 0f));
			return Object.Instantiate<GameObject>(ZNetScene.instance.GetPrefab("Drakenschip"), val.Value, val3);
		}

		private static string MaakMap(string soort)
		{
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)DrakenschipPlugin.Instance).Info.Location), soort, DateTime.Now.ToString("yyyyMMdd_HHmmss"));
			Directory.CreateDirectory(text);
			return text;
		}

		private static Vector3? ZoekWater(Vector3 rond)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			float waterLevel = ZoneSystem.instance.m_waterLevel;
			for (float num = 18f; num <= 60f; num += 6f)
			{
				for (int i = 0; i < 360; i += 30)
				{
					Vector3 val = rond + Quaternion.Euler(0f, (float)i, 0f) * Vector3.forward * num;
					if (waterLevel - ZoneSystem.instance.GetGroundHeight(val) > 2.5f)
					{
						return new Vector3(val.x, waterLevel + 0.5f, val.z);
					}
				}
			}
			return null;
		}

		private static List<Variant> MaakVarianten(GameObject schip)
		{
			Transform val = schip.transform.Find("DrakenschipModel");
			Renderer[] alles = ((Component)val).GetComponentsInChildren<Renderer>(true);
			List<Variant> list = new List<Variant>
			{
				new Variant
				{
					Naam = "01_normal"
				}
			};
			Dictionary<Renderer, (ShadowCastingMode, bool)> schaduw = new Dictionary<Renderer, (ShadowCastingMode, bool)>();
			list.Add(new Variant
			{
				Naam = "02_no_shadows",
				Aan = delegate
				{
					//IL_0017: Unknown result type (might be due to invalid IL or missing references)
					Renderer[] array2 = alles;
					foreach (Renderer val5 in array2)
					{
						schaduw[val5] = (val5.shadowCastingMode, val5.receiveShadows);
						val5.shadowCastingMode = (ShadowCastingMode)0;
						val5.receiveShadows = false;
					}
				},
				Uit = delegate
				{
					//IL_0024: Unknown result type (might be due to invalid IL or missing references)
					foreach (KeyValuePair<Renderer, (ShadowCastingMode, bool)> item in schaduw)
					{
						item.Key.shadowCastingMode = item.Value.Item1;
						item.Key.receiveShadows = item.Value.Item2;
					}
				}
			});
			Transform val2 = val.Find("Watermasker");
			Renderer oud = null;
			Renderer[] componentsInChildren = schip.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val3 in componentsInChildren)
			{
				if (!((Component)val3).transform.IsChildOf(val) && (Object)(object)val3.sharedMaterial != (Object)null && ((Object)val3.sharedMaterial.shader).name.Contains("WaterMask"))
				{
					oud = val3;
				}
			}
			if ((Object)(object)val2 != (Object)null && (Object)(object)oud != (Object)null)
			{
				Renderer eigenR = ((Component)val2).GetComponent<Renderer>();
				list.Add(new Variant
				{
					Naam = "03_longship_water_mask",
					Aan = delegate
					{
						eigenR.enabled = false;
						oud.enabled = true;
					},
					Uit = delegate
					{
						eigenR.enabled = true;
						oud.enabled = false;
					}
				});
				list.Add(new Variant
				{
					Naam = "04_no_water_mask",
					Aan = delegate
					{
						eigenR.enabled = false;
					},
					Uit = delegate
					{
						eigenR.enabled = true;
					}
				});
			}
			int num2 = 5;
			string[] array = new string[6] { "Drakenschip", "Schilden", "Interieur", "Vellen", "Draak", "Ladders" };
			foreach (string text in array)
			{
				Transform val4 = val.Find(text);
				if ((Object)(object)val4 == (Object)null)
				{
					continue;
				}
				Renderer[] rs = ((Component)val4).GetComponentsInChildren<Renderer>(true);
				list.Add(new Variant
				{
					Naam = $"{num2++:00}_without_{DrakenschipPlugin.EngelseGroep(text).ToLower()}",
					Aan = delegate
					{
						Renderer[] array2 = rs;
						for (int i = 0; i < array2.Length; i++)
						{
							array2[i].enabled = false;
						}
					},
					Uit = delegate
					{
						Renderer[] array2 = rs;
						for (int i = 0; i < array2.Length; i++)
						{
							array2[i].enabled = true;
						}
					}
				});
			}
			Dictionary<Material, Texture> relief = new Dictionary<Material,