DAYR.dll

Decompiled 3 hours ago
using System;
using System.Collections.Generic;
using System.Globalization;
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 Photon.Realtime;
using REPOLib.Modules;
using REPOLib.Objects.Sdk;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Animations;
using UnityEngine.Events;

[assembly: AssemblyFileVersion("0.1.4.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyTitle("DAYR")]
[assembly: AssemblyDescription("DAYR - custom enemy for R.E.P.O.")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.4.0")]
[module: UnverifiableCode]
[module: UnverifiableCode]
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace DAYR
{
	internal class AnimClip
	{
		public string Name;

		public float Fps;

		public bool Loop;

		public int Frames;

		public Vector3[] HipOffset;

		public Quaternion[] Rotations;

		public float Length => (float)(Loop ? Frames : (Frames - 1)) / Fps;

		public void Sample(float time, int boneCount, Quaternion[] outRot, out Vector3 outOffset)
		{
			//IL_0088: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			float num = time * Fps;
			int num2;
			int num3;
			if (Loop)
			{
				num = Mathf.Repeat(num, (float)Frames);
				num2 = Mathf.Min((int)num, Frames - 1);
				num3 = (num2 + 1) % Frames;
			}
			else
			{
				num = Mathf.Clamp(num, 0f, (float)(Frames - 1));
				num2 = (int)num;
				num3 = Mathf.Min(num2 + 1, Frames - 1);
			}
			float num4 = num - (float)num2;
			for (int i = 0; i < boneCount; i++)
			{
				ref Quaternion reference = ref outRot[i];
				reference = Quaternion.Slerp(Rotations[num2 * boneCount + i], Rotations[num3 * boneCount + i], num4);
			}
			outOffset = Vector3.Lerp(HipOffset[num2], HipOffset[num3], num4);
		}
	}
	internal class ModelInstance
	{
		public Transform Root;

		public Transform[] Bones;
	}
	internal static class DayrAssets
	{
		public static string[] BoneNames;

		public static int[] BoneParents;

		public static Vector3[] BoneRest;

		public static Mesh[] Meshes;

		public static Texture2D HeadTexture;

		public static Texture2D BodyTexture;

		public static Texture2D HeadSmoothness;

		public static Texture2D FlatNormal;

		public static AudioClip ChaseVoice;

		public static AudioClip DeathVoice;

		private static readonly Dictionary<string, AnimClip> Clips = new Dictionary<string, AnimClip>();

		public static AnimClip Clip(string name)
		{
			return Clips[name];
		}

		public static void Load()
		{
			LoadModel(Resource("DAYR.model.bin"));
			HeadTexture = LoadTexture("DAYR.head.png", "DAYR_head", linear: false);
			BodyTexture = LoadTexture("DAYR.body.png", "DAYR_body", linear: false);
			HeadSmoothness = LoadTexture("DAYR.head_s.png", "DAYR_head_smoothness", linear: true);
			FlatNormal = MakeFlatNormal();
			ChaseVoice = LoadWav("DAYR.voice_chase.wav", "DAYR_voice_chase");
			DeathVoice = LoadWav("DAYR.voice_death.wav", "DAYR_voice_death_TEMP");
			int num = 0;
			for (int i = 0; i < Meshes.Length; i++)
			{
				num += Meshes[i].vertexCount;
			}
			Plugin.Log.LogInfo((object)$"Assetlar: {num} vertex, {BoneNames.Length} suyak, {Clips.Count} animatsiya, ovoz {ChaseVoice.length:0.00}s / {DeathVoice.length:0.00}s");
		}

		private static byte[] Resource(string name)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
			if (stream == null)
			{
				throw new FileNotFoundException("Ichki resurs topilmadi: " + name);
			}
			MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		private static Texture2D MakeFlatNormal()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(4, 4, (TextureFormat)4, false, true);
			Color32[] array = (Color32[])(object)new Color32[16];
			for (int i = 0; i < array.Length; i++)
			{
				ref Color32 reference = ref array[i];
				reference = new Color32(byte.MaxValue, (byte)128, byte.MaxValue, (byte)128);
			}
			val.SetPixels32(array);
			val.Apply(false, true);
			((Object)val).name = "DAYR_flat_normal";
			((Object)val).hideFlags = (HideFlags)32;
			return val;
		}

		private static Texture2D LoadTexture(string resource, string name, bool linear)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, linear);
			if (!ImageConversion.LoadImage(val, Resource(resource), false))
			{
				throw new InvalidDataException("Tekstura o'qilmadi: " + resource);
			}
			((Object)val).name = name;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)2;
			((Texture)val).anisoLevel = 2;
			val.Compress(true);
			val.Apply(false, true);
			((Object)val).hideFlags = (HideFlags)32;
			return val;
		}

		private static AudioClip LoadWav(string resource, string name)
		{
			byte[] array = Resource(resource);
			if (array.Length < 44 || Encoding.ASCII.GetString(array, 0, 4) != "RIFF")
			{
				throw new InvalidDataException("WAV emas: " + resource);
			}
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = -1;
			int num5 = 0;
			int num6;
			for (int i = 12; i + 8 <= array.Length; i += 8 + num6 + (num6 & 1))
			{
				string text = Encoding.ASCII.GetString(array, i, 4);
				num6 = BitConverter.ToInt32(array, i + 4);
				if (text == "fmt ")
				{
					num = BitConverter.ToInt16(array, i + 10);
					num2 = BitConverter.ToInt32(array, i + 12);
					num3 = BitConverter.ToInt16(array, i + 22);
				}
				else if (text == "data")
				{
					num4 = i + 8;
					num5 = Math.Min(num6, array.Length - num4);
					break;
				}
			}
			if (num3 != 16 || num < 1 || num4 < 0)
			{
				throw new InvalidDataException("Faqat PCM 16-bit WAV: " + resource);
			}
			float[] array2 = new float[num5 / 2];
			for (int j = 0; j < array2.Length; j++)
			{
				array2[j] = (float)BitConverter.ToInt16(array, num4 + j * 2) / 32768f;
			}
			AudioClip val = AudioClip.Create(name, array2.Length / num, num, num2, false);
			val.SetData(array2, 0);
			((Object)val).hideFlags = (HideFlags)32;
			return val;
		}

		private static void LoadModel(byte[] data)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: 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_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_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Expected O, but got Unknown
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_047f: Unknown result type (might be due to invalid IL or missing references)
			BinaryReader binaryReader = new BinaryReader(new MemoryStream(data));
			if (Encoding.ASCII.GetString(binaryReader.ReadBytes(8)) != "DAYRMDL1")
			{
				throw new InvalidDataException("Model formati noto'g'ri");
			}
			int num = binaryReader.ReadInt32();
			BoneNames = new string[num];
			BoneParents = new int[num];
			BoneRest = (Vector3[])(object)new Vector3[num];
			for (int i = 0; i < num; i++)
			{
				BoneNames[i] = Str(binaryReader);
				BoneParents[i] = binaryReader.ReadInt32();
				ref Vector3 reference = ref BoneRest[i];
				reference = V3(binaryReader);
			}
			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++)
			{
				ref Vector3 reference2 = ref array[j];
				reference2 = V3(binaryReader);
			}
			for (int k = 0; k < num2; k++)
			{
				ref Vector3 reference3 = ref array2[k];
				reference3 = V3(binaryReader);
			}
			for (int l = 0; l < num2; l++)
			{
				ref Vector2 reference4 = ref array3[l];
				reference4 = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
			}
			byte[] array4 = binaryReader.ReadBytes(num2 * 4);
			BoneWeight[] array5 = (BoneWeight[])(object)new BoneWeight[num2];
			for (int m = 0; m < num2; m++)
			{
				BoneWeight val = default(BoneWeight);
				((BoneWeight)(ref val)).boneIndex0 = array4[m * 4];
				((BoneWeight)(ref val)).boneIndex1 = array4[m * 4 + 1];
				((BoneWeight)(ref val)).boneIndex2 = array4[m * 4 + 2];
				((BoneWeight)(ref val)).boneIndex3 = array4[m * 4 + 3];
				((BoneWeight)(ref val)).weight0 = binaryReader.ReadSingle();
				((BoneWeight)(ref val)).weight1 = binaryReader.ReadSingle();
				((BoneWeight)(ref val)).weight2 = binaryReader.ReadSingle();
				((BoneWeight)(ref val)).weight3 = binaryReader.ReadSingle();
				array5[m] = val;
			}
			Matrix4x4[] array6 = (Matrix4x4[])(object)new Matrix4x4[num];
			for (int n = 0; n < num; n++)
			{
				ref Matrix4x4 reference5 = ref array6[n];
				reference5 = Matrix4x4.Translate(-BoneRest[n]);
			}
			int num3 = binaryReader.ReadInt32();
			Meshes = (Mesh[])(object)new Mesh[num3];
			for (int num4 = 0; num4 < num3; num4++)
			{
				int num5 = binaryReader.ReadInt32();
				int[] array7 = new int[num5];
				int[] array8 = new int[num2];
				for (int num6 = 0; num6 < num2; num6++)
				{
					array8[num6] = -1;
				}
				List<Vector3> list = new List<Vector3>();
				List<Vector3> list2 = new List<Vector3>();
				List<Vector2> list3 = new List<Vector2>();
				List<BoneWeight> list4 = new List<BoneWeight>();
				for (int num7 = 0; num7 < num5; num7++)
				{
					int num8 = binaryReader.ReadInt32();
					if (array8[num8] < 0)
					{
						array8[num8] = list.Count;
						list.Add(array[num8]);
						list2.Add(array2[num8]);
						list3.Add(array3[num8]);
						list4.Add(array5[num8]);
					}
					array7[num7] = array8[num8];
				}
				Mesh val2 = new Mesh();
				((Object)val2).name = "DAYR_mesh_" + num4;
				val2.vertices = list.ToArray();
				val2.normals = list2.ToArray();
				val2.uv = list3.ToArray();
				val2.boneWeights = list4.ToArray();
				val2.triangles = array7;
				val2.bindposes = array6;
				val2.RecalculateBounds();
				val2.RecalculateTangents();
				((Object)val2).hideFlags = (HideFlags)32;
				Meshes[num4] = val2;
			}
			int num9 = binaryReader.ReadInt32();
			for (int num10 = 0; num10 < num9; num10++)
			{
				AnimClip animClip = new AnimClip();
				animClip.Name = Str(binaryReader);
				animClip.Fps = binaryReader.ReadSingle();
				animClip.Frames = binaryReader.ReadInt32();
				animClip.Loop = binaryReader.ReadByte() != 0;
				animClip.HipOffset = (Vector3[])(object)new Vector3[animClip.Frames];
				animClip.Rotations = (Quaternion[])(object)new Quaternion[animClip.Frames * num];
				for (int num11 = 0; num11 < animClip.Frames; num11++)
				{
					ref Vector3 reference6 = ref animClip.HipOffset[num11];
					reference6 = V3(binaryReader);
					for (int num12 = 0; num12 < num; num12++)
					{
						ref Quaternion reference7 = ref animClip.Rotations[num11 * num + num12];
						reference7 = new Quaternion(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
					}
				}
				Clips[animClip.Name] = animClip;
			}
		}

		private static string Str(BinaryReader r)
		{
			return Encoding.UTF8.GetString(r.ReadBytes(r.ReadInt32()));
		}

		private static Vector3 V3(BinaryReader r)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
		}

		public static int Bone(string name)
		{
			return Array.IndexOf(BoneNames, name);
		}

		public static ModelInstance Build(Transform parent, Material[] materials, int layer)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Expected O, but got Unknown
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			ModelInstance modelInstance = new ModelInstance();
			GameObject val = new GameObject("DAYR Model");
			val.layer = layer;
			val.transform.SetParent(parent, false);
			modelInstance.Root = val.transform;
			modelInstance.Bones = (Transform[])(object)new Transform[BoneNames.Length];
			for (int i = 0; i < BoneNames.Length; i++)
			{
				GameObject val2 = new GameObject("bone_" + BoneNames[i]);
				val2.layer = layer;
				int num = BoneParents[i];
				val2.transform.SetParent((num < 0) ? modelInstance.Root : modelInstance.Bones[num], false);
				val2.transform.localPosition = ((num < 0) ? BoneRest[i] : (BoneRest[i] - BoneRest[num]));
				modelInstance.Bones[i] = val2.transform;
			}
			for (int j = 0; j < Meshes.Length; j++)
			{
				GameObject val3 = new GameObject("DAYR Mesh " + j);
				val3.layer = layer;
				val3.transform.SetParent(modelInstance.Root, false);
				SkinnedMeshRenderer val4 = val3.AddComponent<SkinnedMeshRenderer>();
				val4.sharedMesh = Meshes[j];
				val4.bones = modelInstance.Bones;
				val4.rootBone = modelInstance.Bones[0];
				((Renderer)val4).sharedMaterial = materials[j];
				((Renderer)val4).localBounds = new Bounds(new Vector3(0f, 0f, 0.3f), new Vector3(4.5f, 4.5f, 4.5f));
				val4.updateWhenOffscreen = false;
			}
			return modelInstance;
		}
	}
	internal static class DayrPrefab
	{
		public const string SetupName = "Enemy - DAYR";

		public const string BasePrefab = "Enemies/Enemy - Runner";

		public const string VoiceObjectName = "DAYR Voice";

		private const float Height = 2.45f;

		public static Material[] Materials;

		private static GameObject holder;

		private static bool registered;

		public static void Register()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			if (!registered)
			{
				GameObject val = Resources.Load<GameObject>("Enemies/Enemy - Runner");
				if ((Object)(object)val == (Object)null)
				{
					throw new InvalidOperationException("Asos prefab topilmadi: Enemies/Enemy - Runner");
				}
				holder = new GameObject("DAYR Prefab Holder");
				holder.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)holder);
				((Object)holder).hideFlags = (HideFlags)61;
				GameObject val2 = Object.Instantiate<GameObject>(val, holder.transform);
				((Object)val2).name = "Enemy - DAYR";
				Convert(val2);
				EnemySetup val3 = ScriptableObject.CreateInstance<EnemySetup>();
				((Object)val3).name = "Enemy - DAYR";
				val3.status = (Status)1;
				val3.spawnObjects = new List<PrefabRef>();
				val3.levelsCompletedCondition = false;
				val3.runsPlayed = 0;
				RarityPreset val4 = ScriptableObject.CreateInstance<RarityPreset>();
				((Object)val4).name = "DAYR Rarity";
				val4.chance = Plugin.Cfg.SpawnWeight.Value;
				val3.rarityPreset = val4;
				((Object)val3).hideFlags = (HideFlags)32;
				((Object)val4).hideFlags = (HideFlags)32;
				if (Plugin.Cfg.SpawnWeight.Value <= 0f)
				{
					val3.levelsCompletedCondition = true;
					val3.levelsCompletedMin = 100000;
					val3.levelsCompletedMax = 0;
				}
				EnemyContent val5 = ScriptableObject.CreateInstance<EnemyContent>();
				((Object)val5).name = "Enemy - DAYR";
				((Object)val5).hideFlags = (HideFlags)32;
				AccessTools.Field(typeof(EnemyContent), "_setup").SetValue(val5, val3);
				AccessTools.Field(typeof(EnemyContent), "_spawnObjects").SetValue(val5, new List<GameObject> { val2 });
				Enemies.RegisterEnemy(val5);
				registered = true;
				Plugin.Log.LogInfo((object)"DAYR REPOLib'da ro'yxatdan o'tkazildi: \"Enemy - DAYR\"");
			}
		}

		private static T Require<T>(T value, string what) where T : class
		{
			if (value == null || value.Equals(null))
			{
				throw new InvalidOperationException("Asos prefabda yo'q: " + what);
			}
			return value;
		}

		private static GameObject Child(Transform parent, string name, Vector3 localPosition)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.layer = ((Component)parent).gameObject.layer;
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPosition;
			return val;
		}

		private static void Convert(GameObject prefab)
		{
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: 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_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0470: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0600: Unknown result type (might be due to invalid IL or missing references)
			//IL_0614: Unknown result type (might be due to invalid IL or missing references)
			//IL_0619: Unknown result type (might be due to invalid IL or missing references)
			//IL_0651: Unknown result type (might be due to invalid IL or missing references)
			//IL_0669: Unknown result type (might be due to invalid IL or missing references)
			//IL_0673: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0757: Unknown result type (might be due to invalid IL or missing references)
			//IL_075c: Unknown result type (might be due to invalid IL or missing references)
			//IL_076f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0783: Unknown result type (might be due to invalid IL or missing references)
			//IL_0788: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = prefab.transform;
			EnemyParent val = Require<EnemyParent>(prefab.GetComponent<EnemyParent>(), "EnemyParent");
			EnemyRunner val2 = Require<EnemyRunner>(prefab.GetComponentInChildren<EnemyRunner>(true), "EnemyRunner");
			EnemyRunnerAnim val3 = Require<EnemyRunnerAnim>(val2.animator, "EnemyRunnerAnim");
			GameObject gameObject = ((Component)val2).gameObject;
			Transform parent = gameObject.transform.parent;
			Enemy val4 = Require<Enemy>(gameObject.GetComponent<Enemy>(), "Enemy");
			EnemyHealth val5 = Require<EnemyHealth>(gameObject.GetComponent<EnemyHealth>(), "EnemyHealth");
			EnemyVision val6 = Require<EnemyVision>(gameObject.GetComponent<EnemyVision>(), "EnemyVision");
			EnemyOnScreen val7 = Require<EnemyOnScreen>(gameObject.GetComponent<EnemyOnScreen>(), "EnemyOnScreen");
			EnemyRigidbody val8 = Require<EnemyRigidbody>(prefab.GetComponentInChildren<EnemyRigidbody>(true), "EnemyRigidbody");
			HurtCollider val9 = Require<HurtCollider>(val2.hurtCollider, "HurtCollider");
			GameObject gameObject2 = ((Component)val3).gameObject;
			Material val10 = null;
			MeshRenderer[] componentsInChildren = gameObject2.GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val11 in componentsInChildren)
			{
				Material sharedMaterial = ((Renderer)val11).sharedMaterial;
				if ((Object)(object)sharedMaterial != (Object)null && (Object)(object)sharedMaterial.shader != (Object)null && ((Object)sharedMaterial.shader).name.StartsWith("Hurtable") && sharedMaterial.HasProperty("_AlbedoTexture"))
				{
					val10 = sharedMaterial;
					if (((Object)sharedMaterial.shader).name.Contains("Alpha Clip"))
					{
						break;
					}
				}
			}
			Require<Material>(val10, "Hurtable material");
			Materials = (Material[])(object)new Material[2]
			{
				MakeMaterial(val10, "DAYR Head", DayrAssets.HeadTexture, DayrAssets.HeadSmoothness, 1f),
				MakeMaterial(val10, "DAYR Body", DayrAssets.BodyTexture, Texture2D.whiteTexture, 0.08f)
			};
			for (int j = 0; j < Materials.Length; j++)
			{
				Plugin.Log.LogInfo((object)DescribeMaterial(Materials[j]));
			}
			AudioSource val12 = null;
			AudioSource[] componentsInChildren2 = prefab.GetComponentsInChildren<AudioSource>(true);
			foreach (AudioSource val13 in componentsInChildren2)
			{
				if ((Object)(object)((Component)val13).GetComponent<AudioLowPassLogic>() != (Object)null)
				{
					val12 = val13;
					break;
				}
			}
			Require<AudioSource>(val12, "AudioSource + AudioLowPassLogic");
			GameObject val14 = Child(parent, "DAYR Visual", Vector3.zero);
			ModelInstance modelInstance = DayrAssets.Build(val14.transform, Materials, 0);
			Transform val15 = modelInstance.Bones[DayrAssets.Bone("head")];
			GameObject val16 = Object.Instantiate<GameObject>(((Component)val12).gameObject, val15);
			((Object)val16).name = "DAYR Voice";
			val16.transform.localPosition = new Vector3(0f, 0.12f, 0.12f);
			val16.SetActive(true);
			RemoveConstraints(val16);
			AudioSource component = val16.GetComponent<AudioSource>();
			component.Stop();
			component.clip = null;
			component.loop = false;
			component.playOnAwake = false;
			component.volume = Plugin.Cfg.ChaseVoiceVolume.Value;
			component.pitch = 1f;
			component.spatialBlend = 1f;
			component.dopplerLevel = 0f;
			component.rolloffMode = (AudioRolloffMode)0;
			component.minDistance = 3f;
			component.maxDistance = Plugin.Cfg.ChaseVoiceDistance.Value;
			AudioLowPassLogic component2 = val16.GetComponent<AudioLowPassLogic>();
			component2.HasCustomVolume = false;
			component2.HasCustomFalloff = false;
			Transform transform2 = Child(val14.transform, "Vision Transform", new Vector3(0f, 2.2f, 0.42f)).transform;
			Transform transform3 = Child(val15, "Kill Look At", new Vector3(0f, 0.16f, 0.14f)).transform;
			Transform[] points = (Transform[])(object)new Transform[3]
			{
				Child(val14.transform, "On Screen Point Top", new Vector3(0f, 2.3f, 0.2f)).transform,
				Child(val14.transform, "On Screen Point Mid", new Vector3(0f, 1.4f, 0.1f)).transform,
				Child(val14.transform, "On Screen Point Bot", new Vector3(0f, 0.4f, 0.1f)).transform
			};
			RemoveConstraints(((Component)val9).gameObject);
			((Component)val9).transform.SetParent(val14.transform, false);
			((Component)val9).transform.localPosition = Vector3.zero;
			((Component)val9).transform.localRotation = Quaternion.identity;
			((Component)val9).transform.localScale = Vector3.one;
			BoxCollider val17 = Require<BoxCollider>(((Component)val9).GetComponent<BoxCollider>(), "Hurt BoxCollider");
			val17.center = new Vector3(0f, 1.05f, 1.05f);
			val17.size = new Vector3(1.5f, 2f, 1.7f);
			val9.playerLogic = true;
			val9.playerKill = false;
			val9.playerDamage = Plugin.Cfg.Damage.Value;
			val9.playerDamageCooldown = 1.2f;
			val9.enemyHost = val4;
			((Component)val9).gameObject.SetActive(false);
			val6.VisionTransform = transform2;
			val6.VisionDistance = Plugin.Cfg.VisionDistance.Value;
			val4.KillLookAtTransform = transform3;
			val7.points = points;
			val5.meshParent = modelInstance.Root;
			val5.health = Plugin.Cfg.Health.Value;
			Require<EnemyStateInvestigate>(gameObject.GetComponent<EnemyStateInvestigate>(), "EnemyStateInvestigate").OnlyEvent = true;
			val.enemyName = "DAYR";
			val.enemyNameLocalized = null;
			val.difficulty = (Difficulty)(Plugin.Cfg.Difficulty.Value - 1);
			Transform val18 = Require<Transform>(((Component)val8).transform.Find("Collider"), "Rigidbody/Collider");
			CapsuleCollider val19 = Require<CapsuleCollider>(((Component)val18).GetComponent<CapsuleCollider>(), "CapsuleCollider");
			Transform val20 = Require<Transform>(((Component)val8).transform.Find("Feet Transform"), "Feet Transform");
			float num = val20.localPosition.y + 0.03f;
			Vector3 localScale = val18.localScale;
			localScale.y = 2.3500001f / val19.height;
			localScale.x = (localScale.z = 0.36f / val19.radius);
			val18.localScale = localScale;
			val18.localPosition = new Vector3(0f, num + 1.1750001f, val18.localPosition.z);
			Transform centerTransform = val4.CenterTransform;
			if ((Object)(object)centerTransform != (Object)null && (Object)(object)centerTransform.parent == (Object)(object)((Component)val8).transform)
			{
				centerTransform.localPosition = new Vector3(0f, val20.localPosition.y + 1.35f, 0f);
			}
			NavMeshAgent component3 = gameObject.GetComponent<NavMeshAgent>();
			if ((Object)(object)component3 != (Object)null)
			{
				component3.height = 2.45f;
			}
			Transform val21 = transform.Find("Particles");
			if ((Object)(object)val21 != (Object)null)
			{
				for (int num2 = val21.childCount - 1; num2 >= 0; num2--)
				{
					Transform child = val21.GetChild(num2);
					ParticleSystem component4 = ((Component)child).GetComponent<ParticleSystem>();
					if (((Object)child).name.Contains("Hay") || (Object)(object)component4 == (Object)null)
					{
						Object.DestroyImmediate((Object)(object)((Component)child).gameObject);
					}
					else
					{
						MainModule main = component4.main;
						((MainModule)(ref main)).startColor = new MinMaxGradient(new Color(0.28f, 0.02f, 0.02f), new Color(0.12f, 0.01f, 0.01f));
					}
				}
			}
			GameEventObjectSwap[] componentsInChildren3 = prefab.GetComponentsInChildren<GameEventObjectSwap>(true);
			foreach (GameEventObjectSwap val22 in componentsInChildren3)
			{
				Object.DestroyImmediate((Object)(object)val22);
			}
			Object.DestroyImmediate((Object)(object)val2);
			Object.DestroyImmediate((Object)(object)gameObject2);
			Transform val23 = parent.Find("[AUDIO]");
			if ((Object)(object)val23 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)val23).gameObject);
			}
			gameObject.AddComponent<EnemyDayr>();
			val14.AddComponent<DayrVisual>();
			PhotonView[] componentsInChildren4 = prefab.GetComponentsInChildren<PhotonView>(true);
			foreach (PhotonView val24 in componentsInChildren4)
			{
				if (val24.ObservedComponents != null)
				{
					val24.ObservedComponents.RemoveAll((Component c) => (Object)(object)c == (Object)null);
				}
			}
			ReportMissingReferences(prefab);
		}

		private static void RemoveConstraints(GameObject go)
		{
			Behaviour[] components = go.GetComponents<Behaviour>();
			for (int i = 0; i < components.Length; i++)
			{
				if (components[i] is IConstraint)
				{
					Object.DestroyImmediate((Object)(object)components[i]);
				}
			}
		}

		private static Material MakeMaterial(Material source, string name, Texture2D albedo, Texture2D smoothnessMap, float smoothness)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(source);
			((Object)val).name = name;
			((Object)val).hideFlags = (HideFlags)32;
			RequireProperty(val, "_AlbedoTexture");
			RequireProperty(val, "_OffsetX");
			RequireProperty(val, "_OffsetY");
			SetTexture(val, "_AlbedoTexture", (Texture)(object)albedo);
			SetTexture(val, "_NormalTexture", (Texture)(object)DayrAssets.FlatNormal);
			SetTexture(val, "_EmissionTexture", (Texture)(object)Texture2D.blackTexture);
			SetTexture(val, "_MetallicTexture", (Texture)(object)Texture2D.blackTexture);
			SetTexture(val, "_SmoothnessTexture", (Texture)(object)smoothnessMap);
			SetTexture(val, "_texcoord", null);
			if (val.HasProperty("_texcoord"))
			{
				val.SetTextureScale("_texcoord", Vector2.one);
				val.SetTextureOffset("_texcoord", Vector2.zero);
			}
			SetFloat(val, "_TilingX", 1f);
			SetFloat(val, "_TilingY", 1f);
			SetFloat(val, "_OffsetX", 0f);
			SetFloat(val, "_OffsetY", 0f);
			SetColor(val, "_AlbedoColor", Color.white);
			SetColor(val, "_Color", Color.white);
			SetColor(val, "_EmissionColor", Color.black);
			SetFloat(val, "_NormalStrength", 0f);
			SetFloat(val, "_Metallic", 0f);
			SetFloat(val, "_Smoothness", smoothness);
			SetFloat(val, "_Cutoff", 0.5f);
			SetColor(val, "_FresnelColor", Color.black);
			SetFloat(val, "_FresnelAmount", 0f);
			SetFloat(val, "_FresnelEmission", 0f);
			SetFloat(val, "_FresnelScale", 0f);
			SetFloat(val, "_FresnelBias", 0f);
			SetFloat(val, "_FresnelPower", 5f);
			SetFloat(val, "_ColorOverlayAmount", 0f);
			return val;
		}

		private static void RequireProperty(Material m, string property)
		{
			if (!m.HasProperty(property))
			{
				Plugin.Log.LogWarning((object)("DAYR: shaderda " + property + " yo'q - o'yin yangilangan bo'lishi mumkin"));
			}
		}

		public static string DescribeMaterial(Material m)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)m == (Object)null)
			{
				return "DAYR material: yo'q";
			}
			Texture2D val = (Texture2D)(m.HasProperty("_AlbedoTexture") ? /*isinst with value type is only supported in some contexts*/: null);
			string text = (((Object)(object)val == (Object)null) ? "YO'Q" : $"{((Object)val).name} {((Texture)val).width}x{((Texture)val).height} {val.format} mip={((Texture)val).mipmapCount} {((Texture)val).wrapMode}");
			return string.Format("DAYR material \"{0}\": shader=\"{1}\" qo'llab-quvvatlanadi={2} albedo=[{3}] tiling=({4},{5}) offset=({6},{7}) normal={8} metallic={9} smoothness={10} cutoff={11} fresnel={12}", ((Object)m).name, ((Object)m.shader).name, m.shader.isSupported, text, F(m, "_TilingX"), F(m, "_TilingY"), F(m, "_OffsetX"), F(m, "_OffsetY"), F(m, "_NormalStrength"), F(m, "_Metallic"), F(m, "_Smoothness"), F(m, "_Cutoff"), F(m, "_FresnelAmount"));
		}

		private static string F(Material m, string p)
		{
			if (!m.HasProperty(p))
			{
				return "-";
			}
			return m.GetFloat(p).ToString("0.###", CultureInfo.InvariantCulture);
		}

		private static void SetTexture(Material m, string p, Texture t)
		{
			if (m.HasProperty(p))
			{
				m.SetTexture(p, t);
			}
		}

		private static void SetColor(Material m, string p, Color c)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (m.HasProperty(p))
			{
				m.SetColor(p, c);
			}
		}

		private static void SetFloat(Material m, string p, float v)
		{
			if (m.HasProperty(p))
			{
				m.SetFloat(p, v);
			}
		}

		private static void ReportMissingReferences(GameObject prefab)
		{
			int num = 0;
			MonoBehaviour[] componentsInChildren = prefab.GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null)
				{
					Plugin.Log.LogWarning((object)"DAYR prefab: skripti yo'q komponent");
					continue;
				}
				FieldInfo[] fields = ((object)val).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					if (typeof(Object).IsAssignableFrom(fieldInfo.FieldType) && (fieldInfo.IsPublic || fieldInfo.GetCustomAttributes(typeof(SerializeField), inherit: true).Length > 0))
					{
						object value = fieldInfo.GetValue(val);
						Object val2 = (Object)((value is Object) ? value : null);
						if (!object.ReferenceEquals(value, null) && val2 == (Object)null)
						{
							num++;
							Plugin.Log.LogInfo((object)$"DAYR prefab: bo'sh ishora {((object)val).GetType().Name}.{fieldInfo.Name} ({((Object)val).name})");
						}
					}
				}
			}
			Plugin.Log.LogInfo((object)("DAYR prefab tayyor. Bo'sh ishoralar soni: " + num));
		}
	}
	internal class DayrVisual : MonoBehaviour
	{
		private const float WalkClipSpeed = 1.45f;

		private const float RunClipSpeed = 4.6f;

		private const float FlinchLength = 0.45f;

		private const float FlinchPeak = 0.07f;

		private EnemyDayr controller;

		private Transform feet;

		private Transform[] bones;

		private Vector3 hipsRest;

		private Quaternion[] pose;

		private Quaternion[] from;

		private Quaternion[] sample;

		private Vector3 poseOffset;

		private Vector3 fromOffset;

		private AnimClip clip;

		private float clipTime;

		private float blend = 1f;

		private float blendLength = 0.2f;

		private Vector3 lastPosition;

		private float speed;

		private bool restart = true;

		private Vector3[] flinch;

		private Vector3[] flinchSway;

		private float flinchTime = 0.45f;

		private float flinchSide = 1f;

		private void Awake()
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = ((Component)this).transform.parent;
			controller = ((Component)parent).GetComponentInChildren<EnemyDayr>(true);
			EnemyRigidbody componentInChildren = ((Component)parent).GetComponentInChildren<EnemyRigidbody>(true);
			feet = ((Component)componentInChildren).transform.Find("Feet Transform");
			if ((Object)(object)feet == (Object)null)
			{
				Plugin.Log.LogError((object)"DAYR: 'Feet Transform' topilmadi");
			}
			Transform val = ((Component)this).transform.Find("DAYR Model");
			Transform[] componentsInChildren = ((Component)val).GetComponentsInChildren<Transform>(true);
			int num = DayrAssets.BoneNames.Length;
			bones = (Transform[])(object)new Transform[num];
			for (int i = 0; i < num; i++)
			{
				string text = "bone_" + DayrAssets.BoneNames[i];
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					if (((Object)componentsInChildren[j]).name == text)
					{
						bones[i] = componentsInChildren[j];
						break;
					}
				}
			}
			hipsRest = DayrAssets.BoneRest[0];
			pose = (Quaternion[])(object)new Quaternion[num];
			from = (Quaternion[])(object)new Quaternion[num];
			sample = (Quaternion[])(object)new Quaternion[num];
			for (int k = 0; k < num; k++)
			{
				ref Quaternion reference = ref pose[k];
				ref Quaternion reference2 = ref from[k];
				reference = (reference2 = Quaternion.identity);
			}
			flinch = (Vector3[])(object)new Vector3[num];
			flinchSway = (Vector3[])(object)new Vector3[num];
			Bend("spine1", -9f, 0f, 0f);
			Bend("spine2", -10f, 0f, 0f);
			Bend("chest", -9f, 0f, 0f);
			Bend("head", -20f, 0f, 0f);
			Bend("upperarm_R", 20f, 0f, 24f);
			Bend("upperarm_L", 20f, 0f, -24f);
			Bend("forearm_R", -14f, 0f, 0f);
			Bend("forearm_L", -14f, 0f, 0f);
			Sway("chest", 0f, 8f, 0f);
			Sway("head", 0f, 0f, 14f);
		}

		private void Bend(string bone, float x, float y, float z)
		{
			//IL_001b: 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)
			int num = DayrAssets.Bone(bone);
			if (num >= 0)
			{
				ref Vector3 reference = ref flinch[num];
				reference = new Vector3(x, y, z);
			}
		}

		private void Sway(string bone, float x, float y, float z)
		{
			//IL_001b: 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)
			int num = DayrAssets.Bone(bone);
			if (num >= 0)
			{
				ref Vector3 reference = ref flinchSway[num];
				reference = new Vector3(x, y, z);
			}
		}

		public void Flinch()
		{
			float num = FlinchWeight(flinchTime);
			if (num < 0.05f)
			{
				flinchSide = 0f - flinchSide;
			}
			flinchTime = num * 0.07f;
		}

		private static float FlinchWeight(float t)
		{
			if (t >= 0.45f)
			{
				return 0f;
			}
			if (t < 0.07f)
			{
				return t / 0.07f;
			}
			float num = 1f - (t - 0.07f) / 0.38f;
			return num * num;
		}

		private void OnEnable()
		{
			restart = true;
			flinchTime = 0.45f;
		}

		private void Start()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.Cfg.DebugLog.Value)
			{
				return;
			}
			SkinnedMeshRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<SkinnedMeshRenderer>(true);
			Vector2 val = default(Vector2);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Vector2[] uv = componentsInChildren[i].sharedMesh.uv;
				((Vector2)(ref val))..ctor(1f, 1f);
				Vector2 val2 = Vector2.zero;
				for (int j = 0; j < uv.Length; j++)
				{
					val = Vector2.Min(val, uv[j]);
					val2 = Vector2.Max(val2, uv[j]);
				}
				Plugin.Log.LogInfo((object)string.Format("DAYR sahnada \"{0}\": {1} vertex, UV {2}..{3}", ((Object)componentsInChildren[i]).name, uv.Length, ((Vector2)(ref val)).ToString("F3"), ((Vector2)(ref val2)).ToString("F3")));
				Plugin.Log.LogInfo((object)DayrPrefab.DescribeMaterial(((Renderer)componentsInChildren[i]).sharedMaterial));
			}
		}

		public void CopyPose(Quaternion[] rotations, out Vector3 offset)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < pose.Length; i++)
			{
				ref Quaternion reference = ref rotations[i];
				reference = pose[i];
			}
			offset = poseOffset;
		}

		private void LateUpdate()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0446: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_044b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)feet != (Object)null)
			{
				((Component)this).transform.position = feet.position;
				((Component)this).transform.rotation = feet.rotation;
			}
			float deltaTime = Time.deltaTime;
			if (deltaTime <= 0f)
			{
				return;
			}
			if (restart)
			{
				lastPosition = ((Component)this).transform.position;
				speed = 0f;
				clip = null;
			}
			Vector3 val = ((Component)this).transform.position - lastPosition;
			lastPosition = ((Component)this).transform.position;
			val.y = 0f;
			float num = ((Vector3)(ref val)).magnitude / deltaTime;
			if (num > 20f)
			{
				num = speed;
			}
			speed = Mathf.Lerp(speed, num, 1f - Mathf.Exp(-8f * deltaTime));
			DayrState dayrState = ((!((Object)(object)controller != (Object)null)) ? DayrState.Idle : controller.State);
			float num2 = 1f;
			string text;
			switch (dayrState)
			{
			case DayrState.Attack:
				text = "attack";
				break;
			case DayrState.Stun:
				text = "stun";
				break;
			default:
			{
				if (speed < 0.2f)
				{
					text = "idle";
					break;
				}
				bool flag = ((clip != null && clip.Name == "run") ? (speed > 2.3f) : (speed > 2.8f));
				text = (flag ? "run" : "walk");
				num2 = Mathf.Clamp(speed / (flag ? 4.6f : 1.45f), 0.55f, 1.8f);
				break;
			}
			}
			bool flag2 = dayrState == DayrState.Attack && (Object)(object)controller != (Object)null && controller.ConsumeAttackImpulse();
			if (clip == null || clip.Name != text || flag2)
			{
				for (int i = 0; i < pose.Length; i++)
				{
					ref Quaternion reference = ref from[i];
					reference = pose[i];
				}
				fromOffset = poseOffset;
				clip = DayrAssets.Clip(text);
				clipTime = 0f;
				blend = (restart ? 1f : 0f);
				blendLength = ((text == "attack") ? 0.1f : 0.25f);
				restart = false;
			}
			clipTime += deltaTime * num2;
			blend = Mathf.Min(1f, blend + deltaTime / blendLength);
			clip.Sample(clipTime, pose.Length, sample, out var outOffset);
			flinchTime = Mathf.Min(0.45f, flinchTime + deltaTime);
			float num3 = FlinchWeight(flinchTime);
			for (int j = 0; j < pose.Length; j++)
			{
				ref Quaternion reference2 = ref pose[j];
				reference2 = ((blend < 1f) ? Quaternion.Slerp(from[j], sample[j], blend) : sample[j]);
				if (!((Object)(object)bones[j] == (Object)null))
				{
					bones[j].localRotation = ((num3 > 0f) ? (pose[j] * Quaternion.Euler((flinch[j] + flinchSway[j] * flinchSide) * num3)) : pose[j]);
				}
			}
			poseOffset = ((blend < 1f) ? Vector3.Lerp(fromOffset, outOffset, blend) : outOffset);
			bones[0].localPosition = hipsRest + poseOffset;
		}
	}
	internal class DayrCorpse : MonoBehaviour
	{
		private const float StayTime = 5f;

		private const float SinkTime = 2.5f;

		private ModelInstance model;

		private Quaternion[] start;

		private Quaternion[] sample;

		private Vector3 startOffset;

		private float time;

		public static void Spawn(DayrVisual source, Material[] materials)
		{
			//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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)source == (Object)null))
			{
				Vector3 position = ((Component)source).transform.position;
				Quaternion val = Quaternion.Euler(0f, ((Component)source).transform.eulerAngles.y, 0f);
				RaycastHit val2 = default(RaycastHit);
				if (Physics.Raycast(position + Vector3.up * 1.2f, Vector3.down, ref val2, 8f, LayerMask.GetMask(new string[1] { "Default" }), (QueryTriggerInteraction)1))
				{
					position.y = ((RaycastHit)(ref val2)).point.y;
				}
				GameObject val3 = new GameObject("DAYR Corpse");
				val3.transform.SetPositionAndRotation(position, val);
				DayrCorpse dayrCorpse = val3.AddComponent<DayrCorpse>();
				dayrCorpse.model = DayrAssets.Build(val3.transform, materials, 0);
				dayrCorpse.start = (Quaternion[])(object)new Quaternion[DayrAssets.BoneNames.Length];
				dayrCorpse.sample = (Quaternion[])(object)new Quaternion[DayrAssets.BoneNames.Length];
				source.CopyPose(dayrCorpse.start, out dayrCorpse.startOffset);
				dayrCorpse.Apply();
			}
		}

		private void LateUpdate()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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)
			time += Time.deltaTime;
			Apply();
			if (time > 5f)
			{
				Transform transform = ((Component)this).transform;
				transform.position += Vector3.down * (0.35f * Time.deltaTime);
			}
			if (time > 7.5f)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		private void Apply()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			DayrAssets.Clip("death").Sample(time, sample.Length, sample, out var outOffset);
			float num = Mathf.Clamp01(time / 0.15f);
			for (int i = 0; i < sample.Length; i++)
			{
				model.Bones[i].localRotation = Quaternion.Slerp(start[i], sample[i], num);
			}
			model.Bones[0].localPosition = DayrAssets.BoneRest[0] + Vector3.Lerp(startOffset, outOffset, num);
		}
	}
	internal enum DayrState
	{
		Spawn,
		Idle,
		Roam,
		Investigate,
		Notice,
		Chase,
		Attack,
		Seek,
		Stun,
		Leave,
		Despawn
	}
	internal class EnemyDayr : MonoBehaviourPunCallbacks
	{
		private const float AttackLength = 1.1f;

		private const float HitFrom = 0.44f;

		private const float HitTo = 0.7f;

		private Enemy enemy;

		private PhotonView view;

		private bool despawnSent;

		private Transform parentRoot;

		private DayrVisual visual;

		private HurtCollider hurtCollider;

		private AudioSource voice;

		private ParticleSystem[] deathParticles;

		private bool stateImpulse;

		private float stateTimer;

		private float attackClock;

		private bool attackImpulse;

		private float attackCooldown;

		private PlayerAvatar target;

		private Vector3 destination;

		private Vector3 lastKnown;

		private float lastSeen;

		private float sightTimer;

		private bool sightCache;

		private float nextVoice;

		private bool dead;

		private int attackDamage;

		private Quaternion facing = Quaternion.identity;

		public DayrState State { get; private set; }

		private bool IsHost => SemiFunc.IsMasterClientOrSingleplayer();

		private void Awake()
		{
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Expected O, but got Unknown
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: 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_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: 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_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Expected O, but got Unknown
			enemy = ((Component)this).GetComponent<Enemy>();
			view = ((Component)this).GetComponent<PhotonView>();
			EnemyParent componentInParent = ((Component)this).GetComponentInParent<EnemyParent>();
			parentRoot = ((Component)componentInParent).transform;
			Transform parent = ((Component)this).transform.parent;
			visual = ((Component)parent).GetComponentInChildren<DayrVisual>(true);
			hurtCollider = ((Component)parent).GetComponentInChildren<HurtCollider>(true);
			Transform[] componentsInChildren = ((Component)parent).GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if (((Object)componentsInChildren[i]).name == "DAYR Voice")
				{
					voice = ((Component)componentsInChildren[i]).GetComponent<AudioSource>();
					break;
				}
			}
			Transform val = parentRoot.Find("Particles");
			deathParticles = (ParticleSystem[])(((Object)(object)val != (Object)null) ? ((Array)((Component)val).GetComponentsInChildren<ParticleSystem>(true)) : ((Array)new ParticleSystem[0]));
			attackDamage = Plugin.Cfg.Damage.Value;
			if ((Object)(object)hurtCollider != (Object)null)
			{
				((Component)hurtCollider).gameObject.SetActive(false);
			}
			((Component)this).GetComponent<EnemyStateSpawn>().OnSpawn.AddListener(new UnityAction(OnSpawn));
			EnemyHealth component = ((Component)this).GetComponent<EnemyHealth>();
			component.onHurt.AddListener(new UnityAction(OnHurt));
			component.onDeath.AddListener(new UnityAction(OnDeath));
			((Component)this).GetComponent<EnemyVision>().onVisionTriggered.AddListener(new UnityAction(OnVision));
			((Component)this).GetComponent<EnemyStateInvestigate>().onInvestigateTriggered.AddListener(new UnityAction(OnInvestigate));
			EnemyRigidbody componentInChildren = ((Component)parent).GetComponentInChildren<EnemyRigidbody>(true);
			componentInChildren.onGrabbed.AddListener(new UnityAction(OnGrabbed));
			if ((Object)(object)voice == (Object)null)
			{
				Plugin.Log.LogError((object)"DAYR: ovoz manbasi topilmadi");
			}
			if ((Object)(object)hurtCollider == (Object)null)
			{
				Plugin.Log.LogError((object)"DAYR: HurtCollider topilmadi");
			}
		}

		private void Start()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			EnemyHealth component = ((Component)this).GetComponent<EnemyHealth>();
			if (!((Object)(object)visual == (Object)null) && !((Object)(object)component == (Object)null))
			{
				SkinnedMeshRenderer[] componentsInChildren = ((Component)visual).GetComponentsInChildren<SkinnedMeshRenderer>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					Material material = ((Renderer)componentsInChildren[i]).material;
					((Object)material).hideFlags = (HideFlags)0;
					material.SetColor("_ColorOverlay", component.hurtColor);
					component.instancedMaterials.Add(material);
				}
				if (Plugin.Cfg.DebugLog.Value)
				{
					Plugin.Log.LogInfo((object)("DAYR zarar chaqnashi ulandi: " + component.instancedMaterials.Count + " material"));
				}
			}
		}

		private void Update()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Invalid comparison between Unknown and I4
			UpdateHitWindow();
			if (IsHost && !dead && (!((Object)(object)LevelGenerator.Instance != (Object)null) || LevelGenerator.Instance.Generated))
			{
				if ((int)enemy.CurrentState == 11 && !enemy.IsStunned())
				{
					SetState(DayrState.Despawn);
				}
				else if (State == DayrState.Despawn)
				{
					SetState(DayrState.Idle);
				}
				if (enemy.IsStunned())
				{
					SetState(DayrState.Stun);
				}
				if (attackCooldown > 0f)
				{
					attackCooldown -= Time.deltaTime;
				}
				switch (State)
				{
				case DayrState.Spawn:
					UpdateSpawn();
					break;
				case DayrState.Idle:
					UpdateIdle();
					break;
				case DayrState.Roam:
					UpdateRoam();
					break;
				case DayrState.Investigate:
					UpdateInvestigate();
					break;
				case DayrState.Notice:
					UpdateNotice();
					break;
				case DayrState.Chase:
					UpdateChase();
					break;
				case DayrState.Attack:
					UpdateAttack();
					break;
				case DayrState.Seek:
					UpdateSeek();
					break;
				case DayrState.Stun:
					UpdateStun();
					break;
				case DayrState.Leave:
					UpdateLeave();
					break;
				case DayrState.Despawn:
					UpdateDespawn();
					break;
				}
				UpdateRotation();
				UpdateVoiceSchedule();
			}
		}

		private bool Entering()
		{
			if (!stateImpulse)
			{
				return false;
			}
			stateImpulse = false;
			return true;
		}

		private void UpdateSpawn()
		{
			if (Entering())
			{
				stateTimer = 1f;
			}
			stateTimer -= Time.deltaTime;
			if (stateTimer <= 0f)
			{
				SetState(DayrState.Idle);
			}
		}

		private void UpdateIdle()
		{
			if (Entering())
			{
				stateTimer = Random.Range(1.5f, 4f);
				Halt();
			}
			enemy.Rigidbody.IdleSet(0.1f);
			if (!SemiFunc.EnemySpawnIdlePause())
			{
				stateTimer -= Time.deltaTime;
				if (stateTimer <= 0f)
				{
					SetState(DayrState.Roam);
				}
				if (SemiFunc.EnemyForceLeave(enemy))
				{
					SetState(DayrState.Leave);
				}
			}
		}

		private void UpdateRoam()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (stateImpulse)
			{
				LevelPoint val = SemiFunc.LevelPointGet(((Component)this).transform.position, 10f, 25f);
				if ((Object)(object)val == (Object)null)
				{
					val = SemiFunc.LevelPointGet(((Component)this).transform.position, 0f, 999f);
				}
				if (!TryNavPoint(val, out destination))
				{
					return;
				}
				stateImpulse = false;
				stateTimer = 5f;
				enemy.Rigidbody.notMovingTimer = 0f;
			}
			Move(destination, Plugin.Cfg.WalkSpeed.Value, 5f);
			TickWhenStuck();
			JumpWhenStuck(destination);
			if (stateTimer <= 0f || FlatDistance(((Component)this).transform.position, destination) < 1.2f)
			{
				SetState(DayrState.Idle);
			}
			if (SemiFunc.EnemyForceLeave(enemy))
			{
				SetState(DayrState.Leave);
			}
		}

		private void UpdateInvestigate()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			if (Entering())
			{
				stateTimer = 6f;
				enemy.Rigidbody.notMovingTimer = 0f;
			}
			Move(destination, Plugin.Cfg.WalkSpeed.Value * 1.7f, 7f);
			TickWhenStuck();
			JumpWhenStuck(destination);
			if (stateTimer <= 0f || FlatDistance(((Component)this).transform.position, destination) < 1.6f)
			{
				SetState(DayrState.Idle);
			}
			if (SemiFunc.EnemyForceLeave(enemy))
			{
				SetState(DayrState.Leave);
			}
		}

		private void UpdateNotice()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (!TargetValid())
			{
				SetState(DayrState.Idle);
				return;
			}
			if (Entering())
			{
				stateTimer = 0.7f;
				Halt();
				lastSeen = Time.time;
				lastKnown = ((Component)target).transform.position;
			}
			stateTimer -= Time.deltaTime;
			if (stateTimer <= 0f)
			{
				SetState(DayrState.Chase);
			}
		}

		private void UpdateChase()
		{
			//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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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_00a4: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			if (!TargetValid())
			{
				SetState(DayrState.Seek);
				return;
			}
			if (Entering())
			{
				enemy.Rigidbody.notMovingTimer = 0f;
			}
			Vector3 position = ((Component)target).transform.position;
			if (CanSeeTarget())
			{
				lastSeen = Time.time;
			}
			bool flag = Time.time - lastSeen < Plugin.Cfg.ChaseMemory.Value;
			if (flag)
			{
				lastKnown = position;
			}
			Move(lastKnown, ChaseSpeed(), 14f);
			JumpWhenStuck(lastKnown);
			Vector3 a = BodyPosition();
			float num = FlatDistance(a, position);
			float num2 = Mathf.Abs(position.y - a.y);
			float num3 = Plugin.Cfg.AttackRange.Value + (target.isCrawling ? 0.4f : 0f);
			if (attackCooldown <= 0f && num <= num3 && num2 < 2.2f && (CanSeeTarget() || (target.isCrawling && num < 1.8f)))
			{
				SetState(DayrState.Attack);
			}
			else if (attackCooldown <= 0f && enemy.Rigidbody.notMovingTimer > 3f)
			{
				enemy.Rigidbody.notMovingTimer = 0f;
				SetState(DayrState.Attack);
			}
			else if (!flag && FlatDistance(((Component)this).transform.position, lastKnown) < 1.5f)
			{
				SetState(DayrState.Seek);
			}
		}

		private void UpdateAttack()
		{
			if (Entering())
			{
				stateTimer = 1.1f;
				Halt();
			}
			enemy.NavMeshAgent.Stop(0.1f);
			stateTimer -= Time.deltaTime;
			if (stateTimer <= 0f)
			{
				attackCooldown = 0.5f;
				SetState(TargetValid() ? DayrState.Chase : DayrState.Seek);
			}
		}

		private void UpdateSeek()
		{
			//IL_003a: 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_0015: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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 (Entering())
			{
				stateTimer = 10f;
				destination = lastKnown;
				enemy.Rigidbody.notMovingTimer = 0f;
			}
			if (FlatDistance(((Component)this).transform.position, destination) < 1.8f)
			{
				LevelPoint levelPointAhead = enemy.GetLevelPointAhead(destination);
				if ((Object)(object)levelPointAhead != (Object)null)
				{
					destination = ((Component)levelPointAhead).transform.position;
				}
			}
			Move(destination, ChaseSpeed() * 0.6f, 8f);
			JumpWhenStuck(destination);
			stateTimer -= Time.deltaTime;
			if (stateTimer <= 0f || enemy.Rigidbody.notMovingTimer > 3f)
			{
				SetState(DayrState.Roam);
			}
			if (SemiFunc.EnemyForceLeave(enemy))
			{
				SetState(DayrState.Leave);
			}
		}

		private void UpdateStun()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			enemy.NavMeshAgent.Disable(0.1f);
			((Component)this).transform.position = ((Component)enemy.Rigidbody).transform.position;
			if (!enemy.IsStunned())
			{
				SetState(DayrState.Idle);
			}
		}

		private void UpdateLeave()
		{
			//IL_0087: 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_000e: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (stateImpulse)
			{
				LevelPoint val = SemiFunc.LevelPointGetPlayerDistance(((Component)this).transform.position, 30f, 50f, false);
				if ((Object)(object)val == (Object)null)
				{
					val = SemiFunc.LevelPointGetFurthestFromPlayer(((Component)this).transform.position, 5f);
				}
				if (!TryNavPoint(val, out destination))
				{
					return;
				}
				SemiFunc.EnemyLeaveStart(enemy);
				stateImpulse = false;
				stateTimer = 5f;
				enemy.Rigidbody.notMovingTimer = 0f;
			}
			Move(destination, ChaseSpeed() * 0.7f, 8f);
			TickWhenStuck();
			JumpWhenStuck(destination);
			if (stateTimer <= 0f || FlatDistance(((Component)this).transform.position, destination) < 1.2f)
			{
				SetState(DayrState.Idle);
			}
		}

		private void UpdateDespawn()
		{
			if (Entering())
			{
				stateTimer = 0.8f;
				despawnSent = false;
				Halt();
			}
			stateTimer -= Time.deltaTime;
			if (stateTimer <= 0f && !despawnSent)
			{
				despawnSent = true;
				enemy.EnemyParent.Despawn();
			}
		}

		private bool TryNavPoint(LevelPoint point, out Vector3 result)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0031: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			result = ((Component)this).transform.position;
			if ((Object)(object)point == (Object)null)
			{
				return false;
			}
			Vector3 val = ((Component)point).transform.position + Random.insideUnitSphere * 2f;
			NavMeshHit val2 = default(NavMeshHit);
			if (!NavMesh.SamplePosition(val, ref val2, 5f, -1))
			{
				return false;
			}
			if (!Physics.Raycast(((NavMeshHit)(ref val2)).position + Vector3.up * 0.3f, Vector3.down, 5f, LayerMask.GetMask(new string[1] { "Default" })))
			{
				return false;
			}
			result = ((NavMeshHit)(ref val2)).position;
			return true;
		}

		private Vector3 BodyPosition()
		{
			//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_0043: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)enemy.Rigidbody).transform.position;
			position.y = (((Object)(object)visual != (Object)null) ? ((Component)visual).transform.position.y : ((Component)this).transform.position.y);
			return position;
		}

		private static float FlatDistance(Vector3 a, Vector3 b)
		{
			//IL_0018: 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)
			a.y = 0f;
			b.y = 0f;
			return Vector3.Distance(a, b);
		}

		private void Halt()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			enemy.NavMeshAgent.Warp(BodyPosition(), false);
			enemy.NavMeshAgent.ResetPath();
		}

		private void Move(Vector3 to, float speed, float acceleration)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			enemy.NavMeshAgent.OverrideAgent(speed, acceleration, 0.2f);
			enemy.NavMeshAgent.SetDestination(to);
		}

		private void TickWhenStuck()
		{
			if (enemy.Rigidbody.notMovingTimer > 2f)
			{
				stateTimer -= Time.deltaTime;
			}
		}

		private void JumpWhenStuck(Vector3 to)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if (enemy.HasJump && !enemy.Jump.jumping && enemy.Rigidbody.notMovingTimer > 1.8f)
			{
				enemy.Jump.StuckTrigger(to - BodyPosition());
			}
		}

		private float ChaseSpeed()
		{
			if (Plugin.Cfg.ChaseSpeedOverride.Value > 0f)
			{
				return Plugin.Cfg.ChaseSpeedOverride.Value;
			}
			float num = 5f;
			PlayerController instance = PlayerController.instance;
			if ((Object)(object)instance != (Object)null)
			{
				float playerOriginalSprintSpeed = instance.playerOriginalSprintSpeed;
				if (playerOriginalSprintSpeed > 0.5f)
				{
					num = playerOriginalSprintSpeed;
				}
				else if (instance.SprintSpeed > 0.5f)
				{
					num = instance.SprintSpeed;
				}
			}
			return num * Plugin.Cfg.ChaseSpeedMultiplier.Value;
		}

		private bool TargetValid()
		{
			if ((Object)(object)target != (Object)null)
			{
				return !target.isDisabled;
			}
			return false;
		}

		private bool CanSeeTarget()
		{
			if (Time.time < sightTimer)
			{
				return sightCache;
			}
			sightTimer = Time.time + 0.15f;
			sightCache = CanSee(target);
			return sightCache;
		}

		private bool CanSee(PlayerAvatar player)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || (Object)(object)player.PlayerVisionTarget == (Object)null)
			{
				return false;
			}
			Vector3 position = enemy.Vision.VisionTransform.position;
			Vector3 position2 = player.PlayerVisionTarget.VisionTransform.position;
			float num = Vector3.Distance(position, position2);
			if (num > Plugin.Cfg.VisionDistance.Value * 1.25f)
			{
				return false;
			}
			Vector3 val = position2 - position;
			RaycastHit[] array = Physics.RaycastAll(position, ((Vector3)(ref val)).normalized, num, LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()), (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				Transform transform = ((RaycastHit)(ref array[i])).transform;
				if (!transform.IsChildOf(parentRoot) && !((Object)(object)((Component)transform).GetComponentInParent<PlayerAvatar>() != (Object)null) && !((Object)(object)((Component)transform).GetComponentInParent<PlayerController>() != (Object)null) && !((Object)(object)((Component)transform).GetComponentInParent<PlayerTumble>() != (Object)null))
				{
					return false;
				}
			}
			return true;
		}

		private void UpdateRotation()
		{
			//IL_0014: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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)
			if (State == DayrState.Stun || State == DayrState.Despawn)
			{
				return;
			}
			Vector3 val = Vector3.zero;
			float num = 360f;
			if ((State == DayrState.Notice || (State == DayrState.Attack && attackClock < 0.44f)) && TargetValid())
			{
				val = ((Component)target).transform.position - ((Component)enemy.Rigidbody).transform.position;
			}
			else if (State != DayrState.Attack)
			{
				Vector3 agentVelocity = enemy.NavMeshAgent.AgentVelocity;
				if (((Vector3)(ref agentVelocity)).magnitude > 0.15f)
				{
					val = agentVelocity;
				}
				if (State == DayrState.Roam || State == DayrState.Idle)
				{
					num = 180f;
				}
			}
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude > 0.01f)
			{
				facing = Quaternion.LookRotation(val);
			}
			((Component)this).transform.rotation = Quaternion.RotateTowards(((Component)this).transform.rotation, facing, num * Time.deltaTime);
		}

		private void UpdateVoiceSchedule()
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			if ((State == DayrState.Notice || State == DayrState.Chase || State == DayrState.Attack) && !(Time.time < nextVoice))
			{
				float value = Plugin.Cfg.VoiceIntervalMin.Value;
				float num = Mathf.Max(value, Plugin.Cfg.VoiceIntervalMax.Value);
				nextVoice = Time.time + Mathf.Max(Random.Range(value, num), DayrAssets.ChaseVoice.length + 0.5f);
				if (SemiFunc.IsMultiplayer())
				{
					view.RPC("DayrVoiceRPC", (RpcTarget)0, new object[0]);
				}
				else
				{
					DayrVoiceRPC(default(PhotonMessageInfo));
				}
			}
		}

		private void SetState(DayrState next)
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			if (IsHost && next != State)
			{
				if ((Object)(object)enemy.Rigidbody != (Object)null)
				{
					enemy.Rigidbody.notMovingTimer = 0f;
				}
				if (SemiFunc.IsMultiplayer())
				{
					view.RPC("DayrStateRPC", (RpcTarget)0, new object[2]
					{
						(int)next,
						Plugin.Cfg.Damage.Value
					});
				}
				else
				{
					DayrStateRPC((int)next, Plugin.Cfg.Damage.Value, default(PhotonMessageInfo));
				}
			}
		}

		private void SetTarget(PlayerAvatar player)
		{
			//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)
			if (!((Object)(object)player == (Object)null))
			{
				target = player;
				sightTimer = 0f;
				lastSeen = Time.time;
				lastKnown = ((Component)player).transform.position;
				if (SemiFunc.IsMultiplayer())
				{
					view.RPC("DayrTargetRPC", (RpcTarget)1, new object[1] { player.photonView.ViewID });
				}
			}
		}

		private void UpdateHitWindow()
		{
			bool flag = false;
			if (State == DayrState.Attack && !dead)
			{
				attackClock += Time.deltaTime;
				flag = attackClock >= 0.44f && attackClock <= 0.7f;
			}
			if ((Object)(object)hurtCollider != (Object)null && ((Component)hurtCollider).gameObject.activeSelf != flag)
			{
				if (flag)
				{
					hurtCollider.playerDamage = attackDamage;
				}
				((Component)hurtCollider).gameObject.SetActive(flag);
				if (flag && Plugin.Cfg.DebugLog.Value)
				{
					Plugin.Log.LogInfo((object)("DAYR zarba oynasi, zarar " + attackDamage));
				}
			}
		}

		public bool ConsumeAttackImpulse()
		{
			bool result = attackImpulse;
			attackImpulse = false;
			return result;
		}

		private void OnSpawn()
		{
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected I4, but got Unknown
			dead = false;
			attackClock = 0f;
			attackCooldown = 0f;
			target = null;
			nextVoice = 0f;
			State = DayrState.Spawn;
			stateImpulse = true;
			if ((Object)(object)hurtCollider != (Object)null)
			{
				((Component)hurtCollider).gameObject.SetActive(false);
			}
			if (Plugin.Cfg.DebugLog.Value)
			{
				Plugin.Log.LogInfo((object)("DAYR spawn (host=" + IsHost + ")"));
			}
			if (IsHost)
			{
				if (SemiFunc.IsMultiplayer())
				{
					view.RPC("DayrHostRPC", (RpcTarget)1, new object[2]
					{
						"0.1.4",
						(int)enemy.EnemyParent.difficulty
					});
					view.RPC("DayrStateRPC", (RpcTarget)1, new object[2]
					{
						0,
						Plugin.Cfg.Damage.Value
					});
				}
				if (!SemiFunc.EnemySpawn(enemy) && Plugin.Cfg.DebugLog.Value)
				{
					Plugin.Log.LogInfo((object)"DAYR: mos spawn nuqtasi yo'q, keyinroq qayta uriniladi");
				}
			}
		}

		private void OnHurt()
		{
			if ((Object)(object)visual != (Object)null && !dead)
			{
				visual.Flinch();
			}
			if (Plugin.Cfg.DebugLog.Value)
			{
				Plugin.Log.LogInfo((object)("DAYR zarar oldi, HP " + ((Component)this).GetComponent<EnemyHealth>().healthCurrent));
			}
			if (IsHost && !dead && State == DayrState.Leave)
			{
				SetState(DayrState.Idle);
			}
		}

		private void OnDeath()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			if (!dead)
			{
				dead = true;
				Plugin.Log.LogInfo((object)("DAYR o'ldi (host=" + IsHost + ")"));
				if ((Object)(object)hurtCollider != (Object)null)
				{
					((Component)hurtCollider).gameObject.SetActive(false);
				}
				PlayDeathVoice();
				DayrCorpse.Spawn(visual, DayrPrefab.Materials);
				Vector3 position = enemy.CenterTransform.position;
				for (int i = 0; i < deathParticles.Length; i++)
				{
					((Component)deathParticles[i]).transform.position = position;
					deathParticles[i].Play();
				}
				if ((Object)(object)GameDirector.instance != (Object)null)
				{
					GameDirector.instance.CameraShake.ShakeDistance(5f, 3f, 10f, position, 0.5f);
					GameDirector.instance.CameraImpact.ShakeDistance(5f, 3f, 10f, position, 0.05f);
				}
				if (IsHost)
				{
					enemy.EnemyParent.Despawn();
				}
			}
		}

		private void OnVision()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			if (!IsHost || dead || (int)enemy.CurrentState == 11)
			{
				return;
			}
			PlayerAvatar onVisionTriggeredPlayer = enemy.Vision.onVisionTriggeredPlayer;
			if ((Object)(object)onVisionTriggeredPlayer == (Object)null || onVisionTriggeredPlayer.isDisabled)
			{
				return;
			}
			switch (State)
			{
			case DayrState.Idle:
			case DayrState.Roam:
			case DayrState.Investigate:
			case DayrState.Leave:
				SetTarget(onVisionTriggeredPlayer);
				SetState(DayrState.Notice);
				break;
			case DayrState.Seek:
				SetTarget(onVisionTriggeredPlayer);
				SetState(DayrState.Chase);
				break;
			case DayrState.Chase:
				if ((Object)(object)onVisionTriggeredPlayer == (Object)(object)target)
				{
					lastSeen = Time.time;
					lastKnown = ((Component)onVisionTriggeredPlayer).transform.position;
				}
				else if (!TargetValid() || FlatDistance(((Component)this).transform.position, ((Component)onVisionTriggeredPlayer).transform.position) + 2.5f < FlatDistance(((Component)this).transform.position, ((Component)target).transform.position))
				{
					SetTarget(onVisionTriggeredPlayer);
				}
				break;
			case DayrState.Notice:
			case DayrState.Attack:
			case DayrState.Stun:
				break;
			}
		}

		private void OnInvestigate()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007b: 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)
			if (!IsHost || dead)
			{
				return;
			}
			Vector3 onInvestigateTriggeredPosition = ((Component)this).GetComponent<EnemyStateInvestigate>().onInvestigateTriggeredPosition;
			if (State == DayrState.Idle || State == DayrState.Roam || State == DayrState.Investigate)
			{
				destination = onInvestigateTriggeredPosition;
				enemy.Rigidbody.notMovingTimer = 0f;
				if (State == DayrState.Investigate)
				{
					stateTimer = 6f;
				}
				else
				{
					SetState(DayrState.Investigate);
				}
			}
			else if (State == DayrState.Seek)
			{
				destination = onInvestigateTriggeredPosition;
			}
		}

		private void OnGrabbed()
		{
			if (IsHost && !dead && State != DayrState.Leave && State != DayrState.Attack && State != DayrState.Chase && State != DayrState.Stun && State != DayrState.Despawn)
			{
				PlayerAvatar onGrabbedPlayerAvatar = enemy.Rigidbody.onGrabbedPlayerAvatar;
				if (!((Object)(object)onGrabbedPlayerAvatar == (Object)null))
				{
					SetTarget(onGrabbedPlayerAvatar);
					SetState(DayrState.Notice);
				}
			}
		}

		private void PlayDeathVoice()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)voice == (Object)null))
			{
				voice.Stop();
				GameObject val = Object.Instantiate<GameObject>(((Component)voice).gameObject, ((Component)voice).transform.position, Quaternion.identity);
				((Object)val).name = "DAYR Death Voice";
				AudioSource component = val.GetComponent<AudioSource>();
				component.clip = DayrAssets.DeathVoice;
				component.volume = Plugin.Cfg.DeathVoiceVolume.Value;
				component.minDistance = 4f;
				component.maxDistance = Plugin.Cfg.DeathVoiceDistance.Value;
				val.SetActive(true);
				component.Play();
				Object.Destroy((Object)(object)val, DayrAssets.DeathVoice.length + 0.8f);
				Plugin.Log.LogInfo((object)"DAYR o'lim ovozi ijro etildi");
			}
		}

		[PunRPC]
		private void DayrStateRPC(int next, int damage, PhotonMessageInfo info)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(info))
			{
				State = (DayrState)next;
				stateImpulse = true;
				stateTimer = 0f;
				attackDamage = damage;
				if (State == DayrState.Attack)
				{
					attackClock = 0f;
					attackImpulse = true;
				}
				if (Plugin.Cfg != null && Plugin.Cfg.DebugLog.Value)
				{
					Plugin.Log.LogInfo((object)("DAYR holat: " + State));
				}
			}
		}

		[PunRPC]
		private void DayrTargetRPC(int viewId, PhotonMessageInfo info)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (!SemiFunc.MasterOnlyRPC(info))
			{
				return;
			}
			List<PlayerAvatar> list = SemiFunc.PlayerGetList();
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].photonView.ViewID == viewId)
				{
					target = list[i];
					break;
				}
			}
		}

		[PunRPC]
		private void DayrVoiceRPC(PhotonMessageInfo info)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(info) && !((Object)(object)voice == (Object)null) && !dead && ((Behaviour)voice).isActiveAndEnabled && !voice.isPlaying)
			{
				voice.clip = DayrAssets.ChaseVoice;
				voice.Play();
				if (Plugin.Cfg.DebugLog.Value)
				{
					Plugin.Log.LogInfo((object)"DAYR quvish ovozi");
				}
			}
		}

		[PunRPC]
		private void DayrHostRPC(string hostVersion, int difficulty, PhotonMessageInfo info)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(info))
			{
				if (hostVersion != "0.1.4")
				{
					Plugin.Log.LogWarning((object)("DAYR versiyasi mos emas! Host: " + hostVersion + ", sizda: 0.1.4"));
				}
				EnemyParent componentInParent = ((Component)this).GetComponentInParent<EnemyParent>();
				if ((Object)(object)componentInParent != (Object)null)
				{
					componentInParent.difficulty = (Difficulty)Mathf.Clamp(difficulty, 0, 2);
				}
			}
		}

		public override void OnPlayerEnteredRoom(Player newPlayer)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected I4, but got Unknown
			if (IsHost && !((Object)(object)view == (Object)null) && !((Object)(object)enemy == (Object)null))
			{
				view.RPC("DayrHostRPC", newPlayer, new object[2]
				{
					"0.1.4",
					(int)enemy.EnemyParent.difficulty
				});
				view.RPC("DayrStateRPC", newPlayer, new object[2]
				{
					(int)State,
					Plugin.Cfg.Damage.Value
				});
			}
		}
	}
	[HarmonyPatch]
	internal static class RegisterPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(RunManager), "Awake")]
		private static void AfterRunManagerAwake()
		{
			try
			{
				DayrPrefab.Register();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("DAYR ro'yxatdan o'tmadi: " + ex));
			}
		}
	}
	[HarmonyPatch]
	internal static class RewardDespawnPatch
	{
		internal static bool DayrDespawning;

		[HarmonyPatch(typeof(EnemyParent), "Despawn")]
		[HarmonyPrefix]
		private static void Before(EnemyParent __instance)
		{
			DayrDespawning = (Object)(object)((Component)__instance).GetComponentInChildren<EnemyDayr>(true) != (Object)null;
		}

		[HarmonyFinalizer]
		[HarmonyPatch(typeof(EnemyParent), "Despawn")]
		private static void After()
		{
			DayrDespawning = false;
		}
	}
	[HarmonyPatch]
	internal static class RewardValuablePatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(ValuableObject), "Awake")]
		private static void AfterAwake(ValuableObject __instance)
		{
			if (RewardDespawnPatch.DayrDespawning && Plugin.Cfg.RewardValue.Value > 0 && !((Object)(object)((Component)__instance).GetComponent<EnemyValuable>() == (Object)null))
			{
				__instance.dollarValueOverride = Plugin.Cfg.RewardValue.Value;
				Plugin.Log.LogInfo((object)("DAYR mukofoti: $" + Plugin.Cfg.RewardValue.Value));
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("dayr.enemy", "DAYR", "0.1.4")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "dayr.enemy";

		public const string Version = "0.1.4";

		internal static ManualLogSource Log;

		internal static Settings Cfg;

		private void Awake()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Cfg = new Settings(((BaseUnityPlugin)this).Config);
			try
			{
				DayrAssets.Load();
				Harmony val = new Harmony("dayr.enemy");
				val.PatchAll(typeof(RegisterPatch));
				val.PatchAll(typeof(RewardDespawnPatch));
				val.PatchAll(typeof(RewardValuablePatch));
				val.PatchAll(typeof(SpawnChatPatch));
				Log.LogInfo((object)"DAYR 0.1.4 yuklandi.");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("DAYR yuklanmadi: " + ex));
			}
		}
	}
	internal class Settings
	{
		public readonly ConfigEntry<int> Health;

		public readonly ConfigEntry<int> Damage;

		public readonly ConfigEntry<int> RewardValue;

		public readonly ConfigEntry<int> Difficulty;

		public readonly ConfigEntry<float> SpawnWeight;

		public readonly ConfigEntry<float> WalkSpeed;

		public readonly ConfigEntry<float> ChaseSpeedMultiplier;

		public readonly ConfigEntry<float> ChaseSpeedOverride;

		public readonly ConfigEntry<float> VisionDistance;

		public readonly ConfigEntry<float> AttackRange;

		public readonly ConfigEntry<float> ChaseMemory;

		public readonly ConfigEntry<float> VoiceIntervalMin;

		public readonly ConfigEntry<float> VoiceIntervalMax;

		public readonly ConfigEntry<float> ChaseVoiceVolume;

		public readonly ConfigEntry<float> DeathVoiceVolume;

		public readonly ConfigEntry<float> ChaseVoiceDistance;

		public readonly ConfigEntry<float> DeathVoiceDistance;

		public readonly ConfigEntry<bool> DebugLog;

		public Settings(ConfigFile c)
		{
			Health = c.Bind<int>("Gameplay", "Health", 350, Range(1, 5000, "DAYR HP (host)."));
			Damage = c.Bind<int>("Gameplay", "Damage", 40, Range(0, 500, "Bir zarba zarari (host)."));
			RewardValue = c.Bind<int>("Gameplay", "RewardValue", 8000, Range(0, 100000, "O'lganda tushadigan enemy orb qiymati, $. 0 = o'yinning odatiy qiymati (host)."));
			Difficulty = c.Bind<int>("Spawn", "Difficulty", 1, Range(1, 3, "Qaysi qiyinlik ro'yxatiga qo'shiladi (1-3). 1 = 1-leveldan chiqishi mumkin (host)."));
			SpawnWeight = c.Bind<float>("Spawn", "SpawnWeight", 100f, Range(0f, 100f, "Tabiiy spawn og'irligi, foiz EMAS. 100 = oddiy dushman bilan teng; pastroq qiymat spawnni keskin kamaytiradi. 0 = faqat buyruq bilan (host)."));
			WalkSpeed = c.Bind<float>("AI", "WalkSpeed", 1.6f, Range(0.5f, 4f, "Patrol tezligi, m/s."));
			ChaseSpeedMultiplier = c.Bind<float>("AI", "ChaseSpeedMultiplier", 1.08f, Range(0.5f, 2f, "Quvish tezligi = o'yinchi sprint tezligi x shu son."));
			ChaseSpeedOverride = c.Bind<float>("AI", "ChaseSpeedOverride", 0f, Range(0f, 15f, "0 dan katta bo'lsa quvish tezligi aniq shu qiymat (m/s)."));
			VisionDistance = c.Bind<float>("AI", "VisionDistance", 14f, Range(4f, 30f, "Ko'rish masofasi, m."));
			AttackRange = c.Bind<float>("AI", "AttackRange", 2.1f, Range(1f, 3.5f, "Zarba boshlash masofasi, m."));
			ChaseMemory = c.Bind<float>("AI", "ChaseMemory", 5f, Range(1f, 20f, "Ko'rmay qolgandan keyin quvish davom etadigan vaqt, s."));
			VoiceIntervalMin = c.Bind<float>("Audio", "VoiceIntervalMin", 5f, Range(2f, 60f, "Quvish ovozi oralig'i (min), s."));
			VoiceIntervalMax = c.Bind<float>("Audio", "VoiceIntervalMax", 10f, Range(2f, 60f, "Quvish ovozi oralig'i (max), s."));
			ChaseVoiceVolume = c.Bind<float>("Audio", "ChaseVoiceVolume", 0.8f, Range(0f, 1f, "Quvish ovozi balandligi (lokal)."));
			DeathVoiceVolume = c.Bind<float>("Audio", "DeathVoiceVolume", 1f, Range(0f, 1f, "O'lim ovozi balandligi (lokal)."));
			ChaseVoiceDistance = c.Bind<float>("Audio", "ChaseVoiceDistance", 32f, Range(5f, 100f, "Quvish ovozi eshitiladigan masofa."));
			DeathVoiceDistance = c.Bind<float>("Audio", "DeathVoiceDistance", 55f, Range(5f, 150f, "O'lim ovozi eshitiladigan masofa."));
			DebugLog = c.Bind<bool>("Debug", "DebugLog", false, "AI holat va ovoz hodisalarini logga yozish.");
		}

		private static ConfigDescription Range(int a, int b, string text)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			return new ConfigDescription(text, (AcceptableValueBase)(object)new AcceptableValueRange<int>(a, b), new object[0]);
		}

		private static ConfigDescription Range(float a, float b, string text)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			return new ConfigDescription(text, (AcceptableValueBase)(object)new AcceptableValueRange<float>(a, b), new object[0]);
		}
	}
	[HarmonyPatch]
	internal static class SpawnChatPatch
	{
		private const string Command = "spawn enemy dayr";

		internal static bool IsDayrSpawnCommand(string message)
		{
			if (string.IsNullOrEmpty(message))
			{
				return false;
			}
			string text = message.Replace("\u200b", "").Replace("\u200d", "").Trim()
				.TrimStart('/');
			string[] value = text.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
			return string.Equals(string.Join(" ", value), "spawn enemy dayr", StringComparison.OrdinalIgnoreCase);
		}

		[HarmonyPatch(typeof(PlayerAvatar), "ChatMessageSend")]
		[HarmonyPriority(800)]
		[HarmonyPrefix]
		private static bool BeforeChat(PlayerAvatar __instance, string _message, string localeCode)
		{
			if (!string.IsNullOrEmpty(localeCode) || !IsDayrSpawnCommand(_message))
			{
				return true;
			}
			if (SemiFunc.IsMultiplayer() && !__instance.photonView.IsMine)
			{
				return true;
			}
			try
			{
				Run();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("DAYR spawn buyrug'i: " + ex));
			}
			return false;
		}

		private static void Run()
		{
			DebugCommandHandler instance = DebugCommandHandler.instance;
			if ((Object)(object)instance == (Object)null)
			{
				Plugin.Log.LogWarning((object)"DAYR: buyruq tizimi hali tayyor emas.");
			}
			else if (!SemiFunc.DebugTester())
			{
				Plugin.Log.LogWarning((object)"DAYR: spawn uchun REPOLib.cfg da DeveloperMode = true bo'lishi kerak. Xabar yuborilmadi.");
				instance.CommandFailedEffect();
			}
			else if (!SemiFunc.IsMasterClientOrSingleplayer())
			{
				Plugin.Log.LogWarning((object)"DAYR: spawn buyrug'ini faqat host bajara oladi. Xabar yuborilmadi.");
				instance.CommandFailedEffect();
			}
			else if (!instance.Execute("spawn enemy dayr", true))
			{
				Plugin.Log.LogWarning((object)"DAYR: spawn faqat level ichida ishlaydi. Xabar yuborilmadi.");
				instance.CommandFailedEffect();
			}
		}
	}
}