Decompiled source of Frozns Recoil v1.3.5

Frozn's Recoil.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.Json;
using BoneLib;
using BoneLib.BoneMenu;
using FroznRecoil;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using Il2CppSystem;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(FroznsRecoilMod), "Frozn's Recoil", "1.3.2", "Frozn", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Frozn's Recoil")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.3.5.0")]
[assembly: AssemblyInformationalVersion("1.3.5")]
[assembly: AssemblyProduct("Frozn's Recoil")]
[assembly: AssemblyTitle("Frozn's Recoil")]
[assembly: AssemblyVersion("1.3.5.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 FroznRecoil
{
	public enum WeaponClass
	{
		Pistol,
		SMG,
		Rifle,
		Shotgun
	}
	public enum RecoilPreset
	{
		Custom,
		Light,
		Medium,
		Hard,
		Action
	}
	public enum GunHandlingPreset
	{
		Custom,
		Controlled,
		Balanced,
		Loose,
		Punchy
	}
	internal enum PlayerMovement
	{
		Still,
		Crouching,
		Walking,
		Running,
		Jumping
	}
	public sealed class FroznsRecoilMod : MelonMod
	{
		private sealed class Tuning
		{
			public float Snap = 1f;

			public float Shake = 0.45f;

			public float Recovery = 7f;

			public float Vignette = 0.55f;

			public float Duration = 0.2f;

			public float Randomization = 1.4f;
		}

		private sealed class GunProfileRecord
		{
			public string Id { get; set; } = "";

			public string Name { get; set; } = "";

			public int Type { get; set; }
		}

		private sealed class GunProfile
		{
			public string Id;

			public string Name;

			public WeaponClass Type;

			public Tuning Tuning;

			public MelonPreferences_Entry<float>[] Entries;

			public MelonPreferences_Entry<bool> AllowRelease;

			public MelonPreferences_Entry<float> ShotsBeforeRelease;

			public MelonPreferences_Entry<float> ReleaseForce;

			public MelonPreferences_Entry<float> HandlingMultiplier;

			public MelonPreferences_Entry<float> ArmKickForce;

			public MelonPreferences_Entry<int> HandlingPreset;

			public MelonPreferences_Entry<int> RecoilPreset;

			public FloatElement[] Sliders;

			public BoolElement ReleaseToggle;

			public EnumElement PresetElement;

			public EnumElement RecoilPresetElement;

			public Page Page;
		}

		private static readonly Color MenuColor = new Color(0.9f, 0.4f, 0.2f);

		private static readonly Color GeneralColor = new Color(0.35f, 0.82f, 1f);

		private static readonly Color PresetColor = new Color(0.88f, 0.55f, 1f);

		private static readonly Color RecoilColor = new Color(1f, 0.55f, 0.28f);

		private static readonly Color ComfortColor = new Color(0.35f, 1f, 0.68f);

		private readonly Dictionary<WeaponClass, Tuning> _tuning = new Dictionary<WeaponClass, Tuning>();

		private readonly Dictionary<WeaponClass, MelonPreferences_Entry<float>[]> _entries = new Dictionary<WeaponClass, MelonPreferences_Entry<float>[]>();

		private readonly Dictionary<WeaponClass, FloatElement[]> _sliders = new Dictionary<WeaponClass, FloatElement[]>();

		private MelonPreferences_Category _prefs;

		private MelonPreferences_Entry<bool> _enabled;

		private MelonPreferences_Entry<bool> _vignetteEnabled;

		private MelonPreferences_Entry<bool> _dynamicEnabled;

		private MelonPreferences_Entry<float> _dynamicIntensity;

		private MelonPreferences_Entry<bool> _oneHandDropEnabled;

		private MelonPreferences_Entry<float> _defaultReleaseForce;

		private MelonPreferences_Entry<string> _gunProfileIndex;

		private MelonPreferences_Entry<int> _releaseBehaviorVersion;

		private MelonPreferences_Entry<int> _globalPreset;

		private BoolElement _enabledElement;

		private BoolElement _vignetteElement;

		private BoolElement _dynamicElement;

		private FloatElement _dynamicIntensityElement;

		private BoolElement _globalReleaseElement;

		private FloatElement _defaultReleaseForceElement;

		private EnumElement _globalPresetElement;

		private Page _page;

		private Page _handlingRoot;

		private Page _individualGunRoot;

		private Camera _camera;

		private Transform _cameraTransform;

		private Transform _recoilTarget;

		private Transform _overlay;

		private Material _overlayMaterial;

		private Texture2D _overlayTexture;

		private Action<ScriptableRenderContext, Camera> _beginCameraRenderingCallback;

		private Action<ScriptableRenderContext, Camera> _endCameraRenderingCallback;

		private Quaternion _previousRotationOffset = Quaternion.identity;

		private Quaternion _previousTargetRotation = Quaternion.identity;

		private Quaternion _previousCameraRotation = Quaternion.identity;

		private Vector3 _previousTargetPosition;

		private Vector3 _rotationKick;

		private float _vignetteAlpha;

		private float _vignetteTimer;

		private bool _isApplying;

		private float _recoveryRate = 7f;

		private bool _renderOverrideLogged;

		private bool _standaloneAndroid;

		private bool _firstShotLogged;

		private float _cameraSearchTimer;

		private Vector3 _lastRigPosition;

		private bool _hasMovementSample;

		private float _horizontalSpeed;

		private float _verticalSpeed;

		private readonly Dictionary<string, GunProfile> _gunProfiles = new Dictionary<string, GunProfile>(StringComparer.Ordinal);

		private readonly Dictionary<int, Gun> _trackedReleaseGuns = new Dictionary<int, Gun>();

		private readonly Dictionary<int, float> _lastShotTimes = new Dictionary<int, float>();

		private readonly Dictionary<int, float> _lastReleaseShotTimes = new Dictionary<int, float>();

		private readonly Dictionary<int, int> _shotStreaks = new Dictionary<int, int>();

		private readonly Dictionary<int, int> _shotsSinceRelease = new Dictionary<int, int>();

		private float _standingHeadHeight = 1.55f;

		private PlayerMovement _movement;

		private const string LegacyCategoryId = "BodyCamRecoil";

		internal static FroznsRecoilMod Instance { get; private set; }

		public override void OnInitializeMelon()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			_standaloneAndroid = (int)Application.platform == 11;
			bool flag = MelonPreferences.HasEntry("BodyCamRecoil", "Enabled");
			_prefs = MelonPreferences.CreateCategory("FroznsRecoil", "Frozn's Recoil");
			_enabled = _prefs.CreateEntry<bool>("Enabled", LegacyValue("Enabled", fallback: true), (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_vignetteEnabled = _prefs.CreateEntry<bool>("ComfortVignette", LegacyValue("ComfortVignette", fallback: true), (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_dynamicEnabled = _prefs.CreateEntry<bool>("DynamicRecoil", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_dynamicIntensity = _prefs.CreateEntry<float>("DynamicIntensity", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			if (Mathf.Abs(_dynamicIntensity.Value - 0.65f) < 0.001f)
			{
				_dynamicIntensity.Value = 1f;
			}
			_oneHandDropEnabled = _prefs.CreateEntry<bool>("OneHandDropEnabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_defaultReleaseForce = _prefs.CreateEntry<float>("DefaultReleaseForce", 0.6f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_gunProfileIndex = _prefs.CreateEntry<string>("GunProfileIndex", "", (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_releaseBehaviorVersion = _prefs.CreateEntry<int>("ReleaseBehaviorVersion", 0, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_globalPreset = _prefs.CreateEntry<int>("AllGunsPreset", LegacyValue("AllGunsPreset", 2), (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			Instance = this;
			foreach (WeaponClass value in Enum.GetValues(typeof(WeaponClass)))
			{
				Tuning tuning = Defaults(value);
				string text = value.ToString();
				MelonPreferences_Entry<float>[] array = new MelonPreferences_Entry<float>[6]
				{
					_prefs.CreateEntry<float>(text + "Snap", LegacyValue(text + "Snap", tuning.Snap), (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
					_prefs.CreateEntry<float>(text + "Shake", LegacyValue(text + "Shake", tuning.Shake), (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
					_prefs.CreateEntry<float>(text + "Recovery", LegacyValue(text + "Recovery", tuning.Recovery), (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
					_prefs.CreateEntry<float>(text + "Vignette", LegacyValue(text + "Vignette", tuning.Vignette), (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
					_prefs.CreateEntry<float>(text + "VignetteDuration", LegacyValue(text + "VignetteDuration", tuning.Duration), (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
					_prefs.CreateEntry<float>(text + "Randomization", LegacyValue(text + "Randomization", tuning.Randomization), (string)null, (string)null, false, false, (ValueValidator)null, (string)null)
				};
				MigrateSavedPreset(value, array);
				if (Mathf.Abs(array[5].Value - 0.65f) < 0.001f)
				{
					array[5].Value = tuning.Randomization;
				}
				_entries[value] = array;
				_tuning[value] = new Tuning
				{
					Snap = array[0].Value,
					Shake = array[1].Value,
					Recovery = array[2].Value,
					Vignette = array[3].Value,
					Duration = array[4].Value,
					Randomization = array[5].Value
				};
			}
			LoadSavedGunProfiles();
			MigrateReleaseBehavior();
			BuildMenu();
			GunProfile[] array2 = _gunProfiles.Values.ToArray();
			foreach (GunProfile profile in array2)
			{
				AddGunProfilePage(profile);
			}
			Hooking.OnPostFireGun += OnGunFired;
			try
			{
				_beginCameraRenderingCallback = DelegateSupport.ConvertDelegate<Action<ScriptableRenderContext, Camera>>((Delegate)new Action<ScriptableRenderContext, Camera>(OnBeginCameraRendering));
				_endCameraRenderingCallback = DelegateSupport.ConvertDelegate<Action<ScriptableRenderContext, Camera>>((Delegate)new Action<ScriptableRenderContext, Camera>(OnEndCameraRendering));
				RenderPipelineManager.beginCameraRendering += _beginCameraRenderingCallback;
				RenderPipelineManager.endCameraRendering += _endCameraRenderingCallback;
			}
			catch (Exception ex)
			{
				_beginCameraRenderingCallback = null;
				_endCameraRenderingCallback = null;
				((MelonBase)this).LoggerInstance.Warning("VR camera recoil hooks could not initialize; the game will continue without camera rotation: " + ex.Message);
			}
			if (_standaloneAndroid)
			{
				((MelonBase)this).LoggerInstance.Warning("Standalone Android detected: camera recoil is enabled; comfort vignette overlay is disabled for display safety.");
			}
			if (flag)
			{
				MigrateLegacyCategory();
			}
			((MelonBase)this).LoggerInstance.Msg("Frozn's Recoil v1.3.5 loaded. Recoil and Gun Handling settings are under BoneMenu → Frozn's Recoil.");
		}

		public override void OnDeinitializeMelon()
		{
			Hooking.OnPostFireGun -= OnGunFired;
			if ((Delegate)(object)_beginCameraRenderingCallback != (Delegate)null)
			{
				RenderPipelineManager.beginCameraRendering -= _beginCameraRenderingCallback;
			}
			if ((Delegate)(object)_endCameraRenderingCallback != (Delegate)null)
			{
				RenderPipelineManager.endCameraRendering -= _endCameraRenderingCallback;
			}
			RestoreCameraOffset();
			DestroyOverlay();
			Instance = null;
		}

		private void BuildMenu()
		{
			//IL_000b: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: 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_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			_page = Page.Root.CreatePage("Frozn's Recoil", MenuColor, 0, true);
			Page val = _page.CreatePage("01 · General & Dynamics", GeneralColor, 0, true);
			_enabledElement = val.CreateBool("Recoil Enabled", RecoilColor, _enabled.Value, (Action<bool>)delegate(bool value)
			{
				_enabled.Value = value;
				Save();
			});
			_vignetteElement = val.CreateBool("Comfort Vignette", ComfortColor, _vignetteEnabled.Value, (Action<bool>)delegate(bool value)
			{
				_vignetteEnabled.Value = value;
				Save();
			});
			_dynamicElement = val.CreateBool("Dynamic Recoil", GeneralColor, _dynamicEnabled.Value, (Action<bool>)delegate(bool value)
			{
				_dynamicEnabled.Value = value;
				Save();
			});
			_dynamicIntensityElement = val.CreateFloat("Dynamic Intensity", GeneralColor, _dynamicIntensity.Value, 0.05f, 0f, 2f, (Action<float>)delegate(float value)
			{
				_dynamicIntensity.Value = value;
				Save();
			});
			Page val2 = _page.CreatePage("02 · Presets & Reset", PresetColor, 0, true);
			_globalPresetElement = val2.CreateEnum("All-Guns Preset", PresetColor, (Enum)(RecoilPreset)Mathf.Clamp(_globalPreset.Value, 0, 4), (Action<Enum>)delegate(Enum value)
			{
				_globalPreset.Value = Convert.ToInt32(value);
				Save();
			});
			val2.CreateFunction("Apply Preset To Every Gun", RecoilColor, (Action)ApplyPresetToAll);
			val2.CreateFunction("Apply Light To All", GeneralColor, (Action)delegate
			{
				ApplyPresetToAll(RecoilPreset.Light);
			});
			val2.CreateFunction("Apply Medium To All", GeneralColor, (Action)delegate
			{
				ApplyPresetToAll(RecoilPreset.Medium);
			});
			val2.CreateFunction("Apply Hard To All", RecoilColor, (Action)delegate
			{
				ApplyPresetToAll(RecoilPreset.Hard);
			});
			val2.CreateFunction("Apply Action To All", PresetColor, (Action)delegate
			{
				ApplyPresetToAll(RecoilPreset.Action);
			});
			val2.CreateFunction("Reset All Recoil & Gun Settings", ComfortColor, (Action)ResetAllSettings);
			Page val3 = _page.CreatePage("03 · Weapon Profiles", RecoilColor, 0, true);
			foreach (WeaponClass value in Enum.GetValues(typeof(WeaponClass)))
			{
				AddTuningControls(val3.CreatePage(value.ToString(), MenuColor, 0, true), value);
			}
			_handlingRoot = _page.CreatePage("04 · Gun Handling", new Color(0.95f, 0.68f, 0.24f), 0, true);
			Page val4 = _handlingRoot.CreatePage("Handling Settings", GeneralColor, 0, true);
			_globalReleaseElement = val4.CreateBool("Enable Fast-Fire Rifle/SMG Release", RecoilColor, _oneHandDropEnabled.Value, (Action<bool>)delegate(bool value)
			{
				_oneHandDropEnabled.Value = value;
				Save();
			});
			_defaultReleaseForceElement = val4.CreateFloat("Default Release Force For New Profiles", RecoilColor, _defaultReleaseForce.Value, 0.05f, 0f, 1.5f, (Action<float>)delegate(float value)
			{
				_defaultReleaseForce.Value = value;
				Save();
			});
			val4.CreateFunction("Customize Gun In Hand", ComfortColor, (Action)ConfigureGunInHand);
			val4.CreateFunction("Reset Every Saved Gun Profile", PresetColor, (Action)ResetAllGunProfiles);
			_individualGunRoot = _handlingRoot.CreatePage("Individual Gun Profiles", new Color(0.95f, 0.68f, 0.24f), 0, true);
			_individualGunRoot.CreateFunction("Customize Gun In Hand", ComfortColor, (Action)ConfigureGunInHand);
		}

		private void LoadSavedGunProfiles()
		{
			try
			{
				if (string.IsNullOrWhiteSpace(_gunProfileIndex.Value))
				{
					return;
				}
				List<GunProfileRecord> list = JsonSerializer.Deserialize<List<GunProfileRecord>>(_gunProfileIndex.Value);
				if (list == null)
				{
					return;
				}
				foreach (GunProfileRecord item in list)
				{
					if (item != null && !string.IsNullOrWhiteSpace(item.Id) && !string.IsNullOrWhiteSpace(item.Name))
					{
						WeaponClass weaponClass = (WeaponClass)Mathf.Clamp(item.Type, 0, Enum.GetValues(typeof(WeaponClass)).Length - 1);
						WeaponClass weaponClass2 = Classify(item.Name);
						WeaponClass type = ((weaponClass2 != WeaponClass.Rifle || weaponClass == WeaponClass.Rifle) ? weaponClass2 : weaponClass);
						GetOrCreateGunProfile(item.Id, item.Name, type, saveIndex: false);
					}
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("Could not restore saved individual gun profiles: " + ex.Message);
			}
		}

		private void MigrateReleaseBehavior()
		{
			if (_releaseBehaviorVersion.Value >= 1)
			{
				return;
			}
			foreach (GunProfile value in _gunProfiles.Values)
			{
				if (value.Type == WeaponClass.Pistol)
				{
					value.AllowRelease.Value = false;
				}
				else if (value.Type == WeaponClass.SMG && Mathf.Abs(value.ShotsBeforeRelease.Value - 5f) < 0.01f)
				{
					value.ShotsBeforeRelease.Value = 10f;
				}
				else if (value.Type == WeaponClass.Rifle && Mathf.Abs(value.ShotsBeforeRelease.Value - 4f) < 0.01f)
				{
					value.ShotsBeforeRelease.Value = 8f;
				}
			}
			_releaseBehaviorVersion.Value = 1;
			Save();
		}

		private GunProfile GetGunProfile(Gun gun)
		{
			string name = CleanGunName(((Object)(object)gun != (Object)null) ? ((Object)gun).name : "Unknown Gun");
			WeaponClass type = Classify(name);
			return GetOrCreateGunProfile(GunProfileId(name), name, type, saveIndex: true);
		}

		private GunProfile GetOrCreateGunProfile(string id, string name, WeaponClass type, bool saveIndex)
		{
			if (_gunProfiles.TryGetValue(id, out var value))
			{
				if (value.Type != type)
				{
					float num = DefaultShotsBeforeRelease(value.Type);
					value.Type = type;
					if (Mathf.Abs(value.ShotsBeforeRelease.Value - num) < 0.01f)
					{
						value.ShotsBeforeRelease.Value = DefaultShotsBeforeRelease(type);
					}
					if (type == WeaponClass.Pistol)
					{
						value.AllowRelease.Value = false;
					}
					SaveGunProfileIndex();
				}
				return value;
			}
			Tuning tuning = _tuning[type];
			string text = "Gun_" + id + "_";
			GunProfile gunProfile = new GunProfile();
			gunProfile.Id = id;
			gunProfile.Name = name;
			gunProfile.Type = type;
			gunProfile.Entries = new MelonPreferences_Entry<float>[6]
			{
				_prefs.CreateEntry<float>(text + "Snap", tuning.Snap, (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
				_prefs.CreateEntry<float>(text + "Shake", tuning.Shake, (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
				_prefs.CreateEntry<float>(text + "Recovery", tuning.Recovery, (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
				_prefs.CreateEntry<float>(text + "Vignette", tuning.Vignette, (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
				_prefs.CreateEntry<float>(text + "VignetteDuration", tuning.Duration, (string)null, (string)null, false, false, (ValueValidator)null, (string)null),
				_prefs.CreateEntry<float>(text + "Randomization", tuning.Randomization, (string)null, (string)null, false, false, (ValueValidator)null, (string)null)
			};
			gunProfile.AllowRelease = _prefs.CreateEntry<bool>(text + "AllowRelease", type != WeaponClass.Pistol, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			gunProfile.ShotsBeforeRelease = _prefs.CreateEntry<float>(text + "ShotsBeforeRelease", DefaultShotsBeforeRelease(type), (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			gunProfile.ReleaseForce = _prefs.CreateEntry<float>(text + "ReleaseForce", _defaultReleaseForce.Value, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			gunProfile.HandlingMultiplier = _prefs.CreateEntry<float>(text + "HandlingMultiplier", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			gunProfile.ArmKickForce = _prefs.CreateEntry<float>(text + "ArmKickForce", DefaultArmKick(type), (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			gunProfile.HandlingPreset = _prefs.CreateEntry<int>(text + "HandlingPreset", 2, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			gunProfile.RecoilPreset = _prefs.CreateEntry<int>(text + "RecoilPreset", 0, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			GunProfile gunProfile2 = gunProfile;
			gunProfile2.Tuning = new Tuning
			{
				Snap = gunProfile2.Entries[0].Value,
				Shake = gunProfile2.Entries[1].Value,
				Recovery = gunProfile2.Entries[2].Value,
				Vignette = gunProfile2.Entries[3].Value,
				Duration = gunProfile2.Entries[4].Value,
				Randomization = gunProfile2.Entries[5].Value
			};
			_gunProfiles[id] = gunProfile2;
			if (_individualGunRoot != null)
			{
				AddGunProfilePage(gunProfile2);
			}
			if (saveIndex)
			{
				SaveGunProfileIndex();
			}
			return gunProfile2;
		}

		private void AddGunProfilePage(GunProfile profile)
		{
			//IL_004a: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_045a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			if (_individualGunRoot == null || profile.Page != null)
			{
				return;
			}
			Page val = _individualGunRoot.CreatePage(profile.Name, new Color(0.95f, 0.68f, 0.24f), 0, true);
			profile.Page = val;
			val.CreateFunction("Load Gun Properties", ComfortColor, (Action)delegate
			{
				LoadGunProperties(profile);
			});
			Page val2 = val.CreatePage("01 · Recoil", RecoilColor, 0, true);
			Page val3 = val.CreatePage("02 · Handling", new Color(0.95f, 0.68f, 0.24f), 0, true);
			profile.RecoilPresetElement = val2.CreateEnum("Gun Recoil Preset", PresetColor, (Enum)(RecoilPreset)Mathf.Clamp(profile.RecoilPreset.Value, 0, 4), (Action<Enum>)delegate(Enum value)
			{
				ApplyGunRecoilPreset(profile, (RecoilPreset)(object)value);
			});
			AddTypePresetButtons(val2, profile.Type, delegate(RecoilPreset preset)
			{
				ApplyGunRecoilPreset(profile, preset);
			});
			profile.PresetElement = val3.CreateEnum("Gun Handling Preset", PresetColor, (Enum)(GunHandlingPreset)Mathf.Clamp(profile.HandlingPreset.Value, 0, 4), (Action<Enum>)delegate(Enum value)
			{
				ApplyGunHandlingPreset(profile, (GunHandlingPreset)(object)value);
			});
			if (profile.Type == WeaponClass.Shotgun)
			{
				val3.CreateFunction("One-Hand Shotgun Fire Always Releases", RecoilColor, (Action)delegate
				{
					((MelonBase)this).LoggerInstance.Msg("One-hand shotgun release is always active.");
				});
			}
			else
			{
				profile.ReleaseToggle = val3.CreateBool("Allow This Gun To Release", RecoilColor, profile.AllowRelease.Value, (Action<bool>)delegate(bool value)
				{
					profile.AllowRelease.Value = value;
					Save();
				});
			}
			profile.Sliders = (FloatElement[])(object)new FloatElement[10];
			if (profile.Type != WeaponClass.Shotgun)
			{
				profile.Sliders[0] = val3.CreateFloat("Rapid Shots Before Release", RecoilColor, profile.ShotsBeforeRelease.Value, 1f, 2f, 10f, (Action<float>)delegate(float value)
				{
					SetGunFloat(profile, 6, Mathf.Round(value));
				});
			}
			profile.Sliders[1] = val3.CreateFloat("Release Force", RecoilColor, profile.ReleaseForce.Value, 0.05f, 0f, 1.5f, (Action<float>)delegate(float value)
			{
				SetGunFloat(profile, 7, value);
			});
			val3.CreateFunction("Reset This Gun's Handling", ComfortColor, (Action)delegate
			{
				ResetGunHandling(profile);
			});
			profile.Sliders[2] = val2.CreateFloat("Recoil Scale", GeneralColor, profile.HandlingMultiplier.Value, 0.05f, 0f, 2.5f, (Action<float>)delegate(float value)
			{
				SetGunFloat(profile, 8, value);
			});
			profile.Sliders[3] = val2.CreateFloat("Physical Arm Kick", GeneralColor, profile.ArmKickForce.Value, 0.01f, 0f, 0.8f, (Action<float>)delegate(float value)
			{
				SetGunFloat(profile, 9, value);
			});
			profile.Sliders[4] = val2.CreateFloat("Snap Up", RecoilColor, profile.Tuning.Snap, 0.05f, 0f, 3f, (Action<float>)delegate(float value)
			{
				SetGunFloat(profile, 0, value);
			});
			profile.Sliders[5] = val2.CreateFloat("Camera Shake", new Color(1f, 0.66f, 0.3f), profile.Tuning.Shake, 0.05f, 0f, 2f, (Action<float>)delegate(float value)
			{
				SetGunFloat(profile, 1, value);
			});
			profile.Sliders[6] = val2.CreateFloat("Recovery Speed", GeneralColor, profile.Tuning.Recovery, 0.25f, 1f, 18f, (Action<float>)delegate(float value)
			{
				SetGunFloat(profile, 2, value);
			});
			profile.Sliders[7] = val2.CreateFloat("Vignette Strength", ComfortColor, profile.Tuning.Vignette, 0.05f, 0f, 1f, (Action<float>)delegate(float value)
			{
				SetGunFloat(profile, 3, value);
			});
			profile.Sliders[8] = val2.CreateFloat("Vignette Duration", ComfortColor, profile.Tuning.Duration, 0.05f, 0.05f, 1.5f, (Action<float>)delegate(float value)
			{
				SetGunFloat(profile, 4, value);
			});
			profile.Sliders[9] = val2.CreateFloat("Randomization (± degrees)", PresetColor, profile.Tuning.Randomization, 0.1f, 0f, 5f, (Action<float>)delegate(float value)
			{
				SetGunFloat(profile, 5, value);
			});
			val2.CreateFunction("Reset This Gun's Recoil", ComfortColor, (Action)delegate
			{
				ResetGunRecoil(profile);
			});
		}

		private void LoadGunProperties(GunProfile profile)
		{
			profile.Tuning.Snap = profile.Entries[0].Value;
			profile.Tuning.Shake = profile.Entries[1].Value;
			profile.Tuning.Recovery = profile.Entries[2].Value;
			profile.Tuning.Vignette = profile.Entries[3].Value;
			profile.Tuning.Duration = profile.Entries[4].Value;
			profile.Tuning.Randomization = profile.Entries[5].Value;
			if (profile.Sliders != null)
			{
				if (profile.Sliders[0] != null)
				{
					profile.Sliders[0].Value = profile.ShotsBeforeRelease.Value;
				}
				profile.Sliders[1].Value = profile.ReleaseForce.Value;
				profile.Sliders[2].Value = profile.HandlingMultiplier.Value;
				profile.Sliders[3].Value = profile.ArmKickForce.Value;
				for (int i = 0; i < 6; i++)
				{
					profile.Sliders[i + 4].Value = profile.Entries[i].Value;
				}
			}
			if (profile.ReleaseToggle != null)
			{
				profile.ReleaseToggle.Value = profile.AllowRelease.Value;
			}
			if (profile.PresetElement != null)
			{
				profile.PresetElement.Value = (GunHandlingPreset)Mathf.Clamp(profile.HandlingPreset.Value, 0, 4);
			}
			if (profile.RecoilPresetElement != null)
			{
				profile.RecoilPresetElement.Value = (RecoilPreset)Mathf.Clamp(profile.RecoilPreset.Value, 0, 4);
			}
			((MelonBase)this).LoggerInstance.Msg("Loaded saved gun properties for " + profile.Name + ".");
		}

		private void SetGunFloat(GunProfile profile, int index, float value)
		{
			if (index < 6)
			{
				profile.Entries[index].Value = value;
				switch (index)
				{
				case 0:
					profile.Tuning.Snap = value;
					break;
				case 1:
					profile.Tuning.Shake = value;
					break;
				case 2:
					profile.Tuning.Recovery = value;
					break;
				case 3:
					profile.Tuning.Vignette = value;
					break;
				case 4:
					profile.Tuning.Duration = value;
					break;
				case 5:
					profile.Tuning.Randomization = value;
					break;
				}
			}
			else
			{
				switch (index)
				{
				case 6:
					profile.ShotsBeforeRelease.Value = value;
					break;
				case 7:
					profile.ReleaseForce.Value = value;
					break;
				case 8:
					profile.HandlingMultiplier.Value = value;
					break;
				case 9:
					profile.ArmKickForce.Value = value;
					break;
				}
			}
			if (index < 6 || index >= 8)
			{
				profile.RecoilPreset.Value = 0;
				if (profile.RecoilPresetElement != null)
				{
					profile.RecoilPresetElement.Value = RecoilPreset.Custom;
				}
			}
			else
			{
				profile.HandlingPreset.Value = 0;
				if (profile.PresetElement != null)
				{
					profile.PresetElement.Value = GunHandlingPreset.Custom;
				}
			}
			Save();
		}

		private void ApplyGunHandlingPreset(GunProfile profile, GunHandlingPreset preset)
		{
			profile.HandlingPreset.Value = (int)preset;
			if (preset != GunHandlingPreset.Custom)
			{
				float num = ((profile.Type != WeaponClass.Shotgun) ? (preset switch
				{
					GunHandlingPreset.Controlled => (profile.Type == WeaponClass.Shotgun) ? 1f : ((profile.Type == WeaponClass.Pistol) ? 6f : 10f), 
					GunHandlingPreset.Balanced => DefaultShotsBeforeRelease(profile.Type), 
					GunHandlingPreset.Loose => (profile.Type == WeaponClass.Shotgun) ? 1f : ((profile.Type == WeaponClass.Pistol) ? 4f : 8f), 
					_ => (profile.Type == WeaponClass.Shotgun) ? 1f : ((profile.Type == WeaponClass.Pistol) ? 3f : 6f), 
				}) : 1f);
				float value = num;
				float value2 = preset switch
				{
					GunHandlingPreset.Controlled => 0.3f, 
					GunHandlingPreset.Balanced => 0.6f, 
					GunHandlingPreset.Loose => 0.9f, 
					_ => 1.2f, 
				};
				profile.ShotsBeforeRelease.Value = value;
				profile.ReleaseForce.Value = value2;
				profile.AllowRelease.Value = profile.Type != WeaponClass.Pistol;
				if (profile.Sliders != null)
				{
					if (profile.Sliders[0] != null)
					{
						profile.Sliders[0].Value = value;
					}
					profile.Sliders[1].Value = value2;
				}
				if (profile.ReleaseToggle != null)
				{
					profile.ReleaseToggle.Value = profile.AllowRelease.Value;
				}
			}
			if (profile.PresetElement != null)
			{
				profile.PresetElement.Value = preset;
			}
			Save();
		}

		private void ApplyGunRecoilPreset(GunProfile profile, RecoilPreset preset)
		{
			profile.RecoilPreset.Value = (int)preset;
			if (preset != RecoilPreset.Custom)
			{
				Tuning tuning = Defaults(profile.Type);
				float num = RecoilPresetScale(profile.Type, preset);
				float[] array = new float[6]
				{
					tuning.Snap * num,
					tuning.Shake * num,
					tuning.Recovery / Math.Max(0.5f, num),
					Mathf.Clamp01(tuning.Vignette * (0.9f + num * 0.2f)),
					(preset == RecoilPreset.Action) ? 0.14f : tuning.Duration,
					Mathf.Clamp(tuning.Randomization * num, 0f, 5f)
				};
				profile.Tuning = new Tuning
				{
					Snap = array[0],
					Shake = array[1],
					Recovery = array[2],
					Vignette = array[3],
					Duration = array[4],
					Randomization = array[5]
				};
				for (int i = 0; i < array.Length; i++)
				{
					profile.Entries[i].Value = array[i];
					profile.Sliders[i + 4].Value = array[i];
				}
			}
			if (profile.RecoilPresetElement != null)
			{
				profile.RecoilPresetElement.Value = preset;
			}
			Save();
		}

		private void ResetGunProfile(GunProfile profile)
		{
			ResetGunRecoil(profile);
			ResetGunHandling(profile);
		}

		private void ResetGunRecoil(GunProfile profile)
		{
			Tuning tuning = _tuning[profile.Type];
			float[] array = new float[6] { tuning.Snap, tuning.Shake, tuning.Recovery, tuning.Vignette, tuning.Duration, tuning.Randomization };
			for (int i = 0; i < array.Length; i++)
			{
				profile.Entries[i].Value = array[i];
				profile.Sliders[i + 4].Value = array[i];
			}
			profile.Tuning = new Tuning
			{
				Snap = array[0],
				Shake = array[1],
				Recovery = array[2],
				Vignette = array[3],
				Duration = array[4],
				Randomization = array[5]
			};
			profile.HandlingMultiplier.Value = 1f;
			profile.ArmKickForce.Value = DefaultArmKick(profile.Type);
			profile.Sliders[2].Value = 1f;
			profile.Sliders[3].Value = profile.ArmKickForce.Value;
			profile.RecoilPreset.Value = 0;
			profile.RecoilPresetElement.Value = RecoilPreset.Custom;
			Save();
		}

		private void ResetGunHandling(GunProfile profile)
		{
			profile.AllowRelease.Value = profile.Type != WeaponClass.Pistol;
			profile.ShotsBeforeRelease.Value = DefaultShotsBeforeRelease(profile.Type);
			profile.ReleaseForce.Value = _defaultReleaseForce.Value;
			profile.HandlingPreset.Value = 2;
			if (profile.Sliders[0] != null)
			{
				profile.Sliders[0].Value = profile.ShotsBeforeRelease.Value;
			}
			profile.Sliders[1].Value = profile.ReleaseForce.Value;
			if (profile.ReleaseToggle != null)
			{
				profile.ReleaseToggle.Value = profile.AllowRelease.Value;
			}
			profile.PresetElement.Value = GunHandlingPreset.Balanced;
			Save();
		}

		private void ResetAllGunProfiles()
		{
			GunProfile[] array = _gunProfiles.Values.ToArray();
			foreach (GunProfile profile in array)
			{
				ResetGunProfile(profile);
			}
			_shotsSinceRelease.Clear();
			Save();
		}

		private void SaveGunProfileIndex()
		{
			_gunProfileIndex.Value = JsonSerializer.Serialize(_gunProfiles.Values.Select((GunProfile profile) => new GunProfileRecord
			{
				Id = profile.Id,
				Name = profile.Name,
				Type = (int)profile.Type
			}).ToList());
			Save();
		}

		private static float DefaultShotsBeforeRelease(WeaponClass type)
		{
			return type switch
			{
				WeaponClass.Shotgun => 1f, 
				WeaponClass.SMG => 10f, 
				WeaponClass.Rifle => 8f, 
				_ => 4f, 
			};
		}

		private static float DefaultArmKick(WeaponClass type)
		{
			return type switch
			{
				WeaponClass.Pistol => 0.025f, 
				WeaponClass.SMG => 0.035f, 
				WeaponClass.Rifle => 0.05f, 
				_ => 0.075f, 
			};
		}

		private static float RecoilPresetScale(WeaponClass type, RecoilPreset preset)
		{
			if (preset == RecoilPreset.Custom)
			{
				return 1f;
			}
			return type switch
			{
				WeaponClass.Pistol => preset switch
				{
					RecoilPreset.Light => 0.52f, 
					RecoilPreset.Medium => 0.75f, 
					RecoilPreset.Hard => 1.05f, 
					RecoilPreset.Action => 0.92f, 
					_ => 1f, 
				}, 
				WeaponClass.SMG => preset switch
				{
					RecoilPreset.Light => 0.5f, 
					RecoilPreset.Medium => 0.76f, 
					RecoilPreset.Hard => 1.02f, 
					RecoilPreset.Action => 0.9f, 
					_ => 1f, 
				}, 
				WeaponClass.Rifle => preset switch
				{
					RecoilPreset.Light => 0.48f, 
					RecoilPreset.Medium => 0.72f, 
					RecoilPreset.Hard => 1f, 
					RecoilPreset.Action => 0.88f, 
					_ => 1f, 
				}, 
				_ => preset switch
				{
					RecoilPreset.Light => 0.42f, 
					RecoilPreset.Medium => 0.7f, 
					RecoilPreset.Hard => 1.28f, 
					RecoilPreset.Action => 1.1f, 
					_ => 1f, 
				}, 
			};
		}

		private static string CleanGunName(string name)
		{
			if (!string.IsNullOrWhiteSpace(name))
			{
				return name.Replace("(Clone)", "").Trim();
			}
			return "Unknown Gun";
		}

		private static string GunProfileId(string name)
		{
			return new string((from character in CleanGunName(name).ToLowerInvariant()
				select (!char.IsLetterOrDigit(character)) ? '_' : character).ToArray()).Trim('_');
		}

		private static Gun FindHeldGun()
		{
			Hand[] array = (Hand[])(object)new Hand[2]
			{
				Player.LeftHand,
				Player.RightHand
			};
			foreach (Hand val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				try
				{
					GameObject objectInHand = Player.GetObjectInHand(val);
					if (!((Object)(object)objectInHand == (Object)null))
					{
						Gun val2 = objectInHand.GetComponent<Gun>() ?? objectInHand.GetComponentInChildren<Gun>() ?? objectInHand.GetComponentInParent<Gun>();
						if ((Object)(object)val2 != (Object)null)
						{
							return val2;
						}
					}
				}
				catch
				{
				}
			}
			return null;
		}

		private void ConfigureGunInHand()
		{
			Gun val = FindHeldGun();
			if ((Object)(object)val == (Object)null)
			{
				((MelonBase)this).LoggerInstance.Warning("Hold a gun, then select Customize Gun In Hand in the Gun Handling menu.");
				return;
			}
			GunProfile gunProfile = GetGunProfile(val);
			AddGunProfilePage(gunProfile);
			((MelonBase)this).LoggerInstance.Msg("Opened saved handling and recoil properties for " + gunProfile.Name + ".");
		}

		private static void MigrateSavedPreset(WeaponClass type, MelonPreferences_Entry<float>[] entries)
		{
			float num = type switch
			{
				WeaponClass.Pistol => 0.7f, 
				WeaponClass.SMG => 0.8f, 
				WeaponClass.Rifle => 1f, 
				_ => 1.4f, 
			};
			float[] array = new float[5] { 1f, 0.43f, 0.94f, 1.38f, 1.15f };
			RecoilPreset[] array2 = new RecoilPreset[5]
			{
				RecoilPreset.Custom,
				RecoilPreset.Light,
				RecoilPreset.Medium,
				RecoilPreset.Hard,
				RecoilPreset.Action
			};
			for (int i = 0; i < array.Length; i++)
			{
				float num2 = array[i];
				float[] array3 = new float[6]
				{
					0.94f * num * num2,
					0.42f * num * num2,
					7f / Math.Max(0.5f, num2),
					Mathf.Clamp01(0.95f * (0.9f + num2 * 0.2f)),
					(array2[i] == RecoilPreset.Action) ? 0.14f : 0.2f,
					Mathf.Clamp(2f * num * num2, 0f, 5f)
				};
				bool flag = true;
				for (int j = 0; j < array3.Length; j++)
				{
					if (Mathf.Abs(entries[j].Value - array3[j]) > 0.035f)
					{
						flag = false;
						break;
					}
				}
				if (flag)
				{
					Tuning tuning = Defaults(type);
					float num3 = RecoilPresetScale(type, array2[i]);
					float[] array4 = new float[6]
					{
						tuning.Snap * num3,
						tuning.Shake * num3,
						tuning.Recovery / Math.Max(0.5f, num3),
						Mathf.Clamp01(tuning.Vignette * (0.9f + num3 * 0.2f)),
						(array2[i] == RecoilPreset.Action) ? 0.14f : tuning.Duration,
						Mathf.Clamp(tuning.Randomization * num3, 0f, 5f)
					};
					for (int k = 0; k < array4.Length; k++)
					{
						entries[k].Value = array4[k];
					}
					break;
				}
			}
		}

		private void AddTuningControls(Page page, WeaponClass type)
		{
			//IL_0052: 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)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: 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_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: 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_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			Tuning tuning = _tuning[type];
			Color val = (Color)(type switch
			{
				WeaponClass.Pistol => new Color(0.45f, 0.8f, 1f), 
				WeaponClass.SMG => new Color(0.45f, 1f, 0.65f), 
				WeaponClass.Rifle => new Color(1f, 0.66f, 0.3f), 
				_ => new Color(1f, 0.38f, 0.38f), 
			});
			page.CreateEnum("Profile Preset", PresetColor, (Enum)RecoilPreset.Medium, (Action<Enum>)delegate(Enum value)
			{
				ApplyPreset(type, (RecoilPreset)(object)value);
			});
			AddTypePresetButtons(page, type, delegate(RecoilPreset preset)
			{
				ApplyPreset(type, preset);
			});
			_sliders[type] = (FloatElement[])(object)new FloatElement[6]
			{
				page.CreateFloat("Snap Up", RecoilColor, tuning.Snap, 0.05f, 0f, 3f, (Action<float>)delegate(float value)
				{
					Set(type, 0, value);
				}),
				page.CreateFloat("Camera Shake", val, tuning.Shake, 0.05f, 0f, 2f, (Action<float>)delegate(float value)
				{
					Set(type, 1, value);
				}),
				page.CreateFloat("Recovery Speed", GeneralColor, tuning.Recovery, 0.25f, 1f, 18f, (Action<float>)delegate(float value)
				{
					Set(type, 2, value);
				}),
				page.CreateFloat("Vignette Strength", ComfortColor, tuning.Vignette, 0.05f, 0f, 1f, (Action<float>)delegate(float value)
				{
					Set(type, 3, value);
				}),
				page.CreateFloat("Vignette Duration", ComfortColor, tuning.Duration, 0.05f, 0.05f, 1.5f, (Action<float>)delegate(float value)
				{
					Set(type, 4, value);
				}),
				page.CreateFloat("Randomization (± degrees)", PresetColor, tuning.Randomization, 0.1f, 0f, 5f, (Action<float>)delegate(float value)
				{
					Set(type, 5, value);
				})
			};
		}

		private static void AddTypePresetButtons(Page page, WeaponClass type, Action<RecoilPreset> apply)
		{
			//IL_0027: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			Color val = (Color)((type == WeaponClass.Shotgun) ? new Color(1f, 0.38f, 0.38f) : PresetColor);
			page.CreateFunction($"Quick Apply {type}Light", val, (Action)delegate
			{
				apply(RecoilPreset.Light);
			});
			page.CreateFunction($"Quick Apply {type}Medium", val, (Action)delegate
			{
				apply(RecoilPreset.Medium);
			});
			page.CreateFunction($"Quick Apply {type}Hard", val, (Action)delegate
			{
				apply(RecoilPreset.Hard);
			});
			page.CreateFunction($"Quick Apply {type}Action", val, (Action)delegate
			{
				apply(RecoilPreset.Action);
			});
		}

		private void Set(WeaponClass type, int index, float value)
		{
			_entries[type][index].Value = value;
			Tuning tuning = _tuning[type];
			switch (index)
			{
			case 0:
				tuning.Snap = value;
				break;
			case 1:
				tuning.Shake = value;
				break;
			case 2:
				tuning.Recovery = value;
				break;
			case 3:
				tuning.Vignette = value;
				break;
			case 4:
				tuning.Duration = value;
				break;
			case 5:
				tuning.Randomization = value;
				break;
			}
			Save();
		}

		private void ApplyPreset(WeaponClass type, RecoilPreset preset)
		{
			if (ApplyPresetValues(type, preset))
			{
				GunProfile[] array = _gunProfiles.Values.Where((GunProfile gunProfile) => gunProfile.Type == type).ToArray();
				foreach (GunProfile profile in array)
				{
					ApplyGunRecoilPreset(profile, preset);
				}
				Save();
				((MelonBase)this).LoggerInstance.Msg($"Applied {preset} preset to {type}.");
			}
		}

		private bool ApplyPresetValues(WeaponClass type, RecoilPreset preset)
		{
			if (preset == RecoilPreset.Custom)
			{
				return false;
			}
			float num = RecoilPresetScale(type, preset);
			Tuning tuning = Defaults(type);
			Tuning tuning2 = _tuning[type];
			tuning2.Snap = tuning.Snap * num;
			tuning2.Shake = tuning.Shake * num;
			tuning2.Recovery = tuning.Recovery / Math.Max(0.5f, num);
			tuning2.Vignette = Mathf.Clamp01(tuning.Vignette * (0.9f + num * 0.2f));
			tuning2.Duration = ((preset == RecoilPreset.Action) ? 0.14f : tuning.Duration);
			tuning2.Randomization = Mathf.Clamp(tuning.Randomization * num, 0f, 5f);
			for (int i = 0; i < 6; i++)
			{
				MelonPreferences_Entry<float> val = _entries[type][i];
				val.Value = i switch
				{
					0 => tuning2.Snap, 
					1 => tuning2.Shake, 
					2 => tuning2.Recovery, 
					3 => tuning2.Vignette, 
					4 => tuning2.Duration, 
					_ => tuning2.Randomization, 
				};
			}
			for (int j = 0; j < 6; j++)
			{
				_sliders[type][j].Value = _entries[type][j].Value;
			}
			return true;
		}

		private void ApplyPresetToAll()
		{
			ApplyPresetToAll((RecoilPreset)Mathf.Clamp(_globalPreset.Value, 0, 4));
		}

		private void ApplyPresetToAll(RecoilPreset preset)
		{
			if (preset == RecoilPreset.Custom)
			{
				return;
			}
			_globalPreset.Value = (int)preset;
			_globalPresetElement.Value = preset;
			foreach (WeaponClass value in Enum.GetValues(typeof(WeaponClass)))
			{
				ApplyPresetValues(value, preset);
			}
			GunProfile[] array = _gunProfiles.Values.ToArray();
			foreach (GunProfile profile in array)
			{
				ApplyGunRecoilPreset(profile, preset);
			}
			Save();
			((MelonBase)this).LoggerInstance.Msg($"Applied {preset} preset to all gun classes.");
		}

		private void ResetAllSettings()
		{
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			_enabled.Value = true;
			_vignetteEnabled.Value = true;
			_dynamicEnabled.Value = true;
			_dynamicIntensity.Value = 1f;
			_oneHandDropEnabled.Value = true;
			_defaultReleaseForce.Value = 0.6f;
			_globalPreset.Value = 2;
			_enabledElement.Value = true;
			_vignetteElement.Value = true;
			_dynamicElement.Value = true;
			_dynamicIntensityElement.Value = 1f;
			_globalReleaseElement.Value = true;
			_defaultReleaseForceElement.Value = 0.6f;
			_globalPresetElement.Value = RecoilPreset.Medium;
			foreach (WeaponClass value in Enum.GetValues(typeof(WeaponClass)))
			{
				Tuning tuning = Defaults(value);
				Tuning tuning2 = _tuning[value];
				tuning2.Snap = tuning.Snap;
				tuning2.Shake = tuning.Shake;
				tuning2.Recovery = tuning.Recovery;
				tuning2.Vignette = tuning.Vignette;
				tuning2.Duration = tuning.Duration;
				tuning2.Randomization = tuning.Randomization;
				float[] array = new float[6] { tuning2.Snap, tuning2.Shake, tuning2.Recovery, tuning2.Vignette, tuning2.Duration, tuning2.Randomization };
				for (int i = 0; i < array.Length; i++)
				{
					_entries[value][i].Value = array[i];
					_sliders[value][i].Value = array[i];
				}
			}
			_rotationKick = Vector3.zero;
			_vignetteAlpha = 0f;
			_vignetteTimer = 0f;
			GunProfile[] array2 = _gunProfiles.Values.ToArray();
			foreach (GunProfile profile in array2)
			{
				ResetGunProfile(profile);
			}
			_shotsSinceRelease.Clear();
			_shotStreaks.Clear();
			_lastShotTimes.Clear();
			_lastReleaseShotTimes.Clear();
			Save();
			((MelonBase)this).LoggerInstance.Msg("All recoil and comfort settings reset to defaults.");
		}

		private static Tuning Defaults(WeaponClass type)
		{
			return type switch
			{
				WeaponClass.Pistol => new Tuning
				{
					Snap = 0.48f,
					Shake = 0.22f,
					Recovery = 15f,
					Vignette = 0.48f,
					Duration = 0.14f,
					Randomization = 1.35f
				}, 
				WeaponClass.SMG => new Tuning
				{
					Snap = 0.52f,
					Shake = 0.27f,
					Recovery = 13f,
					Vignette = 0.48f,
					Duration = 0.16f,
					Randomization = 1.65f
				}, 
				WeaponClass.Rifle => new Tuning
				{
					Snap = 0.69f,
					Shake = 0.32f,
					Recovery = 11f,
					Vignette = 0.5f,
					Duration = 0.18f,
					Randomization = 1.9f
				}, 
				_ => new Tuning
				{
					Snap = 0.93f,
					Shake = 0.38f,
					Recovery = 9f,
					Vignette = 0.54f,
					Duration = 0.22f,
					Randomization = 2.1f
				}, 
			};
		}

		private static T LegacyValue<T>(string name, T fallback)
		{
			if (!MelonPreferences.HasEntry("BodyCamRecoil", name))
			{
				return fallback;
			}
			return MelonPreferences.GetEntryValue<T>("BodyCamRecoil", name);
		}

		private void MigrateLegacyCategory()
		{
			try
			{
				MelonPreferences.Save();
				MelonPreferences.RemoveCategoryFromFile(Path.Combine(MelonEnvironment.UserDataDirectory, "MelonPreferences.cfg"), "BodyCamRecoil");
				((MelonBase)this).LoggerInstance.Msg("Migrated existing recoil settings to the Frozn's Recoil category.");
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("Could not remove the old settings section: " + ex.Message);
			}
		}

		private void Save()
		{
			MelonPreferences.Save();
		}

		private void OnGunFired(Gun gun)
		{
			if ((Object)(object)gun == (Object)null || !IsHeldByLocalPlayer(gun))
			{
				return;
			}
			GunProfile gunProfile = GetGunProfile(gun);
			Tuning tuning = gunProfile.Tuning;
			TryReleaseGun(gun, gunProfile);
			float num = TrackShotCadence(gun);
			float num2 = (_dynamicEnabled.Value ? GetDynamicScale(gun) : 1f);
			float num3 = (_dynamicEnabled.Value ? Mathf.Clamp(_dynamicIntensity.Value, 0f, 2f) : 0f);
			num2 = Mathf.Clamp(1f + (num2 - 1f) * num3, 0.45f, 3f);
			_recoveryRate = tuning.Recovery;
			if (!_firstShotLogged)
			{
				((MelonBase)this).LoggerInstance.Msg("Local player gunfire detected (" + ((Object)gun).name + "); applying rotational recoil.");
				_firstShotLogged = true;
			}
			if (_enabled.Value)
			{
				float num4 = tuning.Snap * num2 * gunProfile.HandlingMultiplier.Value * num;
				float num5 = ((num4 > 0f) ? Mathf.Clamp(tuning.Randomization * Mathf.Lerp(1f, num2, 0.8f), 0f, 5f) : 0f);
				float num6 = ((num4 > 0f) ? Mathf.Clamp(Mathf.Min(num4 * 5.8f, 6.5f) + Random.Range(0f - num5, num5), 0.15f, 6.5f) : 0f);
				if (num6 > 0f)
				{
					_rotationKick.x = Mathf.Max(_rotationKick.x - num6, -11f);
				}
				_rotationKick.y = Mathf.Clamp(_rotationKick.y + Random.Range(0f - num5, num5), -8f, 8f);
				_rotationKick.z = Mathf.Clamp(_rotationKick.z + Random.Range(0f - num5, num5) * (0.4f + tuning.Shake), -6f, 6f);
				TryApplyArmKick(gun, gunProfile, num2, num);
			}
			if (_vignetteEnabled.Value && tuning.Vignette > 0f)
			{
				_vignetteAlpha = Mathf.Max(_vignetteAlpha, Mathf.Clamp01(tuning.Vignette * 1.7f));
				_vignetteTimer = tuning.Duration;
			}
		}

		private float TrackShotCadence(Gun gun)
		{
			int instanceID = ((Object)gun).GetInstanceID();
			float unscaledTime = Time.unscaledTime;
			_trackedReleaseGuns[instanceID] = gun;
			if (_lastShotTimes.TryGetValue(instanceID, out var value) && unscaledTime - value <= 0.65f)
			{
				_shotStreaks[instanceID] = ((!_shotStreaks.TryGetValue(instanceID, out var value2)) ? 1 : value2) + 1;
			}
			else
			{
				_shotStreaks[instanceID] = 1;
			}
			_lastShotTimes[instanceID] = unscaledTime;
			return 1f + Mathf.Min((float)(_shotStreaks[instanceID] - 1) * 0.065f, 0.52f);
		}

		private float GetDynamicScale(Gun gun)
		{
			//IL_0075: 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_007e: 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)
			WeaponClass weaponClass = Classify(((Object)gun).name);
			float num = ((!IsHeldByLocalHand(gun, Player.LeftHand) || !IsHeldByLocalHand(gun, Player.RightHand)) ? (weaponClass switch
			{
				WeaponClass.Pistol => 1.05f, 
				WeaponClass.SMG => 1.35f, 
				WeaponClass.Rifle => 1.5f, 
				_ => 1.7f, 
			}) : 0.9f);
			float num2 = num;
			Vector3 forward = ((Component)gun).transform.forward;
			float num3 = Mathf.Asin(Mathf.Clamp(Vector3.Dot(((Vector3)(ref forward)).normalized, Vector3.up), -1f, 1f)) * 57.29578f;
			float num4 = ((Mathf.Abs(num3) <= 12f) ? 0.78f : (1f + Mathf.Clamp01((Mathf.Abs(num3) - 12f) / 45f) * 0.62f));
			return Mathf.Clamp(num2 * num4 * _movement switch
			{
				PlayerMovement.Crouching => 0.82f, 
				PlayerMovement.Walking => 1.18f, 
				PlayerMovement.Running => 1.48f, 
				PlayerMovement.Jumping => 1.72f, 
				_ => 0.92f, 
			}, 0.55f, 3f);
		}

		private void TryReleaseGun(Gun gun, GunProfile profile)
		{
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			bool num = IsPistolName(((Object)gun).name) || profile.Type == WeaponClass.Pistol;
			bool flag = Classify(((Object)gun).name) == WeaponClass.Shotgun || profile.Type == WeaponClass.Shotgun;
			if ((num && !profile.AllowRelease.Value) || (!flag && (!_oneHandDropEnabled.Value || !profile.AllowRelease.Value)))
			{
				return;
			}
			int instanceID = ((Object)gun).GetInstanceID();
			Hand val;
			if (IsHeldByLocalHand(gun, Player.LeftHand))
			{
				if (IsHeldByLocalHand(gun, Player.RightHand))
				{
					_shotsSinceRelease[instanceID] = 0;
					_lastReleaseShotTimes.Remove(instanceID);
					return;
				}
				val = Player.LeftHand;
			}
			else
			{
				if (!IsHeldByLocalHand(gun, Player.RightHand))
				{
					return;
				}
				val = Player.RightHand;
			}
			float unscaledTime = Time.unscaledTime;
			_trackedReleaseGuns[instanceID] = gun;
			int num2;
			if (flag)
			{
				num2 = 1;
				_shotsSinceRelease[instanceID] = 1;
			}
			else
			{
				float value;
				float num3 = (_lastReleaseShotTimes.TryGetValue(instanceID, out value) ? (unscaledTime - value) : float.MaxValue);
				num2 = ((!(num3 <= 0.32f) || !_shotsSinceRelease.TryGetValue(instanceID, out var value2)) ? 1 : (value2 + 1));
				_shotsSinceRelease[instanceID] = num2;
				_lastReleaseShotTimes[instanceID] = unscaledTime;
				int num4 = Mathf.Clamp(Mathf.RoundToInt(profile.ShotsBeforeRelease.Value), 1, 10);
				if (num3 > 0.32f || num2 < num4)
				{
					return;
				}
			}
			try
			{
				if (!val.HasAttachedObject())
				{
					return;
				}
				Grip val2 = (((Object)(object)val.AttachedReceiver != (Object)null) ? ((Il2CppObjectBase)val.AttachedReceiver).TryCast<Grip>() : null);
				if (!((Object)(object)val2 == (Object)null))
				{
					Rigidbody val3 = FindGunRigidbody(gun);
					val2.ForceDetach(true);
					if ((Object)(object)val3 != (Object)null && profile.ReleaseForce.Value > 0f)
					{
						Vector3 val4 = ((Component)gun).transform.forward + Vector3.up * 0.25f;
						Vector3 normalized = ((Vector3)(ref val4)).normalized;
						val3.AddForce(normalized * Mathf.Clamp(profile.ReleaseForce.Value, 0f, 1.5f), (ForceMode)1);
					}
					_shotsSinceRelease[instanceID] = 0;
					_lastReleaseShotTimes.Remove(instanceID);
					((MelonBase)this).LoggerInstance.Msg($"Released {profile.Name} after {num2} one-hand shot(s).");
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("Could not release " + profile.Name + ": " + ex.Message);
			}
		}

		private static Rigidbody FindGunRigidbody(Gun gun)
		{
			if ((Object)(object)gun == (Object)null)
			{
				return null;
			}
			Transform val = (((Object)(object)Player.RigManager != (Object)null) ? ((Component)Player.RigManager).transform : null);
			Transform val2 = ((Component)gun).transform;
			while ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)val)
			{
				Rigidbody component = ((Component)val2).GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null)
				{
					return component;
				}
				val2 = val2.parent;
			}
			return ((Component)gun).GetComponentInChildren<Rigidbody>();
		}

		private static void TryApplyArmKick(Gun gun, GunProfile profile, float dynamicScale, float cadenceScale)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			if (!(profile.ArmKickForce.Value <= 0f))
			{
				Rigidbody val = FindGunRigidbody(gun);
				if (!((Object)(object)val == (Object)null))
				{
					Vector3 val2 = -((Component)gun).transform.forward + Vector3.up * 0.3f;
					Vector3 normalized = ((Vector3)(ref val2)).normalized;
					val.AddForce(normalized * profile.ArmKickForce.Value * dynamicScale * cadenceScale, (ForceMode)1);
				}
			}
		}

		private static bool IsHeldByLocalPlayer(Gun gun)
		{
			if ((Object)(object)gun == (Object)null)
			{
				return false;
			}
			if (!IsHeldByLocalHand(gun, Player.LeftHand))
			{
				return IsHeldByLocalHand(gun, Player.RightHand);
			}
			return true;
		}

		private static bool IsHeldByLocalHand(Gun gun, Hand hand)
		{
			if ((Object)(object)hand == (Object)null)
			{
				return false;
			}
			GameObject objectInHand = Player.GetObjectInHand(hand);
			if ((Object)(object)objectInHand == (Object)null)
			{
				return false;
			}
			Transform transform = ((Component)gun).transform;
			Transform transform2 = objectInHand.transform;
			if (!((Object)(object)transform == (Object)(object)transform2) && !transform.IsChildOf(transform2))
			{
				return transform2.IsChildOf(transform);
			}
			return true;
		}

		private static WeaponClass Classify(string name)
		{
			string text = (name ?? string.Empty).ToLowerInvariant();
			if (text.Contains("shotgun") || text.Contains("shot gun") || text.Contains("shotty") || text.Contains("spas") || text.Contains("mossberg") || text.Contains("benelli") || text.Contains("870"))
			{
				return WeaponClass.Shotgun;
			}
			if (text.Contains("smg") || text.Contains("submachine") || text.Contains("machine pistol") || text.Contains("mp5") || text.Contains("mp7") || text.Contains("uzi") || text.Contains("p90") || text.Contains("mac10") || text.Contains("vector") || text.Contains("tec9"))
			{
				return WeaponClass.SMG;
			}
			if (IsPistolName(text))
			{
				return WeaponClass.Pistol;
			}
			return WeaponClass.Rifle;
		}

		private static bool IsPistolName(string name)
		{
			string text = (name ?? string.Empty).ToLowerInvariant();
			if (!text.Contains("pistol") && !text.Contains("handgun") && !text.Contains("glock") && !text.Contains("g17") && !text.Contains("g18") && !text.Contains("m9") && !text.Contains("1911") && !text.Contains("revolver") && !text.Contains("beretta") && !text.Contains("deagle") && !text.Contains("desert eagle") && !text.Contains("five seven"))
			{
				return text.Contains("snub");
			}
			return true;
		}

		public override void OnLateUpdate()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp(Time.unscaledDeltaTime, 0f, 0.05f);
			if (num <= 0f)
			{
				return;
			}
			UpdatePlayerMovement(num);
			ResetReleaseCountsForDroppedGuns();
			_cameraSearchTimer -= num;
			float recoveryRate = _recoveryRate;
			_rotationKick = Vector3.Lerp(_rotationKick, Vector3.zero, 1f - Mathf.Exp((0f - recoveryRate) * num));
			_vignetteTimer = Mathf.Max(0f, _vignetteTimer - num);
			_vignetteAlpha = Mathf.MoveTowards(_vignetteAlpha, 0f, num * ((_vignetteTimer > 0f) ? 0.2f : 3f));
			RestoreCameraOffset();
			if (_cameraSearchTimer <= 0f || ((Object)(object)_camera != (Object)null && !((Behaviour)_camera).isActiveAndEnabled))
			{
				_cameraSearchTimer = 0.5f;
				Camera val = FindViewCamera();
				if ((Object)(object)_camera != (Object)(object)val)
				{
					DestroyOverlay();
					_camera = val;
					_cameraTransform = (((Object)(object)_camera != (Object)null) ? ((Component)_camera).transform : null);
					_recoilTarget = (((Object)(object)_cameraTransform != (Object)null && (Object)(object)_cameraTransform.parent != (Object)null) ? _cameraTransform.parent : _cameraTransform);
				}
				if ((Object)(object)_camera != (Object)null)
				{
					_cameraTransform = ((Component)_camera).transform;
					if (!_renderOverrideLogged)
					{
						((MelonBase)this).LoggerInstance.Msg("VR recoil override attached to camera: " + ((Object)_camera).name);
					}
				}
			}
			if (!_standaloneAndroid && (Object)(object)_cameraTransform != (Object)null)
			{
				UpdateOverlay();
			}
		}

		private void ResetReleaseCountsForDroppedGuns()
		{
			KeyValuePair<int, Gun>[] array = _trackedReleaseGuns.ToArray();
			for (int i = 0; i < array.Length; i++)
			{
				KeyValuePair<int, Gun> keyValuePair = array[i];
				try
				{
					if ((Object)(object)keyValuePair.Value != (Object)null && IsHeldByLocalPlayer(keyValuePair.Value))
					{
						continue;
					}
				}
				catch
				{
				}
				_shotsSinceRelease.Remove(keyValuePair.Key);
				_lastReleaseShotTimes.Remove(keyValuePair.Key);
				_trackedReleaseGuns.Remove(keyValuePair.Key);
			}
		}

		private void UpdatePlayerMovement(float dt)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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)
			try
			{
				if ((Object)(object)Player.RigManager == (Object)null || (Object)(object)Player.Head == (Object)null)
				{
					return;
				}
				Vector3 position = ((Component)Player.RigManager).transform.position;
				float num = Player.Head.position.y - position.y;
				if (num > _standingHeadHeight && num < 2.5f)
				{
					_standingHeadHeight = Mathf.Lerp(_standingHeadHeight, num, 0.03f);
				}
				if (!_hasMovementSample)
				{
					_lastRigPosition = position;
					_hasMovementSample = true;
					return;
				}
				Vector3 val = position - _lastRigPosition;
				Vector2 val2 = new Vector2(val.x, val.z);
				_horizontalSpeed = ((Vector2)(ref val2)).magnitude / dt;
				_verticalSpeed = val.y / dt;
				_lastRigPosition = position;
				if (_verticalSpeed > 1.15f)
				{
					_movement = PlayerMovement.Jumping;
				}
				else if (num < _standingHeadHeight * 0.78f)
				{
					_movement = PlayerMovement.Crouching;
				}
				else if (_horizontalSpeed >= 2.2f)
				{
					_movement = PlayerMovement.Running;
				}
				else if (_horizontalSpeed >= 0.25f)
				{
					_movement = PlayerMovement.Walking;
				}
				else
				{
					_movement = PlayerMovement.Still;
				}
			}
			catch
			{
				_movement = PlayerMovement.Still;
			}
		}

		private static Camera FindViewCamera()
		{
			Camera val = null;
			foreach (Camera item in (Il2CppArrayBase<Camera>)(object)Camera.allCameras)
			{
				if (!((Object)(object)item == (Object)null) && ((Behaviour)item).isActiveAndEnabled)
				{
					if (string.Equals(((Object)item).name, "Headset", StringComparison.OrdinalIgnoreCase))
					{
						return item;
					}
					if (item.stereoEnabled)
					{
						val = item;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			return Camera.main;
		}

		private void OnCameraPreRender(Camera camera)
		{
			ApplyCameraKick(camera);
		}

		internal void ApplyCameraKick(Camera camera)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_00c6: 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_00d7: 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_00e7: 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_00f9: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)camera == (Object)null) && _enabled.Value && !((Object)(object)camera != (Object)(object)_camera))
			{
				RestoreCameraOffset();
				_cameraTransform = ((Component)camera).transform;
				_previousRotationOffset = Quaternion.Euler(_rotationKick);
				if ((Object)(object)_recoilTarget == (Object)null || ((Object)(object)_recoilTarget != (Object)(object)_cameraTransform.parent && (Object)(object)_cameraTransform.parent != (Object)null))
				{
					_recoilTarget = (((Object)(object)_cameraTransform.parent != (Object)null) ? _cameraTransform.parent : _cameraTransform);
				}
				_previousTargetRotation = _recoilTarget.rotation;
				_previousTargetPosition = _recoilTarget.position;
				_previousCameraRotation = _cameraTransform.rotation;
				Vector3 position = _cameraTransform.position;
				_recoilTarget.rotation *= _previousRotationOffset;
				Transform recoilTarget = _recoilTarget;
				recoilTarget.position += position - _cameraTransform.position;
				if ((Object)(object)_recoilTarget == (Object)(object)_cameraTransform)
				{
					_cameraTransform.rotation = _previousCameraRotation * _previousRotationOffset;
				}
				_isApplying = true;
				if (!_renderOverrideLogged)
				{
					((MelonBase)this).LoggerInstance.Msg("Applied VR camera rotation on " + ((Object)camera).name + ".");
					_renderOverrideLogged = true;
				}
			}
		}

		private void OnCameraPostRender(Camera camera)
		{
			if ((Object)(object)camera != (Object)null && (Object)(object)((Component)camera).transform == (Object)(object)_cameraTransform)
			{
				RestoreCameraOffset();
			}
		}

		internal void RestoreCameraOffsetFromDriver(Camera camera)
		{
			if ((Object)(object)camera != (Object)null && (Object)(object)camera == (Object)(object)_camera)
			{
				RestoreCameraOffset();
			}
		}

		private void OnBeginCameraRendering(ScriptableRenderContext context, Camera camera)
		{
			try
			{
				OnCameraPreRender(camera);
			}
			catch (Exception ex)
			{
				RestoreCameraOffset();
				((MelonBase)this).LoggerInstance.Warning("Camera recoil was disabled after a render-hook error: " + ex.Message);
				RenderPipelineManager.beginCameraRendering -= _beginCameraRenderingCallback;
				RenderPipelineManager.endCameraRendering -= _endCameraRenderingCallback;
			}
		}

		private void OnEndCameraRendering(ScriptableRenderContext context, Camera camera)
		{
			try
			{
				OnCameraPostRender(camera);
			}
			catch (Exception ex)
			{
				RestoreCameraOffset();
				((MelonBase)this).LoggerInstance.Warning("Camera recoil restore recovered from a render-hook error: " + ex.Message);
			}
		}

		private void RestoreCameraOffset()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if (_isApplying && !((Object)(object)_cameraTransform == (Object)null))
			{
				if ((Object)(object)_recoilTarget != (Object)null)
				{
					_recoilTarget.rotation = _previousTargetRotation;
					_recoilTarget.position = _previousTargetPosition;
				}
				if ((Object)(object)_recoilTarget == (Object)(object)_cameraTransform)
				{
					_cameraTransform.rotation = _previousCameraRotation;
				}
				_isApplying = false;
			}
		}

		private void UpdateOverlay()
		{
			//IL_003d: 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_0052: 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)
			//IL_0062: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_overlay == (Object)null)
			{
				CreateOverlay();
			}
			if (!((Object)(object)_overlay == (Object)null) && !((Object)(object)_overlayMaterial == (Object)null))
			{
				_overlay.SetPositionAndRotation(_cameraTransform.position + _cameraTransform.forward * 0.3f, _cameraTransform.rotation);
				_overlay.localScale = new Vector3(1.15f, 1.15f, 1f);
				_overlayMaterial.color = new Color(1f, 1f, 1f, _vignetteEnabled.Value ? Mathf.Min(_vignetteAlpha, 0.78f) : 0f);
			}
		}

		private void CreateOverlay()
		{
			//IL_0049: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_011b: 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_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Expected O, but got Unknown
			if ((Object)(object)_cameraTransform == (Object)null)
			{
				return;
			}
			try
			{
				GameObject val = GameObject.CreatePrimitive((PrimitiveType)5);
				((Object)val).name = "FroznsRecoil_ComfortVignette";
				val.transform.SetParent(_cameraTransform, false);
				val.transform.localPosition = new Vector3(0f, 0f, 0.3f);
				val.transform.localRotation = Quaternion.identity;
				val.transform.localScale = new Vector3(1.15f, 1.15f, 1f);
				Collider component = val.GetComponent<Collider>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
				_overlayTexture = new Texture2D(64, 64, (TextureFormat)4, false);
				for (int i = 0; i < 64; i++)
				{
					for (int j = 0; j < 64; j++)
					{
						float num = ((float)j - 31.5f) / 31.5f;
						float num2 = ((float)i - 31.5f) / 31.5f;
						float num3 = Mathf.Clamp01((Mathf.Sqrt(num * num + num2 * num2) - 0.22f) / 0.78f);
						_overlayTexture.SetPixel(j, i, new Color(0f, 0f, 0f, Mathf.Pow(num3, 0.68f)));
					}
				}
				_overlayTexture.Apply();
				Renderer component2 = val.GetComponent<Renderer>();
				Shader val2 = Shader.Find("Unlit/Transparent");
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = Shader.Find("Sprites/Default");
				}
				if ((Object)(object)val2 == (Object)null)
				{
					Object.Destroy((Object)(object)val);
					Object.Destroy((Object)(object)_overlayTexture);
					_overlayTexture = null;
				}
				else
				{
					_overlayMaterial = new Material(val2)
					{
						mainTexture = (Texture)(object)_overlayTexture,
						renderQueue = 4000
					};
					component2.material = _overlayMaterial;
					_overlay = val.transform;
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("Could not create comfort vignette: " + ex.Message);
			}
		}

		private void DestroyOverlay()
		{
			if ((Object)(object)_overlay != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_overlay).gameObject);
			}
			if ((Object)(object)_overlayMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)_overlayMaterial);
			}
			if ((Object)(object)_overlayTexture != (Object)null)
			{
				Object.Destroy((Object)(object)_overlayTexture);
			}
			_overlay = null;
			_overlayMaterial = null;
			_overlayTexture = null;
		}
	}
}