Decompiled source of FovUpdate v0.3.1

FovUpdate.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("FovUpdate")]
[assembly: AssemblyFileVersion("0.3.1")]
[assembly: AssemblyInformationalVersion("0.3.1")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.1.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 FovUpdate
{
	public static class FovConfig
	{
		internal static ConfigEntry<bool> DeveloperLogging;

		internal static ConfigEntry<float> UserDefinedFov;

		internal static ConfigEntry<float> UserCrouchFov;

		internal static ConfigEntry<float> UserSprintFov;

		internal static ConfigEntry<float> MapFov;

		internal static ConfigEntry<float> MaximumPossibleFov;

		public static ConfigEntry<bool> EffectsFix;

		public static ConfigEntry<bool> OnScreenFix;

		public static ConfigEntry<bool> ClampFix;

		public static ConfigEntry<bool> AspectRatioFix;

		public static ConfigEntry<float> ResMultiplier;

		public static ConfigEntry<bool> DontStretchUI;

		internal static bool ChangingSprintFov;

		internal static float UpdateSprintConfigItem()
		{
			if (UserSprintFov.Value + UserDefinedFov.Value > 180f && ClampFix.Value)
			{
				ChangingSprintFov = true;
				Plugin.Log.LogMessage((object)$"Sprint FOV + desired FOV exceeds maximum of {MaximumPossibleFov.Value}. Lowering Sprint FOV to maximum acceptable value");
				UserSprintFov.Value = Mathf.Clamp(MaximumPossibleFov.Value - UserDefinedFov.Value, 0f, 100f);
			}
			ChangingSprintFov = false;
			return UserSprintFov.Value;
		}

		internal static bool StretchUI()
		{
			if (DontStretchUI.Value)
			{
				return false;
			}
			return true;
		}

		internal static void Init()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Expected O, but got Unknown
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Expected O, but got Unknown
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Expected O, but got Unknown
			DeveloperLogging = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Debug", "Developer Logging", false, new ConfigDescription("Enable this to see developer logging output", (AcceptableValueBase)null, Array.Empty<object>()));
			UserDefinedFov = ((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("Settings", "Fov", 70f, new ConfigDescription("Set this to desired Fov value (standard gameplay)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(45f, 140f), Array.Empty<object>()));
			UserCrouchFov = ((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("Settings", "CrouchFov", 55f, new ConfigDescription("Set this to desired Fov value for when the player is crouched (tumble mode)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(45f, 140f), Array.Empty<object>()));
			UserSprintFov = ((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("Settings", "SprintFov", 20f, new ConfigDescription("Set this to the desired base modifier for your fov when sprinting.\nThis number will be added on to your regular fov when you start sprinting.\nDefault in vanilla is 20.\nNOTE: If Maximum FOV fix is enabled, this value will be capped based on your base Fov setting to ensure the fov can never exceed the number set via Maximum Possible Fov", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			MapFov = ((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("Settings", "MapFov", 50f, new ConfigDescription("Set this to desired Fov value for when pulling out your map.\nLeave at default value of 50 to let the Effects fix automatically adjust this value based on your base fov", (AcceptableValueBase)(object)new AcceptableValueRange<float>(35f, 140f), Array.Empty<object>()));
			AspectRatioFix = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Settings", "Aspect-ratio fix on/off", false, "Set this to true to enable Oksamies' UltrawideOrLongFix for widescreen compatibility");
			DontStretchUI = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Settings", "Dont Stretch UI", false, "Set this to true if you want the UI to remain the same size regardless of ultrawide/ultralong status\nThis setting does not automatically update when you change it and will only take effect when changing between game scenes.");
			ResMultiplier = ((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("Settings", "Resolution Multiplier", 1f, new ConfigDescription("Use this to upscale or downscale your game!\nNOTE: This config item will override the \"Pixelation\" graphics setting except when the default is set. (1)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 4f), Array.Empty<object>()));
			OnScreenFix = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Settings", "OnScreen fix on/off", true, "This setting updates the OnScreen method calculation to account for your prefered FOV when enabled\nShould fix some of the more exagerated examples of being able to stare at enemies like the \"Shadow Child\" in the corner of your screen without triggering the looked at effect by using a high fov");
			EffectsFix = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Settings", "Effects fix on/off", true, "This setting adjusts the strength of fov effects based on your base fov.\nSo if you have a higher fov than standard, the amount you zoom in from enemies or items will be lessened to match a similar zoom distance as with the original default fov");
			ClampFix = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Settings", "Maximum FOV fix on/off", true, "This setting prevents the fov from ever being higher than the number set in Maximum Possible Fov.\nFixes the potential for unplayable fovs after numerous speed upgrade");
			MaximumPossibleFov = ((BaseUnityPlugin)Plugin.instance).Config.Bind<float>("Settings", "Maximum Possible Fov", 170f, new ConfigDescription("Requires Maximum FOV fix to be enabled\nClamps the fov to never be higher than this number", (AcceptableValueBase)(object)new AcceptableValueRange<float>(150f, 200f), Array.Empty<object>()));
		}
	}
	[HarmonyPatch(typeof(CameraZoom), "Awake")]
	public class CameraPatchThings
	{
		public static void Prefix(CameraZoom __instance)
		{
			if (!AreWeInGame())
			{
				return;
			}
			Plugin.playerCams.RemoveAll((Camera c) => (Object)(object)c == (Object)null);
			CollectionExtensions.Do<Camera>((IEnumerable<Camera>)__instance.cams, (Action<Camera>)delegate(Camera x)
			{
				Plugin.playerCams.Add(x);
				Plugin.Spam($"Original Fov of {((Object)x).name} is {x.fieldOfView}");
				x.fieldOfView = FovConfig.UserDefinedFov.Value;
				Plugin.Spam($"Field of view for {((Object)x).name} set to {FovConfig.UserDefinedFov.Value}");
				if (FovConfig.AspectRatioFix.Value)
				{
					UltraWideSupport.StretchFix(x);
				}
			});
			__instance.zoomPrev = FovConfig.UserDefinedFov.Value;
			__instance.zoomNew = FovConfig.UserDefinedFov.Value;
			__instance.zoomCurrent = FovConfig.UserDefinedFov.Value;
			__instance.playerZoomDefault = FovConfig.UserDefinedFov.Value;
			__instance.SprintZoom = FovConfig.UpdateSprintConfigItem();
		}

		internal static bool AreWeInGame()
		{
			if (SemiFunc.RunIsLobbyMenu())
			{
				return false;
			}
			if ((Object)(object)RunManager.instance.levelCurrent == (Object)(object)RunManager.instance.levelMainMenu)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(GraphicsManager), "UpdateRenderSize")]
	public class ResolutionOverride
	{
		internal static float lastMultiplier = 1f;

		internal static bool EarlyReturn = false;

		public static void SetResolutionFix()
		{
			if (FovConfig.ResMultiplier.Value == 1f && lastMultiplier == FovConfig.ResMultiplier.Value)
			{
				Plugin.Spam("Pixelation setting remaining unchanged");
				return;
			}
			if (FovConfig.ResMultiplier.Value == 1f)
			{
				Plugin.Spam("Updating to base-game's pixelation setting");
				lastMultiplier = FovConfig.ResMultiplier.Value;
				EarlyReturn = true;
				GraphicsManager.instance.UpdateRenderSize();
				return;
			}
			float num = (float)Screen.width * FovConfig.ResMultiplier.Value;
			float num2 = (float)Screen.height * FovConfig.ResMultiplier.Value;
			float num3 = SystemInfo.maxTextureSize;
			if (num > num3 || num2 > num3)
			{
				Plugin.WARNING($"Unable to apply Resolution Multiplier of {FovConfig.ResMultiplier.Value}!\nExpected Height ({num2}) or Width ({num}) is larger than maxium Unity supported value of (GPU limit) {num3}");
				FovConfig.ResMultiplier.Value = Mathf.Min(num3 / (float)Screen.width, num3 / (float)Screen.height);
				num = (float)Screen.width * FovConfig.ResMultiplier.Value;
				num2 = (float)Screen.height * FovConfig.ResMultiplier.Value;
				Plugin.Log.LogMessage((object)$"Resolution multiplier clamped to {FovConfig.ResMultiplier.Value} (GPU limit: {num3}) Expected Width: {num} Expected Heigh: {num2}");
			}
			RenderTextureMain.instance.textureWidthOriginal = Mathf.FloorToInt(num);
			RenderTextureMain.instance.textureHeightOriginal = Mathf.FloorToInt(num2);
			lastMultiplier = FovConfig.ResMultiplier.Value;
			Plugin.Spam($"RenderTexture resolution set to: {num}x{num2} via multiplier {FovConfig.ResMultiplier.Value}");
		}

		public static void Postfix()
		{
			if (EarlyReturn)
			{
				EarlyReturn = false;
			}
			else
			{
				SetResolutionFix();
			}
		}
	}
	[HarmonyPatch(typeof(GraphicsManager), "Update")]
	public class UltraWideSupport
	{
		public enum ScreenStatus
		{
			Default,
			Wide,
			Tall
		}

		public static ScreenStatus ScreenIs = ScreenStatus.Default;

		public static float previousAspectRatio;

		public static float currentAspectRatio;

		public static readonly float defaultAspectRatio = 1.7777778f;

		public static List<RectTransform> Rects = new List<RectTransform>();

		public static void Postfix(GraphicsManager __instance)
		{
			if (!FovConfig.AspectRatioFix.Value || __instance.fullscreenCheckTimer > 0f)
			{
				return;
			}
			Rects.RemoveAll((RectTransform r) => (Object)(object)r == (Object)null);
			bool flag = false;
			if (Rects.Count == 0)
			{
				if (!FovConfig.StretchUI())
				{
					Rects = new List<RectTransform>(1) { ((Component)RenderTextureMain.instance).gameObject.GetComponent<RectTransform>() };
				}
				else
				{
					Rects = ((Component)RenderTextureMain.instance).gameObject.GetComponentsInChildren<RectTransform>().ToList();
				}
				flag = true;
			}
			currentAspectRatio = (float)Screen.width / (float)Screen.height;
			if (previousAspectRatio == currentAspectRatio && !flag)
			{
				return;
			}
			if (currentAspectRatio > defaultAspectRatio)
			{
				CollectionExtensions.Do<RectTransform>((IEnumerable<RectTransform>)Rects, (Action<RectTransform>)delegate(RectTransform r)
				{
					//IL_0011: Unknown result type (might be due to invalid IL or missing references)
					r.sizeDelta = new Vector2(428f * currentAspectRatio, 428f);
				});
				ScreenIs = ScreenStatus.Wide;
				Plugin.Spam("Updating Aspect Ratio for ultrawide support!");
			}
			else if (currentAspectRatio == defaultAspectRatio)
			{
				CollectionExtensions.Do<RectTransform>((IEnumerable<RectTransform>)Rects, (Action<RectTransform>)delegate(RectTransform r)
				{
					//IL_0011: Unknown result type (might be due to invalid IL or missing references)
					r.sizeDelta = new Vector2(750f, 750f / currentAspectRatio);
				});
				ScreenIs = ScreenStatus.Default;
				Plugin.Spam("Updating Aspect Ratio to default!");
			}
			else
			{
				CollectionExtensions.Do<RectTransform>((IEnumerable<RectTransform>)Rects, (Action<RectTransform>)delegate(RectTransform r)
				{
					//IL_0011: Unknown result type (might be due to invalid IL or missing references)
					r.sizeDelta = new Vector2(750f, 750f / currentAspectRatio);
				});
				ScreenIs = ScreenStatus.Tall;
				Plugin.Spam("Updating Aspect Ratio for ultratall support!");
			}
			Plugin.UpdateCams();
			CollectionExtensions.Do<Camera>((IEnumerable<Camera>)Plugin.playerCams, (Action<Camera>)delegate(Camera c)
			{
				StretchFix(c);
			});
			previousAspectRatio = currentAspectRatio;
		}

		public static void StretchFix(Camera cam)
		{
			if (FovConfig.AspectRatioFix.Value && !((Object)(object)cam == (Object)null))
			{
				currentAspectRatio = (float)Screen.width / (float)Screen.height;
				cam.aspect = currentAspectRatio;
				Plugin.Spam($"{((Object)cam).name} aspect ratio set to {cam.aspect}");
			}
		}
	}
	[HarmonyPatch(typeof(CameraAim), "CameraAimSpawn")]
	public class SpawnPlayerFov
	{
		public static void Postfix()
		{
			if (!CameraPatchThings.AreWeInGame())
			{
				if (UltraWideSupport.ScreenIs != 0)
				{
					Plugin.UpdateCams();
					CollectionExtensions.Do<Camera>((IEnumerable<Camera>)Plugin.playerCams, (Action<Camera>)delegate(Camera x)
					{
						UltraWideSupport.StretchFix(x);
					});
				}
				return;
			}
			if (PlayerAvatar.instance.localCamera.fieldOfView == FovConfig.UserDefinedFov.Value)
			{
				Plugin.Log.LogMessage((object)"@SpawnPatch: Fov already set to correct value");
				return;
			}
			((MonoBehaviour)PlayerAvatar.instance).StartCoroutine(ChatCommandHandler.ForceFovZoomCurve(FovConfig.UserDefinedFov.Value, ((Component)PlayerAvatar.instance).gameObject));
			Plugin.Log.LogMessage((object)$"@SpawnPatch: Fov set to number [ {FovConfig.UserDefinedFov.Value} ]");
			if (!((Object)(object)CameraZoom.Instance == (Object)null))
			{
				CameraZoom.Instance.SprintZoom = FovConfig.UpdateSprintConfigItem();
				Plugin.Log.LogMessage((object)$"@SpawnPatch: SprintFov set to number [ {CameraZoom.Instance.SprintZoom} ]");
			}
		}
	}
	[HarmonyPatch(typeof(CameraZoom), "OverrideZoomSet")]
	public class EffectsFix
	{
		public static void Prefix(ref float zoom)
		{
			bool cont = true;
			if (!ChatCommandHandler.changingFov && !MapAndConfigCheck(ref zoom, ref cont) && !TumbleCheck())
			{
				if (cont)
				{
					float num = 70f / FovConfig.UserDefinedFov.Value;
					zoom /= num;
				}
				if (FovConfig.ClampFix.Value)
				{
					Mathf.Clamp(zoom, 1f, FovConfig.MaximumPossibleFov.Value);
				}
				Plugin.Spam($"zoom set to {zoom}\n Adjusted: {cont}");
			}
		}

		private static bool MapAndConfigCheck(ref float value, ref bool cont)
		{
			if ((Object)(object)Map.Instance != (Object)null && FovConfig.MapFov.Value != 50f && Map.Instance.Active)
			{
				Plugin.Spam("Adjusting mapfov!");
				value = FovConfig.MapFov.Value;
				cont = false;
				return false;
			}
			return !FovConfig.EffectsFix.Value;
		}

		private static bool TumbleCheck()
		{
			if ((Object)(object)PlayerAvatar.instance == (Object)null || (Object)(object)PlayerController.instance == (Object)null)
			{
				return false;
			}
			if ((Object)(object)PlayerAvatar.instance.tumble == (Object)null)
			{
				return false;
			}
			if (PlayerAvatar.instance.tumble.isTumbling)
			{
				return PlayerController.instance.InputDisableTimer <= 0f;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(SemiFunc), "OnScreen")]
	public class AdjustOnScreenBool
	{
		public static void Prefix(ref float paddWidth, ref float paddHeight)
		{
			if (CameraPatchThings.AreWeInGame() && FovConfig.OnScreenFix.Value)
			{
				float num = FovConfig.UserDefinedFov.Value / 70f;
				paddHeight /= num;
				paddWidth /= num;
			}
		}
	}
	[HarmonyPatch(typeof(CameraZoom), "Update")]
	[HarmonyPriority(0)]
	public class CameraZoomUpdateClamp
	{
		private static int replacements;

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> CameraZoom_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			Plugin.Log.LogMessage((object)"CameraZoomUpdateClamp Transpiler Initialized");
			replacements = 0;
			instructions = Transpilers.Manipulator(instructions, (Func<CodeInstruction, bool>)((CodeInstruction instruction) => CodeInstructionExtensions.Calls(instruction, AccessTools.Method("UnityEngine.Camera:set_fieldOfView", (Type[])null, (Type[])null))), (Action<CodeInstruction>)NewInstruction);
			return instructions;
		}

		internal static void NewInstruction(CodeInstruction instruction)
		{
			CodeInstruction val = Transpilers.EmitDelegate<Action<Camera, float>>((Action<Camera, float>)delegate(Camera cam, float fov)
			{
				if (FovConfig.ClampFix.Value)
				{
					cam.fieldOfView = Mathf.Clamp(fov, 1f, FovConfig.MaximumPossibleFov.Value);
				}
				else
				{
					cam.fieldOfView = fov;
				}
			});
			instruction.opcode = val.opcode;
			instruction.operand = val.operand;
			checked
			{
				replacements++;
				Plugin.Log.LogMessage((object)$"CameraZoom_Transpiler patched Update to clamp the final fov value!\n[ {replacements} ] lines changed");
			}
		}
	}
	[HarmonyPatch(typeof(PlayerTumble), "Update")]
	[HarmonyPriority(0)]
	public class TumbleAdjustment
	{
		private static int replacements;

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> TumbleAdjustment_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			Plugin.Log.LogMessage((object)"TumbleAdjustment Transpiler Initialized");
			replacements = 0;
			instructions = Transpilers.Manipulator(instructions, (Func<CodeInstruction, bool>)((CodeInstruction x) => ChangeThisFloat(x, 55f)), (Action<CodeInstruction>)NewInstruction);
			return instructions;
		}

		internal static void NewInstruction(CodeInstruction instruction)
		{
			CodeInstruction val = Transpilers.EmitDelegate<Func<float>>((Func<float>)OverrideZoomSpecial);
			instruction.opcode = val.opcode;
			instruction.operand = val.operand;
			checked
			{
				replacements++;
				Plugin.Log.LogMessage((object)$"TumbleAdjustment patched crouchfov config!\n[ {replacements} ] lines changed");
			}
		}

		internal static bool ChangeThisFloat(CodeInstruction instruction, float expectedValue)
		{
			if (instruction.opcode != OpCodes.Ldc_R4)
			{
				return false;
			}
			if (!float.TryParse(instruction.operand.ToString(), out var result))
			{
				return false;
			}
			if (result != expectedValue)
			{
				return false;
			}
			return true;
		}

		internal static float OverrideZoomSpecial()
		{
			return FovConfig.UserCrouchFov.Value;
		}
	}
	[HarmonyPatch(typeof(ChatManager), "MessageSend")]
	public class ChatCommandHandler
	{
		[CompilerGenerated]
		private sealed class <ForceFovZoomCurve>d__6 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public GameObject obj;

			public float newFov;

			public bool updateDef;

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

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

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

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

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					if ((Object)(object)PlayerAvatar.instance == (Object)null)
					{
						return false;
					}
					if (changingFov)
					{
						return false;
					}
					if ((Object)(object)obj == (Object)null)
					{
						obj = PlayerController.instance.playerAvatar.gameObject;
					}
					changingFov = true;
					CameraZoom.Instance.zoomPrev = CameraZoom.Instance.zoomCurrent;
					CameraZoom.Instance.OverrideZoomSet(newFov, 2f, 1f, 1f, obj, 150);
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if ((double)Mathf.Abs(CameraZoom.Instance.zoomCurrent - newFov) > 0.25 && (Object)(object)CameraZoom.Instance.OverrideZoomObject == (Object)(object)obj)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				if (updateDef)
				{
					CameraZoom.Instance.playerZoomDefault = newFov;
				}
				changingFov = false;
				if ((Object)(object)CameraZoom.Instance.OverrideZoomObject != (Object)(object)obj)
				{
					return false;
				}
				CameraZoom.Instance.OverrideActive = false;
				CameraZoom.Instance.OverrideZoomObject = null;
				CameraZoom.Instance.OverrideZoomPriority = 999;
				CameraZoom.Instance.OverrideZoomSpeedIn = 1f;
				CameraZoom.Instance.OverrideZoomSpeedOut = 1f;
				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();
			}
		}

		private static string lastMsg = ":o";

		internal static bool changingFov = false;

		public static bool Prefix(ChatManager __instance)
		{
			if (__instance.chatMessage == lastMsg)
			{
				return true;
			}
			Plugin.Spam("Reading chat message - " + __instance.chatMessage);
			lastMsg = __instance.chatMessage;
			if (__instance.chatMessage.StartsWith("/fov"))
			{
				__instance.AddLetterToChat(" " + HandleFovChange(__instance.chatMessage));
			}
			else if (__instance.chatMessage.StartsWith("/cfov"))
			{
				__instance.AddLetterToChat(" " + HandleCrouchFovChange(__instance.chatMessage));
			}
			else if (__instance.chatMessage.StartsWith("/sfov"))
			{
				__instance.AddLetterToChat(" " + HandleSprintFovChange(__instance.chatMessage));
			}
			return true;
		}

		internal static string HandleSprintFovChange(string message)
		{
			string[] array = message.Split(' ');
			if (array.Length == 1)
			{
				Plugin.Log.LogMessage((object)("Invalid sprint fov message format given - [ " + message + " ]"));
				return "No number specified for /sfov!";
			}
			string text = array[1];
			if (float.TryParse(text, out var result))
			{
				if (result < 0f || result > 100f)
				{
					return $"Unable to set sprint fov to {result} (out of range)";
				}
				FovConfig.UserSprintFov.Value = result;
				CameraZoom.Instance.SprintZoom = FovConfig.UpdateSprintConfigItem();
				Plugin.Log.LogMessage((object)$"SprintFov set to number [ {CameraZoom.Instance.SprintZoom} ]");
				return "Sprint fov updated";
			}
			Plugin.Log.LogMessage((object)("Unable to parse value from " + text + "!"));
			return "Unable to parse value from " + text + "!";
		}

		internal static string HandleCrouchFovChange(string message)
		{
			if (CameraZoom.Instance.OverrideActive && !PlayerAvatar.instance.tumble.isTumbling)
			{
				Plugin.Log.LogMessage((object)"Unable to update crouch fov, camera OverrideActive is true! (not tumbling)");
				lastMsg = "";
				return "Unable to change crouch fov, overriden by outside entity!";
			}
			string[] array = message.Split(' ');
			if (array.Length == 1)
			{
				Plugin.Log.LogMessage((object)("Invalid crouch fov message format given - [ " + message + " ]"));
				return "No number specified for /cfov!";
			}
			string text = array[1];
			if (float.TryParse(text, out var result))
			{
				if (result < 45f || result > 140f)
				{
					return $"Unable to set crouch fov to {result} (out of range)";
				}
				if (PlayerAvatar.instance.isTumbling)
				{
					((MonoBehaviour)ChatManager.instance).StartCoroutine(ForceFovZoomCurve(result, ((Component)PlayerAvatar.instance.tumble).gameObject, updateDef: false));
				}
				FovConfig.UserCrouchFov.Value = result;
				Plugin.Log.LogMessage((object)$"CrouchFov set to number [ {result} ]");
				return $"crouch fov set to {result}";
			}
			Plugin.Log.LogMessage((object)("Unable to parse value from " + text + "!"));
			return "Unable to parse value from " + text + "!";
		}

		internal static string HandleFovChange(string message)
		{
			if (CameraZoom.Instance.OverrideActive && !PlayerAvatar.instance.isTumbling)
			{
				Plugin.Log.LogMessage((object)"Unable to update fov, camera OverrideActive is true!");
				lastMsg = "";
				return "Unable to change fov, camera is overriden!";
			}
			string[] array = message.Split(' ');
			if (array.Length == 1)
			{
				Plugin.Log.LogMessage((object)("Invalid fov message format given - [ " + message + " ]"));
				return "No number specified for /fov!";
			}
			string text = array[1];
			if (float.TryParse(text, out var result))
			{
				if (result < 45f || result > 140f)
				{
					return $"Unable to set fov to {result} (out of range)";
				}
				if (PlayerAvatar.instance.isTumbling)
				{
					CameraZoom.Instance.playerZoomDefault = result;
					FovConfig.UserDefinedFov.Value = result;
					CameraZoom.Instance.SprintZoom = FovConfig.UpdateSprintConfigItem();
					return $"fov will be {result} when you get up";
				}
				((MonoBehaviour)ChatManager.instance).StartCoroutine(ForceFovZoomCurve(result, ((Component)PlayerAvatar.instance).gameObject));
				FovConfig.UserDefinedFov.Value = result;
				Plugin.Log.LogMessage((object)$"Fov set to number [ {result} ]");
				CameraZoom.Instance.SprintZoom = FovConfig.UpdateSprintConfigItem();
				return $"fov set to {result}";
			}
			Plugin.Log.LogMessage((object)("Unable to parse value from " + text + "!"));
			return "Unable to parse value from " + text + "!";
		}

		[IteratorStateMachine(typeof(<ForceFovZoomCurve>d__6))]
		internal static IEnumerator ForceFovZoomCurve(float newFov, GameObject obj = null, bool updateDef = true)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ForceFovZoomCurve>d__6(0)
			{
				newFov = newFov,
				obj = obj,
				updateDef = updateDef
			};
		}
	}
	[BepInPlugin("com.github.darmuh.FovUpdate", "FovUpdate", "0.3.1")]
	public class Plugin : BaseUnityPlugin
	{
		public static class PluginInfo
		{
			public const string PLUGIN_GUID = "com.github.darmuh.FovUpdate";

			public const string PLUGIN_NAME = "FovUpdate";

			public const string PLUGIN_VERSION = "0.3.1";
		}

		public static Plugin instance = null;

		internal static ManualLogSource Log = null;

		public static List<Camera> playerCams = new List<Camera>();

		private void Awake()
		{
			instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"FovUpdate is loading with version 0.3.1!");
			FovConfig.Init();
			((BaseUnityPlugin)instance).Config.SettingChanged += OnSettingChanged;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			Log.LogInfo((object)"FovUpdate load complete!");
			Log.LogInfo((object)"This version of the mod has been compiled for v0.1.2.42_beta :)");
		}

		private void OnSettingChanged(object sender, SettingChangedEventArgs settingChangedArg)
		{
			Spam("CONFIG SETTING CHANGE EVENT");
			if (settingChangedArg.ChangedSetting == null || (Object)(object)CameraZoom.Instance == (Object)null)
			{
				return;
			}
			if (settingChangedArg.ChangedSetting == FovConfig.DeveloperLogging || settingChangedArg.ChangedSetting == FovConfig.AspectRatioFix)
			{
				Log.LogDebug((object)$"{settingChangedArg.ChangedSetting.Definition.Key} is enabled [ {(bool)settingChangedArg.ChangedSetting.BoxedValue} ]");
			}
			if (settingChangedArg.ChangedSetting == FovConfig.UserSprintFov && !FovConfig.ChangingSprintFov)
			{
				CameraZoom.Instance.SprintZoom = FovConfig.UpdateSprintConfigItem();
				Spam($"SprintFov updated to {CameraZoom.Instance.SprintZoom}");
			}
			if (settingChangedArg.ChangedSetting == FovConfig.ResMultiplier)
			{
				ResolutionOverride.SetResolutionFix();
			}
			if (settingChangedArg.ChangedSetting == FovConfig.UserDefinedFov)
			{
				if (!CameraZoom.Instance.OverrideActive && (Object)(object)CameraNoPlayerTarget.instance == (Object)null)
				{
					((MonoBehaviour)PlayerAvatar.instance).StartCoroutine(ChatCommandHandler.ForceFovZoomCurve((float)settingChangedArg.ChangedSetting.BoxedValue, ((Component)PlayerAvatar.instance).gameObject));
				}
				else
				{
					CameraZoom.Instance.playerZoomDefault = FovConfig.UserDefinedFov.Value;
				}
				CameraZoom.Instance.SprintZoom = FovConfig.UpdateSprintConfigItem();
				Spam($"Fov updated to {(float)settingChangedArg.ChangedSetting.BoxedValue}");
			}
			if (settingChangedArg.ChangedSetting == FovConfig.UserCrouchFov)
			{
				if ((Object)(object)PlayerAvatar.instance == (Object)null || (Object)(object)PlayerAvatar.instance.tumble == (Object)null)
				{
					return;
				}
				if (CameraZoom.Instance.OverrideActive && PlayerAvatar.instance.tumble.isTumbling)
				{
					((MonoBehaviour)PlayerAvatar.instance).StartCoroutine(ChatCommandHandler.ForceFovZoomCurve((float)settingChangedArg.ChangedSetting.BoxedValue, ((Component)PlayerAvatar.instance.tumble).gameObject, updateDef: false));
				}
				Spam($"CrouchFov updated to {(float)settingChangedArg.ChangedSetting.BoxedValue}");
			}
			if (settingChangedArg.ChangedSetting == FovConfig.DontStretchUI)
			{
				UltraWideSupport.Rects = new List<RectTransform>();
			}
		}

		internal static void UpdateCams()
		{
			if (!((Object)(object)CameraZoom.Instance == (Object)null))
			{
				playerCams.RemoveAll((Camera c) => (Object)(object)c == (Object)null);
				CollectionExtensions.DoIf<Camera>((IEnumerable<Camera>)CameraZoom.Instance.cams, (Func<Camera, bool>)((Camera c) => !playerCams.Contains(c)), (Action<Camera>)delegate(Camera c)
				{
					playerCams.Add(c);
				});
			}
		}

		internal static void Spam(string message)
		{
			if (FovConfig.DeveloperLogging.Value)
			{
				Log.LogDebug((object)message);
			}
		}

		internal static void ERROR(string message)
		{
			Log.LogError((object)message);
		}

		internal static void WARNING(string message)
		{
			Log.LogWarning((object)message);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}