using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
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 Pigeon.Math;
using Pigeon.Movement;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("StaticFOV")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("StaticFOV")]
[assembly: AssemblyTitle("StaticFOV")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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;
}
}
}
[HarmonyPatch]
public static class AimFOVPatches
{
[HarmonyPatch(typeof(PlayerLook), "UpdateAiming")]
[HarmonyPrefix]
public static bool UpdateAimingPrefix(PlayerLook __instance)
{
try
{
if (!SparrohPlugin.aimFOVChange.Value && SparrohPlugin.isAimingPLField != null && SparrohPlugin.aimStateChangeTimeField != null && SparrohPlugin.aimDurationPLField != null && SparrohPlugin.aimFOVPLField != null && SparrohPlugin.defaultFOVGetter != null && SparrohPlugin.fovField != null)
{
if ((bool)SparrohPlugin.isAimingPLField.GetValue(__instance))
{
float num = (float)SparrohPlugin.aimStateChangeTimeField.GetValue(__instance);
num = Mathf.Min(num + Time.deltaTime / (float)SparrohPlugin.aimDurationPLField.GetValue(__instance), 1f);
SparrohPlugin.aimStateChangeTimeField.SetValue(__instance, num);
float num2 = (float)SparrohPlugin.defaultFOVGetter.Invoke(__instance, null);
SparrohPlugin.aimFOVPLField.SetValue(__instance, num2);
SparrohPlugin.fovField.SetValue(__instance, Mathf.LerpUnclamped(num2, num2, EaseFunctions.EaseInOutCubic(num)));
}
else if ((float)SparrohPlugin.aimStateChangeTimeField.GetValue(__instance) > 0f)
{
float num3 = (float)SparrohPlugin.aimStateChangeTimeField.GetValue(__instance);
num3 = Mathf.Max(num3 - Time.deltaTime / (float)SparrohPlugin.aimDurationPLField.GetValue(__instance), 0f);
SparrohPlugin.aimStateChangeTimeField.SetValue(__instance, num3);
float num4 = (float)SparrohPlugin.defaultFOVGetter.Invoke(__instance, null);
SparrohPlugin.aimFOVPLField.SetValue(__instance, num4);
SparrohPlugin.fovField.SetValue(__instance, Mathf.LerpUnclamped(num4, num4, EaseFunctions.EaseInOutCubic(num3)));
}
return false;
}
return true;
}
catch (Exception ex)
{
SparrohPlugin.Logger.LogError((object)("Error in UpdateAimingPrefix: " + ex.Message));
return true;
}
}
[HarmonyPatch(typeof(PlayerLook), "UpdateCameraFOV")]
[HarmonyPostfix]
public static void UpdateCameraFOVPostfix(PlayerLook __instance)
{
try
{
if (!SparrohPlugin.aimFOVChange.Value && SparrohPlugin.isAimingPLField != null && SparrohPlugin.fovField != null && SparrohPlugin.defaultFOVGetter != null)
{
object value = SparrohPlugin.isAimingPLField.GetValue(__instance);
bool flag = default(bool);
int num;
if (value is bool)
{
flag = (bool)value;
num = 1;
}
else
{
num = 0;
}
if (((uint)num & (flag ? 1u : 0u)) != 0)
{
SparrohPlugin.fovField.SetValue(__instance, SparrohPlugin.defaultFOVGetter.Invoke(__instance, null));
}
}
}
catch (Exception ex)
{
SparrohPlugin.Logger.LogError((object)("Error in UpdateCameraFOVPostfix: " + ex.Message));
}
}
}
[BepInPlugin("sparroh.staticfov", "StaticFOV", "1.1.0")]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class SparrohPlugin : BaseUnityPlugin
{
public const string PluginGUID = "sparroh.staticfov";
public const string PluginName = "StaticFOV";
public const string PluginVersion = "1.1.0";
internal static ManualLogSource Logger;
internal static ConfigEntry<bool> aimFOVChange;
internal static ConfigEntry<bool> sprintFOVChange;
private FileSystemWatcher configWatcher;
internal static MethodInfo defaultFOVGetter;
internal static FieldInfo isAimingPLField;
internal static FieldInfo fovField;
internal static FieldInfo aimFOVPLField;
internal static FieldInfo aimDurationPLField;
internal static FieldInfo aimStateChangeTimeField;
internal static SparrohPlugin Instance { get; set; }
private void Awake()
{
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
Logger = ((BaseUnityPlugin)this).Logger;
aimFOVChange = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Aim FOV Change", false, "If true, enables FOV zoom changes when aiming.");
sprintFOVChange = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Sprint FOV Change", false, "If true, enables FOV changes while sprinting.");
try
{
SetupFileWatcher();
}
catch (Exception ex)
{
Logger.LogError((object)("Error setting up file watcher: " + ex.Message));
}
try
{
SetupAccessTools();
}
catch (Exception ex2)
{
Logger.LogError((object)("Error setting up access tools: " + ex2.Message));
}
try
{
Harmony val = new Harmony("sparroh.staticfov");
val.PatchAll(typeof(AimFOVPatches));
val.PatchAll(typeof(SprintFOVPatches));
}
catch (Exception ex3)
{
Logger.LogError((object)("Error applying patches: " + ex3.Message));
}
Logger.LogInfo((object)"StaticFOV loaded successfully.");
}
private void SetupFileWatcher()
{
configWatcher = new FileSystemWatcher(Paths.ConfigPath, "sparroh.staticfov.cfg");
configWatcher.Changed += delegate
{
((BaseUnityPlugin)this).Config.Reload();
};
configWatcher.EnableRaisingEvents = true;
}
private void SetupAccessTools()
{
defaultFOVGetter = AccessTools.PropertyGetter(typeof(PlayerLook), "DefaultFOV");
isAimingPLField = AccessTools.Field(typeof(PlayerLook), "isAiming");
fovField = AccessTools.Field(typeof(PlayerLook), "_fov");
aimFOVPLField = AccessTools.Field(typeof(PlayerLook), "aimFOV");
aimDurationPLField = AccessTools.Field(typeof(PlayerLook), "aimDuration");
aimStateChangeTimeField = AccessTools.Field(typeof(PlayerLook), "aimStateChangeTime");
}
private void OnDestroy()
{
if (configWatcher != null)
{
configWatcher.EnableRaisingEvents = false;
configWatcher.Dispose();
}
}
}
[HarmonyPatch]
public static class SprintFOVPatches
{
[HarmonyPatch(typeof(PlayerLook), "AddFOV")]
[HarmonyPrefix]
public static bool Prefix(ref float value)
{
if (SparrohPlugin.sprintFOVChange.Value)
{
return true;
}
StackFrame[] frames = new StackTrace().GetFrames();
for (int i = 0; i < frames.Length; i++)
{
MethodBase method = frames[i].GetMethod();
if (method?.ReflectedType?.Name == "Player" && method.Name.Contains("Update"))
{
return false;
}
}
return true;
}
}
namespace StaticFOV
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "StaticFOV";
public const string PLUGIN_NAME = "StaticFOV";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}