using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using FirstPersonItem;
using GTFO.API.Utilities;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using ZoomFOVScaling.Utils;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ZoomFOVScaling")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d3633742c3cb51f7a24005b7a02f5b4ca4f988a9")]
[assembly: AssemblyProduct("ZoomFOVScaling")]
[assembly: AssemblyTitle("ZoomFOVScaling")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
}
}
}
namespace ZoomFOVScaling
{
internal static class Configuration
{
private static readonly ConfigEntry<float> _baseFOV;
private static readonly ConfigEntry<bool> _fovAffectWeaponZoom;
private static readonly ConfigEntry<bool> _fovAffectWeaponHip;
private static readonly ConfigEntry<bool> _useSensitivityScaling;
private static readonly ConfigEntry<bool> _useCustomSensitivityCurve;
private static readonly ConfigEntry<float> _sensitivityCurveFOVMin;
private static readonly ConfigEntry<float> _sensitivityCurveFOVMax;
private static readonly ConfigEntry<float> _sensitivityCurveSensMin;
private static readonly ConfigEntry<float> _sensitivityCurveSensMax;
private static readonly ConfigFile configFile;
public static float BaseFOV => _baseFOV.Value;
public static bool FOVAffectWeaponZoom => _fovAffectWeaponZoom.Value;
public static bool FOVAffectWeaponHip => _fovAffectWeaponHip.Value;
public static bool UseSensitivityScaling => _useSensitivityScaling.Value;
public static bool UseCustomSensitivityCurve => _useCustomSensitivityCurve.Value;
public static float SensitivityCurveFOVMin => _sensitivityCurveFOVMin.Value;
public static float SensitivityCurveFOVMax => _sensitivityCurveFOVMax.Value;
public static float SensitivityCurveSensMin => _sensitivityCurveSensMin.Value;
public static float SensitivityCurveSensMax => _sensitivityCurveSensMax.Value;
static Configuration()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "ZoomFOVScaling.cfg"), true);
string text = "Field of View Settings";
_baseFOV = configFile.Bind<float>(text, "Base Field of View", 70f, "The field of view considered as 1x zoom.\nFor vanilla behavior, set this to your field of view.");
_fovAffectWeaponZoom = configFile.Bind<bool>(text, "Zoom FOV Affects Weapons", false, "Field of view modifies weapon model field of view while aiming.");
_fovAffectWeaponHip = configFile.Bind<bool>(text, "Hip FOV Affects Weapons", false, "Field of view modifies weapon model field of view while not aiming.");
text = "Sensitivity Settings";
_useSensitivityScaling = configFile.Bind<bool>(text, "Use Sensitivity Scaling", false, "Overrides the base aim sensitivity curve and scales sensitivity by field of view instead.\nIf enabled, recommended to raise Mouse Aim Mode Sensitivity Scaling in-game.");
_useCustomSensitivityCurve = configFile.Bind<bool>(text, "Use Custom Sensitivity Curve", false, "Changes the base aim sensitivity curve to use the values below.\nThe curve scales linearly between minimum and maximum values.\nSensitivity Scaling overrides this.");
_sensitivityCurveFOVMin = configFile.Bind<float>(text, "Sensitivity Curve FOV Min", 10f, "The field of view at or below which minimum sensitivity applies.");
_sensitivityCurveFOVMax = configFile.Bind<float>(text, "Sensitivity Curve FOV Max", 40f, "The field of view at or above which maximum sensitivity applies.");
_sensitivityCurveSensMin = configFile.Bind<float>(text, "Sensitivity Curve Scalar Min", 0.2f, "The scalar applied to sensitivity when field of view is at the minimum value.");
_sensitivityCurveSensMax = configFile.Bind<float>(text, "Sensitivity Curve Scalar Max", 1f, "The scalar applied to sensitivity when field of view is at the maximum value.");
BoundValues();
}
internal static void Init()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
LiveEdit.CreateListener(Paths.ConfigPath, "ZoomFOVScaling.cfg", false).FileChanged += new LiveEditEventHandler(OnFileChanged);
}
private static void OnFileChanged(LiveEditEventArgs _)
{
configFile.Reload();
BoundValues();
}
private static void BoundValues()
{
_baseFOV.Value = Math.Max(_baseFOV.Value, 1f);
if (_sensitivityCurveFOVMax.Value < _sensitivityCurveFOVMin.Value)
{
ConfigEntry<float> sensitivityCurveFOVMax = _sensitivityCurveFOVMax;
ConfigEntry<float> sensitivityCurveFOVMin = _sensitivityCurveFOVMin;
float value = _sensitivityCurveFOVMin.Value;
float value2 = _sensitivityCurveFOVMax.Value;
sensitivityCurveFOVMax.Value = value;
sensitivityCurveFOVMin.Value = value2;
}
}
}
[BepInPlugin("Dinorush.ZoomFOVScaling", "ZoomFOVScaling", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal sealed class EntryPoint : BasePlugin
{
public const string MODNAME = "ZoomFOVScaling";
public override void Load()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
((BasePlugin)this).Log.LogMessage((object)"Loading ZoomFOVScaling");
Configuration.Init();
new Harmony("ZoomFOVScaling").PatchAll();
((BasePlugin)this).Log.LogMessage((object)"Loaded ZoomFOVScaling");
}
}
}
namespace ZoomFOVScaling.Utils
{
internal static class DinoLogger
{
private static ManualLogSource logger = Logger.CreateLogSource("ZoomFOVScaling");
public static void Log(string format, params object[] args)
{
Log(string.Format(format, args));
}
public static void Log(string str)
{
if (logger != null)
{
logger.Log((LogLevel)8, (object)str);
}
}
public static void Warning(string format, params object[] args)
{
Warning(string.Format(format, args));
}
public static void Warning(string str)
{
if (logger != null)
{
logger.Log((LogLevel)4, (object)str);
}
}
public static void Error(string format, params object[] args)
{
Error(string.Format(format, args));
}
public static void Error(string str)
{
if (logger != null)
{
logger.Log((LogLevel)2, (object)str);
}
}
public static void Debug(string format, params object[] args)
{
Debug(string.Format(format, args));
}
public static void Debug(string str)
{
if (logger != null)
{
logger.Log((LogLevel)32, (object)str);
}
}
}
internal static class FloatExtensions
{
public static float Map(this float orig, float fromMin, float fromMax, float toMin, float toMax)
{
if (fromMin == fromMax)
{
if (!(orig < fromMin))
{
return toMax;
}
return toMin;
}
orig = Mathf.Clamp(orig, fromMin, fromMax);
return (orig - fromMin) / (fromMax - fromMin) * (toMax - toMin) + toMin;
}
}
}
namespace ZoomFOVScaling.Patches
{
[HarmonyPatch]
internal static class SensitivityPatch
{
[HarmonyPatch(typeof(FPIS_Aim), "Enter")]
[HarmonyWrapSafe]
[HarmonyPostfix]
private static void Post_AimEnter(FPIS_Aim __instance)
{
if (Configuration.UseSensitivityScaling)
{
((LerpingPair<float>)(object)((FPItemState)__instance).Holder.MouseLookSpeed).Target = ((LerpingPair<float>)(object)((FPItemState)__instance).Holder.LookCamFov).Target / (float)CellSettingsManager.SettingsData.Video.Fov.Value * CellSettingsManager.SettingsData.Gameplay.LookSpeedAiming.Value;
}
else if (Configuration.UseCustomSensitivityCurve)
{
((LerpingPair<float>)(object)((FPItemState)__instance).Holder.MouseLookSpeed).Target = ((LerpingPair<float>)(object)((FPItemState)__instance).Holder.LookCamFov).Target.Map(Configuration.SensitivityCurveFOVMin, Configuration.SensitivityCurveFOVMax, Configuration.SensitivityCurveSensMin, Configuration.SensitivityCurveSensMax) * CellSettingsManager.SettingsData.Gameplay.LookSpeedAiming.Value;
}
}
}
[HarmonyPatch(typeof(ItemEquippable))]
internal static class ZoomPatch
{
[HarmonyPatch("GetWorldCameraZoomFov")]
[HarmonyPostfix]
private static void Post_GetZoomFOV(ref float __result)
{
__result = __result / Configuration.BaseFOV * (float)CellSettingsManager.SettingsData.Video.Fov.Value;
}
[HarmonyPatch("GetItemFovZoom")]
[HarmonyPostfix]
private static void Post_GetItemZoomFOV(ref float __result)
{
if (Configuration.FOVAffectWeaponZoom)
{
__result = __result / Configuration.BaseFOV * (float)CellSettingsManager.SettingsData.Video.Fov.Value;
}
}
[HarmonyPatch("GetItemFovNormal")]
[HarmonyPostfix]
private static void Post_GetItemFOV(ref float __result)
{
if (Configuration.FOVAffectWeaponHip)
{
__result = __result / Configuration.BaseFOV * (float)CellSettingsManager.SettingsData.Video.Fov.Value;
}
}
}
}