Decompiled source of Jormungandr The World Serpent v0.13.325

BepInEx/plugins/Jormungandr_LOCAL_TEST/JormungandrWorldSerpent.dll

Decompiled 18 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
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 UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Audio;
using UnityEngine.Playables;
using UnityEngine.Profiling;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("JormungandrWorldSerpent")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.13.325.0")]
[assembly: AssemblyInformationalVersion("0.13.325")]
[assembly: AssemblyProduct("JormungandrWorldSerpent")]
[assembly: AssemblyTitle("JormungandrWorldSerpent")]
[assembly: AssemblyVersion("0.13.325.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 JormungandrWorldSerpent
{
	internal sealed class EncounterSnapshot
	{
		public Vector3 Position;

		public Vector3 Forward;

		public float Health;

		public float Maximum;

		public bool Aggro;

		public string BrainState;
	}
	internal static class EncounterPersistence
	{
		private static readonly CultureInfo I = CultureInfo.InvariantCulture;

		private static bool Finite(float v)
		{
			if (!float.IsNaN(v))
			{
				return !float.IsInfinity(v);
			}
			return false;
		}

		private static string HexChecksum(string value)
		{
			uint num = 2166136261u;
			byte[] bytes = Encoding.UTF8.GetBytes(value);
			for (int i = 0; i < bytes.Length; i++)
			{
				num = (num ^ bytes[i]) * 16777619;
			}
			return num.ToString("X8", I);
		}

		private static string F(float x)
		{
			return x.ToString("R", I);
		}

		public static string Encode(EncounterSnapshot s)
		{
			if (s == null || !Finite(s.Health) || !Finite(s.Maximum) || s.Health <= 0f || s.Maximum < s.Health || !Finite(s.Position.x) || !Finite(s.Position.y) || !Finite(s.Position.z) || !Finite(s.Forward.x) || !Finite(s.Forward.y) || !Finite(s.Forward.z) || ((Vector3)(ref s.Forward)).sqrMagnitude < 0.001f)
			{
				throw new ArgumentException("Invalid encounter snapshot");
			}
			string text = Convert.ToBase64String(Encoding.UTF8.GetBytes(s.BrainState ?? ""));
			string text2 = string.Join("|", "JORM4", F(s.Position.x), F(s.Position.y), F(s.Position.z), F(s.Forward.x), F(s.Forward.y), F(s.Forward.z), F(s.Health), F(s.Maximum), s.Aggro ? "1" : "0", text);
			return text2 + "|" + HexChecksum(text2);
		}

		public static bool TryDecode(string raw, out EncounterSnapshot result)
		{
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			result = null;
			if (string.IsNullOrEmpty(raw) || raw.Length > 65536)
			{
				return false;
			}
			string[] array = raw.Trim().Split('|');
			bool num = array.Length == 8 && array[0] == "JORM1";
			bool flag = array.Length == 9 && array[0] == "JORM2";
			bool flag2 = array.Length == 10 && array[0] == "JORM3";
			bool flag3 = array.Length == 12 && array[0] == "JORM4";
			if (!num && !flag && !flag2 && !flag3)
			{
				return false;
			}
			if (flag3)
			{
				int num2 = raw.LastIndexOf('|');
				if (num2 < 0 || !string.Equals(HexChecksum(raw.Substring(0, num2)), array[11], StringComparison.OrdinalIgnoreCase))
				{
					return false;
				}
			}
			if ((flag && array[8] != "0" && array[8] != "1") || ((flag2 || flag3) && array[9] != "0" && array[9] != "1"))
			{
				return false;
			}
			float[] array2 = new float[7];
			for (int i = 0; i < array2.Length; i++)
			{
				if (!float.TryParse(array[i + 1], NumberStyles.Float, I, out array2[i]) || !Finite(array2[i]))
				{
					return false;
				}
			}
			if (array2[6] <= 0f)
			{
				return false;
			}
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(array2[3], array2[4], array2[5]);
			if (((Vector3)(ref val)).sqrMagnitude < 0.001f)
			{
				return false;
			}
			float result2 = 0f;
			if ((flag2 || flag3) && (!float.TryParse(array[8], NumberStyles.Float, I, out result2) || !Finite(result2) || result2 <= 0f || result2 < array2[6]))
			{
				return false;
			}
			string brainState = "";
			if (flag3)
			{
				try
				{
					byte[] array3 = Convert.FromBase64String(array[10]);
					if (array3.Length > 32768)
					{
						return false;
					}
					brainState = Encoding.UTF8.GetString(array3);
				}
				catch (FormatException)
				{
					return false;
				}
			}
			result = new EncounterSnapshot
			{
				Position = new Vector3(array2[0], array2[1], array2[2]),
				Forward = ((Vector3)(ref val)).normalized,
				Health = array2[6],
				Maximum = result2,
				Aggro = (flag ? (array[8] == "1") : ((flag2 || flag3) && array[9] == "1")),
				BrainState = brainState
			};
			return true;
		}

		public static bool TryRead(string path, out EncounterSnapshot result, out string origin)
		{
			result = null;
			origin = null;
			if (string.IsNullOrEmpty(path))
			{
				return false;
			}
			string[] array = new string[3]
			{
				path,
				path + ".bak",
				path + ".tmp"
			};
			foreach (string text in array)
			{
				try
				{
					if (File.Exists(text) && TryDecode(File.ReadAllText(text), out result))
					{
						origin = text;
						return true;
					}
				}
				catch (IOException)
				{
				}
				catch (UnauthorizedAccessException)
				{
				}
			}
			return false;
		}

		public static void SaveAtomic(string path, EncounterSnapshot snapshot)
		{
			if (string.IsNullOrEmpty(path))
			{
				throw new ArgumentException("Missing save path");
			}
			Directory.CreateDirectory(Path.GetDirectoryName(path));
			string text = path + ".tmp";
			string text2 = path + ".bak";
			File.WriteAllText(text, Encode(snapshot));
			if (!File.Exists(path))
			{
				File.Move(text, path);
				return;
			}
			try
			{
				File.Replace(text, path, text2);
			}
			catch (PlatformNotSupportedException)
			{
				File.Copy(path, text2, overwrite: true);
				File.Copy(text, path, overwrite: true);
				File.Delete(text);
			}
		}

		public static void DeleteAll(string path)
		{
			if (string.IsNullOrEmpty(path))
			{
				return;
			}
			string[] array = new string[3] { "", ".tmp", ".bak" };
			foreach (string text in array)
			{
				if (File.Exists(path + text))
				{
					File.Delete(path + text);
				}
			}
		}
	}
	internal static class FarSerpentMapMarker
	{
		private sealed class Marker
		{
			public object Pin;

			public string Name;

			public bool Warned;
		}

		private static ZNet world;

		private static object map;

		private static Type pinType;

		private static MethodInfo addPin;

		private static MethodInfo removePin;

		private static FieldInfo pinPosition;

		private static object bossPinType;

		private static bool warned;

		private static float nextTick;

		private static readonly Dictionary<string, Marker> scales = new Dictionary<string, Marker>();

		private static readonly Dictionary<string, Vector3> remoteScales = new Dictionary<string, Vector3>();

		private static readonly List<ZDO> scaleZdos = new List<ZDO>();

		private static readonly List<ZDO> scanningScales = new List<ZDO>();

		private static int scaleCursor;

		private static string completeScaleSnapshot = "";

		private static ZNet scanWorld;

		private static float nextFullScaleScan;

		private static object scalePinType;

		private static float nextScaleScan;

		private static readonly Dictionary<string, Vector3> scalePoints = new Dictionary<string, Vector3>();

		private static readonly Marker real = new Marker
		{
			Name = "Jormungandr - Boss"
		};

		private static readonly Marker preview = new Marker
		{
			Name = "Jormungandr - F3 Vorschau"
		};

		internal static void ReceiveDepthMarkers(string data)
		{
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			if (data == null || data.Length > 12000)
			{
				return;
			}
			Dictionary<string, Vector3> dictionary = new Dictionary<string, Vector3>();
			string[] array = data.Split(';');
			foreach (string text in array)
			{
				if (text.Length != 0)
				{
					string[] array2 = text.Split('|');
					if (array2.Length != 4 || array2[0].Length > 100 || !float.TryParse(array2[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) || !float.TryParse(array2[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) || !float.TryParse(array2[3], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3) || float.IsNaN(result) || float.IsInfinity(result) || float.IsNaN(result2) || float.IsInfinity(result2) || float.IsNaN(result3) || float.IsInfinity(result3))
					{
						return;
					}
					dictionary[array2[0]] = new Vector3(result, result2, result3);
					if (dictionary.Count > 64)
					{
						return;
					}
				}
			}
			remoteScales.Clear();
			foreach (KeyValuePair<string, Vector3> item in dictionary)
			{
				remoteScales[item.Key] = item.Value;
			}
			nextScaleScan = 0f;
		}

		internal unsafe static string DepthMarkerSnapshot()
		{
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			if (ZDOMan.instance == null)
			{
				return "";
			}
			if ((Object)(object)scanWorld != (Object)(object)ZNet.instance)
			{
				scanWorld = ZNet.instance;
				scaleCursor = 0;
				scanningScales.Clear();
				completeScaleSnapshot = "";
				nextFullScaleScan = 0f;
			}
			if (Time.unscaledTime < nextFullScaleScan)
			{
				return completeScaleSnapshot;
			}
			long timestamp = Stopwatch.GetTimestamp();
			for (int i = 0; i < 8; i++)
			{
				scaleZdos.Clear();
				bool allZDOsWithPrefabIterative = ZDOMan.instance.GetAllZDOsWithPrefabIterative("Jormungandr_Tiefenschuppe", scaleZdos, ref scaleCursor);
				foreach (ZDO scaleZdo in scaleZdos)
				{
					if (!string.IsNullOrEmpty(scaleZdo.GetString("JRM145_DepthScaleScene", "")) && scanningScales.Count < 64)
					{
						scanningScales.Add(scaleZdo);
					}
				}
				if (allZDOsWithPrefabIterative)
				{
					List<string> list = new List<string>();
					CultureInfo invariantCulture = CultureInfo.InvariantCulture;
					foreach (ZDO scanningScale in scanningScales)
					{
						if (ZDOMan.instance.GetZDO(scanningScale.m_uid) != null)
						{
							Vector3 position = scanningScale.GetPosition();
							string[] array = new string[7];
							ZDOID uid = scanningScale.m_uid;
							array[0] = ((object)(*(ZDOID*)(&uid))/*cast due to .constrained prefix*/).ToString();
							array[1] = "|";
							array[2] = position.x.ToString("R", invariantCulture);
							array[3] = "|";
							array[4] = position.y.ToString("R", invariantCulture);
							array[5] = "|";
							array[6] = position.z.ToString("R", invariantCulture);
							list.Add(string.Concat(array));
						}
					}
					completeScaleSnapshot = string.Join(";", list);
					scanningScales.Clear();
					scaleCursor = 0;
					nextFullScaleScan = Time.unscaledTime + 2f;
					break;
				}
				if ((double)(Stopwatch.GetTimestamp() - timestamp) * 1000.0 / (double)Stopwatch.Frequency >= 1.5)
				{
					break;
				}
			}
			return completeScaleSnapshot;
		}

		private static void TickDepthScales()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime >= nextScaleScan)
			{
				nextScaleScan = Time.unscaledTime + 3f;
				if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer())
				{
					ReceiveDepthMarkers(DepthMarkerSnapshot());
				}
				nextScaleScan = Time.unscaledTime + 1f;
				scalePoints.Clear();
				foreach (KeyValuePair<string, Vector3> remoteScale in remoteScales)
				{
					scalePoints[remoteScale.Key] = remoteScale.Value;
				}
			}
			foreach (KeyValuePair<string, Marker> scale in scales)
			{
				if (!scalePoints.ContainsKey(scale.Key))
				{
					Remove(scale.Value);
				}
			}
			foreach (KeyValuePair<string, Vector3> scalePoint in scalePoints)
			{
				if (!scales.TryGetValue(scalePoint.Key, out var value))
				{
					value = new Marker
					{
						Name = "Tiefenschuppe"
					};
					scales[scalePoint.Key] = value;
				}
				Set(value, visible: true, scalePoint.Value, scalePinType);
				if (value.Pin == null)
				{
					continue;
				}
				ZNetScene instance = ZNetScene.instance;
				object obj;
				if (instance == null)
				{
					obj = null;
				}
				else
				{
					GameObject prefab = instance.GetPrefab("Jormungandr_Tiefenschuppe");
					if (prefab == null)
					{
						obj = null;
					}
					else
					{
						ItemDrop component = prefab.GetComponent<ItemDrop>();
						obj = ((component != null) ? component.m_itemData.GetIcon() : null);
					}
				}
				Sprite val = (Sprite)obj;
				FieldInfo field = value.Pin.GetType().GetField("m_icon", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if ((Object)(object)val != (Object)null && field != null && field.FieldType == typeof(Sprite))
				{
					field.SetValue(value.Pin, val);
				}
			}
			List<string> list = new List<string>();
			foreach (KeyValuePair<string, Marker> scale2 in scales)
			{
				if (scale2.Value.Pin == null && !scalePoints.ContainsKey(scale2.Key))
				{
					list.Add(scale2.Key);
				}
			}
			foreach (string item in list)
			{
				scales.Remove(item);
			}
		}

		internal static void Clear()
		{
			Remove(real);
			Remove(preview);
			foreach (Marker value in scales.Values)
			{
				Remove(value);
			}
			scales.Clear();
			remoteScales.Clear();
			scalePoints.Clear();
			nextScaleScan = 0f;
			scaleZdos.Clear();
			scanningScales.Clear();
			scaleCursor = 0;
			completeScaleSnapshot = "";
			scanWorld = null;
			nextFullScaleScan = 0f;
			scalePinType = null;
			world = null;
			map = null;
			pinType = null;
			addPin = null;
			removePin = null;
			pinPosition = null;
			bossPinType = null;
			warned = false;
			nextTick = 0f;
		}

		private static object GetMinimap()
		{
			Type type = typeof(Player).Assembly.GetType("Minimap");
			if (type == null)
			{
				return null;
			}
			FieldInfo field = type.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				return field.GetValue(null);
			}
			PropertyInfo property = type.GetProperty("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (!(property != null))
			{
				return null;
			}
			return property.GetValue(null, null);
		}

		private static bool Initialize()
		{
			object minimap = GetMinimap();
			if (minimap == null)
			{
				return false;
			}
			if (map == minimap && addPin != null)
			{
				return true;
			}
			Remove(real);
			Remove(preview);
			foreach (Marker value in scales.Values)
			{
				Remove(value);
			}
			map = minimap;
			Type type = map.GetType();
			pinType = type.GetNestedType("PinType", BindingFlags.Public | BindingFlags.NonPublic);
			if (pinType == null || !pinType.IsEnum)
			{
				return false;
			}
			try
			{
				bossPinType = Enum.Parse(pinType, "Boss");
			}
			catch (ArgumentException)
			{
				try
				{
					bossPinType = Enum.Parse(pinType, "Icon3");
				}
				catch (ArgumentException)
				{
					return false;
				}
			}
			addPin = null;
			removePin = null;
			MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo in methods)
			{
				ParameterInfo[] parameters = methodInfo.GetParameters();
				if (methodInfo.Name == "AddPin" && parameters.Length >= 5 && parameters[0].ParameterType == typeof(Vector3) && parameters[1].ParameterType == pinType && parameters[2].ParameterType == typeof(string) && parameters[3].ParameterType == typeof(bool) && parameters[4].ParameterType == typeof(bool))
				{
					bool flag = true;
					for (int j = 5; j < parameters.Length; j++)
					{
						if (!parameters[j].IsOptional)
						{
							flag = false;
						}
					}
					if (flag && (addPin == null || parameters.Length < addPin.GetParameters().Length))
					{
						addPin = methodInfo;
					}
				}
				if (methodInfo.Name == "RemovePin" && parameters.Length == 1 && parameters[0].ParameterType.Name == "PinData")
				{
					removePin = methodInfo;
				}
			}
			try
			{
				scalePinType = Enum.Parse(pinType, "Icon3");
			}
			catch (ArgumentException)
			{
				scalePinType = bossPinType;
			}
			if (addPin == null || removePin == null)
			{
				return false;
			}
			return true;
		}

		private static void Remove(Marker marker)
		{
			if (marker.Pin == null)
			{
				return;
			}
			try
			{
				if (map != null && removePin != null)
				{
					removePin.Invoke(map, new object[1] { marker.Pin });
				}
			}
			catch (Exception ex)
			{
				if (!marker.Warned)
				{
					Debug.LogWarning((object)("[Jormungandr/v31.10 MAP] Pin entfernen: " + ex.Message));
					marker.Warned = true;
				}
			}
			marker.Pin = null;
		}

		private static void Set(Marker marker, bool visible, Vector3 position, object customType = null)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			if (!visible)
			{
				Remove(marker);
				return;
			}
			try
			{
				if (marker.Pin == null)
				{
					ParameterInfo[] parameters = addPin.GetParameters();
					object[] array = new object[parameters.Length];
					array[0] = position;
					array[1] = customType ?? bossPinType;
					array[2] = JormungandrLocalization.L(marker.Name);
					array[3] = false;
					array[4] = false;
					for (int i = 5; i < array.Length; i++)
					{
						array[i] = parameters[i].DefaultValue;
					}
					marker.Pin = addPin.Invoke(map, array);
					if (marker.Pin == null)
					{
						return;
					}
					pinPosition = marker.Pin.GetType().GetField("m_pos", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					Debug.Log((object)("[Jormungandr/v31.10 MAP] Marker erstellt: " + marker.Name + " pos=" + ((Vector3)(ref position)).ToString("F1")));
				}
				if (pinPosition != null)
				{
					pinPosition.SetValue(marker.Pin, position);
				}
				marker.Pin.GetType().GetField("m_name", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.SetValue(marker.Pin, JormungandrLocalization.L(marker.Name));
			}
			catch (Exception ex)
			{
				if (!marker.Warned)
				{
					Debug.LogWarning((object)("[Jormungandr/v31.10 MAP] Pin update: " + ex.Message));
					marker.Warned = true;
				}
				Remove(marker);
			}
		}

		internal static void Tick()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < nextTick)
			{
				return;
			}
			nextTick = Time.unscaledTime + 0.5f;
			if ((Object)(object)ZNet.instance == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null || !JormungandrNetworkSession.CanParticipate)
			{
				Clear();
				return;
			}
			if ((Object)(object)world != (Object)(object)ZNet.instance)
			{
				Clear();
				world = ZNet.instance;
			}
			if (!Initialize())
			{
				if (!warned)
				{
					warned = true;
					Debug.LogWarning((object)"[Jormungandr/v31.10 MAP] Minimap-Pin API noch nicht verfuegbar.");
				}
			}
			else
			{
				Vector3 position = Vector3.zero;
				Vector3 position2 = Vector3.zero;
				bool flag = (Object)(object)Plugin.Instance != (Object)null && Plugin.Instance.TryGetTrackedBossPosition(out position);
				bool flag2 = HeadScalePreview.TryGetTrackedPosition(out position2);
				Set(real, flag, flag ? position : Vector3.zero);
				Set(preview, flag2, flag2 ? position2 : Vector3.zero);
				TickDepthScales();
			}
		}
	}
	internal static class FarSerpentSurfaceSign
	{
		private sealed class Sign
		{
			internal GameObject Root;

			internal GameObject[] Rings;

			internal LineRenderer[] Lines;

			internal bool WasShowing;

			internal string Label;
		}

		private const float ShowDistance = 1000f;

		private const float FadeStartDistance = 820f;

		private const float TickInterval = 0.12f;

		private static readonly Sign boss = new Sign
		{
			Label = "BOSS"
		};

		private static readonly Sign preview = new Sign
		{
			Label = "F3"
		};

		private static ZNet session;

		private static float nextTick;

		private static float nextBossLookup;

		private static bool cachedBossExists;

		private static Vector3 cachedBossPosition;

		internal static void Clear()
		{
			//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)
			Hide(boss, destroy: true);
			Hide(preview, destroy: true);
			session = null;
			nextTick = 0f;
			nextBossLookup = 0f;
			cachedBossExists = false;
			cachedBossPosition = Vector3.zero;
		}

		private static void Hide(Sign sign, bool destroy)
		{
			if ((Object)(object)sign.Root != (Object)null)
			{
				if (destroy)
				{
					Object.Destroy((Object)(object)sign.Root);
				}
				else
				{
					sign.Root.SetActive(false);
				}
			}
			if (destroy)
			{
				sign.Root = null;
				sign.Rings = null;
				sign.Lines = null;
			}
			sign.WasShowing = false;
		}

		private static void Create(Sign sign)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			sign.Root = new GameObject("Jormungandr_v31_19_Fernwasserzeichen_" + sign.Label);
			sign.Rings = (GameObject[])(object)new GameObject[3];
			sign.Lines = (LineRenderer[])(object)new LineRenderer[3];
			for (int i = 0; i < sign.Rings.Length; i++)
			{
				sign.Rings[i] = VisualFXShapes.Ring("Fernwasser_" + sign.Label + "_" + i, sign.Root.transform, new Color(0.79f, 0.93f, 1f, 0.5f), 3f);
				sign.Rings[i].SetActive(true);
				sign.Lines[i] = sign.Rings[i].GetComponent<LineRenderer>();
			}
			sign.Root.SetActive(false);
		}

		private static void Draw(Sign sign, bool available, Vector3 position, Vector3 player, float sea, float time)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			if (!available)
			{
				if ((Object)(object)sign.Root != (Object)null)
				{
					sign.Root.SetActive(false);
				}
				sign.WasShowing = false;
				return;
			}
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(player.x - position.x, player.z - position.z);
			float magnitude = ((Vector2)(ref val)).magnitude;
			if (magnitude > 1000f)
			{
				if ((Object)(object)sign.Root != (Object)null)
				{
					sign.Root.SetActive(false);
				}
				sign.WasShowing = false;
				return;
			}
			if ((Object)(object)sign.Root == (Object)null)
			{
				Create(sign);
			}
			sign.Root.SetActive(true);
			if (!sign.WasShowing)
			{
				sign.WasShowing = true;
				Debug.Log((object)("[Jormungandr/v31.19 FERNZEICHEN] " + sign.Label + " Oberflaechenbewegung sichtbar bei " + magnitude.ToString("F0") + "m."));
			}
			float num = Mathf.Clamp01((1000f - magnitude) / 180f);
			float num2 = Mathf.Lerp(0.02f, 0.62f, num);
			Vector3 position2 = default(Vector3);
			for (int i = 0; i < 3; i++)
			{
				float num3 = Mathf.Repeat(time * (7f + (float)i * 1.7f) + (float)i * 19f, 65f);
				float radius = 19f + num3 + (float)i * 11f;
				float num4 = 0.6f + 1.1f * Mathf.Sin(time * 1.2f + (float)i * 2.09f);
				((Vector3)(ref position2))..ctor(position.x, sea + 1.8f + num4, position.z);
				VisualFXShapes.SetRing(sign.Rings[i], position2, radius, Mathf.Lerp(2.2f, 4f, num));
				if ((Object)(object)sign.Lines[i] != (Object)null)
				{
					Color val2 = ((i == 1) ? new Color(0.92f, 0.98f, 1f, num2) : new Color(0.68f, 0.87f, 0.96f, num2 * 0.72f));
					LineRenderer obj = sign.Lines[i];
					Color startColor = (sign.Lines[i].endColor = val2);
					obj.startColor = startColor;
				}
			}
		}

		internal static void Tick()
		{
			//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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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)
			if (Time.time < nextTick)
			{
				return;
			}
			nextTick = Time.time + 0.12f;
			ZNet instance = ZNet.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null || !JormungandrNetworkSession.CanParticipate || (Object)(object)ZoneSystem.instance == (Object)null)
			{
				Clear();
				return;
			}
			if ((Object)(object)session != (Object)(object)instance)
			{
				Clear();
				session = instance;
			}
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			Vector3 position2 = Vector3.zero;
			bool available = HeadScalePreview.TryGetVirtualPosition(out position2);
			if (Time.time >= nextBossLookup)
			{
				nextBossLookup = Time.time + 1f;
				cachedBossExists = (Object)(object)Plugin.Instance != (Object)null && (Plugin.Instance.TryGetUnloadedBossPosition(out cachedBossPosition) || Plugin.Instance.TryGetEmergingBossSurface(out cachedBossPosition));
				if (!cachedBossExists)
				{
					cachedBossPosition = Vector3.zero;
				}
			}
			float waterLevel = ZoneSystem.instance.m_waterLevel;
			Draw(preview, available, position2, position, waterLevel, Time.time);
			Draw(boss, cachedBossExists, cachedBossPosition, position, waterLevel, Time.time);
		}
	}
	internal static class HeadScalePreview
	{
		private struct RoutePoint
		{
			internal float Distance;

			internal Vector3 Position;

			internal Vector3 Forward;

			internal RoutePoint(float distance, Vector3 position, Vector3 forward)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				Distance = distance;
				Position = position;
				Forward = forward;
			}
		}

		private const string BundleName = "jormungandr_head_preview";

		private const string PrefabName = "Jormungandr_HeadScalePreview_v11";

		private static AssetBundle bundle;

		private static GameObject cachedPrefab;

		private static bool remoteAssetPrewarmAttempted;

		private static bool previewEmergenceActive;

		private static float previewEmergenceStart;

		private const float EmergenceDepth = 30f;

		private const float EmergenceHeadRiseSeconds = 7f;

		private const float EmergenceTailDelaySeconds = 8f;

		private static GameObject preview;

		private static Transform swimVisualRoot;

		private static Transform swimAlignmentRoot;

		private static Vector3 swimAlignmentRestLocalPosition;

		private static Transform swimHeadBone;

		private static Transform swimRearBone;

		private static ZNet session;

		private static bool warnedBundle;

		private static bool pendingWorldPreview;

		private static ZNet pendingWorldPreviewSession;

		private static bool virtualPreview;

		private static Vector3 virtualPosition;

		private static Vector3 virtualForward;

		private static ZNet virtualWorld;

		private static float nextVirtualLoadAttempt;

		private static float nextRealTerrainMessage;

		private const float PreviewLoadDistance = 650f;

		private const float PreviewUnloadDistance = 1200f;

		private const string DriveMarkerName = "JOR_V31_SWIM_DRIVE";

		private const float SwimCruiseSpeed = 3f;

		private const float SwimAcceleration = 6f;

		private const float SwimTurnDelay = 15f;

		private const float SwimHeadingAmplitudeDeg = 22f;

		private const float SwimTurnPeriodSeconds = 360f;

		private const float SwimMaxYawDegreesPerSecond = 0.4f;

		private const float SwimOldLimitMarker = 150f;

		private static bool swimPatrolActive;

		private static OceanPatrolLoop.Course swimPatrolCourse;

		private static Vector3 swimPatrolGuideOffset;

		private static float swimPatrolNextCheck;

		private static float swimPatrolSpeedFactor = 1f;

		private static bool virtualHasPatrol;

		private static OceanPatrolLoop.Course virtualPatrolCourse;

		private static bool virtualAlreadySurfaced;

		private static bool swimActive;

		private static float swimElapsed;

		private static float swimDistance;

		private static float swimHeadingOffsetDeg;

		private static bool swimPassedOldLimit;

		private static Vector3 swimOrigin;

		private static Vector3 swimInitialDirection;

		private static Vector3 swimDirection;

		private static int swimLastLogBucket;

		private const float CoastScanSeconds = 2.5f;

		private const float CoastLookAhead = 320f;

		private const float CoastFirstStep = 20f;

		private const float CoastStep = 30f;

		private const float CoastHalfWidth = 25f;

		private const float CoastMinimumDepth = 16f;

		private const float CoastEnterDistance = 300f;

		private const float CoastDangerDistance = 105f;

		private const float CoastTurnRate = 0.55f;

		private const float CoastEmergencyTurnRate = 1.25f;

		private static readonly float[] CoastCandidateAngles = new float[7] { -85f, -60f, -35f, 0f, 35f, 60f, 85f };

		private static float coastNextScan;

		private static float coastTargetYaw;

		private static float coastMeanderBaseYaw;

		private static float coastMeanderEpoch;

		private static float coastDesiredSpeedFactor = 1f;

		private static float coastCurrentSpeedFactor = 1f;

		private static float coastNearestUnsafe = 350f;

		private static float coastMinimumMeasuredDepth;

		private static bool coastAvoiding;

		private static bool coastForecastAvoidance;

		private static int coastTurnSide;

		private static int coastClearScans;

		private static float coastLastTargetUpdate;

		private static int coastLastStatusBucket;

		private static bool coastMissingTerrainWarned;

		private static float coastNextMissingTerrainLog;

		private static bool coastFirstOpenWaterLogged;

		private static bool coastHasPreviousScan;

		private static Vector3 coastPreviousHead;

		private static Vector3 coastPreviousForward;

		private static float coastPreviousClearance;

		private static float coastPreviousPredictedSpeed;

		private static bool coastPendingDanger;

		private static Vector3 coastPendingPosition;

		private static int coastPendingSeen;

		private static int coastLastDiagnosticBucket = -1;

		private const int TrailSpineCount = 82;

		private const float TrailPointSpacing = 0.75f;

		private const string SwimWaveMarkerName = "JOR_V31_1_SWIM_WAVE";

		private static readonly List<RoutePoint> swimRoute = new List<RoutePoint>(768);

		private static Transform[] swimSpine;

		private static float[] swimArc;

		private static Vector3[] swimOriginalLocalPos;

		private static Quaternion[] swimOriginalLocalRot;

		private static Vector3[] swimSampledWorldPos;

		private static Quaternion[] swimSampledWorldRot;

		private static Animation swimBoneAnimation;

		private static Vector3 swimGuideLocal;

		private static Vector3 swimGuideOrigin;

		private static float swimSpineLength;

		private static bool swimTrailActive;

		private static int swimLastTrailLogBucket;

		internal static bool TryGetVirtualPosition(out Vector3 position)
		{
			//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_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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			position = Vector3.zero;
			if (virtualPreview && (Object)(object)virtualWorld == (Object)(object)ZNet.instance)
			{
				position = virtualPosition;
				return true;
			}
			if (previewEmergenceActive && (Object)(object)preview != (Object)null && (Object)(object)session == (Object)(object)ZNet.instance)
			{
				position = preview.transform.position;
				return true;
			}
			return false;
		}

		internal static bool TryGetTrackedPosition(out Vector3 position)
		{
			//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_0023: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			position = Vector3.zero;
			if ((Object)(object)preview != (Object)null)
			{
				position = preview.transform.position;
				return true;
			}
			if (virtualPreview && (Object)(object)virtualWorld == (Object)(object)ZNet.instance)
			{
				position = virtualPosition;
				return true;
			}
			return false;
		}

		private static float CoastAdaptiveYawRate(float speed, float clearance)
		{
			float num = Mathf.Clamp01((300f - clearance) / 195f);
			return Mathf.Min(Mathf.Lerp(0.55f, 1.25f, num), Mathf.Max(0.01f, speed) * 57.29578f / 105f);
		}

		private static bool TryCoastDepth(Vector3 position, float seaLevel, out float depth)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return OceanCourseProbe.TryDepth(position, seaLevel, out depth);
		}

		private static float CoastCorridorClearance(Vector3 head, Vector3 forward, float desiredTurnDeg, float yawRateDegPerSecond, float expectedSpeed, float seaLevel, out float shallowestDepth, out bool allSamplesKnown)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return OceanCourseProbe.Clearance(head, forward, desiredTurnDeg, yawRateDegPerSecond, expectedSpeed, seaLevel, out shallowestDepth, out allSamplesKnown);
		}

		private static Vector3 CoastHeadPosition()
		{
			//IL_0007: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (swimTrailActive)
			{
				return CurrentGuidePosition();
			}
			if ((Object)(object)swimHeadBone != (Object)null)
			{
				return swimHeadBone.position;
			}
			return preview.transform.position + swimDirection * 10f;
		}

		private static void ScanUnloadedCoast(Vector3 head, float sea, float predictedSpeed, float firstUnknown, float shallowestVerified)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			OceanCourseProbe.NavigationForecast navigationForecast = OceanCourseProbe.ForecastRoute(head, swimDirection, 0f, 0.55f, predictedSpeed, sea);
			float firstUnverified = Mathf.Min(firstUnknown, navigationForecast.FirstUnverified);
			coastNearestUnsafe = firstUnknown;
			coastMinimumMeasuredDepth = shallowestVerified;
			float num = ((navigationForecast.FullyPassable && firstUnknown > 85f) ? 1.75f : 1.1f);
			coastNextScan = Mathf.Min(coastNextScan, swimElapsed + num);
			coastHasPreviousScan = false;
			coastPendingDanger = false;
			coastPendingSeen = 0;
			if (navigationForecast.FullyPassable)
			{
				if (coastForecastAvoidance && ++coastClearScans >= 3)
				{
					coastAvoiding = false;
					coastForecastAvoidance = false;
					coastTurnSide = 0;
					coastMeanderBaseYaw = swimHeadingOffsetDeg;
					coastMeanderEpoch = swimElapsed;
					Debug.Log((object)"[HeadPreview/v31.23 ROUTE] Seed-Umweg erledigt; Maeandern wieder frei (weiter unbestaetigtes Terrain).");
				}
				float num2 = OceanCourseProbe.ForecastCruiseFactor(firstUnverified, allSeedSamplesPassable: true, unresolved: false);
				coastDesiredSpeedFactor = ((coastAvoiding && !coastForecastAvoidance) ? Mathf.Min(coastDesiredSpeedFactor, num2) : num2);
			}
			else
			{
				coastClearScans = 0;
				float num3 = Mathf.Min(navigationForecast.FirstConfirmedDanger, navigationForecast.FirstProjectedDanger);
				float num4 = navigationForecast.Clearance;
				float num5 = 0f;
				float yawRateDegPerSecond = CoastAdaptiveYawRate(predictedSpeed, Mathf.Min(320f, num3));
				for (int i = 0; i < CoastCandidateAngles.Length; i++)
				{
					float num6 = CoastCandidateAngles[i];
					if (Mathf.Abs(num6) < 0.01f)
					{
						continue;
					}
					OceanCourseProbe.NavigationForecast navigationForecast2 = OceanCourseProbe.ForecastRoute(head, swimDirection, num6, yawRateDegPerSecond, predictedSpeed, sea);
					if (!navigationForecast2.Unresolved && !(navigationForecast2.Clearance < 90f))
					{
						float num7 = navigationForecast2.Clearance - Mathf.Abs(num6) * 0.16f;
						int num8 = ((num6 > 0f) ? 1 : (-1));
						if (coastTurnSide != 0 && num8 != coastTurnSide)
						{
							num7 -= 75f;
						}
						if (num7 > num4 + 25f)
						{
							num4 = num7;
							num5 = num6;
						}
					}
				}
				if (Mathf.Abs(num5) > 0.01f)
				{
					bool num9 = !coastAvoiding;
					if (num9)
					{
						coastForecastAvoidance = true;
					}
					coastAvoiding = true;
					coastTurnSide = ((num5 > 0f) ? 1 : (-1));
					Vector3 val = Quaternion.AngleAxis(num5, Vector3.up) * swimDirection;
					float num10 = Vector3.SignedAngle(swimInitialDirection, val, Vector3.up);
					bool flag = Mathf.Abs(Mathf.DeltaAngle(swimHeadingOffsetDeg, coastTargetYaw)) < 10f;
					if (num9 || flag || (num3 < 70f && swimElapsed - coastLastTargetUpdate > 9f))
					{
						coastTargetYaw = num10;
						coastLastTargetUpdate = swimElapsed;
					}
				}
				float num11 = OceanCourseProbe.ForecastCruiseFactor(firstUnverified, allSeedSamplesPassable: false, navigationForecast.Unresolved);
				if (!float.IsInfinity(num3))
				{
					float num12 = ((num3 <= 50f) ? 0.25f : ((num3 <= 100f) ? 0.45f : ((num3 <= 170f) ? 0.65f : 0.85f)));
					num11 = Mathf.Min(num11, num12);
				}
				if (Mathf.Abs(num5) > 0.01f && num3 > 100f)
				{
					num11 = Mathf.Max(0.5f, num11);
				}
				coastDesiredSpeedFactor = ((coastAvoiding && !coastForecastAvoidance) ? Mathf.Min(coastDesiredSpeedFactor, num11) : num11);
				if (Mathf.Abs(num5) < 0.01f && (navigationForecast.Unresolved || num3 <= 60f))
				{
					coastDesiredSpeedFactor = Mathf.Min(coastDesiredSpeedFactor, 0.25f);
				}
			}
			if (!coastMissingTerrainWarned || swimElapsed >= coastNextMissingTerrainLog)
			{
				coastNextMissingTerrainLog = swimElapsed + 12f;
				Debug.Log((object)("[HeadPreview/v31.23 ROUTE FORECAST] erstesGeladeloch=" + F(firstUnknown) + "m forecast=" + F(navigationForecast.Clearance) + "m seedSamples=" + navigationForecast.SeedSamples + " loadedSamples=" + navigationForecast.LoadedSamples + " unaufgeklaert=" + navigationForecast.Unresolved + " prognoseFrei=" + navigationForecast.FullyPassable + " echtGefahr=" + (float.IsInfinity(navigationForecast.FirstConfirmedDanger) ? "NEIN" : (F(navigationForecast.FirstConfirmedDanger) + "m")) + " speedFactor=" + F(coastDesiredSpeedFactor) + " avoidance=" + coastAvoiding));
			}
			coastMissingTerrainWarned = true;
		}

		private static void ScanCoast()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_00d4: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_056c: Unknown result type (might be due to invalid IL or missing references)
			//IL_056d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0694: Unknown result type (might be due to invalid IL or missing references)
			//IL_0699: Unknown result type (might be due to invalid IL or missing references)
			//IL_069e: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06db: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0700: Unknown result type (might be due to invalid IL or missing references)
			//IL_0701: Unknown result type (might be due to invalid IL or missing references)
			//IL_0705: Unknown result type (might be due to invalid IL or missing references)
			//IL_070a: Unknown result type (might be due to invalid IL or missing references)
			//IL_070f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0716: Unknown result type (might be due to invalid IL or missing references)
			//IL_071b: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_07db: Unknown result type (might be due to invalid IL or missing references)
			//IL_07dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0770: Unknown result type (might be due to invalid IL or missing references)
			//IL_0771: Unknown result type (might be due to invalid IL or missing references)
			if (!swimActive || (Object)(object)preview == (Object)null || (Object)(object)ZoneSystem.instance == (Object)null || swimElapsed < coastNextScan)
			{
				return;
			}
			coastNextScan = swimElapsed + 2.5f;
			float waterLevel = ZoneSystem.instance.m_waterLevel;
			Vector3 val = CoastHeadPosition();
			val.y = waterLevel;
			float num = Mathf.Max(0.75f, 3f * coastCurrentSpeedFactor);
			float shallowestDepth;
			bool allSamplesKnown;
			OceanCourseProbe.Hazard hazard;
			float num2 = OceanCourseProbe.ClearanceDetailed(val, swimDirection, 0f, 0.55f, num, waterLevel, out shallowestDepth, out allSamplesKnown, out hazard);
			if (!allSamplesKnown)
			{
				ScanUnloadedCoast(val, waterLevel, num, num2, shallowestDepth);
				return;
			}
			coastMissingTerrainWarned = false;
			if (hazard.Found && num2 <= 300f)
			{
				coastForecastAvoidance = false;
			}
			bool flag = coastHasPreviousScan && coastPreviousClearance - num2 > 55f && Vector3.Distance(val, coastPreviousHead) < 22f;
			bool flag2 = false;
			float num3 = -1f;
			if (flag)
			{
				num3 = CoastCorridorClearance(coastPreviousHead, coastPreviousForward, 0f, 0.55f, coastPreviousPredictedSpeed, waterLevel, out var _, out var allSamplesKnown2);
				flag2 = !allSamplesKnown2 || Mathf.Abs(num3 - coastPreviousClearance) > 35f;
			}
			int unsafeSamples = 0;
			int knownSamples = 0;
			float minimumDepth = 10000f;
			if (hazard.Found && num2 < 300f)
			{
				OceanCourseProbe.CheckHazardNeighborhood(hazard.Position, swimDirection, waterLevel, out unsafeSamples, out knownSamples, out minimumDepth);
			}
			bool flag3 = hazard.Found && unsafeSamples >= 3;
			int num4;
			if (hazard.Found && num2 <= 105f && !flag3)
			{
				if (!flag2 && unsafeSamples >= 3)
				{
					num4 = ((knownSamples < 9) ? 1 : 0);
					if (num4 == 0)
					{
						goto IL_021e;
					}
				}
				else
				{
					num4 = 1;
				}
				if (coastPendingDanger && Vector3.Distance(coastPendingPosition, hazard.Position) <= 30f)
				{
					coastPendingSeen++;
				}
				else
				{
					coastPendingDanger = true;
					coastPendingPosition = hazard.Position;
					coastPendingSeen = 1;
				}
				if (coastPendingSeen < 2)
				{
					coastNextScan = Mathf.Min(coastNextScan, swimElapsed + 0.7f);
				}
				goto IL_022a;
			}
			num4 = 0;
			goto IL_021e;
			IL_022a:
			bool flag4 = num4 != 0 && coastPendingSeen < 2;
			if (flag || flag4 || (hazard.Found && num2 <= 105f && Mathf.FloorToInt(swimElapsed / 10f) != coastLastDiagnosticBucket))
			{
				coastLastDiagnosticBucket = Mathf.FloorToInt(swimElapsed / 10f);
				Debug.Log((object)("[HeadPreview/v3.1.9.1 COAST SENSOR] t=" + F(swimElapsed) + "s runway=" + F(num2) + "m previous=" + (coastHasPreviousScan ? F(coastPreviousClearance) : "n/a") + "m jump=" + flag + " oldAnchorNow=" + F(num3) + "m terrainChanged=" + flag2 + " hazard=" + (hazard.Found ? ((Vector3)(ref hazard.Position)).ToString("F1") : "NONE") + " lane=" + hazard.Lane + " depth=" + F(hazard.Depth) + "m nearbyUnsafe=" + unsafeSamples + "/" + knownSamples + " pending=" + flag4 + " confirmed=" + flag3 + " repeat=" + coastPendingSeen + " heading=" + ((Vector3)(ref swimDirection)).ToString("F2") + " speedNow=" + F(num) + " speedBefore=" + F(coastPreviousPredictedSpeed)));
			}
			coastHasPreviousScan = true;
			coastPreviousHead = val;
			coastPreviousForward = swimDirection;
			coastPreviousClearance = num2;
			coastPreviousPredictedSpeed = num;
			coastNearestUnsafe = num2;
			coastMinimumMeasuredDepth = shallowestDepth;
			if (!coastFirstOpenWaterLogged)
			{
				coastFirstOpenWaterLogged = true;
				Debug.Log((object)("[HeadPreview/v3.1.9.1 COAST] FIRST SCAN: runway=" + F(Mathf.Min(320f, num2)) + "m " + ((num2 > 300f) ? "OPEN WATER - normaler Geradeausstart" : "KUERZERER KORRIDOR - vorsichtig ausweichen") + "; derselbe Fahrkorridor-Sensor wie beim Tiefsee-Spawn."));
			}
			if (num2 > 300f)
			{
				coastDesiredSpeedFactor = 1f;
				if (coastAvoiding && ++coastClearScans >= 3)
				{
					coastAvoiding = false;
					coastForecastAvoidance = false;
					coastTurnSide = 0;
					coastMeanderBaseYaw = swimHeadingOffsetDeg;
					coastMeanderEpoch = swimElapsed;
					coastDesiredSpeedFactor = 1f;
					Debug.Log((object)("[HeadPreview/v3.1.5 COAST] CLEAR: weiter im Tiefwasser; normales Maeandern setzt sanft bei yaw=" + F(coastMeanderBaseYaw) + "deg fort."));
				}
				return;
			}
			coastClearScans = 0;
			float yawRateDegPerSecond = CoastAdaptiveYawRate(num, num2);
			float num5 = float.NegativeInfinity;
			float num6 = 0f;
			float num7 = num2;
			float value = shallowestDepth;
			for (int i = 0; i < CoastCandidateAngles.Length; i++)
			{
				float num8 = CoastCandidateAngles[i];
				float shallowestDepth3;
				bool allSamplesKnown3;
				float num9 = CoastCorridorClearance(val, swimDirection, num8, yawRateDegPerSecond, num, waterLevel, out shallowestDepth3, out allSamplesKnown3);
				if (allSamplesKnown3)
				{
					int num10 = ((num8 > 0f) ? 1 : ((num8 < 0f) ? (-1) : 0));
					float num11 = num9 + Mathf.Min(50f, Mathf.Max(0f, shallowestDepth3)) * 0.15f - Mathf.Abs(num8) * 0.18f;
					if (coastTurnSide != 0 && num10 != 0 && num10 != coastTurnSide)
					{
						num11 -= ((num2 < 40f) ? 80f : 165f);
					}
					if (coastTurnSide != 0 && num10 == coastTurnSide)
					{
						num11 += 12f;
					}
					if (num11 > num5)
					{
						num5 = num11;
						num6 = num8;
						num7 = num9;
						value = shallowestDepth3;
					}
				}
			}
			if (float.IsNegativeInfinity(num5))
			{
				coastDesiredSpeedFactor = ((flag4 && num2 > 20f) ? 0.55f : Mathf.Min(coastDesiredSpeedFactor, 0.2f));
				Debug.LogWarning((object)"[HeadPreview/v3.1.5 COAST] Keine gueltige Ausweichroute im 320m-Korridor, Geschwindigkeit vorsichtig reduziert.");
				return;
			}
			if (Mathf.Abs(num6) < 0.01f)
			{
				Vector3 val2 = Vector3.Cross(Vector3.up, swimDirection);
				Vector3 normalized = ((Vector3)(ref val2)).normalized;
				float num12 = Mathf.Max(110f, num2 * 0.7f);
				float num13 = Mathf.Min(320f, num2 + 40f);
				float depth;
				bool flag5 = TryCoastDepth(val - normalized * num12 + swimDirection * num13, waterLevel, out depth);
				float depth2;
				bool flag6 = TryCoastDepth(val + normalized * num12 + swimDirection * num13, waterLevel, out depth2);
				num6 = ((coastTurnSide != 0) ? (85f * (float)coastTurnSide) : ((!(flag5 && flag6)) ? (flag5 ? (-85f) : 85f) : ((depth >= depth2) ? (-85f) : 85f)));
				float shallowestDepth4;
				bool allSamplesKnown4;
				float num14 = CoastCorridorClearance(val, swimDirection, num6, yawRateDegPerSecond, num, waterLevel, out shallowestDepth4, out allSamplesKnown4);
				if (allSamplesKnown4)
				{
					num7 = num14;
					value = shallowestDepth4;
				}
			}
			bool flag7 = !coastAvoiding;
			coastAvoiding = true;
			coastForecastAvoidance = false;
			if (num6 != 0f)
			{
				coastTurnSide = ((num6 > 0f) ? 1 : (-1));
			}
			Vector3 val3 = Quaternion.AngleAxis(num6, Vector3.up) * swimDirection;
			float num15 = Vector3.SignedAngle(swimInitialDirection, val3, Vector3.up);
			bool flag8 = Mathf.Abs(Mathf.DeltaAngle(swimHeadingOffsetDeg, coastTargetYaw)) < 10f;
			if (flag7 || flag8 || (num2 <= 40f && swimElapsed - coastLastTargetUpdate >= 10f))
			{
				coastTargetYaw = num15;
				coastLastTargetUpdate = swimElapsed;
			}
			if (num7 <= 20f)
			{
				coastDesiredSpeedFactor = 0.2f;
			}
			else if (num7 < 300f)
			{
				coastDesiredSpeedFactor = Mathf.Clamp((num7 - 20f) / 280f, 0.2f, 1f);
			}
			else
			{
				coastDesiredSpeedFactor = 1f;
			}
			if (flag4)
			{
				if (num2 > 20f)
				{
					coastDesiredSpeedFactor = Mathf.Max(0.55f, coastDesiredSpeedFactor);
				}
				else
				{
					coastDesiredSpeedFactor = Mathf.Min(0.2f, coastDesiredSpeedFactor);
				}
			}
			if (flag7 || swimElapsed - (float)coastLastStatusBucket * 15f >= 15f || num7 < 105f)
			{
				coastLastStatusBucket = Mathf.FloorToInt(swimElapsed / 15f);
				Debug.Log((object)("[HeadPreview/v3.1.9.1 COAST] " + (flag7 ? "AVOID START" : "AVOID") + " t=" + F(swimElapsed) + "s straightClear=" + F(num2) + "m plannedClear=" + F(num7) + "m turn=" + F(num6) + "deg targetYaw=" + F(coastTargetYaw) + "deg minDepth=" + F(value) + "m speedFactor=" + F(coastDesiredSpeedFactor) + " yawRate=" + F(CoastAdaptiveYawRate(num, num2)) + " provisional=" + flag4 + " sample=3x25m-lanes, 320m ahead."));
			}
			return;
			IL_021e:
			coastPendingDanger = false;
			coastPendingSeen = 0;
			goto IL_022a;
		}

		private static void ResetCoastNavigation()
		{
			//IL_0094: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			coastNextScan = 0f;
			coastTargetYaw = 0f;
			coastMeanderBaseYaw = 0f;
			coastMeanderEpoch = 0f;
			coastDesiredSpeedFactor = 1f;
			coastCurrentSpeedFactor = 1f;
			coastNearestUnsafe = 350f;
			coastMinimumMeasuredDepth = 0f;
			coastAvoiding = false;
			coastForecastAvoidance = false;
			coastTurnSide = 0;
			coastClearScans = 0;
			coastLastTargetUpdate = 0f;
			coastLastStatusBucket = 0;
			coastMissingTerrainWarned = false;
			coastNextMissingTerrainLog = 0f;
			coastFirstOpenWaterLogged = false;
			coastHasPreviousScan = false;
			coastPreviousHead = Vector3.zero;
			coastPreviousForward = Vector3.zero;
			coastPreviousClearance = 350f;
			coastPreviousPredictedSpeed = 3f;
			coastPendingDanger = false;
			coastPendingPosition = Vector3.zero;
			coastPendingSeen = 0;
			coastLastDiagnosticBucket = -1;
		}

		private static string F(float value)
		{
			return value.ToString("F2", CultureInfo.InvariantCulture);
		}

		private static Transform FindRigBone(Transform root, string name)
		{
			if ((Object)(object)root == (Object)null)
			{
				return null;
			}
			Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (((Object)val).name == name)
				{
					return val;
				}
			}
			return null;
		}

		private static Vector3 CurrentHeadForward()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0039: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)swimHeadBone == (Object)null || (Object)(object)swimRearBone == (Object)null)
			{
				return Vector3.zero;
			}
			Vector3 val = swimHeadBone.position - swimRearBone.position;
			val.y = 0f;
			if (!(((Vector3)(ref val)).sqrMagnitude > 0.0001f))
			{
				return Vector3.zero;
			}
			return ((Vector3)(ref val)).normalized;
		}

		private static void AlignVisibleRig(Vector3 travelDirection, float seaY)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)swimAlignmentRoot == (Object)null) && !((Object)(object)swimVisualRoot == (Object)null))
			{
				swimHeadBone = FindRigBone(swimVisualRoot, "SPINE_000");
				swimRearBone = FindRigBone(swimVisualRoot, "SPINE_010");
				if ((Object)(object)swimRearBone == (Object)null)
				{
					swimRearBone = FindRigBone(swimVisualRoot, "SPINE_024");
				}
				Vector3 val = CurrentHeadForward();
				if (((Vector3)(ref val)).sqrMagnitude < 0.5f)
				{
					Debug.LogWarning((object)"[HeadPreview/v3.1 AXIS] Keine verwertbaren SPINE_000/010/024-Knochen im Bundle. Modell bleibt ungedreht; bitte dieses Log schicken.");
					return;
				}
				Vector3 position = swimHeadBone.position;
				float num = Vector3.SignedAngle(val, travelDirection, Vector3.up);
				swimAlignmentRoot.rotation = Quaternion.AngleAxis(num, Vector3.up) * swimAlignmentRoot.rotation;
				Transform obj = swimAlignmentRoot;
				obj.position += position - swimHeadBone.position;
				Transform obj2 = swimAlignmentRoot;
				obj2.position += Vector3.up * (seaY - 1.2f - swimHeadBone.position.y);
				float value = Vector3.Dot(CurrentHeadForward(), travelDirection);
				string[] obj3 = new string[13]
				{
					"[HeadPreview/v3.1 AXIS] autoYaw=",
					F(num),
					"deg preDot=",
					F(Vector3.Dot(val, travelDirection)),
					" postDot=",
					F(value),
					" seaY=",
					F(seaY),
					" head=",
					null,
					null,
					null,
					null
				};
				Vector3 position2 = swimHeadBone.position;
				obj3[9] = ((Vector3)(ref position2)).ToString("F1");
				obj3[10] = " travel=";
				obj3[11] = ((Vector3)(ref travelDirection)).ToString("F2");
				obj3[12] = " (Driver bleibt unveraendert)";
				Debug.Log((object)string.Concat(obj3));
			}
		}

		private static void SetupRouteFollowing(bool hasDriveMarker, bool hasWaveMarker)
		{
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: 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_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			swimTrailActive = false;
			swimRoute.Clear();
			swimSpine = null;
			swimArc = null;
			swimOriginalLocalPos = null;
			swimOriginalLocalRot = null;
			swimSampledWorldPos = null;
			swimSampledWorldRot = null;
			swimBoneAnimation = null;
			swimSpineLength = 0f;
			swimLastTrailLogBucket = 0;
			if (!hasDriveMarker || !hasWaveMarker)
			{
				Debug.LogWarning((object)"[HeadPreview/v3.1.3] TRAIL deaktiviert: v31.1-Bundle-Marker fehlen. F3 schwimmt weiter wie v31.2; bitte neues v31.1-Bundle installieren.");
			}
			else
			{
				if ((Object)(object)preview == (Object)null || (Object)(object)swimVisualRoot == (Object)null || (Object)(object)swimHeadBone == (Object)null)
				{
					return;
				}
				swimBoneAnimation = ((Component)swimVisualRoot).GetComponentInChildren<Animation>(true);
				if ((Object)(object)swimBoneAnimation == (Object)null)
				{
					Debug.LogWarning((object)"[HeadPreview/v3.1.3] TRAIL deaktiviert: 82-Knochen-Swim-Animation fehlt.");
					return;
				}
				Transform[] array = (Transform[])(object)new Transform[82];
				float[] array2 = new float[82];
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = FindRigBone(swimVisualRoot, "SPINE_" + i.ToString("D3"));
					if ((Object)(object)array[i] == (Object)null)
					{
						Debug.LogWarning((object)("[HeadPreview/v3.1.3] TRAIL deaktiviert: SPINE_" + i.ToString("D3") + " fehlt."));
						return;
					}
					if (i > 0 && (Object)(object)array[i].parent != (Object)(object)array[0].parent)
					{
						Debug.LogWarning((object)"[HeadPreview/v3.1.3] TRAIL deaktiviert: SPINE-Bones sind nicht unabhaengig unter demselben Parent.");
						return;
					}
				}
				swimBoneAnimation.Sample();
				Vector3[] array3 = (Vector3[])(object)new Vector3[82];
				Quaternion[] array4 = (Quaternion[])(object)new Quaternion[82];
				for (int j = 0; j < array.Length; j++)
				{
					array3[j] = array[j].localPosition;
					array4[j] = array[j].localRotation;
					if (j > 0)
					{
						array2[j] = array2[j - 1] + Vector3.Distance(array[j - 1].position, array[j].position);
						if (array2[j] <= array2[j - 1] + 0.01f)
						{
							Debug.LogWarning((object)"[HeadPreview/v3.1.3] TRAIL deaktiviert: Spine-Bone-Abstand ungueltig.");
							return;
						}
					}
				}
				if (array2[81] < 300f || array2[81] > 520f)
				{
					Debug.LogWarning((object)("[HeadPreview/v3.1.3] TRAIL deaktiviert: ungewoehnliche Wirbelsaeulenlaenge=" + F(array2[81]) + "m."));
					return;
				}
				swimSpine = array;
				swimArc = array2;
				swimOriginalLocalPos = array3;
				swimOriginalLocalRot = array4;
				swimSampledWorldPos = (Vector3[])(object)new Vector3[array.Length];
				swimSampledWorldRot = (Quaternion[])(object)new Quaternion[array.Length];
				swimSpineLength = array2[81];
				swimGuideLocal = preview.transform.InverseTransformPoint(array[0].position);
				swimGuideOrigin = preview.transform.TransformPoint(swimGuideLocal);
				if (swimPatrolActive)
				{
					swimPatrolGuideOffset = swimGuideOrigin - swimPatrolCourse.Position(0f);
				}
				swimRoute.Add(new RoutePoint(0f, swimGuideOrigin, swimInitialDirection));
				swimTrailActive = true;
				preview.AddComponent<HeadScalePreviewRouteFollower>();
				Debug.Log((object)("[HeadPreview/v3.1.3] TRAIL START: 82 independent bones; length=" + F(swimSpineLength) + "m; samples every " + F(0.75f) + "m; wave=12s unchanged; guide=" + ((Vector3)(ref swimGuideOrigin)).ToString("F1") + "; LateUpdate deformation ON."));
			}
		}

		private static Vector3 CurrentGuidePosition()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			return preview.transform.TransformPoint(swimGuideLocal);
		}

		private static void RecordRoutePoint()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (!swimTrailActive || (Object)(object)preview == (Object)null || swimRoute.Count == 0)
			{
				return;
			}
			RoutePoint routePoint = swimRoute[swimRoute.Count - 1];
			if (swimDistance - routePoint.Distance >= 0.75f)
			{
				swimRoute.Add(new RoutePoint(swimDistance, CurrentGuidePosition(), swimDirection));
			}
			float num = swimDistance - swimSpineLength - 20f;
			if (num > 0f && swimRoute.Count > 3)
			{
				int i;
				for (i = 0; i + 1 < swimRoute.Count && swimRoute[i + 1].Distance < num; i++)
				{
				}
				if (i > 0)
				{
					swimRoute.RemoveRange(0, i);
				}
			}
		}

		private static void RouteAt(float distance, out Vector3 point, out Vector3 direction)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			if (distance <= 0f)
			{
				if (swimPatrolActive)
				{
					direction = swimPatrolCourse.Forward(distance);
					point = swimPatrolCourse.Position(distance) + Quaternion.FromToRotation(swimInitialDirection, direction) * swimPatrolGuideOffset;
				}
				else
				{
					point = swimGuideOrigin + swimInitialDirection * distance;
					direction = swimInitialDirection;
				}
				return;
			}
			Vector3 val = CurrentGuidePosition();
			if (distance >= swimDistance)
			{
				point = val;
				direction = swimDirection;
				return;
			}
			RoutePoint routePoint = swimRoute[0];
			if (distance <= routePoint.Distance)
			{
				point = routePoint.Position + routePoint.Forward * (distance - routePoint.Distance);
				direction = routePoint.Forward;
				return;
			}
			int num = swimRoute.Count - 1;
			RoutePoint routePoint2 = swimRoute[num];
			RoutePoint routePoint3;
			RoutePoint routePoint4;
			if (distance >= routePoint2.Distance)
			{
				routePoint3 = routePoint2;
				routePoint4 = new RoutePoint(swimDistance, val, swimDirection);
			}
			else
			{
				int num2 = 0;
				int num3 = num;
				while (num2 + 1 < num3)
				{
					int num4 = (num2 + num3) / 2;
					if (swimRoute[num4].Distance <= distance)
					{
						num2 = num4;
					}
					else
					{
						num3 = num4;
					}
				}
				routePoint3 = swimRoute[num2];
				routePoint4 = swimRoute[num3];
			}
			float num5 = Mathf.Clamp01((distance - routePoint3.Distance) / Mathf.Max(0.0001f, routePoint4.Distance - routePoint3.Distance));
			point = Vector3.LerpUnclamped(routePoint3.Position, routePoint4.Position, num5);
			direction = Vector3.LerpUnclamped(routePoint3.Forward, routePoint4.Forward, num5);
			direction.y = 0f;
			direction = ((((Vector3)(ref direction)).sqrMagnitude > 0.001f) ? ((Vector3)(ref direction)).normalized : swimDirection);
		}

		internal static void ApplyRouteInLateUpdate()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: 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_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			if (!swimTrailActive || !swimActive || (Object)(object)preview == (Object)null || swimSpine == null || (Object)(object)swimBoneAnimation == (Object)null)
			{
				return;
			}
			for (int i = 0; i < swimSpine.Length; i++)
			{
				swimSpine[i].localPosition = swimOriginalLocalPos[i];
				swimSpine[i].localRotation = swimOriginalLocalRot[i];
			}
			swimBoneAnimation.Sample();
			for (int j = 0; j < swimSpine.Length; j++)
			{
				swimSampledWorldPos[j] = swimSpine[j].position;
				swimSampledWorldRot[j] = swimSpine[j].rotation;
			}
			Vector3 val = swimSampledWorldPos[0];
			Vector3 val2 = CurrentGuidePosition();
			float num = 0f;
			float value = 0f;
			for (int k = 0; k < swimSpine.Length; k++)
			{
				Transform val3 = swimSpine[k];
				Vector3 val4 = swimSampledWorldPos[k];
				Quaternion val5 = swimSampledWorldRot[k];
				float num2 = swimArc[k];
				RouteAt(swimDistance - num2, out var point, out var direction);
				Vector3 val6 = val - swimDirection * num2;
				Vector3 val7 = val4 - val6;
				float num3 = Vector3.SignedAngle(swimDirection, direction, Vector3.up);
				Quaternion val8 = Quaternion.AngleAxis(num3, Vector3.up);
				val3.position = val + (point - val2) + val8 * val7;
				val3.rotation = val8 * val5;
				if (previewEmergenceActive)
				{
					float num4 = num2 / Mathf.Max(1f, swimSpineLength) * 8f;
					float num5 = Mathf.Clamp01((Time.time - previewEmergenceStart - num4) / 7f);
					float num6 = Mathf.SmoothStep(0f, 1f, num5);
					val3.position -= Vector3.up * (30f * (1f - num6));
				}
				float num7 = Vector3.Distance(point, val2 - swimDirection * num2);
				num = Mathf.Max(num, num7);
				if (k == swimSpine.Length - 1)
				{
					value = num3;
				}
			}
			int num8 = Mathf.FloorToInt(swimElapsed / 5f);
			if (num8 > swimLastTrailLogBucket)
			{
				swimLastTrailLogBucket = num8;
				string[] obj = new string[12]
				{
					"[HeadPreview/v3.1.3] TRAIL t=",
					F(swimElapsed),
					"s bones=82 routePoints=",
					swimRoute.Count.ToString(),
					" bodyLength=",
					F(swimSpineLength),
					"m maxBend=",
					F(num),
					"m tailYawLag=",
					F(value),
					"deg; lastBone=",
					null
				};
				Vector3 position = swimSpine[81].position;
				obj[11] = ((Vector3)(ref position)).ToString("F1");
				Debug.Log((object)string.Concat(obj));
			}
		}

		private static float SwimDistanceAt(float seconds)
		{
			seconds = Mathf.Max(0f, seconds);
			if (seconds < 6f)
			{
				return 3f * seconds * seconds / 12f;
			}
			return 3f * (seconds - 3f);
		}

		private static void UpdatePatrolMotion(float dt)
		{
			//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_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			float seconds = swimElapsed;
			swimElapsed += dt;
			if (Time.time >= swimPatrolNextCheck)
			{
				swimPatrolNextCheck = Time.time + 2f;
				float sea = (((Object)(object)ZoneSystem.instance != (Object)null) ? ZoneSystem.instance.m_waterLevel : swimPatrolCourse.Center.y);
				float num = OceanPatrolLoop.FirstConfirmedDanger(swimPatrolCourse, swimDistance, 200f, sea);
				if (float.IsInfinity(num))
				{
					swimPatrolSpeedFactor = 1f;
				}
				else
				{
					swimPatrolSpeedFactor = ((num <= 50f) ? 0f : ((num <= 110f) ? 0.2f : 0.65f));
					Debug.LogWarning((object)("[HeadPreview/v31.24 LOOP] Echte geladene Untiefe " + num.ToString("F0") + "m voraus. Kreisfahrt vorsichtig gebremst; keine Seed-False-Positive."));
				}
			}
			float num2 = Mathf.Max(0f, SwimDistanceAt(swimElapsed) - SwimDistanceAt(seconds)) * swimPatrolSpeedFactor;
			swimDistance += num2;
			swimDirection = swimPatrolCourse.Forward(swimDistance);
			preview.transform.position = swimPatrolCourse.Position(swimDistance);
			preview.transform.rotation = Quaternion.LookRotation(swimDirection, Vector3.up);
			swimHeadingOffsetDeg = Vector3.SignedAngle(swimInitialDirection, swimDirection, Vector3.up);
			coastAvoiding = false;
			coastNearestUnsafe = 350f;
			coastCurrentSpeedFactor = swimPatrolSpeedFactor;
			RecordRoutePoint();
			if (!swimPassedOldLimit && swimDistance >= 150f)
			{
				swimPassedOldLimit = true;
				Debug.Log((object)("[HeadPreview/v31.24 LOOP] 150m geschafft. Rundkurs aktiv, Radius=" + swimPatrolCourse.Radius.ToString("F0") + "m."));
			}
			int num3 = Mathf.FloorToInt(swimElapsed / 5f);
			if (num3 > swimLastLogBucket)
			{
				swimLastLogBucket = num3;
				string[] obj = new string[16]
				{
					"[HeadPreview/v31.24 LOOP] SWIM t=",
					F(swimElapsed),
					"s path=",
					F(swimDistance),
					"m radius=",
					F(swimPatrolCourse.Radius),
					"m speedFactor=",
					F(swimPatrolSpeedFactor),
					" pos=",
					null,
					null,
					null,
					null,
					null,
					null,
					null
				};
				Vector3 position = preview.transform.position;
				obj[9] = ((Vector3)(ref position)).ToString("F1");
				obj[10] = " dir=";
				obj[11] = ((Vector3)(ref swimDirection)).ToString("F2");
				obj[12] = " body=";
				obj[13] = (swimTrailActive ? "ROUTE" : "LEGACY");
				obj[14] = " round=";
				obj[15] = F(swimDistance / (MathF.PI * 2f * swimPatrolCourse.Radius));
				Debug.Log((object)string.Concat(obj));
			}
		}

		private static void UpdateSwimMotion()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: 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_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_0417: Unknown result type (might be due to invalid IL or missing references)
			//IL_044b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0450: Unknown result type (might be due to invalid IL or missing references)
			//IL_046b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0470: Unknown result type (might be due to invalid IL or missing references)
			if (!swimActive || (Object)(object)preview == (Object)null)
			{
				return;
			}
			if (previewEmergenceActive)
			{
				if (!swimTrailActive && (Object)(object)swimAlignmentRoot != (Object)null)
				{
					float num = Mathf.Clamp01((Time.time - previewEmergenceStart) / 7f);
					float num2 = Mathf.SmoothStep(0f, 1f, num);
					swimAlignmentRoot.localPosition = swimAlignmentRestLocalPosition + Vector3.down * (30f * (1f - num2));
				}
				if (Time.time - previewEmergenceStart < 15f)
				{
					return;
				}
				previewEmergenceActive = false;
				if (!swimTrailActive && (Object)(object)swimAlignmentRoot != (Object)null)
				{
					swimAlignmentRoot.localPosition = swimAlignmentRestLocalPosition;
				}
				Debug.Log((object)"[HeadPreview/v31.22 EMERGENCE] COMPLETE: 82 bones oben, normales Schwimmen beginnt.");
				if ((Object)(object)Player.m_localPlayer != (Object)null)
				{
					SpawnFeedback.Created("F3 TEST - TIEFSEE", ((Component)Player.m_localPlayer).transform.position, preview.transform.position);
				}
			}
			float num3 = Mathf.Max(0f, Time.deltaTime);
			if (num3 <= 0f)
			{
				return;
			}
			if (swimPatrolActive)
			{
				UpdatePatrolMotion(num3);
				return;
			}
			float seconds = swimElapsed;
			swimElapsed += num3;
			ScanCoast();
			if (coastDesiredSpeedFactor < coastCurrentSpeedFactor)
			{
				coastCurrentSpeedFactor = coastDesiredSpeedFactor;
			}
			else
			{
				coastCurrentSpeedFactor = Mathf.MoveTowards(coastCurrentSpeedFactor, coastDesiredSpeedFactor, num3 * 0.12f);
			}
			float num4 = Mathf.Max(0f, SwimDistanceAt(swimElapsed) - SwimDistanceAt(seconds)) * coastCurrentSpeedFactor;
			float num5 = Mathf.Max(0f, swimElapsed - coastMeanderEpoch - 15f);
			float num6 = (coastAvoiding ? coastTargetYaw : (coastMeanderBaseYaw + 22f * Mathf.Sin(num5 * (MathF.PI / 180f))));
			float num7 = (coastAvoiding ? CoastAdaptiveYawRate(Mathf.Max(0.01f, num4 / num3), coastNearestUnsafe) : 0.4f);
			float num8 = swimHeadingOffsetDeg;
			swimHeadingOffsetDeg = Mathf.MoveTowardsAngle(num8, num6, num7 * num3);
			Vector3 val = Quaternion.AngleAxis(num8 + Mathf.DeltaAngle(num8, swimHeadingOffsetDeg) * 0.5f, Vector3.up) * swimInitialDirection;
			val.y = 0f;
			((Vector3)(ref val)).Normalize();
			swimDirection = Quaternion.AngleAxis(swimHeadingOffsetDeg, Vector3.up) * swimInitialDirection;
			swimDirection.y = 0f;
			((Vector3)(ref swimDirection)).Normalize();
			Transform transform = preview.transform;
			transform.position += val * num4;
			preview.transform.rotation = Quaternion.LookRotation(swimDirection, Vector3.up);
			swimDistance += num4;
			RecordRoutePoint();
			if (!swimPassedOldLimit && swimDistance >= 150f)
			{
				swimPassedOldLimit = true;
				Debug.Log((object)"[HeadPreview/v3.1.2] PASSED 150m: Dauerschwimmen AKTIV, Route laeuft weiter bis F3 oder Weltwechsel.");
			}
			int num9 = Mathf.FloorToInt(swimElapsed / 5f);
			if (num9 > swimLastLogBucket)
			{
				swimLastLogBucket = num9;
				string[] obj = new string[22]
				{
					"[HeadPreview/v3.1.9.1] SWIM t=",
					F(swimElapsed),
					"s path=",
					F(swimDistance),
					"m fromSpawn=",
					F(Vector3.Distance(preview.transform.position, swimOrigin)),
					"m yaw=",
					F(swimHeadingOffsetDeg),
					"deg coast=",
					coastAvoiding ? "AVOID" : "CLEAR",
					" coastClear=",
					F(coastNearestUnsafe),
					"m speedFactor=",
					F(coastCurrentSpeedFactor),
					" dir=",
					((Vector3)(ref swimDirection)).ToString("F2"),
					" driver=",
					null,
					null,
					null,
					null,
					null
				};
				Vector3 position = preview.transform.position;
				obj[17] = ((Vector3)(ref position)).ToString("F1");
				obj[18] = " head=";
				object obj2;
				if (!((Object)(object)swimHeadBone != (Object)null))
				{
					obj2 = "MISSING";
				}
				else
				{
					position = swimHeadBone.position;
					obj2 = ((Vector3)(ref position)).ToString("F1");
				}
				obj[19] = (string)obj2;
				obj[20] = " headTravelDot=";
				obj[21] = F(Vector3.Dot(CurrentHeadForward(), swimDirection));
				Debug.Log((object)string.Concat(obj));
			}
		}

		public static void Tick()
		{
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: 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_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: 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_04f6: 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_0501: Unknown result type (might be due to invalid IL or missing references)
			//IL_0506: Unknown result type (might be due to invalid IL or missing references)
			//IL_050b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: 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_0530: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0599: Unknown result type (might be due to invalid IL or missing references)
			//IL_059a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0581: Unknown result type (might be due to invalid IL or missing references)
			//IL_0582: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: 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)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.DevelopmentToolsEnabled)
			{
				if ((Object)(object)preview != (Object)null || virtualPreview || pendingWorldPreview)
				{
					Clear();
				}
				return;
			}
			if (!JormungandrNetworkSession.CanSimulate || ((Object)(object)session != (Object)null && (Object)(object)session != (Object)(object)ZNet.instance))
			{
				Clear();
				session = null;
				return;
			}
			if ((Object)(object)Plugin.Instance != (Object)null && Plugin.Instance.HasActiveNewBoss)
			{
				if ((Object)(object)preview != (Object)null || virtualPreview || pendingWorldPreview)
				{
					Clear();
				}
				return;
			}
			UpdateSwimMotion();
			if (pendingWorldPreview && (Object)(object)pendingWorldPreviewSession != (Object)(object)ZNet.instance)
			{
				Clear();
			}
			if (pendingWorldPreview && !OceanSighting.IsWorldHomeSearchPending)
			{
				pendingWorldPreview = false;
				if ((Object)(object)Player.m_localPlayer != (Object)null && OceanSighting.TryChooseSeaSpawn(((Component)Player.m_localPlayer).transform.position, out var center, out var heading))
				{
					StartOceanPreviewAt(center, heading);
				}
				else
				{
					SpawnFeedback.Failed("F3 TEST", OceanSighting.LastSpawnFailureReason);
				}
			}
			if (virtualPreview && (Object)(object)virtualWorld != (Object)(object)ZNet.instance)
			{
				Clear();
			}
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				if ((Object)(object)preview != (Object)null)
				{
					Vector3 val = preview.transform.position - ((Component)Player.m_localPlayer).transform.position;
					val.y = 0f;
					if (((Vector3)(ref val)).magnitude > 1200f)
					{
						Vector3 position = preview.transform.position;
						Vector3 val2 = swimDirection;
						bool flag = swimPatrolActive;
						OceanPatrolLoop.Course obj = (flag ? swimPatrolCourse.Rebase(swimDistance) : default(OceanPatrolLoop.Course));
						Clear();
						virtualHasPatrol = flag;
						virtualPatrolCourse = obj;
						virtualAlreadySurfaced = true;
						virtualPreview = true;
						virtualPosition = position;
						virtualForward = val2;
						virtualWorld = ZNet.instance;
						Debug.Log((object)"[HeadPreview/v31.10 REMOTE] 3D-Vorschau ausgeladen, Marker bleibt.");
					}
				}
				if (virtualPreview && (Object)(object)preview == (Object)null && !remoteAssetPrewarmAttempted)
				{
					Vector3 val3 = virtualPosition - ((Component)Player.m_localPlayer).transform.position;
					val3.y = 0f;
					if (((Vector3)(ref val3)).sqrMagnitude <= 1000000f)
					{
						remoteAssetPrewarmAttempted = true;
						if ((Object)(object)LoadPreviewPrefab() != (Object)null)
						{
							Debug.Log((object)("[HeadPreview/v31.21 PREWARM] 3D-Asset vorgeladen bei " + ((Vector3)(ref val3)).magnitude.ToString("F0") + "m; instanziiert erst nach Echtgelaende-Freigabe."));
						}
					}
				}
				if (virtualPreview && (Object)(object)preview == (Object)null && Time.time >= nextVirtualLoadAttempt)
				{
					Vector3 val4 = virtualPosition - ((Component)Player.m_localPlayer).transform.position;
					val4.y = 0f;
					if (((Vector3)(ref val4)).magnitude <= 650f)
					{
						nextVirtualLoadAttempt = Time.time + 0.65f;
						if (virtualHasPatrol ? LocalSeaSpawnGuard.TryResolveKnownPatrol(virtualPatrolCourse, out var position2, out var direction, out var reason) : LocalSeaSpawnGuard.TryResolve(virtualPosition, virtualForward, requirePlayerClearance: true, out position2, out direction, out reason))
						{
							Vector3 val5 = position2 - virtualPosition;
							if ((!(((Vector3)(ref val5)).sqrMagnitude > 0.01f) && !(Vector3.Dot(((Vector3)(ref direction)).normalized, ((Vector3)(ref virtualForward)).normalized) < 0.999f)) || (!virtualHasPatrol && OceanSighting.CommitWorldHomeCorrection(position2, direction)))
							{
								GameObject val6 = LoadPreviewPrefab();
								if ((Object)(object)val6 != (Object)null)
								{
									virtualPosition = position2;
									virtualForward = direction;
									virtualPreview = false;
									SpawnAt(val6, position2, direction, deepOceanPreview: true);
									Debug.Log((object)("[HeadPreview/v31.18 LOADED] " + reason + " 3D bei " + ((Vector3)(ref val4)).magnitude.ToString("F0") + "m geladen."));
								}
							}
							else
							{
								Debug.LogWarning((object)"[HeadPreview/v31.18 LOADED] Alternative konnte nicht im Welt-Cache gespeichert werden.");
							}
						}
						else if (Time.time >= nextRealTerrainMessage)
						{
							nextRealTerrainMessage = Time.time + 15f;
							Debug.Log((object)("[HeadPreview/v31.18 LOADED] " + reason));
							SpawnFeedback.Pending("F3 TEST - GELÄNDEPRÜFUNG", "Jormungandr bleibt am Kartenmarker. " + reason);
						}
					}
				}
			}
			if (!Input.GetKeyDown((KeyCode)284) || !LocalShortcutGuard.CanUseShortcuts() || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			if ((Object)(object)preview != (Object)null)
			{
				Clear();
				SpawnFeedback.Clear();
				Debug.Log((object)"[HeadPreview] F3 removed head v1.1 size preview.");
				return;
			}
			if (virtualPreview || pendingWorldPreview)
			{
				Clear();
				SpawnFeedback.Clear();