Decompiled source of EverythingCanDie v1.2.23

EverythingCanDie.dll

Decompiled 4 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EverythingCanDie
{
	public class Patches
	{
		public static List<string> UnkillableEnemies = new List<string>();

		public static List<string> BonkableEnemies = new List<string>();

		public static List<string> NotBonkableEnemies = new List<string>();

		public static List<string> InvalidEnemies = new List<string>();

		private static readonly int Damage = Animator.StringToHash("damage");

		private static bool CheckingIfBonkable = false;

		public static void StartOfRoundPatch()
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Expected O, but got Unknown
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Expected O, but got Unknown
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Expected O, but got Unknown
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Expected O, but got Unknown
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Expected O, but got Unknown
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Expected O, but got Unknown
			Plugin.enemies = (from EnemyType e in Resources.FindObjectsOfTypeAll(typeof(EnemyType))
				where (Object)(object)e != (Object)null
				select e).ToList();
			Plugin.items = (from Item i in Resources.FindObjectsOfTypeAll(typeof(Item))
				where (Object)(object)i != (Object)null
				select i).ToList();
			Plugin.ENEMY_MASK = 524288;
			Plugin.PLAYER_HIT_MASK = StartOfRound.Instance.collidersRoomMaskDefaultAndPlayers | (Plugin.ENEMY_MASK & 0x280008);
			if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", "UnimmortalAllMobs")))
			{
				ConfigEntry<bool> val = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", "UnimmortalAllMobs", true, "Leave On To Customise Mobs Below Or Turn Off To Make All Mobs Return To Normal(Make Immortal mobs immortal again).");
			}
			if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", "ExplosionEffectAllMobs")))
			{
				ConfigEntry<bool> val2 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", "ExplosionEffectAllMobs", true, "If this is set to true then explosion effect stays and removes the body otherwise when false all explosions on death will not appear and the body will appear.");
			}
			if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", "HealthAllMobs")))
			{
				ConfigEntry<bool> val3 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", "HealthAllMobs", true, "If this is set to false the enemies health will remain the same otherwise have fun configging.");
			}
			foreach (EnemyType enemy in Plugin.enemies)
			{
				string text = Plugin.RemoveInvalidCharacters(enemy.enemyName).ToUpper();
				try
				{
					if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", text + ".Unimmortal")))
					{
						ConfigEntry<bool> val4 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", text + ".Unimmortal", true, "If true this mob will explode and if immortal it will also be killable.");
					}
					if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", text + ".Explodeable")))
					{
						ConfigEntry<bool> val5 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", text + ".Explodeable", true, "The value of whether to spawn an explosion effect(Default on)");
					}
					if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", text + ".Hittable")))
					{
						ConfigEntry<bool> val6 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", text + ".Hittable", true, "The value of whether this mob is hittable with things like shovels.(WARNING: If it is a modded item that happens to shoot then this might effect those items too)");
					}
					if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", text + ".Shootable")))
					{
						ConfigEntry<bool> val7 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", text + ".Shootable", true, "The value of whether this mob is shootable with things like shotguns.(WARNING: Only works for items that use the ShotgunItem as its parent)");
					}
					if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", text + ".Health")))
					{
						EnemyAI component = enemy.enemyPrefab.GetComponent<EnemyAI>();
						ConfigEntry<int> val8 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<int>("Mobs", text + ".Health", component.enemyHP, "The value of the mobs health.(Default Vanilla is 3 for most unkillable mobs)");
						if (Plugin.CanMob("HealthAllMobs", ".Unimmortal", text))
						{
							component.enemyHP = val8.Value;
							Plugin.Log.LogInfo((object)$"Set {((Object)enemy).name} HP to {component.enemyHP}");
						}
					}
				}
				catch (Exception)
				{
					Plugin.Log.LogInfo((object)("It was not possible to generate the configs for the enemy: " + enemy.enemyName));
					InvalidEnemies.Add(enemy.enemyName);
				}
				try
				{
					if (Plugin.CanMob("UnimmortalAllMobs", ".Unimmortal", text))
					{
						UnkillableEnemies.Add(enemy.enemyName);
						enemy.canDie = true;
					}
					Plugin.Log.LogInfo((object)$"Vanilla canDie variable for {enemy.enemyName} = {enemy.canDie}");
				}
				catch (Exception)
				{
					Plugin.Log.LogError((object)("It was not possible to determine whether the enemy " + enemy.enemyName + " was killable or not"));
				}
			}
			if ((Object)(object)Plugin.explosionPrefab == (Object)null && (Object)(object)StartOfRound.Instance.explosionPrefab != (Object)null)
			{
				Plugin.explosionPrefab = Object.Instantiate<GameObject>(StartOfRound.Instance.explosionPrefab);
				if ((Object)(object)Plugin.explosionPrefab.GetComponent<AudioSource>() != (Object)null)
				{
					Plugin.explosionPrefab.GetComponent<AudioSource>().volume = 0.35f;
				}
				Plugin.explosionPrefab.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)Plugin.explosionPrefab);
			}
		}

		public static void HitEnemyPatch(ref EnemyAI __instance, int force = 1, PlayerControllerB playerWhoHit = null)
		{
			if (!((Object)(object)__instance != (Object)null) || CheckingIfBonkable || (InvalidEnemies.Contains(__instance.enemyType.enemyName) && __instance.isEnemyDead))
			{
				return;
			}
			EnemyType enemyType = __instance.enemyType;
			string text = Plugin.RemoveInvalidCharacters(enemyType.enemyName).ToUpper();
			bool flag = true;
			if (!Plugin.CanMob("UnimmortalAllMobs", ".Unimmortal", text) || ((Object)(object)playerWhoHit == (Object)null && __instance.enemyType.enemyName == "RadMech"))
			{
				return;
			}
			if ((Object)(object)playerWhoHit != (Object)null && (Object)(object)playerWhoHit.ItemSlots[playerWhoHit.currentItemSlot] != (Object)null)
			{
				GrabbableObject val = playerWhoHit.ItemSlots[playerWhoHit.currentItemSlot];
				if (val.itemProperties.isDefensiveWeapon && !Plugin.Can(text + ".Hittable"))
				{
					flag = false;
					Plugin.Log.LogInfo((object)("Hit Disabled for " + __instance.enemyType.enemyName + "!"));
				}
				else if (val is ShotgunItem && !Plugin.Can(text + ".Shootable"))
				{
					flag = false;
					Plugin.Log.LogInfo((object)("Shoot Disabled for " + __instance.enemyType.enemyName + "!"));
				}
			}
			if (!flag)
			{
				return;
			}
			if (!BonkableEnemies.Contains(__instance.enemyType.enemyName) && !NotBonkableEnemies.Contains(__instance.enemyType.enemyName))
			{
				Plugin.Log.LogInfo((object)(__instance.enemyType.enemyName + " is not in the Bonkable or in the NotBonkable list"));
				CanEnemyGetBonked(__instance);
			}
			if (BonkableEnemies.Contains(__instance.enemyType.enemyName))
			{
				Plugin.Log.LogInfo((object)(__instance.enemyType.enemyName + " is in the Bonkable list"));
			}
			else if (NotBonkableEnemies.Contains(__instance.enemyType.enemyName))
			{
				Plugin.Log.LogInfo((object)(__instance.enemyType.enemyName + " is in the NotBonkable list"));
				if ((Object)(object)__instance.creatureAnimator != (Object)null)
				{
					__instance.creatureAnimator.SetTrigger(Damage);
				}
				if (__instance.enemyHP - force > 0)
				{
					EnemyAI obj = __instance;
					obj.enemyHP -= force;
				}
				else
				{
					__instance.enemyHP = 0;
				}
				if (__instance.enemyHP <= 0)
				{
					__instance.KillEnemyOnOwnerClient(false);
				}
			}
		}

		public static void CanEnemyGetBonked(EnemyAI __instance)
		{
			CheckingIfBonkable = true;
			int enemyHP = __instance.enemyHP;
			Plugin.Log.LogInfo((object)$"Enemy HP before bonk test: {enemyHP}");
			__instance.HitEnemy(1, (PlayerControllerB)null, false, -3);
			int enemyHP2 = __instance.enemyHP;
			Plugin.Log.LogInfo((object)$"Enemy HP after bonk test: {enemyHP2}");
			if (enemyHP != enemyHP2)
			{
				BonkableEnemies.Add(__instance.enemyType.enemyName);
				__instance.enemyHP = enemyHP;
				Plugin.Log.LogInfo((object)$"{__instance.enemyType.enemyName} is been added to the Bonkable list, HP = {__instance.enemyHP}");
			}
			else
			{
				NotBonkableEnemies.Add(__instance.enemyType.enemyName);
				Plugin.Log.LogInfo((object)$"{__instance.enemyType.enemyName} is been added to the NotBonkable list, HP = {__instance.enemyHP}");
			}
			CheckingIfBonkable = false;
		}

		public static void KillEnemyPatch(ref EnemyAI __instance)
		{
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance != (Object)null) || InvalidEnemies.Contains(__instance.enemyType.enemyName))
			{
				return;
			}
			EnemyType enemyType = __instance.enemyType;
			string mobName = Plugin.RemoveInvalidCharacters(enemyType.enemyName).ToUpper();
			Plugin.Log.LogInfo((object)$"{((Object)__instance).name} HP is {__instance.enemyHP}, killing");
			if (!Plugin.CanMob("ExplosionEffectAllMobs", ".Explodeable", mobName))
			{
				return;
			}
			if (__instance.enemyType.enemyName == "Nutcracker" || __instance.enemyType.enemyName == "Butler")
			{
				HUDManager.Instance.ShakeCamera((ScreenShakeType)0);
				if (((NetworkBehaviour)__instance).IsServer)
				{
					Object.Instantiate<GameObject>(Plugin.explosionPrefab, ((Component)__instance).transform.position, Quaternion.Euler(-90f, 0f, 0f), RoundManager.Instance.mapPropsContainer.transform).SetActive(true);
				}
				return;
			}
			if (Object.op_Implicit((Object)(object)((Component)__instance).GetComponentInChildren<PlayerControllerB>()))
			{
				HUDManager.Instance.ShakeCamera((ScreenShakeType)0);
				if (((NetworkBehaviour)__instance).IsServer)
				{
					Object.Instantiate<GameObject>(Plugin.explosionPrefab, ((Component)__instance).transform.position, Quaternion.Euler(-90f, 0f, 0f), RoundManager.Instance.mapPropsContainer.transform).SetActive(true);
				}
				return;
			}
			HUDManager.Instance.ShakeCamera((ScreenShakeType)0);
			if (((NetworkBehaviour)__instance).IsServer)
			{
				Object.Instantiate<GameObject>(Plugin.explosionPrefab, ((Component)__instance).transform.position, Quaternion.Euler(-90f, 0f, 0f), RoundManager.Instance.mapPropsContainer.transform).SetActive(true);
			}
			((MonoBehaviour)__instance).StartCoroutine(MoveBody(__instance, 0.1f));
		}

		private static IEnumerator MoveBody(EnemyAI __instance, float time)
		{
			yield return (object)new WaitForSeconds(time);
			Vector3 OriginalBodyPos = new Vector3(-10000f, -10000f, -10000f);
			((Component)__instance).transform.position = OriginalBodyPos;
			__instance.SyncPositionToClients();
			if (__instance.enemyType.enemyName == "Blob" && ((NetworkBehaviour)__instance).IsServer)
			{
				((Component)__instance).GetComponent<NetworkObject>().Despawn(true);
			}
		}

		public static bool ReplaceShotgunCode(ref ShotgunItem __instance, Vector3 shotgunPosition, Vector3 shotgunForward)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			ShootGun(__instance, shotgunPosition, shotgunForward);
			return false;
		}

		public static void ShootGun(ShotgunItem gun, Vector3 shotgunPosition, Vector3 shotgunForward)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: 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_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: 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_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_0726: Unknown result type (might be due to invalid IL or missing references)
			//IL_0728: Unknown result type (might be due to invalid IL or missing references)
			//IL_0732: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0771: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0632: Unknown result type (might be due to invalid IL or missing references)
			//IL_0637: Unknown result type (might be due to invalid IL or missing references)
			//IL_067a: Unknown result type (might be due to invalid IL or missing references)
			//IL_067b: 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_05ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			//IL_052a: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB playerHeldBy = ((GrabbableObject)gun).playerHeldBy;
			bool flag = ((GrabbableObject)gun).isHeld && (Object)(object)((GrabbableObject)gun).playerHeldBy != (Object)null;
			if (flag)
			{
				shotgunPosition += ((Component)GameNetworkManager.Instance.localPlayerController.gameplayCamera).transform.up * 0.25f;
			}
			bool flag2 = flag && (Object)(object)((GrabbableObject)gun).playerHeldBy == (Object)(object)GameNetworkManager.Instance.localPlayerController;
			if (flag2)
			{
				((GrabbableObject)gun).playerHeldBy.playerBodyAnimator.SetTrigger("ShootShotgun");
			}
			RoundManager.PlayRandomClip(((Component)gun).GetComponent<ShotgunItem>().gunShootAudio, ((Component)gun).GetComponent<ShotgunItem>().gunShootSFX, true, 1f, 1840, 1000);
			WalkieTalkie.TransmitOneShotAudio(((Component)gun).GetComponent<ShotgunItem>().gunShootAudio, ((Component)gun).GetComponent<ShotgunItem>().gunShootSFX[0], 1f);
			gun.gunShootParticle.Play(true);
			gun.isReloading = false;
			gun.shellsLoaded = Mathf.Clamp(gun.shellsLoaded - 1, 0, 2);
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)localPlayerController == (Object)null)
			{
				return;
			}
			Vector3[] array = (Vector3[])(object)new Vector3[Plugin.numTightPellets + Plugin.numLoosePellets];
			State state = Random.state;
			for (int i = 0; i < Plugin.numTightPellets + Plugin.numLoosePellets; i++)
			{
				float num = ((i < Plugin.numTightPellets) ? Plugin.tightPelletAngle : Plugin.loosePelletAngle);
				Vector3 val = Random.onUnitSphere;
				float num2 = num * Mathf.Sqrt(Random.value);
				if (Vector3.Angle(shotgunForward, val) < num2)
				{
					val *= -1f;
				}
				Vector3 val2 = Vector3.RotateTowards(shotgunForward, val, num2 * MathF.PI / 180f, 0f);
				array[i] = val2;
			}
			Random.state = state;
			float num3 = Vector3.Distance(((Component)localPlayerController).transform.position, ((Component)gun.shotgunRayPoint).transform.position);
			float num4 = 0f;
			if (num3 < 5f)
			{
				num4 = 0.8f;
				HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
			}
			else if (num3 < 15f)
			{
				num4 = 0.5f;
				HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
			}
			else if (num3 < 23f)
			{
				HUDManager.Instance.ShakeCamera((ScreenShakeType)0);
			}
			if (num4 > 0f && SoundManager.Instance.timeSinceEarsStartedRinging > 16f && !flag)
			{
				((MonoBehaviour)gun).StartCoroutine(DelayedEarsRinging(num4));
			}
			Plugin.CountHandler countHandler = new Plugin.CountHandler();
			Ray val4 = default(Ray);
			IHittable val6 = default(IHittable);
			EnemyAI val9 = default(EnemyAI);
			foreach (Vector3 val3 in array)
			{
				((Ray)(ref val4))..ctor(shotgunPosition, val3);
				RaycastHit[] array2 = Physics.RaycastAll(val4, 30f, Plugin.PLAYER_HIT_MASK, (QueryTriggerInteraction)2);
				Array.Sort(array2, (RaycastHit x, RaycastHit y) => ((RaycastHit)(ref x)).distance.CompareTo(((RaycastHit)(ref y)).distance));
				Vector3 val5 = shotgunPosition + val3 * 30f;
				Debug.Log((object)("SHOTGUN: RaycastAll hit " + array2.Length + " things (" + flag + "," + flag2 + ")"));
				for (int k = 0; k < array2.Length; k++)
				{
					GameObject gameObject = ((Component)((RaycastHit)(ref array2[k])).transform).gameObject;
					if (gameObject.TryGetComponent<IHittable>(ref val6))
					{
						if (val6 == ((GrabbableObject)gun).playerHeldBy)
						{
							continue;
						}
						EnemyAI val7 = null;
						EnemyAICollisionDetect val8 = (EnemyAICollisionDetect)(object)((val6 is EnemyAICollisionDetect) ? val6 : null);
						if (val8 != null)
						{
							val7 = val8.mainScript;
						}
						if ((Object)(object)val7 != (Object)null && (val7.isEnemyDead || val7.enemyHP <= 0 || !val7.enemyType.canDie))
						{
							continue;
						}
						if (val6 is PlayerControllerB)
						{
							countHandler.AddPlayerToCount((PlayerControllerB)(object)((val6 is PlayerControllerB) ? val6 : null));
						}
						else if ((Object)(object)val7 != (Object)null)
						{
							countHandler.AddEnemyToCount(val7);
						}
						else
						{
							if (!flag)
							{
								continue;
							}
							countHandler.AddOtherToCount(val6);
						}
						val5 = ((RaycastHit)(ref array2[k])).point;
						Debug.Log((object)("SHOTGUN: Hit [" + ((object)val6)?.ToString() + "] (" + (k + 1) + "@" + Vector3.Distance(shotgunPosition, val5) + ")"));
						break;
					}
					if (((Component)((RaycastHit)(ref array2[k])).collider).TryGetComponent<EnemyAI>(ref val9))
					{
						if (!flag || val9.isEnemyDead || val9.enemyHP <= 0 || !val9.enemyType.canDie)
						{
							continue;
						}
						countHandler.AddEnemyToCount(val9);
						val5 = ((RaycastHit)(ref array2[k])).point;
						Debug.Log((object)("SHOTGUN: Backup hit [" + ((object)val9)?.ToString() + "] (" + (k + 1) + "@" + Vector3.Distance(shotgunPosition, val5) + ")"));
						break;
					}
					val5 = ((RaycastHit)(ref array2[k])).point;
					Debug.Log((object)("SHOTGUN: Wall [" + ((object)gameObject)?.ToString() + "] (" + (k + 1) + "@" + Vector3.Distance(shotgunPosition, val5) + ")"));
					break;
				}
				Plugin.VisualiseShot(shotgunPosition, val5);
			}
			countHandler.player.ForEach(delegate(Plugin.Counter<PlayerControllerB> p)
			{
				//IL_0076: Unknown result type (might be due to invalid IL or missing references)
				int num7 = p.count * 20;
				Debug.Log((object)("SHOTGUN: Hit " + ((object)p.item)?.ToString() + " with " + p.count + " pellets for " + num7 + " damage"));
				p.item.DamagePlayer(num7, true, true, (CauseOfDeath)7, 0, false, shotgunForward);
			});
			countHandler.enemy.ForEach(delegate(Plugin.Counter<EnemyAI> e)
			{
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				int num6 = e.count / 2 + 1;
				Debug.Log((object)("SHOTGUN: Hit " + ((object)e.item)?.ToString() + " with " + e.count + " pellets for " + num6 + " damage"));
				e.item.HitEnemyOnLocalClient(num6, shotgunForward, ((GrabbableObject)gun).playerHeldBy, true, -1);
			});
			countHandler.other.ForEach(delegate(Plugin.Counter<IHittable> o)
			{
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				int num5 = o.count / 2 + 1;
				Debug.Log((object)("SHOTGUN: Hit " + ((object)o.item)?.ToString() + " with " + o.count + " pellets for " + num5 + " damage"));
				o.item.Hit(num5, shotgunForward, ((GrabbableObject)gun).playerHeldBy, true, -1);
			});
			((Ray)(ref val4))..ctor(shotgunPosition, shotgunForward);
			RaycastHit val10 = default(RaycastHit);
			if (Physics.Raycast(val4, ref val10, 30f, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				((Component)gun.gunBulletsRicochetAudio).transform.position = ((Ray)(ref val4)).GetPoint(((RaycastHit)(ref val10)).distance - 0.5f);
				gun.gunBulletsRicochetAudio.Play();
			}
		}

		public static IEnumerator DelayedEarsRinging(float effectSeverity)
		{
			yield return (object)new WaitForSeconds(0.6f);
			SoundManager.Instance.earsRingingTimer = effectSeverity;
		}
	}
	[BepInPlugin("nwnt.EverythingCanDie", "EverythingCanDie", "1.2.22")]
	public class Plugin : BaseUnityPlugin
	{
		public class CountHandler
		{
			public List<Counter<PlayerControllerB>> player = new List<Counter<PlayerControllerB>>();

			public List<Counter<EnemyAI>> enemy = new List<Counter<EnemyAI>>();

			public List<Counter<IHittable>> other = new List<Counter<IHittable>>();

			public void AddPlayerToCount(PlayerControllerB p)
			{
				if (player.Any((Counter<PlayerControllerB> i) => (Object)(object)i.item == (Object)(object)p))
				{
					player.First((Counter<PlayerControllerB> i) => (Object)(object)i.item == (Object)(object)p).count++;
				}
				else
				{
					player.Add(new Counter<PlayerControllerB>
					{
						item = p,
						count = 1
					});
				}
			}

			public void AddEnemyToCount(EnemyAI ai)
			{
				if (enemy.Any((Counter<EnemyAI> i) => (Object)(object)i.item == (Object)(object)ai))
				{
					enemy.First((Counter<EnemyAI> i) => (Object)(object)i.item == (Object)(object)ai).count++;
				}
				else
				{
					enemy.Add(new Counter<EnemyAI>
					{
						item = ai,
						count = 1
					});
				}
			}

			public void AddOtherToCount(IHittable hit)
			{
				if (other.Any((Counter<IHittable> i) => i.item == hit))
				{
					other.First((Counter<IHittable> i) => i.item == hit).count++;
				}
				else
				{
					other.Add(new Counter<IHittable>
					{
						item = hit,
						count = 1
					});
				}
			}
		}

		public class Counter<T>
		{
			public T item;

			public int count;
		}

		public class FadeOutLine : MonoBehaviour
		{
			private const float lifetime = 0.4f;

			private const float width = 0.02f;

			private static readonly Color col = new Color(1f, 0f, 0f);

			private float alive = 0f;

			private LineRenderer line;

			public Vector3 start;

			public Vector3 end;

			private static readonly Material mat = new Material(Shader.Find("Legacy Shaders/Particles/Alpha Blended Premultiply"));

			public void Prep()
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: 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_004f: 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_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: 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)
				float num = Vector3.Distance(start, end);
				float num2 = (30f - num) / 30f;
				line = ((Component)this).gameObject.AddComponent<LineRenderer>();
				line.startColor = col;
				line.endColor = col * num2 + Color.black * (1f - num2);
				line.startWidth = 0.02f;
				line.endWidth = num2 * 0.02f;
				line.SetPositions((Vector3[])(object)new Vector3[2] { start, end });
				((Renderer)line).material = mat;
			}

			private void Update()
			{
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0086: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
				alive += Time.deltaTime;
				if (alive >= 0.4f)
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
					return;
				}
				line.startColor = new Color(col.r, col.g, col.b, (0.4f - alive) / 0.4f);
				line.endColor = new Color(line.endColor.r, line.endColor.g, line.endColor.b, (0.4f - alive) / 0.4f);
			}
		}

		public const string Guid = "nwnt.EverythingCanDie";

		public const string Name = "EverythingCanDie";

		public const string Version = "1.2.22";

		public static Plugin Instance;

		public static Harmony Harmony;

		public static ManualLogSource Log;

		public static GameObject explosionPrefab;

		public static List<EnemyType> enemies;

		public static List<Item> items;

		public const float range = 30f;

		public static int ENEMY_MASK = 524288;

		public static int PLAYER_HIT_MASK;

		public static int numTightPellets = 2;

		public static float tightPelletAngle = 2.5f;

		public static int numLoosePellets = 3;

		public static float loosePelletAngle = 10f;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			Harmony = new Harmony("nwnt.EverythingCanDie");
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Harmony.PatchAll(typeof(Plugin));
			Log = ((BaseUnityPlugin)this).Logger;
			CreateHarmonyPatch(Harmony, typeof(StartOfRound), "Start", null, typeof(Patches), "StartOfRoundPatch", isPrefix: false);
			CreateHarmonyPatch(Harmony, typeof(EnemyAI), "HitEnemy", new Type[4]
			{
				typeof(int),
				typeof(PlayerControllerB),
				typeof(bool),
				typeof(int)
			}, typeof(Patches), "HitEnemyPatch", isPrefix: false);
			CreateHarmonyPatch(Harmony, typeof(EnemyAI), "KillEnemy", new Type[1] { typeof(bool) }, typeof(Patches), "KillEnemyPatch", isPrefix: false);
			CreateHarmonyPatch(Harmony, typeof(ShotgunItem), "ShootGun", new Type[2]
			{
				typeof(Vector3),
				typeof(Vector3)
			}, typeof(Patches), "ReplaceShotgunCode", isPrefix: true);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Patching should be complete now :]");
		}

		public static Type FindType(string fullName)
		{
			try
			{
				if ((from a in AppDomain.CurrentDomain.GetAssemblies()
					where !a.IsDynamic
					select a).SelectMany((Assembly a) => a.GetTypes()).FirstOrDefault((Type t) => t.FullName.Equals(fullName)) != null)
				{
					return (from a in AppDomain.CurrentDomain.GetAssemblies()
						where !a.IsDynamic
						select a).SelectMany((Assembly a) => a.GetTypes()).FirstOrDefault((Type t) => t.FullName.Equals(fullName));
				}
			}
			catch
			{
				return null;
			}
			return null;
		}

		public static void CreateHarmonyPatch(Harmony harmony, Type typeToPatch, string methodToPatch, Type[] parameters, Type patchType, string patchMethod, bool isPrefix)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			if (typeToPatch == null || patchType == null)
			{
				Log.LogInfo((object)"Type is either incorrect or does not exist!");
				return;
			}
			MethodInfo methodInfo = AccessTools.Method(typeToPatch, methodToPatch, parameters, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(patchType, patchMethod, (Type[])null, (Type[])null);
			if (isPrefix)
			{
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)("Prefix " + methodInfo.Name + " Patched!"));
			}
			else
			{
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)("Postfix " + methodInfo.Name + " Patched!"));
			}
		}

		public static string RemoveInvalidCharacters(string source)
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (char c in source)
			{
				if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
				{
					stringBuilder.Append(c);
				}
			}
			return string.Join("", stringBuilder.ToString().Split((string[]?)null, StringSplitOptions.RemoveEmptyEntries));
		}

		public static bool Can(string identifier)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			if (((BaseUnityPlugin)Instance).Config[new ConfigDefinition("Mobs", identifier)].BoxedValue.ToString().ToUpper().Equals("TRUE"))
			{
				return true;
			}
			return false;
		}

		public static bool CanMob(string parentIdentifier, string identifier, string mobName)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			string text = RemoveInvalidCharacters(mobName).ToUpper();
			if (((BaseUnityPlugin)Instance).Config[new ConfigDefinition("Mobs", parentIdentifier)].BoxedValue.ToString().ToUpper().Equals("TRUE"))
			{
				foreach (ConfigDefinition key in ((BaseUnityPlugin)Instance).Config.Keys)
				{
					if (RemoveInvalidCharacters(key.Key.ToUpper()).Equals(RemoveInvalidCharacters(text + identifier.ToUpper())))
					{
						return ((BaseUnityPlugin)Instance).Config[key].BoxedValue.ToString().ToUpper().Equals("TRUE");
					}
				}
				Log.LogInfo((object)(identifier + ": No mob found!"));
				return false;
			}
			Log.LogInfo((object)(parentIdentifier + ": All mobs disabled!"));
			return false;
		}

		public static void VisualiseShot(Vector3 start, Vector3 end)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Trail Visual");
			FadeOutLine fadeOutLine = val.AddComponent<FadeOutLine>();
			fadeOutLine.start = start;
			fadeOutLine.end = end;
			fadeOutLine.Prep();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "EverythingCanDie";

		public const string PLUGIN_NAME = "EverythingCanDie";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}