Decompiled source of WorldCataclysms v1.1.0

plugins/WorldCataclysms.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using WorldCataclysms.Config;
using WorldCataclysms.Core;
using WorldCataclysms.Events;
using WorldCataclysms.Migration;
using WorldCataclysms.Seasons;
using WorldCataclysms.Survival;
using WorldCataclysms.Visuals;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("WorldCataclysms")]
[assembly: AssemblyDescription("Server-coordinated cataclysm events for Valheim")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyVersion("1.1.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 WorldCataclysms
{
	[BepInPlugin("mitsu.worldcataclysms", "WorldCataclysms", "1.1.0")]
	[BepInDependency("com.jotunn.jotunn", "2.30.2")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "mitsu.worldcataclysms";

		public const string PluginName = "WorldCataclysms";

		public const string PluginVersion = "1.1.0";

		private Harmony patches;

		public static Plugin Instance { get; private set; }

		public static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			ModConfig.Bind(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger);
			CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new AdminCommand());
			patches = new Harmony("mitsu.worldcataclysms");
			patches.PatchAll(typeof(Plugin).Assembly);
			((Component)this).gameObject.AddComponent<SeasonManager>();
			((Component)this).gameObject.AddComponent<WorldEventManager>();
			((Component)this).gameObject.AddComponent<AuroraVisual>();
			((Component)this).gameObject.AddComponent<CreatureResponseController>();
			((Component)this).gameObject.AddComponent<WorldCataclysmsHud>();
			((Component)this).gameObject.AddComponent<PersistentHazardController>();
			((Component)this).gameObject.AddComponent<CataclysmEnvironmentRegistry>();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"WorldCataclysms 1.1.0 cargado correctamente.");
		}

		private void OnDestroy()
		{
			Harmony obj = patches;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}
	}
}
namespace WorldCataclysms.Visuals
{
	internal sealed class AuroraVisual : MonoBehaviour
	{
		private static WorldEventType requestedType;

		private static EventPhase requestedPhase;

		private GameObject root;

		private LineRenderer first;

		private LineRenderer second;

		private Material firstMaterial;

		private Material secondMaterial;

		public static void SetState(WorldEventType type, EventPhase phase)
		{
			requestedType = type;
			requestedPhase = phase;
		}

		private void Update()
		{
			//IL_0065: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (requestedType != WorldEventType.MagicalAurora || requestedPhase != EventPhase.Active || !((Object)(object)localPlayer != (Object)null) || ((Character)localPlayer).InInterior() || ((Character)localPlayer).InIntro())
			{
				Clear();
				return;
			}
			if ((Object)(object)root == (Object)null)
			{
				Build();
			}
			if (!((Object)(object)root == (Object)null))
			{
				Vector3 position = ((Component)localPlayer).transform.position;
				Draw(first, position, 0f, new Color(0.1f, 1f, 0.65f, 0.8f));
				Draw(second, position, 9f, new Color(0.55f, 0.2f, 1f, 0.72f));
			}
		}

		private void Build()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			Shader val = Shader.Find("Sprites/Default") ?? Shader.Find("Unlit/Color");
			if (!((Object)(object)val == (Object)null))
			{
				root = new GameObject("WC_Aurora");
				firstMaterial = new Material(val);
				secondMaterial = new Material(val);
				first = MakeLine("AuroraGreen", firstMaterial, 3.8f);
				second = MakeLine("AuroraViolet", secondMaterial, 3f);
			}
		}

		private LineRenderer MakeLine(string name, Material material, float width)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(root.transform, false);
			LineRenderer obj = val.AddComponent<LineRenderer>();
			((Renderer)obj).material = material;
			obj.useWorldSpace = true;
			obj.positionCount = 28;
			float startWidth = (obj.endWidth = width);
			obj.startWidth = startWidth;
			return obj;
		}

		private static void Draw(LineRenderer line, Vector3 center, float phase, Color color)
		{
			//IL_0002: 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_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			Color startColor = (line.endColor = color);
			line.startColor = startColor;
			for (int i = 0; i < line.positionCount; i++)
			{
				float num = ((float)i - (float)(line.positionCount - 1) / 2f) * 5f;
				float num2 = 38f + Mathf.Sin(Time.unscaledTime * 0.5f + (float)i * 0.42f + phase) * 5f;
				float num3 = Mathf.Sin((float)i * 0.23f + phase) * 12f;
				line.SetPosition(i, center + new Vector3(num, num2, num3));
			}
		}

		private void Clear()
		{
			if ((Object)(object)root != (Object)null)
			{
				Object.Destroy((Object)(object)root);
			}
			root = null;
			first = (second = null);
			if ((Object)(object)firstMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)firstMaterial);
			}
			if ((Object)(object)secondMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)secondMaterial);
			}
			firstMaterial = (secondMaterial = null);
		}

		private void OnDestroy()
		{
			Clear();
		}
	}
	internal static class HazardVisual
	{
		private sealed class NativeWaterWaveVisual : MonoBehaviour
		{
			private const int Columns = 17;

			private const int Rows = 9;

			private Mesh mesh;

			private Vector3[] vertices;

			private Vector3 origin;

			private Vector3 direction;

			private float age;

			public void Build(Vector3 at, Vector3 travel)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: 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_0035: 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_0045: 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_005a: Expected O, but got Unknown
				//IL_012a: 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)
				origin = at;
				direction = ((((Vector3)(ref travel)).sqrMagnitude < 0.01f) ? Vector3.forward : ((Vector3)(ref travel)).normalized);
				((Component)this).transform.rotation = Quaternion.LookRotation(direction, Vector3.up);
				mesh = new Mesh
				{
					name = "WC_NativeTsunamiMesh"
				};
				((Component)this).GetComponent<MeshFilter>().sharedMesh = mesh;
				vertices = (Vector3[])(object)new Vector3[153];
				Vector2[] array = (Vector2[])(object)new Vector2[vertices.Length];
				int[] array2 = new int[768];
				int num = 0;
				for (int i = 0; i < 8; i++)
				{
					for (int j = 0; j < 16; j++)
					{
						int num2 = i * 17 + j;
						int num3 = num2 + 1;
						int num4 = num2 + 17;
						int num5 = num4 + 1;
						array2[num++] = num2;
						array2[num++] = num4;
						array2[num++] = num3;
						array2[num++] = num3;
						array2[num++] = num4;
						array2[num++] = num5;
					}
				}
				for (int k = 0; k < 9; k++)
				{
					for (int l = 0; l < 17; l++)
					{
						array[k * 17 + l] = new Vector2((float)l * 0.55f, (float)k * 0.55f);
					}
				}
				mesh.vertices = vertices;
				mesh.uv = array;
				mesh.triangles = array2;
				UpdateMesh(0f);
			}

			private void Update()
			{
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: 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_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
				age += Time.unscaledDeltaTime;
				float num = (((Object)(object)ZoneSystem.instance != (Object)null) ? ZoneSystem.instance.m_waterLevel : origin.y);
				((Component)this).transform.position = origin - direction * 38f + direction * (20f * age);
				((Component)this).transform.position = new Vector3(((Component)this).transform.position.x, num, ((Component)this).transform.position.z);
				UpdateMesh(Mathf.Sin(Mathf.Clamp01(age / 9f) * (float)Math.PI) * 22f);
				if (age > 9f)
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
				}
			}

			private void UpdateMesh(float height)
			{
				//IL_005c: 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)
				int num = 0;
				for (int i = 0; i < 9; i++)
				{
					for (int j = 0; j < 17; j++)
					{
						float num2 = Mathf.Lerp(-42f, 42f, (float)j / 16f);
						float num3 = Mathf.Lerp(-12f, 12f, (float)i / 8f);
						float num4 = Mathf.Exp((0f - num3 * num3) / 35f) * height;
						vertices[num] = new Vector3(num2, num4, num3);
						num++;
					}
				}
				mesh.vertices = vertices;
				mesh.RecalculateNormals();
				mesh.RecalculateBounds();
			}

			private void OnDestroy()
			{
				Live.Remove(((Component)this).gameObject);
				if ((Object)(object)mesh != (Object)null)
				{
					Object.Destroy((Object)(object)mesh);
				}
			}
		}

		private sealed class MeteorVisual : MonoBehaviour
		{
			private static AudioClip impactSound;

			private static GameObject nativeMeteorPrefab;

			private static bool searchedNativePrefab;

			private Material material;

			private Light flash;

			private Vector3 start;

			private Vector3 end;

			private float age;

			private bool impacted;

			public void Build(Vector3 position, int sequence)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: 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_0045: 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_009b: Unknown result type (might be due to invalid IL or missing references)
				end = position;
				Random random = new Random(sequence);
				start = position + new Vector3(-38f + (float)random.NextDouble() * 16f, 105f, 24f + (float)random.NextDouble() * 18f);
				((Component)this).transform.position = start;
				if (!TryNativeEffect())
				{
					BuildFallbackFireball();
				}
				flash = ((Component)this).gameObject.AddComponent<Light>();
				flash.type = (LightType)2;
				flash.color = new Color(1f, 0.2f, 0.025f);
				flash.range = 32f;
				flash.intensity = 4f;
				BuildSound();
			}

			private bool TryNativeEffect()
			{
				//IL_0113: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)ZNetScene.instance == (Object)null)
				{
					return false;
				}
				if (searchedNativePrefab && (Object)(object)nativeMeteorPrefab == (Object)null)
				{
					searchedNativePrefab = false;
				}
				if (!searchedNativePrefab)
				{
					searchedNativePrefab = true;
					foreach (string prefabName in ZNetScene.instance.GetPrefabNames())
					{
						string text = prefabName.ToLowerInvariant();
						if (text.Contains("meteor") && (text.Contains("fx") || text.Contains("vfx")))
						{
							GameObject prefab = ZNetScene.instance.GetPrefab(prefabName);
							if (!((Object)(object)prefab == (Object)null) && !((Object)(object)prefab.GetComponent<ZNetView>() != (Object)null) && !((Object)(object)prefab.GetComponentInChildren<ParticleSystem>(true) == (Object)null))
							{
								nativeMeteorPrefab = prefab;
								Plugin.Log.LogInfo((object)("Meteorito visual nativo seleccionado: " + prefabName));
								break;
							}
						}
					}
				}
				if ((Object)(object)nativeMeteorPrefab == (Object)null)
				{
					return false;
				}
				Object.Instantiate<GameObject>(nativeMeteorPrefab, ((Component)this).transform).transform.localPosition = Vector3.zero;
				return true;
			}

			private void BuildFallbackFireball()
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Expected O, but got Unknown
				//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_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_0083: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e3: 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_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_0113: Unknown result type (might be due to invalid IL or missing references)
				Shader val = Shader.Find("Sprites/Default") ?? Shader.Find("Unlit/Color");
				if ((Object)(object)val != (Object)null)
				{
					material = new Material(val);
					ParticleSystem obj = ((Component)this).gameObject.AddComponent<ParticleSystem>();
					MainModule main = obj.main;
					((MainModule)(ref main)).loop = true;
					((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.45f, 1.1f);
					((MainModule)(ref main)).startSpeed = new MinMaxCurve(1f, 4f);
					((MainModule)(ref main)).startSize = new MinMaxCurve(1.2f, 3.2f);
					((MainModule)(ref main)).startColor = new MinMaxGradient(new Color(1f, 0.08f, 0.01f), new Color(1f, 0.75f, 0.06f));
					((MainModule)(ref main)).maxParticles = 100;
					EmissionModule emission = obj.emission;
					((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(72f);
					ShapeModule shape = obj.shape;
					((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
					((ShapeModule)(ref shape)).radius = 1.5f;
					NoiseModule noise = obj.noise;
					((NoiseModule)(ref noise)).enabled = true;
					((NoiseModule)(ref noise)).strength = MinMaxCurve.op_Implicit(1.2f);
					((NoiseModule)(ref noise)).frequency = 0.65f;
					ParticleSystemRenderer component = ((Component)this).gameObject.GetComponent<ParticleSystemRenderer>();
					((Renderer)component).material = material;
					component.renderMode = (ParticleSystemRenderMode)0;
				}
			}

			private void Update()
			{
				//IL_0036: 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_0044: 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)
				age += Time.unscaledDeltaTime;
				float num = Mathf.Clamp01(age / 1.15f);
				if (!impacted)
				{
					((Component)this).transform.position = Vector3.Lerp(start, end, num * num);
					if (num >= 1f)
					{
						impacted = true;
						if ((Object)(object)flash != (Object)null)
						{
							flash.intensity = 12f;
							flash.range = 55f;
						}
						if ((Object)(object)GameCamera.instance != (Object)null)
						{
							GameCamera.instance.AddShake(end, 150f, 2.8f, false);
						}
					}
				}
				else if ((Object)(object)flash != (Object)null)
				{
					flash.intensity = Mathf.MoveTowards(flash.intensity, 0f, Time.unscaledDeltaTime * 10f);
				}
				if (age > 2.8f)
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
				}
			}

			private void BuildSound()
			{
				if ((Object)(object)impactSound == (Object)null)
				{
					float[] array = new float[48000];
					Random random = new Random(9951);
					float num = 0f;
					for (int i = 0; i < array.Length; i++)
					{
						float num2 = (float)i / 24000f;
						num = num * 0.975f + (float)(random.NextDouble() * 2.0 - 1.0) * 0.025f;
						array[i] = Mathf.Clamp((num * 4f + Mathf.Sin(num2 * 54f) * 0.35f) * Mathf.Exp((0f - num2) * 2.1f), -1f, 1f);
					}
					impactSound = AudioClip.Create("WC_MeteorImpact", array.Length, 1, 24000, false);
					impactSound.SetData(array, 0);
				}
				AudioSource obj = ((Component)this).gameObject.AddComponent<AudioSource>();
				obj.clip = impactSound;
				obj.spatialBlend = 1f;
				obj.minDistance = 18f;
				obj.maxDistance = 350f;
				obj.volume = 1f;
				obj.PlayDelayed(1.05f);
			}

			private void OnDestroy()
			{
				Live.Remove(((Component)this).gameObject);
				if ((Object)(object)material != (Object)null)
				{
					Object.Destroy((Object)(object)material);
				}
			}
		}

		private static readonly List<GameObject> Live = new List<GameObject>();

		public static void Show(WorldEventType type, Vector3 position, Vector3 direction, int sequence)
		{
			//IL_0003: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			switch (type)
			{
			case WorldEventType.Thunderstorm:
				LightningVisual.Show(position, sequence);
				break;
			case WorldEventType.MeteorShower:
				SpawnMeteor(position, sequence);
				break;
			case WorldEventType.Tsunami:
				SpawnNativeWaterWave(position, direction);
				break;
			}
		}

		private static void SpawnMeteor(Vector3 position, int sequence)
		{
			//IL_001d: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && !((Character)localPlayer).InInterior() && !(Vector3.Distance(((Component)localPlayer).transform.position, position) > 400f))
			{
				GameObject val = new GameObject("WC_Meteor");
				Live.Add(val);
				val.AddComponent<MeteorVisual>().Build(position, sequence);
			}
		}

		public static void Clear()
		{
			LightningVisual.Clear();
			GameObject[] array = Live.ToArray();
			foreach (GameObject val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
			Live.Clear();
		}

		private static void SpawnNativeWaterWave(Vector3 position, Vector3 direction)
		{
			//IL_001d: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			//IL_010f: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).InInterior() || Vector3.Distance(((Component)localPlayer).transform.position, position) > 260f)
			{
				return;
			}
			Material val = null;
			float num = float.MaxValue;
			foreach (WaterVolume instance in WaterVolume.Instances)
			{
				if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.m_waterSurface == (Object)null) && !((Object)(object)((Renderer)instance.m_waterSurface).sharedMaterial == (Object)null))
				{
					Vector3 val2 = ((Component)instance).transform.position - position;
					float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						val = ((Renderer)instance.m_waterSurface).sharedMaterial;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"No se encontró material de agua nativo para visualizar la cresta del maremoto.");
				return;
			}
			GameObject val3 = new GameObject("WC_NativeWaterCrest");
			Live.Add(val3);
			val3.AddComponent<MeshFilter>();
			((Renderer)val3.AddComponent<MeshRenderer>()).sharedMaterial = val;
			val3.AddComponent<NativeWaterWaveVisual>().Build(position, direction);
		}
	}
	internal sealed class LightningVisual : MonoBehaviour
	{
		private static readonly List<GameObject> live = new List<GameObject>();

		private static AudioClip thunder;

		private Material material;

		private LineRenderer line;

		private Light flash;

		private float age;

		public static void Show(Vector3 position, int sequence)
		{
			//IL_001d: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0041: 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)
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && !((Character)localPlayer).InInterior() && !(Vector3.Distance(((Component)localPlayer).transform.position, position) > 350f))
			{
				GameObject val = new GameObject("WC_Lightning");
				val.transform.position = position;
				live.Add(val);
				val.AddComponent<LightningVisual>().Build(position, sequence);
			}
		}

		private void Build(Vector3 position, int sequence)
		{
			//IL_0161: 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_0038: Expected O, but got Unknown
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			Random random = new Random(sequence);
			Shader val = Shader.Find("Sprites/Default") ?? Shader.Find("Unlit/Color");
			if ((Object)(object)val != (Object)null)
			{
				material = new Material(val);
				line = ((Component)this).gameObject.AddComponent<LineRenderer>();
				((Renderer)line).material = material;
				line.useWorldSpace = true;
				line.positionCount = 14;
				line.startWidth = 0.22f;
				line.endWidth = 0.08f;
				LineRenderer obj = line;
				LineRenderer obj2 = line;
				Color val2 = default(Color);
				((Color)(ref val2))..ctor(0.7f, 0.85f, 1f);
				obj2.endColor = val2;
				obj.startColor = val2;
				for (int i = 0; i < 14; i++)
				{
					float num = (float)i * 4f;
					float num2 = ((i == 0) ? 0f : ((float)(random.NextDouble() - 0.5) * 6f));
					float num3 = ((i == 0) ? 0f : ((float)(random.NextDouble() - 0.5) * 6f));
					line.SetPosition(i, position + new Vector3(num2, num, num3));
				}
			}
			flash = ((Component)this).gameObject.AddComponent<Light>();
			flash.color = new Color(0.75f, 0.85f, 1f);
			flash.type = (LightType)2;
			flash.range = 35f;
			flash.intensity = 8f;
			if ((Object)(object)thunder == (Object)null)
			{
				float[] array = new float[72000];
				Random random2 = new Random(7241);
				float num4 = 0f;
				for (int j = 0; j < array.Length; j++)
				{
					float num5 = (float)j / 24000f;
					num4 = num4 * 0.94f + (float)(random2.NextDouble() * 2.0 - 1.0) * 0.06f;
					array[j] = Mathf.Clamp((num4 * 3f + Mathf.Sin(num5 * 170f) * 0.08f) * Mathf.Exp((0f - num5) * 1.6f), -1f, 1f);
				}
				thunder = AudioClip.Create("WC_Thunder", array.Length, 1, 24000, false);
				thunder.SetData(array, 0);
			}
			AudioSource obj3 = ((Component)this).gameObject.AddComponent<AudioSource>();
			obj3.clip = thunder;
			obj3.spatialBlend = 1f;
			obj3.minDistance = 15f;
			obj3.maxDistance = 300f;
			obj3.rolloffMode = (AudioRolloffMode)1;
			obj3.volume = 0.8f;
			obj3.PlayDelayed(Mathf.Min(1f, Vector3.Distance(((Component)Player.m_localPlayer).transform.position, position) / 343f));
		}

		private void Update()
		{
			age += Time.unscaledDeltaTime;
			if (age > 0.22f)
			{
				if ((Object)(object)line != (Object)null)
				{
					((Renderer)line).enabled = false;
				}
				if ((Object)(object)flash != (Object)null)
				{
					((Behaviour)flash).enabled = false;
				}
			}
			if (age > 4f)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		private void OnDestroy()
		{
			live.Remove(((Component)this).gameObject);
			if ((Object)(object)material != (Object)null)
			{
				Object.Destroy((Object)(object)material);
			}
		}

		public static void Clear()
		{
			GameObject[] array = live.ToArray();
			foreach (GameObject val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
			live.Clear();
			if ((Object)(object)thunder != (Object)null)
			{
				Object.Destroy((Object)(object)thunder);
			}
			thunder = null;
		}
	}
}
namespace WorldCataclysms.Survival
{
	public sealed class ExposureSample
	{
		public Player Player { get; internal set; }

		public bool Sheltered { get; internal set; }

		public bool Wet { get; internal set; }

		public bool Cold { get; internal set; }

		public bool Freezing { get; internal set; }

		public bool TemperatureEnabled { get; internal set; }

		public bool HydrationEnabled { get; internal set; }

		public bool AirQualityEnabled { get; internal set; }

		public float AirQuality { get; internal set; }

		public float Temperature { get; internal set; }

		public float Hydration { get; internal set; }

		public string Penalty { get; internal set; }

		public string Protection { get; internal set; }

		public string Effect { get; internal set; }

		public EventPhase Phase { get; internal set; }
	}
	public static class SurvivalManager
	{
		private static float nextSample;

		private static float temperature = 55f;

		private static float hydration = 100f;

		private static float air = 100f;

		private static float nextDamage;

		private static float nextSave;

		public static ExposureSample Current { get; private set; }

		public static float MovementMultiplier
		{
			get
			{
				if (Current == null)
				{
					return 1f;
				}
				float num = SurvivalRules.MovementMultiplier(Current.TemperatureEnabled, Current.Temperature, Current.HydrationEnabled, Current.Hydration, Current.AirQualityEnabled, Current.AirQuality);
				WorldEventManager instance = WorldEventManager.Instance;
				if ((Object)(object)instance == (Object)null || instance.Phase != EventPhase.Active || Current.Sheltered)
				{
					return num;
				}
				if (instance.EventType == WorldEventType.Hurricane)
				{
					num *= 0.58f;
				}
				else if (instance.EventType == WorldEventType.Blizzard)
				{
					num *= 0.72f;
				}
				else if (instance.EventType == WorldEventType.ToxicFog)
				{
					num *= 0.88f;
				}
				return num;
			}
		}

		public static event Action<ExposureSample> ExposureUpdated;

		internal static void Reset()
		{
			Current = null;
			nextSample = 0f;
			temperature = PlayerPrefs.GetFloat("WC_Temperature", 55f);
			hydration = PlayerPrefs.GetFloat("WC_Hydration", 100f);
			air = PlayerPrefs.GetFloat("WC_Air", 100f);
		}

		internal static void Rehydrate(float amount)
		{
			if (amount > 0f)
			{
				hydration = Mathf.Clamp(hydration + amount, 0f, 100f);
			}
		}

		internal static void Tick(WorldEventManager manager)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)EnvMan.instance == (Object)null)
			{
				Current = null;
			}
			else if (!(Time.realtimeSinceStartup < nextSample))
			{
				nextSample = Time.realtimeSinceStartup + 1f;
				bool flag = manager.Phase == EventPhase.Active;
				bool flag2 = localPlayer.InShelter() || ((Character)localPlayer).InInterior() || StrikeDamage.HasRoof(localPlayer);
				bool flag3 = ((!flag || manager.EventType != WorldEventType.Blizzard) ? flag2 : (((Character)localPlayer).InInterior() || (flag2 && StrikeDamage.IsNearFire(localPlayer))));
				if (manager.TemperatureEnabled)
				{
					float num = (flag3 ? 55f : ((flag && manager.EventType == WorldEventType.Blizzard) ? 0f : (EnvMan.IsFreezing() ? 10f : (EnvMan.IsCold() ? 30f : ((flag && manager.EventType == WorldEventType.MeteorShower) ? 95f : 55f)))));
					temperature = Mathf.MoveTowards(temperature, num, flag3 ? 1.2f : 0.45f);
				}
				else
				{
					temperature = 55f;
				}
				if (manager.HydrationEnabled)
				{
					float num2 = SurvivalRules.HydrationDelta(enabled: true, flag, manager.EventType == WorldEventType.MeteorShower, flag3);
					hydration = Mathf.Clamp(hydration + num2, 0f, 100f);
				}
				else
				{
					hydration = 100f;
				}
				if (manager.AirQualityEnabled)
				{
					float num3 = ((flag && manager.EventType == WorldEventType.ToxicFog && !flag3) ? 15f : 100f);
					air = Mathf.MoveTowards(air, num3, (num3 < air) ? 2.2f : 1.5f);
				}
				else
				{
					air = 100f;
				}
				string penalty = SurvivalRules.Penalty(manager.TemperatureEnabled, temperature, manager.HydrationEnabled, hydration, manager.AirQualityEnabled, air);
				string effect = Effect(manager, flag3);
				Current = new ExposureSample
				{
					Player = localPlayer,
					Sheltered = flag3,
					Wet = (!flag3 && EnvMan.IsWet()),
					Cold = (!flag3 && EnvMan.IsCold()),
					Freezing = (!flag3 && EnvMan.IsFreezing()),
					TemperatureEnabled = manager.TemperatureEnabled,
					HydrationEnabled = manager.HydrationEnabled,
					AirQualityEnabled = manager.AirQualityEnabled,
					AirQuality = air / 100f,
					Temperature = temperature,
					Hydration = hydration,
					Penalty = penalty,
					Phase = manager.Phase,
					Protection = (flag3 ? "PROTEGIDO" : (flag ? "EXPUESTO" : "EN ALERTA")),
					Effect = effect
				};
				if (SurvivalRules.IsDangerous(manager.TemperatureEnabled, temperature, manager.HydrationEnabled, hydration, manager.AirQualityEnabled, air) && Time.realtimeSinceStartup >= nextDamage)
				{
					nextDamage = Time.realtimeSinceStartup + 5f;
					((Character)localPlayer).UseHealth(1f);
				}
				if (Time.realtimeSinceStartup >= nextSave)
				{
					nextSave = Time.realtimeSinceStartup + 30f;
					PlayerPrefs.SetFloat("WC_Temperature", temperature);
					PlayerPrefs.SetFloat("WC_Hydration", hydration);
					PlayerPrefs.SetFloat("WC_Air", air);
					PlayerPrefs.Save();
				}
				HookDispatcher.Invoke(SurvivalManager.ExposureUpdated, Current);
			}
		}

		private static string Effect(WorldEventManager manager, bool sheltered)
		{
			if (manager.Phase != EventPhase.Active)
			{
				return "Prepárate y busca refugio";
			}
			if (sheltered)
			{
				return "El techo bloquea la exposición";
			}
			return manager.EventType switch
			{
				WorldEventType.Thunderstorm => "Rayos cercanos · daño eléctrico", 
				WorldEventType.ToxicFog => "Veneno continuo · aire irrespirable", 
				WorldEventType.MagicalAurora => "Velocidad +25% · daño causado -50%", 
				WorldEventType.MeteorShower => "Calor extremo · impactos incendiarios", 
				WorldEventType.Tsunami => "Sube a terreno alto · evita el agua", 
				WorldEventType.Hurricane => "Movimiento -42% · viento y golpes", 
				WorldEventType.Blizzard => "Movimiento -28% · frío implacable", 
				_ => "Exposición peligrosa", 
			};
		}
	}
	[HarmonyPatch(typeof(Player), "ConsumeItem")]
	internal static class HydrationConsumePatch
	{
		private static void Postfix(bool __result, ItemData item)
		{
			if (__result && item != null && !((Object)(object)WorldEventManager.Instance == (Object)null) && WorldEventManager.Instance.HydrationEnabled)
			{
				SurvivalManager.Rehydrate(15f);
			}
		}
	}
	internal static class SurvivalRules
	{
		public static float MovementMultiplier(bool temperatureEnabled, float temperature, bool hydrationEnabled, float hydration, bool airEnabled, float air)
		{
			bool num = (hydrationEnabled && hydration < 15f) || (temperatureEnabled && (temperature < 15f || temperature > 90f)) || (airEnabled && air < 0.2f);
			bool flag = (hydrationEnabled && hydration < 35f) || (temperatureEnabled && (temperature < 30f || temperature > 80f)) || (airEnabled && air < 0.45f);
			if (!num)
			{
				if (!flag)
				{
					return 1f;
				}
				return 0.9f;
			}
			return 0.75f;
		}

		public static float HydrationDelta(bool enabled, bool active, bool meteorShower, bool sheltered)
		{
			if (enabled)
			{
				if (!(active && meteorShower))
				{
					if (!active || sheltered)
					{
						if (!sheltered)
						{
							return 0f;
						}
						return 0.05f;
					}
					return -0.035f;
				}
				return -0.075f;
			}
			return 0f;
		}

		public static bool IsDangerous(bool temperatureEnabled, float temperature, bool hydrationEnabled, float hydration, bool airEnabled, float air)
		{
			if ((!temperatureEnabled || (!(temperature < 8f) && !(temperature > 92f))) && (!hydrationEnabled || !(hydration < 5f)))
			{
				if (airEnabled)
				{
					return air < 8f;
				}
				return false;
			}
			return true;
		}

		public static string Penalty(bool temperatureEnabled, float temperature, bool hydrationEnabled, float hydration, bool airEnabled, float air)
		{
			if (!temperatureEnabled || !(temperature < 15f))
			{
				if (!temperatureEnabled || !(temperature > 85f))
				{
					if (!hydrationEnabled || !(hydration < 15f))
					{
						if (!airEnabled || !(air < 20f))
						{
							if ((!temperatureEnabled || !(temperature < 30f)) && (!hydrationEnabled || !(hydration < 35f)) && (!airEnabled || !(air < 45f)))
							{
								return "Ninguna";
							}
							return "Exposición moderada";
						}
						return "Aire tóxico";
					}
					return "Deshidratación";
				}
				return "Sobrecalentamiento";
			}
			return "Hipotermia";
		}
	}
}
namespace WorldCataclysms.Seasons
{
	public static class SeasonalityAdapter
	{
		public static WorldSeason GetCurrentSeason()
		{
			if (!ModConfig.EnableSeasonalityIntegration.Value || (Object)(object)ZoneSystem.instance == (Object)null)
			{
				return WorldSeason.Unknown;
			}
			int num = 0;
			WorldSeason result = WorldSeason.Unknown;
			if (ZoneSystem.instance.GetGlobalKey(ModConfig.SpringKey.Value))
			{
				num++;
				result = WorldSeason.Spring;
			}
			if (ZoneSystem.instance.GetGlobalKey(ModConfig.SummerKey.Value))
			{
				num++;
				result = WorldSeason.Summer;
			}
			if (ZoneSystem.instance.GetGlobalKey(ModConfig.FallKey.Value))
			{
				num++;
				result = WorldSeason.Fall;
			}
			if (ZoneSystem.instance.GetGlobalKey(ModConfig.WinterKey.Value))
			{
				num++;
				result = WorldSeason.Winter;
			}
			if (num != 1)
			{
				return WorldSeason.Unknown;
			}
			return result;
		}
	}
	public sealed class SeasonManager : MonoBehaviour
	{
		private float _refreshTimer;

		public static SeasonManager Instance { get; private set; }

		public WorldSeason CurrentSeason { get; private set; }

		private void Awake()
		{
			Instance = this;
		}

		private void Update()
		{
			_refreshTimer += Time.deltaTime;
			if (_refreshTimer < 5f)
			{
				return;
			}
			_refreshTimer = 0f;
			WorldSeason currentSeason = SeasonalityAdapter.GetCurrentSeason();
			if (currentSeason != CurrentSeason)
			{
				CurrentSeason = currentSeason;
				if ((Object)(object)Plugin.Instance != (Object)null)
				{
					Plugin.Log.LogInfo((object)$"Estación detectada: {CurrentSeason}");
				}
			}
		}
	}
	public enum WorldSeason
	{
		Unknown,
		Spring,
		Summer,
		Fall,
		Winter
	}
}
namespace WorldCataclysms.Migration
{
	public static class MigrationManager
	{
		public static event Action<WorldEventType, EventPhase> EventChanged;

		public static event Action<Vector3, float> MigrationRequested;

		internal static void OnPhase(WorldEventType type, EventPhase phase)
		{
			HookDispatcher.Invoke(MigrationManager.EventChanged, type, phase);
		}

		internal static void OnStrike(Vector3 position, float radius, bool enabled)
		{
			//IL_0009: 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_003a: 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)
			if (!enabled)
			{
				return;
			}
			HookDispatcher.Invoke(MigrationManager.MigrationRequested, position, radius);
			BaseAI[] array = BaseAI.GetAllInstances().ToArray();
			foreach (BaseAI val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Vector3 val2 = ((Component)val).transform.position - position;
				if (!(((Vector3)(ref val2)).sqrMagnitude > radius * radius))
				{
					ZNetView component = ((Component)val).GetComponent<ZNetView>();
					Character component2 = ((Component)val).GetComponent<Character>();
					if ((Object)(object)component != (Object)null && component.IsValid() && component.IsOwner() && (Object)(object)component2 != (Object)null && !component2.IsBoss() && !component2.IsTamed() && component2.GetMaxHealthBase() >= 80f)
					{
						val.Alert();
					}
				}
			}
		}
	}
}
namespace WorldCataclysms.Events
{
	public sealed class BlizzardEvent : PulsedWorldEvent
	{
		public override WorldEventType Type => WorldEventType.Blizzard;

		public override bool IsAllowedInSeason(WorldSeason season)
		{
			if (season != WorldSeason.Unknown)
			{
				return season == WorldSeason.Winter;
			}
			return true;
		}

		protected override void EmitPulse(WorldEventManager manager)
		{
			//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)
			manager.BroadcastHazard(Type, Vector3.zero, Vector3.zero, global: true);
		}
	}
	internal static class EventTargeting
	{
		public static bool TryRandomPlayer(out Vector3 position)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			position = Vector3.zero;
			if ((Object)(object)ZNet.instance == (Object)null)
			{
				return false;
			}
			List<ZDO> allCharacterZDOS = ZNet.instance.GetAllCharacterZDOS();
			if (allCharacterZDOS.Count == 0)
			{
				return false;
			}
			position = allCharacterZDOS[Random.Range(0, allCharacterZDOS.Count)].GetPosition();
			return !Character.InInterior(position);
		}

		public static bool TryRandomCoastalPlayer(out Vector3 position)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_0084: 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)
			position = Vector3.zero;
			if ((Object)(object)ZNet.instance == (Object)null || (Object)(object)ZoneSystem.instance == (Object)null)
			{
				return false;
			}
			List<ZDO> allCharacterZDOS = ZNet.instance.GetAllCharacterZDOS();
			if (allCharacterZDOS.Count == 0)
			{
				return false;
			}
			int num = Random.Range(0, allCharacterZDOS.Count);
			for (int i = 0; i < allCharacterZDOS.Count; i++)
			{
				Vector3 position2 = allCharacterZDOS[(num + i) % allCharacterZDOS.Count].GetPosition();
				if (!Character.InInterior(position2) && position2.y <= ZoneSystem.instance.m_waterLevel + 10f)
				{
					position = position2;
					return true;
				}
			}
			return false;
		}

		public static bool HasCoastalPlayer()
		{
			//IL_0035: 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_003b: 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)
			if ((Object)(object)ZNet.instance == (Object)null || (Object)(object)ZoneSystem.instance == (Object)null)
			{
				return false;
			}
			foreach (ZDO allCharacterZDO in ZNet.instance.GetAllCharacterZDOS())
			{
				Vector3 position = allCharacterZDO.GetPosition();
				if (!Character.InInterior(position) && position.y <= ZoneSystem.instance.m_waterLevel + 10f)
				{
					return true;
				}
			}
			return false;
		}

		public static Vector3 GroundTarget(Vector3 center, float radius)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_0054: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = Random.insideUnitCircle * radius;
			Vector3 val2 = center + new Vector3(val.x, 0f, val.y);
			if (WorldGenerator.instance != null)
			{
				val2.y = WorldGenerator.instance.GetHeight(val2);
			}
			float y = default(float);
			if ((Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGroundHeight(val2, ref y))
			{
				val2.y = y;
			}
			if ((Object)(object)ZoneSystem.instance != (Object)null)
			{
				val2.y = Mathf.Max(val2.y, ZoneSystem.instance.m_waterLevel);
			}
			return val2;
		}

		public static Vector3 HorizontalDirection()
		{
			//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_0008: 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_0022: 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_001c: 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)
			Vector2 insideUnitCircle = Random.insideUnitCircle;
			Vector2 val = ((Vector2)(ref insideUnitCircle)).normalized;
			if (((Vector2)(ref val)).sqrMagnitude < 0.1f)
			{
				val = Vector2.right;
			}
			return new Vector3(val.x, 0f, val.y);
		}
	}
	public sealed class HurricaneEvent : PulsedWorldEvent
	{
		public override WorldEventType Type => WorldEventType.Hurricane;

		public override bool IsAllowedInSeason(WorldSeason season)
		{
			if (season != WorldSeason.Unknown && season != WorldSeason.Summer)
			{
				return season == WorldSeason.Fall;
			}
			return true;
		}

		protected override void EmitPulse(WorldEventManager manager)
		{
			//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)
			manager.BroadcastHazard(Type, Vector3.zero, EventTargeting.HorizontalDirection(), global: true);
		}
	}
	public sealed class MagicalAuroraEvent : WorldEventBase
	{
		public override WorldEventType Type => WorldEventType.MagicalAurora;

		public override bool IsAllowedInSeason(WorldSeason season)
		{
			if (season != WorldSeason.Unknown && season != WorldSeason.Winter)
			{
				return season == WorldSeason.Fall;
			}
			return true;
		}
	}
	public sealed class MeteorShowerEvent : PulsedWorldEvent
	{
		public override WorldEventType Type => WorldEventType.MeteorShower;

		public override bool IsAllowedInSeason(WorldSeason season)
		{
			return true;
		}

		protected override void EmitPulse(WorldEventManager manager)
		{
			//IL_000a: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (EventTargeting.TryRandomPlayer(out var position))
			{
				Vector3 position2 = EventTargeting.GroundTarget(position, ModConfig.Hazards[Type].TargetRadius.Value);
				manager.BroadcastHazard(Type, position2, Vector3.zero, global: false);
			}
		}
	}
	public abstract class PulsedWorldEvent : WorldEventBase
	{
		private double nextPulse;

		protected virtual float InitialDelay => ModConfig.Hazards[Type].Interval.Value;

		public override void BeginServer(double now)
		{
			nextPulse = now + (double)InitialDelay;
		}

		public override void TickServer(double now, WorldEventManager manager)
		{
			if (!(now < nextPulse))
			{
				nextPulse = now + (double)ModConfig.Hazards[Type].Interval.Value;
				EmitPulse(manager);
			}
		}

		protected abstract void EmitPulse(WorldEventManager manager);
	}
	public sealed class ThunderstormEvent : WorldEventBase
	{
		private double nextStrike;

		public override WorldEventType Type => WorldEventType.Thunderstorm;

		public override float Weight => ModConfig.Events[Type].Weight.Value;

		public override float DurationSeconds => ModConfig.Events[Type].Duration.Value;

		public override bool IsAllowedInSeason(WorldSeason season)
		{
			return true;
		}

		public override void BeginServer(double now)
		{
			nextStrike = now + (double)ModConfig.Hazards[Type].Interval.Value;
		}

		public override void TickServer(double now, WorldEventManager manager)
		{
			//IL_0048: 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_0059: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			if (!(now < nextStrike))
			{
				nextStrike = now + (double)ModConfig.Hazards[Type].Interval.Value;
				if (EventTargeting.TryRandomPlayer(out var position))
				{
					HazardSettings hazardSettings = ModConfig.Hazards[Type];
					Vector3 position2 = EventTargeting.GroundTarget(position, hazardSettings.TargetRadius.Value);
					manager.BroadcastHazard(Type, position2, Vector3.zero, global: false);
				}
			}
		}
	}
	public sealed class ToxicFogEvent : PulsedWorldEvent
	{
		public override WorldEventType Type => WorldEventType.ToxicFog;

		public override bool IsAllowedInSeason(WorldSeason season)
		{
			if (season != WorldSeason.Unknown && season != WorldSeason.Spring && season != WorldSeason.Summer)
			{
				return season == WorldSeason.Fall;
			}
			return true;
		}

		protected override void EmitPulse(WorldEventManager manager)
		{
			//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)
			manager.BroadcastHazard(Type, Vector3.zero, Vector3.zero, global: true);
		}
	}
	public sealed class TsunamiEvent : PulsedWorldEvent
	{
		public override WorldEventType Type => WorldEventType.Tsunami;

		protected override float InitialDelay => 4f;

		public override bool IsAllowedInSeason(WorldSeason season)
		{
			return season != WorldSeason.Winter;
		}

		protected override void EmitPulse(WorldEventManager manager)
		{
			//IL_0011: 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)
			if (EventTargeting.TryRandomCoastalPlayer(out var position))
			{
				manager.BroadcastHazard(Type, position, EventTargeting.HorizontalDirection(), global: false);
			}
		}
	}
	public abstract class WorldEventBase
	{
		public abstract WorldEventType Type { get; }

		public virtual float Weight => ModConfig.Events[Type].Weight.Value;

		public virtual float DurationSeconds => ModConfig.Events[Type].Duration.Value;

		public virtual bool IsAllowedInSeason(WorldSeason season)
		{
			return true;
		}

		public virtual void BeginServer(double now)
		{
		}

		public virtual void TickServer(double now, WorldEventManager manager)
		{
		}
	}
	public enum WorldEventType
	{
		Thunderstorm,
		ToxicFog,
		MagicalAurora,
		MeteorShower,
		Tsunami,
		Hurricane,
		Blizzard
	}
}
namespace WorldCataclysms.Core
{
	internal sealed class AdminCommand : ConsoleCommand
	{
		public override string Name => "wc";

		public override string Help => "wc status | wc events | wc start <evento> | wc stop | wc environments | wc exposure";

		public override void Run(string[] args)
		{
			if (args.Length == 1 && args[0].ToLowerInvariant() == "environments")
			{
				if ((Object)(object)EnvMan.instance == (Object)null)
				{
					WorldEventManager.Print("Carga un mundo primero.");
					return;
				}
				{
					foreach (EnvSetup environment in EnvMan.instance.m_environments)
					{
						WorldEventManager.Print(environment.m_name);
					}
					return;
				}
			}
			if (args.Length == 1 && args[0].ToLowerInvariant() == "exposure")
			{
				ExposureSample current = SurvivalManager.Current;
				WorldEventManager.Print((current == null) ? "Sin jugador local." : $"Refugio={current.Sheltered}, lluvia={current.Wet}, temperatura={current.Temperature:F0}, hidratación={current.Hydration:F0}, aire={current.AirQuality * 100f:F0}%, penalización={current.Penalty}; fase={current.Phase}.");
				return;
			}
			if (args.Length == 1 && args[0].ToLowerInvariant() == "events")
			{
				foreach (WorldEventType value in Enum.GetValues(typeof(WorldEventType)))
				{
					EventSettings eventSettings = ModConfig.Events[value];
					WorldEventManager.Print($"{value}: enabled={eventSettings.Enabled.Value}, ambiente={ModConfig.Hazards[value].Environment.Value}");
				}
				return;
			}
			if ((Object)(object)WorldEventManager.Instance == (Object)null)
			{
				WorldEventManager.Print("WorldCataclysms aún no está listo.");
			}
			else
			{
				WorldEventManager.Instance.RunCommand(args);
			}
		}
	}
	internal sealed class CataclysmEnvironmentRegistry : MonoBehaviour
	{
		private EnvMan registeredFor;

		internal static string Name(WorldEventType type)
		{
			return "WC_" + type;
		}

		private void Update()
		{
			if (!((Object)(object)EnvMan.instance == (Object)null) && !((Object)(object)registeredFor == (Object)(object)EnvMan.instance))
			{
				registeredFor = EnvMan.instance;
				Register(WorldEventType.Thunderstorm, new string[2] { "ThunderStorm", "Rain" }, TuneThunder);
				Register(WorldEventType.ToxicFog, new string[3] { "Misty", "SwampRain", "Rain" }, TuneToxic);
				Register(WorldEventType.MagicalAurora, new string[2] { "Twilight_Clear", "Clear" }, TuneAurora);
				Register(WorldEventType.MeteorShower, new string[4] { "Ashlands_RainCinder", "Ashlands_CinderRain", "Ashlands_Misty", "Clear" }, TuneMeteor);
				Register(WorldEventType.Tsunami, new string[2] { "ThunderStorm", "Rain" }, TuneTsunami);
				Register(WorldEventType.Hurricane, new string[2] { "ThunderStorm", "Rain" }, TuneHurricane);
				Register(WorldEventType.Blizzard, new string[3] { "SnowStorm", "DeepNorth_SnowStorm", "Misty" }, TuneBlizzard);
			}
		}

		private static void Register(WorldEventType type, IEnumerable<string> bases, Action<EnvSetup> tune)
		{
			string name = Name(type);
			if (EnvMan.instance.m_environments.Any((EnvSetup e) => e != null && e.m_name == name))
			{
				return;
			}
			EnvSetup val = bases.Select((string n) => ((IEnumerable<EnvSetup>)EnvMan.instance.m_environments).FirstOrDefault((Func<EnvSetup, bool>)((EnvSetup e) => e != null && e.m_name == n))).FirstOrDefault<EnvSetup>((Func<EnvSetup, bool>)((EnvSetup e) => e != null)) ?? ((IEnumerable<EnvSetup>)EnvMan.instance.m_environments).FirstOrDefault((Func<EnvSetup, bool>)((EnvSetup e) => e != null));
			if (type == WorldEventType.MagicalAurora)
			{
				EnvSetup val2 = (from e in EnvMan.instance.m_environments
					where e != null
					orderby Mathf.Max(e.m_auroraIntensityNight, e.m_auroraIntensityEvening) descending
					select e).FirstOrDefault();
				if (val2 != null && Mathf.Max(val2.m_auroraIntensityNight, val2.m_auroraIntensityEvening) > 0f)
				{
					val = val2;
				}
			}
			if (val != null)
			{
				EnvSetup val3 = val.Clone();
				val3.m_name = name;
				val3.m_default = false;
				tune(val3);
				EnvMan.instance.AppendEnvironment(val3);
				Plugin.Log.LogInfo((object)("Ambiente " + name + " creado desde " + val.m_name + "."));
			}
		}

		private static void Fog(EnvSetup e, Color color, float density)
		{
			//IL_0004: 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_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_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_0014: 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_001c: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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)
			//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_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_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_0048: 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)
			e.m_fogColorDay = (e.m_fogColorMorning = (e.m_fogColorEvening = (e.m_fogColorNight = color)));
			e.m_fogColorSunDay = (e.m_fogColorSunMorning = (e.m_fogColorSunEvening = (e.m_fogColorSunNight = color * 1.12f)));
			e.m_fogDensityDay = (e.m_fogDensityMorning = (e.m_fogDensityEvening = (e.m_fogDensityNight = density)));
		}

		private static void TuneThunder(EnvSetup e)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Fog(e, new Color(0.105f, 0.125f, 0.18f), 0.045f);
			e.m_alwaysDark = true;
			e.m_isWet = true;
			e.m_windMin = 0.72f;
			e.m_windMax = 1f;
			e.m_lightIntensityDay = 0.35f;
			e.m_lightIntensityNight = 0.18f;
			e.m_cloudOpacityDay = (e.m_cloudOpacityNight = 1f);
			e.m_ambientVol = Mathf.Max(e.m_ambientVol, 0.9f);
			e.m_rainCloudAlpha = 1f;
		}

		private static void TuneToxic(EnvSetup e)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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)
			Fog(e, new Color(0.16f, 0.29f, 0.105f), 0.095f);
			e.m_alwaysDark = true;
			e.m_isWet = true;
			e.m_windMin = 0.05f;
			e.m_windMax = 0.18f;
			e.m_ambColorDay = new Color(0.2f, 0.34f, 0.14f);
			e.m_ambColorNight = new Color(0.08f, 0.18f, 0.06f);
			e.m_sunColorDay = (e.m_sunColorEvening = new Color(0.42f, 0.57f, 0.18f));
			e.m_lightIntensityDay = 0.38f;
			e.m_lightIntensityNight = 0.14f;
			e.m_cloudOpacityDay = (e.m_cloudOpacityNight = 0.95f);
		}

		private static void TuneMeteor(EnvSetup e)
		{
			//IL_0010: 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)
			//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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			Fog(e, new Color(0.34f, 0.15f, 0.045f), 0.038f);
			e.m_alwaysDark = true;
			e.m_windMin = 0.45f;
			e.m_windMax = 0.85f;
			e.m_ambColorDay = new Color(0.5f, 0.2f, 0.065f);
			e.m_ambColorNight = new Color(0.2f, 0.045f, 0.02f);
			e.m_sunColorDay = (e.m_sunColorEvening = new Color(1f, 0.42f, 0.08f));
			e.m_lightIntensityDay = 0.7f;
			e.m_lightIntensityNight = 0.32f;
			e.m_cloudOpacityDay = (e.m_cloudOpacityNight = 0.88f);
		}

		private static void TuneTsunami(EnvSetup e)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			TuneThunder(e);
			Fog(e, new Color(0.075f, 0.12f, 0.16f), 0.052f);
			e.m_windMin = 0.85f;
			e.m_windMax = 1f;
		}

		private static void TuneHurricane(EnvSetup e)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			TuneThunder(e);
			Fog(e, new Color(0.09f, 0.105f, 0.115f), 0.068f);
			e.m_windMin = 0.96f;
			e.m_windMax = 1f;
			e.m_lightIntensityDay = 0.22f;
			e.m_lightIntensityNight = 0.1f;
		}

		private static void TuneBlizzard(EnvSetup e)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Fog(e, new Color(0.72f, 0.79f, 0.84f), 0.12f);
			e.m_alwaysDark = false;
			e.m_isCold = true;
			e.m_isFreezing = true;
			e.m_isWet = true;
			e.m_windMin = 0.92f;
			e.m_windMax = 1f;
			e.m_snowBuildup = 1f;
			e.m_lightIntensityDay = 0.48f;
			e.m_lightIntensityNight = 0.25f;
			e.m_cloudOpacityDay = (e.m_cloudOpacityNight = 1f);
		}

		private static void TuneAurora(EnvSetup e)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Fog(e, new Color(0.025f, 0.065f, 0.105f), 0.012f);
			e.m_alwaysDark = true;
			e.m_windMin = 0.05f;
			e.m_windMax = 0.22f;
			e.m_cloudOpacityDay = (e.m_cloudOpacityNight = 0.08f);
			e.m_auroraIntensityDay = (e.m_auroraIntensityMorning = (e.m_auroraIntensityEvening = (e.m_auroraIntensityNight = 1f)));
			e.m_lightIntensityDay = 0.32f;
			e.m_lightIntensityNight = 0.28f;
		}
	}
	internal static class CompleteRules
	{
		public static bool Active(WorldEventType type)
		{
			if ((Object)(object)WorldEventManager.Instance != (Object)null && WorldEventManager.Instance.Phase == EventPhase.Active)
			{
				return WorldEventManager.Instance.EventType == type;
			}
			return false;
		}
	}
	internal static class AuroraRetaliation
	{
		private static readonly Dictionary<Character, float> Enraged = new Dictionary<Character, float>();

		public static void Mark(Character creature)
		{
			if ((Object)(object)creature != (Object)null && !creature.IsBoss())
			{
				Enraged[creature] = Time.realtimeSinceStartup + 30f;
			}
		}

		public static void Clear()
		{
			Enraged.Clear();
		}

		public static bool IsEnraged(Character creature)
		{
			if (!CompleteRules.Active(WorldEventType.MagicalAurora) || (Object)(object)creature == (Object)null)
			{
				return false;
			}
			if (Enraged.TryGetValue(creature, out var value) && Time.realtimeSinceStartup < value)
			{
				return true;
			}
			Enraged.Remove(creature);
			return false;
		}
	}
	[HarmonyPatch(typeof(Character), "Damage")]
	internal static class EventDamagePatch
	{
		private static void Prefix(Character __instance, HitData hit)
		{
			if (hit != null && CompleteRules.Active(WorldEventType.MagicalAurora))
			{
				Character attacker = hit.GetAttacker();
				if (attacker is Player && !(__instance is Player) && !__instance.IsBoss())
				{
					hit.ApplyModifier(0.5f);
					AuroraRetaliation.Mark(__instance);
				}
				else if (__instance is Player && AuroraRetaliation.IsEnraged(attacker))
				{
					hit.ApplyModifier(2f);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Player), "GetComfortLevel")]
	internal static class AuroraComfortPatch
	{
		private static void Postfix(ref int __result)
		{
			if (CompleteRules.Active(WorldEventType.MagicalAurora))
			{
				__result = Mathf.Max(__result, 10);
			}
		}
	}
	[HarmonyPatch(typeof(Player), "GetRunSpeedFactor")]
	internal static class AuroraRunPatch
	{
		private static void Postfix(Character __instance, ref float __result)
		{
			if (__instance is Player)
			{
				__result *= SurvivalManager.MovementMultiplier * (CompleteRules.Active(WorldEventType.MagicalAurora) ? 1.25f : 1f);
			}
		}
	}
	[HarmonyPatch(typeof(Player), "GetJogSpeedFactor")]
	internal static class AuroraJogPatch
	{
		private static void Postfix(Character __instance, ref float __result)
		{
			if (__instance is Player)
			{
				__result *= SurvivalManager.MovementMultiplier * (CompleteRules.Active(WorldEventType.MagicalAurora) ? 1.25f : 1f);
			}
		}
	}
	[HarmonyPatch(typeof(BaseAI), "IsEnemy", new Type[] { typeof(Character) })]
	[HarmonyPriority(0)]
	internal static class AuroraPacifismPatch
	{
		private static void Postfix(BaseAI __instance, Character other, ref bool __result)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				Character component = ((Component)__instance).GetComponent<Character>();
				if (CreatureResponseController.IsFrightened(component))
				{
					__result = false;
				}
				else if (CompleteRules.Active(WorldEventType.MagicalAurora) && !((Object)(object)component == (Object)null) && !component.IsBoss() && !AuroraRetaliation.IsEnraged(component))
				{
					__result = false;
				}
			}
		}
	}
	[HarmonyPatch(typeof(BaseAI), "IsEnemy", new Type[]
	{
		typeof(Character),
		typeof(Character)
	})]
	[HarmonyPriority(0)]
	internal static class AuroraStaticPacifismPatch
	{
		private static void Postfix(Character a, Character b, ref bool __result)
		{
			if (!((Object)(object)a == (Object)null) && !((Object)(object)b == (Object)null))
			{
				if (CreatureResponseController.IsFrightened(a))
				{
					__result = false;
				}
				else if (CompleteRules.Active(WorldEventType.MagicalAurora) && !((Object)(object)a.GetBaseAI() == (Object)null) && !a.IsBoss() && !AuroraRetaliation.IsEnraged(a))
				{
					__result = false;
				}
			}
		}
	}
	internal sealed class CreatureResponseController : MonoBehaviour
	{
		private static readonly MethodInfo MoveToMethod = AccessTools.Method(typeof(BaseAI), "MoveTo", (Type[])null, (Type[])null);

		private static readonly MethodInfo SetAlertedMethod = AccessTools.Method(typeof(BaseAI), "SetAlerted", (Type[])null, (Type[])null);

		private static readonly FieldInfo CreatureTargetField = AccessTools.Field(typeof(MonsterAI), "m_targetCreature");

		private static readonly FieldInfo StaticTargetField = AccessTools.Field(typeof(MonsterAI), "m_targetStatic");

		private readonly Dictionary<BaseAI, Vector3> destinations = new Dictionary<BaseAI, Vector3>();

		private readonly Dictionary<Tameable, float> nextFeed = new Dictionary<Tameable, float>();

		private static readonly Dictionary<Character, float> Frightened = new Dictionary<Character, float>();

		private float nextUpdate;

		private int responseCursor;

		private void Update()
		{
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: 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)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			if (Time.realtimeSinceStartup < nextUpdate)
			{
				return;
			}
			nextUpdate = Time.realtimeSinceStartup + 0.75f;
			WorldEventManager instance = WorldEventManager.Instance;
			if ((Object)(object)instance == (Object)null || instance.Phase != EventPhase.Active || !instance.MigrationEnabled)
			{
				destinations.Clear();
				Frightened.Clear();
				responseCursor = 0;
				AuroraRetaliation.Clear();
				return;
			}
			if (instance.EventType != WorldEventType.MagicalAurora)
			{
				AuroraRetaliation.Clear();
			}
			BaseAI[] array = BaseAI.GetAllInstances().ToArray();
			if (array.Length == 0)
			{
				return;
			}
			int num = Mathf.Min(64, array.Length);
			for (int i = 0; i < num; i++)
			{
				BaseAI val = array[(responseCursor + i) % array.Length];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Character component = ((Component)val).GetComponent<Character>();
				ZNetView component2 = ((Component)val).GetComponent<ZNetView>();
				if ((Object)(object)component == (Object)null || component.IsBoss() || (Object)(object)component2 == (Object)null || !component2.IsValid() || !component2.IsOwner())
				{
					continue;
				}
				if (instance.EventType == WorldEventType.MagicalAurora)
				{
					if (AuroraRetaliation.IsEnraged(component))
					{
						val.Alert();
						continue;
					}
					SetAlertedMethod.Invoke(val, new object[1] { false });
					MonsterAI val2 = (MonsterAI)(object)((val is MonsterAI) ? val : null);
					if ((Object)(object)val2 != (Object)null)
					{
						ClearTargets(val2);
					}
					ApproachForTaming(val, component);
				}
				else
				{
					if ((component.IsTamed() && IsEnclosed(((Component)component).transform.position)) || val.m_serpentMovement)
					{
						continue;
					}
					MonsterAI val3 = (MonsterAI)(object)((val is MonsterAI) ? val : null);
					if (val3 != null && val3.m_avoidLand)
					{
						continue;
					}
					Collider componentInChildren = ((Component)component).GetComponentInChildren<Collider>();
					float num2;
					if (!((Object)(object)componentInChildren != (Object)null))
					{
						num2 = 2f;
					}
					else
					{
						Bounds bounds = componentInChildren.bounds;
						Vector3 size = ((Bounds)(ref bounds)).size;
						num2 = ((Vector3)(ref size)).magnitude;
					}
					float num3 = num2;
					if (!component.IsTamed() && (num3 >= 3.2f || component.GetMaxHealthBase() >= 80f))
					{
						Frightened.Remove(component);
						val.Alert();
					}
					else
					{
						Frightened[component] = Time.realtimeSinceStartup + 2f;
						SetAlertedMethod.Invoke(val, new object[1] { false });
						MonsterAI val4 = (MonsterAI)(object)((val is MonsterAI) ? val : null);
						if ((Object)(object)val4 != (Object)null)
						{
							ClearTargets(val4);
						}
					}
					if (!destinations.TryGetValue(val, out var value) || Vector3.Distance(((Component)val).transform.position, value) < 3f)
					{
						value = (component.IsTamed() ? FindStructureSafety(((Component)val).transform.position, instance.EventType) : FindSafety(((Component)val).transform.position, instance.EventType));
						destinations[val] = value;
					}
					Move(val, value, 2f, run: true);
				}
			}
			responseCursor = (responseCursor + num) % array.Length;
		}

		private static Vector3 FindStructureSafety(Vector3 origin, WorldEventType type)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_008a: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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)
			Piece val = null;
			float num = float.MaxValue;
			Collider[] array = Physics.OverlapSphere(origin, 45f, -1, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				Piece componentInParent = ((Component)array[i]).GetComponentInParent<Piece>();
				if (!((Object)(object)componentInParent == (Object)null))
				{
					Vector3 val2 = ((Component)componentInParent).transform.position - origin;
					float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						val = componentInParent;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				return FindSafety(origin, type);
			}
			Vector3 val3 = origin - ((Component)val).transform.position;
			val3.y = 0f;
			if (((Vector3)(ref val3)).sqrMagnitude < 0.1f)
			{
				val3 = Vector3.forward;
			}
			Vector3 val4 = ((Component)val).transform.position + ((Vector3)(ref val3)).normalized * 3f;
			float y = default(float);
			if ((Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGroundHeight(val4, ref y))
			{
				val4.y = y;
			}
			return val4;
		}

		private static Vector3 FindSafety(Vector3 origin, WorldEventType type)
		{
			//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_002e: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00ec: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			Vector3 result = origin;
			float num = float.MinValue;
			float num2 = (((Object)(object)ZoneSystem.instance != (Object)null) ? ZoneSystem.instance.m_waterLevel : 30f);
			float y = default(float);
			for (int i = 0; i < 10; i++)
			{
				Vector2 insideUnitCircle = Random.insideUnitCircle;
				Vector2 val = ((Vector2)(ref insideUnitCircle)).normalized * Random.Range(18f, 48f);
				Vector3 val2 = origin + new Vector3(val.x, 0f, val.y);
				if ((Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGroundHeight(val2, ref y))
				{
					val2.y = y;
				}
				float num3 = Random.value * 3f;
				switch (type)
				{
				case WorldEventType.ToxicFog:
				case WorldEventType.Tsunami:
					num3 += (val2.y - num2) * 2f;
					break;
				case WorldEventType.Thunderstorm:
				case WorldEventType.Hurricane:
					num3 -= Mathf.Abs(val2.y - origin.y);
					break;
				}
				if (num3 > num)
				{
					num = num3;
					result = val2;
				}
			}
			return result;
		}

		private static bool IsEnclosed(Vector3 position)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			Collider[] array = Physics.OverlapSphere(position, 7f, -1, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				if ((Object)(object)((Component)array[i]).GetComponentInParent<Piece>() != (Object)null && ++num >= 4)
				{
					return true;
				}
			}
			return false;
		}

		private void ApproachForTaming(BaseAI ai, Character character)
		{
			//IL_002e: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			Tameable component = ((Component)character).GetComponent<Tameable>();
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)component == (Object)null || component.IsTamed() || (Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			if (Vector3.Distance(((Component)character).transform.position, ((Component)localPlayer).transform.position) > 3f)
			{
				Move(ai, ((Component)localPlayer).transform.position, 2.2f, run: false);
			}
			else
			{
				if (nextFeed.TryGetValue(component, out var value) && Time.realtimeSinceStartup < value)
				{
					return;
				}
				nextFeed[component] = Time.realtimeSinceStartup + 20f;
				ItemData[] array = ((Humanoid)localPlayer).GetInventory().GetAllItems().ToArray();
				foreach (ItemData val in array)
				{
					if (component.UseItem((Humanoid)(object)localPlayer, val))
					{
						break;
					}
				}
			}
		}

		private static void Move(BaseAI ai, Vector3 target, float distance, bool run)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			MoveToMethod.Invoke(ai, new object[4] { 0.75f, target, distance, run });
		}

		private static void ClearTargets(MonsterAI monster)
		{
			CreatureTargetField.SetValue(monster, null);
			StaticTargetField.SetValue(monster, null);
		}

		internal static bool IsFrightened(Character character)
		{
			if ((Object)(object)character == (Object)null || !Frightened.TryGetValue(character, out var value))
			{
				return false;
			}
			if (Time.realtimeSinceStartup <= value)
			{
				return true;
			}
			Frightened.Remove(character);
			return false;
		}
	}
	internal sealed class WorldCataclysmsHud : MonoBehaviour
	{
		private GUIStyle title;

		private void OnGUI()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0058: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			WorldEventManager instance = WorldEventManager.Instance;
			if (!((Object)(object)instance == (Object)null) && instance.Phase != EventPhase.Idle && !((Object)(object)Player.m_localPlayer == (Object)null))
			{
				if (title == null)
				{
					title = new GUIStyle(GUI.skin.label)
					{
						fontSize = 15,
						fontStyle = (FontStyle)1,
						alignment = (TextAnchor)4
					};
				}
				float num = ModConfig.HudScale?.Value ?? 1f;
				Matrix4x4 matrix = GUI.matrix;
				GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f));
				Rect val = default(Rect);
				((Rect)(ref val))..ctor((float)Screen.width * (ModConfig.HudX?.Value ?? 0.02f) / num, (float)Screen.height * (ModConfig.HudY?.Value ?? 0.68f) / num, 310f, 142f);
				GUI.Box(val, "");
				GUI.Label(new Rect(((Rect)(ref val)).x + 8f, ((Rect)(ref val)).y + 5f, 249f, 24f), instance.EventType.ToString() + " — " + instance.Phase, title);
				GUI.Label(new Rect(((Rect)(ref val)).x + 12f, ((Rect)(ref val)).y + 34f, 240f, 20f), "Tiempo: " + Mathf.CeilToInt(instance.RemainingSeconds) + " s");
				ExposureSample current = SurvivalManager.Current;
				if (current != null)
				{
					GUI.Label(new Rect(((Rect)(ref val)).x + 12f, ((Rect)(ref val)).y + 56f, 240f, 20f), "Temp " + Mathf.RoundToInt(current.Temperature) + "% | Agua " + Mathf.RoundToInt(current.Hydration) + "%");
					GUI.Label(new Rect(((Rect)(ref val)).x + 12f, ((Rect)(ref val)).y + 78f, 285f, 20f), "Aire " + Mathf.RoundToInt(current.AirQuality * 100f) + "% | " + current.Penalty);
					GUI.Label(new Rect(((Rect)(ref val)).x + 12f, ((Rect)(ref val)).y + 100f, 285f, 20f), current.Protection + " — " + current.Effect);
				}
				GUI.matrix = matrix;
			}
		}
	}
	public enum EventPhase
	{
		Idle,
		Warning,
		Active,
		Cooldown
	}
	public sealed class EventTimeline
	{
		public EventPhase Phase { get; private set; }

		public double Deadline { get; private set; }

		public double Duration { get; private set; }

		public double Cooldown { get; private set; }

		public bool Start(double now, double warning, double duration, double cooldown)
		{
			if (Phase != EventPhase.Idle)
			{
				return false;
			}
			Duration = Math.Max(1.0, duration);
			Cooldown = Math.Max(0.0, cooldown);
			Phase = ((warning > 0.0) ? EventPhase.Warning : EventPhase.Active);
			Deadline = now + ((warning > 0.0) ? warning : Duration);
			return true;
		}

		public bool Advance(double now)
		{
			EventPhase phase = Phase;
			while (Phase != EventPhase.Idle && now >= Deadline)
			{
				switch (Phase)
				{
				case EventPhase.Warning:
					Phase = EventPhase.Active;
					Deadline += Duration;
					break;
				case EventPhase.Active:
					Phase = EventPhase.Cooldown;
					Deadline += Cooldown;
					break;
				case EventPhase.Cooldown:
					Phase = EventPhase.Idle;
					Deadline = 0.0;
					break;
				}
			}
			return phase != Phase;
		}

		public bool Stop(double now)
		{
			if (Phase != EventPhase.Active && Phase != EventPhase.Warning)
			{
				return false;
			}
			Phase = ((Cooldown > 0.0) ? EventPhase.Cooldown : EventPhase.Idle);
			Deadline = ((Phase == EventPhase.Idle) ? 0.0 : (now + Cooldown));
			return true;
		}

		public void Reset()
		{
			Phase = EventPhase.Idle;
			double num = (Cooldown = 0.0);
			double deadline = (Duration = num);
			Deadline = deadline;
		}

		public void Restore(EventPhase phase, double now, double remaining, double duration, double cooldown)
		{
			Phase = phase;
			Duration = Math.Max(1.0, duration);
			Cooldown = Math.Max(0.0, cooldown);
			Deadline = ((phase == EventPhase.Idle) ? 0.0 : (now + Math.Max(0.0, remaining)));
		}

		public double Remaining(double now)
		{
			return Math.Max(0.0, Deadline - now);
		}
	}
	internal static class HookDispatcher
	{
		public static void Invoke<T, U>(Action<T, U> hook, T first, U second)
		{
			if (hook == null)
			{
				return;
			}
			Delegate[] invocationList = hook.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				Action<T, U> action = (Action<T, U>)invocationList[i];
				try
				{
					action(first, second);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogError((object)("Hook externo falló: " + ex));
				}
			}
		}

		public static void Invoke<T>(Action<T> hook, T value)
		{
			if (hook == null)
			{
				return;
			}
			Delegate[] invocationList = hook.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				Action<T> action = (Action<T>)invocationList[i];
				try
				{
					action(value);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogError((object)("Hook externo falló: " + ex));
				}
			}
		}
	}
	internal static class TsunamiSystem
	{
		private sealed class Wave
		{
			public Vector3 Origin;

			public Vector3 Direction;

			public float Started;

			public float NextDamage;
		}

		private static readonly List<Wave> Waves = new List<Wave>();

		public static void Add(Vector3 origin, Vector3 direction)
		{
			//IL_000b: 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_0029: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			Waves.Add(new Wave
			{
				Origin = origin,
				Direction = ((((Vector3)(ref direction)).sqrMagnitude < 0.01f) ? Vector3.forward : ((Vector3)(ref direction)).normalized),
				Started = Time.realtimeSinceStartup,
				NextDamage = Time.realtimeSinceStartup + 0.35f
			});
			if (Waves.Count > 6)
			{
				Waves.RemoveAt(0);
			}
		}

		public static void Clear()
		{
			Waves.Clear();
		}

		public static float Surface(Vector3 point, float original)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			WorldEventManager instance = WorldEventManager.Instance;
			if ((Object)(object)instance == (Object)null || instance.EventType != WorldEventType.Tsunami)
			{
				return original;
			}
			if (instance.Phase == EventPhase.Warning)
			{
				return original;
			}
			if (instance.Phase != EventPhase.Active)
			{
				return original;
			}
			float num = original;
			for (int num2 = Waves.Count - 1; num2 >= 0; num2--)
			{
				float num3 = Time.realtimeSinceStartup - Waves[num2].Started;
				if (num3 > 9f)
				{
					Waves.RemoveAt(num2);
				}
				else
				{
					Vector3 val = Crest(Waves[num2], num3);
					Vector3 val2 = point - val;
					float num4 = Mathf.Abs(Vector3.Dot(val2, Waves[num2].Direction));
					Vector3 val3 = val2 - Waves[num2].Direction * Vector3.Dot(val2, Waves[num2].Direction);
					if (num4 < 12f && ((Vector3)(ref val3)).magnitude < 42f)
					{
						num = Mathf.Max(num, original + Mathf.Sin(num3 / 9f * (float)Math.PI) * 22f);
					}
				}
			}
			return num;
		}

		public static void Tick()
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: 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_0158: Unknown result type (might be due to invalid IL or missing references)
			if (!CompleteRules.Active(WorldEventType.Tsunami))
			{
				Clear();
				return;
			}
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			for (int num = Waves.Count - 1; num >= 0; num--)
			{
				Wave wave = Waves[num];
				float num2 = realtimeSinceStartup - wave.Started;
				if (num2 > 9f)
				{
					Waves.RemoveAt(num);
				}
				else if (!(realtimeSinceStartup < wave.NextDamage))
				{
					wave.NextDamage = realtimeSinceStartup + 1.35f;
					Vector3 val = Crest(wave, num2);
					Vector3 val2 = Vector3.Cross(Vector3.up, wave.Direction);
					Vector3 normalized = ((Vector3)(ref val2)).normalized;
					float num3 = (((Object)(object)ZoneSystem.instance != (Object)null) ? ZoneSystem.instance.m_waterLevel : wave.Origin.y);
					for (int i = -1; i <= 1; i++)
					{
						Vector3 position = val + normalized * ((float)i * 25f);
						position.y = num3 + 6f;
						StrikeDamage.ApplyArea(position, wave.Direction, 13f, HazardDamageType.Blunt, 32f, 36f, 28f, 24f, 55f, shelter: false);
					}
					Player localPlayer = Player.m_localPlayer;
					if ((Object)(object)localPlayer != (Object)null && Vector3.Distance(((Component)localPlayer).transform.position, val) < 85f && (Object)(object)GameCamera.instance != (Object)null)
					{
						GameCamera.instance.AddShake(val, 100f, 2.2f, false);
					}
				}
			}
		}

		private static Vector3 Crest(Wave wave, float age)
		{
			//IL_0001: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			return wave.Origin - wave.Direction * 38f + wave.Direction * (20f * age);
		}
	}
	[HarmonyPatch(typeof(WaterVolume), "GetWaterSurface")]
	internal static class TsunamiWaterPatch
	{
		private static void Postfix(Vector3 point, ref float __result)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			__result = TsunamiSystem.Surface(point, __result);
		}
	}
	internal static class MeteorFireSystem
	{
		private sealed class Fire
		{
			public Vector3 Position;

			public float NextDamage;

			public GameObject Visual;
		}

		private static readonly List<Fire> Fires = new List<Fire>();

		public static void Add(Vector3 position)
		{
			//IL_000b: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			Fires.Add(new Fire
			{
				Position = position,
				NextDamage = Time.realtimeSinceStartup + 3f,
				Visual = CreateVisual(position)
			});
			if (Fires.Count > 28)
			{
				DestroyVisual(Fires[0]);
				Fires.RemoveAt(0);
			}
		}

		public static void Clear()
		{
			foreach (Fire fire in Fires)
			{
				DestroyVisual(fire);
			}
			Fires.Clear();
		}

		public static void Tick()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (!CompleteRules.Active(WorldEventType.MeteorShower))
			{
				Fires.Clear();
				return;
			}
			foreach (Fire fire in Fires)
			{
				if (!(Time.realtimeSinceStartup < fire.NextDamage))
				{
					fire.NextDamage = Time.realtimeSinceStartup + 3f;
					StrikeDamage.ApplyArea(fire.Position, Vector3.zero, 4f, HazardDamageType.Fire, 8f, 8f, 3f, 3f, 0f, shelter: true);
				}
			}
		}

		private static GameObject CreateVisual(Vector3 position)
		{
			//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_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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_0075: 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_0096: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: 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_012a: 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_013b: Expected O, but got Unknown
			//IL_013b: 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_0178: Expected O, but got Unknown
			if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsDedicated())
			{
				return null;
			}
			Shader val = Shader.Find("Sprites/Default") ?? Shader.Find("Unlit/Color");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			GameObject val2 = new GameObject("WC_MeteorFire");
			val2.transform.position = position + Vector3.up * 0.15f;
			ParticleSystem obj = val2.AddComponent<ParticleSystem>();
			MainModule main = obj.main;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(1.15f);
			((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0.85f);
			((MainModule)(ref main)).startSize = MinMaxCurve.op_Implicit(0.75f);
			((MainModule)(ref main)).start