Decompiled source of ShipLookout v1.1.0

ShipLookout.dll

Decompiled 14 hours 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;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ShipLookout")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ShipLookout")]
[assembly: AssemblyTitle("ShipLookout")]
[assembly: AssemblyVersion("1.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 ShipLookout
{
	[BepInPlugin("com.Azura.shiplookout", "ShipLookout", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.Azura.shiplookout";

		public const string PluginName = "ShipLookout";

		public const string PluginVersion = "1.1.0";

		internal static ConfigEntry<float> HelmDistance;

		internal static ConfigEntry<float> PassengerDistance;

		internal static ConfigEntry<bool> PassengerWind;

		internal static ConfigEntry<bool> PassengerRudder;

		private static readonly FieldRef<Player, bool> SurNavire = AccessTools.FieldRefAccess<Player, bool>("m_attachedToShip");

		private static readonly FieldRef<Player, Transform> PointAttache = AccessTools.FieldRefAccess<Player, Transform>("m_attachPoint");

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			HelmDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Camera", "HelmMaxDistance", 20f, new ConfigDescription("How far the camera can zoom out at the helm (the game's own limit is 6).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(6f, 40f), Array.Empty<object>()));
			PassengerDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Camera", "PassengerMaxDistance", 20f, new ConfigDescription("How far the camera can zoom out when seated on the ship or leaning on its mast (6 = the game's own limit).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(6f, 40f), Array.Empty<object>()));
			PassengerWind = ((BaseUnityPlugin)this).Config.Bind<bool>("Hud", "PassengerWindIndicator", true, "Show the wind indicator to a passenger seated on the ship or leaning on its mast.");
			PassengerRudder = ((BaseUnityPlugin)this).Config.Bind<bool>("Hud", "PassengerRudderGauge", true, "Also show the passenger the rudder gauge (yellow arc) and the turning wheel, mirrored when seen from ahead of the helm.");
			new Harmony("com.Azura.shiplookout").PatchAll();
		}

		internal static Ship NavirePassager(Player p)
		{
			if ((Object)(object)p == (Object)null || !((Character)p).IsAttached() || !SurNavire.Invoke(p) || (Object)(object)p.GetControlledShip() != (Object)null)
			{
				return null;
			}
			Transform val = PointAttache.Invoke(p);
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return ((Component)val).GetComponentInParent<Ship>();
		}
	}
	[HarmonyPatch(typeof(GameCamera), "UpdateCamera")]
	internal static class GameCamera_UpdateCamera_Patch
	{
		private static void Prefix(GameCamera __instance, out float __state)
		{
			__state = __instance.m_maxDistance;
			__instance.m_maxDistanceBoat = Mathf.Max(__instance.m_maxDistanceBoat, Plugin.HelmDistance.Value);
			if ((Object)(object)Plugin.NavirePassager(Player.m_localPlayer) != (Object)null)
			{
				__instance.m_maxDistance = Mathf.Max(__instance.m_maxDistance, Plugin.PassengerDistance.Value);
			}
		}

		private static void Postfix(GameCamera __instance, float __state)
		{
			__instance.m_maxDistance = __state;
		}
	}
	[HarmonyPatch(typeof(Hud), "UpdateShipHud")]
	internal static class Hud_UpdateShipHud_Patch
	{
		private static readonly FieldRef<Color> CouleurVent = AccessTools.StaticFieldRefAccess<Color>(AccessTools.Field(typeof(Hud), "s_shipWindIconColor"));

		private static readonly Vector3 HorsEcran = new Vector3(-10000f, -10000f, 0f);

		internal static bool DeFace;

		private static void Postfix(Hud __instance, Player player)
		{
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.PassengerWind.Value || !__instance.IsVisible())
			{
				return;
			}
			Ship val = Plugin.NavirePassager(player);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			__instance.m_shipHudRoot.SetActive(true);
			GameObject[] array = (GameObject[])(object)new GameObject[9] { __instance.m_rudderSlow, __instance.m_rudderForward, __instance.m_rudderFastForward, __instance.m_rudderBackward, __instance.m_rudderLeft, __instance.m_rudderRight, __instance.m_fullSail, __instance.m_halfSail, __instance.m_rudder };
			foreach (GameObject val2 in array)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					val2.SetActive(false);
				}
			}
			((Transform)__instance.m_shipWindIndicatorRoot).localRotation = Quaternion.Euler(0f, 0f, val.GetShipYawAngle());
			((Transform)__instance.m_shipWindIconRoot).localRotation = Quaternion.Euler(0f, 0f, val.GetWindAngle());
			((Graphic)__instance.m_shipWindIcon).color = Color.Lerp(CouleurVent.Invoke(), Color.white, val.GetWindAngleFactor());
			Camera mainCamera = Utils.GetMainCamera();
			if ((Object)(object)mainCamera == (Object)null || (Object)(object)val.m_controlGuiPos == (Object)null)
			{
				return;
			}
			Vector3 position = val.m_controlGuiPos.position;
			Vector3 val3 = position - ((Component)mainCamera).transform.position;
			if (Vector3.Dot(val3, ((Component)mainCamera).transform.forward) <= 0f)
			{
				__instance.m_shipControlsRoot.transform.position = HorsEcran;
				return;
			}
			__instance.m_shipControlsRoot.transform.position = Utils.WorldToScreenPointScaled(mainCamera, position);
			float num = Vector3.Dot(val3, ((Component)val).transform.forward);
			if (num < -0.5f)
			{
				DeFace = true;
			}
			else if (num > 0.5f)
			{
				DeFace = false;
			}
			Gouvernail(__instance, val, DeFace ? (-1f) : 1f);
		}

		private static void Gouvernail(Hud hud, Ship navire, float sens)
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			Image shipRudderIndicator = hud.m_shipRudderIndicator;
			float rudderValue = navire.GetRudderValue();
			if (!Plugin.PassengerRudder.Value)
			{
				if ((Object)(object)shipRudderIndicator != (Object)null)
				{
					((Component)shipRudderIndicator).gameObject.SetActive(false);
				}
				return;
			}
			if ((Object)(object)shipRudderIndicator != (Object)null)
			{
				bool flag = Mathf.Abs(rudderValue) >= 0.02f;
				((Component)shipRudderIndicator).gameObject.SetActive(flag);
				if (flag)
				{
					shipRudderIndicator.fillClockwise = rudderValue * sens > 0f;
					shipRudderIndicator.fillAmount = Mathf.Abs(rudderValue) * 0.25f;
				}
			}
			if ((Object)(object)hud.m_shipRudderIcon != (Object)null)
			{
				((Component)hud.m_shipRudderIcon).transform.localRotation = Quaternion.Euler(0f, 0f, (0f - rudderValue) * sens * 200f / Mathf.Max(0.05f, navire.m_rudderSpeed));
			}
		}
	}
}