Decompiled source of ZombieAtNight v1.1.2

Plugins/ZombieAtNight.dll

Decompiled 2 weeks ago
using System;
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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.SceneManagement;
using YouWishItWasDay;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DonHaveGUID")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+745f0f67c8ae8ff9857db4a8e5c62c603f400d34")]
[assembly: AssemblyProduct("DonHaveGUID")]
[assembly: AssemblyTitle("YouWishItWasDay")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace YouWishItWasDay
{
	public class ZombieManager
	{
		private struct ZombieTimer
		{
			public GameObject zombie;

			public float deathTime;
		}

		private List<ZombieTimer> _trackingList = new List<ZombieTimer>(500);

		private Action<GameObject> _killAction;

		public ZombieManager(Action<GameObject> killAction)
		{
			_killAction = killAction;
		}

		public void Register(GameObject z, float lifetime)
		{
			_trackingList.Add(new ZombieTimer
			{
				zombie = z,
				deathTime = Time.time + lifetime
			});
		}

		public void OnUpdate()
		{
			if (Time.frameCount % 10 != 0)
			{
				return;
			}
			float time = Time.time;
			for (int num = _trackingList.Count - 1; num >= 0; num--)
			{
				ZombieTimer zombieTimer = _trackingList[num];
				if ((Object)(object)zombieTimer.zombie == (Object)null)
				{
					RemoveAtFast(num);
				}
				else if (time >= zombieTimer.deathTime)
				{
					if (_killAction != null)
					{
						_killAction(zombieTimer.zombie);
					}
					RemoveAtFast(num);
				}
			}
		}

		private void RemoveAtFast(int index)
		{
			int num = _trackingList.Count - 1;
			if (index != num)
			{
				_trackingList[index] = _trackingList[num];
			}
			_trackingList.RemoveAt(num);
		}
	}
}
namespace ZombieChaos
{
	[BepInPlugin("Heroes", "ZombieAtNight", "1.1.1")]
	public class ZombiePlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private ConfigEntry<float> spawnInterval;

		private ConfigEntry<float> spawnJitter;

		private ConfigEntry<int> maxZombies;

		private ConfigEntry<int> spawnChance;

		private ConfigEntry<int> minSpawnCount;

		private ConfigEntry<int> maxSpawnCount;

		private ConfigEntry<float> zombieLifetime;

		private ConfigEntry<float> spawnDistMin;

		private ConfigEntry<float> spawnDistMax;

		private ConfigEntry<bool> alwaysSpawns;

		private ConfigEntry<bool> EnableZombiePlugin;

		private float _nextSpawnTime = 0f;

		private readonly HashSet<GameObject> _liveZombies = new HashSet<GameObject>();

		private ZombieManager _expirationManager;

		private DayNightManager dayNightManager;

		private float lastTimeOfDay;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			spawnInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Zombie", "Interval", 60f, "Seconds between spawn attempts");
			spawnJitter = ((BaseUnityPlugin)this).Config.Bind<float>("Zombie", "Jitter", 1f, "Random time variance (+/-)");
			maxZombies = ((BaseUnityPlugin)this).Config.Bind<int>("Zombie", "MaxZombies", 10, "Maximum simultaneous zombies");
			spawnChance = ((BaseUnityPlugin)this).Config.Bind<int>("Zombie", "SpawnChance", 100, "Chance (0-100) to spawn");
			minSpawnCount = ((BaseUnityPlugin)this).Config.Bind<int>("Zombie", "MinSpawnCount", 2, "Min zombies per wave");
			maxSpawnCount = ((BaseUnityPlugin)this).Config.Bind<int>("Zombie", "MaxSpawnCount", 4, "Max zombies per wave");
			zombieLifetime = ((BaseUnityPlugin)this).Config.Bind<float>("Zombie", "Lifetime", 100f, "Seconds before despawn (5 mins)");
			spawnDistMin = ((BaseUnityPlugin)this).Config.Bind<float>("Zombie", "SpawnDistMin", 3f, "Min distance from player");
			spawnDistMax = ((BaseUnityPlugin)this).Config.Bind<float>("Zombie", "SpawnDistMax", 10f, "Max distance from player");
			alwaysSpawns = ((BaseUnityPlugin)this).Config.Bind<bool>("Zombie", "alwaysSpawns", false, "Toggle always spawn zombies, the interval and jitter still apply");
			SceneManager.sceneLoaded += OnSceneLoaded;
			Log.LogInfo((object)"Zombie Chaos loaded.");
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene s, LoadSceneMode mode)
		{
			if (((Scene)(ref s)).name == "Title" || ((Scene)(ref s)).name == "Airport")
			{
				return;
			}
			dayNightManager = Object.FindObjectOfType<DayNightManager>();
			_liveZombies.Clear();
			lastTimeOfDay = 0f;
			_expirationManager = new ZombieManager(delegate(GameObject go)
			{
				if ((Object)(object)go != (Object)null)
				{
					if (_liveZombies.Contains(go))
					{
						_liveZombies.Remove(go);
					}
					if (PhotonNetwork.IsMasterClient)
					{
						PhotonNetwork.Destroy(go);
					}
				}
			});
		}

		private void Update()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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)
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name == "Title")
			{
				return;
			}
			activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name == "Airport" || !PhotonNetwork.InRoom || !PhotonNetwork.IsMasterClient)
			{
				return;
			}
			if ((Object)(object)dayNightManager == (Object)null)
			{
				dayNightManager = Object.FindObjectOfType<DayNightManager>();
				if ((Object)(object)dayNightManager == (Object)null)
				{
					return;
				}
			}
			_liveZombies.RemoveWhere((GameObject z) => (Object)(object)z == (Object)null);
			float timeOfDay = dayNightManager.timeOfDay;
			if (lastTimeOfDay < 5f && timeOfDay >= 5f)
			{
				Log.LogInfo((object)"Sun is rising (5 AM). Burning zombies.");
				KillAllZombies();
			}
			if (lastTimeOfDay < 21f && timeOfDay >= 21f)
			{
				Log.LogInfo((object)"Night has fallen (9 PM). Zombies are waking up.");
				_nextSpawnTime = Time.time + 2f;
			}
			if ((timeOfDay >= 21f || timeOfDay < 5f || alwaysSpawns.Value) && Time.time >= _nextSpawnTime)
			{
				if (_liveZombies.Count < maxZombies.Value)
				{
					SpawnZombies();
				}
				float num = Random.Range(0f - spawnJitter.Value, spawnJitter.Value);
				_nextSpawnTime = Time.time + Mathf.Max(5f, spawnInterval.Value + num);
			}
			lastTimeOfDay = timeOfDay;
			_expirationManager.OnUpdate();
		}

		private void KillAllZombies()
		{
			foreach (GameObject liveZombie in _liveZombies)
			{
				if ((Object)(object)liveZombie != (Object)null)
				{
					PhotonNetwork.Destroy(liveZombie);
				}
			}
			_liveZombies.Clear();
		}

		public void SpawnZombies()
		{
			//IL_0070: 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)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			int num = Random.Range(0, 100);
			if (num >= spawnChance.Value)
			{
				return;
			}
			int num2 = Random.Range(minSpawnCount.Value, maxSpawnCount.Value + 1);
			for (int i = 0; i < num2; i++)
			{
				if (_liveZombies.Count >= maxZombies.Value)
				{
					break;
				}
				Vector3 randomPlayerTarget = GetRandomPlayerTarget();
				if (default(Vector3) == randomPlayerTarget)
				{
					break;
				}
				Vector3 validSpawnPosition = GetValidSpawnPosition(randomPlayerTarget);
				GameObject val = null;
				string[] array = new string[1] { "MushroomZombie" };
				string[] array2 = array;
				foreach (string text in array2)
				{
					try
					{
						val = PhotonNetwork.Instantiate(text, validSpawnPosition, Random.rotation, (byte)0, (object[])null);
						if ((Object)(object)val != (Object)null)
						{
							break;
						}
					}
					catch
					{
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					_liveZombies.Add(val);
					_expirationManager.Register(val, zombieLifetime.Value);
				}
			}
		}

		public static Vector3 GetRandomPlayerTarget()
		{
			//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_003f: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			List<Player> list = (from player in PlayerHandler.GetAllPlayers()
				where !player.character.IsGhost && !player.character.isScoutmaster && !player.character.isZombie && !player.character.isBot && !player.character.data.dead && player.character.data.fullyConscious
				select player).ToList();
			if (list.Count == 0)
			{
				return default(Vector3);
			}
			return list[Random.Range(0, list.Count)].character.Center;
		}

		private Vector3 GetValidSpawnPosition(Vector3 anchor)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			float value = spawnDistMin.Value;
			float value2 = spawnDistMax.Value;
			RaycastHit val3 = default(RaycastHit);
			for (int i = 0; i < 10; i++)
			{
				Vector2 insideUnitCircle = Random.insideUnitCircle;
				Vector2 val = ((Vector2)(ref insideUnitCircle)).normalized * Random.Range(value, value2);
				Vector3 val2 = anchor + new Vector3(val.x, 2f, val.y);
				if (Physics.Raycast(val2 + Vector3.up * 5f, Vector3.down, ref val3, 20f, -1, (QueryTriggerInteraction)1))
				{
					return ((RaycastHit)(ref val3)).point + Vector3.up * 0.1f;
				}
			}
			return anchor + Vector3.forward * value + Vector3.up;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}