Decompiled source of ShotGunDoom v1.0.0

ShotGunDoom.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ShotGunDoom.Assets;
using ShotGunDoom.Config;
using ShotGunDoom.Core;
using ShotGunDoom.Network;
using ShotGunDoom.PostProcessing;
using ShotGunDoom.UI;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ShotGunDoom")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ShotGunDoom")]
[assembly: AssemblyTitle("ShotGunDoom")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ShotGunDoom
{
	[BepInPlugin("com.shotgundoom.mod", "ShotGunDoom", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGUID = "com.shotgundoom.mod";

		public const string ModName = "ShotGunDoom";

		public const string ModVersion = "1.0.0";

		private Harmony _harmony;

		internal static ManualLogSource Log { get; private set; }

		internal static Plugin Instance { get; private set; }

		private void Awake()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			try
			{
				ModConfig.Bind(((BaseUnityPlugin)this).Config);
				DoomAssets.Load();
				DoomVolumeManager.RegisterCustomPostProcess();
				_harmony = new Harmony("com.shotgundoom.mod");
				_harmony.PatchAll(typeof(Plugin).Assembly);
				DoomNetwork.Initialize();
				Log.LogInfo((object)"ShotGunDoom v1.0.0 loaded successfully (Curse Mode).");
			}
			catch (Exception arg)
			{
				Log.LogError((object)string.Format("Failed to initialize {0}: {1}", "ShotGunDoom", arg));
			}
		}
	}
}
namespace ShotGunDoom.UI
{
	[CreateAssetMenu(menuName = "DoomFont", order = 2, fileName = "DoomFont")]
	public class DoomFont : ScriptableObject
	{
		public List<char> Chars;

		public List<Sprite> Sprites;

		public int CharHeight;

		public Sprite GetSprite(char c)
		{
			if (Chars == null || Sprites == null)
			{
				return null;
			}
			int num = Chars.IndexOf(c);
			if (num > -1 && num < Sprites.Count)
			{
				return Sprites[num];
			}
			return null;
		}
	}
	public class DoomHUD : MonoBehaviour
	{
		public enum SpritePhase
		{
			LEFT,
			STRAIGHT,
			RIGHT,
			MANIAC,
			DAMAGE,
			SECRET,
			DEAD
		}

		public Sprite[] LeftSprites;

		public Sprite[] StraightSprites;

		public Sprite[] RightSprites;

		public Sprite[] ManiacSprites;

		public Sprite[] DamageSprites;

		public Sprite SecretSprite;

		public Sprite DeadSprite;

		private SpritePhase _HeadPhase;

		public Image PlayerHead;

		private int _HP;

		private int _Armor;

		private int _BulletsAmmo;

		private int _ShellsAmmo = 100;

		private int _RocketsAmmo;

		private int _CellsAmmo;

		private bool _HasArms2;

		private bool _HasArms3;

		private bool _HasArms4;

		private bool _HasArms5;

		private bool _HasArms6;

		private bool _HasArms7;

		public Color ActiveColor;

		public Color InactiveColor;

		public DoomText Arms2Text;

		public DoomText Arms3Text;

		public DoomText Arms4Text;

		public DoomText Arms5Text;

		public DoomText Arms6Text;

		public DoomText Arms7Text;

		public DoomText HealthText;

		public DoomText AmmoText;

		public DoomText ArmorText;

		public DoomText BulletsText;

		public DoomText ShellsText;

		public DoomText RocketsText;

		public DoomText CellsText;

		public int CurrentWeapon = 4;

		public Animator ShotgunAnimator;

		private float ShootPhase;

		public SpritePhase HeadPhase
		{
			get
			{
				return _HeadPhase;
			}
			set
			{
				_HeadPhase = value;
				UpdateSprite();
			}
		}

		public int HP
		{
			get
			{
				return _HP;
			}
			set
			{
				_HP = value;
				if ((Object)(object)HealthText != (Object)null)
				{
					HealthText.Text = value + "%";
				}
				UpdateSprite();
			}
		}

		public int Armor
		{
			get
			{
				return _Armor;
			}
			set
			{
				_Armor = value;
				if ((Object)(object)ArmorText != (Object)null)
				{
					ArmorText.Text = value + "%";
				}
			}
		}

		public int BulletsAmmo
		{
			get
			{
				return _BulletsAmmo;
			}
			set
			{
				_BulletsAmmo = value;
				if ((Object)(object)BulletsText != (Object)null)
				{
					BulletsText.Text = value.ToString();
				}
			}
		}

		public int ShellsAmmo
		{
			get
			{
				return _ShellsAmmo;
			}
			set
			{
				_ShellsAmmo = value;
				if ((Object)(object)ShellsText != (Object)null)
				{
					ShellsText.Text = value.ToString();
				}
				if (CurrentWeapon == 4 && (Object)(object)AmmoText != (Object)null)
				{
					AmmoText.Text = value.ToString();
				}
			}
		}

		public int RocketsAmmo
		{
			get
			{
				return _RocketsAmmo;
			}
			set
			{
				_RocketsAmmo = value;
				if ((Object)(object)RocketsText != (Object)null)
				{
					RocketsText.Text = value.ToString();
				}
			}
		}

		public int CellsAmmo
		{
			get
			{
				return _CellsAmmo;
			}
			set
			{
				_CellsAmmo = value;
				if ((Object)(object)CellsText != (Object)null)
				{
					CellsText.Text = value.ToString();
				}
			}
		}

		public bool HasArms2
		{
			get
			{
				return _HasArms2;
			}
			set
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				_HasArms2 = value;
				if ((Object)(object)Arms2Text != (Object)null)
				{
					Arms2Text.Color = (value ? ActiveColor : InactiveColor);
				}
			}
		}

		public bool HasArms3
		{
			get
			{
				return _HasArms3;
			}
			set
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				_HasArms3 = value;
				if ((Object)(object)Arms3Text != (Object)null)
				{
					Arms3Text.Color = (value ? ActiveColor : InactiveColor);
				}
			}
		}

		public bool HasArms4
		{
			get
			{
				return _HasArms4;
			}
			set
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				_HasArms4 = value;
				if ((Object)(object)Arms4Text != (Object)null)
				{
					Arms4Text.Color = (value ? ActiveColor : InactiveColor);
				}
			}
		}

		public bool HasArms5
		{
			get
			{
				return _HasArms5;
			}
			set
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				_HasArms5 = value;
				if ((Object)(object)Arms5Text != (Object)null)
				{
					Arms5Text.Color = (value ? ActiveColor : InactiveColor);
				}
			}
		}

		public bool HasArms6
		{
			get
			{
				return _HasArms6;
			}
			set
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				_HasArms6 = value;
				if ((Object)(object)Arms6Text != (Object)null)
				{
					Arms6Text.Color = (value ? ActiveColor : InactiveColor);
				}
			}
		}

		public bool HasArms7
		{
			get
			{
				return _HasArms7;
			}
			set
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				_HasArms7 = value;
				if ((Object)(object)Arms7Text != (Object)null)
				{
					Arms7Text.Color = (value ? ActiveColor : InactiveColor);
				}
			}
		}

		public void UpdateSprite()
		{
			if (!((Object)(object)PlayerHead == (Object)null))
			{
				int num = Mathf.Clamp(4 - Mathf.RoundToInt((float)Mathf.Clamp(HP, 0, 100) / 100f * 4f), 0, 4);
				if (_HeadPhase == SpritePhase.LEFT && LeftSprites != null && LeftSprites.Length != 0)
				{
					PlayerHead.sprite = LeftSprites[Mathf.Min(num, LeftSprites.Length - 1)];
				}
				else if (_HeadPhase == SpritePhase.STRAIGHT && StraightSprites != null && StraightSprites.Length != 0)
				{
					PlayerHead.sprite = StraightSprites[Mathf.Min(num, StraightSprites.Length - 1)];
				}
				else if (_HeadPhase == SpritePhase.RIGHT && RightSprites != null && RightSprites.Length != 0)
				{
					PlayerHead.sprite = RightSprites[Mathf.Min(num, RightSprites.Length - 1)];
				}
				else if (_HeadPhase == SpritePhase.DAMAGE && DamageSprites != null && DamageSprites.Length != 0)
				{
					PlayerHead.sprite = DamageSprites[Mathf.Min(num, DamageSprites.Length - 1)];
				}
				else if (_HeadPhase == SpritePhase.MANIAC && ManiacSprites != null && ManiacSprites.Length != 0)
				{
					PlayerHead.sprite = ManiacSprites[Mathf.Min(num, ManiacSprites.Length - 1)];
				}
				else if (_HeadPhase == SpritePhase.DEAD)
				{
					PlayerHead.sprite = DeadSprite;
				}
				else if (_HeadPhase == SpritePhase.SECRET)
				{
					PlayerHead.sprite = SecretSprite;
				}
			}
		}

		private void Start()
		{
			if ((Object)(object)BulletsText != (Object)null)
			{
				BulletsText.Text = BulletsAmmo.ToString();
			}
			if ((Object)(object)ShellsText != (Object)null)
			{
				ShellsText.Text = ShellsAmmo.ToString();
			}
			if ((Object)(object)RocketsText != (Object)null)
			{
				RocketsText.Text = RocketsAmmo.ToString();
			}
			if ((Object)(object)CellsText != (Object)null)
			{
				CellsText.Text = CellsAmmo.ToString();
			}
			if (CurrentWeapon == 4 && (Object)(object)AmmoText != (Object)null)
			{
				AmmoText.Text = ShellsAmmo.ToString();
			}
			if ((Object)(object)HealthText != (Object)null)
			{
				HealthText.Text = HP + "%";
			}
			if ((Object)(object)ArmorText != (Object)null)
			{
				ArmorText.Text = Armor + "%";
			}
			UpdateSprite();
		}

		public bool Shoot(float minCooldown = 1.45f)
		{
			if (ShellsAmmo > 1)
			{
				if (ShootPhase > 0f)
				{
					return false;
				}
				if ((Object)(object)ShotgunAnimator != (Object)null)
				{
					ShotgunAnimator.ResetTrigger("Shoot");
					ShotgunAnimator.Play("Base Layer.ShootShotgun", 0, 0.001f);
				}
				DoomSuperShotgun doomSuperShotgun = (((Object)(object)ShotgunAnimator != (Object)null) ? (((Component)ShotgunAnimator).GetComponent<DoomSuperShotgun>() ?? ((Component)this).GetComponentInChildren<DoomSuperShotgun>()) : ((Component)this).GetComponentInChildren<DoomSuperShotgun>());
				if ((Object)(object)doomSuperShotgun != (Object)null)
				{
					doomSuperShotgun.Shoot();
				}
				ShellsAmmo -= 2;
				ShootPhase = Mathf.Max(1.45f, minCooldown);
				return true;
			}
			return false;
		}

		private void Update()
		{
			if (ShootPhase > 0f)
			{
				ShootPhase -= Time.deltaTime;
			}
		}
	}
	public class DoomSuperShotgun : MonoBehaviour
	{
		public AudioSource Audio;

		public void Shoot()
		{
			if ((Object)(object)Audio != (Object)null)
			{
				Audio.Play();
			}
		}
	}
	[ExecuteInEditMode]
	[RequireComponent(typeof(HorizontalLayoutGroup))]
	public class DoomText : MonoBehaviour
	{
		protected HorizontalLayoutGroup LayoutGroup;

		protected RectTransform RectTransform;

		private string LastText;

		private Color LastColor;

		public DoomFont Font;

		public string Text = "";

		public float Spacing;

		public bool Shadow;

		public Color ShadowColor;

		public Color Color;

		protected List<Image> Images = new List<Image>();

		protected List<Image> Shadows = new List<Image>();

		protected List<RectTransform> Containers = new List<RectTransform>();

		private void Update()
		{
			//IL_0014: 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_0119: 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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0729: Unknown result type (might be due to invalid IL or missing references)
			//IL_072e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_051b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0534: Unknown result type (might be due to invalid IL or missing references)
			//IL_0549: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0603: Unknown result type (might be due to invalid IL or missing references)
			//IL_0608: Unknown result type (might be due to invalid IL or missing references)
			//IL_062e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0633: Unknown result type (might be due to invalid IL or missing references)
			//IL_064b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0679: Unknown result type (might be due to invalid IL or missing references)
			//IL_067e: Unknown result type (might be due to invalid IL or missing references)
			if ((Text == LastText && Color == LastColor) || (Object)(object)Font == (Object)null)
			{
				return;
			}
			if ((Object)(object)RectTransform == (Object)null)
			{
				RectTransform = ((Component)this).GetComponent<RectTransform>();
			}
			if ((Object)(object)LayoutGroup == (Object)null)
			{
				LayoutGroup = ((Component)this).GetComponent<HorizontalLayoutGroup>();
			}
			string text = Text ?? string.Empty;
			for (int i = 0; i < text.Length; i++)
			{
				if (i >= Containers.Count || i >= Images.Count || i >= Shadows.Count || (Object)(object)Images[i] == (Object)null || (Object)(object)Shadows[i] == (Object)null || (Object)(object)Containers[i] == (Object)null)
				{
					Transform val = null;
					if (((Component)this).transform.childCount > i)
					{
						val = ((Component)this).transform.GetChild(i);
					}
					else
					{
						RectTransform obj = new GameObject("Letter" + i).AddComponent<RectTransform>();
						((Transform)obj).SetParent((Transform)(object)RectTransform);
						((Transform)obj).localScale = Vector3.one;
						obj.anchoredPosition3D = Vector3.zero;
						val = ((Component)obj).transform;
					}
					((Object)val).name = "Letter" + i;
					if (i >= Containers.Count)
					{
						Containers.Add(((Component)val).GetComponent<RectTransform>());
					}
					else
					{
						Containers[i] = ((Component)val).GetComponent<RectTransform>();
					}
					Transform val2 = null;
					if (val.childCount > 0)
					{
						val2 = val.GetChild(0);
					}
					else
					{
						RectTransform obj2 = new GameObject("Shadow").AddComponent<RectTransform>();
						((Transform)obj2).SetParent(val);
						((Transform)obj2).localScale = Vector3.one;
						obj2.anchoredPosition3D = Vector3.zero;
						val2 = ((Component)obj2).transform;
					}
					Transform val3 = null;
					if (val.childCount > 1)
					{
						val3 = val.GetChild(1);
					}
					else
					{
						RectTransform obj3 = new GameObject("Face").AddComponent<RectTransform>();
						((Transform)obj3).SetParent(val);
						((Transform)obj3).localScale = Vector3.one;
						obj3.anchoredPosition3D = Vector3.zero;
						val3 = ((Component)obj3).transform;
					}
					Image val4 = ((Component)val2).gameObject.GetComponent<Image>();
					if ((Object)(object)val4 == (Object)null)
					{
						val4 = ((Component)val2).gameObject.AddComponent<Image>();
					}
					Image val5 = ((Component)val3).gameObject.GetComponent<Image>();
					if ((Object)(object)val5 == (Object)null)
					{
						val5 = ((Component)val3).gameObject.AddComponent<Image>();
					}
					if (i >= Images.Count)
					{
						Images.Add(val5);
					}
					else
					{
						Images[i] = val5;
					}
					if (i >= Shadows.Count)
					{
						Shadows.Add(val4);
					}
					else
					{
						Shadows[i] = val4;
					}
				}
			}
			for (int num = Containers.Count - 1; num >= text.Length; num--)
			{
				if ((Object)(object)Containers[num] != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)((Component)Containers[num]).gameObject);
				}
			}
			if (Containers.Count > text.Length)
			{
				Containers.RemoveRange(text.Length, Containers.Count - text.Length);
			}
			if (Images.Count > text.Length)
			{
				Images.RemoveRange(text.Length, Images.Count - text.Length);
			}
			if (Shadows.Count > text.Length)
			{
				Shadows.RemoveRange(text.Length, Shadows.Count - text.Length);
			}
			((HorizontalOrVerticalLayoutGroup)LayoutGroup).spacing = Spacing;
			float num2 = ((Font.CharHeight > 0) ? ((float)Font.CharHeight) : 1f);
			Vector2 sizeDelta = default(Vector2);
			for (int j = 0; j < Containers.Count; j++)
			{
				if (j < text.Length)
				{
					if (!((Component)Containers[j]).gameObject.activeSelf)
					{
						((Component)Containers[j]).gameObject.SetActive(true);
					}
					Sprite sprite = Font.GetSprite(text[j]);
					if ((Object)(object)sprite == (Object)null)
					{
						((Behaviour)Images[j]).enabled = false;
						((Component)Shadows[j]).gameObject.SetActive(false);
						continue;
					}
					((Behaviour)Images[j]).enabled = true;
					Images[j].sprite = sprite;
					Rect rect = sprite.rect;
					float num3 = ((Rect)(ref rect)).width / num2;
					rect = RectTransform.rect;
					float num4 = num3 * ((Rect)(ref rect)).height;
					rect = RectTransform.rect;
					float height = ((Rect)(ref rect)).height;
					rect = sprite.rect;
					((Vector2)(ref sizeDelta))..ctor(num4, height * (((Rect)(ref rect)).height / num2));
					Containers[j].sizeDelta = sizeDelta;
					((Graphic)Images[j]).rectTransform.sizeDelta = sizeDelta;
					((Graphic)Images[j]).color = Color;
					if (Shadow)
					{
						if (!((Component)Shadows[j]).gameObject.activeSelf)
						{
							((Component)Shadows[j]).gameObject.SetActive(true);
						}
						Shadows[j].sprite = sprite;
						((Graphic)Shadows[j]).rectTransform.sizeDelta = sizeDelta;
						((Graphic)Shadows[j]).rectTransform.anchorMax = Vector2.op_Implicit(new Vector3(0f, 1f));
						((Graphic)Shadows[j]).rectTransform.anchorMin = Vector2.op_Implicit(new Vector3(0f, 1f));
						((Graphic)Shadows[j]).rectTransform.pivot = Vector2.op_Implicit(new Vector3(0f, 1f));
						((Graphic)Shadows[j]).color = ShadowColor;
						((Graphic)Shadows[j]).rectTransform.anchoredPosition = Vector2.op_Implicit(new Vector3(Spacing, 0f - Spacing, 0f));
					}
					else if (((Component)Shadows[j]).gameObject.activeSelf)
					{
						((Component)Shadows[j]).gameObject.SetActive(false);
					}
				}
				else if ((Object)(object)Containers[j] != (Object)null && ((Component)Containers[j]).gameObject.activeSelf)
				{
					((Component)Containers[j]).gameObject.SetActive(false);
				}
			}
			LastText = Text;
			LastColor = Color;
		}
	}
}
namespace ShotGunDoom.PostProcessing
{
	[Serializable]
	[VolumeComponentMenu("Post-processing/Custom/ShotGunDoom")]
	public sealed class DoomEffect : CustomPostProcessVolumeComponent, IPostProcessComponent
	{
		[Tooltip("Controls the intensity of the Doom pixelation effect.")]
		public ClampedFloatParameter intensity = new ClampedFloatParameter(0f, 0f, 1f, false);

		private Material _material;

		public override CustomPostProcessInjectionPoint injectionPoint => (CustomPostProcessInjectionPoint)2;

		public bool IsActive()
		{
			if ((Object)(object)_material != (Object)null)
			{
				return ((VolumeParameter<float>)(object)intensity).value > 0f;
			}
			return false;
		}

		public override void Setup()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if ((Object)(object)DoomAssets.DoomPostProcessMaterial != (Object)null)
			{
				_material = new Material(DoomAssets.DoomPostProcessMaterial);
			}
			else
			{
				Plugin.Log.LogWarning((object)"DoomEffect: DoomPostProcessMaterial is null; pixel shader disabled.");
			}
		}

		public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_material == (Object)null) && !(((VolumeParameter<float>)(object)intensity).value <= 0f))
			{
				_material.SetFloat("_Intensity", ((VolumeParameter<float>)(object)intensity).value);
				float activePixelFilterWidth = ModConfig.ActivePixelFilterWidth;
				_material.SetFloat("_ScreenWidth", activePixelFilterWidth);
				_material.SetFloat("_ScreenHeight", activePixelFilterWidth * 3f / 4f);
				cmd.Blit(RTHandle.op_Implicit(source), RTHandle.op_Implicit(destination), _material, 0);
			}
		}

		public override void Cleanup()
		{
			CoreUtils.Destroy((Object)(object)_material);
			_material = null;
		}
	}
	internal static class DoomVolumeManager
	{
		private static bool _registered;

		private static GameObject _volumeObject;

		private static Volume _volume;

		private static VolumeProfile _profile;

		private static DoomEffect _effectInstance;

		public static void RegisterCustomPostProcess()
		{
			if (_registered)
			{
				return;
			}
			try
			{
				Type type = typeof(HDRenderPipelineAsset).Assembly.GetType("UnityEngine.Rendering.HighDefinition.HDRenderPipelineGlobalSettings");
				if (type == null)
				{
					Plugin.Log.LogWarning((object)"HDRenderPipelineGlobalSettings type not found; Doom shader may not run.");
					return;
				}
				object obj = type.GetProperty("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy)?.GetValue(null);
				if (obj == null)
				{
					Plugin.Log.LogWarning((object)"HDRenderPipelineGlobalSettings.instance is null; will retry on scene load.");
				}
				else if (type.GetField("afterPostProcessCustomPostProcesses", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy)?.GetValue(obj) is List<string> list)
				{
					string assemblyQualifiedName = typeof(DoomEffect).AssemblyQualifiedName;
					if (!string.IsNullOrEmpty(assemblyQualifiedName) && !list.Contains(assemblyQualifiedName))
					{
						list.Add(assemblyQualifiedName);
						Plugin.Log.LogInfo((object)"Registered DoomEffect into HDRP AfterPostProcess custom post processes.");
					}
					_registered = true;
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Failed to register DoomEffect in HDRP: {arg}");
			}
		}

		public static void EnsureVolume()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			RegisterCustomPostProcess();
			if ((Object)(object)_volumeObject == (Object)null)
			{
				_volumeObject = new GameObject("ShotGunDoom_RenderVolume");
				Object.DontDestroyOnLoad((Object)(object)_volumeObject);
				_volume = _volumeObject.AddComponent<Volume>();
				_volume.isGlobal = true;
				_volume.priority = 1000f;
			}
			if ((Object)(object)_profile == (Object)null)
			{
				_profile = ScriptableObject.CreateInstance<VolumeProfile>();
				((Object)_profile).hideFlags = (HideFlags)32;
				_effectInstance = _profile.Add<DoomEffect>(true);
				((VolumeParameter)_effectInstance.intensity).overrideState = true;
				((VolumeParameter<float>)(object)_effectInstance.intensity).value = 0f;
			}
			if ((Object)(object)_volume.sharedProfile != (Object)(object)_profile)
			{
				_volume.sharedProfile = _profile;
			}
		}

		public static void SetEffectActive(bool active)
		{
			if ((Object)(object)_effectInstance == (Object)null && active)
			{
				EnsureVolume();
			}
			if ((Object)(object)_effectInstance != (Object)null)
			{
				bool flag = active && ModConfig.ActiveEnablePixelShader;
				((VolumeParameter)_effectInstance.intensity).overrideState = true;
				((VolumeParameter<float>)(object)_effectInstance.intensity).value = (flag ? ModConfig.ActivePixelFilterIntensity : 0f);
			}
		}
	}
}
namespace ShotGunDoom.Patches
{
	[HarmonyPatch]
	internal static class EnemyPatches
	{
		private static readonly FieldRef<MouthDogAI, bool> MouthDogInKillAnimRef = AccessTools.FieldRefAccess<MouthDogAI, bool>("inKillAnimation");

		[HarmonyPatch(typeof(ForestGiantAI), "IVisibleThreat.GetThreatVelocity")]
		[HarmonyPrefix]
		private static bool ForestGiantGetThreatVelocityPrefix(ForestGiantAI __instance)
		{
			return (Object)(object)((EnemyAI)__instance).agent != (Object)null;
		}

		[HarmonyPatch(typeof(MouthDogAI), "IVisibleThreat.GetThreatVelocity")]
		[HarmonyPrefix]
		private static bool MouthDogGetThreatVelocityPrefix(MouthDogAI __instance)
		{
			return (Object)(object)((EnemyAI)__instance).agent != (Object)null;
		}

		[HarmonyPatch(typeof(ForestGiantAI), "GrabPlayerServerRpc")]
		[HarmonyPrefix]
		private static bool ForestGiantGrabPlayerPrefix(int playerId)
		{
			if ((Object)(object)StartOfRound.Instance == (Object)null || (Object)(object)StartOfRound.Instance.localPlayerController == (Object)null)
			{
				return true;
			}
			PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
			if ((int)localPlayerController.playerClientId == playerId)
			{
				DoomShotgunState doomShotgunState = DoomShotgunState.TryGet(localPlayerController.currentlyHeldObjectServer);
				if ((Object)(object)doomShotgunState != (Object)null && doomShotgunState.IsCurseActive)
				{
					doomShotgunState.Damage(15);
					if (doomShotgunState.Health <= 0)
					{
						DoomController.StopDoom(doomShotgunState);
						return true;
					}
					return false;
				}
			}
			return true;
		}

		[HarmonyPatch(typeof(MouthDogAI), "OnCollideWithPlayer")]
		[HarmonyPrefix]
		private static bool MouthDogOnCollideWithPlayerPrefix(MouthDogAI __instance, Collider other)
		{
			PlayerControllerB val = ((EnemyAI)__instance).MeetsStandardPlayerCollisionConditions(other, MouthDogInKillAnimRef.Invoke(__instance), false);
			if ((Object)(object)val != (Object)null && ((EnemyAI)__instance).currentBehaviourStateIndex == 3)
			{
				DoomShotgunState doomShotgunState = DoomShotgunState.TryGet(val.currentlyHeldObjectServer);
				if ((Object)(object)doomShotgunState != (Object)null && doomShotgunState.IsCurseActive)
				{
					if ((Object)(object)StartOfRound.Instance != (Object)null && (Object)(object)val == (Object)(object)StartOfRound.Instance.localPlayerController)
					{
						doomShotgunState.Damage(15);
						if (doomShotgunState.Health <= 0)
						{
							DoomController.StopDoom(doomShotgunState);
							return true;
						}
					}
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal static class PlayerPatches
	{
		private static readonly FieldRef<PlayerControllerB, float> CameraUpRef = AccessTools.FieldRefAccess<PlayerControllerB, float>("cameraUp");

		private static DoomShotgunState GetHeldCursedState(PlayerControllerB player)
		{
			if ((Object)(object)player == (Object)null || (Object)(object)player.currentlyHeldObjectServer == (Object)null)
			{
				return null;
			}
			DoomShotgunState doomShotgunState = DoomShotgunState.TryGet(player.currentlyHeldObjectServer);
			if ((Object)(object)doomShotgunState != (Object)null && doomShotgunState.IsCurseActive)
			{
				return doomShotgunState;
			}
			return null;
		}

		private static bool IsLocalPlayer(PlayerControllerB player)
		{
			if ((Object)(object)player != (Object)null && (Object)(object)StartOfRound.Instance != (Object)null)
			{
				return (Object)(object)player == (Object)(object)StartOfRound.Instance.localPlayerController;
			}
			return false;
		}

		[HarmonyPatch("ConnectClientToPlayerObject")]
		[HarmonyPostfix]
		private static void ConnectClientToPlayerObjectPostfix()
		{
			DoomNetwork.TryAttachToNetworkManager();
			DoomNetwork.RequestConfigSync();
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePostfix(PlayerControllerB __instance)
		{
			if (IsLocalPlayer(__instance))
			{
				DoomController.UpdateLocalPlayer(__instance);
			}
		}

		[HarmonyPatch("CalculateNormalLookingInput")]
		[HarmonyPostfix]
		private static void CalculateNormalLookingInputPostfix(PlayerControllerB __instance)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if (ModConfig.ActiveClampCameraPitch && (Object)(object)GetHeldCursedState(__instance) != (Object)null && IsLocalPlayer(__instance))
			{
				ref float reference = ref CameraUpRef.Invoke(__instance);
				reference = Mathf.Clamp(reference, -20f, 20f);
				if ((Object)(object)__instance.gameplayCamera != (Object)null)
				{
					Vector3 localEulerAngles = ((Component)__instance.gameplayCamera).transform.localEulerAngles;
					((Component)__instance.gameplayCamera).transform.localEulerAngles = new Vector3(reference, localEulerAngles.y, localEulerAngles.z);
				}
			}
		}

		[HarmonyPatch("BeginGrabObject")]
		[HarmonyPrefix]
		private static bool BeginGrabObjectPrefix(PlayerControllerB __instance)
		{
			if ((Object)(object)GetHeldCursedState(__instance) != (Object)null)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch("DiscardHeldObject")]
		[HarmonyPrefix]
		private static bool DiscardHeldObjectPrefix(PlayerControllerB __instance)
		{
			if ((Object)(object)GetHeldCursedState(__instance) != (Object)null)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch("ScrollMouse_performed")]
		[HarmonyPrefix]
		private static bool ScrollMousePrefix(PlayerControllerB __instance, CallbackContext context)
		{
			if (IsLocalPlayer(__instance) && DoomController.LockInventory)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch("SwitchToItemSlot")]
		[HarmonyPrefix]
		private static bool SwitchToItemSlotPrefix(PlayerControllerB __instance, int slot, GrabbableObject fillSlotWithItem)
		{
			if (IsLocalPlayer(__instance) && DoomController.LockInventory && (Object)(object)fillSlotWithItem == (Object)null && slot != __instance.currentItemSlot)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch("DamagePlayer")]
		[HarmonyPrefix]
		private static bool DamagePlayerPrefix(PlayerControllerB __instance, bool fallDamage)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			DoomShotgunState heldCursedState = GetHeldCursedState(__instance);
			if ((Object)(object)heldCursedState != (Object)null)
			{
				if (IsLocalPlayer(__instance))
				{
					if (fallDamage)
					{
						return false;
					}
					heldCursedState.Damage(5);
					if (heldCursedState.Health <= 0)
					{
						DoomController.StopDoom(heldCursedState);
						__instance.health = 0;
						__instance.KillPlayer(Vector3.zero, true, (CauseOfDeath)0, 0, default(Vector3), false);
					}
				}
				return false;
			}
			return true;
		}

		[HarmonyPatch("KillPlayer")]
		[HarmonyPrefix]
		private static bool KillPlayerPrefix(PlayerControllerB __instance, CauseOfDeath causeOfDeath)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Invalid comparison between Unknown and I4
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Invalid comparison between Unknown and I4
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Invalid comparison between Unknown and I4
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Invalid comparison between Unknown and I4
			DoomShotgunState heldCursedState = GetHeldCursedState(__instance);
			if ((Object)(object)heldCursedState != (Object)null && IsLocalPlayer(__instance))
			{
				bool flag = (Object)(object)StartOfRound.Instance != (Object)null && StartOfRound.Instance.shipIsLeaving && !__instance.isInHangarShipRoom;
				if ((int)causeOfDeath == 5 || (int)causeOfDeath == 2 || (int)causeOfDeath == 9 || (int)causeOfDeath == 10 || flag)
				{
					DoomController.StopDoom(heldCursedState);
					return true;
				}
				heldCursedState.Damage(10);
				if (heldCursedState.Health <= 0)
				{
					DoomController.StopDoom(heldCursedState);
					return true;
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch]
	internal static class RoundPatches
	{
		private static readonly FieldRef<InteractTrigger, PlayerControllerB> PlayerInSpecialAnimRef = AccessTools.FieldRefAccess<InteractTrigger, PlayerControllerB>("playerScriptInSpecialAnimation");

		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		[HarmonyPostfix]
		private static void StartOfRoundAwakePostfix(StartOfRound __instance)
		{
			DoomController.ResetAll();
			DoomVolumeManager.EnsureVolume();
			DoomNetwork.TryAttachToNetworkManager();
			DoomScrapManager.EnsureRegistered(__instance);
		}

		[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
		[HarmonyPrefix]
		private static void SpawnScrapInLevelPrefix(RoundManager __instance)
		{
			DoomScrapManager.RefreshForCurrentLevel(__instance.currentLevel);
			DoomScrapManager.IsSpawningScrap = true;
		}

		[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
		[HarmonyFinalizer]
		private static void SpawnScrapInLevelFinalizer()
		{
			DoomScrapManager.IsSpawningScrap = false;
		}

		[HarmonyPatch(typeof(RoundManager), "SyncScrapValuesClientRpc")]
		[HarmonyPostfix]
		private static void SyncScrapValuesClientRpcPostfix(NetworkObjectReference[] spawnedScrap)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (spawnedScrap == null)
			{
				return;
			}
			int num = 0;
			NetworkObject val2 = default(NetworkObject);
			for (int i = 0; i < spawnedScrap.Length; i++)
			{
				NetworkObjectReference val = spawnedScrap[i];
				if (((NetworkObjectReference)(ref val)).TryGet(ref val2, (NetworkManager)null) && (Object)(object)val2 != (Object)null)
				{
					ShotgunItem component = ((Component)val2).GetComponent<ShotgunItem>();
					if ((Object)(object)component != (Object)null)
					{
						DoomShotgunState.GetOrAdd(component)?.MarkAsCursedScrap();
						num++;
					}
				}
			}
			if (num > 0)
			{
				Plugin.Log.LogInfo((object)$"Marked {num} scrap-spawned Shotgun(s) as DOOM cursed.");
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "EndOfGame")]
		[HarmonyPrefix]
		private static void EndOfGamePrefix()
		{
			DoomController.ResetAll();
		}

		[HarmonyPatch(typeof(InteractTrigger), "CancelLadderAnimation")]
		[HarmonyPostfix]
		private static void CancelLadderAnimationPostfix(InteractTrigger __instance)
		{
			PlayerControllerB val = PlayerInSpecialAnimRef.Invoke(__instance);
			if (!((Object)(object)val == (Object)null))
			{
				DoomShotgunState doomShotgunState = DoomShotgunState.TryGet(val.currentlyHeldObjectServer);
				if ((Object)(object)doomShotgunState != (Object)null && doomShotgunState.IsCurseActive && (Object)(object)doomShotgunState.Shotgun != (Object)null)
				{
					((GrabbableObject)doomShotgunState.Shotgun).EnableItemMeshes(false);
				}
			}
		}
	}
	[HarmonyPatch]
	internal static class ShotgunPatches
	{
		[HarmonyPatch(typeof(ShotgunItem), "Start")]
		[HarmonyPostfix]
		private static void StartPostfix(ShotgunItem __instance)
		{
			DoomShotgunState orAdd = DoomShotgunState.GetOrAdd(__instance);
			if (!((Object)(object)orAdd == (Object)null))
			{
				if (DoomScrapManager.IsSpawningScrap)
				{
					orAdd.MarkAsCursedScrap();
				}
				else if (((GrabbableObject)__instance).isInShipRoom || ((GrabbableObject)__instance).isInElevator)
				{
					orAdd.CurseLifted = true;
					orAdd.CurseLiftedLastFrame = true;
				}
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "GrabItem")]
		[HarmonyPostfix]
		private static void GrabItemPostfix(GrabbableObject __instance)
		{
			ShotgunItem val = (ShotgunItem)(object)((__instance is ShotgunItem) ? __instance : null);
			if (val != null)
			{
				TryStartDoomForShotgun(val);
			}
		}

		[HarmonyPatch(typeof(ShotgunItem), "EquipItem")]
		[HarmonyPostfix]
		private static void EquipItemPostfix(ShotgunItem __instance)
		{
			TryStartDoomForShotgun(__instance);
		}

		private static void TryStartDoomForShotgun(ShotgunItem shotgun)
		{
			if ((Object)(object)shotgun == (Object)null || (Object)(object)((GrabbableObject)shotgun).playerHeldBy == (Object)null)
			{
				return;
			}
			DoomShotgunState doomShotgunState = DoomShotgunState.TryGet((GrabbableObject)(object)shotgun);
			if (!((Object)(object)doomShotgunState == (Object)null) && doomShotgunState.IsCursedScrap)
			{
				if (((GrabbableObject)shotgun).playerHeldBy.isInHangarShipRoom)
				{
					doomShotgunState.CurseLifted = true;
					doomShotgunState.CurseLiftedLastFrame = true;
				}
				else if (doomShotgunState.IsCurseActive && doomShotgunState.IsHeldByLocalPlayer)
				{
					DoomController.StartDoom(doomShotgunState);
				}
			}
		}

		[HarmonyPatch(typeof(ShotgunItem), "Update")]
		[HarmonyPostfix]
		private static void UpdatePostfix(ShotgunItem __instance)
		{
			DoomShotgunState.TryGet((GrabbableObject)(object)__instance)?.TickShotgunUpdate();
		}

		[HarmonyPatch(typeof(ShotgunItem), "ItemActivate")]
		[HarmonyPrefix]
		private static bool ItemActivatePrefix(ShotgunItem __instance, bool used, bool buttonDown)
		{
			DoomShotgunState doomShotgunState = DoomShotgunState.TryGet((GrabbableObject)(object)__instance);
			if ((Object)(object)doomShotgunState != (Object)null && doomShotgunState.IsCurseActive && DoomController.DoomRunning && (Object)(object)DoomController.ActiveState == (Object)(object)doomShotgunState)
			{
				if (buttonDown)
				{
					DoomController.TryShoot(doomShotgunState);
				}
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(ShotgunItem), "ItemInteractLeftRight")]
		[HarmonyPrefix]
		private static bool ItemInteractLeftRightPrefix(ShotgunItem __instance)
		{
			DoomShotgunState doomShotgunState = DoomShotgunState.TryGet((GrabbableObject)(object)__instance);
			if ((Object)(object)doomShotgunState != (Object)null && doomShotgunState.IsCurseActive && DoomController.DoomRunning && (Object)(object)DoomController.ActiveState == (Object)(object)doomShotgunState)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(ShotgunItem), "DiscardItem")]
		[HarmonyPostfix]
		private static void DiscardItemPostfix(ShotgunItem __instance)
		{
			DoomShotgunState doomShotgunState = DoomShotgunState.TryGet((GrabbableObject)(object)__instance);
			if ((Object)(object)doomShotgunState != (Object)null && (Object)(object)DoomController.ActiveState == (Object)(object)doomShotgunState)
			{
				DoomController.StopDoom(doomShotgunState);
			}
		}

		[HarmonyPatch(typeof(ShotgunItem), "PocketItem")]
		[HarmonyPostfix]
		private static void PocketItemPostfix(ShotgunItem __instance)
		{
			DoomShotgunState doomShotgunState = DoomShotgunState.TryGet((GrabbableObject)(object)__instance);
			if ((Object)(object)doomShotgunState != (Object)null && (Object)(object)DoomController.ActiveState == (Object)(object)doomShotgunState)
			{
				DoomController.StopDoom(doomShotgunState);
			}
		}
	}
}
namespace ShotGunDoom.Network
{
	internal static class DoomNetwork
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Action <0>__OnHostSettingChanged;

			public static Action <1>__OnNetworkStarted;

			public static Action<bool> <2>__OnNetworkStopped;

			public static Action<ulong> <3>__OnClientConnected;

			public static HandleNamedMessageDelegate <4>__OnReceiveShotgunRelay;

			public static HandleNamedMessageDelegate <5>__OnReceiveCurseLiftedRelay;

			public static HandleNamedMessageDelegate <6>__OnReceiveConfigSyncRequest;

			public static HandleNamedMessageDelegate <7>__OnReceiveShotgun;

			public static HandleNamedMessageDelegate <8>__OnReceiveCurseLifted;

			public static HandleNamedMessageDelegate <9>__OnReceiveConfigSync;
		}

		private const string MsgShotgun = "ShotGunDoom_Shotgun";

		private const string MsgShotgunRelay = "ShotGunDoom_ShotgunRelay";

		private const string MsgCurseLifted = "ShotGunDoom_CurseLifted";

		private const string MsgCurseLiftedRelay = "ShotGunDoom_CurseLiftedRelay";

		private const string MsgConfigSync = "ShotGunDoom_ConfigSync";

		private const string MsgConfigSyncRequest = "ShotGunDoom_ConfigSyncRequest";

		private static bool _hooksAttached;

		private static bool _configHooked;

		private static NetworkManager _attachedManager;

		public static void Initialize()
		{
			if (!_configHooked)
			{
				_configHooked = true;
				ModConfig.OnSyncedConfigChanged += OnHostSettingChanged;
			}
			TryAttachToNetworkManager();
		}

		private static void OnHostSettingChanged()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton != (Object)null && singleton.IsListening)
			{
				if (singleton.IsServer)
				{
					BroadcastConfigToAllClients();
					DoomController.ApplyLiveConfig();
				}
			}
			else
			{
				DoomController.ApplyLiveConfig();
			}
		}

		public static void TryAttachToNetworkManager()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton == (Object)null) && (!_hooksAttached || !((Object)(object)_attachedManager == (Object)(object)singleton)))
			{
				_attachedManager = singleton;
				_hooksAttached = true;
				singleton.OnServerStarted += OnNetworkStarted;
				singleton.OnClientStarted += OnNetworkStarted;
				singleton.OnServerStopped += OnNetworkStopped;
				singleton.OnClientStopped += OnNetworkStopped;
				singleton.OnClientConnectedCallback += OnClientConnected;
				if (singleton.IsListening)
				{
					RegisterHandlers();
				}
			}
		}

		private static void OnNetworkStarted()
		{
			RegisterHandlers();
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton != (Object)null && !singleton.IsServer)
			{
				RequestConfigSync();
			}
		}

		private static void OnClientConnected(ulong clientId)
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton != (Object)null && singleton.IsServer && clientId != 0L)
			{
				SendConfigToClient(clientId);
			}
		}

		private static void OnNetworkStopped(bool _)
		{
			UnregisterHandlers();
			ModConfig.ClearSynced();
			DoomController.ResetAll();
		}

		public static void RegisterHandlers()
		{
			//IL_00f2: 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_00fd: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_0118: 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_0123: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_013e: 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_0149: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || singleton.CustomMessagingManager == null)
			{
				return;
			}
			CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager;
			customMessagingManager.UnregisterNamedMessageHandler("ShotGunDoom_Shotgun");
			customMessagingManager.UnregisterNamedMessageHandler("ShotGunDoom_ShotgunRelay");
			customMessagingManager.UnregisterNamedMessageHandler("ShotGunDoom_CurseLifted");
			customMessagingManager.UnregisterNamedMessageHandler("ShotGunDoom_CurseLiftedRelay");
			customMessagingManager.UnregisterNamedMessageHandler("ShotGunDoom_ConfigSync");
			customMessagingManager.UnregisterNamedMessageHandler("ShotGunDoom_ConfigSyncRequest");
			if (singleton.IsServer)
			{
				object obj = <>O.<4>__OnReceiveShotgunRelay;
				if (obj == null)
				{
					HandleNamedMessageDelegate val = OnReceiveShotgunRelay;
					<>O.<4>__OnReceiveShotgunRelay = val;
					obj = (object)val;
				}
				customMessagingManager.RegisterNamedMessageHandler("ShotGunDoom_ShotgunRelay", (HandleNamedMessageDelegate)obj);
				object obj2 = <>O.<5>__OnReceiveCurseLiftedRelay;
				if (obj2 == null)
				{
					HandleNamedMessageDelegate val2 = OnReceiveCurseLiftedRelay;
					<>O.<5>__OnReceiveCurseLiftedRelay = val2;
					obj2 = (object)val2;
				}
				customMessagingManager.RegisterNamedMessageHandler("ShotGunDoom_CurseLiftedRelay", (HandleNamedMessageDelegate)obj2);
				object obj3 = <>O.<6>__OnReceiveConfigSyncRequest;
				if (obj3 == null)
				{
					HandleNamedMessageDelegate val3 = OnReceiveConfigSyncRequest;
					<>O.<6>__OnReceiveConfigSyncRequest = val3;
					obj3 = (object)val3;
				}
				customMessagingManager.RegisterNamedMessageHandler("ShotGunDoom_ConfigSyncRequest", (HandleNamedMessageDelegate)obj3);
			}
			else
			{
				object obj4 = <>O.<7>__OnReceiveShotgun;
				if (obj4 == null)
				{
					HandleNamedMessageDelegate val4 = OnReceiveShotgun;
					<>O.<7>__OnReceiveShotgun = val4;
					obj4 = (object)val4;
				}
				customMessagingManager.RegisterNamedMessageHandler("ShotGunDoom_Shotgun", (HandleNamedMessageDelegate)obj4);
				object obj5 = <>O.<8>__OnReceiveCurseLifted;
				if (obj5 == null)
				{
					HandleNamedMessageDelegate val5 = OnReceiveCurseLifted;
					<>O.<8>__OnReceiveCurseLifted = val5;
					obj5 = (object)val5;
				}
				customMessagingManager.RegisterNamedMessageHandler("ShotGunDoom_CurseLifted", (HandleNamedMessageDelegate)obj5);
				object obj6 = <>O.<9>__OnReceiveConfigSync;
				if (obj6 == null)
				{
					HandleNamedMessageDelegate val6 = OnReceiveConfigSync;
					<>O.<9>__OnReceiveConfigSync = val6;
					obj6 = (object)val6;
				}
				customMessagingManager.RegisterNamedMessageHandler("ShotGunDoom_ConfigSync", (HandleNamedMessageDelegate)obj6);
			}
		}

		private static void UnregisterHandlers()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton == (Object)null) && singleton.CustomMessagingManager != null)
			{
				CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager;
				customMessagingManager.UnregisterNamedMessageHandler("ShotGunDoom_Shotgun");
				customMessagingManager.UnregisterNamedMessageHandler("ShotGunDoom_ShotgunRelay");
				customMessagingManager.UnregisterNamedMessageHandler("ShotGunDoom_CurseLifted");
				customMessagingManager.UnregisterNamedMessageHandler("ShotGunDoom_CurseLiftedRelay");
				customMessagingManager.UnregisterNamedMessageHandler("ShotGunDoom_ConfigSync");
				customMessagingManager.UnregisterNamedMessageHandler("ShotGunDoom_ConfigSyncRequest");
			}
		}

		public unsafe static void RequestConfigSync()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsListening || singleton.IsServer || singleton.CustomMessagingManager == null)
			{
				return;
			}
			try
			{
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(8, (Allocator)2, -1);
				try
				{
					byte b = 1;
					((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
					singleton.CustomMessagingManager.SendNamedMessage("ShotGunDoom_ConfigSyncRequest", 0uL, val, (NetworkDelivery)3);
				}
				finally
				{
					((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Failed to request config sync from host: " + ex.Message));
			}
		}

		public unsafe static void BroadcastConfigToAllClients()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsServer || !singleton.IsListening || singleton.CustomMessagingManager == null)
			{
				return;
			}
			List<ulong> remoteClients = GetRemoteClients(singleton, 0uL);
			if (remoteClients.Count == 0)
			{
				return;
			}
			try
			{
				SyncedConfigData syncedConfigData = ModConfig.CreateLocalSnapshot();
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(1024, (Allocator)2, 65536);
				try
				{
					syncedConfigData.Write(val);
					singleton.CustomMessagingManager.SendNamedMessage("ShotGunDoom_ConfigSync", (IReadOnlyList<ulong>)remoteClients, val, (NetworkDelivery)4);
					Plugin.Log.LogInfo((object)$"Broadcast live config sync to {remoteClients.Count} client(s).");
				}
				finally
				{
					((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Failed to broadcast live config sync: {arg}");
			}
		}

		private unsafe static void SendConfigToClient(ulong clientId)
		{
			//IL_003a: 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)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsServer || singleton.CustomMessagingManager == null)
			{
				return;
			}
			try
			{
				SyncedConfigData syncedConfigData = ModConfig.CreateLocalSnapshot();
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(1024, (Allocator)2, 65536);
				try
				{
					syncedConfigData.Write(val);
					singleton.CustomMessagingManager.SendNamedMessage("ShotGunDoom_ConfigSync", clientId, val, (NetworkDelivery)4);
				}
				finally
				{
					((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Failed to send config sync to client {clientId}: {arg}");
			}
		}

		private static void OnReceiveConfigSyncRequest(ulong senderClientId, FastBufferReader reader)
		{
			SendConfigToClient(senderClientId);
		}

		private static void OnReceiveConfigSync(ulong senderClientId, FastBufferReader reader)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				ModConfig.ApplySynced(SyncedConfigData.Read(reader));
				DoomController.ApplyLiveConfig();
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Failed to read synced config from host: {arg}");
			}
		}

		public unsafe static void SendDoomShotgun(int playerNum, Vector3 position, Vector3 forward)
		{
			//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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			HandleDoomShotgun(playerNum, position, forward);
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsListening || singleton.CustomMessagingManager == null)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(64, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref playerNum, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe(ref position);
				((FastBufferWriter)(ref val)).WriteValueSafe(ref forward);
				if (singleton.IsServer)
				{
					List<ulong> remoteClients = GetRemoteClients(singleton, 0uL);
					if (remoteClients.Count > 0)
					{
						singleton.CustomMessagingManager.SendNamedMessage("ShotGunDoom_Shotgun", (IReadOnlyList<ulong>)remoteClients, val, (NetworkDelivery)3);
					}
				}
				else
				{
					singleton.CustomMessagingManager.SendNamedMessage("ShotGunDoom_ShotgunRelay", 0uL, val, (NetworkDelivery)3);
				}
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		public unsafe static void SendCurseLifted(ShotgunItem shotgun)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)shotgun == (Object)null || (Object)(object)singleton == (Object)null || !singleton.IsListening || singleton.CustomMessagingManager == null)
			{
				return;
			}
			NetworkObject component = ((Component)shotgun).GetComponent<NetworkObject>();
			if ((Object)(object)component == (Object)null || !component.IsSpawned)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1);
			try
			{
				ulong networkObjectId = component.NetworkObjectId;
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref networkObjectId, default(ForPrimitives));
				if (singleton.IsServer)
				{
					List<ulong> remoteClients = GetRemoteClients(singleton, 0uL);
					if (remoteClients.Count > 0)
					{
						singleton.CustomMessagingManager.SendNamedMessage("ShotGunDoom_CurseLifted", (IReadOnlyList<ulong>)remoteClients, val, (NetworkDelivery)3);
					}
				}
				else
				{
					singleton.CustomMessagingManager.SendNamedMessage("ShotGunDoom_CurseLiftedRelay", 0uL, val, (NetworkDelivery)3);
				}
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void OnReceiveShotgun(ulong senderClientId, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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)
			int playerNum = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref playerNum, default(ForPrimitives));
			Vector3 shotgunPosition = default(Vector3);
			((FastBufferReader)(ref reader)).ReadValueSafe(ref shotgunPosition);
			Vector3 shotgunForward = default(Vector3);
			((FastBufferReader)(ref reader)).ReadValueSafe(ref shotgunForward);
			HandleDoomShotgun(playerNum, shotgunPosition, shotgunForward);
		}

		private unsafe static void OnReceiveShotgunRelay(ulong senderClientId, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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)
			int playerNum = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref playerNum, default(ForPrimitives));
			Vector3 shotgunPosition = default(Vector3);
			((FastBufferReader)(ref reader)).ReadValueSafe(ref shotgunPosition);
			Vector3 shotgunForward = default(Vector3);
			((FastBufferReader)(ref reader)).ReadValueSafe(ref shotgunForward);
			HandleDoomShotgun(playerNum, shotgunPosition, shotgunForward);
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton != (Object)null) || !singleton.IsServer || singleton.CustomMessagingManager == null)
			{
				return;
			}
			List<ulong> remoteClients = GetRemoteClients(singleton, senderClientId);
			if (remoteClients.Count > 0)
			{
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(64, (Allocator)2, -1);
				try
				{
					((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref playerNum, default(ForPrimitives));
					((FastBufferWriter)(ref val)).WriteValueSafe(ref shotgunPosition);
					((FastBufferWriter)(ref val)).WriteValueSafe(ref shotgunForward);
					singleton.CustomMessagingManager.SendNamedMessage("ShotGunDoom_Shotgun", (IReadOnlyList<ulong>)remoteClients, val, (NetworkDelivery)3);
				}
				finally
				{
					((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
				}
			}
		}

		private static void OnReceiveCurseLifted(ulong senderClientId, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			ulong netObjId = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref netObjId, default(ForPrimitives));
			ApplyCurseLifted(netObjId);
		}

		private unsafe static void OnReceiveCurseLiftedRelay(ulong senderClientId, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			ulong netObjId = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref netObjId, default(ForPrimitives));
			ApplyCurseLifted(netObjId);
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton != (Object)null) || !singleton.IsServer || singleton.CustomMessagingManager == null)
			{
				return;
			}
			List<ulong> remoteClients = GetRemoteClients(singleton, senderClientId);
			if (remoteClients.Count > 0)
			{
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1);
				try
				{
					((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref netObjId, default(ForPrimitives));
					singleton.CustomMessagingManager.SendNamedMessage("ShotGunDoom_CurseLifted", (IReadOnlyList<ulong>)remoteClients, val, (NetworkDelivery)3);
				}
				finally
				{
					((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
				}
			}
		}

		private static void ApplyCurseLifted(ulong netObjId)
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton == (Object)null) && singleton.SpawnManager != null && singleton.SpawnManager.SpawnedObjects.TryGetValue(netObjId, out var value) && (Object)(object)value != (Object)null)
			{
				ShotgunItem component = ((Component)value).GetComponent<ShotgunItem>();
				if ((Object)(object)component != (Object)null)
				{
					DoomShotgunState.GetOrAdd(component)?.ApplyCurseLiftedFromNetwork();
				}
			}
		}

		private static void HandleDoomShotgun(int playerNum, Vector3 shotgunPosition, Vector3 shotgunForward)
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: 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_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				return;
			}
			PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
			if ((Object)(object)localPlayerController != (Object)null && !localPlayerController.isPlayerDead && (int)localPlayerController.playerClientId != playerNum)
			{
				Vector3 val = localPlayerController.playerCollider.ClosestPoint(shotgunPosition);
				bool flag = false;
				if (!Physics.Linecast(shotgunPosition, val, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1) && Vector3.Angle(shotgunForward, val - shotgunPosition) < 30f)
				{
					flag = Vector3.Distance(val, shotgunPosition) < 10f;
				}
				if (flag)
				{
					Vector3 val2 = ((Component)localPlayerController).transform.position - shotgunPosition;
					Vector3 val3 = ((Vector3)(ref val2)).normalized * 5f;
					val2 = default(Vector3);
					localPlayerController.KillPlayer(val3, true, (CauseOfDeath)7, 0, val2, false);
				}
			}
			if (!((Object)(object)NetworkManager.Singleton != (Object)null) || !NetworkManager.Singleton.IsServer)
			{
				return;
			}
			Collider[] array = Physics.OverlapBox(shotgunPosition + shotgunForward * 10f, new Vector3(1.5f, 4f, 10f), Quaternion.LookRotation(shotgunForward), -1, (QueryTriggerInteraction)2);
			HashSet<EnemyAI> hashSet = new HashSet<EnemyAI>();
			Collider[] array2 = array;
			foreach (Collider val4 in array2)
			{
				if ((Object)(object)val4 == (Object)null)
				{
					continue;
				}
				EnemyAI val5 = ((Component)val4).GetComponent<EnemyAI>() ?? ((Component)val4).GetComponentInParent<EnemyAI>();
				if (!((Object)(object)val5 == (Object)null) && !val5.isEnemyDead && !hashSet.Contains(val5))
				{
					Vector3 val6 = val4.ClosestPoint(shotgunPosition);
					if (!Physics.Linecast(shotgunPosition, val6, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
					{
						hashSet.Add(val5);
						DoomEnemySpawner.KillEnemy(val5);
					}
				}
			}
		}

		private static List<ulong> GetRemoteClients(NetworkManager nm, ulong excludeClientId)
		{
			List<ulong> list = new List<ulong>();
			foreach (ulong connectedClientsId in nm.ConnectedClientsIds)
			{
				if (connectedClientsId != 0L && connectedClientsId != excludeClientId)
				{
					list.Add(connectedClientsId);
				}
			}
			return list;
		}
	}
}
namespace ShotGunDoom.Core
{
	internal static class DoomController
	{
		private static Light _doomLight;

		private static PlayerControllerB _doomPlayer;

		private static float _originalFarClipPlane = -1f;

		private static bool _vanillaHudHidden;

		public static bool DoomRunning { get; private set; }

		public static DoomShotgunState ActiveState { get; private set; }

		public static DoomHUD CurrentHUD { get; private set; }

		public static bool LockInventory
		{
			get
			{
				if (DoomRunning && (Object)(object)ActiveState != (Object)null)
				{
					return ActiveState.IsCurseActive;
				}
				return false;
			}
		}

		private static void SetVanillaHUDVisible(bool visible)
		{
			if ((Object)(object)HUDManager.Instance == (Object)null || (Object)(object)HUDManager.Instance.HUDContainer == (Object)null)
			{
				return;
			}
			GameObject hUDContainer = HUDManager.Instance.HUDContainer;
			CanvasGroup val = hUDContainer.GetComponent<CanvasGroup>();
			if ((Object)(object)val == (Object)null)
			{
				val = hUDContainer.AddComponent<CanvasGroup>();
			}
			val.alpha = (visible ? 1f : 0f);
			val.blocksRaycasts = visible;
			_vanillaHudHidden = !visible;
			if (visible)
			{
				if (!hUDContainer.activeSelf)
				{
					hUDContainer.SetActive(true);
				}
				PlayerControllerB val2 = StartOfRound.Instance?.localPlayerController;
				bool clockVisible = (Object)(object)val2 != (Object)null && !val2.isInsideFactory;
				HUDManager.Instance.SetClockVisible(clockVisible);
				if ((Object)(object)TimeOfDay.Instance != (Object)null)
				{
					TimeOfDay.Instance.RefreshClockUI();
				}
			}
		}

		public static void StartDoom(DoomShotgunState state)
		{
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)state == (Object)null || (Object)(object)state.Shotgun == (Object)null || !state.IsCurseActive)
			{
				return;
			}
			PlayerControllerB playerHeldBy = ((GrabbableObject)state.Shotgun).playerHeldBy;
			if ((Object)(object)playerHeldBy == (Object)null || (Object)(object)StartOfRound.Instance == (Object)null || (Object)(object)playerHeldBy != (Object)(object)StartOfRound.Instance.localPlayerController || (DoomRunning && (Object)(object)ActiveState == (Object)(object)state))
			{
				return;
			}
			if (DoomRunning)
			{
				StopDoom(ActiveState);
			}
			if (!DoomAssets.IsLoaded)
			{
				Plugin.Log.LogError((object)"Cannot start Doom mode: DoomAssets not loaded.");
				return;
			}
			DoomRunning = true;
			ActiveState = state;
			_doomPlayer = playerHeldBy;
			SetVanillaHUDVisible(visible: false);
			SetLocalArmsVisible(playerHeldBy, visible: false);
			((GrabbableObject)state.Shotgun).EnableItemMeshes(false);
			if ((Object)(object)CurrentHUD == (Object)null && (Object)(object)HUDManager.Instance != (Object)null)
			{
				Transform val = null;
				if ((Object)(object)HUDManager.Instance.HUDContainer != (Object)null)
				{
					val = HUDManager.Instance.HUDContainer.transform.parent;
				}
				if ((Object)(object)val == (Object)null && (Object)(object)HUDManager.Instance.HUDAnimator != (Object)null)
				{
					val = ((Component)HUDManager.Instance.HUDAnimator).gameObject.transform.parent;
				}
				if ((Object)(object)val != (Object)null)
				{
					GameObject val2 = Object.Instantiate<GameObject>(DoomAssets.DoomHUDPrefab, val);
					if ((Object)(object)HUDManager.Instance.HUDContainer != (Object)null && (Object)(object)HUDManager.Instance.HUDContainer.transform.parent == (Object)(object)val)
					{
						val2.transform.SetSiblingIndex(HUDManager.Instance.HUDContainer.transform.GetSiblingIndex());
					}
					else
					{
						val2.transform.SetAsFirstSibling();
					}
					CanvasGroup obj = val2.GetComponent<CanvasGroup>() ?? val2.AddComponent<CanvasGroup>();
					obj.blocksRaycasts = false;
					obj.interactable = false;
					RectTransform component = val2.GetComponent<RectTransform>();
					if ((Object)(object)component != (Object)null)
					{
						component.anchoredPosition = Vector2.zero;
					}
					CurrentHUD = val2.GetComponent<DoomHUD>();
					if ((Object)(object)CurrentHUD != (Object)null)
					{
						CurrentHUD.HP = state.Health;
						CurrentHUD.Armor = state.Armor;
						CurrentHUD.ShellsAmmo = state.RemainingShells;
					}
				}
			}
			DoomVolumeManager.EnsureVolume();
			DoomVolumeManager.SetEffectActive(active: true);
			if (ModConfig.ActiveEnableDoomLight)
			{
				CreateDoomLight(playerHeldBy);
			}
			if ((Object)(object)playerHeldBy.gameplayCamera != (Object)null)
			{
				_originalFarClipPlane = playerHeldBy.gameplayCamera.farClipPlane;
				playerHeldBy.gameplayCamera.farClipPlane = _originalFarClipPlane * ModConfig.ActiveViewDistanceMultiplier;
			}
			Plugin.Log.LogInfo((object)"DOOM mode started!");
		}

		public static void StopDoom(DoomShotgunState state = null)
		{
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			if (!DoomRunning || ((Object)(object)state != (Object)null && (Object)(object)ActiveState != (Object)null && (Object)(object)state != (Object)(object)ActiveState))
			{
				return;
			}
			PlayerControllerB val = _doomPlayer ?? state?.LastPlayerHeldBy ?? StartOfRound.Instance?.localPlayerController;
			ShotgunItem val2 = state?.Shotgun ?? ActiveState?.Shotgun;
			if ((Object)(object)_doomLight != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_doomLight).gameObject);
				_doomLight = null;
			}
			if ((Object)(object)CurrentHUD != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)CurrentHUD).gameObject);
				CurrentHUD = null;
			}
			if (_vanillaHudHidden || (Object)(object)HUDManager.Instance != (Object)null)
			{
				SetVanillaHUDVisible(visible: true);
			}
			if ((Object)(object)val != (Object)null)
			{
				SetLocalArmsVisible(val, visible: true);
				if ((Object)(object)val.gameplayCamera != (Object)null)
				{
					((Component)val.gameplayCamera).transform.localPosition = Vector3.zero;
					if (_originalFarClipPlane > 0f)
					{
						val.gameplayCamera.farClipPlane = _originalFarClipPlane;
					}
				}
			}
			_originalFarClipPlane = -1f;
			if ((Object)(object)val2 != (Object)null)
			{
				((GrabbableObject)val2).EnableItemMeshes(true);
			}
			DoomVolumeManager.SetEffectActive(active: false);
			DoomRunning = false;
			ActiveState = null;
			_doomPlayer = null;
			Plugin.Log.LogInfo((object)"DOOM mode stopped.");
		}

		public static void TryShoot(DoomShotgunState state)
		{
			//IL_0099: 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)
			if (!DoomRunning || (Object)(object)state == (Object)null || (Object)(object)state != (Object)(object)ActiveState || !state.IsCurseActive || (Object)(object)CurrentHUD == (Object)null)
			{
				return;
			}
			PlayerControllerB val = ((GrabbableObject)(state.Shotgun?)).playerHeldBy;
			if (!((Object)(object)val == (Object)null) && !val.isPlayerDead && !((Object)(object)val.gameplayCamera == (Object)null) && CurrentHUD.Shoot())
			{
				state.RemainingShells = CurrentHUD.ShellsAmmo;
				DoomNetwork.SendDoomShotgun((int)val.playerClientId, ((Component)val.gameplayCamera).transform.position, ((Component)val.gameplayCamera).transform.forward);
				if (Random.value > 0.5f)
				{
					CurrentHUD.HeadPhase = DoomHUD.SpritePhase.MANIAC;
					state.ManiacPhase = 0.5f;
					state.LeftPhase = 0f;
					state.RightPhase = 0f;
					state.DamagePhase = 0f;
				}
			}
		}

		public static void UpdateLocalPlayer(PlayerControllerB player)
		{
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			DoomVolumeManager.SetEffectActive(DoomRunning);
			if (!DoomRunning || !((Object)(object)ActiveState != (Object)null) || !ActiveState.IsCurseActive || !((Object)(object)CurrentHUD != (Object)null))
			{
				return;
			}
			if (player.isPlayerDead || (Object)(object)player.currentlyHeldObjectServer != (Object)(object)ActiveState.Shotgun)
			{
				StopDoom(ActiveState);
				return;
			}
			player.health = 100;
			player.sprintMeter = 1f;
			player.carryWeight = 1f;
			CurrentHUD.HP = ActiveState.Health;
			CurrentHUD.Armor = ActiveState.Armor;
			if (ActiveState.DamagePhase > 0f)
			{
				ActiveState.DamagePhase -= Time.deltaTime;
			}
			if (ActiveState.ManiacPhase > 0f)
			{
				ActiveState.ManiacPhase -= Time.deltaTime;
			}
			if (ActiveState.LeftPhase > 0f)
			{
				ActiveState.LeftPhase -= Time.deltaTime;
				if (ActiveState.LeftPhase <= 0f)
				{
					ActiveState.RightPhase = 0.5f;
					CurrentHUD.HeadPhase = DoomHUD.SpritePhase.RIGHT;
				}
			}
			if (ActiveState.RightPhase > 0f)
			{
				ActiveState.RightPhase -= Time.deltaTime;
			}
			if (ActiveState.ManiacPhase <= 0f && ActiveState.LeftPhase <= 0f && ActiveState.RightPhase <= 0f && ActiveState.DamagePhase <= 0f)
			{
				if (CurrentHUD.HeadPhase != DoomHUD.SpritePhase.STRAIGHT)
				{
					CurrentHUD.HeadPhase = DoomHUD.SpritePhase.STRAIGHT;
				}
				if (ActiveState.WalkPhase > 0f && Random.value > 0.998f)
				{
					ActiveState.LeftPhase = 0.5f;
					CurrentHUD.HeadPhase = DoomHUD.SpritePhase.LEFT;
				}
			}
			if (((Vector2)(ref player.moveInputVector)).sqrMagnitude > 0.1f)
			{
				if ((Object)(object)CurrentHUD.ShotgunAnimator != (Object)null)
				{
					CurrentHUD.ShotgunAnimator.SetBool("Walking", true);
				}
				ActiveState.WalkPhase += Time.deltaTime * 5f;
				while (ActiveState.WalkPhase > MathF.PI)
				{
					ActiveState.WalkPhase -= MathF.PI;
				}
			}
			else
			{
				ActiveState.WalkPhase = Mathf.Lerp(ActiveState.WalkPhase, (ActiveState.WalkPhase > MathF.PI / 2f) ? MathF.PI : 0f, Time.deltaTime * 5f);
				if ((Object)(object)CurrentHUD.ShotgunAnimator != (Object)null)
				{
					CurrentHUD.ShotgunAnimator.SetBool("Walking", false);
				}
			}
			if ((Object)(object)player.gameplayCamera != (Object)null)
			{
				if (ModConfig.ActiveEnableHeadBob)
				{
					((Component)player.gameplayCamera).transform.localPosition = new Vector3(0f, Mathf.Sin(ActiveState.WalkPhase) * -0.4f, 0f);
				}
				else
				{
					((Component)player.gameplayCamera).transform.localPosition = Vector3.zero;
				}
			}
		}

		private static void SetLocalArmsVisible(PlayerControllerB player, bool visible)
		{
			if (!((Object)(object)player == (Object)null) && !((Object)(object)player.localArmsTransform == (Object)null))
			{
				Transform parent = player.localArmsTransform.parent;
				if ((Object)(object)parent != (Object)null && (Object)(object)parent.parent != (Object)null)
				{
					((Component)parent.parent).gameObject.SetActive(visible);
				}
			}
		}

		private static void CreateDoomLight(PlayerControllerB player)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_doomLight != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_doomLight).gameObject);
				_doomLight = null;
			}
			Transform val = ((Component)player).transform.Find("ScavengerModel/metarig");
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)player).transform;
			}
			GameObject val2 = new GameObject("DoomLight");
			val2.transform.SetParent(val, false);
			val2.transform.localPosition = new Vector3(0f, 0f, 1f);
			val2.transform.localRotation = Quaternion.Euler(90f, 90f, 0f);
			_doomLight = val2.AddComponent<Light>();
			_doomLight.color = new Color(0.5f, 0.5f, 0.5f);
			_doomLight.type = (LightType)0;
			_doomLight.shape = (LightShape)2;
			_doomLight.cullingMask = 2147483519;
			HDAdditionalLightData obj = val2.AddComponent<HDAdditionalLightData>();
			obj.SetBoxSpotSize(new Vector2(500f, 500f));
			obj.SetIntensity(30f, (LightUnit)2);
			obj.spotLightShape = (SpotLightShape)2;
			obj.affectsVolumetric = true;
			obj.volumetricDimmer = 0f;
			obj.range = 1000f;
			obj.lightDimmer = 1f;
			obj.SetCullingMask(2147483519);
		}

		public static void ApplyLiveConfig()
		{
			if (!DoomRunning)
			{
				return;
			}
			DoomVolumeManager.SetEffectActive(active: true);
			PlayerControllerB val = _doomPlayer ?? StartOfRound.Instance?.localPlayerController;
			if (!((Object)(object)val != (Object)null))
			{
				return;
			}
			if (ModConfig.ActiveEnableDoomLight)
			{
				if ((Object)(object)_doomLight == (Object)null)
				{
					CreateDoomLight(val);
				}
			}
			else if ((Object)(object)_doomLight != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_doomLight).gameObject);
				_doomLight = null;
			}
			if ((Object)(object)val.gameplayCamera != (Object)null && _originalFarClipPlane > 0f)
			{
				val.gameplayCamera.farClipPlane = _originalFarClipPlane * ModConfig.ActiveViewDistanceMultiplier;
			}
		}

		public static void ResetAll()
		{
			StopDoom();
			DoomEnemySpawner.Reset();
		}
	}
	internal static class DoomEnemySpawner
	{
		private static readonly MethodInfo SubtractFromPowerLevelMethod = AccessTools.Method(typeof(EnemyAI), "SubtractFromPowerLevel", (Type[])null, (Type[])null);

		private static readonly List<EnemyAI> OutsideSpawnedEnemies = new List<EnemyAI>();

		private static readonly List<EnemyAI> InsideSpawnedEnemies = new List<EnemyAI>();

		private static readonly Dictionary<string, EnemyType> EnemyTypesByName = new Dictionary<string, EnemyType>(StringComparer.OrdinalIgnoreCase);

		private static readonly List<PlayerControllerB> ActiveCarriersBuffer = new List<PlayerControllerB>();

		private static string _cachedExcludedRaw;

		private static HashSet<string> _excludedNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

		private static List<EnemyType> _spawnInsideRotation;

		private static List<EnemyType> _spawnOutsideRotation;

		private static int _currentInsideSpawnPos;

		private static int _currentOutsideSpawnPos;

		private static float _spawnTimer;

		private static int _lastTickFrame = -1;

		private static readonly string[] InsideRotationNames = new string[14]
		{
			"Crawler", "Crawler", "Hoarding bug", "Bunker Spider", "Crawler", "Hoarding bug", "Bunker Spider", "Crawler", "Crawler", "Hoarding bug",
			"Bunker Spider", "Crawler", "Hoarding bug", "Crawler"
		};

		private static readonly string[] OutsideRotationNames = new string[11]
		{
			"MouthDog", "Baboon hawk", "Baboon hawk", "Baboon hawk", "Baboon hawk", "MouthDog", "MouthDog", "MouthDog", "MouthDog", "MouthDog",
			"MouthDog"
		};

		public static void Reset()
		{
			OutsideSpawnedEnemies.Clear();
			InsideSpawnedEnemies.Clear();
			ActiveCarriersBuffer.Clear();
			_currentInsideSpawnPos = 0;
			_currentOutsideSpawnPos = 0;
			_spawnTimer = 0f;
			_lastTickFrame = -1;
		}

		private static void EnsureEnemyCache()
		{
			if (_spawnInsideRotation != null && _spawnOutsideRotation != null)
			{
				return;
			}
			EnemyTypesByName.Clear();
			if ((Object)(object)StartOfRound.Instance != (Object)null && StartOfRound.Instance.levels != null)
			{
				SelectableLevel[] levels = StartOfRound.Instance.levels;
				for (int i = 0; i < levels.Length; i++)
				{
					RegisterLevel(levels[i]);
				}
			}
			QuickMenuManager val = Object.FindObjectOfType<QuickMenuManager>();
			if ((Object)(object)val != (Object)null && (Object)(object)val.testAllEnemiesLevel != (Object)null)
			{
				RegisterLevel(val.testAllEnemiesLevel);
			}
			EnemyType[] array = Resources.FindObjectsOfTypeAll<EnemyType>();
			foreach (EnemyType val2 in array)
			{
				if ((Object)(object)val2 != (Object)null && !string.IsNullOrEmpty(val2.enemyName) && (Object)(object)val2.enemyPrefab != (Object)null && !EnemyTypesByName.ContainsKey(val2.enemyName))
				{
					EnemyTypesByName[val2.enemyName] = val2;
				}
			}
			_spawnInsideRotation = BuildRotation(InsideRotationNames);
			_spawnOutsideRotation = BuildRotation(OutsideRotationNames);
			Plugin.Log.LogInfo((object)($"DoomEnemySpawner initialized: {EnemyTypesByName.Count} enemy types found, " + $"inside rotation={_spawnInsideRotation.Count}, outside rotation={_spawnOutsideRotation.Count}"));
			static void RegisterLevel(SelectableLevel level)
			{
				if (!((Object)(object)level == (Object)null))
				{
					RegisterList(level.Enemies);
					RegisterList(level.OutsideEnemies);
					RegisterList(level.DaytimeEnemies);
				}
			}
			static void RegisterList(List<SpawnableEnemyWithRarity> list)
			{
				if (list == null)
				{
					return;
				}
				foreach (SpawnableEnemyWithRarity item in list)
				{
					if ((Object)(object)item?.enemyType != (Object)null && !string.IsNullOrEmpty(item.enemyType.enemyName) && !EnemyTypesByName.ContainsKey(item.enemyType.enemyName))
					{
						EnemyTypesByName[item.enemyType.enemyName] = item.enemyType;
					}
				}
			}
		}

		private static void EnsureExcludedFilterUpdated()
		{
			string activeExcludedEnemies = ModConfig.ActiveExcludedEnemies;
			if (activeExcludedEnemies == _cachedExcludedRaw)
			{
				return;
			}
			_cachedExcludedRaw = activeExcludedEnemies;
			_excludedNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			if (string.IsNullOrWhiteSpace(activeExcludedEnemies))
			{
				return;
			}
			string[] array = activeExcludedEnemies.Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (!string.IsNullOrEmpty(text))
				{
					_excludedNames.Add(text);
				}
			}
		}

		public static bool IsEnemyExcluded(EnemyType enemyType, EnemyAI enemy = null)
		{
			EnsureExcludedFilterUpdated();
			if (_excludedNames.Count == 0)
			{
				return false;
			}
			if ((Object)(object)enemyType != (Object)null)
			{
				if (!string.IsNullOrEmpty(enemyType.enemyName) && _excludedNames.Contains(enemyType.enemyName.Trim()))
				{
					return true;
				}
				if (!string.IsNullOrEmpty(((Object)enemyType).name) && _excludedNames.Contains(((Object)enemyType).name.Trim()))
				{
					return true;
				}
			}
			if ((Object)(object)enemy != (Object)null && _excludedNames.Contains(((object)enemy).GetType().Name))
			{
				return true;
			}
			return false;
		}

		private static List<EnemyType> BuildRotation(string[] names)
		{
			List<EnemyType> list = new List<EnemyType>();
			foreach (string key in names)
			{
				if (EnemyTypesByName.TryGetValue(key, out var value) && (Object)(object)value.enemyPrefab != (Object)null && !IsEnemyExcluded(value))
				{
					list.Add(value);
				}
			}
			return list;
		}

		public static void TickPerFrame()
		{
			if (_lastTickFrame == Time.frameCount)
			{
				return;
			}
			_lastTickFrame = Time.frameCount;
			if ((Object)(object)RoundManager.Instance == (Object)null)
			{
				return;
			}
			DoomShotgunState.FillActiveCursedCarriers(ActiveCarriersBuffer);
			if (ActiveCarriersBuffer.Count == 0)
			{
				return;
			}
			if (ModConfig.EnableEnemyWaves.Value && (Object)(object)NetworkManager.Singleton != (Object)null && NetworkManager.Singleton.IsServer)
			{
				EnsureEnemyCache();
				_spawnTimer -= Time.deltaTime;
				if (_spawnTimer <= 0f)
				{
					PruneDead(InsideSpawnedEnemies);
					PruneDead(OutsideSpawnedEnemies);
					int value = ModConfig.MaxInsideEnemies.Value;
					int value2 = ModConfig.MaxOutsideEnemies.Value;
					for (int i = 0; i < ActiveCarriersBuffer.Count; i++)
					{
						if (ActiveCarriersBuffer[i].isInsideFactory)
						{
							if (InsideSpawnedEnemies.Count < value && _spawnInsideRotation.Count > 0)
							{
								TrySpawnInside();
							}
						}
						else if (OutsideSpawnedEnemies.Count < value2 && _spawnOutsideRotation.Count > 0)
						{
							TrySpawnOutside();
						}
					}
					_spawnTimer = ModConfig.WaveSpawnInterval.Value;
				}
			}
			AggroEnemiesToNearestCarrier(ActiveCarriersBuffer);
		}

		private static void TrySpawnOutside()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			GameObject[] array = GameObject.FindGameObjectsWithTag("OutsideAINode");
			if (array == null || array.Length == 0 || RoundManager.Instance.AnomalyRandom == null)
			{
				return;
			}
			int num = RoundManager.Instance.AnomalyRandom.Next(0, array.Length);
			Vector3 position = array[num].transform.position;
			position = RoundManager.Instance.GetRandomNavMeshPositionInRadius(position, 4f, default(NavMeshHit));
			GameObject[] spawnDenialPoints = RoundManager.Instance.spawnDenialPoints;
			if (spawnDenialPoints != null && spawnDenialPoints.Length != 0)
			{
				int num2 = num;
				for (int i = 0; i < array.Length - 1; i++)
				{
					bool flag = true;
					for (int j = 0; j < spawnDenialPoints.Length; j++)
					{
						if ((Object)(object)spawnDenialPoints[j] != (Object)null && Vector3.Distance(position, spawnDenialPoints[j].transform.position) < 16f)
						{
							num2 = (num2 + 1) % array.Length;
							position = RoundManager.Instance.GetRandomNavMeshPositionInRadius(array[num2].transform.position, 4f, default(NavMeshHit));
							flag = false;
							break;
						}
					}
					if (flag)
					{
						break;
					}
				}
			}
			EnemyType val = _spawnOutsideRotation[_currentOutsideSpawnPos];
			_currentOutsideSpawnPos = (_currentOutsideSpawnPos + 1) % _spawnOutsideRotation.Count;
			if (!IsEnemyExcluded(val))
			{
				GameObject val2 = Object.Instantiate<GameObject>(val.enemyPrefab, position, Quaternion.identity);
				NetworkObject componentInChildren = val2.GetComponentInChildren<NetworkObject>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.Spawn(true);
				}
				EnemyAI val3 = val2.GetComponent<EnemyAI>() ?? val2.GetComponentInChildren<EnemyAI>();
				if ((Object)(object)val3 != (Object)null)
				{
					RoundManager.Instance.SpawnedEnemies.Add(val3);
					OutsideSpawnedEnemies.Add(val3);
				}
			}
		}

		private static void TrySpawnInside()
		{
			//IL_008a: 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)
			EnemyVent[] allEnemyVents = RoundManager.Instance.allEnemyVents;
			if (allEnemyVents == null || allEnemyVents.Length == 0 || RoundManager.Instance.AnomalyRandom == null)
			{
				return;
			}
			EnemyVent val = allEnemyVents[RoundManager.Instance.AnomalyRandom.Next(0, allEnemyVents.Length)];
			if ((Object)(object)val == (Object)null || (Object)(object)val.floorNode == (Object)null)
			{
				return;
			}
			EnemyType val2 = _spawnInsideRotation[_currentInsideSpawnPos];
			_currentInsideSpawnPos = (_currentInsideSpawnPos + 1) % _spawnInsideRotation.Count;
			if (!IsEnemyExcluded(val2))
			{
				GameObject val3 = Object.Instantiate<GameObject>(val2.enemyPrefab, val.floorNode.position, Quaternion.identity);
				NetworkObject componentInChildren = val3.GetComponentInChildren<NetworkObject>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.Spawn(true);
				}
				EnemyAI val4 = val3.GetComponent<EnemyAI>() ?? val3.GetComponentInChildren<EnemyAI>();
				if ((Object)(object)val4 != (Object)null)
				{
					InsideSpawnedEnemies.Add(val4);
					RoundManager.Instance.SpawnedEnemies.Add(val4);
				}
			}
		}

		private static void AggroEnemiesToNearestCarrier(List<PlayerControllerB> carriers)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			if (carriers == null || carriers.Count == 0 || (Object)(object)RoundManager.Instance == (Object)null || RoundManager.Instance.SpawnedEnemies == null)
			{
				return;
			}
			foreach (EnemyAI spawnedEnemy in RoundManager.Instance.SpawnedEnemies)
			{
				if ((Object)(object)spawnedEnemy == (Object)null || spawnedEnemy.isEnemyDead || !((NetworkBehaviour)spawnedEnemy).IsOwner || IsEnemyExcluded(spawnedEnemy.enemyType, spawnedEnemy))
				{
					continue;
				}
				PlayerControllerB val = null;
				float num = float.MaxValue;
				Vector3 position = ((Component)spawnedEnemy).transform.position;
				for (int i = 0; i < carriers.Count; i++)
				{
					PlayerControllerB val2 = carriers[i];
					if (!((Object)(object)val2 == (Object)null) && spawnedEnemy.isOutside == !val2.isInsideFactory)
					{
						Vector3 val3 = position - ((Component)val2).transform.position;
						float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
						if (sqrMagnitude < num)
						{
							num = sqrMagnitude;
							val = val2;
						}
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					if (spawnedEnemy.currentSearch != null && spawnedEnemy.currentSearch.inProgress)
					{
						spawnedEnemy.StopSearch(spawnedEnemy.currentSearch, true);
					}
					spawnedEnemy.movingTowardsTargetPlayer = true;
					spawnedEnemy.targetPlayer = val;
				}
			}
		}

		public static void KillCurseEnemies()
		{
			for (int num = InsideSpawnedEnemies.Count - 1; num >= 0; num--)
			{
				KillEnemy(InsideSpawnedEnemies[num]);
			}
			InsideSpawnedEnemies.Clear();
			for (int num2 = OutsideSpawnedEnemies.Count - 1; num2 >= 0; num2--)
			{
				KillEnemy(OutsideSpawnedEnemies[num2]);
			}
			OutsideSpawnedEnemies.Clear();
		}

		public static bool KillEnemy(EnemyAI enemy)
		{
			if ((Object)(object)enemy == (Object)null || enemy.isEnemyDead)
			{
				return true;
			}
			if (enemy is SandWormAI)
			{
				return false;
			}
			enemy.CancelSpecialAnimationWithPlayer();
			if (!OutsideSpawnedEnemies.Contains(enemy) && !InsideSpawnedEnemies.Contains(enemy))
			{
				SubtractFromPowerLevelMethod?.Invoke(enemy, null);
			}
			if ((Object)(object)enemy.enemyType != (Object)null && enemy.enemyType.canDie)
			{
				enemy.KillEnemyClientRpc(false);
			}
			else
			{
				enemy.KillEnemy(true);
			}
			return true;
		}

		private static void PruneDead(List<EnemyAI> list)
		{
			for (int num = list.Count - 1; num >= 0; num--)
			{
				if ((Object)(object)list[num] == (Object)null || list[num].isEnemyDead)
				{
					list.RemoveAt(num);
				}
			}
		}
	}
	internal static class DoomScrapManager
	{
		private static readonly HashSet<SelectableLevel> RegisteredLevels = new HashSet<SelectableLevel>();

		public static Item DoomShotgunScrapItem { get; private set; }

		public static bool IsSpawningScrap { get; internal set; }

		public static void EnsureRegistered(StartOfRound startOfRound)
		{
			if ((Object)(object)startOfRound == (Object)null || (Object)(object)startOfRound.allItemsList == (Object)null || startOfRound.allItemsList.itemsList == null)
			{
				return;
			}
			if ((Object)(object)DoomShotgunScrapItem == (Object)null)
			{
				Item val = FindVanillaShotgunItem(startOfRound.allItemsList.itemsList);
				if ((Object)(object)val == (Object)null)
				{
					Plugin.Log.LogWarning((object)ModConfig.L("DoomScrapManager: could not find vanilla Shotgun in allItemsList.", "DoomScrapManager : impossible de trouver le Shotgun vanilla dans allItemsList."));
					return;
				}
				DoomShotgunScrapItem = Object.Instantiate<Item>(val);
				((Object)DoomShotgunScrapItem).name = "ShotGunDoom_CursedShotgunScrap";
				((Object)DoomShotgunScrapItem).hideFlags = (HideFlags)32;
				DoomShotgunScrapItem.isScrap = true;
				DoomShotgunScrapItem.spawnPrefab = val.spawnPrefab;
				DoomShotgunScrapItem.spawnPositionTypes = new List<ItemGroup>();
			}
			RefreshScrapItemValues();
			if (startOfRound.levels == null)
			{
				return;
			}
			int value = ModConfig.ScrapSpawnWeight.Value;
			int num = 0;
			SelectableLevel[] levels = startOfRound.levels;
			foreach (SelectableLevel val2 in levels)
			{
				if (!((Object)(object)val2 == (Object)null) && val2.spawnableScrap != null && val2.spawnableScrap.Count != 0)
				{
					UpdateLevelScrapList(val2, value);
					num++;
				}
			}
			Plugin.Log.LogInfo((object)ModConfig.L($"DoomScrapManager: Cursed Shotgun registered on {num} moons (rarity={value}, minValue={DoomShotgunScrapItem.minValue}, maxValue={DoomShotgunScrapItem.maxValue}).", $"DoomScrapManager : Shotgun maudit enregistre sur {num} lunes (poids/rarity={value}, minValue={DoomShotgunScrapItem.minValue}, maxValue={DoomShotgunScrapItem.maxValue})."));
		}

		public static void RefreshForCurrentLevel(SelectableLevel currentLevel)
		{
			if ((Object)(object)DoomShotgunScrapItem == (Object)null && (Object)(object)StartOfRound.Instance != (Object)null)
			{
				EnsureRegistered(StartOfRound.Instance);
			}
			if (!((Object)(object)DoomShotgunScrapItem == (Object)null) && !((Object)(object)currentLevel == (Object)null) && currentLevel.spawnableScrap != null)
			{
				RefreshScrapItemValues();
				if (currentLevel.spawnableScrap.Count > 0 || RegisteredLevels.Contains(currentLevel))
				{
					UpdateLevelScrapList(currentLevel, ModConfig.ScrapSpawnWeight.Value);
				}
			}
		}

		private static void RefreshScrapItemValues()
		{
			if (!((Object)(object)DoomShotgunScrapItem == (Object)null))
			{
				int value = ModConfig.ScrapMinValue.Value;
				int maxValue = Mathf.Max(value, ModConfig.ScrapMaxValue.Value);
				DoomShotgunScrapItem.minValue = value;
				DoomShotgunScrapItem.maxValue = maxValue;
			}
		}

		private static void UpdateLevelScrapList(SelectableLevel level, int rarity)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			List<SpawnableItemWithRarity> spawnableScrap = level.spawnableScrap;
			SpawnableItemWithRarity val = null;
			for (int num = spawnableScrap.Count - 1; num >= 0; num--)
			{
				if (spawnableScrap[num] != null && (Object)(object)spawnableScrap[num].spawnableItem == (Object)(object)DoomShotgunScrapItem)
				{
					if (rarity <= 0)
					{
						spawnableScrap.RemoveAt(num);
					}
					else
					{
						val = spawnableScrap[num];
					}
				}
			}
			if (rarity > 0)
			{
				if (val != null)
				{
					val.rarity = rarity;
				}
				else
				{
					spawnableScrap.Add(new SpawnableItemWithRarity(DoomShotgunScrapItem, rarity));
				}
				RegisteredLevels.Add(level);
			}
		}

		private static Item FindVanillaShotgunItem(List<Item> items)
		{
			foreach (Item item in items)
			{
				if ((Object)(object)item != (Object)null && (Object)(object)item.spawnPrefab != (Object)null && (Object)(object)item.spawnPrefab.GetComponent<ShotgunItem>() != (Object)null)
				{
					return item;
				}
			}
			return null;
		}
	}
	public class DoomShotgunState : MonoBehaviour
	{
		private static readonly List<DoomShotgunState> AllStates = new List<DoomShotgunState>();

		public ShotgunItem Shotgun;

		public bool IsCursedScrap;

		public bool CurseLifted;

		public bool CurseLiftedLastFrame;

		public PlayerControllerB LastPlayerHeldBy;

		public int Health;

		public int Armor;

		public int RemainingShells;

		public float WalkPhase;

		public float DamagePhase;

		public float ManiacPhase;

		public float LeftPhase;

		public float RightPhase;

		public AudioSource ActiveAudio;

		public AudioSource InactiveAudio;

		private bool _initialized;

		public bool IsCurseActive
		{
			get
			{
				if (IsCursedScrap)
				{
					return !CurseLifted;
				}
				return false;
			}
		}

		public bool IsCursedAndHeld
		{
			get
			{
				if ((Object)(object)Shotgun != (Object)null && IsCurseActive)
				{
					return (Object)(object)((GrabbableObject)Shotgun).playerHeldBy != (Object)null;
				}
				return false;
			}
		}

		public bool IsHeldByLocalPlayer
		{
			get
			{
				if ((Object)(object)Shotgun != (Object)null && (Object)(object)StartOfRound.Instance != (Object)null && (Object)(object)((GrabbableObject)Shotgun).playerHeldBy != (Object)null)
				{