Decompiled source of ZombieAtNight v1.1.1

Plugins/ZombieAtNight.dll

Decompiled 16 hours 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.SceneManagement;

[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+f6f7fc07dec8578d7d19f418ebfe1890e45b7333")]
[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 ZombieChaos
{
	[BepInPlugin("Heroes", "ZombieAtNight", "1.1.1")]
	public class ZombiePlugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <DespawnAfter>d__22 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public GameObject go;

			public float seconds;

			public ZombiePlugin <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DespawnAfter>d__22(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(seconds);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if ((Object)(object)go != (Object)null)
					{
						if (<>4__this._liveZombies.Contains(go))
						{
							<>4__this._liveZombies.Remove(go);
						}
						if (PhotonNetwork.IsMasterClient)
						{
							PhotonNetwork.Destroy(go);
						}
					}
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		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 float _nextSpawnTime = 0f;

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

		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");
			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"))
			{
				dayNightManager = Object.FindObjectOfType<DayNightManager>();
				_liveZombies.Clear();
				lastTimeOfDay = 0f;
			}
		}

		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) && 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);
			}
			if (timeOfDay < lastTimeOfDay)
			{
				lastTimeOfDay = timeOfDay;
			}
			else
			{
				lastTimeOfDay = timeOfDay;
			}
		}

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

		public void SpawnZombies()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: 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_00a4: 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_00ab: 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;
				}
				Log.LogMessage((object)"GetRandomPlayerTarget");
				Vector3 randomPlayerTarget = GetRandomPlayerTarget();
				if (default(Vector3) == randomPlayerTarget)
				{
					break;
				}
				Vector3 validSpawnPosition = GetValidSpawnPosition(randomPlayerTarget);
				GameObject val = null;
				string[] array = new string[3] { "MushroomZombie", "0_Items/MushroomZombie", "Zombie/MushroomZombie" };
				string[] array2 = array;
				foreach (string text in array2)
				{
					try
					{
						Log.LogMessage((object)"Instantiation zombie");
						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)
				{
					Log.LogMessage((object)"_liveZombies.Add(zombie)");
					_liveZombies.Add(val);
					((MonoBehaviour)this).StartCoroutine(DespawnAfter(val, zombieLifetime.Value));
				}
			}
		}

		public static Vector3 GetRandomPlayerTarget()
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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
				select player).ToList();
			Log.LogMessage((object)("Number of player found: " + list.Count));
			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;
		}

		[IteratorStateMachine(typeof(<DespawnAfter>d__22))]
		private IEnumerator DespawnAfter(GameObject go, float seconds)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DespawnAfter>d__22(0)
			{
				<>4__this = this,
				go = go,
				seconds = seconds
			};
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}