Decompiled source of CountryRoadCreature v1.0.7

CountryRoadCreature.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BigEyes.Utils;
using CountryRoadCreature.Scripts;
using GameNetcodeStuff;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BigEyes.Utils
{
	public class RegisterUtil
	{
		public static void RegisterEnemyWithConfig(string configMoonRarity, EnemyType enemy, TerminalNode terminalNode, TerminalKeyword terminalKeyword, float powerLevel, int spawnCount)
		{
			enemy.MaxCount = spawnCount;
			enemy.PowerLevel = powerLevel;
			var (dictionary, dictionary2) = ConfigParsing(configMoonRarity);
			Enemies.RegisterEnemy(enemy, dictionary, dictionary2, terminalNode, terminalKeyword);
		}

		public static void RegisterScrapWithConfig(string configMoonRarity, Item scrap)
		{
			var (dictionary, dictionary2) = ConfigParsing(configMoonRarity);
			Items.RegisterScrap(scrap, dictionary, dictionary2);
		}

		public static void RegisterShopItemWithConfig(bool enabledScrap, Item item, TerminalNode terminalNode, int itemCost, string configMoonRarity)
		{
			Items.RegisterShopItem(item, (TerminalNode)null, (TerminalNode)null, terminalNode, itemCost);
			if (enabledScrap)
			{
				RegisterScrapWithConfig(configMoonRarity, item);
			}
		}

		public static (Dictionary<LevelTypes, int> spawnRateByLevelType, Dictionary<string, int> spawnRateByCustomLevelType) ConfigParsing(string configMoonRarity)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<LevelTypes, int> dictionary = new Dictionary<LevelTypes, int>();
			Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
			foreach (string item in from s in configMoonRarity.Split(',')
				select s.Trim())
			{
				string[] array = item.Split(':');
				if (array.Length != 2)
				{
					continue;
				}
				string text = array[0];
				if (!int.TryParse(array[1], out var result))
				{
					continue;
				}
				if (Enum.TryParse<LevelTypes>(text, ignoreCase: true, out LevelTypes result2))
				{
					dictionary[result2] = result;
					continue;
				}
				string value = text + "Level";
				if (Enum.TryParse<LevelTypes>(value, ignoreCase: true, out result2))
				{
					dictionary[result2] = result;
				}
				else
				{
					dictionary2[text] = result;
				}
			}
			return (dictionary, dictionary2);
		}
	}
}
namespace CountryRoadCreature
{
	[BepInPlugin("wexop.country_road_creature", "CountryRoadCreature", "1.0.7")]
	[BepInDependency("evaisa.lethallib", "0.15.1")]
	public class CountryRoadCreaturePlugin : BaseUnityPlugin
	{
		private const string GUID = "wexop.country_road_creature";

		private const string NAME = "CountryRoadCreature";

		private const string VERSION = "1.0.7";

		public Dictionary<int, LightInformation> lightsInUse = new Dictionary<int, LightInformation>();

		public static CountryRoadCreaturePlugin instance;

		public ConfigEntry<string> spawnMoonRarity;

		public ConfigEntry<string> headScrapMoonRarity;

		public ConfigEntry<string> handScrapMoonRarity;

		public ConfigEntry<int> maxCountryRoadCreatureSpawnNb;

		public ConfigEntry<float> countryRoadBaseSpeed;

		public ConfigEntry<float> countryRoadMaxSpeedMutliplier;

		public ConfigEntry<int> scrapHitPlayerChance;

		private void Awake()
		{
			instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"CountryRoadCreature starting....");
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "countryroadcreature");
			AssetBundle bundle = AssetBundle.LoadFromFile(text);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"CountryRoadCreature bundle found !");
			LoadConfigs();
			RegisterMonster(bundle);
			RegisterScrap(bundle);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"CountryRoadCreature is ready!");
		}

		private void LoadConfigs()
		{
			spawnMoonRarity = ((BaseUnityPlugin)this).Config.Bind<string>("General", "SpawnRarity", "Modded:40,ExperimentationLevel:20,AssuranceLevel:20,VowLevel:20,OffenseLevel:25,MarchLevel:25,RendLevel:30,DineLevel:30,TitanLevel:50,Adamance:50,Embrion:50,Artifice:55", "Chance for Country road creature to spawn for any moon, example => assurance:100,offense:50 . You need to restart the game.");
			CreateStringConfig(spawnMoonRarity, requireRestart: true);
			maxCountryRoadCreatureSpawnNb = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxSpawnNumber", 1, "Max country road creatures spawn number. You need to restart the game.");
			CreateIntConfig(maxCountryRoadCreatureSpawnNb);
			handScrapMoonRarity = ((BaseUnityPlugin)this).Config.Bind<string>("General", "HandScrapSpawnRarity", "Modded:30,ExperimentationLevel:20,AssuranceLevel:20,VowLevel:25,OffenseLevel:25,MarchLevel:30,RendLevel:35,DineLevel:35,TitanLevel:35,Adamance:35,Embrion:35,Artifice:40", "Chance for creature hand scrap to spawn for any moon, example => assurance:100,offense:50 . You need to restart the game.");
			CreateStringConfig(handScrapMoonRarity, requireRestart: true);
			headScrapMoonRarity = ((BaseUnityPlugin)this).Config.Bind<string>("General", "HeadScrapSpawnRarity", "Modded:10,ExperimentationLevel:5,AssuranceLevel:5,VowLevel:10,OffenseLevel:10,MarchLevel:10,RendLevel:13,DineLevel:13,TitanLevel:15,Adamance:15,Embrion:20,Artifice:22", "Chance for creature head scrap to spawn for any moon, example => assurance:100,offense:50 . You need to restart the game.");
			CreateStringConfig(headScrapMoonRarity, requireRestart: true);
			scrapHitPlayerChance = ((BaseUnityPlugin)this).Config.Bind<int>("General", "HeadScrapHitPlayerChance", 10, "Chance for creature head scrap item to hit player after lights animation. You don't need to restart the game.");
			CreateIntConfig(scrapHitPlayerChance);
			countryRoadBaseSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("MonsterBehavior", "CountryRoadBaseSpeed", 3.33f, "Country road Creature base speed. You don't need to restart the game.");
			CreateFloatConfig(countryRoadBaseSpeed);
			countryRoadMaxSpeedMutliplier = ((BaseUnityPlugin)this).Config.Bind<float>("MonsterBehavior", "CountryRoadMaxSpeedMultiplier", 2.4f, "Country road Creature max speed multiplier, based on his angry gauge. You don't need to restart the game.");
			CreateFloatConfig(countryRoadMaxSpeedMutliplier, 1f, 50f);
		}

		private void RegisterMonster(AssetBundle bundle)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			EnemyType val = bundle.LoadAsset<EnemyType>("Assets/LethalCompany/Mods/CountryRoadCreature/CountryRoadCreature.asset");
			val.MaxCount = maxCountryRoadCreatureSpawnNb.Value;
			((BaseUnityPlugin)this).Logger.LogInfo((object)(((Object)val).name + " FOUND"));
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"{val.enemyPrefab} prefab");
			NetworkPrefabs.RegisterNetworkPrefab(val.enemyPrefab);
			Utilities.FixMixerGroups(val.enemyPrefab);
			TerminalNode val2 = new TerminalNode();
			val2.creatureName = "CountryRoadCreature";
			val2.displayText = "Run.";
			TerminalKeyword val3 = new TerminalKeyword();
			val3.word = "CountryRoadCreature";
			RegisterUtil.RegisterEnemyWithConfig(spawnMoonRarity.Value, val, val2, val3, val.PowerLevel, val.MaxCount);
		}

		private void RegisterScrap(AssetBundle bundle)
		{
			Item val = bundle.LoadAsset<Item>("Assets/LethalCompany/Mods/CountryRoadCreature/CountryRoadCreatureScrap.asset");
			((BaseUnityPlugin)this).Logger.LogInfo((object)(((Object)val).name + " FOUND"));
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"{val.spawnPrefab} prefab");
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Utilities.FixMixerGroups(val.spawnPrefab);
			RegisterUtil.RegisterScrapWithConfig(headScrapMoonRarity.Value, val);
			Item val2 = bundle.LoadAsset<Item>("Assets/LethalCompany/Mods/CountryRoadCreature/CountryRoadCreatureHandScrap.asset");
			((BaseUnityPlugin)this).Logger.LogInfo((object)(((Object)val2).name + " FOUND"));
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"{val2.spawnPrefab} prefab");
			NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
			Utilities.FixMixerGroups(val2.spawnPrefab);
			RegisterUtil.RegisterScrapWithConfig(handScrapMoonRarity.Value, val2);
		}

		private void CreateFloatConfig(ConfigEntry<float> configEntry, float min = 0f, float max = 100f)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			FloatSliderOptions val = new FloatSliderOptions();
			((BaseRangeOptions<float>)val).Min = min;
			((BaseRangeOptions<float>)val).Max = max;
			((BaseOptions)val).RequiresRestart = false;
			FloatSliderConfigItem val2 = new FloatSliderConfigItem(configEntry, val);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2);
		}

		private void CreateIntConfig(ConfigEntry<int> configEntry, int min = 0, int max = 100)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			IntSliderOptions val = new IntSliderOptions();
			((BaseRangeOptions<int>)val).Min = min;
			((BaseRangeOptions<int>)val).Max = max;
			((BaseOptions)val).RequiresRestart = false;
			IntSliderConfigItem val2 = new IntSliderConfigItem(configEntry, val);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2);
		}

		private void CreateStringConfig(ConfigEntry<string> configEntry, bool requireRestart = false)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			TextInputFieldConfigItem val = new TextInputFieldConfigItem(configEntry, new TextInputFieldOptions
			{
				RequiresRestart = requireRestart
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "CountryRoadCreature";

		public const string PLUGIN_NAME = "CountryRoadCreature";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace CountryRoadCreature.Scripts
{
	public class CountryRoadCreatureEnemyAI : EnemyAI
	{
		public AudioClip seePlayerSound;

		public List<AudioClip> walkSounds;

		public AudioClip screamSound;

		public AudioClip runSound;

		public AudioSource walkSource;

		public GameObject creatureObject;

		public Transform grabPosition;

		private static readonly int walk = Animator.StringToHash("walk");

		private static readonly int grab = Animator.StringToHash("grab");

		private static readonly int walkSpeed = Animator.StringToHash("walkSpeed");

		private static readonly int stun = Animator.StringToHash("stun");

		public float aiInterval;

		public int lastBehaviorState;

		private float lookAtPlayerTimer;

		private float monsterRunTimer;

		private float walkSoundTimer;

		private float animationParanoidTimer;

		private float animationGrabTimer;

		private float lostPlayerTimer;

		private float stunedTimer;

		private bool isLookingAtPlayer = false;

		private bool isRunningToPlayer = false;

		private bool isWalking = false;

		private bool isStuned = false;

		private float monsterAngryValue = 0f;

		private float monsterSpeedMultiplier = 1f;

		private float monsterLookPlayerTime = 2.5f;

		private float monsterRunToPlayerTime = 5f;

		private float monsterGrabTime = 3f;

		private float lostPlayerTime = 2f;

		private float stunTime = 1.25f;

		private float speed = 3.33f;

		private float normalAcceleration = 255f;

		private float angularSpeed = 900f;

		private float visionWidth = 60f;

		private float maxSpeed = 2f;

		private float timeBetweenWalkSound = 0.75f;

		private PlayerControllerB playerToKIll = null;

		private List<LightInformation> lights = new List<LightInformation>();

		private bool playerToKillIsLocal;

		private void AddAngryValue(float value)
		{
			monsterAngryValue = Mathf.Clamp(monsterAngryValue += value, 0f, 100f);
			monsterSpeedMultiplier = 1f + maxSpeed * (monsterAngryValue / 100f);
		}

		private void WalkingSound()
		{
			if (walkSoundTimer <= 0f)
			{
				walkSource.clip = walkSounds[Random.Range(0, walkSounds.Count)];
				walkSource.Play();
				walkSoundTimer = timeBetweenWalkSound / Mathf.Clamp(monsterSpeedMultiplier, 1f, 1.3f);
			}
		}

		private void ActiveLightList(bool active)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			foreach (LightInformation light in lights)
			{
				float num = Random.Range(0.1f, 0.5f);
				light.Light.color = (Color)(active ? light.color : new Color(num, 0f, 0f));
			}
		}

		private IEnumerator ParanoidAnimation()
		{
			lights.Clear();
			List<Light> closeLights = Object.FindObjectsByType<Light>((FindObjectsSortMode)0).ToList().FindAll((Light light) => Vector3.Distance(((Component)light).transform.position, ((Component)this).transform.position) < 20f && Object.op_Implicit((Object)(object)light));
			foreach (Light closeObject in closeLights)
			{
				LightInformation lightInformation = new LightInformation
				{
					Light = closeObject,
					color = closeObject.color
				};
				lights.Add(lightInformation);
			}
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 1f));
			creatureObject.SetActive(false);
			ActiveLightList(active: true);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 1.2f));
			creatureObject.SetActive(true);
			ActiveLightList(active: false);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 1.5f));
			creatureObject.SetActive(false);
			ActiveLightList(active: true);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 2f));
			creatureObject.SetActive(true);
			ActiveLightList(active: false);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 2.1f));
			creatureObject.SetActive(false);
			ActiveLightList(active: true);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 2.2f));
			creatureObject.SetActive(true);
			ActiveLightList(active: false);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 2.3f));
			creatureObject.SetActive(false);
			ActiveLightList(active: true);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 2.4f));
			creatureObject.SetActive(true);
			ActiveLightList(active: false);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 2.5f));
			creatureObject.SetActive(false);
			ActiveLightList(active: false);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > monsterLookPlayerTime));
			creatureObject.SetActive(true);
			yield return (object)new WaitForSeconds(1f);
			ActiveLightList(active: true);
		}

		public override void Start()
		{
			speed = CountryRoadCreaturePlugin.instance.countryRoadBaseSpeed.Value;
			maxSpeed = CountryRoadCreaturePlugin.instance.countryRoadMaxSpeedMutliplier.Value - 1f;
			((EnemyAI)this).Start();
			AllClientOnSwitchBehaviorState();
			base.agent.angularSpeed = angularSpeed;
		}

		public override void Update()
		{
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Update();
			aiInterval -= Time.deltaTime;
			walkSoundTimer -= Time.deltaTime;
			animationGrabTimer -= Time.deltaTime;
			if (isStuned)
			{
				stunedTimer -= Time.deltaTime;
			}
			if (isLookingAtPlayer)
			{
				lookAtPlayerTimer -= Time.deltaTime;
				animationParanoidTimer += Time.deltaTime;
			}
			if (isRunningToPlayer)
			{
				monsterRunTimer -= Time.deltaTime;
			}
			if (isWalking)
			{
				lostPlayerTimer -= Time.deltaTime;
				WalkingSound();
			}
			if (isStuned)
			{
				isStuned = stunedTimer > 0f;
			}
			if (lastBehaviorState != base.currentBehaviourStateIndex)
			{
				lastBehaviorState = base.currentBehaviourStateIndex;
				AllClientOnSwitchBehaviorState();
			}
			if (isRunningToPlayer && GameNetworkManager.Instance.localPlayerController.HasLineOfSightToPosition(((Component)this).transform.position + Vector3.up * 0.25f, 100f, 60, -1f))
			{
				GameNetworkManager.Instance.localPlayerController.JumpToFearLevel(0.8f, true);
			}
			if (base.currentBehaviourStateIndex == 3)
			{
				GrabAnimation();
			}
			if (aiInterval <= 0f && ((NetworkBehaviour)this).IsOwner)
			{
				aiInterval = base.AIIntervalTime;
				((EnemyAI)this).DoAIInterval();
			}
		}

		public override void DoAIInterval()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00a8: 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)
			((EnemyAI)this).DoAIInterval();
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
				if (lostPlayerTimer <= 0f)
				{
					((EnemyAI)this).TargetClosestPlayer(1.5f, true, visionWidth);
				}
				if ((Object)(object)base.targetPlayer == (Object)null)
				{
					if (!base.currentSearch.inProgress)
					{
						AISearchRoutine val = new AISearchRoutine();
						val.searchWidth = 200f;
						val.searchPrecision = 8f;
						((EnemyAI)this).StartSearch(((EnemyAI)this).ChooseFarthestNodeFromPosition(((Component)this).transform.position, true, 0, false, 50, false).position, val);
					}
				}
				else if (((EnemyAI)this).PlayerIsTargetable(base.targetPlayer, false, false))
				{
					lookAtPlayerTimer = monsterLookPlayerTime;
					((EnemyAI)this).SwitchToBehaviourState(1);
				}
				break;
			case 1:
				base.currentSearch.inProgress = false;
				if (lookAtPlayerTimer > 0f)
				{
					((Component)this).transform.LookAt(((Component)base.targetPlayer).transform);
				}
				else if (((EnemyAI)this).PlayerIsTargetable(base.targetPlayer, false, false))
				{
					monsterRunTimer = monsterRunToPlayerTime;
					((EnemyAI)this).SwitchToBehaviourState(2);
				}
				else
				{
					((EnemyAI)this).SwitchToBehaviourState(0);
				}
				break;
			case 2:
				if (monsterRunTimer <= 0f)
				{
					((EnemyAI)this).TargetClosestPlayer(1.5f, true, visionWidth);
					if ((Object)(object)base.targetPlayer != (Object)null)
					{
						monsterRunTimer += 1f;
						break;
					}
					lostPlayerTimer = lostPlayerTime;
					((EnemyAI)this).SwitchToBehaviourState(0);
				}
				else if ((Object)(object)base.targetPlayer != (Object)null && ((EnemyAI)this).PlayerIsTargetable(base.targetPlayer, false, false))
				{
					((EnemyAI)this).SetMovingTowardsTargetPlayer(base.targetPlayer);
				}
				break;
			case 3:
				if (!(animationGrabTimer <= 0f))
				{
					base.targetPlayer = null;
				}
				break;
			case 4:
				Debug.Log((object)$"IS STUNED {isStuned}");
				if (!isStuned)
				{
					monsterRunTimer = monsterRunToPlayerTime;
					((EnemyAI)this).SwitchToBehaviourState(2);
				}
				break;
			}
		}

		private void LateUpdate()
		{
			//IL_0051: 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)
			if ((Object)(object)playerToKIll != (Object)null && animationGrabTimer > 0f && (Object)(object)base.inSpecialAnimationWithPlayer != (Object)null && !isStuned)
			{
				((Component)base.inSpecialAnimationWithPlayer.gameplayCamera).transform.rotation = grabPosition.rotation;
				base.inSpecialAnimationWithPlayer.cameraContainerTransform.rotation = grabPosition.rotation;
			}
		}

		private void CancelPlayerEffects()
		{
			if ((Object)(object)playerToKIll != (Object)null)
			{
				playerToKIll.disableMoveInput = false;
				playerToKIll.disableLookInput = false;
				playerToKIll.inAnimationWithEnemy = null;
				playerToKIll.isInElevator = false;
				playerToKIll.disableInteract = false;
				playerToKIll.isInHangarShipRoom = false;
			}
			if (playerToKillIsLocal)
			{
				PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
				localPlayerController.disableMoveInput = false;
				localPlayerController.disableLookInput = false;
				localPlayerController.inAnimationWithEnemy = null;
				localPlayerController.isInElevator = false;
				localPlayerController.disableInteract = false;
				localPlayerController.isInHangarShipRoom = false;
			}
			base.inSpecialAnimationWithPlayer = null;
			base.inSpecialAnimation = false;
		}

		private void GrabAnimation()
		{
			//IL_0091: 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_00e0: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			base.targetPlayer = null;
			if ((Object)(object)playerToKIll == (Object)null || !playerToKillIsLocal)
			{
				return;
			}
			if (animationGrabTimer > 0f)
			{
				base.inSpecialAnimation = true;
				playerToKIll.disableMoveInput = true;
				playerToKIll.disableLookInput = true;
				playerToKIll.disableInteract = true;
				base.inSpecialAnimationWithPlayer = playerToKIll;
				playerToKIll.inAnimationWithEnemy = (EnemyAI)(object)this;
				((Component)playerToKIll).transform.position = grabPosition.position;
				((Component)playerToKIll).transform.rotation = grabPosition.rotation;
			}
			else
			{
				((EnemyAI)this).SwitchToBehaviourServerRpc(0);
				CancelPlayerEffects();
				if (playerToKillIsLocal)
				{
					GameNetworkManager.Instance.localPlayerController.KillPlayer(Vector3.zero, false, (CauseOfDeath)8, 0, default(Vector3));
					playerToKillIsLocal = false;
				}
				playerToKIll = null;
			}
		}

		public void AllClientOnSwitchBehaviorState()
		{
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			base.agent.speed = speed * monsterSpeedMultiplier;
			base.agent.acceleration = normalAcceleration;
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
				lostPlayerTimer = lostPlayerTime;
				isLookingAtPlayer = false;
				isRunningToPlayer = false;
				isWalking = true;
				base.creatureAnimator.SetBool(walk, true);
				base.creatureAnimator.SetBool(grab, false);
				base.creatureAnimator.SetBool(stun, false);
				base.creatureAnimator.SetFloat(walkSpeed, 1f);
				break;
			case 1:
				monsterRunTimer = monsterRunToPlayerTime;
				base.agent.speed = 0f;
				base.creatureVoice.clip = seePlayerSound;
				base.creatureVoice.Play();
				lookAtPlayerTimer = monsterLookPlayerTime;
				isLookingAtPlayer = true;
				isWalking = false;
				animationParanoidTimer = 0f;
				base.agent.velocity = Vector3.zero;
				AddAngryValue(15f);
				base.creatureAnimator.SetBool(walk, false);
				base.creatureAnimator.SetBool(grab, false);
				base.creatureAnimator.SetBool(stun, false);
				((MonoBehaviour)this).StartCoroutine(ParanoidAnimation());
				break;
			case 2:
				base.creatureVoice.clip = runSound;
				base.creatureVoice.Play();
				monsterRunTimer = monsterRunToPlayerTime;
				isRunningToPlayer = true;
				base.creatureAnimator.SetBool(walk, true);
				base.creatureAnimator.SetBool(grab, false);
				base.creatureAnimator.SetBool(stun, false);
				base.creatureAnimator.SetFloat(walkSpeed, Mathf.Clamp(monsterSpeedMultiplier, 1f, 1.5f));
				isWalking = true;
				break;
			case 3:
				AddAngryValue(100f);
				base.agent.speed = 0f;
				base.agent.velocity = Vector3.zero;
				animationGrabTimer = monsterGrabTime;
				base.creatureVoice.clip = screamSound;
				base.creatureVoice.Play();
				base.creatureAnimator.SetBool(grab, true);
				base.creatureAnimator.SetBool(stun, false);
				break;
			case 4:
				AddAngryValue(100f);
				base.agent.speed = 0f;
				base.agent.velocity = Vector3.zero;
				base.creatureVoice.clip = screamSound;
				base.creatureVoice.Play();
				base.creatureAnimator.SetBool(stun, true);
				isRunningToPlayer = false;
				monsterRunTimer = monsterRunToPlayerTime;
				break;
			}
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			if (!((Object)(object)playerToKIll != (Object)null) && !isStuned && !(animationGrabTimer > 0f))
			{
				animationGrabTimer = monsterGrabTime;
				PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, true);
				if ((Object)(object)val != (Object)null)
				{
					((EnemyAI)this).SwitchToBehaviourServerRpc(3);
					playerToKillIsLocal = true;
					playerToKIll = val;
					playerToKIll.DropAllHeldItems(true, false);
				}
				((EnemyAI)this).PlayAnimationOfCurrentState();
			}
		}

		public override void HitEnemy(int force = 1, PlayerControllerB playerWhoHit = null, bool playHitSFX = false, int hitID = -1)
		{
			if (!isStuned)
			{
				animationGrabTimer = 0.75f;
				CancelPlayerEffects();
				playerToKIll = null;
				playerToKillIsLocal = false;
				stunedTimer = stunTime;
				isStuned = true;
				base.targetPlayer = playerWhoHit;
				((EnemyAI)this).SwitchToBehaviourServerRpc(4);
			}
		}
	}
	public class CountryRoadCreatureHeadItem : NoisemakerProp
	{
		public AudioSource hitPlayerAudioSource;

		public AudioSource laughtAudioSource;

		private List<LightInformation> lights = new List<LightInformation>();

		private float animationParanoidTimer;

		private bool animationPlaying;

		private int hitPlayerChance = 10;

		public bool canHitPlayer;

		public override void Start()
		{
			((NoisemakerProp)this).Start();
			hitPlayerChance = CountryRoadCreaturePlugin.instance.scrapHitPlayerChance.Value;
		}

		private void ActiveLightList(bool active)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			foreach (LightInformation light in lights)
			{
				float num = Random.Range(0.1f, 0.5f);
				light.Light.color = (Color)(active ? light.color : new Color(num, 0f, 0f));
			}
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if (animationPlaying)
			{
				animationParanoidTimer += Time.deltaTime;
			}
		}

		private IEnumerator ParanoidAnimation()
		{
			lights.Clear();
			List<Light> closeLights = Object.FindObjectsByType<Light>((FindObjectsSortMode)0).ToList().FindAll((Light light) => Vector3.Distance(((Component)light).transform.position, ((Component)this).transform.position) < 15f && Object.op_Implicit((Object)(object)light));
			foreach (Light closeObject in closeLights)
			{
				LightInformation lightInformation = new LightInformation
				{
					Light = closeObject,
					color = closeObject.color
				};
				int instanceId = ((Object)closeObject).GetInstanceID();
				if (CountryRoadCreaturePlugin.instance.lightsInUse.ContainsKey(instanceId))
				{
					lights.Add(CountryRoadCreaturePlugin.instance.lightsInUse[instanceId]);
					continue;
				}
				CountryRoadCreaturePlugin.instance.lightsInUse.Add(instanceId, lightInformation);
				lights.Add(lightInformation);
			}
			ActiveLightList(active: true);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 1f));
			ActiveLightList(active: true);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 1.2f));
			ActiveLightList(active: false);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 1.5f));
			ActiveLightList(active: true);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 2f));
			ActiveLightList(active: false);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 2.1f));
			ActiveLightList(active: true);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 2.2f));
			ActiveLightList(active: false);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 2.3f));
			ActiveLightList(active: true);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 2.4f));
			ActiveLightList(active: false);
			yield return (object)new WaitUntil((Func<bool>)(() => animationParanoidTimer > 2.5f));
			ActiveLightList(active: false);
			yield return (object)new WaitForSeconds(2f);
			bool canHitPlayerValue = (Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null && canHitPlayer;
			if (!(Random.Range(0, 100) < hitPlayerChance && canHitPlayerValue))
			{
				ActiveLightList(active: true);
				animationPlaying = false;
			}
			else
			{
				GameNetworkManager.Instance.localPlayerController.DamagePlayer(15, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
				laughtAudioSource.Play();
				yield return (object)new WaitForSeconds(1f);
				animationPlaying = false;
				ActiveLightList(active: true);
			}
			lights.ForEach(delegate(LightInformation l)
			{
				CountryRoadCreaturePlugin.instance.lightsInUse.Remove(((Object)l.Light).GetInstanceID());
			});
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			canHitPlayer = (Object)(object)((GrabbableObject)this).playerHeldBy == (Object)(object)GameNetworkManager.Instance.localPlayerController;
			if (!animationPlaying)
			{
				animationPlaying = true;
				animationParanoidTimer = 0f;
				((MonoBehaviour)this).StartCoroutine(ParanoidAnimation());
			}
			((NoisemakerProp)this).ItemActivate(used, buttonDown);
		}
	}
	public class LightInformation
	{
		public Light Light;

		public Color color;
	}
}