Decompiled source of WaterWraith v2.0.0

NoteBoxz.WaterWraith.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using LethalMin;
using LethalMin.Patches;
using LethalMin.Utils;
using Microsoft.CodeAnalysis;
using NoteBoxz.WaterWraith.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using WaterWraithMod;
using WaterWraithMod.Patches;
using WaterWraithMod.Scripts;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("com.olegknyazev.softmask")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("EasyTextEffects")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("NoteBoxz.WaterWraith")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0+24ce73dcc9e92305e0917846a220181fefb9a8ff")]
[assembly: AssemblyProduct("WaterWraithMod")]
[assembly: AssemblyTitle("NoteBoxz.WaterWraith")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
		NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<bool>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<bool>();
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
public class PlayAudioOnAnimEvent : MonoBehaviour
{
	public AudioSource audioSource = null;

	public AudioClip[] audioClips = null;

	public void PlayAudio(int index)
	{
		if (audioClips.Length - 1 < index)
		{
			Debug.LogWarning((object)$"Audio clip index out of range: {index}");
		}
		else
		{
			audioSource.PlayOneShot(audioClips[index], audioSource.volume);
		}
	}
}
public class PlayRandomAudioOnAnimEvent : MonoBehaviour
{
	public AudioSource audioSource = null;

	public AudioClip[] audioClips = null;

	public void PlayRandom()
	{
		audioSource.PlayOneShot(audioClips[Random.Range(0, audioClips.Length - 1)], audioSource.volume);
	}
}
public enum GameGeneration
{
	Pikmin4,
	Pikmin2
}
public class WaterWraithMesh : MonoBehaviour
{
	[CompilerGenerated]
	private sealed class <WaitToSwitchOverride>d__5 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public WaterWraithMesh <>4__this;

		private int <i>5__1;

		private WaterWraithMeshOverride <waterWraithMeshOverride>5__2;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <WaitToSwitchOverride>d__5(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<waterWraithMeshOverride>5__2 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				global::WaterWraithMod.WaterWraithMod.Logger.LogInfo((object)$"Buffing switch {<>4__this.IndexBuffering}");
				<>2__current = (object)new WaitUntil((Func<bool>)(() => !((EnemyAI)<>4__this.AI).inSpecialAnimation));
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				<i>5__1 = 0;
				while (<i>5__1 < <>4__this.overrides.Count)
				{
					<waterWraithMeshOverride>5__2 = <>4__this.overrides[<i>5__1];
					if (<i>5__1 == <>4__this.IndexBuffering)
					{
						<waterWraithMeshOverride>5__2.Object.SetActive(true);
						((EnemyAI)<>4__this.AI).meshRenderers = <waterWraithMeshOverride>5__2.meshRenderers;
						((EnemyAI)<>4__this.AI).skinnedMeshRenderers = <waterWraithMeshOverride>5__2.skinnedMeshRenderers;
						((EnemyAI)<>4__this.AI).creatureAnimator = <waterWraithMeshOverride>5__2.Anim;
						<>4__this.AI.moveAud = <waterWraithMeshOverride>5__2.MoveAudioSource;
					}
					else
					{
						<waterWraithMeshOverride>5__2.Object.SetActive(false);
					}
					<waterWraithMeshOverride>5__2 = null;
					<i>5__1++;
				}
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	public List<WaterWraithMeshOverride> overrides = new List<WaterWraithMeshOverride>();

	public WaterWraithMeshOverride curoverride = null;

	public WaterWraithAI AI = null;

	private int IndexBuffering = -1;

	public void SetOverride(int index)
	{
		if (((EnemyAI)AI).inSpecialAnimation)
		{
			IndexBuffering = index;
			((MonoBehaviour)this).StartCoroutine(WaitToSwitchOverride());
		}
		else
		{
			if (((EnemyAI)AI).isEnemyDead)
			{
				return;
			}
			for (int i = 0; i < overrides.Count; i++)
			{
				WaterWraithMeshOverride waterWraithMeshOverride = overrides[i];
				if (i == index)
				{
					waterWraithMeshOverride.Object.SetActive(true);
					((EnemyAI)AI).meshRenderers = waterWraithMeshOverride.meshRenderers;
					((EnemyAI)AI).skinnedMeshRenderers = waterWraithMeshOverride.skinnedMeshRenderers;
					((EnemyAI)AI).creatureAnimator = waterWraithMeshOverride.Anim;
					AI.moveAud = waterWraithMeshOverride.MoveAudioSource;
					AI.BaseColider = waterWraithMeshOverride.BaseColider;
					AI.PikminColider = waterWraithMeshOverride.PikminColider;
					string[] array = new string[4] { "Moving", "HasLostRollers", "IsRunning", "IsScared" };
					if ((Object)(object)curoverride != (Object)null && (Object)(object)curoverride.Anim != (Object)null)
					{
						string[] array2 = array;
						foreach (string text in array2)
						{
							try
							{
								global::WaterWraithMod.WaterWraithMod.Logger.LogInfo((object)$"Setting {text} to {curoverride.Anim.GetBool(text)}");
								waterWraithMeshOverride.Anim.SetBool(text, curoverride.Anim.GetBool(text));
							}
							catch (Exception arg)
							{
								global::WaterWraithMod.WaterWraithMod.Logger.LogError((object)$"Failed to set {text} to {curoverride.Anim.GetBool(text)} due to: {arg}");
							}
						}
					}
					curoverride = waterWraithMeshOverride;
				}
				else
				{
					waterWraithMeshOverride.Object.SetActive(false);
				}
			}
		}
	}

	[IteratorStateMachine(typeof(<WaitToSwitchOverride>d__5))]
	private IEnumerator WaitToSwitchOverride()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <WaitToSwitchOverride>d__5(0)
		{
			<>4__this = this
		};
	}

	[ContextMenu("AutoFind")]
	public void FindMeshes()
	{
		foreach (WaterWraithMeshOverride @override in overrides)
		{
			List<MeshRenderer> list = new List<MeshRenderer>();
			MeshRenderer[] componentsInChildren = @override.Object.GetComponentsInChildren<MeshRenderer>();
			foreach (MeshRenderer item in componentsInChildren)
			{
				list.Add(item);
			}
			@override.meshRenderers = list.ToArray();
		}
		foreach (WaterWraithMeshOverride override2 in overrides)
		{
			List<SkinnedMeshRenderer> list2 = new List<SkinnedMeshRenderer>();
			SkinnedMeshRenderer[] componentsInChildren2 = override2.Object.GetComponentsInChildren<SkinnedMeshRenderer>();
			foreach (SkinnedMeshRenderer item2 in componentsInChildren2)
			{
				list2.Add(item2);
			}
			override2.skinnedMeshRenderers = list2.ToArray();
		}
	}
}
public class WaterWraithMeshOverride : MonoBehaviour
{
	public Animator Anim = null;

	public GameObject Object = null;

	public MeshRenderer[] meshRenderers = Array.Empty<MeshRenderer>();

	public SkinnedMeshRenderer[] skinnedMeshRenderers = Array.Empty<SkinnedMeshRenderer>();

	public AudioSource MoveAudioSource = null;

	public GameObject BaseColider = null;

	public GameObject PikminColider = null;
}
public class WraithProximityAnimEventChecks : MonoBehaviour
{
	public void DoShake()
	{
		//IL_0012: 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_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
		float num = Vector3.Distance(((Component)this).transform.position, ((Component)localPlayerController).transform.position);
		if (num <= 20f)
		{
			ScreenShakeType val = (ScreenShakeType)0;
			val = ((num <= 5f) ? ((ScreenShakeType)3) : ((!(num <= 10f)) ? ((ScreenShakeType)0) : ((ScreenShakeType)1)));
			HUDManager.Instance.ShakeCamera(val);
		}
	}

	public void DoFear()
	{
		//IL_0007: 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)
		if (Vector3.Distance(((Component)this).transform.position, ((Component)GameNetworkManager.Instance.localPlayerController).transform.position) < 16f)
		{
			GameNetworkManager.Instance.localPlayerController.JumpToFearLevel(1f, true);
		}
	}
}
namespace WaterWraithMod
{
	[BepInPlugin("NoteBoxz.WaterWraith", "WaterWraithMod", "2.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class WaterWraithMod : BaseUnityPlugin
	{
		public static ConfigEntry<float> SpawnChanceConfig = null;

		public static ConfigEntry<float> SpawnTimerConfig = null;

		public static ConfigEntry<bool> ChaseEnemyConfig = null;

		public static ConfigEntry<int> DamageConfig = null;

		public static ConfigEntry<int> EDamageConfig = null;

		public static ConfigEntry<string> PerMoonSpawnChanceConfig = null;

		public static ConfigEntry<float> PlayerCollisionBufferMultiplier = null;

		public static ConfigEntry<WraithSpawnPosition> WraithSpawnPositionConfig = null;

		public static ConfigEntry<float> WaterWaithSpawnPositionChance = null;

		public static ConfigEntry<int> PlayerDetectionRange = null;

		public static ConfigEntry<float> EnemyDetectionRange = null;

		public static ConfigEntry<float> PlayerChaseExitDistanceThreshold = null;

		public static ConfigEntry<float> EnemyChaseExitDistanceThreshold = null;

		public static ConfigEntry<float> EnemyChaseTimer = null;

		public static ConfigEntry<float> PlayerOutOfLOSTimer = null;

		public static ConfigEntry<float> RecoveryTime = null;

		public static ConfigEntry<bool> KnowWherePlayerIsWhenOutOfLOS = null;

		public static ConfigEntry<GameGeneration> GameGenerationConfig = null;

		public static List<Type> LibraryTypes = new List<Type>();

		public static WaterWraithMod Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		internal static Harmony? Harmony { get; set; }

		internal static AssetBundle assetBundle { get; private set; } = null;


		internal static EnemyType WraithEnemyType { get; private set; } = null;


		public static Dictionary<string, float> GetParsedMoonSpawn()
		{
			Dictionary<string, float> dictionary = new Dictionary<string, float>();
			if (string.IsNullOrEmpty(PerMoonSpawnChanceConfig.Value))
			{
				return new Dictionary<string, float>();
			}
			foreach (string item in PerMoonSpawnChanceConfig.Value.Split(',').ToList())
			{
				if (string.IsNullOrEmpty(item))
				{
					Logger.LogWarning((object)"Empty item found in PerMoonSpawnChanceConfig. please do not have empty items in your config.");
					continue;
				}
				string[] array = item.Split(':');
				if (float.TryParse(array[1], out var result))
				{
					dictionary.Add(array[0], result);
				}
				else
				{
					Logger.LogWarning((object)("Failed to parse (" + item + ")!"));
				}
			}
			return dictionary;
		}

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			NetcodePatcher();
			Patch();
			BindConfigs();
			LoadAssetBundle();
			RegisterRockAssets();
			if (IsDependencyLoaded("NoteBoxz.LethalMin"))
			{
				LETHALMIN_AddDef();
			}
			Logger.LogInfo((object)"NoteBoxz.WaterWraith v2.0.0 has loaded!");
		}

		public void BindConfigs()
		{
			GameGenerationConfig = ((BaseUnityPlugin)this).Config.Bind<GameGeneration>("Water Wraith", "Game Generation", GameGeneration.Pikmin4, "The game generation of the water wraith.");
			RecoveryTime = ((BaseUnityPlugin)this).Config.Bind<float>("Water Wraith", "Recovery Time", 10f, "The time it takes for the water wraith to recover after being scared");
			SpawnChanceConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "Spawn Chance", 25f, "The chance for a Water Wraith to spawn. (0-100)");
			PerMoonSpawnChanceConfig = ((BaseUnityPlugin)this).Config.Bind<string>("Spawning", "Per-Moon Spawn Chance", "Experimentation:10,Assurance:15,Vow:20,March:30,Adamance:35,Rend:45,Dine:50,Titan:50,Embrion:70,Artifice:70,Zeranos:0,Gordion:0", "The chance for a Water Wraith to spawn per moon these values will override the base spawn chance when spawning on a moon in the list. (Formatted just like Lethal Level Loader's configs) (sperate with commas no spaces inbetween sperate moonnames and spawn chances with colons) (moonname1:25,moonname2:35,moonname3:55...) (0-100)");
			ChaseEnemyConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemy Interaction", "Chase Enemys", true, "Makes the water wraith chase enemies as well as players.");
			WraithSpawnPositionConfig = ((BaseUnityPlugin)this).Config.Bind<WraithSpawnPosition>("Spawning", "Wraith Spawn Position", WraithSpawnPosition.OnlyIndoors, "The position where the Water Wraith will spawn.");
			WaterWaithSpawnPositionChance = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "Spawn Position Chance", 50f, "The chance for the Water Wraith to spawn outdoors or indoors if IndoorsAndOutdoors config is chosen, [0 = indoors] [100 = outdoors]. (0-100)");
			SpawnTimerConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "Spawn Timer (Seconds)", 300f, "The amount of time it takes for the wraith to spawn.");
			DamageConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Player Interaction", "Damage", 50, "The ammount of damage the water wraith deals.(0-100)");
			PlayerCollisionBufferMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Player Interaction", "Collision Buffer", 1.4f, "Multiplies the timer that is used to buffer damage players, higher values = instant death");
			EDamageConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Enemy Interaction", "Enemy Damage", 1, "The ammount of damage the water wraith deals to Enemies. Recomended: (1-3)");
			PlayerDetectionRange = ((BaseUnityPlugin)this).Config.Bind<int>("Player Interaction", "Player Detection Range", 15, "The maximum range at which the Water Wraith can detect players. (in meters)");
			EnemyDetectionRange = ((BaseUnityPlugin)this).Config.Bind<float>("Enemy Interaction", "Enemy Detection Range", 15f, "The maximum range at which the Water Wraith can detect other enemies. (in meters)");
			PlayerChaseExitDistanceThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("Player Interaction", "Player Chase Exit Distance", 30f, "The distance a player needs to be from the Water Wraith to exit chase state. (in meters)");
			EnemyChaseExitDistanceThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("Enemy Interaction", "Enemy Chase Exit Distance", 20f, "The distance an enemy needs to be from the Water Wraith to exit chase state. (in meters)");
			EnemyChaseTimer = ((BaseUnityPlugin)this).Config.Bind<float>("Enemy Interaction", "Enemy Chase Timer", 25f, "The maximum time the Water Wraith will chase an enemy before losing interest. (in seconds)");
			PlayerOutOfLOSTimer = ((BaseUnityPlugin)this).Config.Bind<float>("Player Interaction", "Player Out of LOS Timer", 10f, "How long the Water Wraith will continue chasing a player after losing line of sight. (in seconds)");
			KnowWherePlayerIsWhenOutOfLOS = ((BaseUnityPlugin)this).Config.Bind<bool>("Player Interaction", "Know Where Player Is When Out of LOS", true, "If the Water Wraith will know where the player is when they are out of line of sight. This will make it so players will need to be out of it's LOS for the timer's duration. Making it harder for players to lose the Water Wraith by going out of it's LOS.");
			GameGenerationConfig.SettingChanged += delegate
			{
				UpdateAllOverrides();
			};
		}

		public void UpdateAllOverrides()
		{
			try
			{
				WaterWraithMesh[] array = Object.FindObjectsOfType<WaterWraithMesh>();
				foreach (WaterWraithMesh waterWraithMesh in array)
				{
					waterWraithMesh.SetOverride((int)GameGenerationConfig.Value);
				}
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Error updating overrides: " + ex.Message));
			}
		}

		internal static void LoadAssetBundle()
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			if (directoryName == null)
			{
				throw new InvalidOperationException("Unable to determine assembly location.");
			}
			string text = Path.Combine(directoryName, "wraithassets");
			assetBundle = AssetBundle.LoadFromFile(text);
			if ((Object)(object)assetBundle == (Object)null)
			{
				throw new InvalidOperationException("Failed to load AssetBundle.");
			}
		}

		internal static void RegisterRockAssets()
		{
			WraithEnemyType = assetBundle.LoadAsset<EnemyType>("Assets/ModAsset/WaterType.asset");
			TerminalNode val = assetBundle.LoadAsset<TerminalNode>("Assets/ModAsset/WaterNode.asset");
			Enemies.RegisterEnemy(WraithEnemyType, 0, (LevelTypes)(-1), val, (TerminalKeyword)null);
		}

		internal static void LETHALMIN_AddDef()
		{
			CustomPikminEnemyOverrideDef val = WraithEnemyType.enemyPrefab.AddComponent<CustomPikminEnemyOverrideDef>();
			val.CustomPikminEnemyOverrideType = typeof(WaterWraithPikminEnemy);
		}

		public static bool IsDependencyLoaded(string pluginGUID)
		{
			return Chainloader.PluginInfos.ContainsKey(pluginGUID);
		}

		private void NetcodePatcher()
		{
			Type[] typesWithErrorHandling = GetTypesWithErrorHandling();
			Type[] array = typesWithErrorHandling;
			foreach (Type type in array)
			{
				try
				{
					MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
					MethodInfo[] array2 = methods;
					foreach (MethodInfo methodInfo in array2)
					{
						try
						{
							object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
							if (customAttributes.Length != 0)
							{
								methodInfo.Invoke(null, null);
							}
						}
						catch (Exception ex)
						{
							Logger.LogWarning((object)("Error invoking method " + methodInfo.Name + " in type " + type.FullName + ": " + ex.Message));
							if (ex.InnerException != null)
							{
								Logger.LogWarning((object)("Inner exception: " + ex.InnerException.Message));
							}
						}
					}
				}
				catch (Exception ex2)
				{
					Logger.LogWarning((object)("Error processing type " + type.FullName + ": " + ex2.Message));
				}
			}
			Logger.LogInfo((object)"NetcodePatcher completed.");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("NoteBoxz.WaterWraith");
			}
			Logger.LogDebug((object)"Patching...");
			try
			{
				Type[] typesWithErrorHandling = GetTypesWithErrorHandling();
				Type[] array = typesWithErrorHandling;
				foreach (Type type in array)
				{
					try
					{
						Harmony.PatchAll(type);
					}
					catch (Exception ex)
					{
						Logger.LogError((object)("Error patching type " + type.FullName + ": " + ex.Message));
						if (ex.InnerException != null)
						{
							Logger.LogError((object)("Inner exception: " + ex.InnerException.Message));
						}
					}
				}
				if (IsDependencyLoaded("NoteBoxz.LethalMin"))
				{
					Logger.LogInfo((object)"LethalMin detected. Patching Purple Pikmin.");
				}
			}
			catch (Exception ex2)
			{
				Logger.LogError((object)("Error during patching process: " + ex2.Message));
				if (ex2.InnerException != null)
				{
					Logger.LogError((object)("Inner exception: " + ex2.InnerException.Message));
				}
			}
			Logger.LogDebug((object)"Finished patching!");
		}

		private static Type[] GetTypesWithErrorHandling()
		{
			try
			{
				return Assembly.GetExecutingAssembly().GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				Logger.LogWarning((object)"ReflectionTypeLoadException caught while getting types. Some types will be skipped.");
				Exception[] loaderExceptions = ex.LoaderExceptions;
				foreach (Exception ex2 in loaderExceptions)
				{
					Logger.LogWarning((object)("Loader Exception: " + ex2.Message));
					if (ex2 is FileNotFoundException ex3)
					{
						Logger.LogWarning((object)("Could not load file: " + ex3.FileName));
					}
				}
				return ex.Types.Where((Type t) => t != null).ToArray();
			}
			catch (Exception ex4)
			{
				Logger.LogError((object)("Unexpected error while getting types: " + ex4.Message));
				return new Type[0];
			}
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "NoteBoxz.WaterWraith";

		public const string PLUGIN_NAME = "WaterWraithMod";

		public const string PLUGIN_VERSION = "2.0.0";
	}
}
namespace WaterWraithMod.Scripts
{
	public class EnemyCollisionDetectHidden : EnemyAICollisionDetect
	{
		public void OnTriggerStay(Collider other)
		{
		}
	}
	public class TireFragments : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <RemoveFragments>d__3 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public TireFragments <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <RemoveFragments>d__3(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(30f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					Object.Destroy((Object)(object)((Component)<>4__this).gameObject);
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public Rigidbody[] Fragments = Array.Empty<Rigidbody>();

		public bool P2style = false;

		public void Start()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if (!P2style)
			{
				Fragments = ((Component)((Component)this).transform).GetComponentsInChildren<Rigidbody>();
				Rigidbody[] fragments = Fragments;
				foreach (Rigidbody val in fragments)
				{
					val.AddExplosionForce(15f, ((Component)this).transform.position, 7f);
				}
			}
			((MonoBehaviour)this).StartCoroutine(RemoveFragments());
		}

		[IteratorStateMachine(typeof(<RemoveFragments>d__3))]
		private IEnumerator RemoveFragments()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <RemoveFragments>d__3(0)
			{
				<>4__this = this
			};
		}
	}
	public class WaterWraithAI : EnemyAI
	{
		[CompilerGenerated]
		private sealed class <CallKillOnServer>d__44 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public WaterWraithAI <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <CallKillOnServer>d__44(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(2.5f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					((EnemyAI)<>4__this).KillEnemyOnOwnerClient(false);
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <WaitForCrush>d__30 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public WaterWraithAI <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <WaitForCrush>d__30(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(8.5f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					((EnemyAI)<>4__this).inSpecialAnimation = false;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <WaitToFlee>d__41 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public WaterWraithAI <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <WaitToFlee>d__41(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				//IL_0057: 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_0066: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(2.6f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.FleePos = <>4__this.ChooseFarthestPositionFromPosition(((Component)<>4__this).transform.position);
					((EnemyAI)<>4__this).SwitchToBehaviourClientRpc(2);
					((EnemyAI)<>4__this).inSpecialAnimation = false;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public AISearchRoutine roamWorld = null;

		public EnemyAI TargetEnemy = null;

		public List<EnemyAI> TargetedEnemies = null;

		public WaterWraithMesh WMesh = null;

		public AudioSource moveAud = null;

		public AudioClip KillSFX = null;

		public bool IsChasingEnemy = false;

		public bool IsWandering = false;

		public bool HasLostTires;

		public Vector3 FleePos;

		public NetworkVariable<bool> isVurable = new NetworkVariable<bool>(false, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		public NetworkVariable<bool> isRunning = new NetworkVariable<bool>(false, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		private float timeSinceHitting;

		private float timeInEnemyChase;

		private float timeLostPlayer;

		private float timeBeingScared;

		public GameObject[] TireObjectsToDisable = Array.Empty<GameObject>();

		public Collider[] ColidersToDisable = Array.Empty<Collider>();

		private TireFragments[] TireObjectsToEnable = Array.Empty<TireFragments>();

		public PlayerControllerB PlayerFleeingFrom = null;

		public PlayerControllerB PlayerStunnedBy = null;

		public AudioClip[] DethSounds = Array.Empty<AudioClip>();

		public AudioClip[] HurtSounds = Array.Empty<AudioClip>();

		public GameObject BaseColider = null;

		public GameObject PikminColider = null;

		private Vector3? LastPositionTargetWasSeen;

		private WraithTire[] Tires = Array.Empty<WraithTire>();

		private Vector3 LastPosition;

		private float LastPosCheck;

		private bool lastIsScaredCheck;

		private List<GameObject> chaseableEnemies => (from enemy in RoundManager.Instance.SpawnedEnemies
			where (Object)(object)enemy != (Object)null && (Object)(object)enemy.enemyType != (Object)(object)base.enemyType && !TargetedEnemies.Contains(enemy)
			select ((Component)enemy).gameObject).ToList();

		public override void Start()
		{
			//IL_008e: 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)
			((EnemyAI)this).Start();
			List<GameObject> list = new List<GameObject>();
			GameObject[] collection = GameObject.FindGameObjectsWithTag("AINode");
			GameObject[] collection2 = GameObject.FindGameObjectsWithTag("OutsideAINode");
			list.AddRange(collection2);
			list.AddRange(collection);
			GameObject val = list.OrderBy((GameObject p) => Vector3.Distance(p.transform.position, ((Component)this).transform.position)).FirstOrDefault();
			WaterWraithMod.Logger.LogInfo((object)("WaterWraith: Destemined " + ((Object)val).name + "(" + val.tag + ")" + $" is the position it spawned at: {val.transform.position} - {((Component)this).transform.position}"));
			if (val.CompareTag("OutsideAINode"))
			{
				WaterWraithMod.Logger.LogInfo((object)"WaterWraith: WaterWraith determined it spawned outside");
				base.allAINodes = GameObject.FindGameObjectsWithTag("OutsideAINode");
				base.isOutside = true;
			}
			else
			{
				WaterWraithMod.Logger.LogInfo((object)"WaterWraith: WaterWraith determined it spawned inside");
				base.allAINodes = GameObject.FindGameObjectsWithTag("AINode");
				base.isOutside = false;
			}
			TireObjectsToEnable = ((Component)this).GetComponentsInChildren<TireFragments>(true);
			Tires = ((Component)this).GetComponentsInChildren<WraithTire>(true);
			WaterWraithMod.Logger.LogInfo((object)$"Tires: {Tires.Length}");
			WaterWraithMod.Logger.LogInfo((object)$"DulyAbledTires: {TireObjectsToEnable.Length}");
			WMesh.SetOverride((int)WaterWraithMod.GameGenerationConfig.Value);
			base.creatureAnimator.SetTrigger("Spawn");
			base.inSpecialAnimation = true;
			moveAud.volume = 0f;
			((MonoBehaviour)this).StartCoroutine(WaitForCrush());
		}

		[IteratorStateMachine(typeof(<WaitForCrush>d__30))]
		private IEnumerator WaitForCrush()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitForCrush>d__30(0)
			{
				<>4__this = this
			};
		}

		public override void DoAIInterval()
		{
			//IL_0659: Unknown result type (might be due to invalid IL or missing references)
			//IL_065e: 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_08da: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_06dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0709: Expected O, but got Unknown
			//IL_09a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_09af: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0828: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_071f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0725: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0755: Unknown result type (might be due to invalid IL or missing references)
			//IL_075a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0764: Expected O, but got Unknown
			//IL_0874: Unknown result type (might be due to invalid IL or missing references)
			//IL_087e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0883: Unknown result type (might be due to invalid IL or missing references)
			//IL_088a: Unknown result type (might be due to invalid IL or missing references)
			//IL_078a: Unknown result type (might be due to invalid IL or missing references)
			//IL_079a: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0493: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).DoAIInterval();
			if (StartOfRound.Instance.livingPlayers == 0 || base.isEnemyDead || base.inSpecialAnimation)
			{
				moveAud.volume = 0f;
				return;
			}
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
			{
				if (!IsWandering)
				{
					WaterWraithMod.Logger.LogInfo((object)"WaterWraith: Starting Search!");
					((EnemyAI)this).StartSearch(((Component)this).transform.position, roamWorld);
					IsWandering = true;
				}
				PlayerControllerB val3 = ((EnemyAI)this).CheckLineOfSightForPlayer(-1f, WaterWraithMod.PlayerDetectionRange.Value, WaterWraithMod.PlayerDetectionRange.Value);
				if (Object.op_Implicit((Object)(object)val3))
				{
					((EnemyAI)this).StopSearch(roamWorld, true);
					((EnemyAI)this).SetMovingTowardsTargetPlayer(val3);
					base.moveTowardsDestination = true;
					IsChasingEnemy = false;
					WaterWraithMod.Logger.LogInfo((object)("WaterWraith: Chasing player " + val3.playerUsername));
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
					break;
				}
				GameObject val4 = ((EnemyAI)this).CheckLineOfSight(chaseableEnemies, -1f, (int)WaterWraithMod.EnemyDetectionRange.Value, WaterWraithMod.EnemyDetectionRange.Value, (Transform)null, (int[])null);
				EnemyAI targetEnemy = default(EnemyAI);
				if (WaterWraithMod.ChaseEnemyConfig.Value && Object.op_Implicit((Object)(object)val4) && val4.TryGetComponent<EnemyAI>(ref targetEnemy))
				{
					((EnemyAI)this).StopSearch(roamWorld, true);
					TargetEnemy = targetEnemy;
					IsChasingEnemy = true;
					timeInEnemyChase = 0f;
					WaterWraithMod.Logger.LogInfo((object)("WaterWraith: Chasing enemy " + ((Object)((Component)this).gameObject).name));
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
				}
				break;
			}
			case 1:
			{
				if (IsWandering)
				{
					((EnemyAI)this).StopSearch(roamWorld, true);
					IsWandering = false;
				}
				if (IsChasingEnemy)
				{
					string text = null;
					if ((Object)(object)TargetEnemy == (Object)null)
					{
						text = "target enemy is null";
					}
					else if (TargetEnemy.isEnemyDead)
					{
						text = "target enemy is dead";
					}
					else if (TargetedEnemies.Contains(TargetEnemy))
					{
						text = "target enemy already in targeted list";
					}
					else if (Vector3.Distance(((Component)this).transform.position, ((Component)TargetEnemy).transform.position) > WaterWraithMod.EnemyChaseExitDistanceThreshold.Value)
					{
						text = $"target enemy too far away (>{WaterWraithMod.EnemyChaseExitDistanceThreshold.Value}f)";
					}
					else if (timeInEnemyChase > WaterWraithMod.EnemyChaseTimer.Value)
					{
						text = $"chase time exceeded (>{WaterWraithMod.EnemyChaseTimer.Value}s)";
					}
					if (text != null)
					{
						if ((Object)(object)TargetEnemy != (Object)null)
						{
							TargetedEnemies.Add(TargetEnemy);
						}
						TargetEnemy = null;
						IsChasingEnemy = false;
						WaterWraithMod.Logger.LogMessage((object)("WaterWraith: stopped chasing enemy due to: " + text));
						MoveAwayFromMain();
						((EnemyAI)this).SwitchToBehaviourClientRpc(0);
						break;
					}
					if ((Object)(object)TargetEnemy != (Object)null)
					{
						((EnemyAI)this).SetDestinationToPosition(((Component)TargetEnemy).transform.position, false);
					}
				}
				if (IsChasingEnemy)
				{
					break;
				}
				string text2 = null;
				if ((Object)(object)base.targetPlayer == (Object)null)
				{
					text2 = "target player is null";
				}
				else if (base.targetPlayer.isPlayerDead)
				{
					text2 = "target player is dead";
				}
				else if (!base.targetPlayer.isPlayerControlled)
				{
					text2 = "target player not controlled";
				}
				else if (Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) > WaterWraithMod.PlayerChaseExitDistanceThreshold.Value)
				{
					text2 = $"target player too far away (>{WaterWraithMod.PlayerChaseExitDistanceThreshold.Value}f)";
				}
				if (text2 == null && (Object)(object)base.targetPlayer != (Object)null && !CheckLineOfSightOnPlayer(base.targetPlayer, -1f, WaterWraithMod.PlayerDetectionRange.Value, WaterWraithMod.PlayerDetectionRange.Value))
				{
					if (!LastPositionTargetWasSeen.HasValue)
					{
						LastPositionTargetWasSeen = ((Component)base.targetPlayer).transform.position;
						WaterWraithMod.Logger.LogInfo((object)$"WaterWraith: Player went of of LOS Last position was seen: {LastPositionTargetWasSeen}");
					}
					base.movingTowardsTargetPlayer = false;
					Vector3 val = (WaterWraithMod.KnowWherePlayerIsWhenOutOfLOS.Value ? ((Component)base.targetPlayer).transform.position : LastPositionTargetWasSeen.Value);
					((EnemyAI)this).SetDestinationToPosition(val, false);
					if (base.agent.remainingDistance < 2f && !WaterWraithMod.KnowWherePlayerIsWhenOutOfLOS.Value)
					{
						text2 = "target player not in line of sight";
						LastPositionTargetWasSeen = null;
					}
					if (timeLostPlayer > WaterWraithMod.PlayerOutOfLOSTimer.Value)
					{
						text2 = $"target player out of LOS for too long (>{WaterWraithMod.PlayerOutOfLOSTimer.Value}s)";
						LastPositionTargetWasSeen = null;
					}
				}
				if (LastPositionTargetWasSeen.HasValue)
				{
					PlayerControllerB val2 = ((EnemyAI)this).CheckLineOfSightForPlayer(-1f, WaterWraithMod.PlayerDetectionRange.Value, WaterWraithMod.PlayerDetectionRange.Value);
					if ((Object)(object)val2 != (Object)null)
					{
						((EnemyAI)this).SetMovingTowardsTargetPlayer(val2);
						base.moveTowardsDestination = true;
						LastPositionTargetWasSeen = null;
						WaterWraithMod.Logger.LogInfo((object)("WaterWraith: Player is back in LOS: " + val2?.playerUsername));
					}
				}
				if (text2 != null)
				{
					base.targetPlayer = null;
					base.movingTowardsTargetPlayer = false;
					LastPositionTargetWasSeen = null;
					WaterWraithMod.Logger.LogMessage((object)("WaterWraith: stopped chasing player due to: " + text2));
					MoveAwayFromMain();
					((EnemyAI)this).SwitchToBehaviourClientRpc(0);
				}
				break;
			}
			case 2:
			{
				if (FleePos != Vector3.zero)
				{
					if (IsWandering)
					{
						((EnemyAI)this).StopSearch(roamWorld, true);
						IsWandering = false;
					}
					base.agent.speed = 7f;
					base.agent.acceleration = 999f;
					base.agent.angularSpeed = 300f;
					((EnemyAI)this).SetDestinationToPosition(FleePos, false);
					if (Vector3.Distance(((Component)this).transform.position, FleePos) < 2f || !base.agent.CalculatePath(FleePos, new NavMeshPath()))
					{
						if (Vector3.Distance(((Component)this).transform.position, FleePos) < 2f)
						{
							WaterWraithMod.Logger.LogInfo((object)"WaterWraith: Exiting flee due to distance");
						}
						if (!base.agent.CalculatePath(FleePos, new NavMeshPath()))
						{
							WaterWraithMod.Logger.LogInfo((object)"WaterWraith: Exiting flee do to no pos");
						}
						WaterWraithMod.Logger.LogInfo((object)$"Flee pos: {FleePos}, Water pos: {((Component)this).transform.position}");
						FleePos = Vector3.zero;
					}
				}
				if (!IsWandering && FleePos == Vector3.zero)
				{
					WaterWraithMod.Logger.LogInfo((object)"WaterWraith: Starting Search 2!");
					base.agent.speed = 3.5f;
					base.agent.acceleration = 8f;
					base.agent.angularSpeed = 120f;
					((EnemyAI)this).StartSearch(((Component)this).transform.position, roamWorld);
					IsWandering = true;
				}
				PlayerControllerB val5 = ((EnemyAI)this).CheckLineOfSightForPlayer(-1f, 15, 15);
				if (IsWandering && Object.op_Implicit((Object)(object)val5))
				{
					FleePos = ChooseFarthestPositionFromPosition(((Component)val5).transform.position);
					((EnemyAI)this).SetDestinationToPosition(FleePos, false);
					WaterWraithMod.Logger.LogInfo((object)"WaterWraith: Fleeing from player!");
				}
				break;
			}
			case 3:
				if (IsWandering)
				{
					((EnemyAI)this).StopSearch(roamWorld, true);
					IsWandering = false;
				}
				((EnemyAI)this).SetDestinationToPosition(((Component)this).transform.position, false);
				base.agent.speed = 0f;
				base.agent.acceleration = 0f;
				base.agent.angularSpeed = 0f;
				if (timeBeingScared > WaterWraithMod.RecoveryTime.Value)
				{
					base.agent.speed = 3.5f;
					base.agent.acceleration = 8f;
					base.agent.angularSpeed = 120f;
					timeBeingScared = 0f;
					isVurable.Value = false;
					WaterWraithMod.Logger.LogInfo((object)"WaterWraith: Resetting");
					if (HasLostTires)
					{
						FleePos = ChooseFarthestPositionFromPosition(((Component)this).transform.position, 80f);
						((EnemyAI)this).SwitchToBehaviourClientRpc(2);
					}
					else
					{
						((EnemyAI)this).SwitchToBehaviourClientRpc(0);
					}
				}
				break;
			}
		}

		public bool CheckLineOfSightOnPlayer(PlayerControllerB player, float width = 45f, int range = 60, int proximityAwareness = -1)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			//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_0043: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			if (base.isOutside && !base.enemyType.canSeeThroughFog && (int)TimeOfDay.Instance.currentLevelWeather == 3)
			{
				range = Mathf.Clamp(range, 0, 30);
			}
			Vector3 position = ((Component)player).transform.position;
			if (Vector3.Distance(position, base.eye.position) < (float)range && !Physics.Linecast(base.eye.position, position, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				Vector3 val = position - base.eye.position;
				if (Vector3.Angle(base.eye.forward, val) < width || (proximityAwareness != -1 && Vector3.Distance(base.eye.position, position) < (float)proximityAwareness))
				{
					return true;
				}
			}
			return false;
		}

		public bool MoveAwayFromMain()
		{
			//IL_0007: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			if (Vector3.Distance(((Component)this).transform.position, RoundManager.FindMainEntrancePosition(false, false)) < 20f)
			{
				Transform val = ((EnemyAI)this).ChooseFarthestNodeFromPosition(RoundManager.FindMainEntrancePosition(false, false), false, 0, false, 50, false);
				roamWorld.currentTargetNode = ((Component)val).gameObject;
				roamWorld.choseTargetNode = true;
				WaterWraithMod.Logger.LogInfo((object)"WaterWraith: Setting position away from main");
				return true;
			}
			return false;
		}

		public override void HitEnemy(int force = 1, PlayerControllerB playerWhoHit = null, bool playHitSFX = false, int hitID = -1)
		{
			((EnemyAI)this).HitEnemy(force, playerWhoHit, playHitSFX, hitID);
			if (!isVurable.Value || base.isEnemyDead || base.inSpecialAnimation)
			{
				return;
			}
			base.enemyHP -= force;
			timeBeingScared += Random.Range(0f, 1f);
			if (base.enemyHP <= 0)
			{
				if (!HasLostTires)
				{
					RemoveTiresServerRpc();
				}
				else
				{
					KillWraithServerRpc();
				}
			}
		}

		public override void HitFromExplosion(float distance)
		{
			((EnemyAI)this).HitFromExplosion(distance);
			WaterWraithMod.Logger.LogInfo((object)"Wraith kabboom!");
			SetScaredServerRpc();
		}

		public override void SetEnemyStunned(bool setToStunned, float setToStunTime = 1f, PlayerControllerB setStunnedByPlayer = null)
		{
			((EnemyAI)this).SetEnemyStunned(setToStunned, setToStunTime, setStunnedByPlayer);
			if (setToStunned)
			{
				WaterWraithMod.Logger.LogInfo((object)"Wraith cstuned!");
				SetScaredServerRpc();
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void RemoveTiresServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(118134160u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 118134160u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				WaterWraithMod.Logger.LogInfo((object)"Removing On Serer");
				if (!base.inSpecialAnimation && !HasLostTires)
				{
					RemoveTiresClientRpc();
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void SetScaredServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2926869977u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2926869977u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				if (!isVurable.Value)
				{
					WaterWraithMod.Logger.LogInfo((object)"SetScared");
					((EnemyAI)this).SwitchToBehaviourClientRpc(3);
					timeBeingScared = 0f;
					isVurable.Value = true;
					TargetEnemy = null;
					base.targetPlayer = null;
					IsChasingEnemy = false;
					base.movingTowardsTargetPlayer = false;
					LastPositionTargetWasSeen = null;
				}
				else
				{
					WaterWraithMod.Logger.LogInfo((object)"Already scared");
				}
			}
		}

		public override void KillEnemy(bool destroy = false)
		{
			((EnemyAI)this).KillEnemy(destroy);
		}

		[ClientRpc]
		public void RemoveTiresClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2232173676u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2232173676u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			if (HasLostTires)
			{
				WaterWraithMod.Logger.LogWarning((object)"The wraith has already removed it's tires");
				return;
			}
			WaterWraithMod.Logger.LogInfo((object)"Removing Tires");
			if (((NetworkBehaviour)this).IsServer && IsWandering)
			{
				((EnemyAI)this).StopSearch(roamWorld, true);
				IsWandering = false;
			}
			LastPositionTargetWasSeen = null;
			base.targetPlayer = null;
			base.enemyHP = 10;
			base.inSpecialAnimation = true;
			moveAud.volume = 0f;
			HasLostTires = true;
			base.creatureAnimator.SetTrigger("KnockedOff");
			base.creatureAnimator.SetBool("HasLostRollers", true);
			GameObject[] tireObjectsToDisable = TireObjectsToDisable;
			foreach (GameObject val3 in tireObjectsToDisable)
			{
				val3.SetActive(false);
			}
			TireFragments[] tireObjectsToEnable = TireObjectsToEnable;
			foreach (TireFragments tireFragments in tireObjectsToEnable)
			{
				GameObject gameObject = ((Component)tireFragments).gameObject;
				if (((Component)gameObject.transform.parent).gameObject.activeSelf)
				{
					gameObject.SetActive(true);
				}
				gameObject.transform.SetParent((Transform)null, true);
			}
			Collider[] colidersToDisable = ColidersToDisable;
			foreach (Collider val4 in colidersToDisable)
			{
				val4.enabled = false;
			}
			WraithTire[] tires = Tires;
			foreach (WraithTire wraithTire in tires)
			{
				((Behaviour)wraithTire).enabled = false;
			}
			((MonoBehaviour)this).StartCoroutine(WaitToFlee());
		}

		[IteratorStateMachine(typeof(<WaitToFlee>d__41))]
		private IEnumerator WaitToFlee()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitToFlee>d__41(0)
			{
				<>4__this = this
			};
		}

		[ServerRpc(RequireOwnership = false)]
		public void KillWraithServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3609201593u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3609201593u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && !base.inSpecialAnimation && !base.isEnemyDead)
				{
					WaterWraithMod.Logger.LogInfo((object)"Killing Wraith");
					KillWraithClientRpc();
				}
			}
		}

		[ClientRpc]
		public void KillWraithClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1114460635u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1114460635u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.creatureAnimator.SetTrigger("Die");
				base.inSpecialAnimation = true;
				base.isEnemyDead = true;
				base.creatureVoice.PlayOneShot(DethSounds[Random.Range(0, DethSounds.Length - 1)]);
				if (((NetworkBehaviour)this).IsServer)
				{
					((MonoBehaviour)this).StartCoroutine(CallKillOnServer());
				}
			}
		}

		[IteratorStateMachine(typeof(<CallKillOnServer>d__44))]
		private IEnumerator CallKillOnServer()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <CallKillOnServer>d__44(0)
			{
				<>4__this = this
			};
		}

		public void DamagePlayer(PlayerControllerB player)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0059: 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_0064: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			if (!isVurable.Value && (Object)(object)player != (Object)null)
			{
				Vector3 val = ((Component)player).transform.position - ((Component)this).transform.position;
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				player.DamagePlayer(WaterWraithMod.DamageConfig.Value, true, true, (CauseOfDeath)8, 1, false, -normalized * 5f);
				if (player.isPlayerDead)
				{
					base.creatureSFX.PlayOneShot(KillSFX);
				}
				else
				{
					player.externalForceAutoFade += normalized * 7f;
				}
			}
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			//IL_004a: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0092: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).OnCollideWithPlayer(other);
			PlayerControllerB component = ((Component)other).GetComponent<PlayerControllerB>();
			if ((Object)(object)component != (Object)null && HasLostTires && !isVurable.Value && isRunning.Value)
			{
				Vector3 val = default(Vector3);
				component.DamagePlayer(0, true, true, (CauseOfDeath)0, 0, false, val);
				val = ((Component)component).transform.position - ((Component)this).transform.position;
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				component.externalForceAutoFade += normalized * 2.5f;
			}
		}

		public void DamageEnemy(EnemyAI enemy)
		{
			if (isVurable.Value || !((NetworkBehaviour)this).IsServer || !((Object)(object)enemy != (Object)null) || enemy.isEnemyDead)
			{
				return;
			}
			if (WaterWraithMod.IsDependencyLoaded("NoteBoxz.LethalMin") && LETHALMIN_TRYCRUSH(enemy))
			{
				TargetedEnemies.Add(enemy);
				WaterWraithMod.Logger.LogInfo((object)(((Object)((Component)enemy).gameObject).name + " Is A Pikmin!"));
				return;
			}
			WaterWraithMod.Logger.LogInfo((object)("Hitting enemy: " + ((Object)enemy).name));
			int enemyHP = enemy.enemyHP;
			enemy.HitEnemyServerRpc(WaterWraithMod.EDamageConfig.Value, -1, true, -1);
			if (!enemy.isEnemyDead)
			{
				enemy.stunNormalizedTimer += Random.Range(0f, 1f);
			}
			if (enemyHP == enemy.enemyHP && (Object)(object)enemy == (Object)(object)TargetEnemy)
			{
				WaterWraithMod.Logger.LogInfo((object)("Water Wraith has determined that target enemy " + ((Object)enemy).name + " is unkillable"));
				TargetedEnemies.Add(enemy);
			}
		}

		public bool LETHALMIN_TRYCRUSH(EnemyAI ai)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Invalid comparison between Unknown and I4
			PikminAI val = (PikminAI)(object)((ai is PikminAI) ? ai : null);
			if (val != null)
			{
				WaterWraithPikminEnemy component = ((Component)this).GetComponent<WaterWraithPikminEnemy>();
				if (component.PikminImmune.Contains(val))
				{
					if ((int)val.PreviousIntention == 11 || (int)val.CurrentIntention == 11)
					{
						return true;
					}
					component.PikminImmune.Remove(val);
				}
				if (!PikChecks.IsPikminResistantToHazard(val, (PikminHazard)4, (Object)(object)this))
				{
					val.DoSquishDeathClientRpc(false);
					WaterWraithMod.Logger.LogInfo((object)("Pikmin " + ((Object)val).name + " is not resistant to crush damage!"));
				}
				else
				{
					WaterWraithMod.Logger.LogInfo((object)("Pikmin " + ((Object)val).name + " is resistant to crush damage!"));
				}
				return true;
			}
			return false;
		}

		private void LateUpdate()
		{
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			if (base.isEnemyDead || base.inSpecialAnimation)
			{
				return;
			}
			if (((NetworkBehaviour)this).IsServer)
			{
				if (isVurable.Value)
				{
					timeBeingScared += Time.deltaTime;
				}
				if (IsChasingEnemy)
				{
					timeInEnemyChase += Time.deltaTime;
				}
				if (LastPositionTargetWasSeen.HasValue)
				{
					timeLostPlayer += Time.deltaTime;
				}
				Vector3 val;
				if (!HasLostTires)
				{
					AudioSource obj = moveAud;
					val = base.agent.velocity;
					val = ((Vector3)(ref val)).normalized;
					obj.volume = ((Vector3)(ref val)).magnitude;
				}
				Animator creatureAnimator = base.creatureAnimator;
				val = base.agent.velocity;
				val = ((Vector3)(ref val)).normalized;
				creatureAnimator.SetBool("Moving", ((Vector3)(ref val)).magnitude > 0.1f);
				base.creatureAnimator.SetBool("IsRunning", HasLostTires && FleePos != Vector3.zero);
				isRunning.Value = HasLostTires && FleePos != Vector3.zero;
			}
			else
			{
				LastPosCheck += Time.deltaTime;
				if (Vector3.Distance(LastPosition, ((Component)this).transform.position) > 0.1f)
				{
					LastPosition = ((Component)this).transform.position;
					if (!HasLostTires)
					{
						moveAud.volume = 1f;
					}
					base.creatureAnimator.SetBool("Moving", true);
				}
				else if (LastPosCheck > 1f)
				{
					LastPosCheck = 0f;
					if (!HasLostTires)
					{
						moveAud.volume = 0f;
					}
					base.creatureAnimator.SetBool("Moving", false);
				}
				base.creatureAnimator.SetBool("IsRunning", HasLostTires && isRunning.Value);
			}
			base.creatureAnimator.SetBool("IsScared", isVurable.Value);
			if (lastIsScaredCheck != isVurable.Value)
			{
				lastIsScaredCheck = isVurable.Value;
				if (isVurable.Value)
				{
					base.creatureAnimator.SetTrigger("Scared");
				}
			}
			timeSinceHitting += Time.deltaTime;
		}

		public Vector3 ChooseFarthestPositionFromPosition(Vector3 pos, float MaxDistance = 25f)
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_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)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)this).transform.position - pos;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			Vector3 val2 = ((Component)this).transform.position + normalized * MaxDistance;
			Vector3 position = ((Component)this).transform.position;
			float num = 0f;
			NavMeshHit val5 = default(NavMeshHit);
			for (int i = 0; i < 8; i++)
			{
				Vector3 val3 = Random.insideUnitSphere * (MaxDistance * 0.1f);
				val3.y = 0f;
				Vector3 val4 = val2 + val3;
				if (NavMesh.SamplePosition(val4, ref val5, MaxDistance, -1))
				{
					float num2 = Vector3.Distance(((NavMeshHit)(ref val5)).position, pos);
					if (num2 > num && !((EnemyAI)this).PathIsIntersectedByLineOfSight(((NavMeshHit)(ref val5)).position, false, false, false))
					{
						num = num2;
						position = ((NavMeshHit)(ref val5)).position;
					}
				}
			}
			WaterWraithMod.Logger.LogInfo((object)$"Chosen flee position: {position}, Distance: {num}");
			if (num == 0f)
			{
				WaterWraithMod.Logger.LogInfo((object)"Wraith cornnered!");
				SetScaredServerRpc();
			}
			else if (isVurable.Value)
			{
				isVurable.Value = false;
			}
			return position;
		}

		protected override void __initializeVariables()
		{
			if (isVurable == null)
			{
				throw new Exception("WaterWraithAI.isVurable cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)isVurable).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)isVurable, "isVurable");
			((NetworkBehaviour)this).NetworkVariableFields.Add((NetworkVariableBase)(object)isVurable);
			if (isRunning == null)
			{
				throw new Exception("WaterWraithAI.isRunning cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)isRunning).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)isRunning, "isRunning");
			((NetworkBehaviour)this).NetworkVariableFields.Add((NetworkVariableBase)(object)isRunning);
			((EnemyAI)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_WaterWraithAI()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(118134160u, new RpcReceiveHandler(__rpc_handler_118134160));
			NetworkManager.__rpc_func_table.Add(2926869977u, new RpcReceiveHandler(__rpc_handler_2926869977));
			NetworkManager.__rpc_func_table.Add(2232173676u, new RpcReceiveHandler(__rpc_handler_2232173676));
			NetworkManager.__rpc_func_table.Add(3609201593u, new RpcReceiveHandler(__rpc_handler_3609201593));
			NetworkManager.__rpc_func_table.Add(1114460635u, new RpcReceiveHandler(__rpc_handler_1114460635));
		}

		private static void __rpc_handler_118134160(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((WaterWraithAI)(object)target).RemoveTiresServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2926869977(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((WaterWraithAI)(object)target).SetScaredServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2232173676(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((WaterWraithAI)(object)target).RemoveTiresClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3609201593(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((WaterWraithAI)(object)target).KillWraithServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1114460635(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((WaterWraithAI)(object)target).KillWraithClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "WaterWraithAI";
		}
	}
	public class WaterWraithPikminEnemy : PikminEnemy
	{
		private WaterWraithAI waterWraithAI = null;

		public List<EnemyAICollisionDetect> enemyAICollisionDetects = null;

		public List<PikminAI> PikminImmune = new List<PikminAI>();

		protected override void Start()
		{
			((PikminEnemy)this).Start();
			waterWraithAI = (base.enemyScript as WaterWraithAI) ?? throw new Exception("WaterWraithPE: enemyScript is not a WaterWraithAI");
			if ((Object)(object)waterWraithAI == (Object)null)
			{
				((Behaviour)this).enabled = false;
				return;
			}
			base.OverrideCanDie = true;
			foreach (PikminLatchTrigger latchTrigger in base.LatchTriggers)
			{
				Object.Destroy((Object)(object)latchTrigger);
			}
			base.LatchTriggers.Clear();
			WaterWraithMeshOverride[] componentsInChildren = ((Component)this).GetComponentsInChildren<WaterWraithMeshOverride>(true);
			foreach (WaterWraithMeshOverride waterWraithMeshOverride in componentsInChildren)
			{
				GameObject pikminColider = waterWraithMeshOverride.PikminColider;
				pikminColider.gameObject.SetActive(true);
				PikminLatchTrigger item = EnemyAIPatch.AddLatchTriggerToColider(pikminColider.gameObject, ((Component)this).transform);
				base.LatchTriggers.Add(item);
				enemyAICollisionDetects.Add(pikminColider.GetComponent<EnemyAICollisionDetect>());
				WaterWraithMod.Logger.LogInfo((object)("Added " + ((Object)pikminColider).name + " to LatchTriggers"));
			}
		}

		protected void LateUpdate()
		{
			bool value = waterWraithAI.isVurable.Value;
			if (base.CanBeAttacked && !waterWraithAI.isVurable.Value)
			{
				PikminImmune.Clear();
				foreach (PikminLatchTrigger latchTrigger in base.LatchTriggers)
				{
					PikminImmune.AddRange(latchTrigger.PikminOnLatch);
					latchTrigger.RemoveAllPikmin(0);
				}
			}
			base.CanBeAttacked = value;
			foreach (EnemyAICollisionDetect enemyAICollisionDetect in enemyAICollisionDetects)
			{
				((Behaviour)enemyAICollisionDetect).enabled = base.CanBeAttacked;
			}
		}

		protected override void __initializeVariables()
		{
			((PikminEnemy)this).__initializeVariables();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "WaterWraithPikminEnemy";
		}
	}
	public class WraithTire : MonoBehaviour
	{
		public WaterWraithAI ai = null;

		private Dictionary<Collider, float> objectsInTriggerWDelay = new Dictionary<Collider, float>();

		private const float collisionDelay = 0.5f;

		private void OnTriggerEnter(Collider other)
		{
			if (((Behaviour)this).enabled)
			{
				bool flag = false;
				bool flag2 = false;
				EnemyAICollisionDetect component = ((Component)other).GetComponent<EnemyAICollisionDetect>();
				if ((Object)(object)component == (Object)null || (Object)(object)component.mainScript == (Object)null || (Object)(object)component.mainScript.enemyType == (Object)(object)((EnemyAI)ai).enemyType)
				{
					flag = true;
				}
				if ((Object)(object)((Component)other).GetComponent<PlayerControllerB>() == (Object)null)
				{
					flag2 = true;
				}
				if (!(flag && flag2) && !objectsInTriggerWDelay.ContainsKey(other))
				{
					objectsInTriggerWDelay.Add(other, 2f);
				}
			}
		}

		private void OnTriggerExit(Collider other)
		{
		}

		private void OnTriggerStay(Collider other)
		{
			if (!((Behaviour)this).enabled)
			{
				return;
			}
			if (objectsInTriggerWDelay.ContainsKey(other))
			{
				if (((Component)other).CompareTag("Enemy"))
				{
					objectsInTriggerWDelay[other] += Time.deltaTime * 0.35f;
				}
				else
				{
					objectsInTriggerWDelay[other] += Time.deltaTime * WaterWraithMod.PlayerCollisionBufferMultiplier.Value;
				}
				if (objectsInTriggerWDelay[other] >= 0.5f)
				{
					HandleCollision(other);
					objectsInTriggerWDelay[other] = 0f;
				}
			}
		}

		private void HandleCollision(Collider other)
		{
			if (!((Behaviour)this).enabled)
			{
				return;
			}
			PlayerControllerB component = ((Component)other).GetComponent<PlayerControllerB>();
			if ((Object)(object)component != (Object)null && !component.isPlayerDead)
			{
				ai.DamagePlayer(component);
				return;
			}
			EnemyAI val = ((Component)other).GetComponent<EnemyAICollisionDetect>()?.mainScript;
			if ((Object)(object)val != (Object)null && !val.isEnemyDead)
			{
				ai.DamageEnemy(val);
				return;
			}
			objectsInTriggerWDelay.Remove(other);
			WaterWraithMod.Logger.LogInfo((object)("Remvoing null/dead component from trigger: " + ((other != null) ? ((Object)other).name : null)));
		}

		public List<Collider> GetobjectsInTriggerWDelay()
		{
			return new List<Collider>(objectsInTriggerWDelay.Keys);
		}

		public List<T> GetObjectsOfType<T>() where T : Component
		{
			return (from c in objectsInTriggerWDelay.Keys
				select ((Component)c).GetComponent<T>() into component
				where (Object)(object)component != (Object)null
				select component).ToList();
		}
	}
}
namespace WaterWraithMod.Patches
{
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal class GameNetworkManagerPatch
	{
		public static bool HasInitalized;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void Init(GameNetworkManager __instance)
		{
			if (HasInitalized)
			{
				WaterWraithMod.Logger.LogWarning((object)"Already initalized WaterWraithMod");
				return;
			}
			EnemyType val = WaterWraithMod.assetBundle.LoadAsset<EnemyType>("Assets/ModAsset/WaterType.asset");
			NetworkManager.Singleton.AddNetworkPrefab(val.enemyPrefab);
			WaterWraithMod.Logger.LogInfo((object)"WaterWraithMod initialized on network");
			HasInitalized = true;
		}
	}
	[HarmonyPatch(typeof(PurplePikminAI))]
	internal class PurplePikminAIPatch
	{
		[HarmonyPatch("DoSlam")]
		[HarmonyPostfix]
		public static void SlamDone(PurplePikminAI __instance)
		{
			//IL_0017: 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)
			WaterWraithAI[] array = Object.FindObjectsOfType<WaterWraithAI>();
			foreach (WaterWraithAI waterWraithAI in array)
			{
				if (Vector3.Distance(((Component)waterWraithAI).transform.position, ((Component)__instance).transform.position) < 10f && !waterWraithAI.isVurable.Value)
				{
					waterWraithAI.SetScaredServerRpc();
				}
			}
		}
	}
	public enum WraithSpawnPosition
	{
		OnlyIndoors,
		OnlyOutdoors,
		IndoorsAndOutdoors
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		public static bool IsSpawningWaterWraithThisRound;

		public static float WWTimer;

		[HarmonyPatch("PredictAllOutsideEnemies")]
		[HarmonyPostfix]
		public static void PredictAllOutsideEnemiesPostFix(RoundManager __instance)
		{
			if (!((NetworkBehaviour)__instance).IsServer || RoundManager.Instance.currentLevel.sceneName == "CompanyBuilding")
			{
				return;
			}
			IsSpawningWaterWraithThisRound = false;
			float num = Random.Range(0f, 100f);
			float value = WaterWraithMod.SpawnChanceConfig.Value;
			foreach (string key in WaterWraithMod.GetParsedMoonSpawn().Keys)
			{
				if (__instance.currentLevel.PlanetName.Contains(key))
				{
					WaterWraithMod.GetParsedMoonSpawn().TryGetValue(key, out value);
					WaterWraithMod.Logger.LogInfo((object)$"override value: {value}");
					break;
				}
			}
			WaterWraithMod.Logger.LogInfo((object)$"RNG: {num}, CHANCE: {value}");
			if (num < value)
			{
				WWTimer = WaterWraithMod.SpawnTimerConfig.Value;
				IsSpawningWaterWraithThisRound = true;
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void UpdatePostfix(RoundManager __instance)
		{
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Expected O, but got Unknown
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: 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_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)__instance).IsServer || StartOfRound.Instance.inShipPhase || StartOfRound.Instance.livingPlayers == 0 || !IsSpawningWaterWraithThisRound)
			{
				return;
			}
			if (WWTimer > 0f)
			{
				WWTimer -= Time.deltaTime;
				return;
			}
			IsSpawningWaterWraithThisRound = false;
			GameObject[] array = GameObject.FindGameObjectsWithTag("AINode");
			GameObject[] array2 = GameObject.FindGameObjectsWithTag("OutsideAINode");
			EnemyType val = WaterWraithMod.assetBundle.LoadAsset<EnemyType>("Assets/ModAsset/WaterType.asset");
			int num = -1;
			for (int i = 0; i < __instance.currentLevel.Enemies.Count; i++)
			{
				EnemyType enemyType = __instance.currentLevel.Enemies[i].enemyType;
				if ((Object)(object)enemyType == (Object)(object)val)
				{
					num = i;
					WaterWraithMod.Logger.LogInfo((object)$"Found a WaterWraith at index {i} in the enemies list!");
					break;
				}
			}
			if (num == -1)
			{
				WaterWraithMod.Logger.LogWarning((object)"No WaterWraith found in the enemies list! Injecting...");
				SpawnableEnemyWithRarity val2 = new SpawnableEnemyWithRarity();
				val2.enemyType = val;
				val2.rarity = 0;
				__instance.currentLevel.Enemies.Add(val2);
				num = __instance.currentLevel.Enemies.IndexOf(val2);
				WaterWraithMod.Logger.LogInfo((object)$"WaterWraith added to the enemies list at index {num}");
			}
			switch (WaterWraithMod.WraithSpawnPositionConfig.Value)
			{
			case WraithSpawnPosition.OnlyIndoors:
				if (array.Length != 0)
				{
					__instance.SpawnEnemyOnServer(array[Random.Range(0, array.Length)].transform.position, val.enemyPrefab.transform.rotation.y, num);
				}
				break;
			case WraithSpawnPosition.OnlyOutdoors:
				if (array2.Length != 0)
				{
					__instance.SpawnEnemyOnServer(array2[Random.Range(0, array2.Length)].transform.position, val.enemyPrefab.transform.rotation.y, num);
				}
				break;
			case WraithSpawnPosition.IndoorsAndOutdoors:
			{
				float num2 = Random.Range(0f, 100f);
				float value = WaterWraithMod.WaterWaithSpawnPositionChance.Value;
				Vector3 val3 = Vector3.zero;
				if (num2 < value)
				{
					if (array2.Length != 0)
					{
						val3 = array2[Random.Range(0, array2.Length)].transform.position;
					}
				}
				else if (array.Length != 0)
				{
					val3 = array[Random.Range(0, array.Length)].transform.position;
				}
				__instance.SpawnEnemyOnServer(val3, val.enemyPrefab.transform.rotation.y, num);
				break;
			}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace NoteBoxz.WaterWraith.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}