Decompiled source of FreeCamAssist v0.2.1

plugins/FreeCamAssist.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MMTools;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FreeCamAssist")]
[assembly: AssemblyDescription("Toggleable free camera for Cult of the Lamb")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FreeCamAssist")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("B9B875E3-77F3-4286-9008-D1594F8D9B1E")]
[assembly: AssemblyFileVersion("0.2.1.0")]
[assembly: AssemblyVersion("0.2.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 FreeCamAssist
{
	[BepInPlugin("com.cotl.freecamassist", "FreeCamAssist", "0.2.1")]
	public sealed class FreeCamAssistPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.cotl.freecamassist";

		public const string PluginName = "FreeCamAssist";

		public const string PluginVersion = "0.2.1";

		internal static ManualLogSource Log;

		internal static FreeCamController Controller;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			FreeCamConfig.Bind(((BaseUnityPlugin)this).Config);
			GameObject val = new GameObject("FreeCamAssistController");
			Object.DontDestroyOnLoad((Object)val);
			Controller = val.AddComponent<FreeCamController>();
			_harmony = new Harmony("com.cotl.freecamassist");
			_harmony.PatchAll(typeof(FreeCamAssistPlugin).Assembly);
			Log.LogInfo((object)"FreeCamAssist 0.2.1 loaded.");
		}

		private void OnDestroy()
		{
			if (_harmony != null)
			{
				_harmony.UnpatchSelf();
			}
		}
	}
	internal enum FreeCamMode
	{
		Survey,
		GroundScout,
		LambView
	}
	internal static class FreeCamConfig
	{
		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<string> ToggleKey;

		internal static ConfigEntry<string> ToggleKeySecondary;

		internal static ConfigEntry<string> CameraLockKey;

		internal static ConfigEntry<string> SwitchModeKey;

		internal static ConfigEntry<string> RecenterKey;

		internal static ConfigEntry<string> VerticalUpKey;

		internal static ConfigEntry<string> VerticalDownKey;

		internal static ConfigEntry<string> FastModifierKey;

		internal static ConfigEntry<string> SlowModifierKey;

		internal static ConfigEntry<bool> FreezePlayerWhileActive;

		internal static ConfigEntry<bool> ResetVanillaOnDisable;

		internal static ConfigEntry<float> SurveyMoveSpeed;

		internal static ConfigEntry<float> GroundMoveSpeed;

		internal static ConfigEntry<float> LambViewMoveSpeed;

		internal static ConfigEntry<float> FastMultiplier;

		internal static ConfigEntry<float> SlowMultiplier;

		internal static ConfigEntry<float> ZoomSpeed;

		internal static ConfigEntry<float> VerticalMoveSpeed;

		internal static ConfigEntry<float> MouseLookSensitivity;

		internal static ConfigEntry<float> SurveyPitch;

		internal static ConfigEntry<float> GroundPitch;

		internal static ConfigEntry<float> LambViewPitch;

		internal static ConfigEntry<bool> DisableDuringConversations;

		internal static ConfigEntry<bool> DebugLogging;

		internal static void Bind(ConfigFile config)
		{
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Expected O, but got Unknown
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Expected O, but got Unknown
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Expected O, but got Unknown
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Expected O, but got Unknown
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Expected O, but got Unknown
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Expected O, but got Unknown
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Expected O, but got Unknown
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Expected O, but got Unknown
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Expected O, but got Unknown
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: Expected O, but got Unknown
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Expected O, but got Unknown
			Enabled = config.Bind<bool>("General", "Enabled", true, "Enable FreeCamAssist.");
			ToggleKey = config.Bind<string>("Input", "ToggleKey", "F9", "Unity KeyCode name for toggling free camera.");
			ToggleKeySecondary = config.Bind<string>("Input", "ToggleKeySecondary", "Insert", "Optional second Unity KeyCode name for toggling free camera.");
			CameraLockKey = config.Bind<string>("Input", "CameraLockKey", "F8", "Unity KeyCode name for locking/unlocking the current freecam view while restoring player control.");
			SwitchModeKey = config.Bind<string>("Input", "SwitchModeKey", "F10", "Unity KeyCode name for switching Survey/GroundScout/LambView modes.");
			RecenterKey = config.Bind<string>("Input", "RecenterKey", "F11", "Unity KeyCode name for resetting the current freecam mode near the player.");
			VerticalUpKey = config.Bind<string>("Input", "VerticalUpKey", "Space", "Unity KeyCode name for raising the camera in freecam.");
			VerticalDownKey = config.Bind<string>("Input", "VerticalDownKey", "C", "Unity KeyCode name for lowering the camera in freecam.");
			FastModifierKey = config.Bind<string>("Input", "FastModifierKey", "LeftShift", "Unity KeyCode name for fast movement while held.");
			SlowModifierKey = config.Bind<string>("Input", "SlowModifierKey", "LeftControl", "Unity KeyCode name for slow movement while held.");
			FreezePlayerWhileActive = config.Bind<bool>("Safety", "FreezePlayerWhileActive", true, "Keep the Lamb/player transform pinned while freecam is active so WASD camera movement cannot walk the player into structures.");
			ResetVanillaOnDisable = config.Bind<bool>("Safety", "ResetVanillaOnDisable", true, "When freecam is disabled, snap the camera back to the vanilla player-follow framing.");
			SurveyMoveSpeed = config.Bind<float>("Camera", "SurveyMoveSpeed", 13f, new ConfigDescription("WASD movement speed in Survey mode.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 80f), Array.Empty<object>()));
			GroundMoveSpeed = config.Bind<float>("Camera", "GroundMoveSpeed", 6f, new ConfigDescription("WASD movement speed in GroundScout mode.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 80f), Array.Empty<object>()));
			LambViewMoveSpeed = config.Bind<float>("Camera", "LambViewMoveSpeed", 4f, new ConfigDescription("WASD movement speed in LambView mode.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 40f), Array.Empty<object>()));
			FastMultiplier = config.Bind<float>("Camera", "FastMultiplier", 3f, new ConfigDescription("Movement multiplier while FastModifierKey is held.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>()));
			SlowMultiplier = config.Bind<float>("Camera", "SlowMultiplier", 0.35f, new ConfigDescription("Movement multiplier while SlowModifierKey is held.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 1f), Array.Empty<object>()));
			ZoomSpeed = config.Bind<float>("Camera", "ZoomSpeed", 12f, new ConfigDescription("Q/E and mouse wheel camera in/out speed.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 80f), Array.Empty<object>()));
			VerticalMoveSpeed = config.Bind<float>("Camera", "VerticalMoveSpeed", 6f, new ConfigDescription("Space/C vertical lift speed in freecam.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 40f), Array.Empty<object>()));
			MouseLookSensitivity = config.Bind<float>("Camera", "MouseLookSensitivity", 2.5f, new ConfigDescription("Right mouse drag look sensitivity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 20f), Array.Empty<object>()));
			SurveyPitch = config.Bind<float>("Camera", "SurveyPitch", -60f, new ConfigDescription("Starting camera pitch for Survey mode.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-89f, -5f), Array.Empty<object>()));
			GroundPitch = config.Bind<float>("Camera", "GroundPitch", -15f, new ConfigDescription("Starting camera pitch for GroundScout mode.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-80f, 25f), Array.Empty<object>()));
			LambViewPitch = config.Bind<float>("Camera", "LambViewPitch", -5f, new ConfigDescription("Starting camera pitch for LambView mode.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-70f, 45f), Array.Empty<object>()));
			DisableDuringConversations = config.Bind<bool>("Safety", "DisableDuringConversations", true, "Temporarily yield to vanilla camera while conversations or scripted target cameras are active.");
			DebugLogging = config.Bind<bool>("Debug", "DebugLogging", false, "Verbose FreeCamAssist logs.");
		}
	}
	internal sealed class FreeCamController : MonoBehaviour
	{
		private FreeCamMode _mode;

		private Vector3 _position;

		private float _pitch;

		private float _yaw;

		private bool _active;

		private bool _cameraLocked;

		private bool _hasPosition;

		private bool _cameraTouched;

		private bool _previousSnappyMovement;

		private bool _previousDisablePlayerLook;

		private bool _playersFrozen;

		private readonly Dictionary<PlayerFarming, Vector3> _frozenPlayerPositions = new Dictionary<PlayerFarming, Vector3>();

		private KeyCode _toggleKey = (KeyCode)290;

		private KeyCode _toggleKeySecondary = (KeyCode)277;

		private KeyCode _cameraLockKey = (KeyCode)289;

		private KeyCode _switchModeKey = (KeyCode)291;

		private KeyCode _recenterKey = (KeyCode)292;

		private KeyCode _verticalUpKey = (KeyCode)32;

		private KeyCode _verticalDownKey = (KeyCode)99;

		private KeyCode _fastKey = (KeyCode)304;

		private KeyCode _slowKey = (KeyCode)306;

		private string _lastToggleRaw;

		private string _lastToggleSecondaryRaw;

		private string _lastCameraLockRaw;

		private string _lastSwitchModeRaw;

		private string _lastRecenterRaw;

		private string _lastVerticalUpRaw;

		private string _lastVerticalDownRaw;

		private string _lastFastRaw;

		private string _lastSlowRaw;

		internal bool Active
		{
			get
			{
				if (_active)
				{
					return FreeCamConfig.Enabled.Value;
				}
				return false;
			}
		}

		private void Update()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			RefreshKeys();
			if (!FreeCamConfig.Enabled.Value)
			{
				Disable();
				return;
			}
			if (Input.GetKeyDown(_toggleKey) || Input.GetKeyDown(_toggleKeySecondary))
			{
				Toggle();
			}
			if (!_active)
			{
				return;
			}
			if (Input.GetKeyDown(_cameraLockKey))
			{
				ToggleCameraLock();
			}
			if (_cameraLocked)
			{
				UnfreezePlayers();
				return;
			}
			if (Input.GetKeyDown(_switchModeKey))
			{
				SwitchMode();
			}
			if (Input.GetKeyDown(_recenterKey))
			{
				Recenter(keepModePitch: true);
			}
			HandleMovement();
			HandleMouseLook();
			FreezePlayers();
		}

		private void LateUpdate()
		{
			FreezePlayers();
			Apply(CameraFollowTarget.Instance);
		}

		internal bool ShouldOwnCamera(CameraFollowTarget camera)
		{
			if (Active && (Object)(object)camera != (Object)null)
			{
				return !ShouldYieldToVanilla(camera);
			}
			return false;
		}

		internal void Apply(CameraFollowTarget camera)
		{
			//IL_0043: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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)
			if (!Active || (Object)(object)camera == (Object)null)
			{
				return;
			}
			if (ShouldYieldToVanilla(camera))
			{
				RestoreCameraFlags(camera);
				return;
			}
			if (!_hasPosition)
			{
				CaptureFrom(camera);
			}
			Quaternion rotation = Quaternion.Euler(_pitch, 0f, _yaw);
			Transform transform = ((Component)camera).transform;
			transform.position = _position;
			transform.rotation = rotation;
			camera.CurrentPosition = _position;
			camera.CurrentTargetCameraPosition = _position;
			camera.Look = Vector3.zero;
			SaveCameraFlags(camera);
			camera.SnappyMovement = true;
			camera.DisablePlayerLook = true;
		}

		internal bool ShouldFreezePlayerController()
		{
			if (Active && !_cameraLocked)
			{
				return FreeCamConfig.FreezePlayerWhileActive.Value;
			}
			return false;
		}

		private void Toggle()
		{
			_active = !_active;
			if (_active)
			{
				_cameraLocked = false;
				CameraFollowTarget instance = CameraFollowTarget.Instance;
				if ((Object)(object)instance != (Object)null)
				{
					CaptureFrom(instance);
				}
				else
				{
					Recenter(keepModePitch: false);
				}
				FreezePlayers();
			}
			else
			{
				Disable();
			}
			LogInfo("Free camera " + (_active ? "enabled" : "disabled") + " in " + _mode.ToString() + " mode.");
		}

		private void Disable()
		{
			if (_active || _cameraTouched)
			{
				RestoreCameraFlags(CameraFollowTarget.Instance);
				UnfreezePlayers();
				if (FreeCamConfig.ResetVanillaOnDisable.Value)
				{
					ResetVanillaCamera(CameraFollowTarget.Instance);
				}
				_active = false;
				_cameraLocked = false;
				_hasPosition = false;
			}
		}

		private void SaveCameraFlags(CameraFollowTarget camera)
		{
			if (!_cameraTouched && !((Object)(object)camera == (Object)null))
			{
				_previousSnappyMovement = camera.SnappyMovement;
				_previousDisablePlayerLook = camera.DisablePlayerLook;
				_cameraTouched = true;
			}
		}

		private void RestoreCameraFlags(CameraFollowTarget camera)
		{
			if (_cameraTouched)
			{
				if ((Object)(object)camera != (Object)null)
				{
					camera.SnappyMovement = _previousSnappyMovement;
					camera.DisablePlayerLook = _previousDisablePlayerLook;
				}
				_cameraTouched = false;
			}
		}

		private void SwitchMode()
		{
			_mode = ((_mode == FreeCamMode.Survey) ? FreeCamMode.GroundScout : ((_mode == FreeCamMode.GroundScout) ? FreeCamMode.LambView : FreeCamMode.Survey));
			Recenter(keepModePitch: false);
			LogInfo("Mode -> " + _mode);
		}

		private void ToggleCameraLock()
		{
			_cameraLocked = !_cameraLocked;
			if (_cameraLocked)
			{
				UnfreezePlayers();
			}
			else
			{
				FreezePlayers();
			}
			LogInfo("Camera lock " + (_cameraLocked ? "enabled: player control restored, camera held." : "disabled: freecam controls restored."));
		}

		private void CaptureFrom(CameraFollowTarget camera)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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)
			//IL_0024: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			_position = ((Component)camera).transform.position;
			Quaternion rotation = ((Component)camera).transform.rotation;
			Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles;
			_pitch = NormalizeAngle(eulerAngles.x);
			_yaw = NormalizeAngle(eulerAngles.z);
			if (Mathf.Abs(_pitch) < 0.001f)
			{
				_pitch = ((_mode == FreeCamMode.Survey) ? FreeCamConfig.SurveyPitch.Value : FreeCamConfig.GroundPitch.Value);
			}
			_hasPosition = true;
		}

		private void Recenter(bool keepModePitch)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_0083: 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_0096: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			PlayerFarming instance = PlayerFarming.Instance;
			CameraFollowTarget instance2 = CameraFollowTarget.Instance;
			if (!((Object)(object)instance == (Object)null) || !((Object)(object)instance2 == (Object)null))
			{
				Vector3 val = (((Object)(object)instance != (Object)null) ? ((Component)instance).transform.position : instance2.GetCameraTargetWorldPosition());
				if (_mode == FreeCamMode.Survey)
				{
					float pitch = (keepModePitch ? _pitch : Mathf.Clamp(FreeCamConfig.SurveyPitch.Value, -89f, -5f));
					float distance = 12f;
					_pitch = pitch;
					_yaw = 0f;
					_position = val + CameraOffsetForPitch(_pitch, distance);
				}
				else if (_mode == FreeCamMode.GroundScout)
				{
					_pitch = (keepModePitch ? _pitch : Mathf.Clamp(FreeCamConfig.GroundPitch.Value, -80f, 25f));
					_position = val + new Vector3(0f, -2.4f, -3.2f);
				}
				else
				{
					_pitch = (keepModePitch ? _pitch : Mathf.Clamp(FreeCamConfig.LambViewPitch.Value, -70f, 45f));
					_yaw = PlayerFacingYaw(instance);
					_position = GetLambViewPosition(instance, val);
				}
				_hasPosition = true;
			}
		}

		private void HandleMovement()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			float num = ((_mode == FreeCamMode.Survey) ? FreeCamConfig.SurveyMoveSpeed.Value : ((_mode == FreeCamMode.GroundScout) ? FreeCamConfig.GroundMoveSpeed.Value : FreeCamConfig.LambViewMoveSpeed.Value));
			if (Input.GetKey(_fastKey))
			{
				num *= FreeCamConfig.FastMultiplier.Value;
			}
			if (Input.GetKey(_slowKey))
			{
				num *= FreeCamConfig.SlowMultiplier.Value;
			}
			Vector3 up = default(Vector3);
			Vector3 right = default(Vector3);
			if (_mode == FreeCamMode.GroundScout || _mode == FreeCamMode.LambView)
			{
				float num2 = _yaw * ((float)Math.PI / 180f);
				((Vector3)(ref up))..ctor(Mathf.Sin(num2), Mathf.Cos(num2), 0f);
				((Vector3)(ref right))..ctor(Mathf.Cos(num2), 0f - Mathf.Sin(num2), 0f);
			}
			else
			{
				up = Vector3.up;
				right = Vector3.right;
			}
			Vector3 val = Vector3.zero;
			if (Input.GetKey((KeyCode)119))
			{
				val += up;
			}
			if (Input.GetKey((KeyCode)115))
			{
				val -= up;
			}
			if (Input.GetKey((KeyCode)100))
			{
				val += right;
			}
			if (Input.GetKey((KeyCode)97))
			{
				val -= right;
			}
			if (((Vector3)(ref val)).sqrMagnitude > 1f)
			{
				((Vector3)(ref val)).Normalize();
			}
			_position += val * num * Time.unscaledDeltaTime;
			float num3 = 0f;
			if (Input.GetKey(_verticalUpKey))
			{
				num3 += 1f;
			}
			if (Input.GetKey(_verticalDownKey))
			{
				num3 -= 1f;
			}
			if (Mathf.Abs(num3) > 0.001f)
			{
				_position += Vector3.forward * num3 * FreeCamConfig.VerticalMoveSpeed.Value * Time.unscaledDeltaTime;
			}
			Vector3 val2 = Quaternion.Euler(_pitch, 0f, _yaw) * Vector3.forward;
			float num4 = 0f;
			if (Input.GetKey((KeyCode)101))
			{
				num4 += 1f;
			}
			if (Input.GetKey((KeyCode)113))
			{
				num4 -= 1f;
			}
			num4 += Input.mouseScrollDelta.y * 3f;
			if (Mathf.Abs(num4) > 0.001f)
			{
				_position += val2 * num4 * FreeCamConfig.ZoomSpeed.Value * Time.unscaledDeltaTime;
			}
		}

		private void HandleMouseLook()
		{
			if (Input.GetMouseButton(1))
			{
				float value = FreeCamConfig.MouseLookSensitivity.Value;
				_yaw += Input.GetAxis("Mouse X") * value;
				_pitch -= Input.GetAxis("Mouse Y") * value;
				_pitch = Mathf.Clamp(_pitch, -89f, 60f);
			}
		}

		private bool ShouldYieldToVanilla(CameraFollowTarget camera)
		{
			if (!FreeCamConfig.DisableDuringConversations.Value)
			{
				return false;
			}
			try
			{
				return (Object)(object)camera.TargetCamera != (Object)null || MMConversation.isPlaying || LetterBox.IsPlaying || PhotoModeManager.PhotoModeActive;
			}
			catch
			{
				return false;
			}
		}

		private void RefreshKeys()
		{
			RefreshKey(FreeCamConfig.ToggleKey.Value, ref _lastToggleRaw, ref _toggleKey, (KeyCode)290);
			RefreshKey(FreeCamConfig.ToggleKeySecondary.Value, ref _lastToggleSecondaryRaw, ref _toggleKeySecondary, (KeyCode)277);
			RefreshKey(FreeCamConfig.CameraLockKey.Value, ref _lastCameraLockRaw, ref _cameraLockKey, (KeyCode)289);
			RefreshKey(FreeCamConfig.SwitchModeKey.Value, ref _lastSwitchModeRaw, ref _switchModeKey, (KeyCode)291);
			RefreshKey(FreeCamConfig.RecenterKey.Value, ref _lastRecenterRaw, ref _recenterKey, (KeyCode)292);
			RefreshKey(FreeCamConfig.VerticalUpKey.Value, ref _lastVerticalUpRaw, ref _verticalUpKey, (KeyCode)32);
			RefreshKey(FreeCamConfig.VerticalDownKey.Value, ref _lastVerticalDownRaw, ref _verticalDownKey, (KeyCode)99);
			RefreshKey(FreeCamConfig.FastModifierKey.Value, ref _lastFastRaw, ref _fastKey, (KeyCode)304);
			RefreshKey(FreeCamConfig.SlowModifierKey.Value, ref _lastSlowRaw, ref _slowKey, (KeyCode)306);
		}

		private void FreezePlayers()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if (!Active || _cameraLocked || !FreeCamConfig.FreezePlayerWhileActive.Value)
			{
				UnfreezePlayers();
				return;
			}
			for (int i = 0; i < PlayerFarming.players.Count; i++)
			{
				PlayerFarming val = PlayerFarming.players[i];
				if (!((Object)(object)val == (Object)null))
				{
					if (!_frozenPlayerPositions.ContainsKey(val))
					{
						_frozenPlayerPositions[val] = ((Component)val).transform.position;
					}
					else
					{
						((Component)val).transform.position = _frozenPlayerPositions[val];
					}
				}
			}
			_playersFrozen = true;
		}

		private void UnfreezePlayers()
		{
			if (_playersFrozen)
			{
				_frozenPlayerPositions.Clear();
				_playersFrozen = false;
			}
		}

		private void ResetVanillaCamera(CameraFollowTarget camera)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: 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)
			PlayerFarming instance = PlayerFarming.Instance;
			if ((Object)(object)camera == (Object)null || (Object)(object)instance == (Object)null)
			{
				return;
			}
			try
			{
				GameManager instance2 = GameManager.GetInstance();
				if ((Object)(object)instance2 != (Object)null)
				{
					instance2.CameraSetOffset(Vector3.zero);
					instance2.CameraResetTargetZoom();
					if ((Object)(object)instance.CameraBone != (Object)null && !camera.Contains(instance.CameraBone))
					{
						instance2.AddToCamera(instance.CameraBone, 1f);
					}
				}
			}
			catch
			{
			}
			camera.TargetOffset = Vector3.zero;
			camera.CurrentOffset = Vector3.zero;
			camera.Look = Vector3.zero;
			camera.TargetCamera = null;
			camera.SnappyMovement = _previousSnappyMovement;
			camera.DisablePlayerLook = _previousDisablePlayerLook;
			camera.distance = 12f;
			camera.targetDistance = 12f;
			camera.angle = -45f;
			((Component)camera).transform.rotation = Quaternion.Euler(-45f, 0f, 0f);
			camera.SnapTo(((Component)instance).transform.position);
			camera.CurrentTargetCameraPosition = camera.CurrentPosition;
		}

		private static Vector3 GetLambViewPosition(PlayerFarming player, Vector3 fallback)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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)
			if ((Object)(object)player != (Object)null && (Object)(object)player.CameraBone != (Object)null)
			{
				return player.CameraBone.transform.position + new Vector3(0f, 0.1f, -0.45f);
			}
			return fallback + new Vector3(0f, 0.15f, -0.75f);
		}

		private static float PlayerFacingYaw(PlayerFarming player)
		{
			if ((Object)(object)player != (Object)null && (Object)(object)player.state != (Object)null)
			{
				return 90f - player.state.facingAngle;
			}
			return 0f;
		}

		private static void RefreshKey(string raw, ref string lastRaw, ref KeyCode key, KeyCode fallback)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected I4, but got Unknown
			if (!(raw == lastRaw))
			{
				lastRaw = raw;
				key = (KeyCode)(int)ParseKeyCode(raw, fallback);
			}
		}

		private unsafe static KeyCode ParseKeyCode(string raw, KeyCode fallback)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//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_005c: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrWhiteSpace(raw))
			{
				return (KeyCode)0;
			}
			try
			{
				return (KeyCode)Enum.Parse(typeof(KeyCode), raw.Trim(), ignoreCase: true);
			}
			catch
			{
				if (FreeCamAssistPlugin.Log != null)
				{
					FreeCamAssistPlugin.Log.LogWarning((object)("Invalid KeyCode '" + raw + "', using " + ((object)(*(KeyCode*)(&fallback))/*cast due to .constrained prefix*/).ToString()));
				}
				return fallback;
			}
		}

		private static float NormalizeAngle(float angle)
		{
			while (angle > 180f)
			{
				angle -= 360f;
			}
			while (angle < -180f)
			{
				angle += 360f;
			}
			return angle;
		}

		private static Vector3 CameraOffsetForPitch(float pitchDegrees, float distance)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			float num = pitchDegrees * ((float)Math.PI / 180f);
			return new Vector3(0f, distance * Mathf.Sin(num), (0f - distance) * Mathf.Cos(num));
		}

		private static void DebugLog(string message)
		{
			if (FreeCamConfig.DebugLogging.Value && FreeCamAssistPlugin.Log != null)
			{
				FreeCamAssistPlugin.Log.LogInfo((object)("[FreeCamAssist] " + message));
			}
		}

		private static void LogInfo(string message)
		{
			if (FreeCamAssistPlugin.Log != null)
			{
				FreeCamAssistPlugin.Log.LogInfo((object)("[FreeCamAssist] " + message));
			}
		}
	}
	[HarmonyPatch(typeof(CameraFollowTarget), "LateUpdate")]
	internal static class CameraFollowTargetLateUpdatePatch
	{
		public static bool Prefix(CameraFollowTarget __instance)
		{
			FreeCamController controller = FreeCamAssistPlugin.Controller;
			if ((Object)(object)controller != (Object)null && controller.ShouldOwnCamera(__instance))
			{
				controller.Apply(__instance);
				return false;
			}
			return true;
		}

		public static void Postfix(CameraFollowTarget __instance)
		{
			FreeCamController controller = FreeCamAssistPlugin.Controller;
			if ((Object)(object)controller != (Object)null)
			{
				controller.Apply(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerController), "Update")]
	internal static class PlayerControllerUpdatePatch
	{
		public static bool Prefix()
		{
			FreeCamController controller = FreeCamAssistPlugin.Controller;
			if (!((Object)(object)controller == (Object)null))
			{
				return !controller.ShouldFreezePlayerController();
			}
			return true;
		}
	}
}