Decompiled source of SteadyVisionBoost v1.0.1

plugins/SteadyVisionBoost.dll

Decompiled 15 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SteadyVisionBoost.Patches;
using UnityEngine;
using Zorro.Settings;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyVersion("0.0.0.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 SteadyVisionBoost
{
	internal static class GameFovSettings
	{
		private static FovSetting _fov;

		private static ExtraFovSetting _extra;

		public static float Fov
		{
			get
			{
				if (_fov == null)
				{
					SettingsHandler instance = SettingsHandler.Instance;
					_fov = ((instance != null) ? instance.GetSetting<FovSetting>() : null);
				}
				FovSetting fov = _fov;
				float num = ((fov != null) ? ((FloatSetting)fov).Value : 70f);
				if (!(num < 60f))
				{
					return num;
				}
				return 70f;
			}
		}

		public static float ExtraFov
		{
			get
			{
				if (_extra == null)
				{
					SettingsHandler instance = SettingsHandler.Instance;
					_extra = ((instance != null) ? instance.GetSetting<ExtraFovSetting>() : null);
				}
				ExtraFovSetting extra = _extra;
				if (extra == null)
				{
					return 0f;
				}
				return ((FloatSetting)extra).Value;
			}
		}
	}
	internal static class ModConfig
	{
		public static ConfigEntry<float> FovBoost;

		public static ConfigEntry<bool> AlwaysClimbingFov;

		public static ConfigEntry<float> ClimbFovDelay;

		public static ConfigEntry<float> FovMax;

		public static void BindAll(ConfigFile config)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			FovBoost = config.Bind<float>("视野", "视野加成", 0f, new ConfigDescription("在现有视野基础上额外增加的度数,任何状态都常驻生效(站立、攀爬、游泳、飞行)。0 = 不加成,等同原版;调大可明显拉宽视野,画面边缘畸变感随之增强。改完保存配置文件即生效,无需重启游戏。", (AcceptableValueBase)null, Array.Empty<object>()));
			AlwaysClimbingFov = config.Bind<bool>("视野", "攀爬加成常驻", false, new ConfigDescription("开启后,游戏设置里的「攀爬视野增加」不再只在攀爬时生效,而是全程叠加在视野上。关闭则保留原生行为:只有攀爬时才有这部分加成。注意该数值取自游戏自身的设置面板(默认 40 度,可设 0~50),不是本 Mod 的配置项。", (AcceptableValueBase)null, Array.Empty<object>()));
			ClimbFovDelay = config.Bind<float>("视野", "攀爬加成延迟取消", 1.5f, new ConfigDescription("停止攀爬后继续保留攀爬视野加成的秒数;0 = 立刻取消(原生行为)。调大可给视野留出收敛时间,避免视野刚放大就反转造成的频繁缩放;「攀爬加成常驻」开启时本项无效。", (AcceptableValueBase)null, Array.Empty<object>()));
			FovMax = config.Bind<float>("视野", "视野上限", 179f, new ConfigDescription("最终视野(游戏设置视野 + 攀爬加成 + 本 Mod 加成)被钳制到的上限。不要设成 180:180 度会让相机投影矩阵出现除零,画面直接坏掉。如果不需要那么宽,可以调小(如 120)。", (AcceptableValueBase)null, Array.Empty<object>()));
		}
	}
	[BepInPlugin("SteadyVisionBoost", "Steady Vision Boost", "1.0.1")]
	[BepInProcess("PEAK.exe")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		private void Awake()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			PluginInfo.Init(((BaseUnityPlugin)this).Logger);
			ModConfig.BindAll(((BaseUnityPlugin)this).Config);
			_harmony = new Harmony("SteadyVisionBoost");
			_harmony.PatchAll(typeof(MainCameraMovement_FovPatch));
			PluginInfo.Log("已加载 v1.0.1 —— 视野加成 " + ModConfig.FovBoost.Value + " 度,攀爬加成常驻 " + (ModConfig.AlwaysClimbingFov.Value ? "开" : "关") + ",延迟取消 " + ModConfig.ClimbFovDelay.Value + " 秒,视野上限 " + ModConfig.FovMax.Value + " 度(改配置文件即时生效)");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal static class PluginInfo
	{
		public const string GUID = "SteadyVisionBoost";

		public const string Name = "Steady Vision Boost";

		public const string Version = "1.0.1";

		public const string HarmonyId = "SteadyVisionBoost";

		private static ManualLogSource _logger;

		public static void Init(ManualLogSource logger)
		{
			_logger = logger;
		}

		public static void Log(object message)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogInfo(message);
			}
		}
	}
}
namespace SteadyVisionBoost.Patches
{
	[HarmonyPatch(typeof(MainCameraMovement), "GetFov")]
	internal static class MainCameraMovement_FovPatch
	{
		private static float _smoothFov = -1f;

		private static bool _bonusHeld;

		private static float _bonusHoldTime;

		private static void Postfix(ref float __result)
		{
			Character localCharacter = Character.localCharacter;
			if (!((Object)(object)localCharacter == (Object)null) && !((Object)(object)localCharacter.data == (Object)null))
			{
				float fov = GameFovSettings.Fov;
				float extraFov = GameFovSettings.ExtraFov;
				float num = ((ModConfig.AlwaysClimbingFov.Value || TrackClimbingBonus(localCharacter.data.isClimbing, ModConfig.ClimbFovDelay.Value)) ? extraFov : 0f);
				float num2 = Mathf.Clamp(fov + num + ModConfig.FovBoost.Value, 1f, ModConfig.FovMax.Value);
				_smoothFov = ((_smoothFov < 0f) ? num2 : Mathf.Lerp(_smoothFov, num2, Time.deltaTime * 5f));
				__result = _smoothFov;
			}
		}

		private static bool TrackClimbingBonus(bool isClimbing, float delay)
		{
			if (isClimbing)
			{
				_bonusHeld = true;
				_bonusHoldTime = 0f;
				return true;
			}
			if (!_bonusHeld)
			{
				return false;
			}
			_bonusHoldTime += Time.deltaTime;
			if (_bonusHoldTime >= delay)
			{
				_bonusHeld = false;
				_bonusHoldTime = 0f;
				return false;
			}
			return true;
		}
	}
}