Decompiled source of ContentSpectateEnemies v1.2.0

ContentSpectateEnemies.dll

Decompiled 8 months ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("ContentSpectateEnemies")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+7690f80b7796c34ab14bbec7c5a0ca90af9aef59")]
[assembly: AssemblyProduct("ContentSpectateEnemies")]
[assembly: AssemblyTitle("ContentSpectateEnemies")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace ContentSpectateEnemies
{
	[ContentWarningPlugin("SpectateEnemies", "1.2.0", true)]
	[BepInPlugin("SpectateEnemies", "SpectateEnemies", "1.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony harmony;

		private void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			harmony = new Harmony("SpectateEnemies");
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"SpectateEnemies loaded!");
		}
	}
	internal class SpectateEnemies : MonoBehaviour
	{
		public static SpectateEnemies Instance;

		private static FieldInfo lookDirection;

		private static MethodInfo look;

		private static MethodInfo switching;

		public int SpectatedEnemyIndex = -1;

		public bool SpectatingEnemies = false;

		public float ZoomLevel = 1f;

		private static MethodInfo start;

		private readonly GUIStyle centerStyle = new GUIStyle
		{
			fontSize = 50,
			normal = new GUIStyleState
			{
				textColor = Color.red
			},
			alignment = (TextAnchor)1
		};

		private readonly GUIStyle rightStyle = new GUIStyle
		{
			fontSize = 30,
			normal = new GUIStyleState
			{
				textColor = Color.white
			},
			alignment = (TextAnchor)2
		};

		private void Awake()
		{
			if ((Object)(object)Instance != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			Instance = this;
			lookDirection = AccessTools.Field(typeof(Spectate), "lookDirection");
			look = AccessTools.Method(typeof(Spectate), "Look", (Type[])null, (Type[])null);
			switching = AccessTools.Method(typeof(Spectate), "Switching", (Type[])null, (Type[])null);
			start = AccessTools.Method(typeof(Spectate), "StartSpectate", (Type[])null, (Type[])null);
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		}

		private void OnGUI()
		{
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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)
			if (!Spectate.spectating)
			{
				return;
			}
			if (SpectatingEnemies)
			{
				Bot val = BotHandler.instance.bots.ElementAtOrDefault(SpectatedEnemyIndex);
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				GUI.Label(new Rect((float)(Screen.width / 2 - 150), 20f, 300f, 100f), string.Format("Spectating: {0}", ((Object)((Component)val).transform.parent).name.Replace("(Clone)", "")), centerStyle);
			}
			else if ((Object)(object)Player.observedPlayer != (Object)null)
			{
				string nickName = Player.observedPlayer.refs.view.Owner.NickName;
				GUI.Label(new Rect((float)(Screen.width / 2 - 150), 20f, 300f, 100f), $"Spectating: {nickName}", centerStyle);
			}
			GUI.Label(new Rect((float)(Screen.width - 320), 20f, 300f, 300f), "Controls:\n[E] Spectate " + (SpectatingEnemies ? "Players" : "Enemies") + "\n[F] Toggle Light\n[A] Previous\n[D] Next", rightStyle);
		}

		private void Update()
		{
			if (!Spectate.spectating)
			{
				return;
			}
			if (Input.GetKeyDown((KeyCode)101))
			{
				SpectatingEnemies = !SpectatingEnemies;
				if (SpectatingEnemies)
				{
					if (BotHandler.instance.bots.Count == 0)
					{
						SpectatingEnemies = false;
						Debug.LogWarning((object)"No enemies to spectate");
						return;
					}
					if (SpectatedEnemyIndex == -1 || SpectatedEnemyIndex >= BotHandler.instance.bots.Count)
					{
						GetNextValidSpectatable();
					}
				}
			}
			if (Input.GetKeyDown((KeyCode)102))
			{
				Light component = ((Component)MainCamera.instance).GetComponent<Light>();
				((Behaviour)component).enabled = !((Behaviour)component).enabled;
			}
		}

		public void DoSpectate(Spectate spectate)
		{
			//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_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)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: 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_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			if (!Player.localPlayer.data.dead)
			{
				SpectatingEnemies = false;
				return;
			}
			if (BotHandler.instance.bots.Count == 0)
			{
				SpectatingEnemies = false;
				return;
			}
			Bot val = BotHandler.instance.bots.ElementAtOrDefault(SpectatedEnemyIndex);
			if ((Object)(object)val == (Object)null)
			{
				GetNextValidSpectatable();
				return;
			}
			((Component)spectate).transform.rotation = Quaternion.LookRotation((Vector3)lookDirection.GetValue(spectate));
			((Component)spectate).transform.position = val.centerTransform.position + Vector3.up * 0.75f;
			Vector3 val2 = ((Component)spectate).transform.position + ((Component)spectate).transform.forward * -3f;
			RaycastHit val3 = HelperFunctions.LineCheck(((Component)spectate).transform.position, val2, (LayerType)1, 0f);
			if (Object.op_Implicit((Object)(object)((RaycastHit)(ref val3)).transform))
			{
				Transform transform = ((Component)spectate).transform;
				transform.position += -((Component)spectate).transform.forward * (((RaycastHit)(ref val3)).distance - 0.2f);
			}
			else
			{
				((Component)spectate).transform.position = val2 + ((Component)spectate).transform.forward * 0.2f;
			}
			look.Invoke(spectate, null);
			switching.Invoke(spectate, null);
		}

		public void SwitchEnemy()
		{
			if (Input.GetKeyDown((KeyCode)97))
			{
				SpectatedEnemyIndex--;
				if (SpectatedEnemyIndex < 0)
				{
					SpectatedEnemyIndex = BotHandler.instance.bots.Count - 1;
				}
			}
			if (Input.GetKeyDown((KeyCode)100))
			{
				SpectatedEnemyIndex++;
				if (SpectatedEnemyIndex >= BotHandler.instance.bots.Count)
				{
					SpectatedEnemyIndex = 0;
				}
			}
		}

		private void GetNextValidSpectatable()
		{
			int i = 0;
			int num = SpectatedEnemyIndex;
			for (; i < BotHandler.instance.bots.Count; i++)
			{
				num++;
				if (num >= BotHandler.instance.bots.Count)
				{
					num = 0;
				}
				Bot val = BotHandler.instance.bots.ElementAtOrDefault(num);
				if ((Object)(object)val != (Object)null)
				{
					SpectatedEnemyIndex = num;
					return;
				}
			}
			SpectatingEnemies = false;
			Debug.LogWarning((object)"No enemies to spectate");
		}
	}
	[HarmonyPatch(typeof(Spectate), "DoSpectate")]
	internal class Spectate_DoSpectate
	{
		private static bool Prefix(Spectate __instance)
		{
			if (SpectateEnemies.Instance.SpectatingEnemies)
			{
				SpectateEnemies.Instance.DoSpectate(__instance);
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Spectate), "Switching")]
	internal class Spectate_Switching
	{
		private static bool Prefix()
		{
			if (SpectateEnemies.Instance.SpectatingEnemies)
			{
				SpectateEnemies.Instance.SwitchEnemy();
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(JumpScareSound), "Scare")]
	internal class JumpScareSound_Scare
	{
		private static bool Prefix()
		{
			if (SpectateEnemies.Instance.SpectatingEnemies)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(RoundSpawner), "Start")]
	internal class RoundSpawner_Start
	{
		private static void Postfix()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((Component)MainCamera.instance).gameObject.GetComponent<Light>() == (Object)null)
			{
				Light val = ((Component)MainCamera.instance).gameObject.AddComponent<Light>();
				val.color = Color.white;
				val.type = (LightType)2;
				val.shadows = (LightShadows)0;
				val.range = 100f;
				val.intensity = 8f;
				((Behaviour)val).enabled = false;
			}
		}
	}
	[HarmonyPatch(typeof(MainMenuHandler), "Awake")]
	internal class MainMenuHandler_Awake
	{
		private static void Postfix()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if ((Object)(object)SpectateEnemies.Instance == (Object)null)
			{
				GameObject val = new GameObject("SpectateEnemiesObject");
				val.AddComponent<SpectateEnemies>();
			}
		}
	}
	[HarmonyPatch(typeof(Spectate), "StopSpectate")]
	internal class Spectate_Stop
	{
		private static void Postfix()
		{
			Light component = ((Component)MainCamera.instance).gameObject.GetComponent<Light>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
		}
	}
}