Decompiled source of FPSSpectate v1.0.1

BepInEx/plugins/FPSSpectate.dll

Decompiled a year ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[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("FPSSpectate")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("FPS spectate camera")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ada41809ef3e18d1ac6f547212c170f1debd12d4")]
[assembly: AssemblyProduct("FPSSpectate")]
[assembly: AssemblyTitle("FPSSpectate")]
[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 FPSSpectate
{
	[BepInPlugin("5Bit.FPSSpectate", "FPSSpectate", "1.0.0")]
	public class FPSSpectate : BaseUnityPlugin
	{
		private const string modGUID = "5Bit.FPSSpectate";

		private const string modName = "FPSSpectate";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("5Bit.FPSSpectate");

		private static FPSSpectate Instance;

		internal static ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("5Bit.FPSSpectate");
			harmony.PatchAll();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "FPSSpectate";

		public const string PLUGIN_NAME = "FPSSpectate";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace FPSSpectate.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class FPSSpectatePatch
	{
		private const float SPECTATE_OFFSET = 1.5f;

		private static bool firstPerson = true;

		private static bool debounced = false;

		[HarmonyPatch("LateUpdate")]
		[HarmonyPostfix]
		private static void LateUpdate(PlayerControllerB __instance)
		{
			//IL_008d: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			if (((ButtonControl)Keyboard.current.vKey).wasPressedThisFrame && !debounced)
			{
				firstPerson = !firstPerson;
				debounced = true;
			}
			if (((ButtonControl)Keyboard.current.vKey).wasReleasedThisFrame)
			{
				debounced = false;
			}
			if ((Object)(object)__instance.spectatedPlayerScript != (Object)null && firstPerson)
			{
				Transform transform = ((Component)__instance.spectateCameraPivot).transform;
				Transform transform2 = ((Component)__instance.spectatedPlayerScript.visorCamera).transform;
				Vector3 position = transform2.position;
				Vector3 forward = transform2.forward;
				transform.position = position + ((Vector3)(ref forward)).normalized * 1.5f;
				transform.rotation = transform2.rotation;
			}
		}
	}
}