Decompiled source of WaterWraith v1.0.0

NoteBoxz.WaterWraith.dll

Decompiled 4 hours 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.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using NoteBoxz.WaterWraith.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
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("DissonanceVoip")]
[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("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f9611abfde58b816d64a940a8e697c03841a83f8")]
[assembly: AssemblyProduct("WaterWraithMod")]
[assembly: AssemblyTitle("NoteBoxz.WaterWraith")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
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)
	{
		audioSource.PlayOneShot(audioClips[index], audioSource.volume);
	}
}
public enum GameStle
{
	Pikmin4,
	Pikmin2
}
[Serializable]
public class WaterWraithMeshOverride
{
	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 class WaterWraithMesh : MonoBehaviour
{
	public List<WaterWraithMeshOverride> overrides = new List<WaterWraithMeshOverride>();

	public WaterWraithAI AI = null;

	public void SetOverride(int index)
	{
		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;
			}
			else
			{
				waterWraithMeshOverride.Object.SetActive(false);
			}
		}
	}

	[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();
		}
	}
}
[Serializable]
public class WraithProximityAnimEvent
{
	public bool CamShake;

	public ScreenShakeType screenShakeTypeNear;

	public float DistanceThresholdDistanceNear = 10f;

	public ScreenShakeType screenShakeTypeFar;

	public float DistanceThresholdDistanceFar = 20f;

	public float FearFactor = -1f;
}
public class WraithProximityAnimEventChecks : MonoBehaviour
{
	public List<WraithProximityAnimEvent> animEvents = new List<WraithProximityAnimEvent>();

	public void DoCheck(int index)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: 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)
		WraithProximityAnimEvent wraithProximityAnimEvent = animEvents[index];
		PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
		if (wraithProximityAnimEvent.CamShake)
		{
			if (Vector3.Distance(((Component)localPlayerController).transform.position, ((Component)this).transform.position) < wraithProximityAnimEvent.DistanceThresholdDistanceNear)
			{
				HUDManager.Instance.ShakeCamera(wraithProximityAnimEvent.screenShakeTypeNear);
			}
			else if (Vector3.Distance(((Component)localPlayerController).transform.position, ((Component)this).transform.position) < wraithProximityAnimEvent.DistanceThresholdDistanceFar)
			{
				HUDManager.Instance.ShakeCamera(wraithProximityAnimEvent.screenShakeTypeFar);
			}
		}
		if (wraithProximityAnimEvent.FearFactor > 0f && Vector3.Distance(((Component)localPlayerController).transform.position, ((Component)this).transform.position) < wraithProximityAnimEvent.DistanceThresholdDistanceFar)
		{
			localPlayerController.JumpToFearLevel(wraithProximityAnimEvent.FearFactor, true);
		}
	}
}
namespace WaterWraithMod
{
	[BepInPlugin("NoteBoxz.WaterWraith", "WaterWraithMod", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class WaterWraithMod : BaseUnityPlugin
	{
		public static ConfigEntry<float> SpawnChanceConfig;

		public static ConfigEntry<float> SpawnTimerConfig;

		public static ConfigEntry<bool> ChaseEnemyConfig;

		public static ConfigEntry<int> DamageConfig;

		public static ConfigEntry<WraithSpawnPosition> WraithSpawnPositionConfig;

		public static ConfigEntry<GameStle> gameStleConfig;

		public static WaterWraithMod Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		internal static AssetBundle assetBundle { get; private set; }

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

		public void BindConfigs()
		{
			SpawnChanceConfig = ((BaseUnityPlugin)this).Config.Bind<float>("WaterWraith", "Spawn Chance", 25f, "The chance for a Water Wraith to spawn.");
			ChaseEnemyConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("WaterWraith", "Chase Enemys", true, "Makes the water wraith chase enemies as well as players.");
			WraithSpawnPositionConfig = ((BaseUnityPlugin)this).Config.Bind<WraithSpawnPosition>("WaterWraith", "Wraith Spawn Position", WraithSpawnPosition.OnlyIndoors, "The position where the Water Wraith will spawn.");
			SpawnTimerConfig = ((BaseUnityPlugin)this).Config.Bind<float>("WaterWraith", "Spawn Timer (Seconds)", 180f, "The amount of time it takes for the wraith to spawn.");
			DamageConfig = ((BaseUnityPlugin)this).Config.Bind<int>("WaterWraith", "Damage", 50, "The ammount of damage the water wraith deals.");
			gameStleConfig = ((BaseUnityPlugin)this).Config.Bind<GameStle>("WaterWraith", "Game Stle", GameStle.Pikmin4, "The game stle of the water wraith.");
			gameStleConfig.SettingChanged += delegate
			{
				UpdateAllOverrides();
			};
		}

		public void UpdateAllOverrides()
		{
			try
			{
				WaterWraithMesh[] array = Object.FindObjectsOfType<WaterWraithMesh>();
				foreach (WaterWraithMesh waterWraithMesh in array)
				{
					waterWraithMesh.SetOverride((int)gameStleConfig.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()
		{
			EnemyType val = assetBundle.LoadAsset<EnemyType>("Assets/ModAsset/WaterType.asset");
			TerminalNode val2 = assetBundle.LoadAsset<TerminalNode>("Assets/ModAsset/WaterNode.asset");
			Enemies.RegisterEnemy(val, 0, (LevelTypes)(-1), val2, (TerminalKeyword)null);
		}

		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...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}

		private void NetcodePatcher()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "NoteBoxz.WaterWraith";

		public const string PLUGIN_NAME = "WaterWraithMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace WaterWraithMod.Scripts
{
	public class WaterWraithAI : EnemyAI
	{
		public AISearchRoutine roamFactory = null;

		public EnemyAI TargetEnemy = null;

		public List<EnemyAI> TargetedEnemies = null;

		public WaterWraithMesh WMesh = null;

		public AudioSource moveAud = null;

		public AudioClip KillSFX = null;

		public bool CanEnterState2 = false;

		public bool IsChaseingEnemy = false;

		public bool IsWandering = false;

		private float timeSinceHitting;

		private Vector3 LastPosition;

		private float LastPosCheck;

		public override void Start()
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Start();
			moveAud.volume = 0f;
			base.inSpecialAnimation = true;
			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.isOutside = true;
			}
			else
			{
				WaterWraithMod.Logger.LogInfo((object)"WaterWraith: WaterWraith determined it spawned inside");
				base.isOutside = false;
			}
			WMesh.SetOverride((int)WaterWraithMod.gameStleConfig.Value);
			((MonoBehaviour)this).StartCoroutine(WaitForCrush());
		}

		private IEnumerator WaitForCrush()
		{
			yield return (object)new WaitForSeconds(8.5f);
			base.inSpecialAnimation = false;
			WaterWraithMod.Logger.LogInfo((object)"WaterWraith: Should be able to move now");
			yield return (object)new WaitForSeconds(2f);
			CanEnterState2 = true;
		}

		public override void DoAIInterval()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).DoAIInterval();
			if (StartOfRound.Instance.livingPlayers == 0 || base.isEnemyDead)
			{
				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, roamFactory);
					IsWandering = true;
				}
				if (Object.op_Implicit((Object)(object)((EnemyAI)this).CheckLineOfSightForPlayer(360f, 15, -1)) && CanEnterState2)
				{
					((EnemyAI)this).StopSearch(roamFactory, true);
					((EnemyAI)this).SetMovingTowardsTargetPlayer(((EnemyAI)this).CheckLineOfSightForPlayer(360f, 15, -1));
					IsChaseingEnemy = false;
					WaterWraithMod.Logger.LogInfo((object)"WaterWraith: Chasing player");
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
					break;
				}
				List<GameObject> list = (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();
				if (Object.op_Implicit((Object)(object)((EnemyAI)this).CheckLineOfSight(list, 360f, 15, -1f, (Transform)null, (int[])null)) && CanEnterState2 && WaterWraithMod.ChaseEnemyConfig.Value && (Object)(object)((EnemyAI)this).CheckLineOfSight(list, 360f, 15, -1f, (Transform)null, (int[])null).GetComponentInChildren<EnemyAI>() != (Object)null)
				{
					((EnemyAI)this).StopSearch(roamFactory, true);
					TargetEnemy = ((EnemyAI)this).CheckLineOfSight(list, 360f, 15, -1f, (Transform)null, (int[])null).GetComponentInChildren<EnemyAI>();
					IsChaseingEnemy = true;
					WaterWraithMod.Logger.LogInfo((object)"WaterWraith: Chasing enemy");
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
				}
				break;
			}
			case 1:
				if (IsWandering)
				{
					((EnemyAI)this).StopSearch(roamFactory, true);
					IsWandering = false;
				}
				if (IsChaseingEnemy && ((Object)(object)TargetEnemy == (Object)null || TargetEnemy.isEnemyDead || TargetedEnemies.Contains(TargetEnemy) || Vector3.Distance(((Component)this).transform.position, ((Component)TargetEnemy).transform.position) > 20f))
				{
					TargetEnemy = null;
					IsChaseingEnemy = false;
					WaterWraithMod.Logger.LogInfo((object)"WaterWraith: stopped Chasing enemy");
					((EnemyAI)this).SwitchToBehaviourClientRpc(0);
					break;
				}
				if (IsChaseingEnemy)
				{
					((EnemyAI)this).SetDestinationToPosition(((Component)TargetEnemy).transform.position, false);
				}
				if (!IsChaseingEnemy && ((Object)(object)base.targetPlayer == (Object)null || base.targetPlayer.isPlayerDead || !base.targetPlayer.isPlayerControlled || Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) > 30f))
				{
					base.targetPlayer = null;
					base.movingTowardsTargetPlayer = false;
					if (Vector3.Distance(((Component)this).transform.position, RoundManager.FindMainEntrancePosition(false, false)) < 10f)
					{
						roamFactory.currentTargetNode = ((Component)((EnemyAI)this).ChooseFarthestNodeFromPosition(RoundManager.FindMainEntrancePosition(false, false), false, 0, false, 50, false)).gameObject;
						roamFactory.choseTargetNode = true;
						WaterWraithMod.Logger.LogInfo((object)"WaterWraith: Setting position away from main");
					}
					WaterWraithMod.Logger.LogInfo((object)"WaterWraith: stopped Chasing player");
					((EnemyAI)this).SwitchToBehaviourClientRpc(0);
				}
				break;
			}
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).OnCollideWithPlayer(other);
			if (timeSinceHitting < 0.5f)
			{
				return;
			}
			timeSinceHitting = 0f;
			PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
			if ((Object)(object)component != (Object)null)
			{
				Vector3 forward = ((Component)component).transform.forward;
				component.DamagePlayer(WaterWraithMod.DamageConfig.Value, true, true, (CauseOfDeath)8, 1, false, forward * 25f);
				if (component.isPlayerDead)
				{
					base.creatureSFX.PlayOneShot(KillSFX);
				}
				else
				{
					component.externalForceAutoFade += -forward * 5f;
				}
			}
		}

		public override void OnCollideWithEnemy(Collider other, EnemyAI collidedEnemy = null)
		{
			((EnemyAI)this).OnCollideWithEnemy(other, collidedEnemy);
			if (timeSinceHitting < 0.5f)
			{
				return;
			}
			timeSinceHitting = 0f;
			if ((Object)(object)collidedEnemy != (Object)null)
			{
				collidedEnemy.HitEnemy(2, (PlayerControllerB)null, true, -1);
				if (!collidedEnemy.isEnemyDead)
				{
					collidedEnemy.stunNormalizedTimer = Random.Range(0.1f, 1f);
				}
				TargetedEnemies.Add(collidedEnemy);
			}
		}

		private void LateUpdate()
		{
			//IL_0080: 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_0018: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			if (((NetworkBehaviour)this).IsServer)
			{
				AudioSource obj = moveAud;
				Vector3 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);
			}
			else
			{
				LastPosCheck += Time.deltaTime;
				if (Vector3.Distance(LastPosition, ((Component)this).transform.position) > 0.1f)
				{
					LastPosition = ((Component)this).transform.position;
					moveAud.volume = 1f;
					base.creatureAnimator.SetBool("Moving", true);
				}
				else if (LastPosCheck > 1f)
				{
					LastPosCheck = 0f;
					moveAud.volume = 0f;
					base.creatureAnimator.SetBool("Moving", false);
				}
			}
			timeSinceHitting += Time.deltaTime;
		}

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

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "WaterWraithAI";
		}
	}
}
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;
		}
	}
	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"))
			{
				IsSpawningWaterWraithThisRound = false;
				float num = Random.Range(0f, 100f);
				if (num < WaterWraithMod.SpawnChanceConfig.Value)
				{
					WWTimer = WaterWraithMod.SpawnTimerConfig.Value;
					IsSpawningWaterWraithThisRound = true;
					WaterWraithMod.Logger.LogMessage((object)"Spawning water wraith!!!!!!!!!!!!!!!!!!!!!!!!!!");
				}
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void UpdatePostfix(RoundManager __instance)
		{
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			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.LogError((object)"No WaterWraith found in the enemies list!");
				return;
			}
			int num2 = Random.Range(0, 100);
			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:
			{
				List<GameObject> list = new List<GameObject>();
				list.AddRange(array2);
				list.AddRange(array);
				if (list.Count > 0)
				{
					__instance.SpawnEnemyOnServer(list[Random.Range(0, list.Count)].transform.position, 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
	{
	}
}