Decompiled source of AdvancedWardenObjective v1.2.7

AdvancedWardenObjective.dll

Decompiled 2 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using AIGraph;
using AK;
using AWO.CustomFields;
using AWO.Events;
using AWO.Jsons;
using AWO.Modules.WEE;
using AWO.Modules.WOE;
using AWO.Networking;
using AWO.Networking.CommonReplicator.Inject;
using AWO.Networking.Inject;
using AWO.Sessions;
using AWO.Utils;
using AWO.WEE.Detours;
using AWO.WEE.Events;
using AWO.WEE.JsonInjects;
using AWO.WEE.Replicators;
using Agents;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Hook;
using BepInEx.Unity.IL2CPP.Utils;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using CellMenu;
using ChainedPuzzles;
using Enemies;
using Expedition;
using GTFO.API;
using GameData;
using Globals;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppInterop.Runtime.InteropTypes.Fields;
using Il2CppInterop.Runtime.Runtime;
using Il2CppJsonNet;
using Il2CppJsonNet.Linq;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using InjectLib.FieldInjection;
using InjectLib.JsonNETInjection;
using InjectLib.JsonNETInjection.Converter;
using InjectLib.JsonNETInjection.Handler;
using InjectLib.JsonNETInjection.Supports;
using LevelGeneration;
using Localization;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using TMPro;
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(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AdvancedWardenObjective")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.2.7")]
[assembly: AssemblyInformationalVersion("1.2.7+gitcfa2d23-dirty-master.cfa2d2353c0d0a953e5206ca0175fd822be44365")]
[assembly: AssemblyProduct("AdvancedWardenObjective")]
[assembly: AssemblyTitle("AdvancedWardenObjective")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.7.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
namespace AWO
{
	[BepInPlugin("GTFO.AWO", "AWO", "1.2.7")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class EntryPoint : BasePlugin
	{
		[StructLayout(LayoutKind.Sequential, Size = 1)]
		public struct Coroutines
		{
			public static float CountdownStarted { get; set; }

			public static float TPFStarted { get; set; }
		}

		[StructLayout(LayoutKind.Sequential, Size = 1)]
		public struct TimerMods
		{
			public static float TimeModifier { get; set; }

			public static Color TimerColor { get; set; }

			public static float SpeedModifier { get; set; }

			public static LocaleText CountupText { get; set; }
		}

		public class AWOTerminalCommands
		{
			public WEE_EventData data;

			public bool hidden;

			public bool used;

			public AWOTerminalCommands(WEE_EventData e)
			{
				used = false;
				hidden = false;
				data = e;
			}
		}

		public static List<AWOTerminalCommands> AWOCommandList = new List<AWOTerminalCommands>();

		public static HashSet<int> ActiveEventLoops { get; set; } = new HashSet<int>();


		public static HashSet<LG_WorldEventNavMarker> NavMarkers { get; set; } = new HashSet<LG_WorldEventNavMarker>();


		public static Dictionary<GlobalZoneIndex, LG_DimensionPortal> Portals { get; set; } = new Dictionary<GlobalZoneIndex, LG_DimensionPortal>();


		public static Random SessionSeed { get; set; } = new Random();


		public override void Load()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			WardenEventExt.Initialize();
			new Harmony("AWO.Harmony").PatchAll();
			AssetAPI.OnStartupAssetsLoaded += AssetAPI_OnStartupAssetsLoaded;
			WOEventDataFields.Init();
			WODataBlockFields.Init();
		}

		private void AssetAPI_OnStartupAssetsLoaded()
		{
			BlackoutState.AssetLoaded();
			LevelFailUpdateState.AssetLoaded();
		}
	}
	internal static class Logger
	{
		private static readonly ManualLogSource _Logger;

		static Logger()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_Logger = new ManualLogSource("AWO");
			Logger.Sources.Add((ILogSource)(object)_Logger);
		}

		private static string Format(object msg)
		{
			return msg.ToString();
		}

		public static void Info(BepInExInfoLogInterpolatedStringHandler handler)
		{
			_Logger.LogInfo(handler);
		}

		public static void Info(string str)
		{
			_Logger.LogMessage((object)str);
		}

		public static void Info(object data)
		{
			_Logger.LogMessage((object)Format(data));
		}

		public static void Debug(BepInExDebugLogInterpolatedStringHandler handler)
		{
			_Logger.LogDebug(handler);
		}

		public static void Debug(string str)
		{
			_Logger.LogDebug((object)str);
		}

		public static void Debug(object data)
		{
			_Logger.LogDebug((object)Format(data));
		}

		public static void Error(BepInExErrorLogInterpolatedStringHandler handler)
		{
			_Logger.LogError(handler);
		}

		public static void Error(string str)
		{
			_Logger.LogError((object)str);
		}

		public static void Error(object data)
		{
			_Logger.LogError((object)Format(data));
		}

		public static void Fatal(BepInExFatalLogInterpolatedStringHandler handler)
		{
			_Logger.LogFatal(handler);
		}

		public static void Fatal(string str)
		{
			_Logger.LogFatal((object)str);
		}

		public static void Fatal(object data)
		{
			_Logger.LogFatal((object)Format(data));
		}

		public static void Warn(BepInExWarningLogInterpolatedStringHandler handler)
		{
			_Logger.LogWarning(handler);
		}

		public static void Warn(string str)
		{
			_Logger.LogWarning((object)str);
		}

		public static void Warn(object data)
		{
			_Logger.LogWarning((object)Format(data));
		}

		[Conditional("DEBUG")]
		public static void DebugOnly(object data)
		{
			_Logger.LogDebug((object)Format(data));
		}
	}
	[GeneratedCode("VersionInfoGenerator", "2.0.0+git50a4b1a-master")]
	[CompilerGenerated]
	internal static class VersionInfo
	{
		public const string RootNamespace = "AWO";

		public const string Version = "1.2.7";

		public const string VersionPrerelease = null;

		public const string VersionMetadata = "gitcfa2d23-dirty-master";

		public const string SemVer = "1.2.7+gitcfa2d23-dirty-master";

		public const string GitRevShort = "cfa2d23-dirty";

		public const string GitRevLong = "cfa2d2353c0d0a953e5206ca0175fd822be44365-dirty";

		public const string GitBranch = "master";

		public const string GitTag = null;

		public const bool GitIsDirty = true;
	}
}
namespace AWO.Utils
{
	internal static class LocalizedTextExtensions
	{
		public static string ToText(this LocalizedText text)
		{
			return text.HasTranslation ? Text.Get(text.Id) : text.UntranslatedText;
		}
	}
	internal static class RandomExtensions
	{
		public static bool MeetProbability(this Random rand, float prob)
		{
			if (prob >= 1f)
			{
				return true;
			}
			if (prob <= 0f)
			{
				return false;
			}
			return prob >= rand.NextFloat01();
		}

		public static float NextRange(this Random rand, float min, float max)
		{
			return rand.NextFloat01() * (max - min) + min;
		}

		public static float NextFloat01(this Random rand)
		{
			return (float)rand.NextDouble();
		}
	}
	internal static class RNG
	{
		private static readonly Random _Rand = new Random();

		public static float Float01 => (float)_Rand.NextDouble();

		public static int Int0Positive => _Rand.Next(0, int.MaxValue);

		public static int Int0Negative => _Rand.Next(int.MinValue, 1);

		public static int Int => _Rand.Next(int.MinValue, int.MaxValue);

		public static bool MeetProbability(float prob)
		{
			if (prob >= 1f)
			{
				return true;
			}
			if (prob <= 0f)
			{
				return false;
			}
			return prob >= Float01;
		}
	}
}
namespace AWO.Sessions
{
	internal struct BlackoutStatus
	{
		public bool blackoutEnabled;
	}
	internal static class BlackoutState
	{
		private static StateReplicator<BlackoutStatus> _Replicator;

		public static bool BlackoutEnabled { get; private set; }

		internal static void AssetLoaded()
		{
			if (_Replicator == null)
			{
				_Replicator = StateReplicator<BlackoutStatus>.Create(1u, new BlackoutStatus
				{
					blackoutEnabled = false
				}, LifeTimeType.Permanent);
				_Replicator.OnStateChanged += OnStateChanged;
				LevelEvents.OnLevelCleanup += LevelCleanup;
			}
		}

		private static void LevelCleanup()
		{
			SetEnabled(enabled: false);
		}

		public static void SetEnabled(bool enabled)
		{
			_Replicator.SetState(new BlackoutStatus
			{
				blackoutEnabled = enabled
			});
		}

		private static void OnStateChanged(BlackoutStatus _, BlackoutStatus state, bool isRecall)
		{
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Invalid comparison between Unknown and I4
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Invalid comparison between Unknown and I4
			bool flag = !state.blackoutEnabled;
			foreach (LG_LabDisplay labDisplay in LG_Objects.LabDisplays)
			{
				if (!((Object)(object)labDisplay == (Object)null) && !((Object)(object)labDisplay.m_Text == (Object)null))
				{
					((Behaviour)labDisplay.m_Text).enabled = flag;
				}
			}
			foreach (LG_ComputerTerminal terminal in LG_Objects.Terminals)
			{
				if ((Object)(object)terminal == (Object)null)
				{
					continue;
				}
				terminal.OnProximityExit();
				Interact_ComputerTerminal componentInChildren = ((Component)terminal).GetComponentInChildren<Interact_ComputerTerminal>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					((Behaviour)componentInChildren).enabled = flag;
					((Interact_Base)componentInChildren).SetActive(flag);
				}
				GUIX_VirtualSceneLink component = ((Component)terminal).GetComponent<GUIX_VirtualSceneLink>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.m_virtualScene != (Object)null)
				{
					GUIX_VirtualCamera virtualCamera = component.m_virtualScene.virtualCamera;
					float num = (flag ? 0.3f : 0f);
					float num2 = (flag ? 1000f : 0f);
					virtualCamera.SetFovAndClip(virtualCamera.paramCamera.fieldOfView, num, num2);
				}
				if ((Object)(object)terminal.m_text != (Object)null)
				{
					((Behaviour)terminal.m_text).enabled = flag;
				}
				if (!flag)
				{
					PlayerAgent localInteractionSource = terminal.m_localInteractionSource;
					if ((Object)(object)localInteractionSource != (Object)null && localInteractionSource.FPItemHolder.InTerminalTrigger)
					{
						terminal.ExitFPSView();
					}
				}
			}
			foreach (LG_DoorButton doorButton in LG_Objects.DoorButtons)
			{
				if ((Object)(object)doorButton == (Object)null)
				{
					continue;
				}
				((Component)doorButton.m_anim).gameObject.SetActive(flag);
				doorButton.m_enabled = flag;
				if (flag)
				{
					LG_WeakLock componentInChildren2 = ((Component)doorButton).GetComponentInChildren<LG_WeakLock>();
					if ((Object)(object)componentInChildren2 == (Object)null)
					{
						doorButton.m_enabled = true;
					}
					else if ((int)componentInChildren2.Status == 3)
					{
						doorButton.m_enabled = true;
					}
				}
			}
			foreach (LG_WeakLock weakLock in LG_Objects.WeakLocks)
			{
				if ((Object)(object)weakLock == (Object)null)
				{
					continue;
				}
				((Interact_Base)weakLock.m_intHack).m_isActive = flag;
				Transform val = ((Component)weakLock).transform.FindChild("HackableLock/SecurityLock/g_WeakLock/Security_Display_Locked");
				if ((Object)(object)val != (Object)null)
				{
					((Component)val).gameObject.active = flag;
					continue;
				}
				val = ((Component)weakLock).transform.FindChild("HackableLock/Security_Display_Locked");
				if ((Object)(object)val != (Object)null)
				{
					((Component)val).gameObject.active = flag;
				}
			}
			foreach (LG_HSUActivator_Core hSUActivator in LG_Objects.HSUActivators)
			{
				if ((Object)(object)hSUActivator == (Object)null || !hSUActivator.m_isWardenObjective || (int)hSUActivator.m_stateReplicator.State.status != 0)
				{
					continue;
				}
				hSUActivator.m_insertHSUInteraction.SetActive(flag);
				foreach (GameObject item in (Il2CppArrayBase<GameObject>)(object)hSUActivator.m_activateWhenActive)
				{
					item.SetActive(flag);
				}
			}
			BlackoutEnabled = state.blackoutEnabled;
		}
	}
	internal enum LevelFailMode
	{
		Default,
		Never,
		AnyPlayerDown
	}
	internal struct LevelFailCheck
	{
		public LevelFailMode mode;
	}
	internal sealed class LevelFailUpdateState
	{
		private static StateReplicator<LevelFailCheck> _Replicator;

		internal static void AssetLoaded()
		{
			if (_Replicator == null)
			{
				_Replicator = StateReplicator<LevelFailCheck>.Create(1u, new LevelFailCheck
				{
					mode = LevelFailMode.Default
				}, LifeTimeType.Permanent);
				LG_Factory.OnFactoryBuildStart += Action.op_Implicit((Action)delegate
				{
					_Replicator.ClearAllRecallSnapshot();
					_Replicator.SetState(new LevelFailCheck
					{
						mode = LevelFailMode.Default
					});
				});
				_Replicator.OnStateChanged += OnStateChanged;
				LevelEvents.OnLevelCleanup += LevelCleanup;
			}
		}

		private static void LevelCleanup()
		{
			SetFailAllowed(allowed: true);
		}

		public static void SetFailAllowed(bool allowed)
		{
			_Replicator.SetState(new LevelFailCheck
			{
				mode = ((!allowed) ? LevelFailMode.Never : LevelFailMode.Default)
			});
		}

		public static void SetFailWhenAnyPlayerDown(bool enabled)
		{
			_Replicator.SetState(new LevelFailCheck
			{
				mode = (enabled ? LevelFailMode.AnyPlayerDown : LevelFailMode.Default)
			});
		}

		private static void OnStateChanged(LevelFailCheck _, LevelFailCheck state, bool __)
		{
			switch (state.mode)
			{
			case LevelFailMode.Default:
				Inject_LevelFailCheck.LevelFailAllowed = true;
				Inject_LevelFailCheck.LevelFailWhenAnyPlayerDown = false;
				break;
			case LevelFailMode.Never:
				Inject_LevelFailCheck.LevelFailAllowed = false;
				Inject_LevelFailCheck.LevelFailWhenAnyPlayerDown = false;
				break;
			case LevelFailMode.AnyPlayerDown:
				Inject_LevelFailCheck.LevelFailAllowed = true;
				Inject_LevelFailCheck.LevelFailWhenAnyPlayerDown = true;
				break;
			}
		}
	}
	public static class LG_Objects
	{
		private static readonly List<LG_ComputerTerminal> _TerminalList;

		private static readonly List<LG_LabDisplay> _LabDisplayList;

		private static readonly List<LG_DoorButton> _DoorButtonList;

		private static readonly List<LG_WeakLock> _WeakLockList;

		private static readonly List<LG_HSUActivator_Core> _HSUActivatorList;

		public static IEnumerable<LG_ComputerTerminal> Terminals => _TerminalList;

		public static IEnumerable<LG_LabDisplay> LabDisplays => _LabDisplayList;

		public static IEnumerable<LG_DoorButton> DoorButtons => _DoorButtonList;

		public static IEnumerable<LG_WeakLock> WeakLocks => _WeakLockList;

		public static IEnumerable<LG_HSUActivator_Core> HSUActivators => _HSUActivatorList;

		static LG_Objects()
		{
			_TerminalList = new List<LG_ComputerTerminal>();
			_LabDisplayList = new List<LG_LabDisplay>();
			_DoorButtonList = new List<LG_DoorButton>();
			_WeakLockList = new List<LG_WeakLock>();
			_HSUActivatorList = new List<LG_HSUActivator_Core>();
			LevelEvents.OnLevelCleanup += OnLevelCleanup;
		}

		private static void OnLevelCleanup()
		{
			Clear();
		}

		internal static void Clear()
		{
			_TerminalList.Clear();
			_LabDisplayList.Clear();
			_DoorButtonList.Clear();
			_WeakLockList.Clear();
			_HSUActivatorList.Clear();
			EntryPoint.AWOCommandList.Clear();
			EntryPoint.Portals.Clear();
		}

		public static void AddTerminal(LG_ComputerTerminal terminal)
		{
			AddToList<LG_ComputerTerminal>(in _TerminalList, terminal);
		}

		public static void RemoveTerminal(LG_ComputerTerminal terminal)
		{
			RemoveFromList<LG_ComputerTerminal>(in _TerminalList, terminal);
		}

		public static void AddLabDisplay(LG_LabDisplay display)
		{
			AddToList<LG_LabDisplay>(in _LabDisplayList, display);
		}

		public static void RemoveLabDisplay(LG_LabDisplay display)
		{
			RemoveFromList<LG_LabDisplay>(in _LabDisplayList, display);
		}

		public static void AddDoorButton(LG_DoorButton button)
		{
			AddToList<LG_DoorButton>(in _DoorButtonList, button);
		}

		public static void RemoveDoorButton(LG_DoorButton button)
		{
			RemoveFromList<LG_DoorButton>(in _DoorButtonList, button);
		}

		public static void AddWeakLock(LG_WeakLock weaklock)
		{
			AddToList<LG_WeakLock>(in _WeakLockList, weaklock);
		}

		public static void RemoveWeakLock(LG_WeakLock weaklock)
		{
			RemoveFromList<LG_WeakLock>(in _WeakLockList, weaklock);
		}

		public static void AddHSUActivator(LG_HSUActivator_Core activator)
		{
			AddToList<LG_HSUActivator_Core>(in _HSUActivatorList, activator);
		}

		public static void RemoveHSUActivator(LG_HSUActivator_Core activator)
		{
			RemoveFromList<LG_HSUActivator_Core>(in _HSUActivatorList, activator);
		}

		private static void AddToList<O>(in List<O> list, O itemToAdd) where O : Component
		{
			int id = ((Object)(object)itemToAdd).GetInstanceID();
			if (!list.Any((O t) => ((Object)(object)t).GetInstanceID() == id))
			{
				list.Add(itemToAdd);
			}
		}

		private static void RemoveFromList<O>(in List<O> list, O itemToRemove) where O : Component
		{
			int id = ((Object)(object)itemToRemove).GetInstanceID();
			int num = list.FindIndex((O i) => ((Object)(object)i).GetInstanceID() == id);
			if (num > -1)
			{
				list.RemoveAt(num);
			}
		}
	}
}
namespace AWO.Sessions.Inject
{
	[HarmonyPatch(typeof(LG_DoorButton), "OnWeakLockUnlocked")]
	internal static class Inject_PreventDoorButtonUnlock
	{
		private static bool Prefix()
		{
			return !BlackoutState.BlackoutEnabled;
		}
	}
	[HarmonyPatch(typeof(LG_ComputerTerminal), "OnProximityEnter")]
	[HarmonyPatch(typeof(LG_ComputerTerminal), "OnProximityExit")]
	internal static class Inject_PreventTerminalProximity
	{
		private static bool Prefix()
		{
			return !BlackoutState.BlackoutEnabled;
		}
	}
}
namespace AWO.Sessions.Inject.LG
{
	[HarmonyPatch(typeof(LG_ComputerTerminal))]
	internal static class Inject_LG_ComputerTerminal_Track
	{
		[HarmonyPatch("Setup")]
		[HarmonyPostfix]
		private static void Post_Spawn(LG_ComputerTerminal __instance)
		{
			LG_Objects.AddTerminal(__instance);
		}
	}
	[HarmonyPatch(typeof(LG_DoorButton))]
	internal static class Inject_LG_DoorButton_Track
	{
		[HarmonyPatch("Setup")]
		[HarmonyPostfix]
		private static void Post_Spawn(LG_DoorButton __instance)
		{
			LG_Objects.AddDoorButton(__instance);
		}
	}
	[HarmonyPatch(typeof(LG_HSUActivator_Core))]
	internal static class Inject_LG_HSUActivator_Track
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Post_Spawn(LG_HSUActivator_Core __instance)
		{
			LG_Objects.AddHSUActivator(__instance);
		}
	}
	[HarmonyPatch(typeof(LG_LabDisplay))]
	internal static class Inject_LG_LabDisplay_Track
	{
		[HarmonyPatch("GenerateText")]
		[HarmonyPatch(new Type[]
		{
			typeof(int),
			typeof(SubComplex)
		})]
		[HarmonyPostfix]
		private static void Post_Spawn(LG_LabDisplay __instance)
		{
			LG_Objects.AddLabDisplay(__instance);
		}
	}
	[HarmonyPatch(typeof(LG_WeakLock))]
	internal static class Inject_LG_WeakLock_Track
	{
		[HarmonyPatch("Setup")]
		[HarmonyPostfix]
		private static void Post_Spawn(LG_WeakLock __instance)
		{
			LG_Objects.AddWeakLock(__instance);
		}
	}
}
namespace AWO.Networking
{
	public interface IStateReplicatorHolder<S> where S : struct
	{
		StateReplicator<S> Replicator { get; }

		void OnStateChange(S oldState, S state, bool isRecall);
	}
	public sealed class ReplicatorHandshake
	{
		public delegate void ClientRequestedSyncDel(SNet_Player requestedPlayer);

		public struct Packet
		{
			public uint replicatorID;

			public PacketAction action;
		}

		public enum PacketAction : byte
		{
			Created,
			Destroyed,
			SyncRequest
		}

		public sealed class Data
		{
			public bool SetupOnHost = false;

			public bool SetupOnClient = false;
		}

		private readonly Dictionary<uint, Data> _Lookup = new Dictionary<uint, Data>();

		public string EventName { get; private set; }

		public bool IsReadyToSync { get; private set; }

		public event ClientRequestedSyncDel OnClientSyncRequested;

		public static ReplicatorHandshake Create(string guid)
		{
			if (string.IsNullOrWhiteSpace(guid))
			{
				return null;
			}
			string text = "RHs" + guid;
			return NetworkAPI.IsEventRegistered(text) ? null : new ReplicatorHandshake(text);
		}

		private ReplicatorHandshake(string eventName)
		{
			EventName = eventName;
			NetworkAPI.RegisterEvent<Packet>(eventName, (Action<ulong, Packet>)OnSyncAction);
		}

		public void Reset()
		{
			_Lookup.Clear();
		}

		private void OnSyncAction(ulong sender, Packet packet)
		{
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			if (!SNet.IsMaster && sender == SNet.Master.Lookup)
			{
				if (packet.action == PacketAction.Created)
				{
					SetHostState(packet.replicatorID, isSetup: true);
				}
				else if (packet.action == PacketAction.Destroyed)
				{
					SetHostState(packet.replicatorID, isSetup: false);
				}
			}
			else
			{
				if (!SNet.IsMaster)
				{
					return;
				}
				if (packet.action == PacketAction.Created)
				{
					SetClientState(packet.replicatorID, isSetup: true);
				}
				else if (packet.action == PacketAction.Destroyed)
				{
					SetClientState(packet.replicatorID, isSetup: false);
				}
				else
				{
					if (packet.action != PacketAction.SyncRequest)
					{
						return;
					}
					SNet_Player requestedPlayer = default(SNet_Player);
					if (!SNet.TryGetPlayer(sender, ref requestedPlayer))
					{
						bool flag = default(bool);
						BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(32, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Cannot find player from sender: ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ulong>(sender);
						}
						Logger.Error(val);
					}
					else
					{
						this.OnClientSyncRequested?.Invoke(requestedPlayer);
					}
				}
			}
		}

		public void UpdateCreated(uint id)
		{
			if (SNet.IsInLobby)
			{
				if (SNet.IsMaster)
				{
					SetHostState(id, isSetup: true);
					NetworkAPI.InvokeEvent<Packet>(EventName, new Packet
					{
						replicatorID = id,
						action = PacketAction.Created
					}, (SNet_ChannelType)2);
				}
				else if (SNet.HasMaster)
				{
					SetClientState(id, isSetup: true);
					NetworkAPI.InvokeEvent<Packet>(EventName, new Packet
					{
						replicatorID = id,
						action = PacketAction.Created
					}, SNet.Master, (SNet_ChannelType)2);
				}
				else
				{
					Logger.Error("Handshake::MASTER is NULL in lobby; This should NOT happen!!!!!!!!!!!!");
				}
			}
			else
			{
				Logger.Error("Handshake::Session Type StateReplicator cannot be created without lobby!");
			}
		}

		public void UpdateDestroyed(uint id)
		{
			if (SNet.IsInLobby)
			{
				if (SNet.IsMaster)
				{
					SetHostState(id, isSetup: true);
					NetworkAPI.InvokeEvent<Packet>(EventName, new Packet
					{
						replicatorID = id,
						action = PacketAction.Destroyed
					}, (SNet_ChannelType)2);
				}
				else if (SNet.HasMaster)
				{
					SetClientState(id, isSetup: true);
					NetworkAPI.InvokeEvent<Packet>(EventName, new Packet
					{
						replicatorID = id,
						action = PacketAction.Destroyed
					}, SNet.Master, (SNet_ChannelType)2);
				}
				else
				{
					Logger.Error("Handshake::MASTER is NULL in lobby; This should NOT happen!!!!!!!!!!!!");
				}
			}
			else
			{
				Logger.Error("Handshake::Session Type StateReplicator cannot be created without lobby!");
			}
		}

		private void SetHostState(uint id, bool isSetup)
		{
			if (_Lookup.TryGetValue(id, out Data value))
			{
				value.SetupOnHost = isSetup;
			}
			else
			{
				_Lookup[id] = new Data
				{
					SetupOnHost = isSetup
				};
			}
			UpdateSyncState(id);
		}

		private void SetClientState(uint id, bool isSetup)
		{
			if (_Lookup.TryGetValue(id, out Data value))
			{
				value.SetupOnClient = isSetup;
			}
			else
			{
				_Lookup[id] = new Data
				{
					SetupOnClient = isSetup
				};
			}
			UpdateSyncState(id);
		}

		private void UpdateSyncState(uint id)
		{
			bool isReadyToSync = IsReadyToSync;
			if (_Lookup.TryGetValue(id, out Data value))
			{
				IsReadyToSync = value.SetupOnHost && value.SetupOnClient;
			}
			else
			{
				IsReadyToSync = false;
			}
			if (IsReadyToSync && isReadyToSync != IsReadyToSync && SNet.HasMaster && !SNet.IsMaster)
			{
				NetworkAPI.InvokeEvent<Packet>(EventName, new Packet
				{
					replicatorID = id,
					action = PacketAction.SyncRequest
				}, SNet.Master, (SNet_ChannelType)2);
			}
		}
	}
	public delegate void OnReceiveDel<S>(ulong sender, uint replicatorID, S newState) where S : struct;
	public static class StatePayloads
	{
		public enum Size
		{
			State4Byte = 4,
			State8Byte = 8,
			State16Byte = 16,
			State32Byte = 32,
			State48Byte = 48,
			State64Byte = 64,
			State80Byte = 80,
			State96Byte = 96,
			State128Byte = 128,
			State196Byte = 196,
			State256Byte = 256
		}

		public static Size GetSizeType(int size)
		{
			Size size2 = Size.State8Byte;
			foreach (object value in Enum.GetValues(typeof(Size)))
			{
				if (size <= (int)value && (int)size2 < (int)value)
				{
					size2 = (Size)value;
					break;
				}
			}
			return size2;
		}

		public static IReplicatorEvent<S> CreateEvent<S>(Size size, string eventName, OnReceiveDel<S> onReceiveCallback) where S : struct
		{
			return size switch
			{
				Size.State4Byte => ReplicatorPayloadWrapper<S, StatePayload4Byte>.Create(eventName, onReceiveCallback), 
				Size.State8Byte => ReplicatorPayloadWrapper<S, StatePayload8Byte>.Create(eventName, onReceiveCallback), 
				Size.State16Byte => ReplicatorPayloadWrapper<S, StatePayload16Byte>.Create(eventName, onReceiveCallback), 
				Size.State32Byte => ReplicatorPayloadWrapper<S, StatePayload32Byte>.Create(eventName, onReceiveCallback), 
				Size.State48Byte => ReplicatorPayloadWrapper<S, StatePayload48Byte>.Create(eventName, onReceiveCallback), 
				Size.State64Byte => ReplicatorPayloadWrapper<S, StatePayload64Byte>.Create(eventName, onReceiveCallback), 
				Size.State80Byte => ReplicatorPayloadWrapper<S, StatePayload80Byte>.Create(eventName, onReceiveCallback), 
				Size.State96Byte => ReplicatorPayloadWrapper<S, StatePayload96Byte>.Create(eventName, onReceiveCallback), 
				Size.State128Byte => ReplicatorPayloadWrapper<S, StatePayload128Byte>.Create(eventName, onReceiveCallback), 
				Size.State196Byte => ReplicatorPayloadWrapper<S, StatePayload196Byte>.Create(eventName, onReceiveCallback), 
				Size.State256Byte => ReplicatorPayloadWrapper<S, StatePayload256Byte>.Create(eventName, onReceiveCallback), 
				_ => null, 
			};
		}

		public static S Get<S>(byte[] bytes, int bytesLength) where S : struct
		{
			int num = Marshal.SizeOf(typeof(S));
			if (num > bytesLength)
			{
				throw new ArgumentException($"StateData Exceed size of {bytesLength} : Unable to Deserialize", "S");
			}
			IntPtr intPtr = Marshal.AllocHGlobal(num);
			Marshal.Copy(bytes, 0, intPtr, num);
			S result = (S)Marshal.PtrToStructure(intPtr, typeof(S));
			Marshal.FreeHGlobal(intPtr);
			return result;
		}

		public static void Set<S>(S stateData, int size, ref byte[] payloadBytes) where S : struct
		{
			int num = Marshal.SizeOf(stateData);
			if (num > size)
			{
				throw new ArgumentException($"StateData Exceed size of {size} : Unable to Serialize", "S");
			}
			byte[] array = new byte[size];
			IntPtr intPtr = Marshal.AllocHGlobal(size);
			Marshal.StructureToPtr(stateData, intPtr, fDeleteOld: false);
			Marshal.Copy(intPtr, array, 0, size);
			Marshal.FreeHGlobal(intPtr);
			payloadBytes = array;
		}
	}
	public interface IReplicatorEvent<S> where S : struct
	{
		string Name { get; }

		bool IsRegistered { get; }

		void Invoke(uint replicatorID, S data);

		void Invoke(uint replicatorID, S data, SNet_ChannelType channelType);

		void Invoke(uint replicatorID, S data, SNet_Player target);

		void Invoke(uint replicatorID, S data, SNet_Player target, SNet_ChannelType channelType);
	}
	public class ReplicatorPayloadWrapper<S, P> : IReplicatorEvent<S> where S : struct where P : struct, IStatePayload
	{
		public string Name { get; private set; }

		public bool IsRegistered { get; private set; } = false;


		public static IReplicatorEvent<S> Create(string eventName, OnReceiveDel<S> onReceiveCallback)
		{
			ReplicatorPayloadWrapper<S, P> replicatorPayloadWrapper = new ReplicatorPayloadWrapper<S, P>();
			replicatorPayloadWrapper.Register(eventName, onReceiveCallback);
			object result;
			if (!replicatorPayloadWrapper.IsRegistered)
			{
				result = null;
			}
			else
			{
				IReplicatorEvent<S> replicatorEvent = replicatorPayloadWrapper;
				result = replicatorEvent;
			}
			return (IReplicatorEvent<S>)result;
		}

		public void Register(string eventName, OnReceiveDel<S> onReceiveCallback)
		{
			OnReceiveDel<S> onReceiveCallback2 = onReceiveCallback;
			if (!IsRegistered && !NetworkAPI.IsEventRegistered(eventName))
			{
				NetworkAPI.RegisterEvent<P>(eventName, (Action<ulong, P>)delegate(ulong sender, P payload)
				{
					onReceiveCallback2?.Invoke(sender, payload.ID, payload.Get<S>());
				});
				IsRegistered = true;
				Name = eventName;
			}
		}

		public void Invoke(uint replicatorID, S data)
		{
			P val = new P
			{
				ID = replicatorID
			};
			val.Set(data);
			NetworkAPI.InvokeEvent<P>(Name, val, (SNet_ChannelType)2);
		}

		public void Invoke(uint replicatorID, S data, SNet_ChannelType channelType)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			P val = new P
			{
				ID = replicatorID
			};
			val.Set(data);
			NetworkAPI.InvokeEvent<P>(Name, val, channelType);
		}

		public void Invoke(uint replicatorID, S data, SNet_Player target)
		{
			P val = new P
			{
				ID = replicatorID
			};
			val.Set(data);
			NetworkAPI.InvokeEvent<P>(Name, val, target, (SNet_ChannelType)2);
		}

		public void Invoke(uint replicatorID, S data, SNet_Player target, SNet_ChannelType channelType)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			P val = new P
			{
				ID = replicatorID
			};
			val.Set(data);
			NetworkAPI.InvokeEvent<P>(Name, val, target, channelType);
		}
	}
	public interface IStatePayload
	{
		uint ID { get; set; }

		S Get<S>() where S : struct;

		void Set<S>(S stateData) where S : struct;
	}
	public struct StatePayload4Byte : IStatePayload
	{
		public const int Size = 4;

		private uint id;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
		public byte[] PayloadBytes;

		public uint ID
		{
			get
			{
				return id;
			}
			set
			{
				id = value;
			}
		}

		public S Get<S>() where S : struct
		{
			return StatePayloads.Get<S>(PayloadBytes, 4);
		}

		public void Set<S>(S stateData) where S : struct
		{
			StatePayloads.Set(stateData, 4, ref PayloadBytes);
		}
	}
	public struct StatePayload8Byte : IStatePayload
	{
		public const int Size = 8;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
		public byte[] PayloadBytes;

		[field: MarshalAs(UnmanagedType.U4)]
		public uint ID { get; set; }

		public S Get<S>() where S : struct
		{
			return StatePayloads.Get<S>(PayloadBytes, 8);
		}

		public void Set<S>(S stateData) where S : struct
		{
			StatePayloads.Set(stateData, 8, ref PayloadBytes);
		}
	}
	public struct StatePayload16Byte : IStatePayload
	{
		public const int Size = 16;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
		public byte[] PayloadBytes;

		[field: MarshalAs(UnmanagedType.U4)]
		public uint ID { get; set; }

		public S Get<S>() where S : struct
		{
			return StatePayloads.Get<S>(PayloadBytes, 16);
		}

		public void Set<S>(S stateData) where S : struct
		{
			StatePayloads.Set(stateData, 16, ref PayloadBytes);
		}
	}
	public struct StatePayload32Byte : IStatePayload
	{
		public const int Size = 32;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
		public byte[] PayloadBytes;

		[field: MarshalAs(UnmanagedType.U4)]
		public uint ID { get; set; }

		public S Get<S>() where S : struct
		{
			return StatePayloads.Get<S>(PayloadBytes, 32);
		}

		public void Set<S>(S stateData) where S : struct
		{
			StatePayloads.Set(stateData, 32, ref PayloadBytes);
		}
	}
	public struct StatePayload48Byte : IStatePayload
	{
		public const int Size = 48;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 48)]
		public byte[] PayloadBytes;

		[field: MarshalAs(UnmanagedType.U4)]
		public uint ID { get; set; }

		public S Get<S>() where S : struct
		{
			return StatePayloads.Get<S>(PayloadBytes, 48);
		}

		public void Set<S>(S stateData) where S : struct
		{
			StatePayloads.Set(stateData, 48, ref PayloadBytes);
		}
	}
	public struct StatePayload64Byte : IStatePayload
	{
		public const int Size = 64;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
		public byte[] PayloadBytes;

		[field: MarshalAs(UnmanagedType.U4)]
		public uint ID { get; set; }

		public S Get<S>() where S : struct
		{
			return StatePayloads.Get<S>(PayloadBytes, 64);
		}

		public void Set<S>(S stateData) where S : struct
		{
			StatePayloads.Set(stateData, 64, ref PayloadBytes);
		}
	}
	public struct StatePayload80Byte : IStatePayload
	{
		public const int Size = 80;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 80)]
		public byte[] PayloadBytes;

		[field: MarshalAs(UnmanagedType.U4)]
		public uint ID { get; set; }

		public S Get<S>() where S : struct
		{
			return StatePayloads.Get<S>(PayloadBytes, 80);
		}

		public void Set<S>(S stateData) where S : struct
		{
			StatePayloads.Set(stateData, 80, ref PayloadBytes);
		}
	}
	public struct StatePayload96Byte : IStatePayload
	{
		public const int Size = 96;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 96)]
		public byte[] PayloadBytes;

		[field: MarshalAs(UnmanagedType.U4)]
		public uint ID { get; set; }

		public S Get<S>() where S : struct
		{
			return StatePayloads.Get<S>(PayloadBytes, 96);
		}

		public void Set<S>(S stateData) where S : struct
		{
			StatePayloads.Set(stateData, 96, ref PayloadBytes);
		}
	}
	public struct StatePayload128Byte : IStatePayload
	{
		public const int Size = 128;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
		public byte[] PayloadBytes;

		[field: MarshalAs(UnmanagedType.U4)]
		public uint ID { get; set; }

		public S Get<S>() where S : struct
		{
			return StatePayloads.Get<S>(PayloadBytes, 128);
		}

		public void Set<S>(S stateData) where S : struct
		{
			StatePayloads.Set(stateData, 128, ref PayloadBytes);
		}
	}
	public struct StatePayload196Byte : IStatePayload
	{
		public const int Size = 196;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 196)]
		public byte[] PayloadBytes;

		[field: MarshalAs(UnmanagedType.U4)]
		public uint ID { get; set; }

		public S Get<S>() where S : struct
		{
			return StatePayloads.Get<S>(PayloadBytes, 196);
		}

		public void Set<S>(S stateData) where S : struct
		{
			StatePayloads.Set(stateData, 196, ref PayloadBytes);
		}
	}
	public struct StatePayload256Byte : IStatePayload
	{
		public const int Size = 256;

		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
		public byte[] PayloadBytes;

		[field: MarshalAs(UnmanagedType.U4)]
		public uint ID { get; set; }

		public S Get<S>() where S : struct
		{
			return StatePayloads.Get<S>(PayloadBytes, 256);
		}

		public void Set<S>(S stateData) where S : struct
		{
			StatePayloads.Set(stateData, 256, ref PayloadBytes);
		}
	}
	public enum LifeTimeType
	{
		Permanent,
		Session
	}
	public sealed class StateReplicator<S> where S : struct
	{
		private readonly Dictionary<eBufferType, S> _RecallStateSnapshots = new Dictionary<eBufferType, S>();

		public static readonly string Name;

		public static readonly string HashName;

		public static readonly string ClientRequestEventName;

		public static readonly string HostSetStateEventName;

		public static readonly string HostSetRecallStateEventName;

		public static readonly int StateSize;

		public static readonly StatePayloads.Size StateSizeType;

		private static readonly IReplicatorEvent<S> _C_RequestEvent;

		private static readonly IReplicatorEvent<S> _H_SetStateEvent;

		private static readonly IReplicatorEvent<S> _H_SetRecallStateEvent;

		private static readonly ReplicatorHandshake _Handshake;

		private static readonly Dictionary<uint, StateReplicator<S>> _Replicators;

		public bool IsValid => ID != 0;

		public bool IsInvalid => ID == 0;

		public uint ID { get; private set; }

		public LifeTimeType LifeTime { get; private set; }

		public IStateReplicatorHolder<S> Holder { get; private set; }

		public S State { get; private set; }

		public bool ClientSendStateAllowed { get; set; } = true;


		public bool CanSendToClient => SNet.IsInLobby && SNet.IsMaster;

		public bool CanSendToHost => SNet.IsInLobby && !SNet.IsMaster && SNet.HasMaster && ClientSendStateAllowed;

		public event Action<S, S, bool> OnStateChanged;

		public void SetState(S state)
		{
			if (!IsInvalid)
			{
				DoSync(state);
			}
		}

		public void SetStateUnsynced(S state)
		{
			if (!IsInvalid)
			{
				State = state;
			}
		}

		public void Unload()
		{
			if (IsValid)
			{
				_Replicators.Remove(ID);
				_RecallStateSnapshots.Clear();
				_Handshake.UpdateDestroyed(ID);
				ID = 0u;
			}
		}

		private void DoSync(S newState)
		{
			if (!IsInvalid)
			{
				if (CanSendToClient)
				{
					_H_SetStateEvent.Invoke(ID, newState);
					Internal_ChangeState(newState, isRecall: false);
				}
				else if (CanSendToHost)
				{
					_C_RequestEvent.Invoke(ID, newState, SNet.Master);
				}
			}
		}

		private void Internal_ChangeState(S state, bool isRecall)
		{
			if (!IsInvalid)
			{
				S state2 = State;
				State = state;
				this.OnStateChanged?.Invoke(state2, state, isRecall);
				Holder?.OnStateChange(state2, state, isRecall);
			}
		}

		private void SendDropInState(SNet_Player target)
		{
			if (!IsInvalid)
			{
				if ((Object)(object)target == (Object)null)
				{
					Logger.Error("SendDropInState::Target was null??");
				}
				else
				{
					_H_SetRecallStateEvent.Invoke(ID, State, target);
				}
			}
		}

		public void ClearAllRecallSnapshot()
		{
			if (!IsInvalid)
			{
				_RecallStateSnapshots.Clear();
			}
		}

		private void SaveSnapshot(eBufferType type)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!IsInvalid)
			{
				_RecallStateSnapshots[type] = State;
			}
		}

		private void RestoreSnapshot(eBufferType type)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (IsInvalid || !CanSendToClient)
			{
				return;
			}
			if (_RecallStateSnapshots.TryGetValue(type, out var value))
			{
				_H_SetRecallStateEvent.Invoke(ID, value);
				Internal_ChangeState(value, isRecall: true);
				return;
			}
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(29, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("RestoreSnapshot");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("::There was no snapshot for ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<eBufferType>(type);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("?");
			}
			Logger.Error(val);
		}

		static StateReplicator()
		{
			_Replicators = new Dictionary<uint, StateReplicator<S>>();
			Name = typeof(S).Name;
			StateSize = Marshal.SizeOf(typeof(S));
			StateSizeType = StatePayloads.GetSizeType(StateSize);
			using MD5 mD = MD5.Create();
			byte[] inArray = mD.ComputeHash(Encoding.UTF8.GetBytes(typeof(S).FullName));
			HashName = Convert.ToBase64String(inArray);
			ClientRequestEventName = "SRs" + Name + "-" + HashName;
			HostSetStateEventName = "SRr" + Name + "-" + HashName;
			HostSetRecallStateEventName = "SRre" + Name + "-" + HashName;
			_C_RequestEvent = StatePayloads.CreateEvent<S>(StateSizeType, ClientRequestEventName, ClientRequestEventCallback);
			_H_SetStateEvent = StatePayloads.CreateEvent<S>(StateSizeType, HostSetStateEventName, HostSetStateEventCallback);
			_H_SetRecallStateEvent = StatePayloads.CreateEvent<S>(StateSizeType, HostSetRecallStateEventName, HostSetRecallStateEventCallback);
			_Handshake = ReplicatorHandshake.Create(Name + "-" + HashName);
			_Handshake.OnClientSyncRequested += ClientSyncRequested;
			Inject_SNet_Capture.OnBufferCapture += BufferStored;
			Inject_SNet_Capture.OnBufferRecalled += BufferRecalled;
			LevelEvents.OnLevelCleanup += LevelCleanedUp;
		}

		private static void ClientSyncRequested(SNet_Player requestedPlayer)
		{
			foreach (StateReplicator<S> value in _Replicators.Values)
			{
				if (value.IsValid)
				{
					value.SendDropInState(requestedPlayer);
				}
			}
		}

		private static void BufferStored(eBufferType type)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			foreach (StateReplicator<S> value in _Replicators.Values)
			{
				if (value.IsValid)
				{
					value.SaveSnapshot(type);
				}
			}
		}

		private static void BufferRecalled(eBufferType type)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			foreach (StateReplicator<S> value in _Replicators.Values)
			{
				if (value.IsValid)
				{
					value.RestoreSnapshot(type);
				}
			}
		}

		private static void LevelCleanedUp()
		{
			UnloadSessionReplicator();
		}

		private StateReplicator()
		{
		}

		public static StateReplicator<S> Create(uint replicatorID, S startState, LifeTimeType lifeTime, IStateReplicatorHolder<S> holder = null)
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			if (replicatorID == 0)
			{
				Logger.Error("Replicator ID 0 is reserved for empty!");
				return null;
			}
			if (_Replicators.ContainsKey(replicatorID))
			{
				Logger.Error("Replicator ID has already assigned!");
				return null;
			}
			StateReplicator<S> stateReplicator = new StateReplicator<S>
			{
				ID = replicatorID,
				LifeTime = lifeTime,
				Holder = holder,
				State = startState
			};
			switch (lifeTime)
			{
			case LifeTimeType.Permanent:
				Logger.Debug("LifeTime is Permanent :: Handshaking is disabled!");
				break;
			case LifeTimeType.Session:
				_Handshake.UpdateCreated(replicatorID);
				break;
			default:
			{
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(22, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("LifeTime is invalid!: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<LifeTimeType>(lifeTime);
				}
				Logger.Error(val);
				return null;
			}
			}
			_Replicators[replicatorID] = stateReplicator;
			return stateReplicator;
		}

		public static void UnloadSessionReplicator()
		{
			List<uint> list = new List<uint>();
			foreach (StateReplicator<S> value in _Replicators.Values)
			{
				if (value.LifeTime == LifeTimeType.Session)
				{
					list.Add(value.ID);
					value.Unload();
				}
			}
			foreach (uint item in list)
			{
				_Replicators.Remove(item);
			}
			_Handshake.Reset();
		}

		private static void ClientRequestEventCallback(ulong sender, uint replicatorID, S newState)
		{
			if (SNet.IsMaster && _Replicators.TryGetValue(replicatorID, out StateReplicator<S> value))
			{
				value.SetState(newState);
			}
		}

		private static void HostSetStateEventCallback(ulong sender, uint replicatorID, S newState)
		{
			if (SNet.HasMaster && SNet.Master.Lookup == sender && _Replicators.TryGetValue(replicatorID, out StateReplicator<S> value))
			{
				value.Internal_ChangeState(newState, isRecall: false);
			}
		}

		private static void HostSetRecallStateEventCallback(ulong sender, uint replicatorID, S newState)
		{
			if (SNet.HasMaster && SNet.Master.Lookup == sender && _Replicators.TryGetValue(replicatorID, out StateReplicator<S> value))
			{
				value.Internal_ChangeState(newState, isRecall: true);
			}
		}
	}
}
namespace AWO.Networking.CommonReplicator.Inject
{
	[HarmonyPatch(typeof(WardenObjectiveManager), "CheckExpeditionFailed")]
	internal static class Inject_LevelFailCheck
	{
		public static bool LevelFailAllowed = true;

		public static bool LevelFailWhenAnyPlayerDown = false;

		private static void Postfix(ref bool __result)
		{
			if (!LevelFailAllowed)
			{
				__result = false;
			}
			else if (LevelFailWhenAnyPlayerDown && HasAnyDownedPlayer())
			{
				__result = true;
			}
		}

		private static bool HasAnyDownedPlayer()
		{
			bool result = false;
			int count = PlayerManager.PlayerAgentsInLevel.Count;
			if (count <= 0)
			{
				return false;
			}
			for (int i = 0; i < count; i++)
			{
				PlayerAgent val = PlayerManager.PlayerAgentsInLevel[i];
				if (!((Agent)val).Alive)
				{
					result = true;
				}
			}
			return result;
		}
	}
}
namespace AWO.Networking.Inject
{
	[HarmonyPatch(typeof(SNet_Capture))]
	internal static class Inject_SNet_Capture
	{
		public static event Action<eBufferType> OnBufferCapture;

		public static event Action<eBufferType> OnBufferRecalled;

		[HarmonyPatch("TriggerCapture")]
		[HarmonyPrefix]
		private static void Pre_TriggerCapture(SNet_Capture __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			eBufferType primedBufferType = __instance.PrimedBufferType;
			Inject_SNet_Capture.OnBufferCapture?.Invoke(primedBufferType);
		}

		[HarmonyPatch("RecallBuffer")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		private static void Post_RecallBuffer(SNet_Capture __instance, eBufferType bufferType)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.IsRecalling)
			{
				Inject_SNet_Capture.OnBufferRecalled?.Invoke(bufferType);
			}
		}
	}
}
namespace AWO.Modules.WOE
{
	public static class WardenObjectiveExt
	{
		private static readonly Dictionary<eWardenObjectiveType, Type> _DTOTypes;

		private static readonly List<WOE_ContextBase> _ActiveContexts;

		static WardenObjectiveExt()
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Expected O, but got Unknown
			_DTOTypes = new Dictionary<eWardenObjectiveType, Type>();
			_ActiveContexts = new List<WOE_ContextBase>();
			IEnumerable<Type> enumerable = from x in typeof(WOE_ContextBase).Assembly.GetTypes()
				where !x.IsAbstract
				where x.IsAssignableTo(typeof(WOE_ContextBase))
				select x;
			bool flag = default(bool);
			foreach (Type item in enumerable)
			{
				WOE_ContextBase wOE_ContextBase = (WOE_ContextBase)Activator.CreateInstance(item);
				if (_DTOTypes.TryGetValue(wOE_ContextBase.TargetType, out Type _))
				{
					Logger.Error("Duplicate TargetType Detected!");
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(14, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("With '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item.Name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' and '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(wOE_ContextBase.GetType().Name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
					}
					Logger.Error(val);
				}
				else if (!wOE_ContextBase.DataType.IsAssignableTo(typeof(WOE_DataBase)))
				{
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(41, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item.Name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" does not have valid ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("DataType");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (not derived from ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("WOE_DataBase");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
					}
					Logger.Error(val);
				}
				else
				{
					_DTOTypes[wOE_ContextBase.TargetType] = item;
				}
			}
			WOEvents.OnSetup += ObjectiveSetup;
			LevelEvents.OnLevelCleanup += LevelCleanup;
		}

		internal static void Initialize()
		{
		}

		private static void ObjectiveSetup(LG_LayerType layer, int chainIndex)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			WardenObjectiveDataBlock val = default(WardenObjectiveDataBlock);
			Type value;
			if (!WardenObjectiveManager.TryGetWardenObjectiveDataForLayer(layer, chainIndex, ref val))
			{
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(44, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<LG_LayerType>(layer);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" Layer (CI: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(chainIndex);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(") does not have ObjectiveData!!!");
				}
				Logger.Error(val2);
			}
			else if (_DTOTypes.TryGetValue(val.Type, out value))
			{
				WOE_ContextBase wOE_ContextBase = (WOE_ContextBase)Activator.CreateInstance(value);
				wOE_ContextBase.Setup(layer, chainIndex);
				_ActiveContexts.Add(wOE_ContextBase);
			}
		}

		private static void LevelCleanup()
		{
			foreach (WOE_ContextBase activeContext in _ActiveContexts)
			{
				activeContext.OnLevelCleanup();
			}
			_ActiveContexts.Clear();
		}
	}
	internal abstract class WOE_ContextBase
	{
		public abstract eWardenObjectiveType TargetType { get; }

		public abstract Type DataType { get; }

		protected WOE_DataBase Data { get; private set; }

		protected LG_LayerType Layer { get; private set; }

		protected int ChainIndex { get; private set; }

		public void Setup(LG_LayerType layer, int chainIndex)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			Layer = layer;
			ChainIndex = chainIndex;
		}

		public virtual void OnSetup()
		{
		}

		public virtual void OnBuildDone()
		{
		}

		public virtual void OnBuildDoneLate()
		{
		}

		public virtual void OnLevelCleanup()
		{
		}
	}
	internal abstract class WOE_DataBase
	{
		public uint ObjectiveID { get; set; }

		public WardenObjectiveDataBlock GameData { get; set; }
	}
}
namespace AWO.Modules.WOE.Objectives.Uplinks
{
	internal sealed class WOE_UplinkContext : WOE_ContextBase
	{
		public override eWardenObjectiveType TargetType => (eWardenObjectiveType)8;

		public override Type DataType => typeof(WOE_UplinkData);
	}
	internal sealed class WOE_UplinkData : WOE_DataBase
	{
		public UplinkCodeBehaviour[] CodeBehaviours { get; set; } = Array.Empty<UplinkCodeBehaviour>();

	}
	internal sealed class UplinkCodeBehaviour
	{
		public bool ShowCodesOnTerminal { get; set; } = false;


		public bool ShowCodesOnHUD { get; set; } = true;


		public bool ShowCodeToOtherTerminal { get; set; } = true;


		public TerminalZoneSelectionData TerminalZone { get; set; } = new TerminalZoneSelectionData();


		public TerminalOutput[] StartOutputs { get; set; } = Array.Empty<TerminalOutput>();


		public TerminalOutput[] EndOutputs { get; set; } = Array.Empty<TerminalOutput>();


		public WardenObjectiveEventData[] EventsOnStart { get; set; } = Array.Empty<WardenObjectiveEventData>();


		public WardenObjectiveEventData[] EventsOnEnd { get; set; } = Array.Empty<WardenObjectiveEventData>();

	}
}
namespace AWO.Modules.WOE.Objectives.ReactorStartups
{
	internal sealed class WOE_ReactorStartupContext : WOE_ContextBase
	{
		public override eWardenObjectiveType TargetType => (eWardenObjectiveType)1;

		public override Type DataType => typeof(WOE_ReactorStartupData);
	}
	internal enum ReactorWavePuzzleType
	{
		Default,
		CustomLock,
		UseCommand_OnMainTerminal,
		UseCommand_InZone,
		PowerGenerator_InZone
	}
	internal sealed class WOE_ReactorStartupData : WOE_DataBase
	{
		public bool RemoveMainStartupCommand { get; set; } = false;


		public bool RemoveMainVerifyCommand { get; set; } = false;


		public ScriptedWaveData[] WaveDatas { get; set; } = Array.Empty<ScriptedWaveData>();


		public ReactorWavePuzzleData[] WavePuzzles { get; set; } = Array.Empty<ReactorWavePuzzleData>();

	}
	internal enum SettingWarpMode
	{
		Clamped,
		Repeat,
		PingPong
	}
	internal sealed class ScriptedWaveData
	{
		public float[] IntroDuration { get; set; } = Array.Empty<float>();


		public SettingWarpMode IntroDurationWarpMode { get; set; } = SettingWarpMode.Clamped;


		public float[] WaveDuration { get; set; } = Array.Empty<float>();


		public SettingWarpMode WaveDurationWarpMode { get; set; } = SettingWarpMode.Clamped;


		public string[][] WaveInstructions { get; set; } = Array.Empty<string[]>();


		public SettingWarpMode WaveInstructionsWarpMode { get; set; } = SettingWarpMode.Clamped;

	}
	internal sealed class ReactorWavePuzzleData
	{
		public ReactorWavePuzzleType Type { get; set; } = ReactorWavePuzzleType.Default;


		public bool ShowBeacon { get; set; } = false;


		public string BeaconText { get; set; } = "Auxiliary Terminal";


		public Color BeaconColor { get; set; } = Color.magenta;


		public string Command { get; set; } = "REACTOR_CONTINUE";


		public string CommandDescription { get; set; } = "CONTINUE REACTOR STARTUP PROCESS";


		public bool ForceJumpWaveWhenSolved { get; set; } = true;

	}
}
namespace AWO.Modules.WOE.Objectives.GenClusters
{
	internal sealed class WOE_GenClusterContext : WOE_ContextBase
	{
		public override eWardenObjectiveType TargetType => (eWardenObjectiveType)9;

		public override Type DataType => typeof(int);
	}
}
namespace AWO.Modules.WOE.JsonInjects
{
	internal class ObjectiveDataHandler : Il2CppJsonReferenceTypeHandler<WardenObjectiveDataBlock>
	{
		public override void OnRead(in Object result, in JToken jToken)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Invalid comparison between Unknown and I4
			if ((int)jToken.Type == 1)
			{
				JObject val = (JObject)jToken;
				JToken val2 = default(JToken);
				if (val.TryGetValue("woeEnabled", ref val2) && (int)val2.Type == 9 && (bool)val2)
				{
					WardenObjectiveDataBlock val3 = ((Il2CppObjectBase)result).Cast<WardenObjectiveDataBlock>();
				}
			}
		}
	}
}
namespace AWO.Modules.WEE
{
	public static class WardenEventExt
	{
		internal static readonly Dictionary<WEE_Type, BaseEvent> _EventsToTrigger;

		static WardenEventExt()
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			_EventsToTrigger = new Dictionary<WEE_Type, BaseEvent>();
			IEnumerable<Type> enumerable = from x in typeof(BaseEvent).Assembly.GetTypes()
				where !x.IsAbstract
				where x.IsAssignableTo(typeof(BaseEvent))
				select x;
			bool flag = default(bool);
			foreach (Type item in enumerable)
			{
				BaseEvent baseEvent = (BaseEvent)Activator.CreateInstance(item);
				if (_EventsToTrigger.TryGetValue(baseEvent.EventType, out BaseEvent value))
				{
					Logger.Error("Duplicate EventType Detected!");
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(14, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("With '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(value.Name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' and '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(baseEvent.Name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
					}
					Logger.Error(val);
				}
				else
				{
					baseEvent.Setup();
					_EventsToTrigger[baseEvent.EventType] = baseEvent;
				}
			}
		}

		internal static void Initialize()
		{
			ClassInjector.RegisterTypeInIl2Cpp<ScanPositionReplicator>();
			ClassInjector.RegisterTypeInIl2Cpp<ZoneLightReplicator>();
			JsonInjector.SetConverter<eWardenObjectiveEventType>((Il2CppJsonUnmanagedTypeConverter<eWardenObjectiveEventType>)new EventTypeConverter());
			JsonInjector.AddHandler<WardenObjectiveEventData>((Il2CppJsonReferenceTypeHandler<WardenObjectiveEventData>)(object)new EventDataHandler());
			JsonInjector.AddHandler<WorldEventFromSourceData>((Il2CppJsonReferenceTypeHandler<WorldEventFromSourceData>)(object)new TriggerDataHandler());
			WEE_EnumInjector.Inject();
			Detour_ExecuteEvent.Patch();
		}

		internal static void HandleEvent(WEE_Type type, WardenObjectiveEventData e, float currentDuration)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			bool flag = default(bool);
			BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(36, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("We got Type ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<WEE_Type>(type);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" on WardenEventExt event");
			}
			Logger.Debug(val);
			WEE_EventData wEEData = e.GetWEEData();
			if (wEEData != null)
			{
				CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(Handle(type, wEEData, currentDuration)), (Action)null);
				return;
			}
			BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(71, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("WardenEvent Type is Extension (");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<WEE_Type>(type);
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(") But it's not registered to dataholder!");
			}
			Logger.Error(val2);
		}

		private static IEnumerator Handle(WEE_Type type, WEE_EventData e, float currentDuration)
		{
			float delay = Mathf.Max(e.Delay - currentDuration, 0f);
			if (delay > 0f)
			{
				yield return (object)new WaitForSeconds(delay);
			}
			if (WorldEventManager.GetCondition(e.Condition.ConditionIndex) != e.Condition.IsTrue)
			{
				yield break;
			}
			WardenObjectiveManager.DisplayWardenIntel(e.Layer, e.WardenIntel.ToLocalizedText());
			if (e.DialogueID != 0)
			{
				PlayerDialogManager.WantToStartDialog(e.DialogueID, -1, false, false);
			}
			if (e.SoundID != 0)
			{
				WardenObjectiveManager.Current.m_sound.Post(e.SoundID, true);
				string line = e.SoundSubtitle.ToString();
				if (!string.IsNullOrWhiteSpace(line))
				{
					GuiManager.PlayerLayer.ShowMultiLineSubtitle(line);
				}
			}
			if (e.SubObjective.DoUpdate)
			{
				WardenObjectiveManager.UpdateSyncCustomSubObjective(e.SubObjective.CustomSubObjectiveHeader.ToLocalizedText(), e.SubObjective.CustomSubObjective.ToLocalizedText());
			}
			if (e.Fog.DoUpdate)
			{
				EnvironmentStateManager.AttemptStartFogTransition(e.Fog.FogSetting, e.Fog.FogTransitionDuration, e.DimensionIndex);
			}
			if (_EventsToTrigger.TryGetValue(type, out BaseEvent eventInstance))
			{
				eventInstance.Trigger(e);
				yield break;
			}
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(26, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<WEE_Type>(type);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" does not exist in lookup!");
			}
			Logger.Error(val);
		}
	}
	internal static class WEE_EnumInjector
	{
		public const int ExtendedIndex = 10000;

		private static readonly Dictionary<string, object> _EventTypes;

		private static int _CurrentIndex;

		static WEE_EnumInjector()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			_EventTypes = new Dictionary<string, object>();
			_CurrentIndex = 0;
			WEE_Type[] values = Enum.GetValues<WEE_Type>();
			bool flag = default(bool);
			for (int i = 0; i < values.Length; i++)
			{
				WEE_Type wEE_Type = values[i];
				string text = wEE_Type.ToString();
				AddEvent(text);
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(22, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Injecting EWOEvent: '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
				}
				Logger.Debug(val);
			}
		}

		private static void AddEvent(string name)
		{
			_EventTypes[name] = _CurrentIndex + 10000;
			_CurrentIndex++;
		}

		internal static void Inject()
		{
			EnumInjector.InjectEnumValues<eWardenObjectiveEventType>(_EventTypes);
		}
	}
	public sealed class WEE_EventData
	{
		public WEE_Type Type { get; set; }

		public WorldEventConditionPair Condition { get; set; } = new WorldEventConditionPair
		{
			ConditionIndex = -1,
			IsTrue = false
		};


		public eWardenObjectiveEventTrigger Trigger { get; set; } = (eWardenObjectiveEventTrigger)0;


		public uint ChainPuzzle { get; set; } = 0u;


		public bool UseStaticBioscanPoints { get; set; } = false;


		public LG_LayerType Layer { get; set; } = (LG_LayerType)0;


		public eDimensionIndex DimensionIndex { get; set; } = (eDimensionIndex)0;


		public eLocalZoneIndex LocalIndex { get; set; } = (eLocalZoneIndex)0;


		public Vector3 Position { get; set; } = Vector3.zero;


		public float Delay { get; set; } = 0f;


		public float Duration { get; set; } = 0f;


		public LocaleText WardenIntel { get; set; } = LocaleText.Empty;


		public uint SoundID { get; set; } = 0u;


		public LocaleText SoundSubtitle { get; set; } = LocaleText.Empty;


		public uint DialogueID { get; set; } = 0u;


		public int Count { get; set; } = 0;


		public bool Enabled { get; set; } = true;


		public int SpecialNumber { get; set; } = -1;


		public LocaleText SpecialText { get; set; } = LocaleText.Empty;


		public WEE_SubObjectiveData SubObjective { get; set; } = new WEE_SubObjectiveData();


		public WEE_UpdateFogData Fog { get; set; } = new WEE_UpdateFogData();


		public bool CleanUpEnemiesBehind { get; set; } = true;


		public WEE_ReactorEventData Reactor { get; set; } = new WEE_ReactorEventData();


		public WEE_CountdownData Countdown { get; set; } = new WEE_CountdownData();


		public WEE_ZoneLightData SetZoneLight { get; set; } = new WEE_ZoneLightData();


		public WEE_CleanupEnemiesData CleanupEnemies { get; set; } = new WEE_CleanupEnemiesData();


		public WEE_SpawnHibernateData SpawnHibernates { get; set; } = new WEE_SpawnHibernateData();


		public WEE_SpawnScoutData SpawnScouts { get; set; } = new WEE_SpawnScoutData();


		public WEE_AddTerminalCommand AddTerminalCommand { get; set; } = new WEE_AddTerminalCommand();


		public WEE_HideTerminalCommand HideTerminalCommand { get; set; } = new WEE_HideTerminalCommand();


		public WEE_UnhideTerminalCommand UnhideTerminalCommand { get; set; } = new WEE_UnhideTerminalCommand();


		public WEE_NestedEvent NestedEvent { get; set; } = new WEE_NestedEvent();


		public WEE_StartEventLoop StartEventLoop { get; set; } = new WEE_StartEventLoop();


		public WEE_StartEventLoop EventLoop
		{
			get
			{
				return StartEventLoop;
			}
			set
			{
				StartEventLoop = value;
			}
		}

		public WEE_TeleportPlayer TeleportPlayer { get; set; } = new WEE_TeleportPlayer();


		public WEE_InfectPlayer InfectPlayer { get; set; } = new WEE_InfectPlayer();


		public WEE_DamagePlayer DamagePlayer { get; set; } = new WEE_DamagePlayer();


		public WEE_RevivePlayer RevivePlayer { get; set; } = new WEE_RevivePlayer();


		public WEE_AdjustTimer AdjustTimer { get; set; } = new WEE_AdjustTimer();


		public WEE_CountupData Countup { get; set; } = new WEE_CountupData();


		public WEE_ShakeScreen CameraShake { get; set; } = new WEE_ShakeScreen();


		public WEE_StartPortalMachine Portal { get; set; } = new WEE_StartPortalMachine();


		public WEE_SetSuccessScreen SuccessScreen { get; set; } = new WEE_SetSuccessScreen();


		public List<WEE_SubObjectiveData> MultiProgression { get; set; } = new List<WEE_SubObjectiveData>();


		public WEE_PlayWaveDistantRoar WaveRoarSound { get; set; } = new WEE_PlayWaveDistantRoar();


		public WEE_CustomHudText CustomHudText { get; set; } = new WEE_CustomHudText();


		public WEE_SpecialHudTimer SpecialHudTimer { get; set; } = new WEE_SpecialHudTimer();


		public WardenObjectiveEventData CreateDummyEventData()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			return new WardenObjectiveEventData
			{
				Type = (eWardenObjectiveEventType)Type,
				ChainPuzzle = ChainPuzzle,
				UseStaticBioscanPoints = UseStaticBioscanPoints,
				Trigger = Trigger,
				Condition = Condition
			};
		}
	}
	public sealed class WEE_UpdateFogData
	{
		public bool DoUpdate { get; set; } = false;


		public uint FogSetting { get; set; }

		public float FogTransitionDuration { get; set; }
	}
	public sealed class WEE_SubObjectiveData
	{
		public LG_LayerType Layer = (LG_LayerType)0;

		public bool DoUpdate { get; set; } = false;


		public LocaleText CustomSubObjectiveHeader { get; set; } = LocaleText.Empty;


		public LocaleText CustomSubObjective { get; set; } = LocaleText.Empty;


		public uint Index { get; set; } = 0u;


		public LocaleText OverrideTag { get; set; } = LocaleText.Empty;

	}
	public sealed class WEE_ReactorEventData
	{
		public enum WaveState
		{
			Intro,
			Wave,
			Verify
		}

		public WaveState State { get; set; } = WaveState.Intro;


		public int Wave { get; set; } = 1;


		public float Progress { get; set; } = 0f;

	}
	public sealed class WEE_DoorInteractionData
	{
		public bool LockdownState { get; set; }

		public string LockdownMessage { get; set; }
	}
	public sealed class WEE_CountdownData
	{
		public float Duration { get; set; } = 0f;


		public LocaleText TimerText { get; set; } = LocaleText.Empty;


		public Color TimerColor { get; set; } = Color.red;


		public List<EventsOnTimerProgress> EventsOnProgress { get; set; } = new List<EventsOnTimerProgress>();


		public WardenObjectiveEventData[] EventsOnDone { get; set; } = Array.Empty<WardenObjectiveEventData>();

	}
	public sealed class WEE_CleanupEnemiesData
	{
		public enum CleanUpType
		{
			Kill,
			Despawn
		}

		public CleanUpType Type { get; set; } = CleanUpType.Despawn;


		public int AreaIndex { get; set; } = -1;


		public bool IncludeHibernate { get; set; } = true;


		public bool IncludeAggressive { get; set; } = true;


		public bool IncludeScout { get; set; } = true;


		public uint[] ExcludeEnemyID { get; set; } = Array.Empty<uint>();


		public uint[] IncludeOnlyID { get; set; } = Array.Empty<uint>();


		public void DoClear(AIG_CourseNode node)
		{
			//IL_0072: 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_0079: 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_0092: Expected I4, but got Unknown
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			if (!SNet.IsMaster || node == null || node.m_enemiesInNode == null)
			{
				return;
			}
			List<EnemyAgent> list = new List<EnemyAgent>();
			list.Clear();
			Enumerator<EnemyAgent> enumerator = node.m_enemiesInNode.GetEnumerator();
			while (enumerator.MoveNext())
			{
				EnemyAgent current = enumerator.Current;
				list.Add(current);
			}
			foreach (EnemyAgent item in list)
			{
				AgentMode mode = ((AgentAI)item.AI).Mode;
				if ((mode - 1) switch
				{
					0 => IncludeAggressive, 
					2 => IncludeScout, 
					3 => IncludeHibernate, 
					_ => true, 
				} && !ExcludeEnemyID.Contains(item.EnemyDataID) && (IncludeOnlyID.Length == 0 || IncludeOnlyID.Contains(item.EnemyDataID)))
				{
					switch (Type)
					{
					case CleanUpType.Despawn:
						((Agent)item).m_replicator.Despawn();
						break;
					case CleanUpType.Kill:
						item.Damage.IsImortal = false;
						item.Damage.BulletDamage(((Dam_SyncedDamageBase)item.Damage).DamageMax, (Agent)null, default(Vector3), default(Vector3), default(Vector3), false, 0, 1f, 1f, 0u);
						break;
					}
				}
			}
		}
	}
	public sealed class WEE_ZoneLightData
	{
		public enum ModifierType : byte
		{
			RevertToOriginal,
			SetZoneLightData
		}

		public ModifierType Type { get; set; } = ModifierType.RevertToOriginal;


		public uint LightDataID { get; set; }

		public float TransitionDuration { get; set; } = 0.5f;


		public int Seed { get; set; } = 0;

	}
	public sealed class WEE_SpawnHibernateData
	{
		public int AreaIndex { get; set; } = -1;


		public uint EnemyID { get; set; } = 0u;


		public uint Count { get; set; } = 1u;


		public Vector3 Position { get; set; } = Vector3.zero;


		public Vector3 Rotation { get; set; } = Vector3.zero;

	}
	public sealed class WEE_SpawnScoutData
	{
		public int AreaIndex { get; set; } = -1;


		public eEnemyGroupType GroupType { get; set; }

		public eEnemyRoleDifficulty Difficulty { get; set; }

		public uint Count { get; set; } = 1u;

	}
	public enum FilterMode
	{
		Exclude,
		Include
	}
	public sealed class WEE_AddTerminalCommand
	{
		public int TerminalIndex { get; set; } = 0;


		public int CommandNumber { get; set; } = 6;


		public string Command { get; set; } = "";


		public LocaleText CommandDesc { get; set; } = LocaleText.Empty;


		public TERM_CommandRule SpecialCommandRule { get; set; } = (TERM_CommandRule)0;


		public WardenObjectiveEventData[] CommandEvents { get; set; } = Array.Empty<WardenObjectiveEventData>();


		public TerminalOutput[] PostCommandOutputs { get; set; } = Array.Empty<TerminalOutput>();

	}
	public sealed class WEE_HideTerminalCommand
	{
		public int TerminalIndex { get; set; } = 0;


		public TERM_Command CommandEnum { get; set; } = (TERM_Command)0;


		public int CommandNumber { get; set; } = 0;


		public bool DeleteCommand { get; set; } = false;

	}
	public sealed class WEE_UnhideTerminalCommand
	{
		public int TerminalIndex { get; set; } = 0;


		public TERM_Command CommandEnum { get; set; } = (TERM_Command)0;


		public int CommandNumber { get; set; } = 0;

	}
	public sealed class WEE_NestedEvent
	{
		public enum NestedMode : byte
		{
			ActivateAll,
			RandomAny
		}

		public NestedMode Type { get; set; } = NestedMode.ActivateAll;


		public int MaxRandomEvents { get; set; } = -1;


		public bool AllowRepeatsInRandom { get; set; } = false;


		public WardenObjectiveEventData[] EventsToActivate { get; set; } = Array.Empty<WardenObjectiveEventData>();

	}
	public sealed class WEE_StartEventLoop
	{
		public int LoopIndex { get; set; } = 0;


		public float LoopDelay { get; set; } = 1f;


		public int LoopCount { get; set; } = -1;


		public WardenObjectiveEventData[] EventsToActivate { get; set; } = Array.Empty<WardenObjectiveEventData>();

	}
	public enum SlotIndex : byte
	{
		P0,
		P1,
		P2,
		P3
	}
	public sealed class WEE_TeleportPlayer
	{
		public HashSet<SlotIndex> PlayerFilter { get; set; } = new HashSet<SlotIndex>();


		public bool PlayWarpAnimation { get; set; } = true;


		public bool FlashTeleport { get; set; } = false;


		public bool WarpSentries { get; set; } = true;


		public bool WarpBigPickups { get; set; } = true;


		public bool SendBPUsToHost { get; set; } = false;


		public Vector3 Player0Position { get; set; } = Vector3.zero;


		public int P0LookDir { get; set; } = 0;


		public Vector3 Player1Position { get; set; } = Vector3.zero;


		public int P1LookDir { get; set; } = 0;


		public Vector3 Player2Position { get; set; } = Vector3.zero;


		public int P2LookDir { get; set; } = 0;


		public Vector3 Player3Position { get; set; } = Vector3.zero;


		public int P3LookDir { get; set; } = 0;

	}
	public sealed class WEE_InfectPlayer
	{
		public HashSet<SlotIndex> PlayerFilter { get; set; } = new HashSet<SlotIndex>
		{
			SlotIndex.P0,
			SlotIndex.P1,
			SlotIndex.P2,
			SlotIndex.P3
		};


		public float InfectionAmount { get; set; } = 0f;


		public bool InfectOverTime { get; set; } = false;


		public bool UseZone { get; set; } = false;

	}
	public sealed class WEE_DamagePlayer
	{
		public HashSet<SlotIndex> PlayerFilter { get; set; } = new HashSet<SlotIndex>
		{
			SlotIndex.P0,
			SlotIndex.P1,
			SlotIndex.P2,
			SlotIndex.P3
		};


		public float DamageAmount { get; set; } = 0f;


		public bool DamageOverTime { get; set; } = false;


		public bool UseZone { get; set; } = false;

	}
	public sealed class WEE_RevivePlayer
	{
		public HashSet<SlotIndex> PlayerFilter { get; set; } = new HashSet<SlotIndex>
		{
			SlotIndex.P0,
			SlotIndex.P1,
			SlotIndex.P2,
			SlotIndex.P3
		};

	}
	public sealed class WEE_AdjustTimer
	{
		public float Duration { get; set; } = 0f;


		public float Speed { get; set; } = 0f;


		public bool UpdateText { get; set; } = false;


		public LocaleText CustomText { get; set; } = LocaleText.Empty;


		public Color TimerColor { get; set; } = Color.red;

	}
	public sealed class WEE_CountupData
	{
		public float Duration { get; set; } = 0f;


		public float StartValue { get; set; } = 0f;


		public float Speed { get; set; } = 1f;


		public LocaleText TimerText { get; set; } = LocaleText.Empty;


		public LocaleText CustomText { get; set; } = LocaleText.Empty;


		public Color TimerColor { get; set; } = Color.red;


		public int DecimalPoints { get; set; } = 0;


		public List<EventsOnTimerProgress> EventsOnProgress { get; set; } = new List<EventsOnTimerProgress>();


		public WardenObjectiveEventData[] EventsOnDone { get; set; } = Array.Empty<WardenObjectiveEventData>();

	}
	public struct EventsOnTimerProgress
	{
		public float Progress { get; set; }

		public WardenObjectiveEventData[] Events { get; set; }
	}
	public sealed class WEE_ShakeScreen
	{
		public float Radius { get; set; } = 0f;


		public float Duration { get; set; } = 0f;


		public float Amplitude { get; set; } = 0f;


		public float Frequency { get; set; } = 0f;


		public bool Directional { get; set; } = true;

	}
	public sealed class WEE_StartPortalMachine
	{
		public eDimensionIndex TargetDimension { get; set; } = (eDimensionIndex)1;


		public eLocalZoneIndex TargetZone { get; set; } = (eLocalZoneIndex)0;

	}
	public sealed class WEE_SetSuccessScreen
	{
		public enum ScreenType : byte
		{
			SetSuccessScreen,
			FlashFakeScreen
		}

		public ScreenType Type { get; set; } = ScreenType.SetSuccessScreen;


		public WinScreen CustomSuccessScreen { get; set; } = WinScreen.Empty;


		public eCM_MenuPage FakeEndScreen { get; set; } = (eCM_MenuPage)17;


		public float Duration { get; set; } = 0f;

	}
	public sealed class WEE_PlayWaveDistantRoar
	{
		public enum WaveRoarSound : byte
		{
			Striker,
			Shooter,
			Birther,
			Shadow,
			Tank,
			Flyer,
			Immortal,
			Bullrush,
			Pouncer,
			Striker_Berserk,
			Shooter_Spread
		}

		public enum WaveRoarSize : byte
		{
			Small,
			Medium,
			Big
		}

		public WaveRoarSound RoarSound { get; set; }

		public WaveRoarSize RoarSize { get; set; }

		public bool IsOutside { get; set; }
	}
	public sealed class WEE_CustomHudText
	{
		public LocaleText Title { get; set; } = LocaleText.Empty;


		public LocaleText Body { get; set; } = LocaleText.Empty;

	}
	public sealed class WEE_SpecialHudTimer
	{
		public LocaleText Message { get; set; } = LocaleText.Empty;


		public ePUIMessageStyle Style { get; set; } = (ePUIMessageStyle)0;


		public int Priority { get; set; } = -2;


		public bool ShowTimeInProgressBar { get; set; } = true;


		public float Duration { get; set; } = 0f;


		public List<EventsOnTimerProgress> EventsOnProgress { get; set; } = new List<EventsOnTimerProgress>();


		public WardenObjectiveEventData[] EventsOnDone { get; set; } = Array.Empty<WardenObjectiveEventData>();

	}
	public enum WEE_Type
	{
		CloseSecurityDoor = 10000,
		LockSecurityDoor = 10001,
		SetDoorInteraction = 10002,
		TriggerSecurityDoorAlarm = 10003,
		SolveSecurityDoorAlarm = 10004,
		StartReactor = 10005,
		ModifyReactorWaveState = 10006,
		ForceCompleteReactor = 10007,
		ForceCompleteLevel = 10008,
		ForceFailLevel = 10009,
		Countdown = 10010,
		SetLevelFailCheckEnabled = 10011,
		SetLevelFailWhenAnyPlayerDowned = 10012,
		KillAllPlayers = 10013,
		KillPlayersInZone = 10014,
		SolveSingleObjectiveItem = 10015,
		SetLightDataInZone = 10016,
		AlertEnemiesInZone = 10017,
		CleanupEnemiesInZone = 10018,
		SpawnHibernateInZone = 10019,
		SpawnScoutInZone = 10020,
		SaveCheckpoint = 10021,
		MoveExtractionWorldPosition = 10022,
		SetBlackoutEnabled = 10023,
		AddTerminalCommand = 10024,
		HideTerminalCommand = 10025,
		UnhideTerminalCommand = 10026,
		AddChainPuzzleToSecurityDoor = 10027,
		NestedEvent = 20000,
		StartEventLoop = 20001,
		StopEventLoop = 20002,
		TeleportPlayer = 20003,
		InfectPlayer = 20004,
		DamagePlayer = 20005,
		RevivePlayer = 20006,
		AdjustAWOTimer = 20007,
		Countup = 20008,
		ForceCompleteChainPuzzle = 20009,
		SpawnNavMarker = 20010,
		ShakeScreen = 20011,
		StartPortalMachine = 20012,
		SetSuccessScreen = 20013,
		PlaySubtitles = 20014,
		MultiProgression = 20015,
		PlayWaveRoarSound = 20016,
		CustomHudText = 20017,
		SpecialHudTimer = 20018
	}
}
namespace AWO.Modules.WEE.Events
{
	internal sealed class NestedEvent : BaseEvent
	{
		public override WEE_Type EventType => WEE_Type.NestedEvent;

		protected override void OnSetup()
		{
			LevelEvents.OnLevelBuildDoneLate += PostFactoryDone;
		}

		private void PostFactoryDone()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			int sessionSeed = RundownManager.GetActiveExpeditionData().sessionSeed;
			EntryPoint.SessionSeed = new Random(sessionSeed);
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(12, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("SessionSeed ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(sessionSeed);
			}
			Logger.Info(val);
		}

		protected override void TriggerCommon(WEE_EventData e)
		{
			int maxValue = e.NestedEvent.EventsToActivate.Length;
			List<WardenObjectiveEventData> list;
			if (e.NestedEvent.Type == WEE_NestedEvent.NestedMode.RandomAny)
			{
				list = new List<WardenObjectiveEventData>();
				for (int i = 0; i < e.NestedEvent.MaxRandomEvents && i < e.NestedEvent.EventsToActivate.Length; i++)
				{
					int num;
					do
					{
						num = EntryPoint.SessionSeed.Next(maxValue);
					}
					while (!e.NestedEvent.AllowRepeatsInRandom && list.Contains(e.NestedEvent.EventsToActivate[num]));
					list.Add(e.NestedEvent.EventsToActivate[num]);
				}
			}
			else
			{
				list = new List<WardenObjectiveEventData>(e.NestedEvent.EventsToActivate);
			}
			foreach (WardenObjectiveEventData item in list)
			{
				WorldEventManager.ExecuteEvent(item, 0f);
			}
		}
	}
	internal sealed class StartEventLoop : BaseEvent
	{
		public override WEE_Type EventType => WEE_Type.StartEventLoop;

		protected override void TriggerCommon(WEE_EventData e)
		{
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			if (e.StartEventLoop.LoopDelay < 1f)
			{
				LogError("LoopDelay must be > 1.0 seconds");
				return;
			}
			lock (EntryPoint.ActiveEventLoops)
			{
				bool flag = default(bool);
				if (EntryPoint.ActiveEventLoops.Contains(e.StartEventLoop.LoopIndex))
				{
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("EventLoop ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(e.StartEventLoop.LoopIndex);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is already active...");
					}
					LogError(val);
					return;
				}
				EntryPoint.ActiveEventLoops.Add(e.StartEventLoop.LoopIndex);
				BepInExDebugLogInterpolatedStringHandler val2 = new BepInExDebugLogInterpolatedStringHandler(26, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Starting EventLoop Index: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(e.StartEventLoop.LoopIndex);
				}
				LogDebug(val2);
				CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(DoLoop(e)), (Action)null);
				LevelAPI.OnLevelCleanup += OnLevelCleanup;
			}
		}

		private void OnLevelCleanup()
		{
			Logger.Debug("[StartEventLoop] Cleaning up active EventLoops...");
			EntryPoint.ActiveEventLoops.Clear();
		}

		private static IEnumerator DoLoop(WEE_EventData e)
		{
			WEE_StartEventLoop sel = e.StartEventLoop;
			int repeatNum = 0;
			int repeatMax = sel.LoopCount;
			bool repeatInf = repeatMax == -1;
			int index = sel.LoopIndex;
			int myReloadCount = CheckpointManager.Current.m_stateReplicator.State.reloadCount;
			WaitForSeconds delay = new WaitForSeconds(sel.LoopDelay);
			bool flag = default(bool);
			BepInExDebugLogInterpolatedStringHandler val;
			for (; repeatNum < repeatMax || repeatInf; repeatNum++)
			{
				lock (EntryPoint.ActiveEventLoops)
				{
					if ((int)GameStateManager.CurrentStateName != 10)
					{
						EntryPoint.ActiveEventLoops.Remove(index);
						yield break;
					}
					if (CheckpointManager.Current.m_stateReplicator.State.reloadCount > myReloadCount)
					{
						EntryPoint.ActiveEventLoops.Remove(index);
						yield break;
					}
					if (!EntryPoint.ActiveEventLoops.Contains(index))
					{
						val = new BepInExDebugLogInterpolatedStringHandler(39, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[StartEventLoop] EventLoop ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(index);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is now done");
						}
						Logger.Debug(val);
						yield break;
					}
				}
				val = new BepInExDebugLogInterpolatedStringHandler(39, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[StartEventLoop] EventLoop ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(index);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" repeating #");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(repeatNum);
				}
				Logger.Debug(val);
				WardenObjectiveEventData[] eventsToActivate = sel.EventsToActivate;
				foreach (WardenObjectiveEventData eventData in eventsToActivate)
				{
					WorldEventManager.ExecuteEvent(eventData, 0f);
				}
				yield return delay;
			}
			val = new BepInExDebugLogInterpolatedStringHandler(39, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[StartEventLoop] EventLoop ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(index);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is now done");
			}
			Logger.Debug(val);
		}
	}
	internal sealed class StopEventLoop : BaseEvent
	{
		public override WEE_Type EventType => WEE_Type.StopEventLoop;

		protected override void TriggerCommon(WEE_EventData e)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			lock (EntryPoint.ActiveEventLoops)
			{
				if (e.Count == -1)
				{
					LogDebug("Stopping all EventLoops...");
					EntryPoint.ActiveEventLoops.Clear();
					return;
				}
				bool flag = default(bool);
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(22, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Stopping EventLoop ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(e.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("...");
				}
				LogDebug(val);
				EntryPoint.ActiveEventLoops.Remove(e.Count);
			}
		}
	}
}
namespace AWO.Modules.WEE.Events.World
{
	internal sealed class DamagePlayerEvent : BaseEvent
	{
		public override WEE_Type EventType => WEE_Type.DamagePlayer;

		protected override void TriggerMaster(WEE_EventData e)
		{
			HashSet<int> hashSet = new HashSet<int>(e.DamagePlayer.PlayerFilter.Select((SlotIndex filter) => (int)filter));
			if (!TryGetZone(e, out LG_Zone zone))
			{
				LogError("Cannot find zone!");
				return;
			}
			Enumerator<PlayerAgent> enumerator = PlayerManager.PlayerAgentsInLevel.GetEnumerator();
			while (enumerator.MoveNext())
			{
				PlayerAgent current = enumerator.Current;
				if (!hashSet.Contains(current.PlayerSlotIndex))
				{
					continue;
				}
				AIG_CourseNode courseNode = ((Agent)current).CourseNode;
				if (!((Object)(object)((courseNode != null) ? courseNode.m_zone : null) == (Object)null))
				{
					if (e.DamagePlayer.DamageOverTime && e.Duration > 0f)
					{
						CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(DamageOverTime(e, current, zone.ID)), (Action)null);
					}
					else
					{
						ApplyDamage(current, e.DamagePlayer.DamageAmount, e.DamagePlayer.UseZone, zone.ID);
					}
				}
			}
		}

		private static IEnumerator DamageOverTime(WEE_EventData e, PlayerAgent player, int id)
		{
			int reloadCount = CheckpointManager.Current.m_stateReplicator.State.reloadCount;
			float damagePerSecond = e.DamagePlayer.DamageAmount / e.Duration;
			float elapsed = 0f;
			WaitForSeconds delay = new WaitForSeconds(1f);
			while (elapsed <= e.Duration && (int)GameStateManager.CurrentStateName == 10 && CheckpointManager.Current.m_stateReplicator.State.reloadCount <= reloadCount)
			{
				ApplyDamage(player, damagePerSecond, e.DamagePlayer.UseZone, id);
				elapsed += Time.deltaTime;
				yield return delay;
			}
		}

		private static void ApplyDamage(PlayerAgent player, float damage, bool useZone, int id)
		{
			if (!useZone || ((Agent)player).CourseNode.m_zone.ID == id)
			{
				player.Damage.OnIncomingDamage(damage / 4f, 0f, (Agent)null);
			}
		}
	}
	internal sealed class InfectPlayerEvent : BaseEvent
	{
		public override WEE_Type EventType => WEE_Type.InfectPlayer;

		protected override void TriggerMaster(WEE_EventData e)
		{
			HashSet<int> hashSet = new HashSet<int>(e.InfectPlayer.PlayerFilter.Select((SlotIndex filter) => (int)filter));
			if (!TryGetZone(e, out LG_Zone zone))
			{
				LogError("Cannot find zone!");
				return;
			}
			Enumerator<PlayerAgent> enumerator = PlayerManager.PlayerAgentsInLevel.GetEnumerator();
			while (enumerator.MoveNext())
			{
				PlayerAgent current = enumerator.Current;
				if (!hashSet.Contains(current.PlayerSlotIndex) || current.Owner.IsBot)
				{
					continue;
				}
				AIG_CourseNode courseNode = ((Agent)current).CourseNode;
				if (!((Object)(object)((courseNode != null) ? courseNode.m_zone : null) == (Object)null))
				{
					if (e.InfectPlayer.InfectOverTime && e.Duration > 0f)
					{
						CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(InfectOverTime(e, current, zone.ID)), (Action)null);
					}
					else
					{
						ApplyInfection(current, e.InfectPlayer.InfectionAmount, e.InfectPlayer.UseZone, zone.ID);
					}
				}
			}
		}

		private static IEnumerator InfectOverTime(WEE_EventData e, PlayerAgent player, int id)
		{
			int reloadCount = CheckpointManager.Current.m_stateReplicator.State.reloadCount;
			float infectionPerSecond = e.InfectPlayer.InfectionAmount / e.Duration;
			float elapsed = 0f;
			WaitForSeconds delay = new WaitForSeconds(1f);
			while (elapsed <= e.Duration && (int)GameStateManager.CurrentStateName == 10 && CheckpointManager.Current.m_stateReplicator.State.reloadCount <= reloadCount)
			{
				ApplyInfection(player, infectionPerSecond, e.InfectPlayer.UseZone, id);
				elapsed += Time.deltaTime;
				yield return delay;
			}
		}

		private static void ApplyInfection(PlayerAgent player, float infection, bool useZone, int id)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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)
			pInfection val = default(pInfection);
			val.amount = infection / 100f;
			val.mode = (pInfectionMode)1;
			val.effect = (pInfectionEffect)0;
			pInfection val2 = val;
			if (!useZone || ((Agent)player).CourseNode.m_zone.ID == id)
			{
				player.Damage.ModifyInfection(val2, true, true);
			}
		}
	}
	internal sealed class KillPlayersInZoneEvent : BaseEvent
	{
		public override WEE_Type EventType => WEE_Type.KillPlayersInZone;

		protected override void TriggerMaster(WEE_EventData e)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			if (!TryGetZone(e, out LG_Zone zone))
			{
				LogError("Cannot find zone!");
				return;
			}
			int iD = zone.ID;
			Enumerator<PlayerAgent> enumerator = PlayerManager.PlayerAgentsInLevel.GetEnumerator();
			while (enumerator.MoveNext())
			{
				PlayerAgent current = enumerator.Current;
				AIG_CourseNode courseNode = ((Agent)current).CourseNode;
				if (courseNode != null && !((Object)(object)courseNode.m_zone == (Object)null) && courseNode.m_zone.ID == iD)
				{
					((Dam_SyncedDamageBase)current.Damage).ExplosionDamage(((Dam_SyncedDamageBase)current.Damage).DamageMax, default(Vector3), default(Vector3), 0u);
				}
			}
		}
	}
	internal sealed class PlayWaveDistantRoarEvent : BaseEvent
	{
		public override WEE_Type EventType => WEE_Type.PlayWaveRoarSound;

		protected override void TriggerCommon(WEE_EventData e)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			CellSoundPlayer val = new CellSoundPlayer(Vector3.zero);
			val.UpdatePosition(GetSoundPlayerPosition(e.Position, e.SpecialText));
			switch ((byte)e.WaveRoarSound.RoarSound)
			{
			case 0:
				val.SetSwitch(ENEMY_TYPE.GROUP, SWITCH.STRIKER);
				break;
			case 1:
				val.SetSwitch(ENEMY_TYPE.GROUP, SWITCH.SHOOTER);
				break;
			case 2:
				val.SetSwitch(ENEMY_TYPE.GROUP, SWITCH.BIRTHER);
				break;
			case 3:
				val.SetSwitch(ENEMY_TYPE.GROUP, SWITCH.SHADOW);
				break;
			case 4:
				val.SetSwitch(ENEMY_TYPE.GROUP, SWITCH.TANK);
				break;
			case 5:
				val.SetSwitch(ENEMY_TYPE.GROUP, SWITCH.FLYER);
				break;
			case 6:
				val.SetSwitch(ENEMY_TYPE.GROUP, SWITCH.IMMORTAL);
				break;
			case 7:
				val.SetSwitch(ENEMY_TYPE.GROUP, SWITCH.BULLRUSHER);
				break;
			case 8:
				val.SetSwitch(ENEMY_TYPE.GROUP, SWITCH.POUNCER);
				break;
			case 9:
				val.SetSwitch(ENEMY_TYPE.GROUP, SWITCH.STRIKER_BERSERK);
				break;
			case 10:
				val.SetSwitch(ENEMY_TYPE.GROUP, SWITCH.SHOOTER_SPREAD);
				break;
			}
			switch ((byte)e.WaveRoarSound.RoarSize)
			{
			case 0:
				val.SetSwitch(ROAR_SIZE.GROUP, SWITCH.SMALL);
				break;
			case 1:
				val.SetSwitch(ROAR_SIZE.GROUP, SWITCH.MEDIUM);
				break;
			case 2:
				val.SetSwitch(ROAR_SIZE.GROUP, SWITCH.BIG);
				break;
			}
			val.SetSwitch(ENVIROMENT.GROUP, e.WaveRoarSound.IsOutside ? SWITCH.DESERT : SWITCH.COMPLEX);
			val.Post(EVENTS.PLAY_WAVE_DISTANT_ROAR, true);
			CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(Cleanup(val)), (Action)null);
		}

		private static Vector3 GetSoundPlayerPosition(Vector3 pos, string weObjectFilter)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			if (pos != Vector3.zero)
			{
				return pos;
			}
			if (Utility.IsNullOrWhiteSpace(weObjectFilter))
			{
				return Vector3.zero;
			}
			Enumerator<LG_WorldEventObject> enumerator = WorldEventManager.Current.m_worldEventObjects.GetEnumerator();
			while (enumerator.MoveNext())
			{
				LG_WorldEventObject current = enumerator.Current;
				if (((Object)((Component)current).gameObject).name == weObjectFilter)
				{
					return ((Component)current).gameObject.transform.position;
				}
			}
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(65, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[PlayWaveDistantRoarEvent] Could not find WorldEventObjectFilter ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(weObjectFilter);
			}
			Logger.Error(val);
			return Vector3.zero;
		}

		private static IEnumerator Cleanup(CellSoundPlayer csPlayer)
		{
			yield return (object)new WaitForSeconds(10f);
			csPlayer.Recycle();
		}
	}
	internal sealed class RevivePlayerEvent : BaseEvent
	{
		public override WEE_Type EventType => WEE_Type.RevivePlayer;

		protected override void TriggerMaster(WEE_EventData e)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			HashSet<int> hashSet = new HashSet<int>(e.RevivePlayer.PlayerFilter.Select((SlotIndex filter) => (int)filter));
			Enumerator<PlayerAgent> enumerator = PlayerManager.PlayerAgentsInLevel.GetEnumerator();
			while (enumerator.MoveNext())
			{
				PlayerAgent current = enumerator.Current;
				if (hashSet.Contains(current.PlayerSlotIndex) && !((Agent)current).Alive)
				{
					AgentReplicatedActions.PlayerReviveAction(current, current, ((Agent)current).Position);
				}
			}
		}
	}
	internal sealed class TeleportPlayerEvent : BaseEvent
	{
		private class TPData
		{
			public SlotIndex SlotIndex { get; set; }

			public Vector3 Position { get; set; }

			public int LookDir { get; set; }

			public eDimensionIndex LastDim { get; set; }

			public Vector3 LastPosition { get; set; }

			public Vector3 LastLookDir { get; set; }

			public List<IWarpableObject> ItemsToWarp { get; set; }

			public TPData(SlotIndex a, Vector3 b, int c, eDimensionIndex d, Vector3 e, Vector3 f, List<IWarpableObject> g)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)