Decompiled source of OpeningDoorHearing v1.1.0

OpeningDoorHearing.dll

Decompiled 2 hours 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 AIGraph;
using Agents;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Enemies;
using GTFO.API;
using GTFO.API.Utilities;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem.Collections.Generic;
using LevelGeneration;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("OpeningDoorHearing")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("OpeningDoorHearing")]
[assembly: AssemblyTitle("OpeningDoorHearing")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace OpeningDoorHearing
{
	[BepInPlugin("OpeningDoorHearing", "Opening Door Hearing", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public const string GUID = "OpeningDoorHearing";

		public const string VERSION = "1.1.0";

		private const string BuiltInCopyGuid = "DamHell.Fixes";

		internal static ManualLogSource L;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> HearShots;

		internal static ConfigEntry<bool> WakeOnHit;

		internal static ConfigEntry<float> HitDelay;

		internal static ConfigEntry<float> Range;

		internal static ConfigEntry<bool> WeakDoors;

		private static int _errorsLogged;

		public override void Load()
		{
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Expected O, but got Unknown
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Expected O, but got Unknown
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Expected O, but got Unknown
			L = ((BasePlugin)this).Log;
			Enabled = ((BasePlugin)this).Config.Bind<bool>("OpeningDoorHearing", "Enabled", true, "Enemies behind a door can hear gunshots from the moment the door starts opening (host side).");
			HearShots = ((BasePlugin)this).Config.Bind<bool>("OpeningDoorHearing", "HearShots", true, "Main mechanism: while a door is opening, a player's gunshot wakes sleepers in the areas next to that door, within the vanilla weapon detection distance.");
			WakeOnHit = ((BasePlugin)this).Config.Bind<bool>("OpeningDoorHearing", "WakeOnHit", true, "Safety net: if an enemy next to an opening door is damaged by a player on the other side, nearby sleepers are woken the same way. Covers shots the host did not register as noise.");
			HitDelay = ((BasePlugin)this).Config.Bind<float>("OpeningDoorHearing", "HitDelay", 0.25f, "Seconds between such a hit and the safety net waking sleepers.");
			Range = ((BasePlugin)this).Config.Bind<float>("OpeningDoorHearing", "Range", 0f, "Hearing range in meters from the shooter. 0 = vanilla rule from each enemy's detection data (with default data: 30 m when the shooter is in the area right across the door, 10 m when further away).");
			WeakDoors = ((BasePlugin)this).Config.Bind<bool>("OpeningDoorHearing", "WeakDoors", true, "Also handle weak (breakable) doors. Security, apex and bulkhead doors are always handled.");
			bool flag = default(bool);
			if (((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("DamHell.Fixes"))
			{
				ManualLogSource l = L;
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(97, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("DamHell.Fixes");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is installed and already contains this fix. This plugin does nothing to avoid applying it twice.");
				}
				l.LogWarning(val);
				return;
			}
			Harmony val2 = new Harmony("OpeningDoorHearing");
			val2.PatchAll();
			Hearing.PatchNoiseSetter(val2);
			LevelAPI.OnBuildStart += Hearing.Clear;
			LevelAPI.OnLevelCleanup += Hearing.Clear;
			ManualLogSource l2 = L;
			BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(52, 4, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("loaded: enabled=");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<bool>(Enabled.Value);
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(", hearShots=");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<bool>(HearShots.Value);
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(", wakeOnHit=");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<bool>(WakeOnHit.Value);
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(", weakDoors=");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<bool>(WeakDoors.Value);
			}
			l2.LogInfo(val3);
		}

		internal static void Guard(string where, Action body)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			try
			{
				body();
			}
			catch (Exception ex)
			{
				if (_errorsLogged++ < 20)
				{
					ManualLogSource l = L;
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(2, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(where);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
					}
					l.LogError(val);
				}
			}
		}
	}
	internal static class Hearing
	{
		private sealed class Window
		{
			public IntPtr Key;

			public string Name = "";

			public bool Weak;

			public bool Closing;

			public LG_Gate Gate;

			public iLG_Door_Sync Sync;

			public Func<bool> InAnimation;

			public bool TraversableAtStart;

			public float Started;

			public float NextShot;

			public bool HitPending;

			public bool ShotLogged;

			public int Woken;

			public string EndReason = "";
		}

		[HarmonyPatch(typeof(LG_SecurityDoor), "OnDoorOpenStarted")]
		private static class Patch_Security_OpenStarted
		{
			private static void Postfix(LG_SecurityDoor __instance)
			{
				Plugin.Guard("OnDoorOpenStarted", delegate
				{
					Begin(((Il2CppObjectBase)__instance).Pointer, __instance.Gate, __instance.m_sync, () => __instance.InAnimation, weak: false, "OnDoorOpenStarted");
				});
			}
		}

		[HarmonyPatch(typeof(LG_SecurityDoor), "OnSyncDoorStatusChange")]
		private static class Patch_Security_StatusChange
		{
			private static void Postfix(LG_SecurityDoor __instance, pDoorState state, bool isRecall)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				Plugin.Guard("OnSyncDoorStatusChange", delegate
				{
					//IL_002c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0033: Invalid comparison between Unknown and I4
					//IL_003b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0042: Invalid comparison between Unknown and I4
					//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
					//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
					if (Active)
					{
						if (isRecall)
						{
							End(((Il2CppObjectBase)__instance).Pointer, "state recall");
						}
						else if ((int)state.status == 16 || ((int)state.status == 10 && __instance.InAnimation))
						{
							Begin(((Il2CppObjectBase)__instance).Pointer, __instance.Gate, __instance.m_sync, () => __instance.InAnimation, weak: false, $"status {state.status}");
						}
						else
						{
							End(((Il2CppObjectBase)__instance).Pointer, $"status {state.status}");
						}
					}
				});
			}
		}

		[HarmonyPatch(typeof(LG_SecurityDoor), "OnDoorIsOpened")]
		private static class Patch_Security_Opened
		{
			private static void Postfix(LG_SecurityDoor __instance)
			{
				Plugin.Guard("OnDoorIsOpened", delegate
				{
					End(((Il2CppObjectBase)__instance).Pointer, "fully open");
				});
			}
		}

		[HarmonyPatch(typeof(LG_WeakDoor), "OnSyncDoorStateChange")]
		private static class Patch_Weak_StateChange
		{
			private static void Postfix(LG_WeakDoor __instance, pDoorState state, bool isDropinState)
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				Plugin.Guard("OnSyncDoorStateChange", delegate
				{
					//IL_001a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0021: Invalid comparison between Unknown and I4
					//IL_0029: Unknown result type (might be due to invalid IL or missing references)
					//IL_0030: Invalid comparison between Unknown and I4
					//IL_00de: Unknown result type (might be due to invalid IL or missing references)
					//IL_00e4: Invalid comparison between Unknown and I4
					//IL_016b: 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)
					if (Active)
					{
						IntPtr pointer = ((Il2CppObjectBase)__instance).Pointer;
						bool flag = (int)state.status == 16 || (int)state.status == 10;
						bool flag2 = (flag ? (!OpenWeakDoors.Add(pointer)) : OpenWeakDoors.Remove(pointer));
						if (isDropinState)
						{
							End(pointer, "state recall");
						}
						else if (flag)
						{
							Begin(pointer, __instance.Gate, __instance.m_sync, () => __instance.InAnimation, weak: true, $"status {state.status}");
						}
						else if ((int)state.status == 1)
						{
							Window value;
							bool flag3 = Windows.TryGetValue(pointer, out value) && !value.Closing;
							if (flag2 || flag3)
							{
								Begin(pointer, __instance.Gate, __instance.m_sync, () => __instance.InAnimation, weak: true, "status Closed", closing: true);
							}
						}
						else
						{
							End(pointer, $"status {state.status}");
						}
					}
				});
			}
		}

		[HarmonyPatch(typeof(Dam_EnemyDamageBase), "ProcessReceivedDamage")]
		private static class Patch_EnemyDamaged
		{
			private static void Postfix(Dam_EnemyDamageBase __instance, Agent damageSource, DamageNoiseLevel damageNoiseLevel)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				Plugin.Guard("ProcessReceivedDamage", delegate
				{
					//IL_000d: Unknown result type (might be due to invalid IL or missing references)
					OnEnemyDamaged(__instance, damageSource, damageNoiseLevel);
				});
			}
		}

		private const float MaxListenSeconds = 20f;

		private const float StartGraceSeconds = 0.15f;

		private const float ShotInterval = 0.1f;

		private const float ShotMemorySeconds = 0.2f;

		private const float WeakDoorMaxSeconds = 4f;

		private const float WeakDoorCloseSeconds = 1.5f;

		private const float ForceCombatAfter = 3f;

		private static readonly Dictionary<IntPtr, Window> Windows = new Dictionary<IntPtr, Window>();

		private static readonly HashSet<IntPtr> OpenWeakDoors = new HashSet<IntPtr>();

		private static readonly Dictionary<IntPtr, float> LastShot = new Dictionary<IntPtr, float>();

		private static readonly HashSet<IntPtr> Awakened = new HashSet<IntPtr>();

		private static readonly List<EnemyAgent> Scratch = new List<EnemyAgent>();

		private static bool Active
		{
			get
			{
				if (Plugin.Enabled.Value)
				{
					return SNet.IsMaster;
				}
				return false;
			}
		}

		public static void Clear()
		{
			Windows.Clear();
			OpenWeakDoors.Clear();
			LastShot.Clear();
			Awakened.Clear();
		}

		private static string Describe(LG_Gate gate, bool weak)
		{
			LG_Zone val = (((Object)(object)((LG_ZoneExpander)gate).m_linksTo != (Object)null) ? ((LG_ZoneExpander)gate).m_linksTo.m_zone : null);
			string text = (weak ? "weak door" : "security door");
			if (!((Object)(object)val != (Object)null))
			{
				return text;
			}
			return $"{text} to ZONE {val.Alias}";
		}

		private static void Begin(IntPtr key, LG_Gate gate, iLG_Door_Sync sync, Func<bool> inAnimation, bool weak, string via, bool closing = false)
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			if (!Active || (Object)(object)gate == (Object)null || sync == null || (weak && !Plugin.WeakDoors.Value))
			{
				return;
			}
			if (Windows.TryGetValue(key, out Window value))
			{
				if (value.Closing == closing)
				{
					return;
				}
				End(key, closing ? "door closing" : "door reopening");
			}
			Window window = new Window
			{
				Key = key,
				Name = Describe(gate, weak),
				Weak = weak,
				Closing = closing,
				Gate = gate,
				Sync = sync,
				InAnimation = inAnimation,
				TraversableAtStart = gate.IsTraversable,
				Started = Time.time
			};
			Windows[key] = window;
			ManualLogSource l = Plugin.L;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(67, 5, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(window.Name);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(closing ? "closing" : "opening");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", listening for gunshots (via ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(via);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; gate traversable=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(window.TraversableAtStart);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", in animation=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(inAnimation());
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
			}
			l.LogInfo(val);
			if (CoroutineDispatcher.StartInLevelCoroutine(Listen(window)) == null)
			{
				Windows.Remove(key);
			}
		}

		private static void End(IntPtr key, string reason)
		{
			if (Windows.TryGetValue(key, out Window value) && value.EndReason.Length == 0)
			{
				value.EndReason = reason;
			}
			Windows.Remove(key);
		}

		private static bool IsCurrent(Window w)
		{
			if (Windows.TryGetValue(w.Key, out Window value))
			{
				return value == w;
			}
			return false;
		}

		private static bool StillOpening(Window w)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Invalid comparison between Unknown and I4
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Invalid comparison between Unknown and I4
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			if (!IsCurrent(w))
			{
				return false;
			}
			if ((Object)(object)w.Gate == (Object)null)
			{
				w.EndReason = "door destroyed";
				return false;
			}
			float num = Time.time - w.Started;
			if (w.Closing)
			{
				if (num > 1.5f)
				{
					w.EndReason = "door closed";
					return false;
				}
				return true;
			}
			if (num < 0.15f)
			{
				return true;
			}
			eDoorStatus status = w.Sync.GetCurrentSyncState().status;
			if ((int)status != 16 && (int)status != 10)
			{
				w.EndReason = $"status {status}";
				return false;
			}
			if (!w.TraversableAtStart && w.Gate.IsTraversable)
			{
				w.EndReason = "game made the gate traversable";
				return false;
			}
			if (num > (w.Weak ? 4f : 20f))
			{
				w.EndReason = "timeout";
				return false;
			}
			return true;
		}

		private static IEnumerator Listen(Window w)
		{
			while (true)
			{
				bool opening = false;
				Plugin.Guard("listen", delegate
				{
					opening = StillOpening(w);
					if (opening && Active && Plugin.HearShots.Value && Time.time >= w.NextShot)
					{
						PollShots(w);
					}
				});
				if (!opening)
				{
					break;
				}
				yield return null;
			}
			if (IsCurrent(w))
			{
				Windows.Remove(w.Key);
			}
			ManualLogSource l = Plugin.L;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(48, 4, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(w.Name);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": stopped listening after ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(Time.time - w.Started, "0.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("s (");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>((w.EndReason.Length > 0) ? w.EndReason : "error");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("); woke ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(w.Woken);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" sleeper(s)");
			}
			l.LogInfo(val);
		}

		public static void PatchNoiseSetter(Harmony harmony)
		{
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				MethodInfo methodInfo = AccessTools.DeclaredPropertySetter(typeof(PlayerAgent), "Noise") ?? AccessTools.PropertySetter(typeof(Agent), "Noise");
				if (methodInfo == null)
				{
					Plugin.L.LogWarning((object)"player noise setter not found; relying on per-frame noise checks only");
					return;
				}
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(Hearing), "OnNoiseSet", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				ManualLogSource l = Plugin.L;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("listening to ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(methodInfo.DeclaringType?.Name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(methodInfo.Name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" for gunshots");
				}
				l.LogInfo(val);
			}
			catch (Exception ex)
			{
				ManualLogSource l2 = Plugin.L;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(81, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("could not patch the player noise setter; relying on per-frame noise checks only: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				l2.LogWarning(val2);
			}
		}

		private static void OnNoiseSet(Agent __instance, NoiseType value)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)value == 8 && Windows.Count != 0)
			{
				LastShot[((Il2CppObjectBase)__instance).Pointer] = Time.time;
			}
		}

		private static void PollShots(Window w)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Invalid comparison between Unknown and I4
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			List<PlayerAgent> playerAgentsInLevel = PlayerManager.PlayerAgentsInLevel;
			if (playerAgentsInLevel == null)
			{
				return;
			}
			bool flag3 = default(bool);
			for (int i = 0; i < playerAgentsInLevel.Count; i++)
			{
				PlayerAgent val = playerAgentsInLevel[i];
				if ((Object)(object)val == (Object)null || !((Agent)val).Alive)
				{
					continue;
				}
				bool flag = (int)((Agent)val).Noise == 8;
				float value;
				bool flag2 = LastShot.TryGetValue(((Il2CppObjectBase)val).Pointer, out value) && Time.time - value <= 0.2f;
				if (!flag && !flag2)
				{
					continue;
				}
				if (!w.ShotLogged)
				{
					w.ShotLogged = true;
					ManualLogSource l = Plugin.L;
					BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(52, 4, ref flag3);
					if (flag3)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(w.Name);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": gunshot heard from ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Agent)val).IsLocallyOwned ? "the host" : "a remote player or bot");
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (noise state=");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<bool>(flag);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", setter record=");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<bool>(flag2);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(")");
					}
					l.LogInfo(val2);
				}
				w.NextShot = Time.time + 0.1f;
				WakeAround(w, (Agent)(object)val, ((Agent)val).Position, ((Agent)val).CourseNode);
			}
		}

		private static void WakeAround(Window w, Agent shooter, Vector3 shooterPosition, AIG_CourseNode? shooterNode)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			AIG_CourseNode val = (((Object)(object)((LG_ZoneExpander)w.Gate).m_linksFrom != (Object)null) ? ((LG_ZoneExpander)w.Gate).m_linksFrom.m_courseNode : null);
			AIG_CourseNode val2 = (((Object)(object)((LG_ZoneExpander)w.Gate).m_linksTo != (Object)null) ? ((LG_ZoneExpander)w.Gate).m_linksTo.m_courseNode : null);
			WakeInNode(w, val2, val, shooter, shooterPosition, shooterNode);
			WakeInNode(w, val, val2, shooter, shooterPosition, shooterNode);
		}

		private static void WakeInNode(Window w, AIG_CourseNode? node, AIG_CourseNode? otherSide, Agent shooter, Vector3 shooterPosition, AIG_CourseNode? shooterNode)
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Invalid comparison between Unknown and I4
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Invalid comparison between Unknown and I4
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			if (node == null || node.m_enemiesInNode == null || (shooterNode != null && ((Il2CppObjectBase)shooterNode).Pointer == ((Il2CppObjectBase)node).Pointer))
			{
				return;
			}
			float nodeDistance = ((shooterNode != null && otherSide != null && ((Il2CppObjectBase)shooterNode).Pointer == ((Il2CppObjectBase)otherSide).Pointer) ? 1f : 2f);
			Scratch.Clear();
			Enumerator<EnemyAgent> enumerator = node.m_enemiesInNode.GetEnumerator();
			while (enumerator.MoveNext())
			{
				EnemyAgent current = enumerator.Current;
				Scratch.Add(current);
			}
			foreach (EnemyAgent item in Scratch)
			{
				if (!((Object)(object)item == (Object)null) && ((Agent)item).Alive && !((Object)(object)item.AI == (Object)null) && (int)((AgentAI)item.AI).Mode == 4 && !Awakened.Contains(((Il2CppObjectBase)item).Pointer) && (int)item.Locomotion.CurrentStateEnum == 14)
				{
					Vector3 towardsNoise = shooterPosition - item.Position;
					if (!(((Vector3)(ref towardsNoise)).magnitude > HearingRange(item, nodeDistance)))
					{
						Awakened.Add(((Il2CppObjectBase)item).Pointer);
						Wake(item, shooter, towardsNoise);
						w.Woken++;
					}
				}
			}
			Scratch.Clear();
		}

		private static float HearingRange(EnemyAgent enemy, float nodeDistance)
		{
			if (Plugin.Range.Value > 0f)
			{
				return Plugin.Range.Value;
			}
			EnemyDetectionDataBlock enemyDetectionData = enemy.EnemyDetectionData;
			if (enemyDetectionData == null)
			{
				return 30f;
			}
			float weaponDetectionDistanceMax = enemyDetectionData.weaponDetectionDistanceMax;
			float weaponDetectionDistanceMin = enemyDetectionData.weaponDetectionDistanceMin;
			float detectionNodeDistanceMax = enemyDetectionData.detectionNodeDistanceMax;
			if (detectionNodeDistanceMax <= 0f)
			{
				return weaponDetectionDistanceMax;
			}
			if (nodeDistance > detectionNodeDistanceMax)
			{
				return 0f;
			}
			return Mathf.Lerp(weaponDetectionDistanceMax, weaponDetectionDistanceMin, nodeDistance / detectionNodeDistanceMax);
		}

		private static void Wake(EnemyAgent enemy, Agent shooter, Vector3 towardsNoise)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Guard("set detected agent", delegate
			{
				((AgentAI)enemy.AI).SetDetectedAgent(shooter, (AgentTargetDetectionType)2);
			});
			enemy.Locomotion.HibernateWakeup.ActivateState(((Vector3)(ref towardsNoise)).normalized, ((Vector3)(ref towardsNoise)).magnitude, Random.Range(0f, 0.3f), false);
			CoroutineDispatcher.StartInLevelCoroutine(EnsureAwake(enemy));
		}

		private static IEnumerator EnsureAwake(EnemyAgent enemy)
		{
			yield return (object)new WaitForSeconds(3f);
			Plugin.Guard("ensure awake", delegate
			{
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: Invalid comparison between Unknown and I4
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Invalid comparison between Unknown and I4
				if (Active && !((Object)(object)enemy == (Object)null) && ((Agent)enemy).Alive && !((Object)(object)enemy.AI == (Object)null) && (int)((AgentAI)enemy.AI).Mode == 4 && (int)enemy.Locomotion.CurrentStateEnum == 14)
				{
					enemy.AI.m_behaviour.ChangeState((EB_States)5);
					Plugin.L.LogInfo((object)"a sleeper was still hibernating after the wake-up call; switched it to combat directly");
				}
			});
		}

		private static void OnEnemyDamaged(Dam_EnemyDamageBase damage, Agent? damageSource, DamageNoiseLevel noiseLevel)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			if (Windows.Count == 0 || !Active || !Plugin.WakeOnHit.Value || (Object)(object)damageSource == (Object)null || (int)noiseLevel == 1)
			{
				return;
			}
			PlayerAgent val = ((Il2CppObjectBase)damageSource).TryCast<PlayerAgent>();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			EnemyAgent owner = damage.Owner;
			AIG_CourseNode val2 = (((Object)(object)owner != (Object)null) ? ((Agent)owner).CourseNode : null);
			if (val2 == null)
			{
				return;
			}
			AIG_CourseNode courseNode = ((Agent)val).CourseNode;
			if (courseNode != null && ((Il2CppObjectBase)courseNode).Pointer == ((Il2CppObjectBase)val2).Pointer)
			{
				return;
			}
			foreach (Window value in Windows.Values)
			{
				if (!value.HitPending && !((Object)(object)value.Gate == (Object)null))
				{
					AIG_CourseNode val3 = (((Object)(object)((LG_ZoneExpander)value.Gate).m_linksFrom != (Object)null) ? ((LG_ZoneExpander)value.Gate).m_linksFrom.m_courseNode : null);
					AIG_CourseNode val4 = (((Object)(object)((LG_ZoneExpander)value.Gate).m_linksTo != (Object)null) ? ((LG_ZoneExpander)value.Gate).m_linksTo.m_courseNode : null);
					if ((val3 != null && ((Il2CppObjectBase)val3).Pointer == ((Il2CppObjectBase)val2).Pointer) || (val4 != null && ((Il2CppObjectBase)val4).Pointer == ((Il2CppObjectBase)val2).Pointer))
					{
						value.HitPending = CoroutineDispatcher.StartInLevelCoroutine(WakeAfterHit(value, val, ((Agent)val).Position, courseNode)) != null;
						break;
					}
				}
			}
		}

		private static IEnumerator WakeAfterHit(Window w, PlayerAgent shooter, Vector3 shooterPosition, AIG_CourseNode? shooterNode)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			yield return (object)new WaitForSeconds(Mathf.Max(0f, Plugin.HitDelay.Value));
			w.HitPending = false;
			Plugin.Guard("wake on hit", delegate
			{
				//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)
				//IL_007d: Expected O, but got Unknown
				if (Active && IsCurrent(w) && !((Object)(object)w.Gate == (Object)null) && !((Object)(object)shooter == (Object)null))
				{
					int woken = w.Woken;
					WakeAround(w, (Agent)(object)shooter, shooterPosition, shooterNode);
					if (w.Woken > woken)
					{
						ManualLogSource l = Plugin.L;
						bool flag = default(bool);
						BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(61, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(w.Name);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": safety net woke ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(w.Woken - woken);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" sleeper(s) after a hit from the other side");
						}
						l.LogInfo(val);
					}
				}
			});
		}
	}
}