Decompiled source of StrangerThingsMod v0.0.32

StrangerThingsMod/StrangerThingsMod.dll

Decompiled 9 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
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("StrangerThingsMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A mod that adds stuff from Stranger Things, such as a new Demogoron enemy")]
[assembly: AssemblyFileVersion("0.0.31.0")]
[assembly: AssemblyInformationalVersion("0.0.31+ae62236394be7f66cf555222e16379a9b4ffe3ed")]
[assembly: AssemblyProduct("StrangerThingsMod")]
[assembly: AssemblyTitle("StrangerThingsMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.31.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 StrangerThingsMod
{
	public static class CarriedPlayerManager
	{
		public static PlayerControllerB CarriedPlayer { get; private set; }

		public static bool IsPlayerCarried(PlayerControllerB carriedPlayer)
		{
			return (Object)(object)CarriedPlayer == (Object)(object)carriedPlayer;
		}

		public static void SetCarriedPlayer(PlayerControllerB carriedPlayer)
		{
			CarriedPlayer = carriedPlayer;
		}

		public static void ClearCarriedPlayer()
		{
			CarriedPlayer = null;
		}
	}
	public class Config
	{
		public static ConfigEntry<int> DemogorgonSpawnWeight;

		public static ConfigEntry<bool> EnableFlickeringLights;

		public static ConfigEntry<string> version;

		public static void Load()
		{
			DemogorgonSpawnWeight = Plugin.config.Bind<int>("Enemies", "DemogorgonSpawnWeight", 10, "The weight of the Demogorgon spawning in the level. Higher values mean it will spawn more often.");
			EnableFlickeringLights = Plugin.config.Bind<bool>("General", "FlickeringLights", true, "Enable or disable flickering lights and sound when the Demogorgon is nearby.");
			version = Plugin.config.Bind<string>("Misc", "Version", "1.0.1", "Version of the mod config.");
		}
	}
	public class Content
	{
		public class CustomEnemy
		{
			public string name;

			public string enemyPath;

			public int rarity;

			public LevelTypes levelFlags;

			public SpawnType spawnType;

			public string infoKeyword;

			public string infoNode;

			public bool enabled = true;

			public CustomEnemy(string name, string enemyPath, int rarity, LevelTypes levelFlags, SpawnType spawnType, string infoKeyword, string infoNode)
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: 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)
				this.name = name;
				this.enemyPath = enemyPath;
				this.rarity = rarity;
				this.levelFlags = levelFlags;
				this.spawnType = spawnType;
				this.infoKeyword = infoKeyword;
				this.infoNode = infoNode;
			}

			public static CustomEnemy Add(string name, string enemyPath, int rarity, LevelTypes levelFlags, SpawnType spawnType, string infoKeyword, string infoNode, bool enabled = true)
			{
				//IL_0004: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				CustomEnemy customEnemy = new CustomEnemy(name, enemyPath, rarity, levelFlags, spawnType, infoKeyword, infoNode);
				customEnemy.enabled = enabled;
				return customEnemy;
			}
		}

		public static List<CustomEnemy> customEnemies;

		public static AssetBundle MainAssets;

		public static Dictionary<string, GameObject> Prefabs = new Dictionary<string, GameObject>();

		public static void TryLoadAssets()
		{
			if ((Object)(object)MainAssets == (Object)null)
			{
				MainAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "demogorgonenemy"));
				Plugin.logger.LogInfo((object)"Loaded asset bundle");
			}
		}

		public static AudioClip LoadAudioClip(string clipName)
		{
			if ((Object)(object)MainAssets == (Object)null)
			{
				Plugin.logger.LogWarning((object)"MainAssets is null, cannot load audio clip.");
				return null;
			}
			AudioClip val = MainAssets.LoadAsset<AudioClip>(clipName);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.logger.LogWarning((object)("Failed to load audio clip: " + clipName));
			}
			return val;
		}

		public static void Load()
		{
			//IL_00dc: 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)
			TryLoadAssets();
			customEnemies = new List<CustomEnemy> { CustomEnemy.Add("Demogorgon", "Assets/Demogorgon/Demogorgon.asset", Config.DemogorgonSpawnWeight.Value, (LevelTypes)(-1), (SpawnType)0, null, "DemogorgonTN") };
			foreach (CustomEnemy customEnemy in customEnemies)
			{
				if (customEnemy.enabled)
				{
					EnemyType val = MainAssets.LoadAsset<EnemyType>(customEnemy.enemyPath);
					TerminalNode val2 = MainAssets.LoadAsset<TerminalNode>(customEnemy.infoNode);
					TerminalKeyword val3 = null;
					if (customEnemy.infoKeyword != null)
					{
						val3 = MainAssets.LoadAsset<TerminalKeyword>(customEnemy.infoKeyword);
					}
					NetworkPrefabs.RegisterNetworkPrefab(val.enemyPrefab);
					Prefabs.Add(customEnemy.name, val.enemyPrefab);
					Enemies.RegisterEnemy(val, customEnemy.rarity, customEnemy.levelFlags, customEnemy.spawnType, val2, val3);
				}
			}
			Plugin.logger.LogInfo((object)"Loaded content");
		}
	}
	public class DemogorgonAI : EnemyAI
	{
		public enum DemogorgonState
		{
			Wandering,
			Chasing,
			CarryingPlayer,
			Fleeing
		}

		private Animator anim;

		private AudioSource audioSource;

		public AudioClip[] sounds;

		public AudioClip hitDemogorgonSFX;

		private AudioClip demogorgonSpawnSound;

		public AudioClip[] screamSounds;

		private float soundTimer;

		public AISearchRoutine roamMap;

		private PlayerControllerB closestSeenPlayer;

		private PlayerControllerB lastSeenPlayer;

		private bool playerIsInLOS;

		private bool isSwitchingToWandering = false;

		private bool isCarryingPlayer = false;

		private PlayerControllerB carriedPlayer = null;

		public Transform carryPoint;

		private Coroutine damageCoroutine;

		private float pickupCooldownTimer = 0f;

		private bool isFleeing = false;

		private float fleeCooldownTimer = 0f;

		private ManualLogSource myLogSource;

		private bool hasStartedChasing = false;

		public AudioClip[] stepSounds;

		private Vector3 lastStepPosition;

		private float stepDistance = 2f;

		private Random enemyRandom;

		public override void Start()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Start();
			myLogSource = Logger.CreateLogSource("Demogorgon AI");
			myLogSource.LogInfo((object)"Demogorgon Spawned");
			anim = ((Component)this).GetComponent<Animator>();
			audioSource = ((Component)this).GetComponent<AudioSource>();
			lastStepPosition = ((Component)this).transform.position;
			stepSounds = (AudioClip[])(object)new AudioClip[5];
			for (int i = 0; i < 5; i++)
			{
				stepSounds[i] = Content.LoadAudioClip("Footstep" + (i + 1));
			}
			demogorgonSpawnSound = Content.LoadAudioClip("DemogorgonSpawn");
			audioSource.PlayOneShot(demogorgonSpawnSound);
			if (Config.EnableFlickeringLights.Value)
			{
				LightTriggerScript[] array = Object.FindObjectsOfType<LightTriggerScript>();
				LightTriggerScript[] array2 = array;
				foreach (LightTriggerScript lightTriggerScript in array2)
				{
					lightTriggerScript.AddDemogorgon(((Component)this).gameObject);
				}
			}
			enemyRandom = new Random(StartOfRound.Instance.randomMapSeed + base.thisEnemyIndex);
			base.currentBehaviourStateIndex = 0;
			InitializeDemogorgon();
		}

		public void InitializeDemogorgon()
		{
			base.enemyHP = 6;
			soundTimer = 0f;
			isCarryingPlayer = false;
			carriedPlayer = null;
			fleeCooldownTimer = 0f;
			pickupCooldownTimer = 0f;
			base.agent.speed = 4.5f;
			hasStartedChasing = false;
			isFleeing = false;
			isSwitchingToWandering = false;
			closestSeenPlayer = null;
			lastSeenPlayer = null;
			playerIsInLOS = false;
			CarriedPlayerManager.ClearCarriedPlayer();
			base.currentBehaviourStateIndex = 0;
			anim.SetBool("IsWalking", false);
			anim.SetBool("IsRunning", false);
			anim.SetBool("IsCloseRunning", false);
			anim.SetBool("IsCarrying", false);
		}

		public override void Update()
		{
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Update();
			if (!base.isEnemyDead && !StartOfRound.Instance.allPlayersDead)
			{
				soundTimer += Time.deltaTime;
				if (soundTimer >= 5f)
				{
					PlayRandomSound();
					soundTimer = 0f;
				}
				if (pickupCooldownTimer > 0f)
				{
					pickupCooldownTimer -= Time.deltaTime;
				}
				if (fleeCooldownTimer > 0f)
				{
					fleeCooldownTimer -= Time.deltaTime;
				}
				if (isCarryingPlayer && (Object)(object)carriedPlayer != (Object)null)
				{
					RunAway();
					UpdateCarriedPlayerPositionServerRpc(carryPoint.position, carryPoint.rotation);
					carriedPlayer.ResetFallGravity();
				}
				if (Vector3.Distance(((Component)this).transform.position, lastStepPosition) > stepDistance)
				{
					OnStep();
					lastStepPosition = ((Component)this).transform.position;
				}
				if (base.stunNormalizedTimer > 0f)
				{
					base.agent.speed = 0f;
					ReleasePlayerServerRpc();
				}
			}
		}

		private void OnStep()
		{
			AudioClip val = stepSounds[enemyRandom.Next(0, stepSounds.Length)];
			audioSource.PlayOneShot(val, 0.4f);
		}

		public override void DoAIInterval()
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).DoAIInterval();
			if (base.isEnemyDead || StartOfRound.Instance.allPlayersDead)
			{
				return;
			}
			PlayerControllerB val = null;
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
				base.agent.speed = 4.5f;
				DoAnimationsServerRPC(isWalking: true, isRunning: false, isCloseRunning: false, isCarrying: false);
				if (!roamMap.inProgress && !isCarryingPlayer && !base.isEnemyDead && !isFleeing)
				{
					((EnemyAI)this).StartSearch(((Component)this).transform.position, roamMap);
					myLogSource.LogInfo((object)"Starting search...");
				}
				val = ((EnemyAI)this).CheckLineOfSightForPlayer(140f, 25, 6);
				playerIsInLOS = Object.op_Implicit((Object)(object)val);
				if (playerIsInLOS && !val.isPlayerDead && !isCarryingPlayer && !base.isEnemyDead && (Object)(object)CarriedPlayerManager.CarriedPlayer != (Object)(object)val)
				{
					((EnemyAI)this).ChangeOwnershipOfEnemy(val.actualClientId);
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
				}
				break;
			case 1:
				if (roamMap.inProgress)
				{
					((EnemyAI)this).StopSearch(roamMap, true);
				}
				closestSeenPlayer = ((EnemyAI)this).CheckLineOfSightForClosestPlayer(140f, 25, 6, 0f);
				if ((Object)(object)closestSeenPlayer != (Object)null)
				{
					lastSeenPlayer = closestSeenPlayer;
				}
				playerIsInLOS = Object.op_Implicit((Object)(object)closestSeenPlayer);
				if (playerIsInLOS && !closestSeenPlayer.isPlayerDead && !isCarryingPlayer && !base.isEnemyDead && (Object)(object)CarriedPlayerManager.CarriedPlayer != (Object)(object)closestSeenPlayer)
				{
					base.agent.speed = 7f;
					if (!hasStartedChasing)
					{
						int num = enemyRandom.Next(0, screamSounds.Length);
						audioSource.PlayOneShot(screamSounds[num]);
						WalkieTalkie.TransmitOneShotAudio(audioSource, screamSounds[num], 1f);
						hasStartedChasing = true;
					}
					if ((Object)(object)closestSeenPlayer != (Object)null)
					{
						((EnemyAI)this).SetDestinationToPosition(((Component)closestSeenPlayer).transform.position, false);
					}
					myLogSource.LogInfo((object)("Chasing player! " + ((Object)closestSeenPlayer).name));
					DoAnimationsServerRPC(isWalking: false, isRunning: false, isCloseRunning: true, isCarrying: false);
					isSwitchingToWandering = false;
				}
				else
				{
					if ((Object)(object)lastSeenPlayer != (Object)null)
					{
						((EnemyAI)this).SetDestinationToPosition(((Component)lastSeenPlayer).transform.position, false);
					}
					if (!isSwitchingToWandering)
					{
						myLogSource.LogInfo((object)"Lost sight of player, loosing interest...");
						((MonoBehaviour)this).StartCoroutine(SwitchToWanderingIfLostPlayer(5f));
						isSwitchingToWandering = true;
					}
				}
				break;
			case 2:
				base.agent.speed = 5f;
				if ((Object)(object)carriedPlayer == (Object)null || carriedPlayer.isPlayerDead || base.isEnemyDead)
				{
					myLogSource.LogInfo((object)"Player is dead or enemy is dead or carriedPlayer is null, releasing player...");
					ReleasePlayerServerRpc();
				}
				break;
			case 3:
				if (fleeCooldownTimer <= 0f)
				{
					isFleeing = false;
				}
				if (isFleeing)
				{
					RunAway();
				}
				else
				{
					((EnemyAI)this).SwitchToBehaviourClientRpc(0);
				}
				break;
			default:
				myLogSource.LogWarning((object)"Demogorgon state not found!");
				break;
			}
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			((EnemyAI)this).OnCollideWithPlayer(other);
			if (!base.isEnemyDead && !isCarryingPlayer)
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if (pickupCooldownTimer <= 0f && !isCarryingPlayer && !component.isPlayerDead && (Object)(object)CarriedPlayerManager.CarriedPlayer != (Object)(object)component)
				{
					myLogSource.LogInfo((object)("Picking up player! " + ((Object)component).name));
					GrabPlayerServerRpc(component.playerClientId);
					((EnemyAI)this).SwitchToBehaviourClientRpc(2);
				}
			}
		}

		private IEnumerator SwitchToWanderingIfLostPlayer(float delay)
		{
			yield return (object)new WaitForSeconds(delay);
			if (isSwitchingToWandering)
			{
				((EnemyAI)this).SwitchToBehaviourClientRpc(0);
				myLogSource.LogInfo((object)"Switching to wandering...");
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void DoAnimationsServerRPC(bool isWalking, bool isRunning, bool isCloseRunning, bool isCarrying)
		{
			SetAnimationState(isWalking, isRunning, isCloseRunning, isCarrying);
			DoAnimationsClientRPC(isWalking, isRunning, isCloseRunning, isCarrying);
		}

		[ClientRpc]
		public void DoAnimationsClientRPC(bool isWalking, bool isRunning, bool isCloseRunning, bool isCarrying)
		{
			SetAnimationState(isWalking, isRunning, isCloseRunning, isCarrying);
		}

		private void SetAnimationState(bool isWalking, bool isRunning, bool isCloseRunning, bool isCarrying)
		{
			anim.SetBool("IsWalking", isWalking);
			anim.SetBool("IsRunning", isRunning);
			anim.SetBool("IsCloseRunning", isCloseRunning);
			anim.SetBool("IsCarrying", isCarrying);
		}

		[ServerRpc(RequireOwnership = false)]
		public void GrabPlayerServerRpc(ulong playerId)
		{
			PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[playerId];
			carriedPlayer = val;
			GrabPlayerClientRpc(playerId);
		}

		[ClientRpc]
		public void GrabPlayerClientRpc(ulong playerId)
		{
			//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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[playerId];
			if ((Object)(object)val != (Object)null)
			{
				isCarryingPlayer = true;
				carriedPlayer = val;
				CarriedPlayerManager.SetCarriedPlayer(val);
				MovementActions movement = val.playerActions.Movement;
				((MovementActions)(ref movement)).Move.Disable();
				movement = val.playerActions.Movement;
				((MovementActions)(ref movement)).Jump.Disable();
				movement = val.playerActions.Movement;
				((MovementActions)(ref movement)).Sprint.Disable();
				movement = val.playerActions.Movement;
				((MovementActions)(ref movement)).Crouch.Disable();
				DoAnimationsServerRPC(isWalking: false, isRunning: false, isCloseRunning: false, isCarrying: true);
				damageCoroutine = ((MonoBehaviour)this).StartCoroutine(DamagePlayerOverTime());
				((Component)val).transform.position = carryPoint.position;
				((Component)val).transform.rotation = carryPoint.rotation;
				val.ResetFallGravity();
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void ReleasePlayerServerRpc()
		{
			ReleasePlayer();
			ReleasePlayerClientRpc();
		}

		[ClientRpc]
		public void ReleasePlayerClientRpc()
		{
			ReleasePlayer();
		}

		private void ReleasePlayer()
		{
			//IL_003d: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			if (isCarryingPlayer && (Object)(object)carriedPlayer != (Object)null)
			{
				((Component)carriedPlayer).transform.parent = null;
				MovementActions movement = carriedPlayer.playerActions.Movement;
				((MovementActions)(ref movement)).Move.Enable();
				movement = carriedPlayer.playerActions.Movement;
				((MovementActions)(ref movement)).Jump.Enable();
				movement = carriedPlayer.playerActions.Movement;
				((MovementActions)(ref movement)).Sprint.Enable();
				movement = carriedPlayer.playerActions.Movement;
				((MovementActions)(ref movement)).Crouch.Enable();
				carriedPlayer.takingFallDamage = true;
				DoAnimationsServerRPC(isWalking: true, isRunning: false, isCloseRunning: false, isCarrying: false);
				((MonoBehaviour)this).StopCoroutine(damageCoroutine);
				isCarryingPlayer = false;
				CarriedPlayerManager.ClearCarriedPlayer();
				pickupCooldownTimer = 5f;
				isFleeing = true;
				fleeCooldownTimer = 5f;
				carriedPlayer = null;
				((EnemyAI)this).SwitchToBehaviourClientRpc(3);
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void UpdateCarriedPlayerPositionServerRpc(Vector3 position, Quaternion rotation)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			((Component)carriedPlayer).transform.position = position;
			((Component)carriedPlayer).transform.rotation = rotation;
			UpdateCarriedPlayerPositionClientRpc(position, rotation);
		}

		[ClientRpc]
		public void UpdateCarriedPlayerPositionClientRpc(Vector3 position, Quaternion rotation)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			((Component)carriedPlayer).transform.position = position;
			((Component)carriedPlayer).transform.rotation = rotation;
		}

		private void RunAway()
		{
			//IL_004f: 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)
			if (!base.isEnemyDead && !base.agent.hasPath && !base.agent.pathPending && !(fleeCooldownTimer > 0f) && base.agent.isOnNavMesh)
			{
				Transform val = ((EnemyAI)this).ChooseFarthestNodeFromPosition(((Component)this).transform.position, true, 0, false);
				if ((Object)(object)val != (Object)null)
				{
					base.targetNode = val;
					((EnemyAI)this).SetDestinationToPosition(base.targetNode.position, false);
				}
			}
		}

		private IEnumerator DamagePlayerOverTime()
		{
			while (isCarryingPlayer)
			{
				yield return (object)new WaitForSeconds(1f);
				if ((Object)(object)carriedPlayer != (Object)null)
				{
					carriedPlayer.DamagePlayer(15, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
				}
			}
		}

		private void PlayRandomSound()
		{
			if (sounds.Length != 0)
			{
				AudioClip val = sounds[Random.Range(0, sounds.Length)];
				audioSource.PlayOneShot(val);
			}
		}

		public override void HitEnemy(int force = 1, PlayerControllerB playerWhoHit = null, bool playHitSFX = false)
		{
			((EnemyAI)this).HitEnemy(force, playerWhoHit, playHitSFX);
			if (!base.isEnemyDead)
			{
				base.creatureSFX.PlayOneShot(hitDemogorgonSFX, 1f);
				WalkieTalkie.TransmitOneShotAudio(base.creatureSFX, hitDemogorgonSFX, 1f);
				base.enemyHP -= force;
				if (isCarryingPlayer)
				{
					ReleasePlayerServerRpc();
				}
				if (((NetworkBehaviour)this).IsOwner && base.enemyHP <= 0 && !base.isEnemyDead)
				{
					((EnemyAI)this).KillEnemyOnOwnerClient(false);
				}
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class LightColliderSpawnerPatch
	{
		public static List<GameObject> eligibleLights = new List<GameObject>();

		[HarmonyPatch("FinishGeneratingLevel")]
		[HarmonyPostfix]
		public static void FinishGeneratingLevelPostfix(RoundManager __instance)
		{
			if (!Config.EnableFlickeringLights.Value)
			{
				return;
			}
			Plugin.logger.LogInfo((object)"Adding colliders to lights");
			eligibleLights.Clear();
			Light[] array = Object.FindObjectsOfType<Light>();
			Light[] array2 = array;
			foreach (Light val in array2)
			{
				Transform parent = ((Component)val).transform.parent;
				if ((Object)(object)parent != (Object)null && (((Object)parent).name.StartsWith("HangingLight") || ((Object)parent).name.StartsWith("MansionWallLamp") || ((Object)parent).name.StartsWith("Chandelier")))
				{
					eligibleLights.Add(((Component)val).gameObject);
					LightTriggerScript lightTriggerScript = ((Component)val).gameObject.AddComponent<LightTriggerScript>();
					lightTriggerScript.Init(val);
				}
			}
		}
	}
	public class LightTriggerScript : MonoBehaviour
	{
		private Light lightComponent;

		private AudioSource audioSource;

		private AudioClip[] lightFlickerSounds;

		private List<GameObject> demogorgons = new List<GameObject>();

		private bool isFlickering = false;

		private bool hasExited = true;

		public Vector3 spawnPosition = ((Component)Object.FindAnyObjectByType<PlayerControllerB>()).transform.position;

		public void Init(Light light)
		{
			lightComponent = light;
			audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
			audioSource.spatialBlend = 1f;
			lightFlickerSounds = (AudioClip[])(object)new AudioClip[4]
			{
				Content.LoadAudioClip("BreakerLever1"),
				Content.LoadAudioClip("BreakerLever2"),
				Content.LoadAudioClip("BreakerLever3"),
				Content.LoadAudioClip("FlashlightFlicker")
			};
		}

		public void AddDemogorgon(GameObject demogorgon)
		{
			demogorgons.Add(demogorgon);
			Debug.Log((object)("Demogorgon added: " + (object)demogorgon));
		}

		private void Update()
		{
			//IL_0030: 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)
			foreach (GameObject demogorgon in demogorgons)
			{
				if ((Object)(object)demogorgon == (Object)null)
				{
					continue;
				}
				float num = Vector3.Distance(((Component)this).transform.position, demogorgon.transform.position);
				if (num < 5f)
				{
					if (!isFlickering && hasExited)
					{
						Debug.Log((object)"Starting FlickerLight coroutine");
						((MonoBehaviour)this).StartCoroutine(FlickerLight());
						break;
					}
				}
				else
				{
					hasExited = true;
				}
			}
		}

		private IEnumerator FlickerLight()
		{
			Debug.Log((object)"In FlickerLight coroutine");
			isFlickering = true;
			hasExited = false;
			int flickerCount = Random.Range(1, 5);
			for (int i = 0; i < flickerCount; i++)
			{
				audioSource.PlayOneShot(lightFlickerSounds[Random.Range(0, lightFlickerSounds.Length)]);
				((Behaviour)lightComponent).enabled = !((Behaviour)lightComponent).enabled;
				yield return (object)new WaitForSeconds(Random.Range(0.08f, 0.3f));
			}
			((Behaviour)lightComponent).enabled = true;
			isFlickering = false;
		}
	}
	[HarmonyPatch]
	public class Patches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "StartGame")]
		public static void ResetAI()
		{
			DemogorgonAI demogorgonAI = Object.FindObjectOfType<DemogorgonAI>();
			if ((Object)(object)demogorgonAI != (Object)null)
			{
				demogorgonAI.InitializeDemogorgon();
			}
		}
	}
	[BepInPlugin("scoliosis.strangerthingsmod", "StrangerThingsMod", "0.0.31")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGUID = "scoliosis.strangerthingsmod";

		public const string ModName = "StrangerThingsMod";

		public const string ModVersion = "0.0.31";

		public static ManualLogSource logger;

		public static ConfigFile config;

		private void Awake()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			logger = ((BaseUnityPlugin)this).Logger;
			config = ((BaseUnityPlugin)this).Config;
			Config.Load();
			Content.Load();
			Harmony val = new Harmony("scoliosis.strangerthingsmod");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Stranger Things Mod");
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
	public class Utilities
	{
		public static void SpawnDemogorgon(Vector3 spawningPosition)
		{
			//IL_0017: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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)
			string text = "Demogorgon";
			if (Content.Prefabs.ContainsKey(text))
			{
				Quaternion identity = Quaternion.identity;
				Plugin.logger.LogInfo((object)("Spawning " + text + " at light"));
				GameObject val = Object.Instantiate<GameObject>(Content.Prefabs[text], spawningPosition, identity);
				val.GetComponent<NetworkObject>().Spawn(false);
			}
			else
			{
				Plugin.logger.LogWarning((object)("Prefab " + text + " not found!"));
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "StrangerThingsMod";

		public const string PLUGIN_NAME = "StrangerThingsMod";

		public const string PLUGIN_VERSION = "0.0.31";
	}
}