Decompiled source of ScaryLamps v1.0.1

ScaryLamps.dll

Decompiled a week ago
using System;
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 GameNetcodeStuff;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using ScaryLamps.NetcodePatcher;
using ScaryLamps.Utils;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Rendering;

[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("ScaryLamps")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("ScaryLamps")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+17f8fef2135a74eb14b5666f4b5ffa56e97db881")]
[assembly: AssemblyProduct("ScaryLamps")]
[assembly: AssemblyTitle("ScaryLamps")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
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 ScaryLamps
{
	[BepInPlugin("wexop.scary_lamps", "ScaryLamps", "1.0.1")]
	public class ScaryLampsPlugin : BaseUnityPlugin
	{
		private const string GUID = "wexop.scary_lamps";

		private const string NAME = "ScaryLamps";

		private const string VERSION = "1.0.1";

		public ConfigEntry<string> spawnMoonRarity;

		public ConfigEntry<int> scaryLampDamage;

		public ConfigEntry<string> MonsterDetectorspawnRarity;

		public ConfigEntry<float> MonsterDetectorRange;

		public ConfigEntry<string> streetLampSpawnRarity;

		public static ScaryLampsPlugin instance;

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

		private string RarityString(int rarity)
		{
			return $"Modded:{rarity},ExperimentationLevel:{rarity},AssuranceLevel:{rarity},VowLevel:{rarity},OffenseLevel:{rarity},MarchLevel:{rarity},RendLevel:{rarity},DineLevel:{rarity},TitanLevel:{rarity},Adamance:{rarity},Embrion:{rarity},Artifice:{rarity},All:{rarity}";
		}

		private void LoadConfigs()
		{
			spawnMoonRarity = ((BaseUnityPlugin)this).Config.Bind<string>("ScaryLamp", "ScaryLampRarity", RarityString(50), "Chance for Scary Lamp to spawn for any moon, example => assurance:100,offense:50 . You need to restart the game.");
			CreateStringConfig(spawnMoonRarity, requireRestart: true);
			scaryLampDamage = ((BaseUnityPlugin)this).Config.Bind<int>("ScaryLamp", "ScaryLampDamage", 5, "Damage for each tick of ScaryLamp attack . No need to restart the game.");
			CreateIntConfig(scaryLampDamage, 1);
			MonsterDetectorspawnRarity = ((BaseUnityPlugin)this).Config.Bind<string>("MonsterDetectorLamp", "MonsterDetectorSpawnRarity", RarityString(40), "Chance for Monster Detector Lamp to spawn for any moon, example => assurance:100,offense:50 . You need to restart the game.");
			CreateStringConfig(MonsterDetectorspawnRarity, requireRestart: true);
			MonsterDetectorRange = ((BaseUnityPlugin)this).Config.Bind<float>("MonsterDetectorLamp", "MonsterDetectorRange", 35f, "Monster Detector Lamp detection range. No need to restart the game.");
			CreateFloatConfig(MonsterDetectorRange, 0f, 200f);
			streetLampSpawnRarity = ((BaseUnityPlugin)this).Config.Bind<string>("StreetLamp", "streetLampSpawnRarity", RarityString(50), "Chance for Street Lamp to spawn for any moon, example => assurance:100,offense:50 . You need to restart the game.");
			CreateStringConfig(streetLampSpawnRarity, requireRestart: true);
		}

		private void RegisterMonster(AssetBundle bundle)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Expected O, but got Unknown
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			EnemyType val = bundle.LoadAsset<EnemyType>("Assets/LethalCompany/Mods/ScaryLamps/LampMonster/ScaryLamp.asset");
			((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 = "ScaryLamp";
			val2.displayText = "Don't wake him, or he will be very angry...";
			TerminalKeyword val3 = new TerminalKeyword();
			val3.word = "ScaryLamp";
			RegisterUtil.RegisterEnemyWithConfig(spawnMoonRarity.Value, val, val2, val3, val.PowerLevel, val.MaxCount);
			EnemyType val4 = bundle.LoadAsset<EnemyType>("Assets/LethalCompany/Mods/ScaryLamps/StreetLampMonster/ScaryStreetLamp.asset");
			((BaseUnityPlugin)this).Logger.LogInfo((object)(((Object)val4).name + " FOUND"));
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"{val4.enemyPrefab} prefab");
			NetworkPrefabs.RegisterNetworkPrefab(val4.enemyPrefab);
			Utilities.FixMixerGroups(val4.enemyPrefab);
			TerminalNode val5 = new TerminalNode();
			val5.creatureName = "ScaryLamp";
			val5.displayText = "Don't wake him, or he will be very angry...";
			TerminalKeyword val6 = new TerminalKeyword();
			val6.word = "ScaryLamp";
			RegisterUtil.RegisterEnemyWithConfig(streetLampSpawnRarity.Value, val4, val5, val6, val4.PowerLevel, val4.MaxCount);
		}

		private void RegisterScrap(AssetBundle bundle)
		{
			Item val = bundle.LoadAsset<Item>("Assets/LethalCompany/Mods/ScaryLamps/LampMonsterDetector/LampMonsterDetector.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(MonsterDetectorspawnRarity.Value, val);
		}

		private static void NetcodePatcher()
		{
			Type[] array;
			try
			{
				array = Assembly.GetExecutingAssembly().GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				array = ex.Types.Where((Type type) => type != null).ToArray();
			}
			Type[] array2 = array;
			foreach (Type type2 in array2)
			{
				MethodInfo[] methods = type2.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}

		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 bool StringContain(string name, string verifiedName)
		{
			string text = name.ToLower();
			while (text.Contains(" "))
			{
				text = text.Replace(" ", "");
			}
			string text2 = verifiedName.ToLower();
			while (text2.Contains(" "))
			{
				text2 = text2.Replace(" ", "");
			}
			return text.Contains(text2);
		}

		private void CreateBoolConfig(ConfigEntry<bool> configEntry)
		{
			//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
			BoolCheckBoxConfigItem val = new BoolCheckBoxConfigItem(configEntry, new BoolCheckBoxOptions
			{
				RequiresRestart = false
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ScaryLamps";

		public const string PLUGIN_NAME = "ScaryLamps";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ScaryLamps.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 ScaryLamps.Scripts
{
	public class MonsterDetectorLamp : MonoBehaviour
	{
		public GameObject greenObject;

		public GameObject orangeObject;

		public GameObject RedObject;

		private int currentState = 0;

		private float checkTimer;

		private float checkDelay = 0.2f;

		private void OnChangeState(int newState)
		{
			greenObject.SetActive(newState == 0);
			orangeObject.SetActive(newState == 1);
			RedObject.SetActive(newState == 2);
			currentState = newState;
		}

		private int StateFromDistance(float distance)
		{
			if (distance > ScaryLampsPlugin.instance.MonsterDetectorRange.Value)
			{
				return 0;
			}
			if (distance < ScaryLampsPlugin.instance.MonsterDetectorRange.Value / 2f)
			{
				return 2;
			}
			return 1;
		}

		private void Start()
		{
			OnChangeState(0);
		}

		private void Update()
		{
			checkTimer -= Time.deltaTime;
			if (checkTimer > 0f)
			{
				return;
			}
			checkTimer = checkDelay;
			float distance = ScaryLampsPlugin.instance.MonsterDetectorRange.Value + 1f;
			RoundManager.Instance.SpawnedEnemies.ToList().ForEach(delegate(EnemyAI ai)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				float num2 = Vector3.Distance(((Component)ai).transform.position, ((Component)this).transform.position);
				if (num2 < distance && !ai.isEnemyDead)
				{
					distance = num2;
				}
			});
			int num = StateFromDistance(distance);
			if (num != currentState)
			{
				OnChangeState(num);
			}
		}
	}
	public class ScaryLampEnemyAI : EnemyAI
	{
		private static readonly int Attack = Animator.StringToHash("Attack");

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

		public List<AudioClip> walkSounds;

		public AudioSource AttackAudioSource;

		public AudioClip deathSound;

		public Light angryLight;

		public Volume Volume;

		private readonly float walkSpeed = 3.5f;

		private float aiInterval = 0.2f;

		private int lastBehaviorState;

		private readonly float walkSoundDelayRun = 0.5f;

		private readonly float walkSoundDelayWalk = 0.9f;

		private float attackPlayerTimer;

		private readonly float attackPlayerDelay = 0.5f;

		private float volumeWeightTimer;

		private readonly float volumeWeightDelay = 2f;

		private float walkSoundTimer;

		private float visionWidth = 100f;

		public override void Start()
		{
			((EnemyAI)this).Start();
			base.agent.speed = walkSpeed;
			base.agent.acceleration = 255f;
			base.agent.angularSpeed = 900f;
			((Behaviour)angryLight).enabled = false;
		}

		public override void Update()
		{
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			Volume.weight = Mathf.Clamp(volumeWeightTimer / volumeWeightDelay, 0f, 1f);
			volumeWeightTimer -= Time.deltaTime;
			if (base.isEnemyDead)
			{
				return;
			}
			((EnemyAI)this).Update();
			attackPlayerTimer -= Time.deltaTime;
			if (lastBehaviorState != base.currentBehaviourStateIndex)
			{
				Debug.Log((object)$"New behavior state : {base.currentBehaviourStateIndex} last : {lastBehaviorState}");
				lastBehaviorState = base.currentBehaviourStateIndex;
				AllClientOnSwitchBehaviorState();
			}
			walkSoundTimer -= Time.deltaTime;
			if (walkSoundTimer <= 0f && base.currentBehaviourStateIndex == 0)
			{
				AudioClip val = walkSounds[Random.Range(0, walkSounds.Count)];
				base.creatureSFX.PlayOneShot(val);
				walkSoundTimer = ((base.currentBehaviourStateIndex == 1) ? walkSoundDelayRun : walkSoundDelayWalk);
			}
			if (base.currentBehaviourStateIndex == 1 && GameNetworkManager.Instance.localPlayerController.HasLineOfSightToPosition(((Component)this).transform.position + Vector3.up * 0.25f, visionWidth, 60, -1f, -1))
			{
				volumeWeightTimer = volumeWeightDelay;
				if (attackPlayerTimer <= 0f)
				{
					attackPlayerTimer = attackPlayerDelay;
					GameNetworkManager.Instance.localPlayerController.DamagePlayer(ScaryLampsPlugin.instance.scaryLampDamage.Value, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
					GameNetworkManager.Instance.localPlayerController.sprintMeter = 0f;
					volumeWeightTimer = volumeWeightDelay;
				}
			}
			if (((NetworkBehaviour)this).IsServer && aiInterval <= 0f)
			{
				aiInterval = base.AIIntervalTime;
				((EnemyAI)this).DoAIInterval();
			}
		}

		public override void DoAIInterval()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_008a: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).DoAIInterval();
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
				((EnemyAI)this).TargetClosestPlayer(1.5f, true, visionWidth, false, false, true);
				if ((Object)(object)base.targetPlayer == (Object)null)
				{
					if (base.currentSearch.inProgress)
					{
						break;
					}
					AISearchRoutine val = new AISearchRoutine();
					val.searchWidth = 50f;
					val.searchPrecision = 8f;
					((EnemyAI)this).StartSearch(((EnemyAI)this).ChooseFarthestNodeFromPosition(((Component)this).transform.position, true, 0, false, 50, -1).position, val);
				}
				if (Object.op_Implicit((Object)(object)base.targetPlayer) && ((EnemyAI)this).PlayerIsTargetable(base.targetPlayer, false, false, true))
				{
					((Component)this).transform.LookAt(((Component)base.targetPlayer.gameplayCamera).transform);
					((Component)this).transform.eulerAngles = new Vector3(0f, ((Component)this).transform.eulerAngles.y, 0f);
					TurnOnPlayerTargetClientRpc(((Component)this).transform.rotation);
					((EnemyAI)this).SwitchToBehaviourState(1);
				}
				break;
			case 1:
				((EnemyAI)this).TargetClosestPlayer(1.5f, true, visionWidth, false, false, true);
				if (!Object.op_Implicit((Object)(object)base.targetPlayer))
				{
					((EnemyAI)this).SwitchToBehaviourState(0);
				}
				break;
			case 2:
				((EnemyAI)this).KillEnemyServerRpc(false);
				break;
			}
		}

		[ClientRpc]
		private void TurnOnPlayerTargetClientRpc(Quaternion value)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_0089: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3794112327u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe(ref value);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3794112327u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
					((Component)this).transform.rotation = value;
				}
			}
		}

		private void AllClientOnSwitchBehaviorState()
		{
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
				base.agent.speed = walkSpeed;
				base.creatureAnimator.SetBool(Attack, false);
				((Behaviour)angryLight).enabled = false;
				AttackAudioSource.Stop();
				break;
			case 1:
				base.agent.speed = 0f;
				base.creatureAnimator.SetBool(Attack, true);
				AttackAudioSource.Play();
				((Behaviour)angryLight).enabled = true;
				break;
			case 2:
				base.agent.speed = 0f;
				base.creatureAnimator.SetBool(Attack, false);
				base.creatureAnimator.SetBool(Death, true);
				((Behaviour)angryLight).enabled = false;
				base.creatureVoice.PlayOneShot(deathSound);
				AttackAudioSource.Stop();
				break;
			}
		}

		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)
			{
				base.enemyHP -= force;
				if (base.enemyHP <= 0)
				{
					((EnemyAI)this).SwitchToBehaviourServerRpc(2);
				}
			}
		}

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

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(3794112327u, new RpcReceiveHandler(__rpc_handler_3794112327), "TurnOnPlayerTargetClientRpc");
			((EnemyAI)this).__initializeRpcs();
		}

		private static void __rpc_handler_3794112327(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				Quaternion value = default(Quaternion);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref value);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((ScaryLampEnemyAI)(object)target).TurnOnPlayerTargetClientRpc(value);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "ScaryLampEnemyAI";
		}
	}
	public class StreetLampEnemyAI : EnemyAI
	{
		private static readonly int Attack = Animator.StringToHash("Attack");

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

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

		public List<AudioClip> walkSounds;

		public AudioClip explodeSound;

		public ParticleSystem explosionParticles;

		private readonly float walkSpeed = 3.5f;

		private readonly float runSpeed = 8f;

		private float aiInterval = 0.2f;

		private int lastBehaviorState;

		private readonly float walkSoundDelayRun = 0.5f;

		private readonly float walkSoundDelayWalk = 0.9f;

		private float walkSoundTimer;

		private float visionWidth = 100f;

		private float runAfterPlayerTimer;

		private float runAfterPlayerDelay = 3f;

		private float explosionRange = 8f;

		private float jumpRange = 6f;

		public override void Start()
		{
			((EnemyAI)this).Start();
			base.agent.speed = walkSpeed;
			base.agent.acceleration = 255f;
			base.agent.angularSpeed = 900f;
		}

		public override void Update()
		{
			if (!base.isEnemyDead)
			{
				((EnemyAI)this).Update();
				runAfterPlayerTimer -= Time.deltaTime;
				if (lastBehaviorState != base.currentBehaviourStateIndex)
				{
					Debug.Log((object)$"New behavior state : {base.currentBehaviourStateIndex} last : {lastBehaviorState}");
					lastBehaviorState = base.currentBehaviourStateIndex;
					AllClientOnSwitchBehaviorState();
				}
				walkSoundTimer -= Time.deltaTime;
				if (walkSoundTimer <= 0f && base.currentBehaviourStateIndex != 2)
				{
					AudioClip val = walkSounds[Random.Range(0, walkSounds.Count)];
					base.creatureSFX.PlayOneShot(val);
					walkSoundTimer = ((base.currentBehaviourStateIndex == 1) ? walkSoundDelayRun : walkSoundDelayWalk);
				}
				if (((NetworkBehaviour)this).IsServer && aiInterval <= 0f)
				{
					aiInterval = base.AIIntervalTime;
					((EnemyAI)this).DoAIInterval();
				}
			}
		}

		public override void DoAIInterval()
		{
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_008a: 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_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).DoAIInterval();
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
				((EnemyAI)this).TargetClosestPlayer(1.5f, true, visionWidth, false, false, true);
				if ((Object)(object)base.targetPlayer == (Object)null)
				{
					if (base.currentSearch.inProgress)
					{
						break;
					}
					AISearchRoutine val = new AISearchRoutine();
					val.searchWidth = 100f;
					val.searchPrecision = 8f;
					((EnemyAI)this).StartSearch(((EnemyAI)this).ChooseFarthestNodeFromPosition(((Component)this).transform.position, true, 0, false, 50, -1).position, val);
				}
				if (Object.op_Implicit((Object)(object)base.targetPlayer) && ((EnemyAI)this).PlayerIsTargetable(base.targetPlayer, false, false, true))
				{
					runAfterPlayerTimer = runAfterPlayerDelay;
					((EnemyAI)this).SwitchToBehaviourState(1);
				}
				break;
			case 1:
				if (Object.op_Implicit((Object)(object)base.targetPlayer))
				{
					((EnemyAI)this).SetMovingTowardsTargetPlayer(base.targetPlayer);
					if (Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) <= jumpRange)
					{
						((Component)this).transform.LookAt(((Component)base.targetPlayer.gameplayCamera).transform);
						((Component)this).transform.eulerAngles = new Vector3(0f, ((Component)this).transform.eulerAngles.y, 0f);
						TurnOnPlayerTargetClientRpc(((Component)this).transform.rotation);
						((EnemyAI)this).SwitchToBehaviourState(2);
					}
				}
				if (runAfterPlayerTimer <= 0f)
				{
					((EnemyAI)this).TargetClosestPlayer(1.5f, true, visionWidth, false, false, true);
					if (Object.op_Implicit((Object)(object)base.targetPlayer))
					{
						runAfterPlayerTimer = runAfterPlayerDelay / 2f;
					}
					else
					{
						((EnemyAI)this).SwitchToBehaviourState(0);
					}
				}
				break;
			case 2:
				((EnemyAI)this).KillEnemyServerRpc(false);
				break;
			}
		}

		[ClientRpc]
		private void TurnOnPlayerTargetClientRpc(Quaternion value)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_0089: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(818274119u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe(ref value);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 818274119u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
					((Component)this).transform.rotation = value;
				}
			}
		}

		public void Explode()
		{
			//IL_002e: 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_0065: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			base.creatureVoice.PlayOneShot(explodeSound);
			explosionParticles.Play();
			float num = Vector3.Distance(((Component)GameNetworkManager.Instance.localPlayerController).transform.position, ((Component)this).transform.position);
			if (num <= explosionRange)
			{
				GameNetworkManager.Instance.localPlayerController.KillPlayer(((Component)this).transform.forward, true, (CauseOfDeath)0, 0, default(Vector3), false);
			}
			else if ((double)num <= (double)explosionRange * 1.5)
			{
				GameNetworkManager.Instance.localPlayerController.DamagePlayer(25, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
			}
			if (!((NetworkBehaviour)this).IsServer)
			{
				return;
			}
			List<EnemyAI> list = Object.FindObjectsOfType<EnemyAI>().ToList();
			list.ForEach(delegate(EnemyAI enemy)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				if (Vector3.Distance(((Component)enemy).transform.position, ((Component)this).transform.position) <= explosionRange)
				{
					enemy.HitEnemyServerRpc(5, 0, false, -1);
				}
			});
		}

		private void AllClientOnSwitchBehaviorState()
		{
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
				base.agent.speed = walkSpeed;
				base.creatureAnimator.SetBool(Run, false);
				break;
			case 1:
				base.agent.speed = runSpeed;
				base.creatureAnimator.SetBool(Run, true);
				break;
			case 2:
				base.agent.speed = 0f;
				base.creatureAnimator.SetBool(Attack, false);
				base.creatureAnimator.SetBool(Jump, true);
				break;
			}
		}

		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)
			{
				base.enemyHP -= force;
				if (base.enemyHP <= 0)
				{
					((EnemyAI)this).SwitchToBehaviourServerRpc(2);
				}
			}
		}

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

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(818274119u, new RpcReceiveHandler(__rpc_handler_818274119), "TurnOnPlayerTargetClientRpc");
			((EnemyAI)this).__initializeRpcs();
		}

		private static void __rpc_handler_818274119(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				Quaternion value = default(Quaternion);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref value);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((StreetLampEnemyAI)(object)target).TurnOnPlayerTargetClientRpc(value);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "StreetLampEnemyAI";
		}
	}
	public class StreetLampExplosion : MonoBehaviour
	{
		public StreetLampEnemyAI creature;

		public void Explode()
		{
			creature.Explode();
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace ScaryLamps.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}