Decompiled source of EnhancedEnemies v1.0.0

EnhancedEnemies/EnhancedEnemies.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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 EnhancedEnemies.Patches;
using FMOD.Studio;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Receiver2;
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(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("EnhancedEnemies")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("The Threat has dreamt up some adjustments to our adversaries...")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+db522e1fedb172931679d4fe7d331ce4e849d035")]
[assembly: AssemblyProduct("EnhancedEnemies")]
[assembly: AssemblyTitle("EnhancedEnemies")]
[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 EnhancedEnemies
{
	[BepInPlugin("EnhancedEnemies", "EnhancedEnemies", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private static Harmony _harmony;

		private void Awake()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_0047: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_0089: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//IL_00c4: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_0106: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Expected O, but got Unknown
			//IL_0148: Expected O, but got Unknown
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Expected O, but got Unknown
			//IL_018a: Expected O, but got Unknown
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Expected O, but got Unknown
			//IL_01ba: Expected O, but got Unknown
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Expected O, but got Unknown
			//IL_01fc: Expected O, but got Unknown
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Expected O, but got Unknown
			//IL_023e: Expected O, but got Unknown
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Expected O, but got Unknown
			//IL_0280: Expected O, but got Unknown
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Expected O, but got Unknown
			//IL_02b0: Expected O, but got Unknown
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Expected O, but got Unknown
			//IL_02f2: Expected O, but got Unknown
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Expected O, but got Unknown
			//IL_0334: Expected O, but got Unknown
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Expected O, but got Unknown
			//IL_0364: Expected O, but got Unknown
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Expected O, but got Unknown
			//IL_03a6: Expected O, but got Unknown
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Expected O, but got Unknown
			//IL_03e8: Expected O, but got Unknown
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Expected O, but got Unknown
			//IL_042a: Expected O, but got Unknown
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Expected O, but got Unknown
			//IL_046c: Expected O, but got Unknown
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ae: Expected O, but got Unknown
			//IL_04ae: Expected O, but got Unknown
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Expected O, but got Unknown
			//IL_04de: Expected O, but got Unknown
			//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0516: Unknown result type (might be due to invalid IL or missing references)
			//IL_0520: Expected O, but got Unknown
			//IL_0520: Expected O, but got Unknown
			//IL_0535: Unknown result type (might be due to invalid IL or missing references)
			//IL_0558: Unknown result type (might be due to invalid IL or missing references)
			//IL_0562: Expected O, but got Unknown
			//IL_0562: Expected O, but got Unknown
			//IL_0577: Unknown result type (might be due to invalid IL or missing references)
			//IL_0588: Unknown result type (might be due to invalid IL or missing references)
			//IL_0592: Expected O, but got Unknown
			//IL_0592: Expected O, but got Unknown
			//IL_05a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d4: Expected O, but got Unknown
			//IL_05d4: Expected O, but got Unknown
			//IL_05e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_060c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0616: Expected O, but got Unknown
			//IL_0616: Expected O, but got Unknown
			//IL_062b: Unknown result type (might be due to invalid IL or missing references)
			//IL_064e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0658: Expected O, but got Unknown
			//IL_0658: Expected O, but got Unknown
			//IL_066d: Unknown result type (might be due to invalid IL or missing references)
			//IL_067e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0688: Expected O, but got Unknown
			//IL_0688: Expected O, but got Unknown
			//IL_069d: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ca: Expected O, but got Unknown
			//IL_06ca: Expected O, but got Unknown
			//IL_06df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0702: Unknown result type (might be due to invalid IL or missing references)
			//IL_070c: Expected O, but got Unknown
			//IL_070c: Expected O, but got Unknown
			//IL_0721: Unknown result type (might be due to invalid IL or missing references)
			//IL_0732: Unknown result type (might be due to invalid IL or missing references)
			//IL_073c: Expected O, but got Unknown
			//IL_073c: Expected O, but got Unknown
			//IL_0751: Unknown result type (might be due to invalid IL or missing references)
			//IL_0762: Unknown result type (might be due to invalid IL or missing references)
			//IL_076c: Expected O, but got Unknown
			//IL_076c: Expected O, but got Unknown
			//IL_0781: Unknown result type (might be due to invalid IL or missing references)
			//IL_0792: Unknown result type (might be due to invalid IL or missing references)
			//IL_079c: Expected O, but got Unknown
			//IL_079c: Expected O, but got Unknown
			//IL_07a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b0: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin EnhancedEnemies is loaded!");
			ShotgunTurrets.enabled = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Shotgun Turrets", "Enabled"), true, new ConfigDescription("Enables turrets to shoot multiple shotgun pellets instead of singular bullets", (AcceptableValueBase)null, Array.Empty<object>()));
			ShotgunTurrets.spread = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Shotgun Turrets", "Pellet spread"), 15f, new ConfigDescription("Angle, in degrees, of pellet spread cone", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 180f), Array.Empty<object>()));
			ShotgunTurrets.pellets = ((BaseUnityPlugin)this).Config.Bind<int>(new ConfigDefinition("Shotgun Turrets", "Pellet count"), 9, new ConfigDescription("Number of pellets per shot", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 300), Array.Empty<object>()));
			ShotgunTurrets.chance = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Shotgun Turrets", "Chance"), 0.5f, new ConfigDescription("Determines the proportion of turrets that are shotgun turrets. 0 means only regular turrets, 1 mean all shotgun turrets", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			ShotgunTurrets.fireDelayMod = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Shotgun Turrets", "Fire delay multiplier"), 4f, new ConfigDescription("Fire delay for shotgun turrets is multiplied by this factor. 2 means half fire rate, 0.5 means double", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			ShotgunTurrets.alertDelayMod = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Shotgun Turrets", "Reaction time multiplier"), 1.5f, new ConfigDescription("Delay for the first shot after being spotting for shotgun turrets is multiplied by this factor. 2 means double time to react, 0.5 means half", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			SleepyTurrets.overrideLevelStartAsleepChance = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Turret Sleep Control", "Override level start asleep chance"), false, new ConfigDescription("Enable override of levels' start asleep chance, using \"Start asleep chance\" instead", (AcceptableValueBase)null, Array.Empty<object>()));
			SleepyTurrets.startAsleepChance = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Turret Sleep Control", "Start asleep chance"), 0.25f, new ConfigDescription("Determines the proportion of turrets that start asleep. \"Override level start asleep chance\" must be enabled to work. 0 means no turrets start asleep, 1 mean all. Vanilla values range 0 - 0.3", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			SleepyTurrets.wakeupDelay = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Turret Sleep Control", "Wakeup delay"), 0.5f, new ConfigDescription("Time, in seconds, it takes before turrets can react after waking from sleep. Vanilla value is 1.5", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()));
			SleepyTurrets.firstWakeupExtraDelay = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Turret Sleep Control", "First wakeup extra delay"), 1f, new ConfigDescription("Additional time, in seconds, it takes before turrets can react after waking from sleep for the first time. Vanilla value is 0", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()));
			SleepyTurrets.enabled = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Sleepy Turrets", "Enabled"), true, new ConfigDescription("Enables turrets that start asleep to go back to sleep", (AcceptableValueBase)null, Array.Empty<object>()));
			SleepyTurrets.sleepTimeout = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Sleepy Turrets", "Sleep timeout"), 10f, new ConfigDescription("Time, in seconds, it takes for sleepy turrets to sleep after not spotting the player", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 60f), Array.Empty<object>()));
			SleepyTurrets.sleepyChance = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Sleepy Turrets", "Sleepy chance"), 0.5f, new ConfigDescription("Determines the proportion of turrets which start asleep that can go back to sleep. 0 mean no sleepy turrets, 1 mean all sleepy turrets", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			SleepyDrones.startAsleepEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Sleeping Drones", "Enabled"), true, new ConfigDescription("Enables drones to start asleep", (AcceptableValueBase)null, Array.Empty<object>()));
			SleepyDrones.startAsleepChance = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Sleeping Drones", "Start asleep chance"), 0.25f, new ConfigDescription("Determines the proportion of drones that start asleep. 0 means no drones start asleep, 1 mean all. Vanilla values for turrets range 0 - 0.3", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			SleepyDrones.wakeupDelay = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Sleeping Drones", "Wakeup delay"), 0.5f, new ConfigDescription("Time, in seconds, it takes before drones can react after waking from sleep. Vanilla value for turrets is 1.5", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()));
			SleepyDrones.firstWakeupExtraDelay = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Sleeping Drones", "First wakeup extra delay"), 1f, new ConfigDescription("Additional time, in seconds, it takes before drones can react after waking from sleep for the first time. Vanilla value for turrets is 0", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()));
			SleepyDrones.groundedChance = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Sleeping Drones", "Grounded sleep chance"), 0.5f, new ConfigDescription("Determines the proportions of sleeping drones that will attempt to land and turn off its rotors. 0 means all sleeping drones will still fly, 1 mean all will attempt to land", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			SleepyDrones.sleepVolumeMod = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Sleeping Drones", "Rotor sleep volume multiplier"), 0.5f, new ConfigDescription("The volume of the rotors of non-grounded sleeping drone are multiplied by this factor. 0.5 means half as loud, 2 means twice as loud", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			SleepyDrones.sleepyEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Sleepy Drones", "Enabled"), true, new ConfigDescription("Enables drones to that start asleep to go back to sleep. \"Sleeping Drones\" must be enabled to work", (AcceptableValueBase)null, Array.Empty<object>()));
			SleepyDrones.sleepTimeout = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Sleepy Drones", "Sleep timeout"), 10f, new ConfigDescription("Time, in seconds, it takes for sleepy drones to sleep after not spotting the player", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 60f), Array.Empty<object>()));
			SleepyDrones.sleepyChance = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Sleepy Drones", "Sleepy chance"), 0.5f, new ConfigDescription("Determines the proportion of drones which start asleep that can go back to sleep. 0 mean no sleepy drones, 1 mean all sleepy drones", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			SleepySecurityCameras.startAsleepEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Sleeping Security Cameras", "Enabled"), true, new ConfigDescription("Enables security cameras to start asleep", (AcceptableValueBase)null, Array.Empty<object>()));
			SleepySecurityCameras.startAsleepChance = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Sleeping Security Cameras", "Start asleep chance"), 0.25f, new ConfigDescription("Determines the proportion of security cameras that start asleep. 0 means no security cameras start asleep, 1 mean all. Vanilla values for turrets range 0 - 0.3", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			SleepySecurityCameras.wakeupDelay = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Sleeping Security Cameras", "Wakeup delay"), 0.5f, new ConfigDescription("Time, in seconds, it takes before security cameras can react after waking from sleep. Vanilla value for turrets is 1.5", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()));
			SleepySecurityCameras.firstWakeupExtraDelay = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Sleeping Security Cameras", "First wakeup extra delay"), 1f, new ConfigDescription("Additional time, in seconds, it takes before security cameras can react after waking from sleep for the first time. Vanilla value for turrets is 0", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()));
			SleepySecurityCameras.sleepyEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Sleepy Security Cameras", "Enabled"), true, new ConfigDescription("Enables security cameras to that start asleep to go back to sleep. \"Sleeping Security Cameras\" must be enabled to work", (AcceptableValueBase)null, Array.Empty<object>()));
			SleepySecurityCameras.sleepTimeout = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Sleepy Security Cameras", "Sleep timeout"), 10f, new ConfigDescription("Time, in seconds, it takes for sleepy security cameras to sleep after not spotting the player", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 60f), Array.Empty<object>()));
			SleepySecurityCameras.sleepyChance = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Sleepy Security Cameras", "Sleepy chance"), 0.5f, new ConfigDescription("Determines the proportion of security cameras which start asleep that can go back to sleep. 0 mean no sleepy security cameras, 1 mean all sleepy security cameras", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			SecurityCameraLinkedEnemies.turretsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Security Camera Link", "Turrets enabled"), true, new ConfigDescription("Enables turrets to activate through security cameras even if its camera is destroyed", (AcceptableValueBase)null, Array.Empty<object>()));
			SecurityCameraLinkedEnemies.dronesEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Security Camera Link", "Drones enabled"), true, new ConfigDescription("Enables drones to activate through security cameras even if its camera is destroyed", (AcceptableValueBase)null, Array.Empty<object>()));
			SecurityCameraLinkedEnemies.camerasEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Security Camera Link", "Cameras enabled"), true, new ConfigDescription("Enables security cameras to activate through other security cameras (they still need their own camera though)", (AcceptableValueBase)null, Array.Empty<object>()));
			_harmony = new Harmony("EnhancedEnemies");
			_harmony.PatchAll(typeof(ShotgunTurrets));
			_harmony.PatchAll(typeof(SleepyTurrets));
			_harmony.PatchAll(typeof(SleepyDrones));
			_harmony.PatchAll(typeof(SleepySecurityCameras));
			_harmony.PatchAll(typeof(SecurityCameraLinkedEnemies));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "EnhancedEnemies";

		public const string PLUGIN_NAME = "EnhancedEnemies";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace EnhancedEnemies.Patches
{
	[HarmonyPatch]
	internal static class MyopicTurrets
	{
		private static float spread = 0.05f;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(BulletTrajectoryCluster), "Evaluate")]
		private static bool InaccurateFire(ref bool __result, Ray ray, CartridgeSpec spec, float player_hit_multiplier, int num_trajectories, out BulletTrajectory best_trajectory)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			BulletTrajectory[] array = (BulletTrajectory[])(object)new BulletTrajectory[num_trajectories];
			for (int i = 0; i < num_trajectories; i++)
			{
				Quaternion val = Quaternion.Lerp(Quaternion.identity, Random.rotationUniform, spread + 0.001f * (float)i);
				array[i] = BulletTrajectoryManager.PlanTrajectory(((Ray)(ref ray)).origin, spec, val * ((Ray)(ref ray)).direction, true);
			}
			float[] array2 = new float[num_trajectories];
			float num = float.MinValue;
			best_trajectory = null;
			for (int j = 0; j < num_trajectories; j++)
			{
				array2[j] = BulletTrajectoryCluster.EvaluateTrajectory(array[j], player_hit_multiplier);
				if (array2[j] > num)
				{
					num = array2[j];
					best_trajectory = array[j];
				}
			}
			__result = num > 0f;
			return false;
		}
	}
	[HarmonyPatch]
	internal static class ShotgunTurrets
	{
		internal static ConfigEntry<bool> enabled;

		internal static ConfigEntry<float> spread;

		internal static ConfigEntry<int> pellets;

		internal static ConfigEntry<float> fireDelayMod;

		internal static ConfigEntry<float> alertDelayMod;

		internal static ConfigEntry<float> chance;

		public static CartridgeSpec _00Pellet = Init00Pellet();

		private static CartridgeSpec Init00Pellet()
		{
			//IL_0003: 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)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			CartridgeSpec val = default(CartridgeSpec);
			val.gravity = true;
			val.extra_mass = 1.63f;
			val.mass = 3.54f;
			val.speed = 396f;
			val.diameter = 0.00838f;
			val.density = 11340f;
			CartridgeSpec val2 = val;
			float num = val2.diameter * 0.5f;
			float num2 = val2.mass / 1000f / val2.density;
			val2.cylinder_length = num2 / ((float)Math.PI * num * num);
			return val2;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TurretScript), "Start")]
		private static void TurretSetup(TurretScript __instance, ref CartridgeSpec ___cartridge_spec)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (Random.value < chance.Value)
			{
				___cartridge_spec = _00Pellet;
				__instance.fire_interval *= fireDelayMod.Value;
				__instance.blind_fire_interval *= fireDelayMod.Value;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(TurretScript), "UpdateCameraAlive")]
		private static void AlertDelayPre(ref AIState ___ai_state, out AIState __state)
		{
			__state = ___ai_state;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TurretScript), "UpdateCameraAlive")]
		private static void AlertDelayPost(TurretScript __instance, ref float ___alert_delay, AIState __state)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			if (((RobotScript)__instance).CanSeePlayer() && (int)__state == 0)
			{
				___alert_delay *= alertDelayMod.Value;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(BulletTrajectoryManager), "ExecuteTrajectory")]
		private static bool TurretShotgunShot(BulletTrajectory trajectory)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Invalid comparison between Unknown and I4
			//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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Invalid comparison between Unknown and I4
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			if (enabled.Value && ((object)(CartridgeSpec)(ref trajectory.cartridge_spec)).Equals((object?)_00Pellet) && ((int)trajectory.bullet_source_entity_type == 1 || (int)trajectory.bullet_source_entity_type == 13))
			{
				Vector3 start_pos = trajectory.movement_events[0].start_pos;
				Vector3 val = trajectory.movement_events[0].end_pos - start_pos;
				for (int i = 0; i < pellets.Value; i++)
				{
					Quaternion val2 = Quaternion.Lerp(Quaternion.identity, Random.rotationUniform, spread.Value / 2f / 180f);
					BulletTrajectory val3 = BulletTrajectoryManager.PlanTrajectory(start_pos, _00Pellet, val2 * val, true);
					val3.draw_path = trajectory.draw_path;
					val3.bullet_source = trajectory.bullet_source;
					val3.bullet_source_entity_type = trajectory.bullet_source_entity_type;
					VanillaExecuteTrajectory(val3);
				}
				return false;
			}
			return true;
		}

		private static void VanillaExecuteTrajectory(BulletTrajectory trajectory)
		{
			ReceiverEvents.TriggerEvent((ReceiverEventTypeBulletTrajectory)0, trajectory);
			BulletTrajectoryManager.active_trajectories.Add(trajectory);
		}
	}
	[HarmonyPatch]
	internal static class SleepyTurrets
	{
		private struct OverrideWakeupState
		{
			public AIState ai_state;

			public float standby_wakeup_delay;
		}

		[CompilerGenerated]
		private sealed class <DelayStartAsleep>d__12 : IEnumerator<WaitForSeconds>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private WaitForSeconds <>2__current;

			public TurretScript turret;

			WaitForSeconds IEnumerator<WaitForSeconds>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DelayStartAsleep>d__12(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					state_access.Invoke(turret) = (AIState)5;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static Dictionary<TurretScript, float> sleepTimers = new Dictionary<TurretScript, float>();

		internal static FieldRef<TurretScript, AIState> state_access = AccessTools.FieldRefAccess<TurretScript, AIState>("ai_state");

		internal static ConfigEntry<bool> enabled;

		internal static ConfigEntry<bool> overrideLevelStartAsleepChance;

		internal static ConfigEntry<float> startAsleepChance;

		internal static ConfigEntry<float> sleepyChance;

		internal static ConfigEntry<float> sleepTimeout;

		internal static ConfigEntry<float> wakeupDelay;

		internal static ConfigEntry<float> firstWakeupExtraDelay;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TurretScript), "Update")]
		private static void SleepTimer(TurretScript __instance, ref AIState ___ai_state)
		{
			if (enabled.Value && sleepTimers.ContainsKey(__instance))
			{
				if ((int)___ai_state == 3)
				{
					sleepTimers[__instance] = sleepTimeout.Value;
				}
				else if ((int)___ai_state == 0 && (sleepTimers[__instance] -= Time.deltaTime) <= 0f)
				{
					___ai_state = (AIState)5;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TurretScript), "OnDestroy")]
		private static void Deregister(TurretScript __instance)
		{
			sleepTimers.Remove(__instance);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(TurretScript), "Start")]
		private static void TurretSetup(TurretScript __instance, ref float ___standby_wakeup_delay, ref AIState ___ai_state)
		{
			if (((RobotScript)__instance).kds.identifier == "")
			{
				((RobotScript)__instance).kds.identifier = Random.Range(int.MinValue, int.MaxValue).ToString();
			}
			if (!int.TryParse(((RobotScript)__instance).kds.identifier, out var result))
			{
				result = Random.Range(int.MinValue, int.MaxValue);
			}
			Random random = new Random(result);
			double num = random.NextDouble();
			if (overrideLevelStartAsleepChance.Value)
			{
				((RobotScript)__instance).start_in_standby_mode = num < (double)startAsleepChance.Value;
			}
			if (!((RobotScript)__instance).start_in_standby_mode)
			{
				return;
			}
			___standby_wakeup_delay = firstWakeupExtraDelay.Value;
			if (__instance.is_ceiling_mounted)
			{
				___ai_state = (AIState)0;
				((MonoBehaviour)__instance).StartCoroutine((IEnumerator)DelayStartAsleep(__instance));
			}
			num = random.NextDouble();
			if (num < (double)sleepyChance.Value)
			{
				sleepTimers[__instance] = sleepTimeout.Value;
				if (sleepTimers.Count >= 50)
				{
					Plugin.Logger.LogWarning((object)$"turret register abnormally large ({sleepTimers.Count}); you have an unusual number of turrets or they are not being deregistered");
				}
			}
		}

		[IteratorStateMachine(typeof(<DelayStartAsleep>d__12))]
		private static IEnumerator<WaitForSeconds> DelayStartAsleep(TurretScript turret)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DelayStartAsleep>d__12(0)
			{
				turret = turret
			};
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(TurretScript), "UpdateSensor")]
		private static void OverrideWakeupDelayPre(AIState ___ai_state, ref float ___standby_wakeup_delay, out OverrideWakeupState __state)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			__state = new OverrideWakeupState
			{
				ai_state = ___ai_state,
				standby_wakeup_delay = ___standby_wakeup_delay
			};
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TurretScript), "UpdateSensor")]
		private static void OverrideWakeupDelayPost(TurretScript __instance, ref float ___standby_wakeup_delay, OverrideWakeupState __state)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			if ((int)__state.ai_state == 5 && __instance.motion_sensor_alive && !((RobotScript)__instance).powered_off && ((RobotScript)__instance).CanSeePlayer())
			{
				___standby_wakeup_delay = __state.standby_wakeup_delay + wakeupDelay.Value;
				if (sleepTimers.ContainsKey(__instance))
				{
					sleepTimers[__instance] = sleepTimeout.Value + ___standby_wakeup_delay;
				}
			}
		}
	}
	[HarmonyPatch]
	internal class SleepyDrones
	{
		[CompilerGenerated]
		private sealed class <DelayStartAsleep>d__21 : IEnumerator<WaitForSeconds>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private WaitForSeconds <>2__current;

			public ShockDrone drone;

			WaitForSeconds IEnumerator<WaitForSeconds>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DelayStartAsleep>d__21(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = new WaitForSeconds(firstSleepDelay);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if ((int)state_access.Invoke(drone) == 0)
					{
						ReversePatch_TransitionToState(drone, (ShockDroneState)3);
					}
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static Dictionary<ShockDrone, float> wakeUpTimers = new Dictionary<ShockDrone, float>();

		private static Dictionary<ShockDrone, float> sleepTimers = new Dictionary<ShockDrone, float>();

		private static HashSet<ShockDrone> grounded = new HashSet<ShockDrone>();

		private static Dictionary<CameraPart, ShockDrone> cameraToDrone = new Dictionary<CameraPart, ShockDrone>();

		private static Dictionary<OscillatorPart, ShockDrone> oscillatorToDrone = new Dictionary<OscillatorPart, ShockDrone>();

		private static Dictionary<MotorPart, ShockDrone> motorToDrone = new Dictionary<MotorPart, ShockDrone>();

		internal static FieldRef<SensorPart, RobotPart> part_access = AccessTools.FieldRefAccess<SensorPart, RobotPart>("part");

		internal static FieldRef<ShockDrone, ShockDroneState> state_access = AccessTools.FieldRefAccess<ShockDrone, ShockDroneState>("state");

		internal static FieldRef<MotorPart, EventInstance> event_instance_motor_access = AccessTools.FieldRefAccess<MotorPart, EventInstance>("event_instance_motor");

		internal static MethodInfo throttle_set_access = AccessTools.PropertySetter(typeof(MotorPart), "Throttle");

		internal static ConfigEntry<bool> startAsleepEnabled;

		internal static ConfigEntry<float> startAsleepChance;

		internal static ConfigEntry<float> wakeupDelay;

		internal static ConfigEntry<float> firstWakeupExtraDelay;

		internal static ConfigEntry<bool> sleepyEnabled;

		internal static ConfigEntry<float> sleepTimeout;

		internal static ConfigEntry<float> sleepyChance;

		internal static ConfigEntry<float> sleepVolumeMod;

		internal static float firstSleepDelay = 3f;

		internal static ConfigEntry<float> groundedChance;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ShockDrone), "Start")]
		private static void DroneSetup(ShockDrone __instance)
		{
			cameraToDrone[__instance.camera_part] = __instance;
			oscillatorToDrone[__instance.oscillator_part] = __instance;
			motorToDrone[__instance.motor_part] = __instance;
			if (startAsleepEnabled.Value && Random.value < startAsleepChance.Value)
			{
				wakeUpTimers[__instance] = firstWakeupExtraDelay.Value;
				if (sleepyEnabled.Value && Random.value < sleepyChance.Value)
				{
					sleepTimers[__instance] = sleepTimeout.Value + firstSleepDelay;
				}
				if (Random.value < groundedChance.Value)
				{
					grounded.Add(__instance);
				}
				((MonoBehaviour)__instance).StartCoroutine((IEnumerator)DelayStartAsleep(__instance));
			}
			if (cameraToDrone.Count >= 50)
			{
				Plugin.Logger.LogWarning((object)$"drone register abnormally large ({cameraToDrone.Count}); you have an unusual number of drones or they are not being deregistered");
			}
		}

		[IteratorStateMachine(typeof(<DelayStartAsleep>d__21))]
		private static IEnumerator<WaitForSeconds> DelayStartAsleep(ShockDrone drone)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DelayStartAsleep>d__21(0)
			{
				drone = drone
			};
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(CameraPart), "OnDestroy")]
		private static void Deregister(CameraPart __instance)
		{
			if (cameraToDrone.ContainsKey(__instance))
			{
				ShockDrone val = cameraToDrone[__instance];
				sleepTimers.Remove(val);
				wakeUpTimers.Remove(val);
				grounded.Remove(val);
				cameraToDrone.Remove(__instance);
				oscillatorToDrone.Remove(val.oscillator_part);
				motorToDrone.Remove(val.motor_part);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(ShockDrone), "StandbyUpdate")]
		private static bool StandbyUpdate(ShockDrone __instance, ref ShockDroneState __result)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.camera_part.Alive)
			{
				Vector3 velocity = __instance.motor_part.Velocity;
				if (((Vector3)(ref velocity)).magnitude > 3.5f && Vector3.Angle(__instance.motor_part.Velocity, __instance.motor_part.TargetPosition - ((Component)__instance.motor_part).transform.position) > 45f)
				{
					goto IL_00c2;
				}
				if (__instance.motor_part.Throttle < 0.1f)
				{
					velocity = __instance.motor_part.Velocity;
					if (((Vector3)(ref velocity)).magnitude > 0.8f && Vector3.Distance(((Component)__instance.motor_part).transform.position, __instance.motor_part.TargetPosition) < 0.1f)
					{
						goto IL_00c2;
					}
				}
			}
			if (part_access.Invoke(__instance.sensor_part).Alive && __instance.camera_part.CanSeePlayer)
			{
				__result = (ShockDroneState)0;
				return false;
			}
			return true;
			IL_00c2:
			__instance.motor_part.FacePosition = ((Component)__instance).transform.position;
			__result = (ShockDroneState)0;
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ShockDrone), "OnExitState")]
		private static void OnExitSleep(ShockDrone __instance, ShockDroneState ___state)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if ((int)___state == 3)
			{
				AudioManager.PlayOneShot3D(__instance.sound_events.alert, ((Component)__instance).transform.position, 1f, 0.66f);
				if (wakeUpTimers.ContainsKey(__instance))
				{
					wakeUpTimers[__instance] += wakeupDelay.Value;
				}
				else
				{
					wakeUpTimers[__instance] = wakeupDelay.Value + firstWakeupExtraDelay.Value;
				}
				if (sleepTimers.ContainsKey(__instance))
				{
					sleepTimers[__instance] = sleepTimeout.Value + wakeUpTimers[__instance];
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(ShockDrone), "IdleUpdate")]
		private static bool IdleUpdate(ShockDrone __instance, ref float ___idle_look_angle)
		{
			//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_005b: Unknown result type (might be due to invalid IL or missing references)
			if (wakeUpTimers.ContainsKey(__instance))
			{
				if ((wakeUpTimers[__instance] -= Time.deltaTime) < 0f)
				{
					wakeUpTimers.Remove(__instance);
					Quaternion rotation = ((Component)__instance).transform.rotation;
					___idle_look_angle = ((Quaternion)(ref rotation)).eulerAngles.y;
					return true;
				}
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(OscillatorPart), "UpdateCameraMovement")]
		private static bool StopCameraWhileAsleep(OscillatorPart __instance, ref float ___angle, float ___speed)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Invalid comparison between Unknown and I4
			//IL_0038: 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)
			if (!oscillatorToDrone.ContainsKey(__instance))
			{
				return true;
			}
			ShockDrone val = oscillatorToDrone[__instance];
			ShockDroneState val2 = state_access.Invoke(val);
			if ((int)val2 == 3 || ((int)val2 == 0 && wakeUpTimers.ContainsKey(val)))
			{
				if (val.motor_part.Throttle < 0.1f)
				{
					if (___angle > 0f)
					{
						___angle -= ___speed * Time.deltaTime;
						if (___angle < 0f)
						{
							___angle = 0f;
						}
					}
					else if (___angle < 0f)
					{
						___angle += ___speed * Time.deltaTime;
						if (___angle > 0f)
						{
							___angle = 0f;
						}
					}
					((Component)__instance).transform.localRotation = Quaternion.Euler(___angle, 0f, 0f);
				}
				return false;
			}
			return true;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ShockDrone), "IdleUpdate")]
		private static void SleepTimer(ShockDrone __instance, ref ShockDroneState __result)
		{
			if (sleepyEnabled.Value && (int)__result == 0 && sleepTimers.ContainsKey(__instance) && (sleepTimers[__instance] -= Time.deltaTime) < 0f)
			{
				__result = (ShockDroneState)3;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ShockDrone), "AlertUpdate")]
		private static void ResetTimer(ShockDrone __instance)
		{
			if (sleepTimers.ContainsKey(__instance))
			{
				sleepTimers[__instance] = sleepTimeout.Value;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MotorPart), "UpdateSound")]
		private static void ModSleepNoise(MotorPart __instance)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			ShockDrone val = motorToDrone[__instance];
			if ((int)state_access.Invoke(val) == 3)
			{
				EventInstance val2 = event_instance_motor_access.Invoke(__instance);
				float num = default(float);
				((EventInstance)(ref val2)).getVolume(ref num);
				((EventInstance)(ref val2)).setVolume(num * sleepVolumeMod.Value);
			}
		}

		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(ShockDrone), "TransitionToState")]
		private static void ReversePatch_TransitionToState(object instance, ShockDroneState to_state)
		{
			throw new NotImplementedException("method ShockDrone.TransitionToState was not reverse patched");
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(MotorPart), "FixedUpdate")]
		private static bool UpdateRotorWhileAsleep(MotorPart __instance)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			ShockDrone val = motorToDrone[__instance];
			RaycastHit val2 = default(RaycastHit);
			if ((int)state_access.Invoke(val) == 3 && grounded.Contains(val) && Physics.Raycast(((Component)val).transform.position, new Vector3(0f, -1f, 0f), ref val2, 5f, 134225920, (QueryTriggerInteraction)1))
			{
				__instance.TargetPosition = ((RaycastHit)(ref val2)).point;
				if (Vector3.Distance(((Component)val).transform.position, __instance.TargetPosition) < 0.1f)
				{
					Vector3 velocity = __instance.Velocity;
					if (((Vector3)(ref velocity)).magnitude < 0.5f)
					{
						throttle_set_access.Invoke(__instance, new object[1] { 0 });
						return false;
					}
				}
			}
			return true;
		}
	}
	internal class SleepySecurityCameras
	{
		[CompilerGenerated]
		private sealed class <DelayStartAsleep>d__11 : IEnumerator<WaitForSeconds>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private WaitForSeconds <>2__current;

			public SecurityCamera camera;

			WaitForSeconds IEnumerator<WaitForSeconds>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DelayStartAsleep>d__11(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					ReversePatch_TransitionToState(camera, (SecurityCameraState)3);
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static Dictionary<SecurityCamera, float> wakeUpTimers = new Dictionary<SecurityCamera, float>();

		private static Dictionary<SecurityCamera, float> sleepTimers = new Dictionary<SecurityCamera, float>();

		internal static MethodInfo CanSeePlayerAccess = AccessTools.PropertyGetter(typeof(SecurityCamera), "CanSeePlayer");

		internal static ConfigEntry<bool> startAsleepEnabled;

		internal static ConfigEntry<float> startAsleepChance;

		internal static ConfigEntry<float> wakeupDelay;

		internal static ConfigEntry<float> firstWakeupExtraDelay;

		internal static ConfigEntry<bool> sleepyEnabled;

		internal static ConfigEntry<float> sleepTimeout;

		internal static ConfigEntry<float> sleepyChance;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SecurityCamera), "Start")]
		private static void SetupSecurityCamera(SecurityCamera __instance, ref SecurityCameraState ___state)
		{
			if (!startAsleepEnabled.Value || !(Random.value < startAsleepChance.Value))
			{
				return;
			}
			__instance.light_part.SetTargetLightMode((LightMode)3, false);
			wakeUpTimers[__instance] = firstWakeupExtraDelay.Value;
			if (sleepyEnabled.Value && Random.value < sleepyChance.Value)
			{
				sleepTimers[__instance] = sleepTimeout.Value;
				if (sleepTimers.Count >= 50)
				{
					Plugin.Logger.LogWarning((object)$"security camera register abnormally large ({sleepTimers.Count}); you have an unusual number of security cameras or they are not being deregistered");
				}
			}
			((MonoBehaviour)__instance).StartCoroutine((IEnumerator)DelayStartAsleep(__instance));
		}

		[IteratorStateMachine(typeof(<DelayStartAsleep>d__11))]
		private static IEnumerator<WaitForSeconds> DelayStartAsleep(SecurityCamera camera)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DelayStartAsleep>d__11(0)
			{
				camera = camera
			};
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SecurityCamera), "OnDestroy")]
		private static void Deregister(SecurityCamera __instance)
		{
			wakeUpTimers.Remove(__instance);
			sleepTimers.Remove(__instance);
		}

		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(SecurityCamera), "TransitionToState")]
		private static void ReversePatch_TransitionToState(object instance, SecurityCameraState to_state)
		{
			throw new NotImplementedException("method SecurityCamera.TransitionToState was not reverse patched");
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SecurityCamera), "OffUpdate")]
		private static bool StandbyUpdate(SecurityCamera __instance, ref SecurityCameraState __result)
		{
			if ((bool)CanSeePlayerAccess.Invoke(__instance, Array.Empty<object>()))
			{
				Plugin.Logger.LogInfo((object)"spotted");
				__result = (SecurityCameraState)0;
			}
			else
			{
				__result = (SecurityCameraState)3;
			}
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SecurityCamera), "OnExitState")]
		private static void OnExitSleep(SecurityCamera __instance, SecurityCameraState ___state)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if ((int)___state == 3)
			{
				AudioManager.PlayOneShot3D(__instance.sound_events.alert, ((Component)__instance).transform.position, 1f, 0.66f);
				if (wakeUpTimers.ContainsKey(__instance))
				{
					wakeUpTimers[__instance] += wakeupDelay.Value;
				}
				else
				{
					wakeUpTimers[__instance] = wakeupDelay.Value + firstWakeupExtraDelay.Value;
				}
				if (sleepTimers.ContainsKey(__instance))
				{
					sleepTimers[__instance] = sleepTimeout.Value + wakeUpTimers[__instance];
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SecurityCamera), "IdleUpdate")]
		private static bool IdleUpdate(SecurityCamera __instance)
		{
			if (wakeUpTimers.ContainsKey(__instance))
			{
				if ((wakeUpTimers[__instance] -= Time.deltaTime) < 0f)
				{
					wakeUpTimers.Remove(__instance);
					return true;
				}
				return false;
			}
			return true;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SecurityCamera), "IdleUpdate")]
		private static void SleepTimer(SecurityCamera __instance, ref SecurityCameraState __result)
		{
			if (sleepyEnabled.Value && (int)__result == 0 && sleepTimers.ContainsKey(__instance) && (sleepTimers[__instance] -= Time.deltaTime) < 0f)
			{
				__result = (SecurityCameraState)3;
			}
		}
	}
	[HarmonyPatch]
	internal class SecurityCameraLinkedEnemies
	{
		internal static FieldRef<CameraPart, StochasticVision> external_vision_access = AccessTools.FieldRefAccess<CameraPart, StochasticVision>("external_vision");

		internal static ConfigEntry<bool> turretsEnabled;

		internal static ConfigEntry<bool> dronesEnabled;

		internal static ConfigEntry<bool> camerasEnabled;

		private static FieldInfo camera_part_drone_access = AccessTools.Field(typeof(ShockDrone), "camera_part");

		private static FieldInfo camera_part_camera_access = AccessTools.Field(typeof(SecurityCamera), "camera_part");

		private static MethodInfo get_componenet_camera = AccessTools.Method(typeof(GameObject), "GetComponent", (Type[])null, new Type[1] { typeof(SecurityCamera) });

		private static FieldInfo enemy_access = AccessTools.Field(typeof(ActiveEnemy), "enemy");

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SecurityCamera), "AlertEnemies")]
		private static bool AlertCameras(SecurityCamera __instance, ref List<IAlertable> ___alertable_enemies)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			if (camerasEnabled.Value)
			{
				RuntimeTileLevelGenerator instance = RuntimeTileLevelGenerator.instance;
				if (Object.op_Implicit((Object)(object)instance))
				{
					ActiveTile activeTile = instance.GetActiveTile(((Component)__instance).transform.position);
					List<ActiveEnemy> list = new List<ActiveEnemy>();
					list.AddRange(instance.GetActiveEnemiesInTile(activeTile.tile_position - 1));
					list.AddRange(instance.GetActiveEnemiesInTile(activeTile.tile_position));
					list.AddRange(instance.GetActiveEnemiesInTile(activeTile.tile_position + 1));
					foreach (ActiveEnemy item in list)
					{
						if (!((Object)(object)item.enemy != (Object)null) || !(Vector3.Distance(item.enemy.transform.position, ((Component)__instance).transform.position) <= __instance.alert_radius))
						{
							continue;
						}
						IAlertable component = (IAlertable)(object)item.enemy.GetComponent<TurretScript>();
						IAlertable val;
						if ((val = component) == null)
						{
							ShockDrone component2 = item.enemy.GetComponent<ShockDrone>();
							if ((Object)(object)component2 != (Object)null)
							{
								val = (IAlertable)(object)component2.camera_part;
							}
							else
							{
								SecurityCamera component3 = item.enemy.GetComponent<SecurityCamera>();
								if ((Object)(object)component3 != (Object)null)
								{
									val = (IAlertable)(object)component3.camera_part;
								}
							}
						}
						IAlertable val2 = val;
						if (val2 != null)
						{
							___alertable_enemies.Add(val2);
						}
					}
				}
				else
				{
					Debug.LogWarning((object)"SecurityCamera: RuntimeTileLevelGenerator could not be found. Used FindObjectsOfType fallback.");
					___alertable_enemies = new List<IAlertable>();
					___alertable_enemies.AddRange((IEnumerable<IAlertable>)(object)Object.FindObjectsOfType<CameraPart>());
					___alertable_enemies.AddRange((IEnumerable<IAlertable>)(object)Object.FindObjectsOfType<TurretScript>());
				}
				foreach (IAlertable ___alertable_enemy in ___alertable_enemies)
				{
					___alertable_enemy.Alert(__instance.camera_part.Vision, LocalAimHandler.player_instance);
				}
				return false;
			}
			return true;
		}

		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(TurretScript), "CalculateTargetAim")]
		private static Vector2 ReversePatch_CalculateTargetAim(object instance)
		{
			throw new NotImplementedException("method TurretScript.CalculateTargetAim was not reverse patched");
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TurretScript), "UpdateMotor")]
		private static void TurretAimWithoutCamera(TurretScript __instance, ref float ___target_angle_x, ref float ___target_angle_y)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (turretsEnabled.Value && !__instance.camera_alive && (int)SleepyTurrets.state_access.Invoke(__instance) == 3)
			{
				Vector2 val = ReversePatch_CalculateTargetAim(__instance);
				___target_angle_x = val.x;
				___target_angle_y = val.y;
			}
		}

		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(TurretScript), "UpdateCameraAlive")]
		private static void ReversePatch_UpdateCameraAlive(object instance)
		{
			throw new NotImplementedException("method TurretScript.UpdateCameraAlive was not reverse patched");
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(TurretScript), "UpdateCameraDestroyed")]
		private static bool BypassDestroyedTurretCamera(TurretScript __instance, StochasticVision ___external_vision)
		{
			if (turretsEnabled.Value && ___external_vision != null)
			{
				ReversePatch_UpdateCameraAlive(__instance);
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(TurretScript), "IsNeutralized")]
		private static bool OverrideIsNeutralized(TurretScript __instance, ref bool __result)
		{
			__result = !__instance.motor_alive || !__instance.battery_alive || !__instance.motion_sensor_alive || !__instance.ammo_alive;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(TurretScript), "IsIncapacitated")]
		private static bool OverrideIsIncapacitated(TurretScript __instance, ref bool __result, ref bool ___given_up, ref bool ___fell_off_world)
		{
			__result = (!__instance.battery_alive | ___given_up | ___fell_off_world) || (!__instance.ammo_alive && __instance.bullets == 0);
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(ShockDrone), "IdleUpdate")]
		private static bool BypassDestroyedDroneCamera(ShockDrone __instance, ref ShockDroneState __result)
		{
			if (dronesEnabled.Value && external_vision_access.Invoke(__instance.camera_part) != null && !__instance.camera_part.CanSeePlayer)
			{
				__result = (ShockDroneState)1;
				return false;
			}
			return true;
		}
	}
}