Decompiled source of ShipCameraZoom v1.3.0

ShipCameraZoom.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("ShipCameraZoom")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0")]
[assembly: AssemblyProduct("ShipCameraZoom")]
[assembly: AssemblyTitle("ShipCameraZoom")]
[assembly: AssemblyVersion("1.3.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 ShipCameraZoom
{
	[HarmonyPatch(typeof(GameCamera), "Awake")]
	internal static class GameCamera_Awake_CaptureDefaults
	{
		internal static float VanillaMaxDistance;

		internal static bool Captured;

		private static void Postfix(ref float ___m_maxDistance)
		{
			VanillaMaxDistance = ___m_maxDistance;
			Captured = true;
		}
	}
	[HarmonyPatch(typeof(GameCamera), "UpdateCamera")]
	internal static class GameCamera_UpdateCamera_ShipZoom
	{
		private const float GraceSeconds = 0.5f;

		private static float _currentMaxDistance = -1f;

		private static float _lastOnShipTime = -999f;

		private static void Prefix(ref float ___m_maxDistance, ref float ___m_maxDistanceBoat)
		{
			if (!ShipCameraZoomPlugin.Enabled.Value || !GameCamera_Awake_CaptureDefaults.Captured || GameCamera.InFreeFly())
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null))
			{
				float vanillaMaxDistance = GameCamera_Awake_CaptureDefaults.VanillaMaxDistance;
				if (_currentMaxDistance < 0f)
				{
					_currentMaxDistance = vanillaMaxDistance;
				}
				Transform val = (((Character)localPlayer).IsAttached() ? localPlayer.GetAttachPoint() : null);
				bool flag = (Object)(object)val != (Object)null && (Object)(object)((Component)val).GetComponentInParent<Ship>() != (Object)null;
				if (((Character)localPlayer).InNumShipVolumes > 0 || ((Character)localPlayer).IsAttachedToShip() || flag || (Object)(object)((Character)localPlayer).GetStandingOnShip() != (Object)null || (Object)(object)localPlayer.GetControlledShip() != (Object)null)
				{
					_lastOnShipTime = Time.time;
				}
				bool num = Time.time - _lastOnShipTime <= 0.5f;
				float num2 = (num ? (vanillaMaxDistance * ShipCameraZoomPlugin.ZoomMultiplier.Value) : vanillaMaxDistance);
				if (num)
				{
					_currentMaxDistance = num2;
				}
				else
				{
					_currentMaxDistance = Mathf.MoveTowards(_currentMaxDistance, num2, ShipCameraZoomPlugin.ExitZoomSpeed.Value * Time.deltaTime);
				}
				___m_maxDistance = _currentMaxDistance;
				___m_maxDistanceBoat = _currentMaxDistance;
			}
		}
	}
	[BepInPlugin("sopmehua.valheim.shipcamerazoom", "ShipCameraZoom", "1.3.0")]
	public class ShipCameraZoomPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "sopmehua.valheim.shipcamerazoom";

		public const string PluginName = "ShipCameraZoom";

		public const string PluginVersion = "1.3.0";

		public static ConfigEntry<float> ZoomMultiplier;

		public static ConfigEntry<float> ExitZoomSpeed;

		public static ConfigEntry<bool> Enabled;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Включить/выключить мод без удаления файла.");
			ZoomMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ZoomMultiplier", 2.5f, new ConfigDescription("Во сколько раз увеличить максимальную дальность отдаления камеры, пока персонаж стоит на корабле или управляет им (относительно стандартного максимума игры).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 6f), Array.Empty<object>()));
			ExitZoomSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ExitZoomSpeed", 8f, new ConfigDescription("Скорость плавного возврата максимальной дальности к стандартной после ухода с корабля, метров в секунду. Чем больше значение, тем быстрее приближение.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), Array.Empty<object>()));
			_harmony = new Harmony("sopmehua.valheim.shipcamerazoom");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"ShipCameraZoom 1.3.0 загружен.");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}