Decompiled source of RatKing v1.0.0

RoiDesRats.dll

Decompiled 35 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using REPOLib.Modules;
using REPOLib.Objects.Sdk;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace RoiDesRats
{
	internal static class Snd
	{
		public static void Play(Sound s, Vector3 pos, float volume = 1f, float pitch = 1f)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if (s == null || s.Sounds == null || s.Sounds.Length == 0)
			{
				return;
			}
			float pitch2 = s.Pitch;
			try
			{
				s.Pitch = pitch2 * pitch;
				s.Play(pos, volume, 1f, 1f, 1f);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("Sound play failed: " + ex.Message));
			}
			finally
			{
				s.Pitch = pitch2;
			}
		}

		public static Sound Make(string name, float volume, float spatial, float pitchRandom, params string[] wavs)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			List<AudioClip> list = new List<AudioClip>();
			foreach (string text in wavs)
			{
				try
				{
					list.Add(Wav.Load("RoiDesRats." + text, name + " " + text));
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Sound " + text + ": " + ex.Message));
				}
			}
			return new Sound
			{
				Sounds = list.ToArray(),
				Type = (AudioType)0,
				Volume = volume,
				VolumeRandom = 0.05f,
				Pitch = 1f,
				PitchRandom = pitchRandom,
				SpatialBlend = spatial,
				Doppler = 0f,
				ReverbMix = 1f,
				FalloffMultiplier = 1f,
				OffscreenVolume = 1f,
				OffscreenFalloff = 1f,
				LowPassIgnoreColliders = new List<Collider>()
			};
		}

		public static Sound Loop(Sound from, AudioSource src, float volume)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0059: 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_006f: 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_0085: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			if (from == null || (Object)(object)src == (Object)null)
			{
				return null;
			}
			return new Sound
			{
				Sounds = from.Sounds,
				Type = (AudioType)0,
				Volume = volume,
				VolumeRandom = 0f,
				Pitch = 1f,
				PitchRandom = 0f,
				SpatialBlend = 1f,
				Doppler = 0f,
				ReverbMix = 1f,
				FalloffMultiplier = 1f,
				OffscreenVolume = 1f,
				OffscreenFalloff = 1f,
				LowPassIgnoreColliders = new List<Collider>(),
				Source = src
			};
		}

		public static AudioSource Source(Transform parent, string name, float minD, float maxD)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			AudioSource obj = val.AddComponent<AudioSource>();
			obj.playOnAwake = false;
			obj.loop = true;
			obj.spatialBlend = 1f;
			obj.rolloffMode = (AudioRolloffMode)1;
			obj.minDistance = minD;
			obj.maxDistance = maxD;
			obj.dopplerLevel = 0f;
			obj.volume = 0f;
			return obj;
		}

		public static void Route(AudioSource src)
		{
			if (Object.op_Implicit((Object)(object)src) && Object.op_Implicit((Object)(object)AudioManager.instance))
			{
				src.outputAudioMixerGroup = AudioManager.instance.SoundMasterGroup;
			}
		}

		public static void PlayLoop(Sound s, bool on, float fadeIn, float fadeOut, float pitch = 1f, float vol = 1f)
		{
			if (s == null || (Object)(object)s.Source == (Object)null)
			{
				return;
			}
			try
			{
				s.PlayLoop(on, fadeIn, fadeOut, pitch, vol);
			}
			catch (Exception)
			{
			}
		}
	}
	internal static class Wav
	{
		public static AudioClip Load(string resource, string clipName)
		{
			byte[] array = Resource.Embedded(resource);
			int num = BitConverter.ToInt16(array, 22);
			int num2 = BitConverter.ToInt32(array, 24);
			if (BitConverter.ToInt16(array, 34) != 16)
			{
				throw new Exception("only 16-bit PCM");
			}
			int i = 12;
			int num3 = -1;
			int num4 = 0;
			int num5;
			for (; i + 8 <= array.Length; i += 8 + num5 + (num5 & 1))
			{
				string text = Encoding.ASCII.GetString(array, i, 4);
				num5 = BitConverter.ToInt32(array, i + 4);
				if (text == "data")
				{
					num3 = i + 8;
					num4 = num5;
					break;
				}
			}
			if (num3 < 0)
			{
				throw new Exception("no data chunk");
			}
			int num6 = num4 / 2;
			float[] array2 = new float[num6];
			for (int j = 0; j < num6; j++)
			{
				array2[j] = (float)BitConverter.ToInt16(array, num3 + j * 2) / 32768f;
			}
			AudioClip obj = AudioClip.Create(clipName, num6 / num, num, num2, false);
			obj.SetData(array2, 0);
			((Object)obj).hideFlags = (HideFlags)32;
			return obj;
		}
	}
	internal static class Resource
	{
		public static T Load<T>(string path) where T : Object
		{
			T val = Resources.Load<T>(path);
			if ((Object)(object)val == (Object)null)
			{
				val = Resources.Load<T>(path.ToLowerInvariant());
			}
			return val;
		}

		public static byte[] Embedded(string name)
		{
			using Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream(name);
			if (stream == null)
			{
				throw new FileNotFoundException("Embedded resource missing: " + name);
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		public static T AnimOf<T>(string path) where T : Component
		{
			GameObject val = Resource.Load<GameObject>(path);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return default(T);
			}
			return val.GetComponentInChildren<T>(true);
		}
	}
	internal static class U
	{
		public static bool MP => GameManager.Multiplayer();

		public static bool Master => SemiFunc.IsMasterClientOrSingleplayer();

		public static Vector3 Flat(Vector3 v)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			v.y = 0f;
			return v;
		}

		public static bool Valid(PlayerAvatar p)
		{
			if ((Object)(object)p != (Object)null && !p.isDisabled)
			{
				return !p.deadSet;
			}
			return false;
		}

		public static float Damp(float c, float t, float s, float dt)
		{
			return Mathf.Lerp(c, t, 1f - Mathf.Exp((0f - s) * dt));
		}

		public static float Smooth(float a, float b, float x)
		{
			float num = Mathf.Clamp01((x - a) / (b - a));
			return num * num * (3f - 2f * num);
		}

		public static Vector3 Body(PlayerAvatar p)
		{
			//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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)p.tumble) || !p.tumble.isTumbling)
			{
				return ((Component)p).transform.position + Vector3.up * 0.9f;
			}
			return ((Component)p.tumble).transform.position;
		}

		public static PlayerAvatar Find(int viewId)
		{
			if (viewId < 0)
			{
				return null;
			}
			PhotonView val = PhotonView.Find(viewId);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			return ((Component)val).GetComponent<PlayerAvatar>();
		}

		public static int Id(PlayerAvatar p)
		{
			if (!Object.op_Implicit((Object)(object)p) || !Object.op_Implicit((Object)(object)p.photonView))
			{
				return -1;
			}
			return p.photonView.ViewID;
		}

		public static List<PlayerAvatar> Players()
		{
			return SemiFunc.PlayerGetList() ?? new List<PlayerAvatar>();
		}

		public static void Shake(Vector3 pos, float strength, float time, float dMin, float dMax)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (Object.op_Implicit((Object)(object)GameDirector.instance) && Object.op_Implicit((Object)(object)GameDirector.instance.CameraShake))
				{
					GameDirector.instance.CameraShake.ShakeDistance(strength, dMin, dMax, pos, time);
				}
			}
			catch (Exception)
			{
			}
		}

		public static void Hurt(PlayerAvatar p, int dmg, Enemy by)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if (Valid(p) && dmg > 0 && Object.op_Implicit((Object)(object)p.playerHealth))
			{
				p.playerHealth.HurtOther(dmg, ((Component)p).transform.position + Vector3.up, false, SemiFunc.EnemyGetIndex(by), false);
			}
		}

		public static Vector3 TruckPos()
		{
			//IL_002a: 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)
			LevelGenerator instance = LevelGenerator.Instance;
			if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)instance.LevelPathTruck))
			{
				return new Vector3(9999f, 9999f, 9999f);
			}
			return ((Component)instance.LevelPathTruck).transform.position;
		}

		public static void DestroyLater(GameObject go, float delay)
		{
			if (Object.op_Implicit((Object)(object)Plugin.Instance) && Object.op_Implicit((Object)(object)go))
			{
				((MonoBehaviour)Plugin.Instance).StartCoroutine(DestroyRun(go, delay));
			}
		}

		private static IEnumerator DestroyRun(GameObject go, float delay)
		{
			yield return (object)new WaitForSeconds(delay);
			if (Object.op_Implicit((Object)(object)go))
			{
				Object.Destroy((Object)(object)go);
			}
		}

		public static PlayerAvatar BreakGrabs(PhysGrabObject pgo)
		{
			if (!Object.op_Implicit((Object)(object)pgo) || pgo.playerGrabbing.Count == 0)
			{
				return null;
			}
			PlayerAvatar val = null;
			int num = (Object.op_Implicit((Object)(object)pgo.photonView) ? pgo.photonView.ViewID : (-1));
			foreach (PhysGrabber item in new List<PhysGrabber>(pgo.playerGrabbing))
			{
				if (Object.op_Implicit((Object)(object)item))
				{
					if (!Object.op_Implicit((Object)(object)val) && Valid(item.playerAvatar))
					{
						val = item.playerAvatar;
					}
					if (SemiFunc.IsMultiplayer())
					{
						item.ReleaseObject(num, 1.5f);
					}
					else
					{
						item.OverrideGrabRelease(num, 1.5f);
					}
				}
			}
			return val;
		}

		public static bool Linecast(Vector3 a, Vector3 b, int mask, out RaycastHit hit)
		{
			//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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			bool queriesHitBackfaces = Physics.queriesHitBackfaces;
			Physics.queriesHitBackfaces = true;
			try
			{
				bool num = Physics.Linecast(a, b, ref hit, mask, (QueryTriggerInteraction)1);
				if (num && Vector3.Dot(((RaycastHit)(ref hit)).normal, b - a) > 0f)
				{
					((RaycastHit)(ref hit)).normal = -((RaycastHit)(ref hit)).normal;
				}
				return num;
			}
			finally
			{
				Physics.queriesHitBackfaces = queriesHitBackfaces;
			}
		}

		public static bool Blocked(Vector3 a, Vector3 b, int mask)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit hit;
			return Linecast(a, b, mask, out hit);
		}

		public static bool Raycast(Vector3 o, Vector3 dir, float max, int mask, out RaycastHit hit)
		{
			//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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			bool queriesHitBackfaces = Physics.queriesHitBackfaces;
			Physics.queriesHitBackfaces = true;
			try
			{
				bool num = Physics.Raycast(o, dir, ref hit, max, mask, (QueryTriggerInteraction)1);
				if (num && Vector3.Dot(((RaycastHit)(ref hit)).normal, dir) > 0f)
				{
					((RaycastHit)(ref hit)).normal = -((RaycastHit)(ref hit)).normal;
				}
				return num;
			}
			finally
			{
				Physics.queriesHitBackfaces = queriesHitBackfaces;
			}
		}

		public static bool InSafeRoom(Vector3 p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			Collider[] array = Physics.OverlapSphere(p, 0.25f, -1, (QueryTriggerInteraction)2);
			foreach (Collider val in array)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					RoomVolume componentInParent = ((Component)val).GetComponentInParent<RoomVolume>();
					if (Object.op_Implicit((Object)(object)componentInParent) && (componentInParent.Truck || componentInParent.Extraction))
					{
						return true;
					}
				}
			}
			return false;
		}
	}
	internal interface IHeavyHit
	{
		void HeavyHit(PhysGrabObject by, float speed, Vector3 point);
	}
	public class HeavyImpact : MonoBehaviour
	{
		internal IHeavyHit ai;

		internal static float MinMass = 2f;

		internal static float MinSpeed = 4f;

		private void OnCollisionEnter(Collision c)
		{
			//IL_0057: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			if (ai == null || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			Rigidbody rigidbody = c.rigidbody;
			if ((Object)(object)rigidbody == (Object)null || rigidbody.isKinematic)
			{
				return;
			}
			PhysGrabObject component = ((Component)rigidbody).GetComponent<PhysGrabObject>();
			if ((Object)(object)component == (Object)null || (Object)(object)((Component)rigidbody).GetComponent<PlayerAvatar>() != (Object)null || (Object)(object)((Component)rigidbody).GetComponentInParent<Enemy>() != (Object)null)
			{
				return;
			}
			Vector3 relativeVelocity = c.relativeVelocity;
			float magnitude = ((Vector3)(ref relativeVelocity)).magnitude;
			if (rigidbody.mass >= MinMass && magnitude >= MinSpeed)
			{
				IHeavyHit heavyHit = ai;
				Vector3 point;
				if (c.contactCount <= 0)
				{
					point = ((Component)this).transform.position;
				}
				else
				{
					ContactPoint contact = c.GetContact(0);
					point = ((ContactPoint)(ref contact)).point;
				}
				heavyHit.HeavyHit(component, magnitude, point);
			}
		}
	}
	internal struct Part
	{
		public Mesh Mesh;

		public int[] MatIds;
	}
	internal static class Kit
	{
		public static Material[] Materials;

		public static Texture2D Atlas;

		private static Material baseMat;

		private static Shader standard;

		public static void Init()
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			Atlas = new Texture2D(2, 2, (TextureFormat)4, true);
			ImageConversion.LoadImage(Atlas, Resource.Embedded("RoiDesRats.atlas.png"), false);
			((Object)Atlas).name = "RoiDesRats Atlas";
			((Texture)Atlas).wrapMode = (TextureWrapMode)1;
			((Texture)Atlas).filterMode = (FilterMode)2;
			((Texture)Atlas).anisoLevel = 4;
			Atlas.Apply(true, true);
			((Object)Atlas).hideFlags = (HideFlags)32;
			GameObject val = Resource.Load<GameObject>("Valuables/03 Medium/Valuable Manor Vase");
			if (Object.op_Implicit((Object)(object)val))
			{
				MeshRenderer componentInChildren = val.GetComponentInChildren<MeshRenderer>(true);
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					baseMat = ((Renderer)componentInChildren).sharedMaterial;
				}
			}
			standard = Shader.Find("Standard");
		}

		public static Material Mat(string name, float gloss, float metal, Color emission, float alpha = 1f)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_00b5: 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_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			bool num = alpha < 0.999f;
			Material val = ((!num || !Object.op_Implicit((Object)(object)standard) || (Object.op_Implicit((Object)(object)baseMat) && !(((Object)baseMat.shader).name != "Standard"))) ? (Object.op_Implicit((Object)(object)baseMat) ? new Material(baseMat) : new Material(Object.op_Implicit((Object)(object)standard) ? standard : Shader.Find("Diffuse"))) : new Material(standard));
			((Object)val).name = "RoiDesRats " + name;
			val.mainTexture = (Texture)(object)Atlas;
			val.color = new Color(1f, 1f, 1f, alpha);
			if (val.HasProperty("_Glossiness"))
			{
				val.SetFloat("_Glossiness", gloss);
			}
			if (val.HasProperty("_Metallic"))
			{
				val.SetFloat("_Metallic", metal);
			}
			if (((Color)(ref emission)).maxColorComponent > 0.001f && val.HasProperty("_EmissionColor"))
			{
				val.EnableKeyword("_EMISSION");
				val.SetColor("_EmissionColor", emission);
				if (val.HasProperty("_EmissionMap"))
				{
					val.SetTexture("_EmissionMap", (Texture)(object)Atlas);
				}
				val.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1;
			}
			else
			{
				val.DisableKeyword("_EMISSION");
				if (val.HasProperty("_EmissionColor"))
				{
					val.SetColor("_EmissionColor", Color.black);
				}
			}
			if (num)
			{
				if (val.HasProperty("_Mode"))
				{
					val.SetFloat("_Mode", 2f);
				}
				val.SetOverrideTag("RenderType", "Transparent");
				val.SetInt("_SrcBlend", 5);
				val.SetInt("_DstBlend", 10);
				val.SetInt("_ZWrite", 0);
				val.DisableKeyword("_ALPHATEST_ON");
				val.EnableKeyword("_ALPHABLEND_ON");
				val.DisableKeyword("_ALPHAPREMULTIPLY_ON");
				val.renderQueue = 3000;
			}
			((Object)val).hideFlags = (HideFlags)32;
			return val;
		}

		public static Material[] MatsFor(int[] ids)
		{
			Material[] array = (Material[])(object)new Material[ids.Length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = Materials[Mathf.Clamp(ids[i], 0, Materials.Length - 1)];
			}
			return array;
		}

		public static Transform MakePart(string name, Part p, Transform parent, Vector3 localPos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPos;
			val.AddComponent<MeshFilter>().sharedMesh = p.Mesh;
			((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterials = MatsFor(p.MatIds);
			return val.transform;
		}

		public static GameObject Prop(string name, Part p, Vector3 pos, Quaternion rot, float scale = 1f)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetPositionAndRotation(pos, rot);
			val.transform.localScale = Vector3.one * scale;
			val.AddComponent<MeshFilter>().sharedMesh = p.Mesh;
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterials = MatsFor(p.MatIds);
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1;
			return val;
		}

		public static Dictionary<string, Transform> Build(Transform model, Dictionary<string, Part> parts, Dictionary<string, Part> detached)
		{
			//IL_0071: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, Transform> dictionary = new Dictionary<string, Transform>();
			for (int i = 0; i < ModelLayout.Parts.Length; i++)
			{
				string text = ModelLayout.Parts[i];
				if (Array.IndexOf(ModelLayout.Detached, text) >= 0)
				{
					if (detached != null)
					{
						detached[text] = parts[text];
					}
				}
				else
				{
					string text2 = ModelLayout.Parents[i];
					Transform parent = (string.IsNullOrEmpty(text2) ? model : dictionary[text2]);
					Vector3 val = (string.IsNullOrEmpty(text2) ? Vector3.zero : ModelLayout.Pivots[Array.IndexOf(ModelLayout.Parts, text2)]);
					dictionary[text] = MakePart(text, parts[text], parent, ModelLayout.Pivots[i] - val);
				}
			}
			return dictionary;
		}

		public static Dictionary<string, Part> LoadMeshes(byte[] data)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			Dictionary<string, Part> dictionary = new Dictionary<string, Part>();
			using BinaryReader binaryReader = new BinaryReader(new MemoryStream(data));
			if (new string(binaryReader.ReadChars(4)) != "FMSH")
			{
				throw new Exception("Bad mesh data");
			}
			int num = binaryReader.ReadInt32();
			for (int i = 0; i < num; i++)
			{
				string text = Encoding.UTF8.GetString(binaryReader.ReadBytes(binaryReader.ReadInt32()));
				int num2 = binaryReader.ReadInt32();
				Vector3[] array = (Vector3[])(object)new Vector3[num2];
				Vector3[] array2 = (Vector3[])(object)new Vector3[num2];
				Vector2[] array3 = (Vector2[])(object)new Vector2[num2];
				for (int j = 0; j < num2; j++)
				{
					array[j] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				}
				for (int k = 0; k < num2; k++)
				{
					array2[k] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				}
				for (int l = 0; l < num2; l++)
				{
					array3[l] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
				}
				int num3 = binaryReader.ReadInt32();
				Mesh val = new Mesh
				{
					name = "RoiDesRats " + text
				};
				if (num2 > 65000)
				{
					val.indexFormat = (IndexFormat)1;
				}
				val.vertices = array;
				val.normals = array2;
				val.uv = array3;
				val.subMeshCount = num3;
				int[] array4 = new int[num3];
				for (int m = 0; m < num3; m++)
				{
					array4[m] = binaryReader.ReadInt32();
					int num4 = binaryReader.ReadInt32();
					int[] array5 = new int[num4];
					for (int n = 0; n < num4; n++)
					{
						array5[n] = binaryReader.ReadInt32();
					}
					val.SetTriangles(array5, m);
				}
				val.RecalculateBounds();
				val.RecalculateTangents();
				((Object)val).hideFlags = (HideFlags)32;
				dictionary[text] = new Part
				{
					Mesh = val,
					MatIds = array4
				};
			}
			return dictionary;
		}
	}
	internal struct Shell
	{
		public GameObject Prefab;

		public Transform Enable;

		public Transform Controller;

		public Transform Rigidbody;

		public Transform Visuals;

		public Transform VisionT;

		public Transform Particles;

		public EnemyParent Parent;

		public Enemy Enemy;

		public EnemyHealth Health;

		public EnemyRigidbody Erb;

		public CapsuleCollider Capsule;

		public const float RigidbodyHeight = 0.5f;

		public static Shell Make(string enemyName)
		{
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Expected O, but got Unknown
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Resource.Load<GameObject>("Enemies/Enemy - Valuable Thrower");
			if ((Object)(object)val == (Object)null)
			{
				throw new Exception("Vanilla prefab 'Enemies/Enemy - Valuable Thrower' not found");
			}
			Shell result = new Shell
			{
				Prefab = Object.Instantiate<GameObject>(val, Plugin.Holder.transform)
			};
			((Object)result.Prefab).name = "Enemy - " + enemyName;
			result.Enable = result.Prefab.transform.Find("Enable");
			result.Controller = result.Enable.Find("Controller");
			result.Rigidbody = result.Enable.Find("Rigidbody");
			result.Visuals = result.Enable.Find("Visuals");
			if ((Object)(object)result.Controller == (Object)null || (Object)(object)result.Rigidbody == (Object)null || (Object)(object)result.Visuals == (Object)null)
			{
				throw new Exception("Unexpected Rugrat hierarchy (game update?)");
			}
			Kill((Component)(object)((Component)result.Controller).GetComponent<EnemyValuableThrower>());
			Kill((Component)(object)((Component)result.Visuals).GetComponent<EnemyValuableThrowerAnim>());
			Kill((Component)(object)((Component)result.Visuals).GetComponent<Animator>());
			result.VisionT = result.Visuals.Find("Vision Transform");
			List<GameObject> list = new List<GameObject>();
			foreach (Transform visual in result.Visuals)
			{
				Transform val2 = visual;
				if ((Object)(object)val2 != (Object)(object)result.VisionT)
				{
					list.Add(((Component)val2).gameObject);
				}
			}
			Transform val3 = result.Prefab.transform.Find("Plane");
			if (Object.op_Implicit((Object)(object)val3))
			{
				list.Add(((Component)val3).gameObject);
			}
			foreach (GameObject item in list)
			{
				Object.DestroyImmediate((Object)(object)item);
			}
			result.Parent = result.Prefab.GetComponent<EnemyParent>();
			result.Parent.enemyName = enemyName;
			result.Parent.enemyNameLocalized = null;
			result.Parent.difficulty = (Difficulty)Mathf.Clamp(Plugin.CfgDifficulty.Value - 1, 0, 2);
			result.Enemy = ((Component)result.Controller).GetComponent<Enemy>();
			result.Health = ((Component)result.Controller).GetComponent<EnemyHealth>();
			result.Health.spawnValuable = true;
			result.Erb = ((Component)result.Rigidbody).GetComponent<EnemyRigidbody>();
			Transform val4 = result.Rigidbody.Find("Collider");
			if (Object.op_Implicit((Object)(object)val4))
			{
				val4.localScale = Vector3.one;
				val4.localPosition = Vector3.zero;
				val4.localRotation = Quaternion.identity;
				result.Capsule = ((Component)val4).GetComponent<CapsuleCollider>();
			}
			if (!Object.op_Implicit((Object)(object)result.Capsule))
			{
				throw new Exception("Rugrat collider is not a capsule (game update?)");
			}
			new GameObject("Center of Mass").transform.SetParent(result.Rigidbody, false);
			result.Particles = result.Prefab.transform.Find("Particles");
			return result;
		}

		public void Body(float radius, float bottom, float top, float comY)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			float height = Mathf.Max(top - bottom, radius * 2f + 0.01f);
			((Component)Capsule).transform.localPosition = new Vector3(0f, (bottom + top) * 0.5f - 0.5f, 0f);
			Capsule.direction = 1;
			Capsule.radius = radius;
			Capsule.height = height;
			Capsule.center = Vector3.zero;
			Rigidbody.Find("Center of Mass").localPosition = new Vector3(0f, comY - 0.5f, 0f);
		}

		public void ParticleColors(Color a, Color b)
		{
			//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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)Particles))
			{
				ParticleSystem[] componentsInChildren = ((Component)Particles).GetComponentsInChildren<ParticleSystem>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					MainModule main = componentsInChildren[i].main;
					((MainModule)(ref main)).startColor = new MinMaxGradient(a, b);
				}
			}
		}

		private static void Kill(Component c)
		{
			if ((Object)(object)c != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)c);
			}
		}
	}
	[HarmonyPatch(typeof(EnemyDirector), "AmountSetup")]
	internal static class DirectorExcludePatch
	{
		private static void Prefix(EnemyDirector __instance)
		{
			if (Plugin.CfgPoolWeight.Value <= 0 && !((Object)(object)Plugin.Setup == (Object)null))
			{
				string name = ((Object)Plugin.Setup).name;
				if (Strip(__instance.enemiesDifficulty1, name) + Strip(__instance.enemiesDifficulty2, name) + Strip(__instance.enemiesDifficulty3, name) > 0)
				{
					Plugin.Log.LogInfo((object)"[Roi des rats] Removed from the regular monster picks (PoolWeight = 0).");
				}
			}
		}

		private static int Strip(List<EnemySetup> list, string n)
		{
			return list?.RemoveAll((EnemySetup s) => (Object)(object)s == (Object)(object)Plugin.Setup || ((Object)(object)s != (Object)null && ((Object)s).name == n)) ?? 0;
		}
	}
	[BepInPlugin("maxime.repo.roidesrats", "Roi des rats", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "maxime.repo.roidesrats";

		public const string NAME = "Roi des rats";

		public const string VERSION = "1.0.0";

		internal const int DefaultTier = 2;

		internal const KeyCode DefaultKey = (KeyCode)283;

		internal static ConfigEntry<int> CfgHealth;

		internal static ConfigEntry<int> CfgDamageCap;

		internal static ConfigEntry<int> CfgRats;

		internal static ConfigEntry<float> CfgHiddenSpeed;

		internal static ConfigEntry<float> CfgTrigger;

		internal static ConfigEntry<float> CfgTruckSafe;

		internal static ConfigEntry<float> CfgFirst;

		internal static ConfigEntry<float> CfgIntervalMin;

		internal static ConfigEntry<float> CfgIntervalMax;

		internal static ConfigEntry<float> CfgWarn;

		internal static ConfigEntry<float> CfgWaveLength;

		internal static ConfigEntry<float> CfgWaveSpeed;

		internal static ConfigEntry<float> CfgWaveWidth;

		internal static ConfigEntry<float> CfgDps;

		internal static ConfigEntry<float> CfgSlow;

		internal static ConfigEntry<float> CfgExposed;

		internal static Plugin Instance;

		internal static ManualLogSource Log;

		internal static ConfigEntry<int> CfgPoolWeight;

		internal static ConfigEntry<int> CfgSpawnChance;

		internal static ConfigEntry<int> CfgDifficulty;

		internal static ConfigEntry<bool> CfgDebugSpawn;

		internal static ConfigEntry<KeyCode> CfgDebugSpawnKey;

		internal const float MinPlayerDistance = 15f;

		internal static EnemySetup Setup;

		internal static GameObject Prefab;

		private static GameObject holder;

		private Harmony harmony;

		private float lastDebugSpawn = -10f;

		private LevelGenerator handledLevel;

		private float levelReadyTime = -1f;

		private float nextSpawnTry;

		private bool rolled;

		internal static GameObject Holder
		{
			get
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Expected O, but got Unknown
				if ((Object)(object)holder == (Object)null)
				{
					holder = new GameObject("Roi des ratsPrefabHolder");
					holder.SetActive(false);
					((Object)holder).hideFlags = (HideFlags)61;
					Object.DontDestroyOnLoad((Object)(object)holder);
				}
				return holder;
			}
		}

		private static void BindModConfig(ConfigFile c)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Expected O, but got Unknown
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Expected O, but got Unknown
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Expected O, but got Unknown
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Expected O, but got Unknown
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Expected O, but got Unknown
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Expected O, but got Unknown
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Expected O, but got Unknown
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Expected O, but got Unknown
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Expected O, but got Unknown
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Expected O, but got Unknown
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Expected O, but got Unknown
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Expected O, but got Unknown
			CfgHealth = c.Bind<int>("King", "Health", 120, new ConfigDescription("Hit points. It can only be hit while exposed.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 3000), Array.Empty<object>()));
			CfgHiddenSpeed = c.Bind<float>("King", "HiddenSpeed", 2.5f, new ConfigDescription("Speed of the king moving inside the walls (m/s).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 10f), Array.Empty<object>()));
			CfgExposed = c.Bind<float>("King", "ExposedAfterWave", 6f, new ConfigDescription("The king stays out of the wall during the wave and this long after it (s).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()));
			CfgTrigger = c.Bind<float>("Wave", "TriggerRange", 15f, new ConfigDescription("A wave starts only when a player is within this range of the king (m)...", (AcceptableValueBase)(object)new AcceptableValueRange<float>(3f, 60f), Array.Empty<object>()));
			CfgTruckSafe = c.Bind<float>("Wave", "TruckSafeRange", 20f, new ConfigDescription("...never within this range of the truck (m)...", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			CfgFirst = c.Bind<float>("Wave", "FirstWaveDelay", 20f, new ConfigDescription("...not before this long after it appeared (s)...", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 300f), Array.Empty<object>()));
			CfgIntervalMin = c.Bind<float>("Wave", "IntervalMin", 60f, new ConfigDescription("...and then every IntervalMin to IntervalMax seconds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 600f), Array.Empty<object>()));
			CfgIntervalMax = c.Bind<float>("Wave", "IntervalMax", 90f, new ConfigDescription("...", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 600f), Array.Empty<object>()));
			CfgWarn = c.Bind<float>("Wave", "Warning", 4f, new ConfigDescription("Squeaking in the walls before a wave (s).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 15f), Array.Empty<object>()));
			CfgWaveLength = c.Bind<float>("Wave", "Length", 25f, new ConfigDescription("Distance the wave runs, from the king towards the nearest player and beyond (m).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 80f), Array.Empty<object>()));
			CfgWaveSpeed = c.Bind<float>("Wave", "Speed", 4.5f, new ConfigDescription("Speed of the wave (m/s).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 15f), Array.Empty<object>()));
			CfgWaveWidth = c.Bind<float>("Wave", "Width", 1.8f, new ConfigDescription("Width of the carpet of rats (m).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 5f), Array.Empty<object>()));
			CfgRats = c.Bind<int>("Wave", "RatCount", 70, new ConfigDescription("Rats drawn in a wave.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 300), Array.Empty<object>()));
			CfgDps = c.Bind<float>("Damage", "DamagePerSecond", 5f, new ConfigDescription("Damage per second inside the wave...", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			CfgDamageCap = c.Bind<int>("Damage", "DamageCapPerWave", 25, new ConfigDescription("...at most this much per player and per wave.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 200), Array.Empty<object>()));
			CfgSlow = c.Bind<float>("Damage", "SlowInside", 0.6f, new ConfigDescription("Speed multiplier inside the wave (0.6 = -40%).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
		}

		private void Awake()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			CfgSpawnChance = ((BaseUnityPlugin)this).Config.Bind<int>("Spawn", "BonusChance", 0, new ConfigDescription("Optional extra copy ON TOP of the level's monsters: chance (%) per level, only if the normal draw did not pick it. 0 = off.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			CfgPoolWeight = ((BaseUnityPlugin)this).Config.Bind<int>("Spawn", "PoolWeight", 100, new ConfigDescription("Weight in the game's normal monster draw: it takes the place of a vanilla pick, never adds one. 100 = as likely as a standard vanilla monster, 0 = never drawn. Needs a restart.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 300), Array.Empty<object>()));
			CfgDifficulty = ((BaseUnityPlugin)this).Config.Bind<int>("Spawn", "DifficultyTier", 2, new ConfigDescription("Enemy tier (1-3): size of the orb it drops. Needs a restart.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 3), Array.Empty<object>()));
			CfgDebugSpawn = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableSpawnKey", false, "Host only: the key brings the Roi des rats 4 m in front of you (or spawns it).");
			CfgDebugSpawnKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Debug", "SpawnKey", (KeyCode)283, "Debug spawn key.");
			BindModConfig(((BaseUnityPlugin)this).Config);
			Lang.Bind(((BaseUnityPlugin)this).Config);
			harmony = new Harmony("maxime.repo.roidesrats");
			harmony.PatchAll(typeof(Plugin).Assembly);
			try
			{
				Kit.Init();
				Prefab = PrefabBuilder.Build();
				Register();
				Log.LogInfo((object)"Roi des rats v1.0.0 loaded: enemy prefab built and registered with REPOLib.");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed to build/register the Roi des rats: " + ex));
			}
		}

		private static void Register()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			Setup = ScriptableObject.CreateInstance<EnemySetup>();
			((Object)Setup).name = "Enemy - Roi des rats";
			((Object)Setup).hideFlags = (HideFlags)32;
			Setup.status = (Status)1;
			Setup.spawnObjects = new List<PrefabRef>();
			Setup.levelsCompletedCondition = false;
			Setup.levelsCompletedMin = 0;
			Setup.levelsCompletedMax = 10;
			RarityPreset val = ScriptableObject.CreateInstance<RarityPreset>();
			((Object)val).name = "Roi des rats Rarity";
			val.chance = Mathf.Max(1f, (float)CfgPoolWeight.Value);
			((Object)val).hideFlags = (HideFlags)32;
			Setup.rarityPreset = val;
			EnemyContent val2 = ScriptableObject.CreateInstance<EnemyContent>();
			((Object)val2).name = "Roi des rats";
			((Object)val2).hideFlags = (HideFlags)32;
			AccessTools.Field(typeof(EnemyContent), "_setup").SetValue(val2, Setup);
			AccessTools.Field(typeof(EnemyContent), "_spawnObjects").SetValue(val2, new List<GameObject> { Prefab });
			Enemies.RegisterEnemy(val2);
		}

		private void Update()
		{
			BonusSpawnTick();
			DebugKeyTick();
			Lang.Tick();
		}

		private void BonusSpawnTick()
		{
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Setup == (Object)null)
			{
				return;
			}
			LevelGenerator instance = LevelGenerator.Instance;
			if ((Object)(object)instance == (Object)null || !instance.Generated)
			{
				levelReadyTime = -1f;
			}
			else
			{
				if ((Object)(object)instance == (Object)(object)handledLevel)
				{
					return;
				}
				try
				{
					if (!SemiFunc.IsMasterClientOrSingleplayer() || !SemiFunc.RunIsLevel())
					{
						handledLevel = instance;
						return;
					}
					if (levelReadyTime < 0f)
					{
						levelReadyTime = Time.time;
						rolled = false;
						nextSpawnTry = 0f;
						return;
					}
					float num = Time.time - levelReadyTime;
					if (num < 4f || Time.time < nextSpawnTry)
					{
						return;
					}
					nextSpawnTry = Time.time + 1f;
					if ((Object)(object)RatKingAI.Existing() != (Object)null)
					{
						handledLevel = instance;
						return;
					}
					if (!rolled)
					{
						rolled = true;
						if (Random.Range(0, 100) >= CfgSpawnChance.Value)
						{
							handledLevel = instance;
							return;
						}
					}
					if (!TryQuietPoint(Vector3.zero, 0f, 999f, out var pos))
					{
						if (!(num < 29f))
						{
							handledLevel = instance;
						}
					}
					else
					{
						handledLevel = instance;
						RatKingAI.SkipTeleportUntil = Time.time + 5f;
						Enemies.SpawnEnemy(Setup, pos, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f), false);
						Log.LogInfo((object)string.Format("[{0}] Bonus copy spawned at {1}.", "Roi des rats", pos));
					}
				}
				catch (Exception ex)
				{
					handledLevel = instance;
					Log.LogError((object)("[Roi des rats] Level spawn failed: " + ex));
				}
			}
		}

		internal static bool TryQuietPoint(Vector3 from, float minD, float maxD, out Vector3 pos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			pos = Vector3.zero;
			List<LevelPoint> list = (Object.op_Implicit((Object)(object)LevelGenerator.Instance) ? LevelGenerator.Instance.LevelPathPoints : null);
			if (list == null || list.Count == 0)
			{
				return false;
			}
			List<PlayerAvatar> list2 = SemiFunc.PlayerGetList();
			for (int i = 0; i < 60; i++)
			{
				LevelPoint val = list[Random.Range(0, list.Count)];
				if (!Object.op_Implicit((Object)(object)val) || val.Truck)
				{
					continue;
				}
				Vector3 position = ((Component)val).transform.position;
				if (from != Vector3.zero)
				{
					float num = Vector3.Distance(from, position);
					if (num < minD || num > maxD)
					{
						continue;
					}
				}
				bool flag = true;
				if (list2 != null)
				{
					foreach (PlayerAvatar item in list2)
					{
						if (Object.op_Implicit((Object)(object)item) && !item.isDisabled && Vector3.Distance(((Component)item).transform.position, position) < 15f)
						{
							flag = false;
							break;
						}
					}
				}
				if (flag || i >= 45)
				{
					pos = position + Vector3.up * 0.1f;
					return true;
				}
			}
			return false;
		}

		private void DebugKeyTick()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			if (!CfgDebugSpawn.Value || (Object)(object)Setup == (Object)null || !Input.GetKeyDown(CfgDebugSpawnKey.Value) || Time.unscaledTime - lastDebugSpawn < 0.75f)
			{
				return;
			}
			lastDebugSpawn = Time.unscaledTime;
			try
			{
				if (!SemiFunc.IsMasterClientOrSingleplayer())
				{
					Log.LogInfo((object)"[Debug] Only the host can spawn the Roi des rats.");
					return;
				}
				if (!SemiFunc.RunIsLevel() || (Object)(object)PlayerAvatar.instance == (Object)null)
				{
					Log.LogInfo((object)"[Debug] Spawn key only works inside a level.");
					return;
				}
				Transform transform = ((Component)PlayerAvatar.instance).transform;
				Vector3 val = Vector3.ProjectOnPlane(transform.forward, Vector3.up);
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				Vector3 val2 = transform.position + normalized * 4f + Vector3.up * 0.2f;
				NavMeshHit val3 = default(NavMeshHit);
				if (NavMesh.SamplePosition(val2, ref val3, 3f, -1))
				{
					val2 = ((NavMeshHit)(ref val3)).position + Vector3.up * 0.1f;
				}
				RatKingAI ratKingAI = RatKingAI.Existing();
				if ((Object)(object)ratKingAI != (Object)null)
				{
					ratKingAI.DebugBring(val2);
					Log.LogInfo((object)string.Format("[Debug] {0} brought to {1}.", "Roi des rats", val2));
					return;
				}
				RatKingAI.SkipTeleportUntil = Time.time + 5f;
				Enemies.SpawnEnemy(Setup, val2, Quaternion.LookRotation(-normalized), false);
				handledLevel = LevelGenerator.Instance;
				Log.LogInfo((object)string.Format("[Debug] {0} spawned at {1}.", "Roi des rats", val2));
			}
			catch (Exception ex)
			{
				Log.LogError((object)("[Debug] Spawn failed: " + ex));
			}
		}
	}
	internal static class Lang
	{
		internal static readonly string[] Codes = new string[21]
		{
			"en", "fr", "de", "es", "es-419", "it", "pt", "pt-BR", "ru", "uk",
			"pl", "tr", "ja", "ko", "zh-Hans", "zh-Hant", "ar", "da", "fi", "sv",
			"th"
		};

		internal static ConfigEntry<string> Cfg;

		private static string code = "en";

		private static float codeAt = -99f;

		private static float nextTick;

		internal static readonly Dictionary<string, string> NameTable = new Dictionary<string, string>
		{
			{ "en", "Rat King" },
			{ "fr", "Roi des rats" },
			{ "de", "Rattenkönig" },
			{ "es", "Rey de las ratas" },
			{ "es-419", "Rey de las ratas" },
			{ "it", "Re dei ratti" },
			{ "pt", "Rei dos Ratos" },
			{ "pt-BR", "Rei dos Ratos" },
			{ "ru", "Крысиный король" },
			{ "uk", "Щурячий король" },
			{ "pl", "Szczurzy król" },
			{ "tr", "Sıçan Kral" },
			{ "ja", "鼠の王" },
			{ "ko", "쥐의 왕" },
			{ "zh-Hans", "鼠王" },
			{ "zh-Hant", "鼠王" },
			{ "ar", "ملك الجرذان" },
			{ "da", "Rottekonge" },
			{ "fi", "Rottakuningas" },
			{ "sv", "Råttkung" },
			{ "th", "ราชาหน\u0e39" }
		};

		internal const bool HasMessages = false;

		internal static string Code
		{
			get
			{
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				if (Time.unscaledTime - codeAt < 1f)
				{
					return code;
				}
				codeAt = Time.unscaledTime;
				string text = ((Cfg != null) ? Cfg.Value : "Auto");
				if (string.IsNullOrEmpty(text) || text.Trim().Equals("Auto", StringComparison.OrdinalIgnoreCase))
				{
					text = "en";
					try
					{
						Locale selectedLocale = LocalizationSettings.SelectedLocale;
						if ((Object)(object)selectedLocale != (Object)null)
						{
							LocaleIdentifier identifier = selectedLocale.Identifier;
							text = ((LocaleIdentifier)(ref identifier)).Code;
						}
					}
					catch (Exception)
					{
					}
				}
				code = Normalize(text);
				return code;
			}
		}

		internal static string Name => Pick(NameTable);

		internal static void Bind(ConfigFile config)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			List<string> list = new List<string> { "Auto" };
			list.AddRange(Codes);
			Cfg = config.Bind<string>("Language", "Language", "Auto", new ConfigDescription("Language of this monster's in-game texts (its name when grabbed). Auto = the game's language (English if the game's language is not one of these).", (AcceptableValueBase)(object)new AcceptableValueList<string>(list.ToArray()), Array.Empty<object>()));
		}

		internal static void Tick()
		{
			if (Time.unscaledTime < nextTick)
			{
				return;
			}
			nextTick = Time.unscaledTime + 1f;
			try
			{
				string name = Name;
				if (Object.op_Implicit((Object)(object)Plugin.Prefab))
				{
					EnemyParent componentInChildren = Plugin.Prefab.GetComponentInChildren<EnemyParent>(true);
					if (Object.op_Implicit((Object)(object)componentInChildren))
					{
						componentInChildren.enemyName = name;
					}
				}
				foreach (RatKingAI item in RatKingAI.All)
				{
					if (Object.op_Implicit((Object)(object)item))
					{
						EnemyParent componentInParent = ((Component)item).GetComponentInParent<EnemyParent>(true);
						if (Object.op_Implicit((Object)(object)componentInParent) && componentInParent.enemyName != name)
						{
							componentInParent.enemyName = name;
						}
					}
				}
			}
			catch (Exception)
			{
			}
		}

		internal static string Normalize(string c)
		{
			c = (c ?? "en").Trim().Replace('_', '-').ToLowerInvariant();
			if (c.StartsWith("zh"))
			{
				if (!c.Contains("hant") && !c.Contains("tw") && !c.Contains("hk") && !c.Contains("mo"))
				{
					return "zh-Hans";
				}
				return "zh-Hant";
			}
			if (c.StartsWith("es"))
			{
				if (!(c == "es") && !(c == "es-es"))
				{
					return "es-419";
				}
				return "es";
			}
			if (c.StartsWith("pt"))
			{
				if (!(c == "pt-br"))
				{
					return "pt";
				}
				return "pt-BR";
			}
			string text = ((c.Length >= 2) ? c.Substring(0, 2) : c);
			if (Array.IndexOf(Codes, text) < 0)
			{
				return "en";
			}
			return text;
		}

		internal static string Pick(Dictionary<string, string> t)
		{
			if (!t.TryGetValue(Code, out var value) || string.IsNullOrEmpty(value))
			{
				return t["en"];
			}
			return value;
		}
	}
	internal static class ModelLayout
	{
		public static readonly string[] Parts = new string[2] { "king", "rat" };

		public static readonly string[] Parents = new string[2] { "", "" };

		public static readonly Vector3[] Pivots = (Vector3[])(object)new Vector3[2]
		{
			new Vector3(0f, 0f, 0f),
			new Vector3(0f, 0f, 0f)
		};

		public static readonly string[] Detached = new string[1] { "rat" };
	}
	internal static class Sounds
	{
		public static Sound Squeak;

		public static Sound Squeal;

		public static Sound Scratch;

		public static Sound Scurry;

		public static Sound KingLoop;

		public static Sound Hurt;

		public static Sound Death;

		public static Sound Burst;
	}
	internal static class PrefabBuilder
	{
		internal const int M_FUR = 0;

		internal const int M_SKIN = 1;

		internal const int M_EYE = 2;

		internal const int M_KNOT = 3;

		internal const int M_TOOTH = 4;

		internal static Part RatPart;

		public static GameObject Build()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: 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_02c3: Unknown result type (might be due to invalid IL or missing references)
			Shell shell = Shell.Make("Roi des rats");
			CollectSounds();
			shell.Parent.SpawnedTimeMin = 300f;
			shell.Parent.SpawnedTimeMax = 420f;
			shell.Parent.DespawnedTimeMin = 60f;
			shell.Parent.DespawnedTimeMax = 120f;
			shell.Enemy.Type = (EnemyType)2;
			shell.Health.health = Plugin.CfgHealth.Value;
			shell.Health.objectHurtStun = false;
			shell.Erb.gravity = false;
			shell.Erb.grabStun = false;
			shell.Erb.positionSpeedIdle = 6f;
			shell.Erb.positionSpeedChase = 6f;
			shell.Erb.distanceWarpIdle = 3f;
			shell.Erb.distanceWarpChase = 3f;
			shell.Erb.rotationSpeedIdle = 0.6f;
			shell.Erb.rotationSpeedChase = 0.6f;
			shell.Capsule.direction = 1;
			shell.Capsule.radius = 0.02f;
			shell.Capsule.height = 0.05f;
			shell.Capsule.center = Vector3.zero;
			shell.ParticleColors(new Color(0.35f, 0.27f, 0.22f), new Color(0.55f, 0.08f, 0.08f));
			Dictionary<string, Part> parts = Kit.LoadMeshes(Resource.Embedded("RoiDesRats.rats.mesh"));
			Kit.Materials = (Material[])(object)new Material[5]
			{
				Kit.Mat("Fur", 0.15f, 0f, Color.black),
				Kit.Mat("Skin", 0.5f, 0f, Color.black),
				Kit.Mat("Eye", 0.8f, 0f, new Color(2.5f, 0.5f, 0.4f)),
				Kit.Mat("Knot", 0.4f, 0f, Color.black),
				Kit.Mat("Tooth", 0.6f, 0f, Color.black)
			};
			Transform transform = new GameObject("RatKingModel").transform;
			transform.SetParent(shell.Visuals, false);
			transform.localPosition = new Vector3(0f, -0.3f, 0f);
			Dictionary<string, Part> dictionary = new Dictionary<string, Part>();
			Kit.Build(transform, parts, dictionary);
			RatPart = dictionary["rat"];
			shell.Health.meshParent = transform;
			if (Object.op_Implicit((Object)(object)shell.VisionT))
			{
				shell.VisionT.localPosition = new Vector3(0f, 0f, 0.2f);
				shell.VisionT.localRotation = Quaternion.identity;
			}
			Snd.Source(transform, "King Squeaks", 1.5f, 14f);
			((Component)shell.Controller).gameObject.AddComponent<RatKingAI>();
			return shell.Prefab;
		}

		private static void CollectSounds()
		{
			try
			{
				Sounds.Squeak = Snd.Make("Squeak", 0.6f, 1f, 0.2f, "squeak_1", "squeak_2", "squeak_3", "squeak_4");
				Sounds.Squeal = Snd.Make("Squeal", 1f, 1f, 0f, "warning");
				Sounds.Scratch = Snd.Make("Scratch", 0.55f, 1f, 0.15f, "scratch_1", "scratch_2");
				Sounds.Scurry = Snd.Make("Scurry", 0.9f, 1f, 0f, "scurry");
				Sounds.KingLoop = Snd.Make("KingLoop", 0.6f, 1f, 0f, "king");
				Sounds.Hurt = Snd.Make("Hurt", 0.9f, 1f, 0.15f, "hurt");
				Sounds.Death = Snd.Make("Death", 1f, 1f, 0f, "death");
				Sounds.Burst = Snd.Make("Burst", 1f, 1f, 0.05f, "burst");
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not prepare sounds: " + ex.Message));
			}
		}
	}
	public class RatKingAI : MonoBehaviour
	{
		public enum State
		{
			Spawn,
			Lurk,
			Warn,
			Wave,
			Exposed
		}

		private const int EV_SQUEAL = 1;

		private const int EV_BURST = 2;

		private const float WaveDepth = 4f;

		private Enemy enemy;

		private PhotonView photonView;

		private EnemyHealth health;

		private EnemyRigidbody erb;

		private Transform visuals;

		private Transform model;

		private Transform particles;

		private Transform follow;

		private Vector3 followRest;

		private CapsuleCollider capsule;

		private Sound kingLoop;

		private Sound scurry;

		private AudioSource kingSrc;

		private AudioSource scurrySrc;

		private int wallMask;

		private bool ready;

		public State state;

		private bool stateImpulse = true;

		private float stateTimer;

		private float stateTime;

		private float nextWave;

		private float pathTimer;

		private float grabTimer;

		private float spawnTime;

		private float roamTimer;

		private Vector3 anchor;

		private Vector3 anchorFace;

		private Vector3 roamPoint;

		private readonly Dictionary<int, float> dmgDone = new Dictionary<int, float>();

		private readonly Dictionary<int, float> dmgAcc = new Dictionary<int, float>();

		private Vector3[] wavePts;

		private float[] waveDist;

		private float waveTotal;

		private float waveStart = -99f;

		private bool waveActive;

		private readonly List<Transform> rats = new List<Transform>();

		private float[] ratOff;

		private float[] ratLat;

		private float[] ratSeed;

		private GameObject ratRoot;

		private float squeakTimer;

		private float scratchTimer;

		private float t;

		internal static float SkipTeleportUntil;

		internal static readonly List<RatKingAI> All = new List<RatKingAI>();

		private float Head => (Time.time - waveStart) * Plugin.CfgWaveSpeed.Value;

		internal static RatKingAI Existing()
		{
			All.RemoveAll((RatKingAI a) => (Object)(object)a == (Object)null);
			if (All.Count <= 0)
			{
				return null;
			}
			return All[0];
		}

		private void Awake()
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Expected O, but got Unknown
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Expected O, but got Unknown
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Expected O, but got Unknown
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Expected O, but got Unknown
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			enemy = ((Component)this).GetComponent<Enemy>();
			photonView = ((Component)this).GetComponent<PhotonView>();
			health = ((Component)this).GetComponent<EnemyHealth>();
			Transform parent = ((Component)this).transform.parent;
			erb = ((Component)parent.Find("Rigidbody")).GetComponent<EnemyRigidbody>();
			follow = (Object.op_Implicit((Object)(object)erb) ? erb.followTarget : null);
			if (Object.op_Implicit((Object)(object)follow))
			{
				followRest = follow.localPosition;
			}
			visuals = parent.Find("Visuals");
			model = (Object.op_Implicit((Object)(object)visuals) ? visuals.Find("RatKingModel") : null);
			particles = parent.parent.Find("Particles");
			Transform val = (Object.op_Implicit((Object)(object)erb) ? ((Component)erb).transform.Find("Collider") : null);
			capsule = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<CapsuleCollider>() : null);
			if (Object.op_Implicit((Object)(object)model))
			{
				Transform val2 = model.Find("King Squeaks");
				kingSrc = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponent<AudioSource>() : null);
				kingLoop = Snd.Loop(Sounds.KingLoop, kingSrc, 0.6f);
			}
			GameObject val3 = new GameObject("Rat Wave Sound");
			val3.transform.SetParent(((Component)this).transform, false);
			scurrySrc = val3.AddComponent<AudioSource>();
			scurrySrc.playOnAwake = false;
			scurrySrc.loop = true;
			scurrySrc.spatialBlend = 1f;
			scurrySrc.rolloffMode = (AudioRolloffMode)1;
			scurrySrc.minDistance = 3f;
			scurrySrc.maxDistance = 28f;
			scurrySrc.dopplerLevel = 0f;
			scurrySrc.volume = 0f;
			scurry = Snd.Loop(Sounds.Scurry, scurrySrc, 0.9f);
			EnemyStateSpawn component = ((Component)this).GetComponent<EnemyStateSpawn>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.OnSpawn.AddListener(new UnityAction(OnSpawn));
			}
			if (Object.op_Implicit((Object)(object)health))
			{
				health.onHurt.AddListener(new UnityAction(OnHurt));
				health.onDeath.AddListener(new UnityAction(OnDeath));
			}
			int num = 1 << ((Component)erb).gameObject.layer;
			Collider[] componentsInChildren = ((Component)erb).GetComponentsInChildren<Collider>(true);
			foreach (Collider val4 in componentsInChildren)
			{
				num |= 1 << ((Component)val4).gameObject.layer;
			}
			int mask = LayerMask.GetMask(new string[7] { "Player", "PhysGrabObject", "PhysGrabObjectCart", "PhysGrabObjectHinge", "Enemy", "Ragdoll", "Triggers" });
			wallMask = LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()) & ~num & ~mask;
			ready = Object.op_Implicit((Object)(object)model) && Object.op_Implicit((Object)(object)erb) && Object.op_Implicit((Object)(object)follow) && Object.op_Implicit((Object)(object)capsule);
			if (!ready)
			{
				Plugin.Log.LogError((object)"RatKingAI: hierarchy incomplete, behaviour disabled.");
			}
			All.Add(this);
		}

		private void Start()
		{
			Snd.Route(kingSrc);
			Snd.Route(scurrySrc);
		}

		private void OnDisable()
		{
			waveActive = false;
			if (Object.op_Implicit((Object)(object)ratRoot))
			{
				ratRoot.SetActive(false);
			}
		}

		private void OnDestroy()
		{
			All.Remove(this);
			if (Object.op_Implicit((Object)(object)ratRoot))
			{
				Object.Destroy((Object)(object)ratRoot);
			}
		}

		private void Update()
		{
			if (ready)
			{
				float deltaTime = Time.deltaTime;
				t += deltaTime;
				if (!U.Master)
				{
					stateTime += deltaTime;
				}
				if (U.Master)
				{
					MasterLogic(deltaTime);
				}
				WaveTick(deltaTime);
				Ambience(deltaTime);
			}
		}

		private void LateUpdate()
		{
			//IL_001a: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			if (ready)
			{
				visuals.position = ((Component)erb).transform.position;
				visuals.rotation = ((Component)erb).transform.rotation;
				bool flag = state == State.Wave || state == State.Exposed;
				if (((Component)model).gameObject.activeSelf != flag)
				{
					((Component)model).gameObject.SetActive(flag);
				}
				if (flag)
				{
					float num = 1f + 0.05f * Mathf.Sin(t * 9f) + 0.03f * Mathf.Sin(t * 23f);
					model.localScale = new Vector3(num, 2f - num, num);
					model.localRotation = Quaternion.Euler(6f * Mathf.Sin(t * 3.3f), 25f * Mathf.Sin(t * 1.1f), 6f * Mathf.Sin(t * 2.7f));
					float num2 = U.Smooth(0f, 0.35f, stateTime);
					model.localPosition = new Vector3(0f, -0.3f, -0.35f * (1f - num2));
				}
				Snd.PlayLoop(kingLoop, flag, 0.3f, 0.6f);
			}
		}

		private void MasterLogic(float dt)
		{
			//IL_002a: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			stateTime += dt;
			if (state == State.Wave || state == State.Exposed)
			{
				follow.position = anchor;
				((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, Quaternion.LookRotation(anchorFace, Vector3.up), 1f - Mathf.Exp(-8f * dt));
				if ((grabTimer -= dt) <= 0f)
				{
					grabTimer = 0.25f;
					U.BreakGrabs(erb.physGrabObject);
				}
			}
			else if (follow.localPosition != followRest)
			{
				follow.localPosition = followRest;
			}
			if (state == State.Wave)
			{
				WaveDamage(dt);
			}
			switch (state)
			{
			case State.Spawn:
				if (stateImpulse)
				{
					stateImpulse = false;
					stateTimer = 1f;
					spawnTime = Time.time;
					nextWave = Time.time + Plugin.CfgFirst.Value;
				}
				Halt();
				if ((stateTimer -= dt) <= 0f)
				{
					SetState(State.Lurk);
				}
				break;
			case State.Lurk:
			{
				if (stateImpulse)
				{
					stateImpulse = false;
				}
				float dist;
				PlayerAvatar val = Nearest(out dist);
				if (Object.op_Implicit((Object)(object)val) && dist < 10f)
				{
					Halt();
				}
				else if (Object.op_Implicit((Object)(object)val) && dist < 60f)
				{
					GoTo(((Component)val).transform.position, dt);
				}
				else
				{
					Roam(dt);
				}
				if (Time.time >= nextWave && Object.op_Implicit((Object)(object)val) && dist <= Plugin.CfgTrigger.Value && FarFromTruck(val))
				{
					SetState((Plugin.CfgWarn.Value > 0f) ? State.Warn : State.Wave);
				}
				break;
			}
			case State.Warn:
				if (stateImpulse)
				{
					stateImpulse = false;
					Event(1);
				}
				Halt();
				if (stateTime >= Plugin.CfgWarn.Value)
				{
					float dist2;
					PlayerAvatar val2 = Nearest(out dist2);
					if (Object.op_Implicit((Object)(object)val2) && dist2 <= Plugin.CfgTrigger.Value + 5f && FarFromTruck(val2) && LaunchWave(val2))
					{
						SetState(State.Wave);
						break;
					}
					nextWave = Time.time + 10f;
					SetState(State.Lurk);
				}
				break;
			case State.Wave:
				if (stateImpulse)
				{
					stateImpulse = false;
				}
				Halt();
				if (!waveActive && stateTime > 0.5f)
				{
					SetState(State.Exposed);
				}
				break;
			case State.Exposed:
				if (stateImpulse)
				{
					stateImpulse = false;
				}
				Halt();
				if (stateTime >= Plugin.CfgExposed.Value)
				{
					nextWave = Time.time + Random.Range(Plugin.CfgIntervalMin.Value, Mathf.Max(Plugin.CfgIntervalMin.Value, Plugin.CfgIntervalMax.Value));
					SetState(State.Lurk);
				}
				break;
			}
		}

		private PlayerAvatar Nearest(out float dist)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar result = null;
			dist = float.MaxValue;
			Vector3 position = ((Component)enemy.NavMeshAgent).transform.position;
			foreach (PlayerAvatar item in U.Players())
			{
				if (U.Valid(item))
				{
					float num = Vector3.Distance(((Component)item).transform.position, position);
					if (num < dist)
					{
						dist = num;
						result = item;
					}
				}
			}
			return result;
		}

		private bool FarFromTruck(PlayerAvatar p)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = U.TruckPos();
			float value = Plugin.CfgTruckSafe.Value;
			if (Vector3.Distance(val, ((Component)enemy.NavMeshAgent).transform.position) >= value && Vector3.Distance(val, ((Component)p).transform.position) >= value)
			{
				if (Object.op_Implicit((Object)(object)p.RoomVolumeCheck))
				{
					return !p.RoomVolumeCheck.inTruck;
				}
				return true;
			}
			return false;
		}

		private bool LaunchWave(PlayerAvatar p)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Expected O, but got Unknown
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0485: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)enemy.NavMeshAgent).transform.position;
			NavMeshHit val = default(NavMeshHit);
			if (NavMesh.SamplePosition(position, ref val, 2f, -1))
			{
				position = ((NavMeshHit)(ref val)).position;
			}
			float max = 3f;
			Vector3 val2 = Vector3.zero;
			Vector3 val3 = Vector3.zero;
			Vector3 val4;
			for (int i = 0; i < 16; i++)
			{
				Vector3 dir = Quaternion.Euler(0f, (float)i * 22.5f, 0f) * Vector3.forward;
				if (U.Raycast(position + Vector3.up * 0.45f, dir, max, wallMask, out var hit) && Mathf.Abs(((RaycastHit)(ref hit)).normal.y) < 0.4f)
				{
					max = ((RaycastHit)(ref hit)).distance;
					val2 = ((RaycastHit)(ref hit)).point;
					val4 = U.Flat(((RaycastHit)(ref hit)).normal);
					val3 = ((Vector3)(ref val4)).normalized;
				}
			}
			if (val3 != Vector3.zero)
			{
				anchor = val2 + val3 * 0.3f;
				anchorFace = val3;
				if (U.Blocked(position + Vector3.up * 0.45f, anchor, wallMask))
				{
					val3 = Vector3.zero;
				}
			}
			if (val3 == Vector3.zero)
			{
				anchor = position + Vector3.up * 0.3f;
				val4 = U.Flat(((Component)p).transform.position - position);
				anchorFace = ((Vector3)(ref val4)).normalized;
				if (anchorFace == Vector3.zero)
				{
					anchorFace = Vector3.forward;
				}
			}
			Vector3 position2 = ((Component)p).transform.position;
			NavMeshHit val5 = default(NavMeshHit);
			if (NavMesh.SamplePosition(position2, ref val5, 2f, -1))
			{
				position2 = ((NavMeshHit)(ref val5)).position;
			}
			NavMeshPath val6 = new NavMeshPath();
			if (!NavMesh.CalculatePath(position, position2, -1, val6) || val6.corners.Length < 2)
			{
				Plugin.Log.LogInfo((object)"[Roi des rats] No path to the player: wave cancelled.");
				return false;
			}
			List<Vector3> list = new List<Vector3>(val6.corners);
			float num = 0f;
			for (int j = 1; j < list.Count; j++)
			{
				num += Vector3.Distance(list[j - 1], list[j]);
			}
			float value = Plugin.CfgWaveLength.Value;
			if (num < value)
			{
				Vector3 val7 = list[list.Count - 1];
				val4 = U.Flat(val7 - list[list.Count - 2]);
				Vector3 normalized = ((Vector3)(ref val4)).normalized;
				if (normalized != Vector3.zero)
				{
					Vector3 val8 = val7 + normalized * (value - num);
					NavMeshHit val9 = default(NavMeshHit);
					if (NavMesh.Raycast(val7, val8, ref val9, -1))
					{
						val8 = ((NavMeshHit)(ref val9)).position;
					}
					if (Vector3.Distance(val7, val8) > 0.5f)
					{
						list.Add(val8);
					}
				}
			}
			List<Vector3> list2 = new List<Vector3> { list[0] };
			float num2 = 0f;
			float num3 = 0.5f;
			float num4 = 0f;
			for (int k = 1; k < list.Count; k++)
			{
				if (!(num2 < value))
				{
					break;
				}
				Vector3 val10 = list[k - 1];
				Vector3 val11 = list[k];
				float num5 = Vector3.Distance(val10, val11);
				float num6;
				for (num6 = num3 - num4; num6 <= num5; num6 += num3)
				{
					if (!(num2 + num3 <= value))
					{
						break;
					}
					list2.Add(Vector3.Lerp(val10, val11, num6 / num5));
					num2 += num3;
				}
				num4 = num5 - (num6 - num3);
			}
			if (list2.Count < 3)
			{
				return false;
			}
			Plugin.Log.LogInfo((object)$"[Roi des rats] Wave towards {p.playerName}: {(float)(list2.Count - 1) * 0.5f:0} m.");
			dmgDone.Clear();
			dmgAcc.Clear();
			Event(2);
			float[] array = new float[list2.Count * 3];
			for (int l = 0; l < list2.Count; l++)
			{
				array[l * 3] = list2[l].x;
				array[l * 3 + 1] = list2[l].y;
				array[l * 3 + 2] = list2[l].z;
			}
			if (U.MP)
			{
				photonView.RPC("RatWaveRPC", (RpcTarget)0, new object[1] { array });
			}
			else
			{
				RatWaveRPC(array);
			}
			return true;
		}

		private void WaveDamage(float dt)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if (!waveActive)
			{
				return;
			}
			float value = Plugin.CfgDps.Value;
			float num = Plugin.CfgDamageCap.Value;
			foreach (PlayerAvatar item in U.Players())
			{
				if (!U.Valid(item) || !Inside(((Component)item).transform.position))
				{
					continue;
				}
				int key = U.Id(item);
				float value2;
				float num2 = (dmgDone.TryGetValue(key, out value2) ? value2 : 0f);
				if (num2 >= num)
				{
					continue;
				}
				float value3;
				float num3 = (dmgAcc.TryGetValue(key, out value3) ? value3 : 0f) + value * dt;
				if (num3 >= 2.5f || num2 + num3 >= num)
				{
					int num4 = Mathf.Min(Mathf.RoundToInt(num3), Mathf.RoundToInt(num - num2));
					if (num4 > 0)
					{
						U.Hurt(item, num4, enemy);
						num2 += (float)num4;
					}
					num3 = 0f;
				}
				dmgAcc[key] = num3;
				dmgDone[key] = num2;
			}
		}

		private void Roam(float dt)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			if (!((roamTimer -= dt) <= 0f))
			{
				Vector3 val = U.Flat(roamPoint - ((Component)enemy.NavMeshAgent).transform.position);
				if (!(((Vector3)(ref val)).magnitude < 1.5f))
				{
					goto IL_00b1;
				}
			}
			roamTimer = 25f;
			List<LevelPoint> list = (Object.op_Implicit((Object)(object)LevelGenerator.Instance) ? LevelGenerator.Instance.LevelPathPoints : null);
			if (list != null && list.Count > 0)
			{
				LevelPoint val2 = list[Random.Range(0, list.Count)];
				if (Object.op_Implicit((Object)(object)val2) && !val2.Truck)
				{
					roamPoint = ((Component)val2).transform.position;
				}
			}
			goto IL_00b1;
			IL_00b1:
			GoTo(roamPoint, dt);
		}

		private void GoTo(Vector3 p, float dt)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if ((pathTimer -= dt) <= 0f)
			{
				pathTimer = 0.5f;
				NavMeshHit val = default(NavMeshHit);
				if (NavMesh.SamplePosition(p, ref val, 2f, -1))
				{
					p = ((NavMeshHit)(ref val)).position;
				}
				enemy.NavMeshAgent.SetDestination(p);
			}
			enemy.NavMeshAgent.OverrideAgent(Plugin.CfgHiddenSpeed.Value, 8f, 0.6f);
		}

		private void Halt()
		{
			enemy.NavMeshAgent.Stop(0.2f);
		}

		[PunRPC]
		private void RatWaveRPC(float[] flat, PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0000: 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_0078: 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)
			if (SemiFunc.MasterOnlyRPC(info) && flat != null && flat.Length >= 6)
			{
				Vector3[] array = (Vector3[])(object)new Vector3[flat.Length / 3];
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = new Vector3(flat[i * 3], flat[i * 3 + 1], flat[i * 3 + 2]);
				}
				wavePts = array;
				waveDist = new float[array.Length];
				for (int j = 1; j < array.Length; j++)
				{
					waveDist[j] = waveDist[j - 1] + Vector3.Distance(array[j - 1], array[j]);
				}
				waveTotal = waveDist[array.Length - 1];
				waveStart = Time.time;
				waveActive = true;
				EnsureRats();
			}
		}

		private void EnsureRats()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			int value = Plugin.CfgRats.Value;
			if (!Object.op_Implicit((Object)(object)ratRoot))
			{
				ratRoot = new GameObject("Rat Wave");
				rats.Clear();
			}
			ratRoot.SetActive(true);
			if (!((Object)(object)PrefabBuilder.RatPart.Mesh == (Object)null))
			{
				while (rats.Count < value)
				{
					GameObject val = Kit.Prop("Rat", PrefabBuilder.RatPart, Vector3.zero, Quaternion.identity, Random.Range(0.85f, 1.2f));
					((Renderer)val.GetComponent<MeshRenderer>()).shadowCastingMode = (ShadowCastingMode)0;
					val.transform.SetParent(ratRoot.transform, true);
					val.SetActive(false);
					rats.Add(val.transform);
				}
				ratOff = new float[value];
				ratLat = new float[value];
				ratSeed = new float[value];
				for (int i = 0; i < value; i++)
				{
					ratOff[i] = Mathf.Pow(Random.value, 0.8f) * 4f;
					ratLat[i] = (Random.value - 0.5f) * Plugin.CfgWaveWidth.Value * (1f - 0.4f * ratOff[i] / 4f);
					ratSeed[i] = Random.value * 100f;
				}
			}
		}

		private Vector3 PointAt(float s, out Vector3 tangent)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009e: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			tangent = Vector3.forward;
			if (wavePts == null)
			{
				return Vector3.zero;
			}
			s = Mathf.Clamp(s, 0f, waveTotal);
			int i;
			for (i = 1; i < waveDist.Length - 1 && waveDist[i] < s; i++)
			{
			}
			float num = Mathf.Max(0.0001f, waveDist[i] - waveDist[i - 1]);
			tangent = (wavePts[i] - wavePts[i - 1]) / num;
			return Vector3.Lerp(wavePts[i - 1], wavePts[i], (s - waveDist[i - 1]) / num);
		}

		private bool Inside(Vector3 feet)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			if (!waveActive || wavePts == null)
			{
				return false;
			}
			float head = Head;
			float num = head - 4f;
			float num2 = Plugin.CfgWaveWidth.Value * 0.5f + 0.35f;
			for (float num3 = Mathf.Max(0f, num); num3 <= Mathf.Min(head, waveTotal); num3 += 0.25f)
			{
				Vector3 tangent;
				Vector3 val = PointAt(num3, out tangent);
				if (Mathf.Abs(feet.y - val.y) < 1.3f)
				{
					tangent = U.Flat(feet - val);
					if (((Vector3)(ref tangent)).magnitude < num2)
					{
						return true;
					}
				}
			}
			return false;
		}

		private void WaveTick(float dt)
		{
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: 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_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			if (!waveActive)
			{
				Snd.PlayLoop(scurry, on: false, 0.2f, 0.6f);
				return;
			}
			float head = Head;
			if (head - 4f > waveTotal)
			{
				waveActive = false;
				foreach (Transform rat in rats)
				{
					if (Object.op_Implicit((Object)(object)rat))
					{
						((Component)rat).gameObject.SetActive(false);
					}
				}
				Snd.PlayLoop(scurry, on: false, 0.2f, 0.6f);
				return;
			}
			Vector3 tangent;
			Vector3 val = PointAt(Mathf.Clamp(head - 1.6f, 0f, waveTotal), out tangent);
			((Component)scurrySrc).transform.position = val + Vector3.up * 0.2f