Decompiled source of NovaOceanExperience v0.5.1

NovaOceanExperience.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SoftReferenceableAssets;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace OceanPhenomena
{
	[BepInPlugin("oceanphenomena.valheim", "NovaOceanExperience", "0.5.1")]
	public sealed class OceanPhenomenaPlugin : BaseUnityPlugin
	{
		private enum BreezeMode
		{
			Auto,
			On,
			Off
		}

		private enum Phenomenon
		{
			None,
			AzureBreeze,
			Waterspout,
			Mirage,
			PoisonWater,
			Whirlpool,
			LightningStorm,
			IceFog,
			SeaHail
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static ConsoleOptionsFetcher <>9__38_7;

			internal List<string> <Awake>b__38_7()
			{
				return new List<string> { "on", "off", "auto" };
			}
		}

		private ConfigEntry<bool> enabledSetting;

		private ConfigEntry<float> brightness;

		private ConfigEntry<bool> naturalWaterspouts;

		private ConfigEntry<bool> naturalMirages;

		private ConfigEntry<bool> naturalPoisonWater;

		private ConfigEntry<bool> naturalLightning;

		private ConfigEntry<bool> naturalIceFog;

		private OceanGlow glow;

		private WaterspoutSystem waterspouts;

		private OceanMirage mirage;

		private PoisonWater poisonWater;

		private WhirlpoolSystem whirlpool;

		private OceanLightning lightning;

		private IceFog iceFog;

		private OceanHail hail;

		private readonly OceanWeather weather = new OceanWeather();

		private Harmony harmony;

		private World currentWorld;

		private BreezeMode mode;

		private Phenomenon active;

		private bool automaticActive;

		private float visibility;

		private Color color;

		private double lastCheckFrame = double.NaN;

		private double sailingTime;

		private double cooldownUntil;

		private readonly OceanMultiplayer multiplayer = new OceanMultiplayer();

		private long appliedNetworkSequence;

		private bool networkApplied;

		private bool manualPending;

		private bool manualIssuer;

		private bool waitingForServer;

		private bool hadPlayablePlayer;

		private double pendingSince;

		private Phenomenon pendingKind;

		private readonly List<Phenomenon> eligible = new List<Phenomenon>();

		private void Awake()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Expected O, but got Unknown
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Expected O, but got Unknown
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Expected O, but got Unknown
			enabledSetting = ((BaseUnityPlugin)this).Config.Bind<bool>("Bioluminescence", "Enabled", true, "Enable Azure Breeze.");
			brightness = ((BaseUnityPlugin)this).Config.Bind<float>("Bioluminescence", "Brightness", 1f, new ConfigDescription("Brightness of the glow, wake and sparks.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			naturalWaterspouts = ((BaseUnityPlugin)this).Config.Bind<bool>("Waterspouts", "NaturalSpawns", true, "Allow naturally occurring waterspouts in the Ocean biome.");
			naturalMirages = ((BaseUnityPlugin)this).Config.Bind<bool>("OceanMirage", "NaturalSpawns", true, "Allow naturally occurring ship mirages in the Ocean biome.");
			naturalPoisonWater = ((BaseUnityPlugin)this).Config.Bind<bool>("PoisonWater", "NaturalSpawns", true, "Allow naturally occurring poisonous haze in the Ocean biome.");
			naturalLightning = ((BaseUnityPlugin)this).Config.Bind<bool>("LightningStorm", "NaturalSpawns", true, "Allow naturally occurring lightning storms in the Ocean biome.");
			naturalIceFog = ((BaseUnityPlugin)this).Config.Bind<bool>("IceFog", "NaturalSpawns", true, "Allow naturally occurring ice fog in the Ocean biome.");
			harmony = new Harmony("oceanphenomena.valheim.azurewind");
			OceanConnectionCheck.Install(harmony, ((BaseUnityPlugin)this).Logger);
			Shader val = Shader.Find("Sprites/Default");
			if (!Object.op_Implicit((Object)(object)val) || !val.isSupported)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Azure Breeze requires the supported Sprites/Default shader.");
				return;
			}
			glow = new OceanGlow(val);
			harmony.PatchAll(typeof(AzureWind));
			WaterspoutRiders.InstallPatches(harmony);
			harmony.PatchAll(typeof(WhirlpoolSystem));
			harmony.PatchAll(typeof(StormSwell));
			mirage = new OceanMirage(val, delegate
			{
				SelectManual(Phenomenon.Mirage);
			});
			poisonWater = new PoisonWater(val, delegate
			{
				SelectManual(Phenomenon.PoisonWater);
			});
			whirlpool = new WhirlpoolSystem(val, delegate
			{
				SelectManual(Phenomenon.Whirlpool);
			});
			lightning = new OceanLightning(val, delegate
			{
				SelectManual(Phenomenon.LightningStorm);
			});
			waterspouts = new WaterspoutSystem(val, delegate
			{
				SelectManual(Phenomenon.Waterspout);
			}, null, lightning.StopVortexWind, lightning.UpdateVortexWind);
			iceFog = new IceFog(val, delegate
			{
				SelectManual(Phenomenon.IceFog);
			});
			hail = new OceanHail(val, delegate
			{
				SelectManual(Phenomenon.SeaHail);
			});
			ConsoleEvent val2 = RunBreezeCommand;
			object obj = <>c.<>9__38_7;
			if (obj == null)
			{
				ConsoleOptionsFetcher val3 = () => new List<string> { "on", "off", "auto" };
				<>c.<>9__38_7 = val3;
				obj = (object)val3;
			}
			new ConsoleCommand("azure_breeze", "[on|off|auto] - control the local Azure Breeze.", val2, false, false, false, false, false, false, (ConsoleOptionsFetcher)obj, false, false, false);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Azure Breeze initialized. Console: azure_breeze on|off|auto.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Waterspouts initialized. Console: ocean_tornado start|stop.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Ocean Mirage initialized. Console: ocean_mirage start|stop.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Poison Water initialized. Console: ocean_poisonwater start|stop.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Whirlpool initialized. Console: ocean_whirlpool start|stop.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Lightning storms initialized. Console: ocean_storm start|stop.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Ice fog initialized. Console: ocean_icefog start|stop.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Sea hail initialized. Console: ocean_hail start|stop.");
		}

		private void LateUpdate()
		{
			ZNet instance = ZNet.instance;
			World val = (Object.op_Implicit((Object)(object)instance) ? ZNet.World : null);
			multiplayer.Update(val, instance);
			if (glow == null)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			EnvMan instance2 = EnvMan.instance;
			ZoneSystem instance3 = ZoneSystem.instance;
			SyncWorld(val);
			if (val == null || !Object.op_Implicit((Object)(object)instance2) || !Object.op_Implicit((Object)(object)instance3) || !Object.op_Implicit((Object)(object)localPlayer) || ((Character)localPlayer).IsDead() || ((Character)localPlayer).IsTeleporting())
			{
				if (hadPlayablePlayer || active != Phenomenon.None)
				{
					hadPlayablePlayer = false;
					ResetGlow();
					waterspouts.Hide();
					mirage.Stop();
					poisonWater.Stop();
					whirlpool.Stop();
					lightning.Stop();
					iceFog.Stop();
					hail.Stop();
					weather.Clear();
					if (active != Phenomenon.None && Object.op_Implicit((Object)(object)instance))
					{
						cooldownUntil = instance.GetTimeSeconds() + 600.0;
					}
					active = Phenomenon.None;
					automaticActive = false;
					networkApplied = false;
					appliedNetworkSequence = 0L;
					lastCheckFrame = double.NaN;
				}
				return;
			}
			hadPlayablePlayer = true;
			Ship localShip = Ship.GetLocalShip();
			float waterLevel = instance3.m_waterLevel;
			double timeSeconds = instance.GetTimeSeconds();
			ApplyNetworkEvent(val, localPlayer, localShip, instance2, waterLevel, timeSeconds);
			if (active == Phenomenon.LightningStorm && networkApplied)
			{
				lightning.ShowSharedShipStrike(multiplayer.Current, timeSeconds);
			}
			if (active != Phenomenon.None && !DrawPhenomenon(active, val, localPlayer, localShip, instance, instance2, waterLevel))
			{
				active = Phenomenon.None;
				cooldownUntil = timeSeconds + 600.0;
			}
			if (manualPending && active != Phenomenon.None)
			{
				PublishEvent(active, manual: true, val, localPlayer, localShip, timeSeconds);
				manualIssuer = true;
				manualPending = false;
			}
			else if (manualIssuer && active == Phenomenon.None)
			{
				multiplayer.StopManual();
				manualIssuer = false;
			}
			if (active == Phenomenon.None)
			{
				CheckForEvent(val, localPlayer, localShip, instance2, waterLevel, timeSeconds);
			}
			else
			{
				lastCheckFrame = timeSeconds;
			}
			OceanWeather.Kind kind = OceanWeather.Kind.Natural;
			if (active == Phenomenon.AzureBreeze)
			{
				kind = OceanWeather.Kind.AzureClear;
			}
			else if (active == Phenomenon.Waterspout)
			{
				kind = OceanWeather.Kind.WaterspoutRain;
			}
			else if (active == Phenomenon.Mirage)
			{
				kind = OceanWeather.Kind.MirageDry;
			}
			else if (active == Phenomenon.LightningStorm)
			{
				kind = OceanWeather.Kind.LightningStorm;
			}
			else if (active == Phenomenon.PoisonWater)
			{
				kind = OceanWeather.Kind.PoisonOvercast;
			}
			else if (active == Phenomenon.IceFog)
			{
				kind = OceanWeather.Kind.IceFog;
			}
			else if (active == Phenomenon.SeaHail)
			{
				kind = OceanWeather.Kind.SeaHail;
			}
			AzureWind.Active = active == Phenomenon.AzureBreeze;
			weather.Update(instance2, kind, automaticActive);
		}

		private void CheckForEvent(World world, Player player, Ship ship, EnvMan environment, float seaLevel, double now)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Invalid comparison between Unknown and I4
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			double num = (double.IsNaN(lastCheckFrame) ? 0.0 : Math.Max(0.0, Math.Min(2.0, now - lastCheckFrame)));
			lastCheckFrame = now;
			if (!Object.op_Implicit((Object)(object)ship) || ((Character)player).InInterior() || ((Character)player).InIntro() || (int)player.GetCurrentBiome() != 256)
			{
				return;
			}
			sailingTime = Math.Min(300.0, sailingTime + num);
			OceanEventState current = multiplayer.Current;
			if (current.Kind != 0 && now < current.Ends)
			{
				return;
			}
			ZNetView component = ((Component)ship).GetComponent<ZNetView>();
			if ((Object.op_Implicit((Object)(object)component) && !component.IsOwner()) || sailingTime < 300.0 || now < cooldownUntil)
			{
				return;
			}
			sailingTime = 0.0;
			if (!IsOpenOcean(((Component)ship).transform.position, seaLevel) || Random.value >= 0.2f)
			{
				return;
			}
			eligible.Clear();
			if (enabledSetting.Value && brightness.Value > 0f && mode == BreezeMode.Auto && EnvMan.IsNight())
			{
				AddEligible(Phenomenon.AzureBreeze);
			}
			if (naturalWaterspouts.Value)
			{
				AddEligible(Phenomenon.Waterspout);
			}
			if (naturalMirages.Value && mirage.CanStartScheduled(environment))
			{
				AddEligible(Phenomenon.Mirage);
			}
			if (naturalLightning.Value && OceanWeather.FindNativeStorm(environment) != null)
			{
				AddEligible(Phenomenon.LightningStorm);
			}
			if (naturalPoisonWater.Value && PoisonWater.Unlocked(ZoneSystem.instance))
			{
				AddEligible(Phenomenon.PoisonWater);
			}
			if (naturalIceFog.Value)
			{
				eligible.Add(Phenomenon.IceFog);
			}
			while (eligible.Count > 0)
			{
				Phenomenon chosen = eligible[Random.Range(0, eligible.Count)];
				if (StartScheduled(chosen, world, player, ship, environment, seaLevel, now))
				{
					active = chosen;
					automaticActive = true;
					PublishEvent(chosen, manual: false, world, player, ship, now);
					break;
				}
				eligible.RemoveAll((Phenomenon candidate) => candidate == chosen);
			}
		}

		private static ZDOID GetShipId(Ship ship)
		{
			//IL_0008: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)ship))
			{
				return ZDOID.None;
			}
			ZNetView component = ((Component)ship).GetComponent<ZNetView>();
			if (!Object.op_Implicit((Object)(object)component) || !component.IsValid())
			{
				return ZDOID.None;
			}
			return component.GetZDO()?.m_uid ?? ZDOID.None;
		}

		private void PublishEvent(Phenomenon kind, bool manual, World world, Player player, Ship ship, double now)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			Transform val = (Object.op_Implicit((Object)(object)ship) ? ((Component)ship).transform : ((Component)player).transform);
			OceanEventState requested = new OceanEventState
			{
				Kind = (int)kind,
				WorldId = world.m_uid,
				Manual = manual,
				Started = now,
				Anchor = val.position,
				Heading = val.forward,
				Seed = (int)OceanGlow.Hash((uint)(int)world.m_uid ^ (uint)(now * 1000.0)),
				LightningTarget = ((kind == Phenomenon.LightningStorm) ? GetShipId(ship) : ZDOID.None)
			};
			switch (kind)
			{
			case Phenomenon.PoisonWater:
				poisonWater.ExportState(out requested.Origin, out requested.Motion, out requested.Seed);
				break;
			case Phenomenon.Whirlpool:
				whirlpool.ExportState(out requested.Origin, out requested.Extra, out requested.Seed);
				break;
			default:
				if (kind == Phenomenon.Waterspout && manual)
				{
					waterspouts.ExportPreview(out requested.Origin, out requested.Motion, out requested.Extra, out requested.Seed);
				}
				break;
			}
			multiplayer.Publish(requested);
			if (Object.op_Implicit((Object)(object)ZNet.instance) && !ZNet.instance.IsServer())
			{
				waitingForServer = true;
				pendingSince = now;
				pendingKind = kind;
			}
		}

		private void ApplyNetworkEvent(World world, Player player, Ship ship, EnvMan environment, float seaLevel, double now)
		{
			//IL_0152: 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_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Invalid comparison between Unknown and I4
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			OceanEventState current = multiplayer.Current;
			if (waitingForServer)
			{
				if (current.Kind == (int)pendingKind && current.Started >= pendingSince - 5.0 && now < current.Ends)
				{
					waitingForServer = false;
				}
				else if (current.Kind != 0 && now < current.Ends && current.Started >= pendingSince - 5.0)
				{
					waitingForServer = false;
				}
				else if (now - pendingSince > 12.0)
				{
					if (pendingKind == Phenomenon.AzureBreeze)
					{
						((BaseUnityPlugin)this).Logger.LogWarning((object)"Azure Breeze did not receive a server event snapshot within 12 seconds.");
					}
					ClearCurrentEvent();
					waitingForServer = false;
					manualIssuer = false;
					cooldownUntil = now + 600.0;
				}
			}
			if (current.Sequence == 0L)
			{
				return;
			}
			if (current.Kind == 0 || now >= current.Ends)
			{
				if (networkApplied)
				{
					ClearCurrentEvent();
					networkApplied = false;
				}
				appliedNetworkSequence = current.Sequence;
				cooldownUntil = Math.Max(cooldownUntil, current.Ends + 600.0);
				return;
			}
			Vector3 val = (Object.op_Implicit((Object)(object)ship) ? ((Component)ship).transform.position : ((Component)player).transform.position);
			if (((current.Kind != 1 || !current.Manual) && (int)player.GetCurrentBiome() != 256) || ((Character)player).InInterior() || ((Character)player).InIntro() || !(Utils.DistanceXZ(val, current.Anchor) <= 650f))
			{
				if (networkApplied)
				{
					ClearCurrentEvent();
					networkApplied = false;
					appliedNetworkSequence = 0L;
				}
			}
			else
			{
				if (networkApplied && appliedNetworkSequence == current.Sequence)
				{
					return;
				}
				ClearCurrentEvent();
				Phenomenon kind = (Phenomenon)current.Kind;
				switch (kind)
				{
				default:
					return;
				case Phenomenon.AzureBreeze:
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"Applying Azure Breeze snapshot {current.Sequence} (manual: {current.Manual}).");
					break;
				case Phenomenon.Waterspout:
					if (current.Manual)
					{
						waterspouts.StartSharedPreview(world, current.Origin, current.Motion, current.Extra, current.Started, (uint)current.Seed);
					}
					else
					{
						waterspouts.StartScheduled(world, current.Started);
					}
					break;
				case Phenomenon.Mirage:
					mirage.StartShared(world, environment, current.Anchor, current.Heading, current.Seed, (float)Math.Max(0.0, now - current.Started));
					break;
				case Phenomenon.PoisonWater:
					poisonWater.StartShared(world, current.Origin, current.Motion, (uint)current.Seed, (float)Math.Max(0.0, now - current.Started));
					break;
				case Phenomenon.Whirlpool:
					whirlpool.StartShared(world, current.Origin, current.Extra, current.Seed, (float)Math.Max(0.0, now - current.Started));
					break;
				case Phenomenon.LightningStorm:
					lightning.StartScheduled(world, current.Started, (uint)current.Seed, current.Anchor, current.LightningTarget);
					break;
				case Phenomenon.IceFog:
					iceFog.StartScheduled(world, current.Started);
					break;
				case Phenomenon.SeaHail:
					hail.StartShared(world, current.Started, current.Ends);
					break;
				}
				active = kind;
				automaticActive = !current.Manual;
				appliedNetworkSequence = current.Sequence;
				networkApplied = true;
				sailingTime = 0.0;
			}
		}

		private void ClearCurrentEvent()
		{
			ResetGlow();
			waterspouts.Hide();
			mirage.Stop();
			poisonWater.Stop();
			whirlpool.Stop();
			lightning.Stop();
			iceFog.Stop();
			hail.Stop();
			weather.Clear();
			active = Phenomenon.None;
			automaticActive = false;
			if (!manualIssuer && mode == BreezeMode.On)
			{
				mode = BreezeMode.Auto;
			}
		}

		private void AddEligible(Phenomenon phenomenon)
		{
			for (int i = 0; i < 5; i++)
			{
				eligible.Add(phenomenon);
			}
		}

		private bool StartScheduled(Phenomenon phenomenon, World world, Player player, Ship ship, EnvMan environment, float seaLevel, double now)
		{
			//IL_0076: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			switch (phenomenon)
			{
			case Phenomenon.Waterspout:
				waterspouts.StartScheduled(world, now);
				break;
			case Phenomenon.Mirage:
				mirage.StartScheduled(world, environment);
				break;
			case Phenomenon.LightningStorm:
				return lightning.StartScheduled(world, now, (uint)(int)world.m_uid ^ (uint)now, Object.op_Implicit((Object)(object)ship) ? ((Component)ship).transform.position : ((Component)player).transform.position, GetShipId(ship));
			case Phenomenon.IceFog:
				iceFog.StartScheduled(world, now);
				break;
			case Phenomenon.PoisonWater:
				return poisonWater.StartScheduled(world, player, ship, environment, seaLevel);
			}
			return true;
		}

		private static bool IsOpenOcean(Vector3 position, float seaLevel)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			WorldGenerator instance = WorldGenerator.instance;
			if (instance == null)
			{
				return false;
			}
			for (int i = 0; i < 8; i++)
			{
				float num = (float)i * ((float)Math.PI / 4f);
				Vector3 val = position + new Vector3(Mathf.Cos(num) * 85f, 0f, Mathf.Sin(num) * 85f);
				if (instance.GetHeight(val) >= seaLevel - 3f)
				{
					return false;
				}
			}
			return true;
		}

		private bool DrawPhenomenon(Phenomenon phenomenon, World world, Player player, Ship ship, ZNet network, EnvMan environment, float seaLevel)
		{
			switch (phenomenon)
			{
			case Phenomenon.AzureBreeze:
				return DrawBreeze(world, player, ship, network, environment, seaLevel);
			case Phenomenon.Waterspout:
				waterspouts.Draw(world, player, ship, network, seaLevel, naturalEnabled: false);
				return waterspouts.HasActive;
			case Phenomenon.Mirage:
				mirage.Draw(world, player, ship, environment, seaLevel, natural: false);
				return mirage.HasActive;
			case Phenomenon.PoisonWater:
				poisonWater.Draw(world, player, ship, environment, seaLevel, natural: false);
				return poisonWater.HasActive;
			case Phenomenon.Whirlpool:
				return whirlpool.Draw(world, player);
			case Phenomenon.LightningStorm:
				return lightning.Draw(world, player, ship, network, seaLevel, natural: false);
			case Phenomenon.IceFog:
				return iceFog.Draw(world, player, network, seaLevel, natural: false);
			case Phenomenon.SeaHail:
				return hail.Draw(world, player, ship, network, seaLevel, natural: false);
			default:
				return false;
			}
		}

		private bool DrawBreeze(World world, Player player, Ship ship, ZNet network, EnvMan environment, float seaLevel)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Invalid comparison between Unknown and I4
			//IL_0116: 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_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			OceanEventState current = multiplayer.Current;
			bool flag = networkApplied && current.Kind == 1 && current.Sequence == appliedNetworkSequence;
			if (mode == BreezeMode.Off || (mode != BreezeMode.On && !enabledSetting.Value && (!flag || !current.Manual)))
			{
				ResetGlow();
				return false;
			}
			bool flag2 = flag || mode == BreezeMode.On;
			if (flag2 || (EnvMan.IsNight() && (int)player.GetCurrentBiome() == 256))
			{
				double num = (flag ? current.Started : network.GetTimeSeconds());
				int day = environment.GetDay(num + (double)environment.m_dayLengthSec * 0.5);
				uint num2 = (uint)((int)world.m_uid ^ (int)(world.m_uid >> 32) ^ (day * -1640531527));
				flag2 = true;
				color = (((OceanGlow.Hash(num2 ^ 0x85EBCA6Bu) & 1) == 0) ? new Color(0.2f, 0.67f, 0.91f) : new Color(0.21f, 0.76f, 0.83f));
			}
			visibility = Mathf.MoveTowards(visibility, flag2 ? 1f : 0f, Time.deltaTime * 0.65f);
			float num3 = brightness.Value;
			if ((mode == BreezeMode.On || (flag && current.Manual)) && num3 <= 0f)
			{
				num3 = 1f;
			}
			if (visibility <= 0f)
			{
				ResetGlow();
				return false;
			}
			if (num3 > 0f)
			{
				Vector3 origin = (Object.op_Implicit((Object)(object)ship) ? ((Component)ship).transform.position : ((Component)player).transform.position);
				glow.Draw(origin, ship, seaLevel, color, num3 * visibility);
			}
			else
			{
				glow.Clear();
			}
			return true;
		}

		private void RunBreezeCommand(ConsoleEventArgs args)
		{
			World val = (Object.op_Implicit((Object)(object)ZNet.instance) ? ZNet.World : null);
			if (val == null || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || !((Behaviour)this).isActiveAndEnabled)
			{
				args.Context.AddString("Join a world to use azure_breeze.");
				return;
			}
			SyncWorld(val);
			if (args.Length != 2)
			{
				args.Context.AddString("azure_breeze [on|off|auto] (current mode: " + mode.ToString().ToLowerInvariant() + ")");
				return;
			}
			switch (args[1].ToLowerInvariant())
			{
			case "on":
				mode = BreezeMode.On;
				SelectManual(Phenomenon.AzureBreeze);
				args.Context.AddString("Azure Breeze forced on. Look for it in nearby water.");
				break;
			case "off":
				mode = BreezeMode.Off;
				ResetGlow();
				if (active == Phenomenon.AzureBreeze)
				{
					active = Phenomenon.None;
					cooldownUntil = ZNet.instance.GetTimeSeconds() + 600.0;
				}
				args.Context.AddString("Azure Breeze off.");
				break;
			case "auto":
				mode = BreezeMode.Auto;
				args.Context.AddString("Azure Breeze back to its automatic night schedule.");
				break;
			default:
				args.Context.AddString("Usage: azure_breeze on|off|auto");
				break;
			}
		}

		private void SelectManual(Phenomenon phenomenon)
		{
			SyncWorld(ZNet.World);
			if (phenomenon != Phenomenon.AzureBreeze)
			{
				ResetGlow();
				if (mode == BreezeMode.On)
				{
					mode = BreezeMode.Auto;
				}
			}
			if (phenomenon != Phenomenon.Waterspout)
			{
				waterspouts.Clear();
			}
			if (phenomenon != Phenomenon.Mirage)
			{
				mirage.Stop();
			}
			if (phenomenon != Phenomenon.PoisonWater)
			{
				poisonWater.Stop();
			}
			if (phenomenon != Phenomenon.Whirlpool)
			{
				whirlpool.Stop();
			}
			if (phenomenon != Phenomenon.LightningStorm)
			{
				lightning.Stop();
			}
			if (phenomenon != Phenomenon.IceFog)
			{
				iceFog.Stop();
			}
			if (phenomenon != Phenomenon.SeaHail)
			{
				hail.Stop();
			}
			active = phenomenon;
			automaticActive = false;
			manualPending = true;
		}

		private void SyncWorld(World world)
		{
			if (world != currentWorld)
			{
				currentWorld = world;
				sailingTime = 0.0;
				lastCheckFrame = double.NaN;
				cooldownUntil = 0.0;
				appliedNetworkSequence = 0L;
				networkApplied = false;
				manualPending = false;
				manualIssuer = false;
				waitingForServer = false;
				mode = BreezeMode.Auto;
				active = Phenomenon.None;
				automaticActive = false;
				ResetGlow();
				weather.Clear();
				whirlpool.Stop();
				lightning.Stop();
				iceFog.Stop();
				hail.Stop();
				if (world == null)
				{
					waterspouts.Clear();
				}
			}
		}

		private void FixedUpdate()
		{
			if (!waitingForServer && !manualPending)
			{
				waterspouts?.ApplyForce();
				whirlpool?.ApplyForce();
			}
		}

		private void ResetGlow()
		{
			AzureWind.Active = false;
			visibility = 0f;
			glow.Clear();
		}

		private void OnDisable()
		{
			if (glow != null)
			{
				ResetGlow();
			}
			waterspouts?.Clear();
			mirage?.Stop();
			poisonWater?.Stop();
			whirlpool?.Stop();
			lightning?.Stop();
			iceFog?.Stop();
			hail?.Stop();
			weather.Clear();
			active = Phenomenon.None;
		}

		private void OnDestroy()
		{
			AzureWind.Active = false;
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			glow?.Dispose();
			waterspouts?.Dispose();
			mirage?.Dispose();
			poisonWater?.Dispose();
			whirlpool?.Dispose();
			lightning?.Dispose();
			iceFog?.Dispose();
			hail?.Dispose();
			weather.Clear();
		}
	}
	internal sealed class OceanMultiplayer
	{
		private const string RequestRpc = "nova_ocean_event_request_v8";

		private const string StateRpc = "nova_ocean_event_state_v8";

		private const string QueryRpc = "nova_ocean_event_query_v8";

		private const string StopRpc = "nova_ocean_event_stop_v8";

		private static readonly MethodInfo GetServerIdMethod = AccessTools.Method(typeof(ZRoutedRpc), "GetServerPeerID", (Type[])null, (Type[])null);

		private ZRoutedRpc routed;

		private World world;

		private double nextQuery;

		private double serverCooldown;

		private long sequence;

		private long senderOwner;

		private OceanEventState state;

		private double shipStrikeAt = double.PositiveInfinity;

		internal OceanEventState Current => state;

		private static long GetServerId()
		{
			if (ZRoutedRpc.instance == null || GetServerIdMethod == null)
			{
				return 0L;
			}
			try
			{
				return (long)GetServerIdMethod.Invoke(ZRoutedRpc.instance, null);
			}
			catch
			{
				return 0L;
			}
		}

		private void SendToServer(string name, ZPackage data)
		{
			if (routed != null)
			{
				long serverId = GetServerId();
				if (serverId != 0L)
				{
					routed.InvokeRoutedRPC(serverId, name, new object[1] { data });
				}
			}
		}

		internal void Update(World current, ZNet network)
		{
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Expected O, but got Unknown
			if (world != current)
			{
				world = current;
				state = default(OceanEventState);
				state.WorldId = current?.m_uid ?? 0;
				serverCooldown = 0.0;
				nextQuery = 0.0;
				senderOwner = 0L;
				sequence = 0L;
				shipStrikeAt = double.PositiveInfinity;
			}
			if (!Object.op_Implicit((Object)(object)network) || world == null || ZRoutedRpc.instance == null)
			{
				return;
			}
			ZRoutedRpc instance = ZRoutedRpc.instance;
			if (routed != instance)
			{
				routed = instance;
				routed.Register<ZPackage>("nova_ocean_event_request_v8", (Action<long, ZPackage>)ReceiveRequest);
				routed.Register<ZPackage>("nova_ocean_event_state_v8", (Action<long, ZPackage>)ReceiveState);
				routed.Register<ZPackage>("nova_ocean_event_query_v8", (Action<long, ZPackage>)ReceiveQuery);
				routed.Register<ZPackage>("nova_ocean_event_stop_v8", (Action<long, ZPackage>)ReceiveStop);
				nextQuery = 0.0;
			}
			double timeSeconds = network.GetTimeSeconds();
			if (network.IsServer())
			{
				if (state.Kind != 0 && timeSeconds >= state.Ends)
				{
					StopServer(timeSeconds);
				}
				else if (state.Kind == 6 && timeSeconds >= shipStrikeAt)
				{
					ResolveShipStrike(timeSeconds);
				}
			}
			else if (timeSeconds >= nextQuery)
			{
				nextQuery = timeSeconds + 25.0;
				SendToServer("nova_ocean_event_query_v8", new ZPackage());
			}
		}

		internal void Publish(OceanEventState requested)
		{
			ZNet instance = ZNet.instance;
			if (routed != null && Object.op_Implicit((Object)(object)instance) && world != null && requested.Kind != 0)
			{
				if (instance.IsServer())
				{
					Accept(requested, 0L);
				}
				else
				{
					SendToServer("nova_ocean_event_request_v8", requested.Serialize());
				}
			}
		}

		internal void StopManual()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			ZNet instance = ZNet.instance;
			if (routed != null && Object.op_Implicit((Object)(object)instance) && world != null)
			{
				if (instance.IsServer())
				{
					StopServer(instance.GetTimeSeconds());
				}
				else
				{
					SendToServer("nova_ocean_event_stop_v8", new ZPackage());
				}
			}
		}

		private void ReceiveQuery(long sender, ZPackage package)
		{
			if (Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer())
			{
				Broadcast(sender);
			}
		}

		private void ReceiveRequest(long sender, ZPackage package)
		{
			if (!Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsServer())
			{
				return;
			}
			try
			{
				Accept(OceanEventState.Deserialize(package), sender);
			}
			catch (Exception)
			{
			}
		}

		private void ReceiveStop(long sender, ZPackage package)
		{
			if (Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer() && state.Kind != 0 && state.Manual && senderOwner == sender)
			{
				StopServer(ZNet.instance.GetTimeSeconds());
			}
		}

		private void ReceiveState(long sender, ZPackage package)
		{
			if (!Object.op_Implicit((Object)(object)ZNet.instance) || ZNet.instance.IsServer() || world == null || sender != GetServerId())
			{
				return;
			}
			try
			{
				OceanEventState oceanEventState = OceanEventState.Deserialize(package);
				if (oceanEventState.WorldId == world.m_uid && oceanEventState.Sequence >= state.Sequence && oceanEventState.Kind >= 0 && oceanEventState.Kind <= 8)
				{
					state = oceanEventState;
					nextQuery = ZNet.instance.GetTimeSeconds() + 25.0;
				}
			}
			catch (Exception)
			{
			}
		}

		private void Accept(OceanEventState proposed, long sender)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: 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_017c: Invalid comparison between Unknown and I4
			//IL_01bc: 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_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)ZNet.instance) || !ZNet.instance.IsServer() || world == null || proposed.Kind < 1 || proposed.Kind > 8 || proposed.WorldId != world.m_uid || !IsFinite(proposed.Anchor) || !IsFinite(proposed.Origin) || !IsFinite(proposed.Motion) || !IsFinite(proposed.Heading) || float.IsNaN(proposed.Extra) || float.IsInfinity(proposed.Extra) || (sender != 0L && ZNet.instance.GetPeer(sender) == null) || (!proposed.Manual && (proposed.Kind == 5 || proposed.Kind == 8)))
			{
				return;
			}
			double timeSeconds = ZNet.instance.GetTimeSeconds();
			if (state.Kind != 0 && timeSeconds >= state.Ends)
			{
				StopServer(timeSeconds);
			}
			if (!proposed.Manual && (timeSeconds < serverCooldown || (state.Kind != 0 && timeSeconds < state.Ends)))
			{
				Broadcast();
			}
			else if (state.Kind != 0 && timeSeconds < state.Ends && proposed.Manual && sender != 0L && senderOwner != sender)
			{
				Broadcast(sender);
			}
			else
			{
				if (!proposed.Manual && (WorldGenerator.instance == null || (int)WorldGenerator.instance.GetBiome(proposed.Anchor) != 256))
				{
					return;
				}
				proposed.Sequence = ++sequence;
				if (proposed.Kind == 6 && !((ZDOID)(ref proposed.LightningTarget)).IsNone())
				{
					ZDOMan instance = ZDOMan.instance;
					ZDO val = ((instance != null) ? instance.GetZDO(proposed.LightningTarget) : null);
					if (val == null || Utils.DistanceXZ(val.GetPosition(), proposed.Anchor) > 30f)
					{
						proposed.LightningTarget = ZDOID.None;
					}
				}
				proposed.Started = timeSeconds;
				proposed.Ends = timeSeconds + OceanEventState.DurationFor(proposed.Kind);
				proposed.ShipStrikeAt = 0.0;
				proposed.ShipStrikePoint = Vector3.zero;
				state = proposed;
				uint seed = (uint)state.Seed;
				shipStrikeAt = ((state.Kind == 6 && !((ZDOID)(ref state.LightningTarget)).IsNone() && OceanGlow.UnitHash(seed ^ 0x9E3779B9u) < 0.08f) ? (timeSeconds + 20.0 + (state.Ends - timeSeconds - 40.0) * (double)OceanGlow.UnitHash(seed ^ 0x27D4EB2F)) : double.PositiveInfinity);
				senderOwner = sender;
				Broadcast();
			}
		}

		private void ResolveShipStrike(double now)
		{
			//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_0087: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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_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)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Expected O, but got Unknown
			shipStrikeAt = double.PositiveInfinity;
			GameObject val = (Object.op_Implicit((Object)(object)ZNetScene.instance) ? ZNetScene.instance.FindInstance(state.LightningTarget) : null);
			Ship val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<Ship>() : null);
			if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)ZoneSystem.instance) || Mathf.Abs(((Component)val2).transform.position.y - ZoneSystem.instance.m_waterLevel) > 9f || Utils.DistanceXZ(((Component)val2).transform.position, state.Anchor) > 650f)
			{
				return;
			}
			WearNTear component = ((Component)val2).GetComponent<WearNTear>();
			Destructible component2 = ((Component)val2).GetComponent<Destructible>();
			if (Object.op_Implicit((Object)(object)component) || Object.op_Implicit((Object)(object)component2))
			{
				state.ShipStrikePoint = (Object.op_Implicit((Object)(object)val2.m_mastObject) ? (val2.m_mastObject.transform.position + Vector3.up * 3f) : (((Component)val2).transform.position + Vector3.up * 1.5f));
				state.ShipStrikeAt = now;
				HitData val3 = new HitData
				{
					m_point = ((Component)val2).transform.position,
					m_dir = Vector3.down,
					m_damage = new DamageTypes
					{
						m_damage = (Object.op_Implicit((Object)(object)component) ? component.m_health : component2.m_health) * 0.15f
					}
				};
				if (Object.op_Implicit((Object)(object)component))
				{
					component.Damage(val3);
				}
				else
				{
					component2.Damage(val3);
				}
				Broadcast();
			}
		}

		private static bool IsFinite(Vector3 p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_0034: 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)
			if (!float.IsNaN(p.x) && !float.IsInfinity(p.x) && !float.IsNaN(p.y) && !float.IsInfinity(p.y) && !float.IsNaN(p.z))
			{
				return !float.IsInfinity(p.z);
			}
			return false;
		}

		private void StopServer(double now)
		{
			if (state.Kind != 0)
			{
				state.Kind = 0;
				state.Started = now;
				state.Ends = now;
				state.Sequence = ++sequence;
				senderOwner = 0L;
				serverCooldown = now + 600.0;
				Broadcast();
			}
		}

		private void Broadcast()
		{
			Broadcast(0L);
		}

		private void Broadcast(long peerId)
		{
			if (routed != null)
			{
				routed.InvokeRoutedRPC(peerId, "nova_ocean_event_state_v8", new object[1] { state.Serialize() });
			}
		}
	}
	internal struct OceanEventState
	{
		public long Sequence;

		public long WorldId;

		public int Kind;

		public bool Manual;

		public double Started;

		public double Ends;

		public Vector3 Anchor;

		public Vector3 Heading;

		public Vector3 Origin;

		public Vector3 Motion;

		public float Extra;

		public int Seed;

		public ZDOID LightningTarget;

		public double ShipStrikeAt;

		public Vector3 ShipStrikePoint;

		internal ZPackage Serialize()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0035: 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_004d: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00ba: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			val.Write(Sequence);
			val.Write(WorldId);
			val.Write(Kind);
			val.Write(Manual);
			val.Write(Started);
			val.Write(Ends);
			val.Write(Anchor);
			val.Write(Heading);
			val.Write(Origin);
			val.Write(Motion);
			val.Write(Extra);
			val.Write(Seed);
			val.Write(LightningTarget);
			val.Write(ShipStrikeAt);
			val.Write(ShipStrikePoint);
			return val;
		}

		internal static OceanEventState Deserialize(ZPackage data)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			return new OceanEventState
			{
				Sequence = data.ReadLong(),
				WorldId = data.ReadLong(),
				Kind = data.ReadInt(),
				Manual = data.ReadBool(),
				Started = data.ReadDouble(),
				Ends = data.ReadDouble(),
				Anchor = data.ReadVector3(),
				Heading = data.ReadVector3(),
				Origin = data.ReadVector3(),
				Motion = data.ReadVector3(),
				Extra = data.ReadSingle(),
				Seed = data.ReadInt(),
				LightningTarget = data.ReadZDOID(),
				ShipStrikeAt = data.ReadDouble(),
				ShipStrikePoint = data.ReadVector3()
			};
		}

		internal static double DurationFor(int kind)
		{
			return kind switch
			{
				1 => 320.0, 
				2 => 720.0, 
				3 => 140.0, 
				4 => 155.0, 
				5 => 120.0, 
				6 => 300.0, 
				7 => 240.0, 
				8 => 120.0, 
				_ => 0.0, 
			};
		}
	}
	internal sealed class OceanGlow : IDisposable
	{
		private const float Radius = 34f;

		private const float CellSize = 5f;

		private const int CellRange = 7;

		private const float MaxSparkHeight = 7f;

		private static readonly Color SparkColor = new Color(0.55f, 0.83f, 1f);

		private static readonly Color SubmergedSparkColor = new Color(0.12f, 0.43f, 0.72f);

		private readonly GameObject root;

		private readonly Mesh mesh;

		private readonly Material material;

		private readonly Texture2D texture;

		private readonly List<Vector3> vertices = new List<Vector3>(7200);

		private readonly List<Vector2> uvs = new List<Vector2>(7200);

		private readonly List<Color32> colors = new List<Color32>(7200);

		private readonly List<int> indices = new List<int>(10800);

		private readonly Dictionary<(int X, int Z), float> seabedByCell = new Dictionary<(int, int), float>();

		private readonly Light[] planktonLights = (Light[])(object)new Light[4];

		private readonly AzureWaterTint waterTint = new AzureWaterTint();

		private readonly AzureWake wake = new AzureWake();

		private Vector3 cameraPosition;

		private bool hasCamera;

		private Vector3 sparkUp;

		private Vector3 sparkRight;

		private WaterVolume water;

		private float nextSeabedRefresh;

		private Vector3 center;

		private float seaLevel;

		public OceanGlow(Shader shader)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Expected O, but got Unknown
			//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)
			//IL_019c: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			root = new GameObject("PerfectOceanExperience - Azure Breeze")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)(object)root);
			root.SetActive(false);
			texture = new Texture2D(32, 32, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[1024];
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num = ((float)j - 15.5f) / 15.5f;
					float num2 = ((float)i - 15.5f) / 15.5f;
					float num3 = Mathf.Clamp01(1f - num * num - num2 * num2);
					array[i * 32 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(255f * num3 * num3 * num3));
				}
			}
			texture.SetPixels32(array);
			texture.Apply(false, true);
			material = new Material(shader)
			{
				mainTexture = (Texture)(object)texture,
				renderQueue = 3100,
				enableInstancing = false
			};
			mesh = new Mesh
			{
				name = "Bioluminescent water"
			};
			mesh.MarkDynamic();
			root.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer obj = root.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = material;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			((Renderer)obj).lightProbeUsage = (LightProbeUsage)0;
			((Renderer)obj).reflectionProbeUsage = (ReflectionProbeUsage)0;
			for (int k = 0; k < planktonLights.Length; k++)
			{
				GameObject val = new GameObject("Submerged plankton light");
				val.transform.SetParent(root.transform, false);
				Light val2 = val.AddComponent<Light>();
				val2.type = (LightType)2;
				val2.range = 8f;
				val2.shadows = (LightShadows)0;
				planktonLights[k] = val2;
			}
		}

		public void Draw(Vector3 origin, Ship ship, float waterLevel, Color tint, float intensity)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_008c: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			center = new Vector3(origin.x, waterLevel, origin.z);
			seaLevel = waterLevel;
			root.transform.position = center;
			Camera main = Camera.main;
			hasCamera = Object.op_Implicit((Object)(object)main);
			cameraPosition = (Object.op_Implicit((Object)(object)main) ? ((Component)main).transform.position : origin);
			sparkUp = (Object.op_Implicit((Object)(object)main) ? ((Component)main).transform.up : Vector3.forward);
			sparkRight = (Object.op_Implicit((Object)(object)main) ? ((Component)main).transform.right : Vector3.right);
			float time = Time.time;
			vertices.Clear();
			uvs.Clear();
			colors.Clear();
			indices.Clear();
			waterTint.Draw(tint, intensity);
			DrawWaves(tint, intensity, time);
			DrawPlanktonLights(tint, intensity, time);
			DrawWake(ship, tint, intensity, time);
			mesh.Clear();
			if (vertices.Count != 0)
			{
				mesh.SetVertices(vertices);
				mesh.SetUVs(0, uvs);
				mesh.SetColors(colors);
				mesh.SetTriangles(indices, 0);
			}
			root.SetActive(vertices.Count != 0);
		}

		private void DrawWaves(Color tint, float intensity, float now)
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			if (now >= nextSeabedRefresh)
			{
				seabedByCell.Clear();
				nextSeabedRefresh = now + 2f;
			}
			int num = Mathf.FloorToInt(center.x / 5f);
			int num2 = Mathf.FloorToInt(center.z / 5f);
			Vector3 point = default(Vector3);
			for (int i = num2 - 7; i <= num2 + 7; i++)
			{
				for (int j = num - 7; j <= num + 7; j++)
				{
					uint num3 = (uint)((j * -1640531527) ^ (i * -2048144789));
					float num4 = UnitHash(num3 ^ 0xC2B2AE35u);
					((Vector3)(ref point))..ctor(((float)j + UnitHash(num3)) * 5f + 0.25f * Mathf.Sin(now * 0.7f + 10f * num4), seaLevel, ((float)i + UnitHash(num3 ^ 0x27D4EB2F)) * 5f + 0.25f * Mathf.Cos(now * 0.6f + 10f * num4));
					float num5 = RangeFade(point);
					if (!(num5 <= 0f) && PlaceOnWater(ref point))
					{
						if ((num3 & 3) != 0)
						{
							DrawCrest(point, num4, tint, num5 * intensity, now);
						}
						DrawAirborneSparks(point, num3, num5 * intensity, now);
						DrawWaterColumn(point, (X: j, Z: i), num3, num5 * intensity, now);
					}
				}
			}
		}

		private void DrawCrest(Vector3 point, float phase, Color tint, float intensity, float now)
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0042: 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_004d: 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_0081: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: 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_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			Vector3 point2 = point + Vector3.left * 0.7f;
			Vector3 point3 = point + Vector3.right * 0.7f;
			Vector3 point4 = point + Vector3.forward * 0.7f;
			Vector3 point5 = point + Vector3.back * 0.7f;
			if (PlaceOnWater(ref point2) && PlaceOnWater(ref point3) && PlaceOnWater(ref point4) && PlaceOnWater(ref point5))
			{
				float num = point.y - (point2.y + point3.y + point4.y + point5.y) * 0.25f;
				float num2 = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.006f, 0.15f, num));
				if (!(num2 <= 0f))
				{
					Vector3 val = default(Vector3);
					((Vector3)(ref val))..ctor(point3.y - point2.y, 0f, point4.y - point5.y);
					Vector3 val2 = ((((Vector3)(ref val)).sqrMagnitude > 0.0025f) ? ((Vector3)(ref val)).normalized : Vector3.forward);
					Vector3 val3 = Vector3.Cross(Vector3.up, val2);
					val2.y = ((Vector3)(ref val)).magnitude / 1.4f;
					point.y += 0.06f;
					float num3 = 0.62f + 0.38f * Mathf.Sin(now * (1.3f + phase) + phase * 14f);
					AddQuad(point, val3 * (0.65f + 1.3f * phase), val2 * (0.12f + 0.24f * phase), Color.Lerp(tint, SparkColor, 0.37f), intensity * num2 * num3 * 0.29f);
				}
			}
		}

		private void DrawWake(Ship ship, Color tint, float intensity, float now)
		{
			//IL_000e: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_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_0077: 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_011d: 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_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			wake.Update(ship, now);
			Color tint2 = Color.Lerp(tint, SparkColor, 0.4f);
			IReadOnlyList<AzureWake.Spark> sparks = wake.Sparks;
			for (int i = 0; i < sparks.Count; i++)
			{
				AzureWake.Spark spark = sparks[i];
				float num = now - spark.Born;
				float num2 = num / spark.Lifetime;
				Vector3 point = spark.Origin + spark.Drift * (num / (1f + 0.075f * num));
				float num3 = RangeFade(point);
				if (!(num3 <= 0f) && PlaceOnWater(ref point))
				{
					float num4 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num * 6f));
					float num5 = 1f - num2;
					float num6 = 0.7f + 0.3f * Mathf.Sin(now * 6.1f + 23f * spark.Phase);
					float num7 = num3 * intensity * spark.Brightness * num4 * num5 * num5 * num6;
					float num8 = spark.Size * (1f + 0.75f * num2);
					AddQuad(point, ((Vector3)(ref spark.Drift)).normalized, num8 * 3.1f, num8, tint2, num7 * 0.82f);
					if (spark.Phase > 0.73f)
					{
						point.y += 0.08f + 0.22f * Mathf.Sin(num2 * (float)Math.PI);
						AddQuad(point, sparkUp * num8, sparkRight * num8, tint2, num7 * 0.93f);
					}
				}
			}
		}

		private void DrawWaterColumn(Vector3 point, (int X, int Z) cell, uint cellKey, float intensity, float now)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			if (!hasCamera)
			{
				return;
			}
			if (!seabedByCell.TryGetValue(cell, out var value))
			{
				if (!Heightmap.GetHeight(point, ref value))
				{
					WorldGenerator instance = WorldGenerator.instance;
					if (instance == null)
					{
						return;
					}
					value = instance.GetHeight(point);
				}
				seabedByCell.Add(cell, value);
			}
			if (point.y - value < 1.5f)
			{
				return;
			}
			for (int num = 2; num >= 0; num--)
			{
				uint num2 = cellKey ^ (uint)((num + 1) * -1028477387);
				float num3 = UnitHash(num2);
				float num4 = now * (0.36f + 0.4f * num3) + 22f * num3;
				float num5 = 0.5f + 0.5f * Mathf.Sin(num4);
				Vector3 point2 = point + new Vector3(3.4f * (UnitHash(num2 ^ 0x27D4EB2F) - 0.5f) + 0.8f * Mathf.Sin(num4), 0f, 3.4f * (UnitHash(num2 ^ 0x85EBCA6Bu) - 0.5f) + 0.8f * Mathf.Cos(num4));
				if (PlaceOnWater(ref point2))
				{
					float y = point2.y;
					float num6 = y - value;
					float num7 = ((num == 0) ? (0.06f + 0.1f * num3) : (0.32f + 0.22f * num3));
					float num8 = ((num == 2) ? (num6 - (0.45f + 1.1f * num3 + 0.6f * num5)) : Mathf.Min(num6 * num7 + 0.22f * num5, (num == 0) ? 4f : 23f));
					if (!(num8 < 0.22f))
					{
						point2.y -= num8;
						float size = (0.075f + 0.1f * num3) * (1f + Mathf.Min(num8, 60f) * 0.012f);
						float num9 = 0.5f + 0.5f * Mathf.Sin(num4 * 1.45f);
						Color tint = Color.Lerp(SparkColor, SubmergedSparkColor, 0.25f + 0.3f * (float)num);
						float num10 = 0.26f + 0.74f / (1f + 0.085f * num8);
						float opacity = intensity * num10 * (0.4f + 0.49f * num9);
						DrawSubmergedSpark(point2, y, tint, size, opacity);
					}
				}
			}
		}

		private void DrawAirborneSparks(Vector3 point, uint cellKey, float intensity, float now)
		{
			//IL_0075: 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)
			//IL_00cc: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			for (uint num = 0u; num < 3; num++)
			{
				uint num2 = cellKey ^ (uint)((int)(num + 1) * -1640531527);
				float num3 = UnitHash(num2);
				float num4 = now * (0.6f + 0.45f * num3) + 19f * num3;
				float num5 = 0.5f + 0.5f * Mathf.Sin(num4);
				float num6 = 0.3f + 6.7f * ((float)num + 0.06f + 0.68f * num3 + 0.26f * num5) / 3f;
				Vector3 point2 = point + new Vector3(3.5f * (UnitHash(num2 ^ 0x27D4EB2F) - 0.5f) + 0.9f * Mathf.Cos(num4), num6, 3.5f * (UnitHash(num2 ^ 0x85EBCA6Bu) - 0.5f) + 0.9f * Mathf.Sin(num4));
				float num7 = 0.03f + 0.07f * num3;
				float num8 = 0.5f + 0.5f * Mathf.Sin(2.1f * num4);
				AddQuad(point2, sparkUp * num7, sparkRight * num7, SparkColor, intensity * (0.08f + 0.56f * num8 * num8));
			}
		}

		private void DrawPlanktonLights(Color tint, float intensity, float now)
		{
			//IL_0053: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < planktonLights.Length; i++)
			{
				Light val = planktonLights[i];
				float num = (float)i * (float)Math.PI * 0.5f;
				float num2 = num + 0.28f * Mathf.Sin(now * 0.31f + num);
				float num3 = 5.5f + 0.9f * Mathf.Sin(now * 0.43f + num);
				Vector3 point = center + new Vector3(Mathf.Cos(num2) * num3, 0f, Mathf.Sin(num2) * num3);
				((Behaviour)val).enabled = PlaceOnWater(ref point);
				if (((Behaviour)val).enabled)
				{
					float y = point.y;
					float num4 = 0.5f + 0.5f * Mathf.Sin(now * 1.25f + num);
					point.y -= 2.25f + 0.8f * num4;
					Color val2 = Color.Lerp(tint, SparkColor, 0.6f);
					((Component)val).transform.position = point;
					val.color = val2;
					val.intensity = Mathf.Min(intensity, 1.5f) * (1.2f + 0.6f * num4);
					DrawSubmergedSpark(point, y, val2, 0.2f, intensity * (0.45f + 0.34f * num4));
				}
			}
		}

		private void DrawSubmergedSpark(Vector3 point, float surfaceHeight, Color tint, float size, float opacity)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0042: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: 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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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)
			if (!hasCamera)
			{
				return;
			}
			float num = surfaceHeight - point.y;
			Vector3 val = point;
			val.y = surfaceHeight - num * 0.75f;
			Vector3 val2 = val - cameraPosition;
			if (val2.y >= -0.01f)
			{
				return;
			}
			float num2 = surfaceHeight;
			Vector3 point2 = point;
			float num3 = 0f;
			for (int i = 0; i < 3; i++)
			{
				num3 = (num2 - cameraPosition.y) / val2.y;
				if (num3 <= 0.015f || num3 >= 1f)
				{
					return;
				}
				point2 = cameraPosition + val2 * num3;
				if (!PlaceOnWater(ref point2))
				{
					return;
				}
				num2 = point2.y;
			}
			float num4 = size * num3;
			point2.y += 0.14f + num4;
			float magnitude = ((Vector3)(ref val2)).magnitude;
			opacity *= 1f - Mathf.InverseLerp(38f, 125f, magnitude) * 0.48f;
			AddQuad(point2, sparkUp * (num4 * 2.4f), sparkRight * (num4 * 2.4f), tint, opacity * 0.33f);
			AddQuad(point2, sparkUp * num4, sparkRight * num4, Color.Lerp(tint, SparkColor, 0.4f), opacity);
		}

		private float RangeFade(Vector3 point)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			float num = point.x - center.x;
			float num2 = point.z - center.z;
			return Mathf.Clamp01((34f - Mathf.Sqrt(num * num + num2 * num2)) / 9f);
		}

		private bool PlaceOnWater(ref Vector3 point)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			point.y = seaLevel;
			float waterLevel = Floating.GetWaterLevel(point, ref water);
			if (waterLevel < seaLevel - 20f)
			{
				return false;
			}
			point.y = waterLevel + 0.1f;
			return true;
		}

		private void AddQuad(Vector3 point, Vector3 direction, float halfLength, float halfWidth, Color tint, float opacity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 length = direction * halfLength;
			Vector3 width = new Vector3(direction.z, 0f, 0f - direction.x) * halfWidth;
			AddQuad(point, length, width, tint, opacity);
		}

		private void AddQuad(Vector3 point, Vector3 length, Vector3 width, Color tint, float opacity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0058: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			point -= center;
			int count = vertices.Count;
			vertices.Add(point - length - width);
			vertices.Add(point - length + width);
			vertices.Add(point + length + width);
			vertices.Add(point + length - width);
			uvs.Add(new Vector2(0f, 0f));
			uvs.Add(new Vector2(1f, 0f));
			uvs.Add(new Vector2(1f, 1f));
			uvs.Add(new Vector2(0f, 1f));
			tint.a = Mathf.Clamp01(opacity);
			Color32 item = Color32.op_Implicit(tint);
			for (int i = 0; i < 4; i++)
			{
				colors.Add(item);
			}
			indices.Add(count);
			indices.Add(count + 2);
			indices.Add(count + 1);
			indices.Add(count);
			indices.Add(count + 3);
			indices.Add(count + 2);
		}

		internal static uint Hash(uint value)
		{
			value ^= value >> 16;
			value *= 2146121005;
			value ^= value >> 15;
			value *= 2221713035u;
			return value ^ (value >> 16);
		}

		internal static float UnitHash(uint value)
		{
			return (float)(Hash(value) >> 8) * 5.9604645E-08f;
		}

		public void Clear()
		{
			root.SetActive(false);
			water = null;
			seabedByCell.Clear();
			waterTint.Clear();
			wake.Clear();
		}

		public void Dispose()
		{
			Clear();
			Object.Destroy((Object)(object)root);
			Object.Destroy((Object)(object)mesh);
			Object.Destroy((Object)(object)material);
			Object.Destroy((Object)(object)texture);
		}
	}
	internal sealed class AzureWaterTint
	{
		private sealed class WaterTile
		{
			public Material Material;

			public readonly MaterialPropertyBlock Original = new MaterialPropertyBlock();

			public Color Surface;

			public Color Top;

			public Color Shallow;

			public Color Deep;

			public int LastSeen;
		}

		private static readonly int Surface = Shader.PropertyToID("_SurfaceColor");

		private static readonly int Top = Shader.PropertyToID("_ColorTop");

		private static readonly int Shallow = Shader.PropertyToID("_ColorBottomShallow");

		private static readonly int Deep = Shader.PropertyToID("_ColorBottom");

		private readonly Dictionary<MeshRenderer, WaterTile> tiles = new Dictionary<MeshRenderer, WaterTile>();

		private readonly List<MeshRenderer> removed = new List<MeshRenderer>();

		private readonly MaterialPropertyBlock working = new MaterialPropertyBlock();

		private float nextUpdate;

		private int update;

		public void Draw(Color tint, float intensity)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: 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_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: 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_0226: 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_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < nextUpdate)
			{
				return;
			}
			nextUpdate = Time.unscaledTime + 0.12f;
			update++;
			float num = Mathf.Clamp01(intensity * 0.82f);
			foreach (WaterVolume instance in WaterVolume.Instances)
			{
				if (!Object.op_Implicit((Object)(object)instance) || !((Behaviour)instance).isActiveAndEnabled || (int)instance.GetLiquidType() != 0)
				{
					continue;
				}
				MeshRenderer waterSurface = instance.m_waterSurface;
				if (!Object.op_Implicit((Object)(object)waterSurface))
				{
					continue;
				}
				Material sharedMaterial = ((Renderer)waterSurface).sharedMaterial;
				if (!Object.op_Implicit((Object)(object)sharedMaterial) || !sharedMaterial.HasProperty(Surface) || !sharedMaterial.HasProperty(Top) || !sharedMaterial.HasProperty(Shallow) || !sharedMaterial.HasProperty(Deep))
				{
					continue;
				}
				if (!tiles.TryGetValue(waterSurface, out var value) || (Object)(object)value.Material != (Object)(object)sharedMaterial)
				{
					if (value != null)
					{
						Restore(waterSurface, value);
					}
					value = new WaterTile
					{
						Material = sharedMaterial
					};
					((Renderer)waterSurface).GetPropertyBlock(value.Original);
					value.Surface = GetColor(value, Surface);
					value.Top = GetColor(value, Top);
					value.Shallow = GetColor(value, Shallow);
					value.Deep = GetColor(value, Deep);
					tiles[waterSurface] = value;
				}
				value.LastSeen = update;
				((Renderer)waterSurface).GetPropertyBlock(working);
				working.SetColor(Surface, Blend(value.Surface, tint * 2.55f, num));
				working.SetColor(Top, Blend(value.Top, tint * 2.1f, num));
				working.SetColor(Shallow, Blend(value.Shallow, tint * 1.32f, num * 0.76f));
				working.SetColor(Deep, Blend(value.Deep, tint * 0.55f, num * 0.52f));
				((Renderer)waterSurface).SetPropertyBlock(working);
			}
			removed.Clear();
			foreach (KeyValuePair<MeshRenderer, WaterTile> tile in tiles)
			{
				if (!Object.op_Implicit((Object)(object)tile.Key) || tile.Value.LastSeen != update)
				{
					Restore(tile.Key, tile.Value);
					removed.Add(tile.Key);
				}
			}
			foreach (MeshRenderer item in removed)
			{
				tiles.Remove(item);
			}
		}

		private static Color GetColor(WaterTile tile, int property)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (!tile.Original.HasColor(property))
			{
				return tile.Material.GetColor(property);
			}
			return tile.Original.GetColor(property);
		}

		private static Color Blend(Color source, Color tint, float weight)
		{
			//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_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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)
			Color result = Color.Lerp(source, tint, weight);
			result.a = source.a;
			return result;
		}

		private static void Restore(MeshRenderer renderer, WaterTile tile)
		{
			if (Object.op_Implicit((Object)(object)renderer))
			{
				((Renderer)renderer).SetPropertyBlock(tile.Original.isEmpty ? null : tile.Original);
			}
		}

		public void Clear()
		{
			foreach (KeyValuePair<MeshRenderer, WaterTile> tile in tiles)
			{
				Restore(tile.Key, tile.Value);
			}
			tiles.Clear();
			removed.Clear();
			nextUpdate = 0f;
		}
	}
	internal sealed class AzureWake
	{
		public struct Spark
		{
			public Vector3 Origin;

			public Vector3 Drift;

			public float Born;

			public float Lifetime;

			public float Size;

			public float Brightness;

			public float Phase;
		}

		private const float Spacing = 0.52f;

		private const int Limit = 448;

		private readonly List<Spark> sparks = new List<Spark>(448);

		private Ship lastShip;

		private Vector3 lastBow;

		private Vector3 lastPosition;

		private float untilNext;

		private uint serial;

		public IReadOnlyList<Spark> Sparks => sparks;

		public void Update(Ship ship, float now)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c3: 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_00e8: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: 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_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: 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_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: 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_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: 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_027a: 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_0280: Unknown result type (might be due to invalid IL or missing references)
			for (int num = sparks.Count - 1; num >= 0; num--)
			{
				if (!(now - sparks[num].Born < sparks[num].Lifetime))
				{
					sparks[num] = sparks[sparks.Count - 1];
					sparks.RemoveAt(sparks.Count - 1);
				}
			}
			if (!Object.op_Implicit((Object)(object)ship))
			{
				lastShip = null;
				return;
			}
			Vector3 position = ((Component)ship).transform.position;
			BoxCollider floatCollider = ship.m_floatCollider;
			Transform val = (Object.op_Implicit((Object)(object)floatCollider) ? ((Component)floatCollider).transform : ((Component)ship).transform);
			Vector3 val2 = (Object.op_Implicit((Object)(object)floatCollider) ? val.TransformPoint(floatCollider.center) : position);
			Vector3 val3 = val.TransformVector(Vector3.forward * (Object.op_Implicit((Object)(object)floatCollider) ? (floatCollider.size.z * 0.49f) : 2.1f));
			Vector3 val4 = val.TransformVector(Vector3.right * (Object.op_Implicit((Object)(object)floatCollider) ? (floatCollider.size.x * 0.5f) : 1f));
			val3.y = (val4.y = 0f);
			Vector3 val5 = val2 + val3 * 0.91f;
			if ((Object)(object)ship != (Object)(object)lastShip)
			{
				lastShip = ship;
				lastBow = val5;
				lastPosition = position;
				untilNext = 0.52f;
				return;
			}
			Vector3 val6 = position - lastPosition;
			val6.y = 0f;
			float magnitude = ((Vector3)(ref val6)).magnitude;
			Vector3 val7 = lastBow;
			lastBow = val5;
			lastPosition = position;
			if (magnitude > 10f)
			{
				sparks.Clear();
				untilNext = 0.52f;
				return;
			}
			Vector3 normalized = ((Vector3)(ref val3)).normalized;
			float num2 = Vector3.Dot(val6, normalized) / Mathf.Max(Time.deltaTime, 0.001f);
			if (!(num2 < 0.25f) && !(magnitude <= 0.001f))
			{
				float beam = Mathf.Max(0.45f, ((Vector3)(ref val4)).magnitude);
				float strength = Mathf.InverseLerp(0.25f, 2.6f, num2);
				while (untilNext <= magnitude)
				{
					Vector3 point = Vector3.Lerp(val7, val5, untilNext / magnitude);
					Spawn(point, normalized, -((Vector3)(ref val4)).normalized, beam, num2, now, strength);
					Spawn(point, normalized, ((Vector3)(ref val4)).normalized, beam, num2, now, strength);
					untilNext += 0.52f;
				}
				untilNext -= magnitude;
			}
		}

		private void Spawn(Vector3 point, Vector3 forward, Vector3 side, float beam, float speed, float now, float strength)
		{
			//IL_0051: 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_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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 3; i++)
			{
				if (sparks.Count >= 448)
				{
					break;
				}
				int num = (int)(++serial) * -1640531527;
				float num2 = OceanGlow.UnitHash((uint)num);
				float num3 = OceanGlow.UnitHash((uint)(num ^ -2048144789));
				float num4 = OceanGlow.UnitHash((uint)(num ^ 0x27D4EB2F));
				sparks.Add(new Spark
				{
					Origin = point + side * (beam * (0.22f + 0.48f * num2)) - forward * (1.1f * num3),
					Drift = side * (0.52f + 0.26f * Mathf.Min(speed, 5f)) * (0.44f + 0.86f * num2) + forward * ((num3 - 0.33f) * 0.46f),
					Born = now,
					Lifetime = 3.4f + 4.8f * num4,
					Size = 0.075f + 0.16f * num3 * num3,
					Brightness = strength * (0.25f + 0.65f * num2),
					Phase = num4
				});
			}
		}

		public void Clear()
		{
			sparks.Clear();
			lastShip = null;
			untilNext = 0f;
		}
	}
	[HarmonyPatch(typeof(EnvMan), "GetWindDir")]
	internal static class AzureWind
	{
		public static bool Active { get; set; }

		private static void Postfix(ref Vector3 __result)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			if (!Active || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return;
			}
			Ship localShip = Ship.GetLocalShip();
			if (Object.op_Implicit((Object)(object)localShip))
			{
				Vector3 forward = ((Component)localShip).transform.forward;
				forward.y = 0f;
				if (((Vector3)(ref forward)).sqrMagnitude > 0.0001f)
				{
					__result = ((Vector3)(ref forward)).normalized;
				}
			}
		}
	}
	internal sealed class WaterspoutSystem : IDisposable
	{
		private struct Vortex
		{
			public Vector3 Origin;

			public Vector3 Velocity;

			public float TurnRadius;

			public double Start;

			public uint Seed;

			public Vector3 Position(double time)
			{
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_008f: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				float num = Mathf.Clamp((float)(time - Start), 0f, 600f);
				if (TurnRadius <= 0f)
				{
					return Origin + Velocity * num;
				}
				Vector3 normalized = ((Vector3)(ref Velocity)).normalized;
				Vector3 val = Vector3.Cross(Vector3.up, normalized);
				float num2 = num * ((Vector3)(ref Velocity)).magnitude / TurnRadius;
				return Origin + (normalized * Mathf.Sin(num2) + val * (1f - Mathf.Cos(num2))) * TurnRadius;
			}

			public Vector3 VelocityAt(double time)
			{
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				if (TurnRadius <= 0f)
				{
					return Velocity;
				}
				float num = (float)(time - Start) * ((Vector3)(ref Velocity)).magnitude / TurnRadius;
				return Velocity * Mathf.Cos(num) + Vector3.Cross(Vector3.up, Velocity) * Mathf.Sin(num);
			}

			public float Strength(double time)
			{
				float num = (float)(time - Start);
				return Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num / 5f)) * Mathf.SmoothStep(0f, 1f, Mathf.Clamp01((600f - num) / 8f));
			}
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static ConsoleOptionsFetcher <>9__35_0;

			internal List<string> <.ctor>b__35_0()
			{
				return new List<string> { "start", "stop" };
			}
		}

		private const float Duration = 600f;

		private const float CycleSeconds = 2400f;

		private const float RainDuration = 720f;

		private const float RainChance = 0.33f;

		private const float RainLead = 45f;

		private const float EncounterDelay = 20f;

		private const float SpawnSpread = 40f;

		private const float CellSize = 192f;

		private const float NaturalChance = 0.08f;

		private const float TravelSpeed = 2.2f;

		private const float SightRange = 240f;

		private readonly WaterspoutVisual visual;

		private readonly WaterspoutFish fish = new WaterspoutFish();

		private readonly WaterspoutRiders riders = new WaterspoutRiders();

		private readonly WaterspoutShips capturedShips;

		private readonly Action onPreviewStarted;

		private readonly Action<float, float> playWind;

		private readonly Action stopWind;

		private readonly Action<Vector3, float, float> playVortexWind;

		private readonly List<Vortex> nearby = new List<Vortex>();

		private readonly Dictionary<uint, bool> checkedRoutes