Decompiled source of FreecamSpectate v1.0.0

FreecamSpectate/FreecamSpectate.dll

Decompiled a month ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using FreecamSpectate.Patches;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FreecamSpectate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FreecamSpectate")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a2043f9c-7dc3-4250-829c-60987fbb66e7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FreecamSpectate
{
	[BepInPlugin("Leo.FreecamSpectate", "FreecamSpectate", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "Leo.FreecamSpectate";

		private const string modName = "FreecamSpectate";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Leo.FreecamSpectate");

		internal ManualLogSource mls;

		private static Plugin Instance;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Leo.FreecamSpectate");
			mls.LogInfo((object)"FreecamSpectate has loaded");
			harmony.PatchAll(typeof(Plugin));
			harmony.PatchAll(typeof(KillCamPatch));
		}
	}
}
namespace FreecamSpectate.Patches
{
	[HarmonyPatch(typeof(KillCam), "Update")]
	internal class KillCamPatch
	{
		private static bool freecamActive = false;

		private static Vector3 movementInput = Vector3.zero;

		private static Vector2 rotationInput = Vector2.zero;

		private static float baseSpeed = 20f;

		private static readonly float shiftMultiplier = 2f;

		private static readonly float mouseSensitivity = 2f;

		private static readonly float scrollSpeedStep = 1f;

		private static readonly float minSpeed = 1f;

		private static readonly float maxSpeed = 100f;

		private static bool Prefix(KillCam __instance)
		{
			HandleToggle();
			if (freecamActive)
			{
				HandleScrollSpeed();
				HandleMovement(((Component)__instance).transform);
				HandleRotation(((Component)__instance).transform);
				return false;
			}
			return true;
		}

		private static void HandleToggle()
		{
			if (Input.GetKeyDown((KeyCode)102))
			{
				freecamActive = !freecamActive;
				Cursor.lockState = (CursorLockMode)(freecamActive ? 1 : 0);
				Cursor.visible = !freecamActive;
			}
		}

		private static void HandleScrollSpeed()
		{
			float axis = Input.GetAxis("Mouse ScrollWheel");
			if (Mathf.Abs(axis) > 0.01f)
			{
				baseSpeed = Mathf.Clamp(baseSpeed + axis * scrollSpeedStep * 10f, minSpeed, maxSpeed);
				Debug.Log((object)$"Freecam speed adjusted to: {baseSpeed:F1}");
			}
		}

		private static void HandleMovement(Transform cam)
		{
			//IL_0064: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303)) ? (baseSpeed * shiftMultiplier) : baseSpeed);
			movementInput = new Vector3(Input.GetAxis("Horizontal"), Input.GetKey((KeyCode)101) ? 1f : (Input.GetKey((KeyCode)113) ? (-1f) : 0f), Input.GetAxis("Vertical"));
			cam.position += cam.TransformDirection(movementInput) * num * Time.deltaTime;
		}

		private static void HandleRotation(Transform cam)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			rotationInput.x += Input.GetAxis("Mouse X") * mouseSensitivity;
			rotationInput.y -= Input.GetAxis("Mouse Y") * mouseSensitivity;
			rotationInput.y = Mathf.Clamp(rotationInput.y, -90f, 90f);
			cam.rotation = Quaternion.Euler(rotationInput.y, rotationInput.x, 0f);
		}
	}
}