Decompiled source of Jeongmonster v1.0.0

Jeongmonster.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;
using UnityEngine.Networking;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Jeongmonster")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+530c1a1c8c799b3bbd4f8489b0ca3940461f56ec")]
[assembly: AssemblyProduct("Jeongmonster")]
[assembly: AssemblyTitle("Jeongmonster")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Jeongmonster
{
	internal static class AudioLoader
	{
		private static readonly string[] Extensions = new string[3] { ".ogg", ".wav", ".mp3" };

		public static AudioClip LoadFirst(string dir, string baseName)
		{
			if (string.IsNullOrEmpty(dir) || !Directory.Exists(dir))
			{
				return null;
			}
			string[] files;
			try
			{
				files = Directory.GetFiles(dir, "*", SearchOption.AllDirectories);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not search " + dir + " for sounds: " + ex.Message));
				return null;
			}
			string[] extensions = Extensions;
			foreach (string ext in extensions)
			{
				string text = files.FirstOrDefault((string f) => string.Equals(Path.GetFileNameWithoutExtension(f), baseName, StringComparison.OrdinalIgnoreCase) && string.Equals(Path.GetExtension(f), ext, StringComparison.OrdinalIgnoreCase));
				if (text == null)
				{
					continue;
				}
				try
				{
					AudioClip val = ((ext == ".wav") ? LoadWav(File.ReadAllBytes(text), Path.GetFileNameWithoutExtension(text)) : LoadWithUnity(text, (AudioType)((ext == ".mp3") ? 13 : 14)));
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
				catch (Exception arg)
				{
					Plugin.Log.LogError((object)$"Failed to load sound {text}: {arg}");
				}
			}
			return null;
		}

		private static AudioClip LoadWithUnity(string path, AudioType type)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Invalid comparison between Unknown and I4
			UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(new Uri(Path.GetFullPath(path)).AbsoluteUri, type);
			try
			{
				DownloadHandlerAudioClip val = (DownloadHandlerAudioClip)audioClip.downloadHandler;
				val.streamAudio = false;
				val.compressed = false;
				audioClip.SendWebRequest();
				Stopwatch stopwatch = Stopwatch.StartNew();
				while (!audioClip.isDone)
				{
					if (stopwatch.ElapsedMilliseconds > 15000)
					{
						Plugin.Log.LogError((object)("Timed out loading " + path));
						return null;
					}
					Thread.Sleep(1);
				}
				if ((int)audioClip.result != 1)
				{
					Plugin.Log.LogError((object)("Failed to load " + path + ": " + audioClip.error));
					return null;
				}
				AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
				if ((Object)(object)content == (Object)null || content.length <= 0f)
				{
					return null;
				}
				((Object)content).name = Path.GetFileNameWithoutExtension(path);
				return content;
			}
			finally
			{
				((IDisposable)audioClip)?.Dispose();
			}
		}

		public static AudioClip LoadWav(byte[] d, string name)
		{
			if (d.Length < 44 || Encoding.ASCII.GetString(d, 0, 4) != "RIFF" || Encoding.ASCII.GetString(d, 8, 4) != "WAVE")
			{
				throw new InvalidDataException("not a RIFF/WAVE file");
			}
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			int num5 = -1;
			int num6 = 0;
			int num7 = 12;
			while (num7 + 8 <= d.Length)
			{
				string text = Encoding.ASCII.GetString(d, num7, 4);
				int num8 = BitConverter.ToInt32(d, num7 + 4);
				int num9 = num7 + 8;
				if (text == "fmt ")
				{
					num = BitConverter.ToUInt16(d, num9);
					num2 = BitConverter.ToUInt16(d, num9 + 2);
					num3 = BitConverter.ToInt32(d, num9 + 4);
					num4 = BitConverter.ToUInt16(d, num9 + 14);
					if (num == 65534 && num8 >= 26)
					{
						num = BitConverter.ToUInt16(d, num9 + 24);
					}
				}
				else if (text == "data")
				{
					num5 = num9;
					num6 = Math.Min(num8, d.Length - num9);
					break;
				}
				num7 = num9 + num8 + (num8 & 1);
			}
			if (num5 < 0 || num2 <= 0 || num3 <= 0)
			{
				throw new InvalidDataException("missing fmt/data chunk");
			}
			if (num != 1 && num != 3)
			{
				throw new InvalidDataException($"unsupported WAV format {num} (use PCM, or convert to .ogg)");
			}
			int num10 = num4 / 8;
			int num11 = num6 / num10;
			float[] array = new float[num11];
			for (int i = 0; i < num11; i++)
			{
				int num12 = num5 + i * num10;
				switch (num4)
				{
				case 8:
					array[i] = (float)(d[num12] - 128) / 128f;
					break;
				case 16:
					array[i] = (float)BitConverter.ToInt16(d, num12) / 32768f;
					break;
				case 24:
					array[i] = (float)(d[num12] | (d[num12 + 1] << 8) | ((sbyte)d[num12 + 2] << 16)) / 8388608f;
					break;
				case 32:
					array[i] = ((num == 3) ? BitConverter.ToSingle(d, num12) : ((float)BitConverter.ToInt32(d, num12) / 2.1474836E+09f));
					break;
				default:
					throw new InvalidDataException($"unsupported bit depth {num4}");
				}
			}
			AudioClip obj = AudioClip.Create(name, num11 / num2, num2, num3, false);
			obj.SetData(array, 0);
			return obj;
		}

		public static List<AudioClip> SplitBySilence(AudioClip clip, float minLength = 0.35f)
		{
			List<AudioClip> list = new List<AudioClip>();
			if ((Object)(object)clip == (Object)null)
			{
				return list;
			}
			int channels = clip.channels;
			int frequency = clip.frequency;
			int samples = clip.samples;
			float[] array = new float[samples * channels];
			if (!clip.GetData(array, 0))
			{
				return list;
			}
			int num = Mathf.Max(1, frequency / 20);
			int num2 = samples / num;
			float[] array2 = new float[num2];
			float num3 = 0f;
			for (int i = 0; i < num2; i++)
			{
				double num4 = 0.0;
				for (int j = i * num; j < (i + 1) * num; j++)
				{
					for (int k = 0; k < channels; k++)
					{
						float num5 = array[j * channels + k];
						num4 += (double)(num5 * num5);
					}
				}
				array2[i] = (float)Math.Sqrt(num4 / (double)(num * channels));
				num3 = Mathf.Max(num3, array2[i]);
			}
			float num6 = num3 * 0.12f;
			int num7 = -1;
			for (int l = 0; l <= num2; l++)
			{
				int num8;
				if (l < num2)
				{
					num8 = ((array2[l] > num6) ? 1 : 0);
					if (num8 != 0 && num7 < 0)
					{
						num7 = l;
					}
				}
				else
				{
					num8 = 0;
				}
				if (num8 != 0 || num7 < 0)
				{
					continue;
				}
				if ((float)((l - num7) * num) >= minLength * (float)frequency)
				{
					int num9 = Mathf.Max(0, num7 - 1) * num;
					int num10 = Mathf.Min(num2, l + 1) * num;
					float[] array3 = new float[(num10 - num9) * channels];
					Array.Copy(array, num9 * channels, array3, 0, array3.Length);
					int num11 = Mathf.Min(array3.Length / channels, frequency / 50);
					for (int m = 0; m < num11; m++)
					{
						for (int n = 0; n < channels; n++)
						{
							float num12 = (float)m / (float)num11;
							array3[m * channels + n] *= num12;
							array3[array3.Length - (m + 1) * channels + n] *= num12;
						}
					}
					AudioClip val = AudioClip.Create($"{((Object)clip).name}_{list.Count}", num10 - num9, channels, frequency, false);
					val.SetData(array3, 0);
					list.Add(val);
				}
				num7 = -1;
			}
			return list;
		}

		public static AudioClip CreateCrunch(int seed)
		{
			int num = 14112;
			Random random = new Random(seed);
			float[] array = new float[num];
			float num2 = 0f;
			for (int i = 0; i < num; i++)
			{
				float num3 = (float)i / 44100f;
				float num4 = Mathf.Exp((0f - num3) * 11f);
				float num5 = (float)(random.NextDouble() * 2.0 - 1.0);
				num2 += (num5 - num2) * 0.35f;
				float num6 = ((random.NextDouble() < 0.012) ? ((float)(random.NextDouble() * 2.0 - 1.0) * 0.9f) : 0f);
				float num7 = Mathf.Sin(MathF.PI * 140f * num3) * Mathf.Exp((0f - num3) * 25f);
				array[i] = Mathf.Clamp((num2 * 0.8f + num6) * num4 + num7 * 0.6f, -1f, 1f);
			}
			AudioClip obj = AudioClip.Create("JeongmonsterCrunch" + seed, num, 1, 44100, false);
			obj.SetData(array, 0);
			return obj;
		}

		public static AudioClip CreateSilence()
		{
			AudioClip obj = AudioClip.Create("JeongmonsterSilence", 256, 1, 44100, false);
			obj.SetData(new float[256], 0);
			return obj;
		}
	}
	public class JeongmonsterAI : EnemyAI
	{
		private Transform _modelRoot;

		private Transform _hips;

		private Transform _spine;

		private Transform _chest;

		private Transform _neck;

		private Transform _head;

		private Transform _jaw;

		private Transform _clavL;

		private Transform _clavR;

		private Transform _upArmL;

		private Transform _upArmR;

		private Transform _loArmL;

		private Transform _loArmR;

		private Transform _handL;

		private Transform _handR;

		private Transform _upLegL;

		private Transform _upLegR;

		private Transform _loLegL;

		private Transform _loLegR;

		private Transform _footL;

		private Transform _footR;

		private Transform _itemHold;

		private Transform _carryPoint;

		private Vector3 _hipsBasePos;

		private readonly Dictionary<Transform, Vector3> _pose = new Dictionary<Transform, Vector3>();

		private Vector3 _lastPos;

		private float _speed;

		private float _phase;

		private float _flinch;

		private float _deathTime;

		private float _twitchUntil;

		private float _nextTwitch;

		private Vector3 _twitch;

		private PlayerControllerB _visualTarget;

		private float _nextVisualTargetPick;

		internal const int Roaming = 0;

		internal const int Staring = 1;

		internal const int Stalking = 2;

		internal const int Rushing = 3;

		internal const int EatingScrap = 4;

		internal const int Carrying = 5;

		internal const int Fed = 6;

		internal const float CarryGrab = 0.45f;

		internal const float CarryGiggle = 1.1f;

		internal const float CarryScream = 3f;

		internal const float CarryBite1 = 4.35f;

		internal const float CarryBiteGap = 0.45f;

		internal const float CarryKill = 5.7f;

		internal const float CarryEnd = 7.2f;

		internal static readonly Vector3 CarryHeadStare = new Vector3(-0.3f, 0.98f, 0.34f);

		internal static readonly Vector3 CarryHeadBite = new Vector3(-0.13f, 1.07f, 0.27f);

		private AISearchRoutine _roam;

		private float _stateTime;

		private float _lostSight;

		private float _satisfiedUntil;

		private float _serverEatEnd;

		private float _serverCarryStart;

		private PlayerControllerB _carryTargetServer;

		private GrabbableObject _serverEatItem;

		private int _lastState = -1;

		private float _nextContact;

		private float _nextAmbientVoice;

		private float _nextRushScream;

		private float _voiceBusyUntil;

		internal PlayerControllerB carriedPlayer;

		private bool _carryActive;

		private float _carryStart;

		private bool _carryKilled;

		private bool _carryScreamed;

		private bool _carryGiggled;

		private int _carryBites;

		private float _victimEye = 2f;

		private Vector3 _victimStartPos;

		private Quaternion _victimStartRot;

		private Quaternion _camStartRot;

		private bool _camHooked;

		private GrabbableObject _eatItem;

		private PlayerControllerB _eatVictim;

		private float _eatStart;

		private Vector3 _eatItemScale;

		private float _nextCrunch;

		private ScanNodeProperties _scanNode;

		private float Scale => Mathf.Max(0.1f, Cfg.ModelScale.Value);

		private JeongmonsterConfig Cfg => Plugin.Cfg;

		private void StealScrapFrom(PlayerControllerB player)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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)
			GrabbableObject currentlyHeldObjectServer = player.currentlyHeldObjectServer;
			Vector3 val = ((Component)player).transform.position - ((Component)this).transform.position;
			val.y = 0f;
			val = ((((Vector3)(ref val)).sqrMagnitude > 0.001f) ? ((Vector3)(ref val)).normalized : (-((Component)player).transform.forward));
			player.DamagePlayer(Cfg.ScrapDamage.Value, true, true, (CauseOfDeath)6, 0, false, val * 6f + Vector3.up * 2f);
			HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
			player.JumpToFearLevel(0.8f, true);
			if (!player.isPlayerDead && (Object)(object)player.currentlyHeldObjectServer == (Object)(object)currentlyHeldObjectServer)
			{
				player.DiscardHeldObject(false, (NetworkObject)null, default(Vector3), true);
			}
			if (!player.isPlayerDead)
			{
				((MonoBehaviour)this).StartCoroutine(Knockback(player, val));
			}
			if ((Object)(object)currentlyHeldObjectServer != (Object)null && (Object)(object)((NetworkBehaviour)currentlyHeldObjectServer).NetworkObject != (Object)null)
			{
				JeongmonsterNet.SendToServer(JeongmonsterNet.Op.TakeScrap, this, PlayerIndex(player), ((NetworkBehaviour)currentlyHeldObjectServer).NetworkObjectId);
			}
		}

		private IEnumerator Knockback(PlayerControllerB player, Vector3 dir)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			float speed = Cfg.Knockback.Value;
			float t = 0f;
			while (t < 0.35f && (Object)(object)player != (Object)null && !player.isPlayerDead && (Object)(object)player.thisController != (Object)null && ((Collider)player.thisController).enabled)
			{
				float num = 1f - t / 0.35f;
				player.thisController.Move((dir * speed * num + Vector3.up * 2.5f * num) * Time.deltaTime);
				t += Time.deltaTime;
				yield return null;
			}
		}

		internal void ServerTryBeginEatScrap(PlayerControllerB player, GrabbableObject item)
		{
			if (!base.isEnemyDead && !((Object)(object)item == (Object)null) && !((Object)(object)((NetworkBehaviour)item).NetworkObject == (Object)null) && ((NetworkBehaviour)item).NetworkObject.IsSpawned)
			{
				int currentBehaviourStateIndex = base.currentBehaviourStateIndex;
				if (currentBehaviourStateIndex != 4 && currentBehaviourStateIndex != 5 && currentBehaviourStateIndex != 6 && !_carryActive && !item.isHeldByEnemy && (!item.isHeld || !((Object)(object)item.playerHeldBy != (Object)null) || !((Object)(object)item.playerHeldBy != (Object)(object)player)))
				{
					((EnemyAI)this).StopSearch(_roam, true);
					StopMoving();
					base.targetPlayer = player;
					_serverEatItem = item;
					_serverEatEnd = Time.time + Mathf.Max(1.5f, Cfg.EatScrapTime.Value);
					GoState(4);
					JeongmonsterNet.Broadcast(JeongmonsterNet.Op.BeginEatScrap, this, PlayerIndex(player), ((NetworkBehaviour)item).NetworkObjectId);
				}
			}
		}

		internal void ServerTryBeginCarry(PlayerControllerB player)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			if (base.isEnemyDead || base.stunNormalizedTimer > 0f || (Object)(object)player == (Object)null)
			{
				return;
			}
			int currentBehaviourStateIndex = base.currentBehaviourStateIndex;
			if (currentBehaviourStateIndex == 4 || currentBehaviourStateIndex == 5 || _carryActive || currentBehaviourStateIndex == 6 || player.isPlayerDead || !player.isPlayerControlled || (Object)(object)player.inAnimationWithEnemy != (Object)null || HasScrap(player))
			{
				return;
			}
			float num = Mathf.Max(0.1f, Cfg.ModelScale.Value);
			if (!(Vector3.Distance(((Component)player).transform.position, ((Component)this).transform.position) > 3.5f * num + 1f))
			{
				((EnemyAI)this).StopSearch(_roam, true);
				StopMoving();
				base.targetPlayer = player;
				_carryTargetServer = player;
				_serverCarryStart = Time.time;
				Vector3 val = ((Component)player).transform.position - ((Component)this).transform.position;
				val.y = 0f;
				if (((Vector3)(ref val)).sqrMagnitude > 0.01f)
				{
					((Component)this).transform.rotation = Quaternion.LookRotation(val);
				}
				GoState(5);
				JeongmonsterNet.Broadcast(JeongmonsterNet.Op.BeginCarry, this, PlayerIndex(player), 0uL);
			}
		}

		private void ServerUpdateBusyStates(float now)
		{
			if (!((NetworkBehaviour)this).IsServer)
			{
				return;
			}
			int currentBehaviourStateIndex = base.currentBehaviourStateIndex;
			if (currentBehaviourStateIndex == 4 && now >= _serverEatEnd)
			{
				if ((Object)(object)_serverEatItem != (Object)null && (Object)(object)((NetworkBehaviour)_serverEatItem).NetworkObject != (Object)null && ((NetworkBehaviour)_serverEatItem).NetworkObject.IsSpawned)
				{
					((NetworkBehaviour)_serverEatItem).NetworkObject.Despawn(true);
				}
				_serverEatItem = null;
				BackToRoaming(fed: true);
			}
			else if (currentBehaviourStateIndex == 5)
			{
				float num = now - _serverCarryStart;
				bool flag = (Object)(object)_carryTargetServer == (Object)null || _carryTargetServer.isPlayerDead || !_carryTargetServer.isPlayerControlled;
				if ((flag && num >= 5.7f) || num >= 9.7f)
				{
					_carryTargetServer = null;
					BackToRoaming(fed: true);
				}
				else if (flag && num < 5.7f)
				{
					_carryTargetServer = null;
					JeongmonsterNet.Broadcast(JeongmonsterNet.Op.CancelCarry, this, -1, 0uL);
					BackToRoaming();
				}
				else if (base.stunNormalizedTimer > 0f && num < 5.7f)
				{
					_carryTargetServer = null;
					JeongmonsterNet.Broadcast(JeongmonsterNet.Op.CancelCarry, this, -1, 0uL);
					BackToRoaming();
				}
			}
		}

		internal void BeginEatScrapLocal(PlayerControllerB victim, GrabbableObject item)
		{
			//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)
			if (!((Object)(object)item == (Object)null))
			{
				EndEatLocal(dropItem: true);
				_eatItem = item;
				_eatVictim = victim;
				_eatStart = Time.time;
				_eatItemScale = ((Component)item).transform.localScale;
				_nextCrunch = Time.time + 0.9f;
				item.parentObject = _itemHold;
				item.isHeldByEnemy = true;
				item.grabbable = false;
				item.grabbableToEnemies = false;
				item.hasHitGround = false;
				item.EnablePhysics(false);
				try
				{
					item.GrabItemFromEnemy((EnemyAI)(object)this);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogDebug((object)("GrabItemFromEnemy: " + ex.Message));
				}
				PlayVoice(JeongmonsterAssets.RandomVoice(), 0.8f, 1.15f, interrupt: true);
			}
		}

		private void UpdateEatLocal(float now)
		{
			//IL_0054: 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)
			if (!((Object)(object)_eatItem == (Object)null))
			{
				float num = Mathf.Max(1.5f, Cfg.EatScrapTime.Value);
				float num2 = now - _eatStart;
				float num3 = Mathf.Clamp01((num2 - 0.8f) / (num - 1.2f));
				((Component)_eatItem).transform.localScale = _eatItemScale * Mathf.Lerp(1f, 0.08f, num3);
				if (num2 > 0.8f && num2 < num - 0.25f && now >= _nextCrunch)
				{
					PlaySfx(JeongmonsterAssets.RandomCrunch(), 0.9f);
					_nextCrunch = now + Random.Range(0.32f, 0.55f);
				}
				if (num2 > num + 1.5f)
				{
					EndEatLocal(dropItem: false);
				}
			}
		}

		private void EndEatLocal(bool dropItem)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			GrabbableObject eatItem = _eatItem;
			_eatItem = null;
			_eatVictim = null;
			if ((Object)(object)eatItem == (Object)null)
			{
				return;
			}
			if (dropItem)
			{
				((Component)eatItem).transform.localScale = _eatItemScale;
				eatItem.parentObject = null;
				eatItem.isHeldByEnemy = false;
				eatItem.grabbable = true;
				eatItem.grabbableToEnemies = true;
				eatItem.EnablePhysics(true);
				try
				{
					eatItem.DiscardItemFromEnemy();
					eatItem.FallToGround(false, false, default(Vector3));
					return;
				}
				catch (Exception ex)
				{
					Plugin.Log.LogDebug((object)("Drop eaten item: " + ex.Message));
					return;
				}
			}
			try
			{
				eatItem.EnableItemMeshes(false);
			}
			catch
			{
			}
		}

		internal void BeginCarryLocal(PlayerControllerB player)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)player == (Object)null) && !player.isPlayerDead)
			{
				ReleaseCarriedPlayer(cancelled: true);
				carriedPlayer = player;
				_carryActive = true;
				_carryStart = Time.time;
				_carryKilled = (_carryScreamed = (_carryGiggled = false));
				_carryBites = 0;
				base.inSpecialAnimationWithPlayer = player;
				player.inAnimationWithEnemy = (EnemyAI)(object)this;
				player.inSpecialInteractAnimation = true;
				_victimStartPos = ((Component)player).transform.position;
				_victimStartRot = ((Component)player).transform.rotation;
				float num = (((Object)(object)player.gameplayCamera != (Object)null) ? (((Component)player.gameplayCamera).transform.position.y - ((Component)player).transform.position.y) : 2f);
				_victimEye = Mathf.Clamp(num, 1f, 3.2f);
				if (IsLocal(player))
				{
					player.disableLookInput = true;
					_camStartRot = ((Component)player.gameplayCamera).transform.rotation;
					HookCamera();
					HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
					player.JumpToFearLevel(1f, true);
				}
			}
		}

		private void UpdateCarryLocal(float now)
		{
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			if (!_carryActive)
			{
				return;
			}
			float num = now - _carryStart;
			PlayerControllerB val = carriedPlayer;
			if ((Object)(object)val != (Object)null && !_carryKilled && (base.stunNormalizedTimer > 0f || base.isEnemyDead))
			{
				ReleaseCarriedPlayer(cancelled: true);
				return;
			}
			if (!_carryGiggled && num >= 1.1f)
			{
				_carryGiggled = true;
				PlayVoice(JeongmonsterAssets.RandomVoice(), 0.55f, 0.78f, interrupt: true);
			}
			if (!_carryScreamed && num >= 3f)
			{
				_carryScreamed = true;
				PlayVoice(JeongmonsterAssets.LoudestVoice, 1f, 1f, interrupt: true);
				if (IsLocal(val))
				{
					HUDManager.Instance.ShakeCamera((ScreenShakeType)3);
					val.JumpToFearLevel(1f, true);
				}
			}
			if (_carryBites < 3 && num >= 4.35f + (float)_carryBites * 0.45f)
			{
				_carryBites++;
				PlaySfx(JeongmonsterAssets.RandomCrunch());
				if (IsLocal(val))
				{
					HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
				}
			}
			if (!_carryKilled && num >= 5.7f)
			{
				_carryKilled = true;
				if ((Object)(object)val != (Object)null && IsLocal(val) && !val.isPlayerDead)
				{
					val.inSpecialInteractAnimation = false;
					if ((Object)(object)val.inAnimationWithEnemy == (Object)(object)this)
					{
						val.inAnimationWithEnemy = null;
					}
					val.KillPlayer(Vector3.zero, false, (CauseOfDeath)6, 0, default(Vector3), false);
				}
			}
			if (_carryKilled && (Object)(object)val != (Object)null && (val.isPlayerDead || num > 7.2f))
			{
				ReleaseCarriedPlayer(cancelled: false);
			}
			if (num >= 7.2f && (Object)(object)carriedPlayer == (Object)null)
			{
				_carryActive = false;
			}
		}

		internal void ReleaseCarriedPlayer(bool cancelled)
		{
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			if (cancelled)
			{
				_carryActive = false;
			}
			PlayerControllerB val = carriedPlayer;
			if ((Object)(object)val == (Object)null)
			{
				if (cancelled)
				{
					UnhookCamera();
				}
				return;
			}
			carriedPlayer = null;
			if ((Object)(object)base.inSpecialAnimationWithPlayer == (Object)(object)val)
			{
				base.inSpecialAnimationWithPlayer = null;
			}
			if ((Object)(object)val.inAnimationWithEnemy == (Object)(object)this)
			{
				val.inAnimationWithEnemy = null;
			}
			val.inSpecialInteractAnimation = false;
			if (IsLocal(val))
			{
				val.disableLookInput = false;
				UnhookCamera();
				if (!val.isPlayerDead && !_carryKilled)
				{
					Vector3 val2 = ((Component)this).transform.position + ((Component)this).transform.forward * 1f * Mathf.Max(0.1f, Cfg.ModelScale.Value);
					((Component)val).transform.rotation = Quaternion.Euler(0f, ((Component)this).transform.eulerAngles.y + 180f, 0f);
					val.TeleportPlayer(val2 + Vector3.up * 0.1f, false, 0f, false, true);
					val.ResetFallGravity();
					val.cameraUp = 0f;
					((Component)val.gameplayCamera).transform.localEulerAngles = Vector3.zero;
				}
			}
			else if (!val.isPlayerDead)
			{
				((Component)val).transform.rotation = Quaternion.Euler(0f, ((Component)val).transform.eulerAngles.y, 0f);
			}
		}

		private void PoseCarriedPlayer()
		{
			//IL_005a: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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_00a1: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB obj = carriedPlayer;
			float num = Time.time - _carryStart;
			float num2 = Mathf.Clamp01(num / 0.45f);
			num2 = num2 * num2 * (3f - 2f * num2);
			float num3 = ((num >= 4f) ? Mathf.Clamp01((num - 4f) / 0.35f) : 0f);
			Vector3 right = ((Component)this).transform.right;
			Vector3 forward = ((Component)this).transform.forward;
			Vector3 val = -right + Vector3.up * (0.12f + 0.25f * num3);
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			val = Vector3.ProjectOnPlane(Vector3.up * 0.9f - forward * 0.45f, normalized);
			Quaternion val2 = Quaternion.LookRotation(((Vector3)(ref val)).normalized, normalized);
			Vector3 val3 = _modelRoot.TransformPoint(Vector3.Lerp(CarryHeadStare, CarryHeadBite, num3)) - normalized * _victimEye;
			((Component)obj).transform.position = Vector3.Lerp(_victimStartPos, val3, num2);
			((Component)obj).transform.rotation = Quaternion.Slerp(_victimStartRot, val2, num2);
		}

		private void FindRig()
		{
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			_modelRoot = ((Component)this).transform.Find("ModelRoot");
			_hips = B("Hips");
			_spine = B("Spine");
			_chest = B("Chest");
			_neck = B("Neck");
			_head = B("Head");
			_jaw = B("Jaw");
			_clavL = B("Clavicle.L");
			_clavR = B("Clavicle.R");
			_upArmL = B("UpperArm.L");
			_upArmR = B("UpperArm.R");
			_loArmL = B("LowerArm.L");
			_loArmR = B("LowerArm.R");
			_handL = B("Hand.L");
			_handR = B("Hand.R");
			_upLegL = B("UpperLeg.L");
			_upLegR = B("UpperLeg.R");
			_loLegL = B("LowerLeg.L");
			_loLegR = B("LowerLeg.R");
			_footL = B("Foot.L");
			_footR = B("Foot.R");
			_itemHold = B("ItemHold");
			_carryPoint = B("CarryPoint");
			_hipsBasePos = _hips.localPosition;
			_lastPos = ((Component)this).transform.position;
			Transform B(string n)
			{
				return FindDeep(_modelRoot, n);
			}
		}

		private static Transform FindDeep(Transform root, string name)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			if ((Object)(object)root == (Object)null)
			{
				return null;
			}
			if (((Object)root).name == name)
			{
				return root;
			}
			foreach (Transform item in root)
			{
				Transform val = FindDeep(item, name);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}

		private void Set(Transform bone, float x, float y = 0f, float z = 0f)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)bone != (Object)null)
			{
				_pose[bone] = new Vector3(x, y, z);
			}
		}

		private Vector2 LookAngles(Vector3 worldTarget, float bodyLean)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = _head.position + _head.up * 0.08f * Scale;
			Vector3 val2 = _modelRoot.InverseTransformDirection(worldTarget - val);
			float num = Mathf.Atan2(val2.x, val2.z) * 57.29578f;
			float y = val2.y;
			Vector2 val3 = new Vector2(val2.x, val2.z);
			float num2 = (0f - Mathf.Atan2(y, ((Vector2)(ref val3)).magnitude)) * 57.29578f - bodyLean;
			return new Vector2(Mathf.Clamp(num, -85f, 85f), Mathf.Clamp(num2, -45f, 75f));
		}

		private PlayerControllerB VisualTarget()
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)base.targetPlayer != (Object)null)
			{
				return base.targetPlayer;
			}
			if (Time.time >= _nextVisualTargetPick && (Object)(object)StartOfRound.Instance != (Object)null)
			{
				_nextVisualTargetPick = Time.time + 0.5f;
				_visualTarget = null;
				float num = 30f;
				PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
				foreach (PlayerControllerB val in allPlayerScripts)
				{
					if (!((Object)(object)val == (Object)null) && val.isPlayerControlled && !val.isPlayerDead)
					{
						Vector3 val2 = ((Component)val).transform.position - ((Component)this).transform.position;
						float magnitude = ((Vector3)(ref val2)).magnitude;
						if (magnitude < num && magnitude > 0.01f && Vector3.Dot(((Component)this).transform.forward, val2 / magnitude) > 0.2f)
						{
							num = magnitude;
							_visualTarget = val;
						}
					}
				}
			}
			return _visualTarget;
		}

		private static Vector3 PlayerHead(PlayerControllerB p)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)p.gameplayCamera != (Object)null))
			{
				return ((Component)p).transform.position + Vector3.up * 1.8f;
			}
			return ((Component)p.gameplayCamera).transform.position;
		}

		private void Animate(float dt)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0469: Unknown result type (might be due to invalid IL or missing references)
			//IL_046e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0500: Unknown result type (might be due to invalid IL or missing references)
			//IL_0786: Unknown result type (might be due to invalid IL or missing references)
			//IL_078d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0792: Unknown result type (might be due to invalid IL or missing references)
			//IL_079d: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_08df: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0863: Unknown result type (might be due to invalid IL or missing references)
			//IL_0892: Unknown result type (might be due to invalid IL or missing references)
			//IL_0897: Unknown result type (might be due to invalid IL or missing references)
			//IL_089c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0829: Unknown result type (might be due to invalid IL or missing references)
			//IL_0847: Unknown result type (might be due to invalid IL or missing references)
			//IL_084c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0943: Unknown result type (might be due to invalid IL or missing references)
			//IL_094a: Unknown result type (might be due to invalid IL or missing references)
			//IL_094f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0956: Unknown result type (might be due to invalid IL or missing references)
			//IL_0985: Unknown result type (might be due to invalid IL or missing references)
			//IL_098b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0990: Unknown result type (might be due to invalid IL or missing references)
			//IL_0992: Unknown result type (might be due to invalid IL or missing references)
			//IL_0999: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_modelRoot == (Object)null || dt <= 0f)
			{
				return;
			}
			float time = Time.time;
			Vector3 val = ((Component)this).transform.position - _lastPos;
			_lastPos = ((Component)this).transform.position;
			val.y = 0f;
			float num = ((Vector3)(ref val)).magnitude / dt;
			if (num > 40f)
			{
				num = 0f;
			}
			_speed = Mathf.Lerp(_speed, num, 1f - Mathf.Exp(-8f * dt));
			float num2 = _speed / Scale;
			if (_flinch > 0f)
			{
				_flinch -= dt;
			}
			_pose.Clear();
			Vector3 hipsOffset = Vector3.zero;
			float rate = 14f;
			if (base.isEnemyDead)
			{
				AnimateDeath(dt);
				return;
			}
			_modelRoot.localRotation = Quaternion.Slerp(_modelRoot.localRotation, Quaternion.identity, 1f - Mathf.Exp(-10f * dt));
			_modelRoot.localPosition = Vector3.Lerp(_modelRoot.localPosition, Vector3.zero, 1f - Mathf.Exp(-10f * dt));
			int currentBehaviourStateIndex = base.currentBehaviourStateIndex;
			bool flag = currentBehaviourStateIndex == 3;
			bool carryActive = _carryActive;
			bool num3 = (Object)(object)_eatItem != (Object)null || currentBehaviourStateIndex == 4;
			float num4 = (flag ? 1.9f : 1.15f);
			_phase += num2 / num4 * MathF.PI * 2f * dt;
			float num5 = Mathf.Clamp01(num2 / (flag ? 3f : 1.2f));
			float num6 = Mathf.Sin(_phase);
			float num7 = Mathf.Cos(_phase);
			float num8 = (flag ? 48f : 26f) * num5;
			float num9 = (flag ? 75f : 38f) * num5;
			Set(_upLegL, (0f - num6) * num8);
			Set(_upLegR, num6 * num8);
			Set(_loLegL, num9 * Mathf.Max(0f, Mathf.Sin(_phase + 1.25f)));
			Set(_loLegR, num9 * Mathf.Max(0f, Mathf.Sin(_phase + MathF.PI + 1.25f)));
			Set(_footL, num6 * 10f * num5);
			Set(_footR, (0f - num6) * 10f * num5);
			hipsOffset.y = (0f - Mathf.Abs(num7)) * (flag ? 0.05f : 0.025f) * num5;
			float num10 = (flag ? 55f : 22f) * num5;
			float num11 = (flag ? 20f : (3f + 3f * num5));
			Set(_upArmL, num6 * num10, 0f, -5f);
			Set(_upArmR, (0f - num6) * num10, 0f, 5f);
			Set(_loArmL, 0f - (flag ? 70f : 14f) - 10f * num5);
			Set(_loArmR, 0f - (flag ? 70f : 14f) - 10f * num5);
			Set(_spine, num11 * 0.5f, num6 * 4f * num5);
			Set(_chest, num11 * 0.5f, (0f - num6) * 6f * num5);
			Set(_jaw, 0f);
			if (time >= _nextTwitch)
			{
				_twitch = new Vector3(Random.Range(-15f, 15f), Random.Range(-45f, 45f), Random.Range(-25f, 25f));
				_twitchUntil = time + Random.Range(0.12f, 0.3f);
				_nextTwitch = time + Random.Range(1.5f, 5f);
			}
			Vector3 headRot = default(Vector3);
			((Vector3)(ref headRot))..ctor(4f + Mathf.Sin(time * 0.9f) * 5f, Mathf.Sin(time * 0.55f) * 25f, 14f + Mathf.Sin(time * 0.7f) * 6f);
			if (time < _twitchUntil)
			{
				headRot += _twitch;
			}
			PlayerControllerB val2 = null;
			if (currentBehaviourStateIndex == 1 || currentBehaviourStateIndex == 2 || currentBehaviourStateIndex == 3)
			{
				val2 = VisualTarget();
			}
			switch (currentBehaviourStateIndex)
			{
			case 1:
				((Vector3)(ref headRot))..ctor(0f, 0f, 28f);
				Set(_jaw, 6f + Mathf.Sin(time * 2f) * 2f);
				Set(_upArmL, Mathf.Sin(time * 31f) * 2f, 0f, -6f);
				Set(_upArmR, Mathf.Sin(time * 27f) * 2f, 0f, 6f);
				Set(_spine, 5f);
				Set(_chest, 4f);
				rate = 6f;
				break;
			case 2:
				Set(_upArmL, -62f + num6 * 6f * num5, 0f, 8f);
				Set(_upArmR, -62f - num6 * 6f * num5, 0f, -8f);
				Set(_loArmL, -12f);
				Set(_loArmR, -12f);
				Set(_handL, 10f);
				Set(_handR, 10f);
				((Vector3)(ref headRot))..ctor(0f, 0f, 18f + Mathf.Sin(time * 1.3f) * 4f);
				Set(_jaw, 4f);
				break;
			case 3:
				((Vector3)(ref headRot))..ctor(Mathf.Sin(time * 29f) * 10f, Mathf.Sin(time * 37f) * 14f, Mathf.Sin(time * 23f) * 18f);
				Set(_jaw, 22f + Mathf.Sin(time * 19f) * 6f);
				rate = 22f;
				break;
			}
			if ((Object)(object)val2 != (Object)null)
			{
				Vector2 val3 = LookAngles(PlayerHead(val2), num11);
				headRot.x += val3.y;
				headRot.y = headRot.y * 0.2f + val3.x;
			}
			if (num3)
			{
				AnimateEatScrap(time, ref headRot, ref rate);
			}
			if (carryActive)
			{
				AnimateCarry(time, ref headRot, ref hipsOffset, ref rate);
			}
			if (_flinch > 0f)
			{
				headRot.x -= 25f * (_flinch / 0.35f);
				if (_pose.TryGetValue(_spine, out var value))
				{
					_pose[_spine] = value + new Vector3(-12f * (_flinch / 0.35f), 0f, 0f);
				}
			}
			if (base.stunNormalizedTimer > 0f)
			{
				headRot += new Vector3(Random.Range(-4f, 4f), Random.Range(-4f, 4f), Random.Range(-6f, 6f));
				rate = 40f;
			}
			Set(_neck, headRot.x * 0.35f, headRot.y * 0.4f, headRot.z * 0.3f);
			Set(_head, headRot.x * 0.65f, headRot.y * 0.6f, headRot.z * 0.7f);
			float num12 = 1f - Mathf.Exp((0f - rate) * dt);
			foreach (KeyValuePair<Transform, Vector3> item in _pose)
			{
				item.Key.localRotation = Quaternion.Slerp(item.Key.localRotation, Quaternion.Euler(item.Value), num12);
			}
			_hips.localPosition = Vector3.Lerp(_hips.localPosition, _hipsBasePos + hipsOffset, num12);
		}

		private void AnimateEatScrap(float now, ref Vector3 headRot, ref float rate)
		{
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: 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_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(0f, Mathf.Sin(now * 9f));
			float num2 = Mathf.Sin(now * 9f) * 4f;
			Set(_upArmL, -50.7f + num2, 19.2f, -15.5f);
			Set(_upArmR, -55.1f + num2, -17.8f, 15.3f);
			Set(_loArmL, -108.8f, 39.4f);
			Set(_loArmR, -108.1f, -40.9f);
			Set(_handL, -10f);
			Set(_handR, -10f);
			Set(_spine, 6f);
			Set(_chest, 4f);
			Set(_jaw, 6f + num * 18f);
			Set(_upLegL, 0f);
			Set(_upLegR, 0f);
			Set(_loLegL, 0f);
			Set(_loLegR, 0f);
			headRot = new Vector3(8f + num * 4f, 0f, 10f);
			if ((Object)(object)_eatVictim != (Object)null)
			{
				Vector2 val = LookAngles(PlayerHead(_eatVictim), 10f);
				headRot.x = Mathf.Lerp(headRot.x, val.y, 0.35f);
				headRot.y = val.x * 0.6f;
			}
			rate = 16f;
		}

		private void AnimateCarry(float now, ref Vector3 headRot, ref Vector3 hipsOffset, ref float rate)
		{
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			float num = now - _carryStart;
			float num2 = CarryLean(num);
			float num3 = 0f - (num2 + 6f);
			Set(_upArmL, -45f + num3, -1.2f, -2.5f);
			Set(_upArmR, -42.2f + num3, 1.5f, 2.3f);
			Set(_loArmL, -16.5f, -5.5f);
			Set(_loArmR, -18.2f, 5.3f);
			Set(_handL, -20f);
			Set(_handR, -20f);
			Set(_upLegL, -6f);
			Set(_upLegR, 4f);
			Set(_loLegL, 12f);
			Set(_loLegR, 8f);
			Set(_spine, num2 * 0.45f);
			Set(_chest, num2 * 0.55f);
			hipsOffset.y = -0.03f;
			Vector3 worldTarget = (((Object)(object)carriedPlayer != (Object)null) ? PlayerHead(carriedPlayer) : _carryPoint.position);
			Vector2 val = LookAngles(worldTarget, num2);
			if (num < 3f)
			{
				float num4 = Mathf.Clamp01(num / 3f);
				headRot = new Vector3(val.y + 8f * num4, val.x, 22f + 10f * num4);
				Set(_jaw, 4f + 8f * num4);
				rate = 5f;
				return;
			}
			if (num < 4.0499997f)
			{
				headRot = new Vector3(val.y + 4f + Mathf.Sin(now * 33f) * 8f, val.x + Mathf.Sin(now * 41f) * 10f, 15f + Mathf.Sin(now * 27f) * 14f);
				Set(_jaw, 30f + Mathf.Sin(now * 21f) * 5f);
				rate = 25f;
				return;
			}
			if (num < 5.7f)
			{
				float num5 = Mathf.Abs(Mathf.Sin((num - 4.35f) / 0.45f * MathF.PI));
				headRot = new Vector3(val.y + 8f + 10f * num5, val.x, 12f);
				Set(_jaw, 8f + 30f * num5);
				rate = 30f;
				return;
			}
			float num6 = Mathf.Max(0f, Mathf.Sin(now * 8f));
			headRot = new Vector3(10f + num6 * 5f, Mathf.Sin(now * 0.8f) * 10f, 12f);
			Set(_jaw, 5f + num6 * 16f);
			float num7 = Mathf.Clamp01((num - 5.7f) / 1.2f);
			Set(_upArmL, Mathf.Lerp(-45f + num3, -12f, num7), 0f, -4f);
			Set(_upArmR, Mathf.Lerp(-42.2f + num3, -12f, num7), 0f, 4f);
			Set(_loArmL, Mathf.Lerp(-16.5f, -10f, num7));
			Set(_loArmR, Mathf.Lerp(-18.2f, -10f, num7));
			rate = 8f;
		}

		private static float CarryLean(float t)
		{
			if (t < 3f)
			{
				return -6f + 12f * Mathf.Clamp01(t / 3f);
			}
			if (t < 4.0499997f)
			{
				return 8f;
			}
			if (t < 5.7f)
			{
				float num = Mathf.Abs(Mathf.Sin((t - 4.35f) / 0.45f * MathF.PI));
				return 22f + 14f * num;
			}
			return Mathf.Lerp(10f, 0f, Mathf.Clamp01((t - 5.7f) / 1.2f));
		}

		private void AnimateDeath(float dt)
		{
			//IL_003b: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			_deathTime += dt;
			float num = Mathf.Clamp01(_deathTime / 0.55f);
			num *= num;
			_modelRoot.localRotation = Quaternion.Euler(-84f * num, 0f, 0f);
			_modelRoot.localPosition = new Vector3(0f, 0.17f * num * Scale, 0f);
			Set(_upArmL, -40f, 0f, -70f);
			Set(_upArmR, -30f, 0f, 75f);
			Set(_loArmL, -30f);
			Set(_loArmR, -50f);
			Set(_upLegL, -20f, 0f, -8f);
			Set(_upLegR, -8f, 0f, 10f);
			Set(_loLegL, 35f);
			Set(_loLegR, 15f);
			Set(_neck, -10f, 0f, 10f);
			Set(_head, -15f, 25f, 20f);
			Set(_jaw, 26f);
			float num2 = 1f - Mathf.Exp(-12f * dt);
			foreach (KeyValuePair<Transform, Vector3> item in _pose)
			{
				item.Key.localRotation = Quaternion.Slerp(item.Key.localRotation, Quaternion.Euler(item.Value), num2);
			}
		}

		public override void Start()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			FindRig();
			JeongmonsterAssets.ApplyMaterials(((Component)this).gameObject);
			JeongmonsterAssets.SetupAudio(this);
			_scanNode = ((Component)this).GetComponentInChildren<ScanNodeProperties>();
			if ((Object)(object)_scanNode != (Object)null && (Object)(object)Plugin.InfoNode != (Object)null)
			{
				_scanNode.creatureScanID = Plugin.InfoNode.creatureFileID;
			}
			_roam = new AISearchRoutine();
			((EnemyAI)this).Start();
			base.currentBehaviourState = base.enemyBehaviourStates[base.currentBehaviourStateIndex];
			_lastState = base.currentBehaviourStateIndex;
			_nextAmbientVoice = Time.time + Random.Range(6f, 15f);
			if (((NetworkBehaviour)this).IsOwner)
			{
				((EnemyAI)this).StartSearch(((Component)this).transform.position, _roam);
			}
		}

		public override void OnNetworkSpawn()
		{
			((NetworkBehaviour)this).OnNetworkSpawn();
			JeongmonsterNet.EnsureRegistered();
		}

		public override void OnDestroy()
		{
			try
			{
				ReleaseCarriedPlayer(cancelled: true);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("Release on destroy: " + ex.Message));
			}
			UnhookCamera();
			((EnemyAI)this).OnDestroy();
		}

		internal bool HasScrap(PlayerControllerB p)
		{
			if ((Object)(object)p == (Object)null || (Object)(object)p.currentlyHeldObjectServer == (Object)null)
			{
				return false;
			}
			GrabbableObject currentlyHeldObjectServer = p.currentlyHeldObjectServer;
			if (!Cfg.AnyItemCounts.Value)
			{
				if ((Object)(object)currentlyHeldObjectServer.itemProperties != (Object)null)
				{
					return currentlyHeldObjectServer.itemProperties.isScrap;
				}
				return false;
			}
			return true;
		}

		private bool ValidTarget(PlayerControllerB p)
		{
			if ((Object)(object)p != (Object)null && !p.isPlayerDead && p.isPlayerControlled && (Object)(object)p.inAnimationWithEnemy == (Object)null)
			{
				return ((EnemyAI)this).PlayerIsTargetable(p, false, false, true);
			}
			return false;
		}

		private void StopMoving()
		{
			base.movingTowardsTargetPlayer = false;
			base.moveTowardsDestination = false;
			base.agent.speed = 0f;
			if (((Behaviour)base.agent).enabled && base.agent.isOnNavMesh)
			{
				base.agent.ResetPath();
			}
		}

		private void GoState(int state)
		{
			_stateTime = 0f;
			_lostSight = 0f;
			if (state != base.currentBehaviourStateIndex)
			{
				((EnemyAI)this).SwitchToBehaviourState(state);
			}
		}

		private void BackToRoaming(bool fed = false)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			base.targetPlayer = null;
			base.movingTowardsTargetPlayer = false;
			base.moveTowardsDestination = true;
			if (fed)
			{
				_satisfiedUntil = Time.time + Cfg.SatisfiedTime.Value;
			}
			GoState((fed && Cfg.SatisfiedTime.Value > 0f) ? 6 : 0);
			if (_roam != null && !_roam.inProgress)
			{
				((EnemyAI)this).StartSearch(((Component)this).transform.position, _roam);
			}
		}

		public override void DoAIInterval()
		{
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).DoAIInterval();
			if (base.isEnemyDead || StartOfRound.Instance.allPlayersDead)
			{
				return;
			}
			if (base.stunNormalizedTimer > 0f)
			{
				base.agent.speed = 0f;
				return;
			}
			_stateTime += base.AIIntervalTime;
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
			{
				base.agent.speed = Cfg.RoamSpeed.Value;
				if (_roam != null && !_roam.inProgress)
				{
					((EnemyAI)this).StartSearch(((Component)this).transform.position, _roam);
				}
				PlayerControllerB val = ((EnemyAI)this).CheckLineOfSightForClosestPlayer(70f, Cfg.SightRange.Value, 3, 0f);
				if (ValidTarget(val))
				{
					((EnemyAI)this).StopSearch(_roam, true);
					base.targetPlayer = val;
					StopMoving();
					GoState(1);
				}
				break;
			}
			case 6:
				base.agent.speed = Cfg.RoamSpeed.Value;
				if (_roam != null && !_roam.inProgress)
				{
					((EnemyAI)this).StartSearch(((Component)this).transform.position, _roam);
				}
				if (Time.time >= _satisfiedUntil)
				{
					GoState(0);
				}
				break;
			case 1:
				StopMoving();
				if (!ValidTarget(base.targetPlayer))
				{
					BackToRoaming();
				}
				else if (_stateTime >= Cfg.StareTime.Value)
				{
					ChaseTarget(base.targetPlayer);
				}
				break;
			case 2:
			case 3:
			{
				if (!ValidTarget(base.targetPlayer))
				{
					PlayerControllerB p = ((EnemyAI)this).CheckLineOfSightForClosestPlayer(70f, Cfg.SightRange.Value, 3, 0f);
					if (ValidTarget(p))
					{
						ChaseTarget(p);
					}
					else
					{
						BackToRoaming();
					}
					break;
				}
				bool flag = ((EnemyAI)this).CheckLineOfSightForPosition(((Component)base.targetPlayer.gameplayCamera).transform.position, 140f, Cfg.SightRange.Value + 10, 4f, (Transform)null);
				_lostSight = (flag ? 0f : (_lostSight + base.AIIntervalTime));
				if (_lostSight > Cfg.LoseInterestTime.Value)
				{
					BackToRoaming();
				}
				else
				{
					ChaseTarget(base.targetPlayer);
				}
				break;
			}
			case 4:
			case 5:
				StopMoving();
				break;
			}
		}

		private void ChaseTarget(PlayerControllerB p)
		{
			bool flag = HasScrap(p);
			int num = (flag ? 3 : 2);
			base.moveTowardsDestination = true;
			((EnemyAI)this).SetMovingTowardsTargetPlayer(p);
			base.agent.speed = (flag ? Cfg.RunSpeed.Value : Cfg.WalkSpeed.Value);
			if (base.currentBehaviourStateIndex != num)
			{
				GoState(num);
			}
		}

		public override void Update()
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Update();
			float time = Time.time;
			if (base.currentBehaviourStateIndex != _lastState)
			{
				int lastState = _lastState;
				_lastState = base.currentBehaviourStateIndex;
				OnStateChanged(lastState, _lastState);
			}
			if (((NetworkBehaviour)this).IsOwner && !base.isEnemyDead)
			{
				PlayerControllerB val = null;
				if (base.currentBehaviourStateIndex == 1)
				{
					val = base.targetPlayer;
				}
				else if (base.currentBehaviourStateIndex == 4)
				{
					val = _eatVictim;
				}
				if ((Object)(object)val != (Object)null && base.stunNormalizedTimer <= 0f)
				{
					Vector3 val2 = ((Component)val).transform.position - ((Component)this).transform.position;
					val2.y = 0f;
					if (((Vector3)(ref val2)).sqrMagnitude > 0.01f)
					{
						((Component)this).transform.rotation = Quaternion.RotateTowards(((Component)this).transform.rotation, Quaternion.LookRotation(val2), 360f * Time.deltaTime);
					}
				}
				ServerUpdateBusyStates(time);
			}
			UpdateCarryLocal(time);
			UpdateEatLocal(time);
			UpdateAmbientVoice(time);
		}

		public void LateUpdate()
		{
			Animate(Time.deltaTime);
			if ((Object)(object)carriedPlayer != (Object)null && !carriedPlayer.isPlayerDead)
			{
				PoseCarriedPlayer();
				if (IsLocal(carriedPlayer))
				{
					LockCamera(carriedPlayer.gameplayCamera);
				}
			}
		}

		private void OnStateChanged(int oldState, int newState)
		{
			if (oldState == 5)
			{
				ReleaseCarriedPlayer(cancelled: false);
			}
			if (oldState == 4)
			{
				EndEatLocal(dropItem: false);
			}
			if (!base.isEnemyDead)
			{
				switch (newState)
				{
				case 3:
					PlayVoice(JeongmonsterAssets.RandomVoice(), 1f, Random.Range(0.95f, 1.08f), Time.time >= _voiceBusyUntil - 0.4f);
					_nextRushScream = Time.time + Random.Range(2.5f, 4.5f);
					break;
				case 2:
					PlayVoice(JeongmonsterAssets.RandomVoice(), 0.45f, 0.82f, interrupt: false);
					break;
				case 1:
					_flinch = 0f;
					break;
				}
			}
		}

		private void UpdateAmbientVoice(float now)
		{
			if (!base.isEnemyDead && !(base.stunNormalizedTimer > 0f))
			{
				int currentBehaviourStateIndex = base.currentBehaviourStateIndex;
				if (currentBehaviourStateIndex == 3 && now >= _nextRushScream)
				{
					PlayVoice(JeongmonsterAssets.RandomVoice(), 1f, Random.Range(0.95f, 1.1f), interrupt: false);
					_nextRushScream = now + Random.Range(2.5f, 5f);
				}
				else if ((currentBehaviourStateIndex == 0 || currentBehaviourStateIndex == 2 || currentBehaviourStateIndex == 6) && now >= _nextAmbientVoice)
				{
					PlayVoice(JeongmonsterAssets.RandomVoice(), (currentBehaviourStateIndex == 0) ? 0.3f : 0.5f, Random.Range(0.78f, 0.92f), interrupt: false);
					_nextAmbientVoice = now + Random.Range(10f, 22f);
				}
			}
		}

		internal void PlayVoice(AudioClip clip, float volume, float pitch, bool interrupt)
		{
			if (!((Object)(object)clip == (Object)null) && !((Object)(object)base.creatureVoice == (Object)null) && (interrupt || !(Time.time < _voiceBusyUntil)))
			{
				if (interrupt)
				{
					base.creatureVoice.Stop();
				}
				base.creatureVoice.pitch = pitch;
				base.creatureVoice.PlayOneShot(clip, volume);
				WalkieTalkie.TransmitOneShotAudio(base.creatureVoice, clip, volume);
				_voiceBusyUntil = Time.time + clip.length / Mathf.Max(0.1f, pitch);
			}
		}

		private void PlaySfx(AudioClip clip, float volume = 1f)
		{
			if (!((Object)(object)clip == (Object)null) && !((Object)(object)base.creatureSFX == (Object)null))
			{
				base.creatureSFX.pitch = Random.Range(0.9f, 1.1f);
				base.creatureSFX.PlayOneShot(clip, volume);
				WalkieTalkie.TransmitOneShotAudio(base.creatureSFX, clip, volume);
			}
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			((EnemyAI)this).OnCollideWithPlayer(other);
			if (base.isEnemyDead || base.stunNormalizedTimer > 0f || Time.time < _nextContact)
			{
				return;
			}
			int currentBehaviourStateIndex = base.currentBehaviourStateIndex;
			if (currentBehaviourStateIndex == 4 || currentBehaviourStateIndex == 5 || currentBehaviourStateIndex == 6 || _carryActive)
			{
				return;
			}
			PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false);
			if (!((Object)(object)val == (Object)null) && !((Object)(object)val.inAnimationWithEnemy != (Object)null))
			{
				_nextContact = Time.time + 0.75f;
				if (HasScrap(val))
				{
					StealScrapFrom(val);
				}
				else
				{
					JeongmonsterNet.SendToServer(JeongmonsterNet.Op.RequestCarry, this, PlayerIndex(val), 0uL);
				}
			}
		}

		internal static int PlayerIndex(PlayerControllerB p)
		{
			if (!((Object)(object)StartOfRound.Instance != (Object)null))
			{
				return -1;
			}
			return Array.IndexOf(StartOfRound.Instance.allPlayerScripts, p);
		}

		internal static bool IsLocal(PlayerControllerB p)
		{
			if ((Object)(object)p != (Object)null && (Object)(object)GameNetworkManager.Instance != (Object)null)
			{
				return (Object)(object)p == (Object)(object)GameNetworkManager.Instance.localPlayerController;
			}
			return false;
		}

		public override void HitEnemy(int force = 1, PlayerControllerB playerWhoHit = null, bool playHitSFX = false, int hitID = -1)
		{
			((EnemyAI)this).HitEnemy(force, playerWhoHit, playHitSFX, hitID);
			if (base.isEnemyDead)
			{
				return;
			}
			base.enemyHP -= force;
			_flinch = 0.35f;
			PlayVoice(JeongmonsterAssets.RandomVoice(), 0.9f, Random.Range(1.15f, 1.3f), interrupt: true);
			if (!((NetworkBehaviour)this).IsOwner)
			{
				return;
			}
			if (base.enemyHP <= 0)
			{
				((EnemyAI)this).KillEnemyOnOwnerClient(false);
				return;
			}
			int currentBehaviourStateIndex = base.currentBehaviourStateIndex;
			if ((Object)(object)playerWhoHit != (Object)null && currentBehaviourStateIndex != 5 && currentBehaviourStateIndex != 4 && !_carryActive && ValidTarget(playerWhoHit))
			{
				((EnemyAI)this).StopSearch(_roam, true);
				_satisfiedUntil = 0f;
				ChaseTarget(playerWhoHit);
			}
		}

		public override void KillEnemy(bool destroy = false)
		{
			ReleaseCarriedPlayer(cancelled: true);
			EndEatLocal(dropItem: true);
			((EnemyAI)this).KillEnemy(destroy);
			if (!destroy)
			{
				_deathTime = 0f;
				PlayVoice(JeongmonsterAssets.LoudestVoice, 1f, 0.62f, interrupt: true);
			}
		}

		public override void CancelSpecialAnimationWithPlayer()
		{
			ReleaseCarriedPlayer(cancelled: true);
			((EnemyAI)this).CancelSpecialAnimationWithPlayer();
		}

		private void HookCamera()
		{
			if (!_camHooked)
			{
				RenderPipelineManager.beginCameraRendering += OnBeginCameraRendering;
				_camHooked = true;
			}
		}

		private void UnhookCamera()
		{
			if (_camHooked)
			{
				RenderPipelineManager.beginCameraRendering -= OnBeginCameraRendering;
				_camHooked = false;
			}
		}

		private void OnBeginCameraRendering(ScriptableRenderContext ctx, Camera cam)
		{
			if (!((Object)(object)this == (Object)null) && !((Object)(object)carriedPlayer == (Object)null) && !carriedPlayer.isPlayerDead && IsLocal(carriedPlayer) && (Object)(object)cam == (Object)(object)carriedPlayer.gameplayCamera)
			{
				LockCamera(cam);
			}
		}

		private void LockCamera(Camera cam)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)cam == (Object)null) && !((Object)(object)_head == (Object)null))
			{
				Transform transform = ((Component)cam).transform;
				Vector3 val = FacePoint() - transform.position;
				if (!(((Vector3)(ref val)).sqrMagnitude < 0.0001f))
				{
					Vector3 val2 = ((Mathf.Abs(Vector3.Dot(((Vector3)(ref val)).normalized, Vector3.up)) > 0.95f) ? ((Component)this).transform.forward : Vector3.up);
					Quaternion val3 = Quaternion.LookRotation(val, val2);
					float num = Mathf.Clamp01((Time.time - _carryStart) / 0.45f);
					transform.rotation = Quaternion.Slerp(_camStartRot, val3, num * num * (3f - 2f * num));
				}
			}
		}

		internal Vector3 FacePoint()
		{
			//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)
			return _head.TransformPoint(new Vector3(0f, 0.012f, 0.1f));
		}
	}
	internal static class JeongmonsterAssets
	{
		public static JeongmonsterModelData Model;

		public static Texture2D SkinTex;

		public static Texture2D ClothesTex;

		public static Texture2D ShoesTex;

		public static AudioClip Scream;

		public static List<AudioClip> Voices = new List<AudioClip>();

		public static AudioClip LoudestVoice;

		public static List<AudioClip> Crunches = new List<AudioClip>();

		public static AudioClip Silence;

		private static readonly Dictionary<string, Material> _materials = new Dictionary<string, Material>();

		private static Material _radar;

		private static AudioMixerGroup _mixer;

		private static bool _searchedVanilla;

		public static Material RadarMaterial
		{
			get
			{
				//IL_0039: 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_0043: Expected O, but got Unknown
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_0098: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_radar != (Object)null)
				{
					return _radar;
				}
				Shader val = Shader.Find("HDRP/Unlit");
				_radar = (((Object)(object)val != (Object)null) ? new Material(val) : new Material(GetMaterial("Skin")));
				((Object)_radar).name = "JeongmonsterRadarDot";
				SetIfHas(_radar, "_UnlitColor", Color.red);
				SetIfHas(_radar, "_BaseColorMap", (Texture)(object)Texture2D.whiteTexture);
				SetIfHas(_radar, "_BaseColor", Color.red);
				SetIfHas(_radar, "_Color", Color.red);
				return _radar;
			}
		}

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

		private static Texture2D LoadTexture(string name)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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_0027: Expected O, but got Unknown
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true)
			{
				name = "Jeongmonster_" + name
			};
			ImageConversion.LoadImage(val, Resource(name), true);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)2;
			((Texture)val).anisoLevel = 4;
			return val;
		}

		public static void Load(string pluginDir)
		{
			using (MemoryStream stream = new MemoryStream(Resource("jeongmonster_model.bin")))
			{
				Model = ModelLoader.Load(stream);
			}
			SkinTex = LoadTexture("skin.jpg");
			ClothesTex = LoadTexture("clothes.jpg");
			ShoesTex = LoadTexture("shoes.jpg");
			Silence = AudioLoader.CreateSilence();
			Scream = AudioLoader.LoadFirst(pluginDir, "scream");
			if ((Object)(object)Scream != (Object)null)
			{
				Plugin.Log.LogInfo((object)("Using custom scream sound '" + ((Object)Scream).name + "' from the mod folder."));
			}
			else
			{
				Scream = AudioLoader.LoadWav(Resource("scream.wav"), "JeongmonsterScream");
			}
			Voices = AudioLoader.SplitBySilence(Scream);
			if (Voices.Count == 0)
			{
				Voices.Add(Scream);
			}
			LoudestVoice = Voices.OrderByDescending(Loudness).First();
			for (int i = 0; i < 3; i++)
			{
				Crunches.Add(AudioLoader.CreateCrunch(11 + i * 7));
			}
		}

		private static float Loudness(AudioClip c)
		{
			float[] array = new float[c.samples * c.channels];
			c.GetData(array, 0);
			double num = 0.0;
			float[] array2 = array;
			foreach (float num2 in array2)
			{
				num += (double)(num2 * num2);
			}
			return (float)(num / (double)Mathf.Max(1, array.Length)) * Mathf.Min(c.length, 2f);
		}

		public static AudioClip RandomVoice()
		{
			return Voices[Random.Range(0, Voices.Count)];
		}

		public static AudioClip RandomCrunch()
		{
			return Crunches[Random.Range(0, Crunches.Count)];
		}

		private static Material NewLit(string name, Texture2D tex, float smoothness)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_0084: Expected O, but got Unknown
			Shader val = Shader.Find("HDRP/Lit");
			Material val2;
			if ((Object)(object)val != (Object)null)
			{
				val2 = new Material(val);
			}
			else
			{
				Plugin.Log.LogWarning((object)"HDRP/Lit shader not found, copying a player material instead.");
				SkinnedMeshRenderer val3 = (((Object)(object)StartOfRound.Instance != (Object)null && StartOfRound.Instance.allPlayerScripts.Length != 0) ? StartOfRound.Instance.allPlayerScripts[0].thisPlayerModel : null);
				val2 = (((Object)(object)val3 != (Object)null) ? new Material(((Renderer)val3).sharedMaterial) : new Material(Shader.Find("Standard")));
				if (val2.HasProperty("_NormalMap"))
				{
					val2.SetTexture("_NormalMap", (Texture)null);
				}
				val2.DisableKeyword("_NORMALMAP");
			}
			((Object)val2).name = "Jeongmonster_" + name;
			SetIfHas(val2, "_BaseColorMap", (Texture)(object)tex);
			SetIfHas(val2, "_MainTex", (Texture)(object)tex);
			SetIfHas(val2, "_BaseColor", Color.white);
			SetIfHas(val2, "_Color", Color.white);
			SetIfHas(val2, "_Smoothness", smoothness);
			SetIfHas(val2, "_Metallic", 0f);
			return val2;
		}

		public static Material GetMaterial(string name)
		{
			if (_materials.TryGetValue(name, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			value = (Material)(name switch
			{
				"Skin" => NewLit(name, SkinTex, 0.32f), 
				"Clothes" => NewLit(name, ClothesTex, 0.12f), 
				"Shoes" => NewLit(name, ShoesTex, 0.25f), 
				_ => NewLit(name, Texture2D.grayTexture, 0.2f), 
			});
			_materials[name] = value;
			return value;
		}

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

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

		private static void SetIfHas(Material m, string prop, float f)
		{
			if (m.HasProperty(prop))
			{
				m.SetFloat(prop, f);
			}
		}

		public static void ApplyMaterials(GameObject root)
		{
			SkinnedMeshRenderer[] componentsInChildren = root.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Renderer)componentsInChildren[i]).sharedMaterials = Model.Materials.Select(GetMaterial).ToArray();
			}
			MeshRenderer[] componentsInChildren2 = root.GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val in componentsInChildren2)
			{
				if (((Object)((Component)val).gameObject).name == "RadarDot")
				{
					((Renderer)val).sharedMaterial = RadarMaterial;
				}
			}
		}

		public static void SetupAudio(JeongmonsterAI ai)
		{
			if (!_searchedVanilla && (Object)(object)StartOfRound.Instance != (Object)null)
			{
				_searchedVanilla = true;
				List<AudioClip> list = new List<AudioClip>();
				SelectableLevel[] levels = StartOfRound.Instance.levels;
				foreach (SelectableLevel val in levels)
				{
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					List<SpawnableEnemyWithRarity>[] array = new List<SpawnableEnemyWithRarity>[3] { val.Enemies, val.OutsideEnemies, val.DaytimeEnemies };
					foreach (List<SpawnableEnemyWithRarity> list2 in array)
					{
						if (list2 == null)
						{
							continue;
						}
						foreach (SpawnableEnemyWithRarity item in list2)
						{
							if (item == null || (Object)(object)item.enemyType == (Object)null || (Object)(object)item.enemyType == (Object)(object)Plugin.EnemyType || (Object)(object)item.enemyType.enemyPrefab == (Object)null)
							{
								continue;
							}
							EnemyAI component = item.enemyType.enemyPrefab.GetComponent<EnemyAI>();
							if (!((Object)(object)component == (Object)null))
							{
								if ((Object)(object)_mixer == (Object)null && (Object)(object)component.creatureVoice != (Object)null)
								{
									_mixer = component.creatureVoice.outputAudioMixerGroup;
								}
								if ((Object)(object)Plugin.EnemyType.hitBodySFX == (Object)null && (Object)(object)item.enemyType.hitBodySFX != (Object)null)
								{
									Plugin.EnemyType.hitBodySFX = item.enemyType.hitBodySFX;
								}
								MouthDogAI val2 = (MouthDogAI)(object)((component is MouthDogAI) ? component : null);
								if (val2 != null && (Object)(object)val2.killPlayerSFX != (Object)null)
								{
									list.Add(val2.killPlayerSFX);
								}
								CaveDwellerAI val3 = (CaveDwellerAI)(object)((component is CaveDwellerAI) ? component : null);
								if (val3 != null && (Object)(object)val3.biteSFX != (Object)null)
								{
									list.Add(val3.biteSFX);
								}
							}
						}
					}
				}
				list = list.Distinct().ToList();
				if (list.Count > 0)
				{
					Crunches = list.Concat(Crunches.Take(1)).ToList();
					Plugin.Log.LogInfo((object)$"Borrowed {list.Count} vanilla bite sounds.");
				}
			}
			if ((Object)(object)_mixer != (Object)null)
			{
				if ((Object)(object)((EnemyAI)ai).creatureVoice != (Object)null)
				{
					((EnemyAI)ai).creatureVoice.outputAudioMixerGroup = _mixer;
				}
				if ((Object)(object)((EnemyAI)ai).creatureSFX != (Object)null)
				{
					((EnemyAI)ai).creatureSFX.outputAudioMixerGroup = _mixer;
				}
			}
		}
	}
	internal class JeongmonsterConfig
	{
		public readonly ConfigEntry<string> MonsterName;

		public readonly ConfigEntry<int> SpawnWeight;

		public readonly ConfigEntry<int> MaxCount;

		public readonly ConfigEntry<float> PowerLevel;

		public readonly ConfigEntry<int> Health;

		public readonly ConfigEntry<float> RoamSpeed;

		public readonly ConfigEntry<float> WalkSpeed;

		public readonly ConfigEntry<float> RunSpeed;

		public readonly ConfigEntry<float> StareTime;

		public readonly ConfigEntry<float> LoseInterestTime;

		public readonly ConfigEntry<int> SightRange;

		public readonly ConfigEntry<int> ScrapDamage;

		public readonly ConfigEntry<float> Knockback;

		public readonly ConfigEntry<float> EatScrapTime;

		public readonly ConfigEntry<float> SatisfiedTime;

		public readonly ConfigEntry<bool> AnyItemCounts;

		public readonly ConfigEntry<float> ModelScale;

		public readonly ConfigEntry<float> ScreamVolume;

		public readonly ConfigEntry<float> ScreamDistance;

		public JeongmonsterConfig(ConfigFile cfg)
		{
			MonsterName = cfg.Bind<string>("General", "MonsterName", "Jeongmonster", "Name shown on the scanner and in the terminal bestiary.");
			SpawnWeight = cfg.Bind<int>("Spawning", "SpawnWeight", 30, "Spawn weight on every moon (vanilla enemies use roughly 1-100). 0 disables natural spawning.");
			MaxCount = cfg.Bind<int>("Spawning", "MaxCount", 2, "Maximum number alive at the same time.");
			PowerLevel = cfg.Bind<float>("Spawning", "PowerLevel", 1f, "How much of the moon's indoor power budget one Jeongmonster uses.");
			Health = cfg.Bind<int>("Stats", "Health", 4, "Hit points. A shovel hit does 1 damage.");
			RoamSpeed = cfg.Bind<float>("Stats", "RoamSpeed", 2.4f, "Speed while wandering around.");
			WalkSpeed = cfg.Bind<float>("Stats", "WalkSpeed", 3f, "Speed while WALKING toward a player who is NOT holding scrap (slow, but deadly if it reaches you).");
			RunSpeed = cfg.Bind<float>("Stats", "RunSpeed", 9.5f, "Speed while RUNNING at a player who is holding scrap.");
			StareTime = cfg.Bind<float>("Stats", "StareTime", 0.9f, "Seconds it stands still staring at a player before it comes for them.");
			LoseInterestTime = cfg.Bind<float>("Stats", "LoseInterestTime", 7f, "Seconds without seeing its target before it gives up.");
			SightRange = cfg.Bind<int>("Stats", "SightRange", 25, "How far it can see players.");
			ScrapDamage = cfg.Bind<int>("Scrap", "ScrapDamage", 20, "Damage dealt when it catches a player who is holding scrap.");
			Knockback = cfg.Bind<float>("Scrap", "Knockback", 14f, "How hard it shoves that player away (initial push speed).");
			EatScrapTime = cfg.Bind<float>("Scrap", "EatScrapTime", 4.5f, "Seconds it spends eating the stolen scrap in front of the player.");
			SatisfiedTime = cfg.Bind<float>("Scrap", "SatisfiedTime", 15f, "After eating (scrap or a player) it ignores players for this many seconds.");
			AnyItemCounts = cfg.Bind<bool>("Scrap", "AnyItemCounts", false, "If true, any held item (flashlight, shovel...) counts as 'holding scrap'. If false, only scrap items do.");
			ModelScale = cfg.Bind<float>("Visual", "ModelScale", 1f, "Model size multiplier. 1.0 = about 1.35 m tall.");
			ScreamVolume = cfg.Bind<float>("Audio", "ScreamVolume", 1f, "Monster voice volume (0 - 1).");
			ScreamDistance = cfg.Bind<float>("Audio", "ScreamDistance", 45f, "How far away the monster voice can be heard.");
		}
	}
	internal static class JeongmonsterNet
	{
		public enum Op : byte
		{
			RequestCarry = 1,
			TakeScrap = 2,
			BeginCarry = 10,
			BeginEatScrap = 11,
			CancelCarry = 12
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnMessage;
		}

		private const string MessageName = "Jeongmonster.Net.v1";

		private static CustomMessagingManager _registeredOn;

		public static void EnsureRegistered()
		{
			//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_004c: Expected O, but got Unknown
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton == (Object)null) && singleton.CustomMessagingManager != null && _registeredOn != singleton.CustomMessagingManager)
			{
				CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager;
				object obj = <>O.<0>__OnMessage;
				if (obj == null)
				{
					HandleNamedMessageDelegate val = OnMessage;
					<>O.<0>__OnMessage = val;
					obj = (object)val;
				}
				customMessagingManager.RegisterNamedMessageHandler("Jeongmonster.Net.v1", (HandleNamedMessageDelegate)obj);
				_registeredOn = singleton.CustomMessagingManager;
			}
		}

		public unsafe static void SendToServer(Op op, JeongmonsterAI ai, int playerIndex, ulong arg = 0uL)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			EnsureRegistered();
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || (Object)(object)ai == (Object)null || (Object)(object)((NetworkBehaviour)ai).NetworkObject == (Object)null)
			{
				return;
			}
			if (singleton.IsServer)
			{
				HandleServer(singleton.LocalClientId, op, ((NetworkBehaviour)ai).NetworkObjectId, playerIndex, arg);
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(32, (Allocator)2, -1);
			try
			{
				Write(val, op, ((NetworkBehaviour)ai).NetworkObjectId, playerIndex, arg);
				singleton.CustomMessagingManager.SendNamedMessage("Jeongmonster.Net.v1", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		public unsafe static void Broadcast(Op op, JeongmonsterAI ai, int playerIndex, ulong arg = 0uL)
		{
			//IL_0036: 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)
			EnsureRegistered();
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsServer)
			{
				return;
			}
			HandleClient(op, ((NetworkBehaviour)ai).NetworkObjectId, playerIndex, arg);
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(32, (Allocator)2, -1);
			try
			{
				Write(val, op, ((NetworkBehaviour)ai).NetworkObjectId, playerIndex, arg);
				foreach (ulong connectedClientsId in singleton.ConnectedClientsIds)
				{
					if (connectedClientsId != singleton.LocalClientId)
					{
						singleton.CustomMessagingManager.SendNamedMessage("Jeongmonster.Net.v1", connectedClientsId, val, (NetworkDelivery)3);
					}
				}
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void Write(FastBufferWriter w, Op op, ulong enemyId, int playerIndex, ulong arg)
		{
			//IL_0008: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			byte b = (byte)op;
			((FastBufferWriter)(ref w)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
			((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref enemyId, default(ForPrimitives));
			((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref playerIndex, default(ForPrimitives));
			((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref arg, default(ForPrimitives));
		}

		private static void OnMessage(ulong sender, FastBufferReader r)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_003f: 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)
			byte b = default(byte);
			((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
			ulong enemyId = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref enemyId, default(ForPrimitives));
			int playerIndex = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref playerIndex, default(ForPrimitives));
			ulong arg = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref arg, default(ForPrimitives));
			NetworkManager singleton = NetworkManager.Singleton;
			if (b < 10)
			{
				if ((Object)(object)singleton != (Object)null && singleton.IsServer)
				{
					HandleServer(sender, (Op)b, enemyId, playerIndex, arg);
				}
			}
			else if (sender == 0L)
			{
				HandleClient((Op)b, enemyId, playerIndex, arg);
			}
		}

		private static JeongmonsterAI FindAI(ulong enemyId)
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || singleton.SpawnManager == null)
			{
				return null;
			}
			if (!singleton.SpawnManager.SpawnedObjects.TryGetValue(enemyId, out var value) || (Object)(object)value == (Object)null)
			{
				return null;
			}
			return ((Component)value).GetComponent<JeongmonsterAI>();
		}

		public static GrabbableObject FindItem(ulong itemId)
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || singleton.SpawnManager == null)
			{
				return null;
			}
			if (!singleton.SpawnManager.SpawnedObjects.TryGetValue(itemId, out var value) || (Object)(object)value == (Object)null)
			{
				return null;
			}
			return ((Component)value).GetComponent<GrabbableObject>();
		}

		public static PlayerControllerB Player(int index)
		{
			PlayerControllerB[] array = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.allPlayerScripts : null);
			if (array == null || index < 0 || index >= array.Length)
			{
				return null;
			}
			return array[index];
		}

		private static void HandleServer(ulong sender, Op op, ulong enemyId, int playerIndex, ulong arg)
		{
			JeongmonsterAI jeongmonsterAI = FindAI(enemyId);
			PlayerControllerB val = Player(playerIndex);
			if (!((Object)(object)jeongmonsterAI == (Object)null) && !((Object)(object)val == (Object)null) && val.actualClientId == sender)
			{
				switch (op)
				{
				case Op.RequestCarry:
					jeongmonsterAI.ServerTryBeginCarry(val);
					break;
				case Op.TakeScrap:
					jeongmonsterAI.ServerTryBeginEatScrap(val, FindItem(arg));
					break;
				}
			}
		}

		private static void HandleClient(Op op, ulong enemyId, int playerIndex, ulong arg)
		{
			JeongmonsterAI jeongmonsterAI = FindAI(enemyId);
			if (!((Object)(object)jeongmonsterAI == (Object)null))
			{
				switch (op)
				{
				case Op.BeginCarry:
					jeongmonsterAI.BeginCarryLocal(Player(playerIndex));
					break;
				case Op.BeginEatScrap:
					jeongmonsterAI.BeginEatScrapLocal(Player(playerIndex), FindItem(arg));
					break;
				case Op.CancelCarry:
					jeongmonsterAI.ReleaseCarriedPlayer(cancelled: true);
					break;
				}
			}
		}
	}
	internal static class JeongmonsterPrefab
	{
		public const string RadarDotName = "RadarDot";

		public const float ModelHeight = 1.35f;

		public static EnemyType Build()
		{
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Expected O, but got Unknown
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Expected O, but got Unknown
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0463: Unknown result type (might be due to invalid IL or missing references)
			//IL_0472: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: 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_04cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_060a: Unknown result type (might be due to invalid IL or missing references)
			//IL_061d: Unknown result type (might be due to invalid IL or missing references)
			//IL_063a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0640: Unknown result type (might be due to invalid IL or missing references)
			//IL_0659: Unknown result type (might be due to invalid IL or missing references)
			//IL_065f: 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_0694: Unknown result type (might be due to invalid IL or missing references)
			//IL_0699: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0790: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			JeongmonsterConfig cfg = Plugin.Cfg;
			float num = Mathf.Max(0.1f, cfg.ModelScale.Value);
			int layer = Layer("Enemies", 19);
			int layer2 = Layer("ScanNode", 22);
			int layer3 = Layer("MapRadar", 14);
			EnemyType val = ScriptableObject.CreateInstance<EnemyType>();
			((Object)val).name = "JeongmonsterEnemyType";
			val.enemyName = cfg.MonsterName.Value;
			val.probabilityCurve = AnimationCurve.Constant(0f, 1f, 1f);
			val.numberSpawnedFalloff = AnimationCurve.Constant(0f, 10f, 1f);
			val.useNumberSpawnedFalloff = false;
			val.spawnInGroupsOf = 1;
			val.PowerLevel = cfg.PowerLevel.Value;
			val.MaxCount = Mathf.Max(1, cfg.MaxCount.Value);
			val.isOutsideEnemy = false;
			val.isDaytimeEnemy = false;
			val.increasedChanceInterior = -1;
			val.normalizedTimeInDayToLeave = 1f;
			val.stunTimeMultiplier = 1f;
			val.doorSpeedMultiplier = 1f;
			val.stunGameDifficultyMultiplier = 0f;
			val.canBeStunned = true;
			val.canDie = true;
			val.canBeDestroyed = true;
			val.destroyOnDeath = false;
			val.canSeeThroughFog = false;
			val.pushPlayerForce = 0f;
			val.pushPlayerDistance = 0f;
			val.SizeLimit = (NavSizeLimit)0;
			val.EnemySize = (EnemySize)2;
			val.WaterType = (EnemyWaterType)0;
			val.timeToPlayAudio = 0.5f;
			val.loudnessMultiplier = 1f;
			val.hitEnemyVoiceSFX = JeongmonsterAssets.Silence;
			val.stunSFX = JeongmonsterAssets.Silence;
			val.deathSFX = JeongmonsterAssets.Silence;
			val.miscAnimations = (MiscAnimation[])(object)new MiscAnimation[0];
			val.audioClips = (AudioClip[])(object)new AudioClip[1] { JeongmonsterAssets.Scream };
			GameObject val2 = NetworkPrefabs.CreateNetworkPrefab("JeongmonsterEnemy");
			val2.layer = layer;
			val.enemyPrefab = val2;
			NavMeshAgent obj = val2.AddComponent<NavMeshAgent>();
			obj.speed = cfg.RoamSpeed.Value;
			obj.angularSpeed = 400f;
			obj.acceleration = 24f;
			obj.stoppingDistance = 0f;
			obj.autoBraking = true;
			obj.radius = 0.3f * num;
			obj.height = 1.35f * num;
			obj.baseOffset = 0f;
			obj.obstacleAvoidanceType = (ObstacleAvoidanceType)2;
			obj.areaMask = -1;
			Animator val3 = val2.AddComponent<Animator>();
			val3.applyRootMotion = false;
			AudioSource val4 = val2.AddComponent<AudioSource>();
			Setup3DAudio(val4, 1f, 30f);
			GameObject val5 = new GameObject("ModelRoot");
			val5.layer = layer;
			val5.transform.SetParent(val2.transform, false);
			val5.transform.localScale = Vector3.one * num;
			JeongmonsterModelData model = JeongmonsterAssets.Model;
			Transform[] array = (Transform[])(object)new Transform[model.BoneNames.Length];
			for (int i = 0; i < array.Length; i++)
			{
				GameObject val6 = new GameObject(model.BoneNames[i]);
				val6.layer = layer;
				int num2 = model.BoneParents[i];
				val6.transform.SetParent((num2 < 0) ? val5.transform : array[num2], false);
				val6.transform.localPosition = model.BonePositions[i] - ((num2 < 0) ? Vector3.zero : model.BonePositions[num2]);
				array[i] = val6.transform;
			}
			GameObject val7 = new GameObject("Body")
			{
				layer = layer
			};
			val7.transform.SetParent(val5.transform, false);
			SkinnedMeshRenderer obj2 = val7.AddComponent<SkinnedMeshRenderer>();
			obj2.sharedMesh = model.Mesh;
			obj2.bones = array;
			obj2.rootBone = array[model.BoneIndex("Hips")];
			obj2.quality = (SkinQuality)4;
			obj2.updateWhenOffscreen = false;
			((Renderer)obj2).localBounds = new Bounds(Vector3.zero, new Vector3(3f, 3f, 3f));
			((Renderer)obj2).shadowCastingMode = (ShadowCastingMode)1;
			Transform val8 = array[model.BoneIndex("Head")];
			Transform val9 = array[model.BoneIndex("Hand.R")];
			Transform transform = new GameObject("Eye").tra