Decompiled source of BoatStatusHUD v1.0.0

BoatStatusHUD.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BoatStatusHUD")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BoatStatusHUD")]
[assembly: AssemblyTitle("BoatStatusHUD")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BoatStatusHUD;

[BepInPlugin("com.luizbag.sailwind.boatstatushud", "BoatStatusHUD", "1.0.0")]
public class BoatStatusHUDPlugin : BaseUnityPlugin
{
	public static class PluginInfo
	{
		public const string GUID = "com.luizbag.sailwind.boatstatushud";

		public const string Name = "BoatStatusHUD";

		public const string Version = "1.0.0";
	}

	public static BoatDamage CurrentBoatDamage;

	private void Awake()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			new Harmony("com.luizbag.sailwind.boatstatushud").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[BoatStatusHUD] Telemetry system successfully initialized.");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("[BoatStatusHUD] Critical failure hook mapping: " + ex.Message));
		}
	}

	private void OnGUI()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: 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_01a2: Expected O, but got Unknown
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		if (!GameState.playing || GameState.justStarted || (Object)(object)GameState.lastBoat == (Object)null)
		{
			return;
		}
		BoatDamage component = ((Component)GameState.lastBoat).GetComponent<BoatDamage>();
		Rigidbody component2 = ((Component)GameState.lastBoat).GetComponent<Rigidbody>();
		if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null)
		{
			return;
		}
		float num = Vector3.Dot(component2.velocity, GameState.lastBoat.forward) * 1.94384f;
		if (Mathf.Abs(num) < 0.1f)
		{
			num = 0f;
		}
		float num2 = Vector3.Angle(GameState.lastBoat.up, Vector3.up);
		float num3 = component.hullDamage * 100f;
		float num4 = component.waterLevel * 100f;
		float num5 = (float)AccessTools.Field(typeof(BoatDamage), "baseMass").GetValue(component);
		float num6 = (component2.mass - num5) * 2.20462f;
		if (num6 < 0f)
		{
			num6 = 0f;
		}
		float num7 = (component2.mass - num5) / (num5 * 0.5f);
		if (num7 < 0f)
		{
			num7 = 0f;
		}
		float num8 = 0.65f + num7;
		float num9 = ((Vector3)(ref Wind.currentWind)).magnitude * 1.94384f;
		float num10 = 999f;
		float num11 = 999f;
		RaycastHit val = default(RaycastHit);
		if (Physics.Raycast(GameState.lastBoat.position, Vector3.down, ref val, 200f))
		{
			num10 = ((RaycastHit)(ref val)).distance;
			num11 = num10 - num8;
			if (num11 < 0f)
			{
				num11 = 0f;
			}
		}
		GUI.Box(new Rect(20f, 60f, 270f, 270f), "");
		GUIStyle defaultStyle = new GUIStyle();
		defaultStyle.fontSize = 13;
		defaultStyle.fontStyle = (FontStyle)1;
		defaultStyle.normal.textColor = Color.white;
		float startX = 32f;
		float startY = 65f;
		float lineHeight = 15f;
		int currentLine = 0;
		DrawHUDLine("[ VESSEL INSTRUMENTS ]", defaultStyle);
		DrawHUDLine("---------------------------", defaultStyle);
		DrawHUDLine($"Vessel Speed   : {num:F1} kts", defaultStyle);
		DrawHUDLine($"Wind Speed     : {num9:F1} kts", defaultStyle);
		DrawHUDLine($"Heel Angle     : {num2:F1}° / {component.safeAngleLimit:F0}°", GetStyleForAngle(num2, component.safeAngleLimit));
		DrawHUDLine($"Cargo Weight   : {num6:F0} lbs", defaultStyle);
		DrawHUDLine("---------------------------", defaultStyle);
		DrawHUDLine($"Waterline Sink : +{num7:F2} m", defaultStyle);
		DrawHUDLine($"Current Draft  : {num8:F2} m", defaultStyle);
		DrawHUDLine("---------------------------", defaultStyle);
		DrawHUDLine("Sea Depth      : " + ((num10 > 190f) ? "Deep Ocean" : (num10.ToString("F1") + " m")), defaultStyle);
		string text = ((num11 > 190f) ? "Safe" : (num11.ToString("F1") + " m"));
		DrawHUDLine("Keel Clearance : " + text, GetStyleForClearance(num11));
		DrawHUDLine("---------------------------", defaultStyle);
		DrawHUDLine($"Hull Integrity : {100f - num3:F1}%", GetStyleForDamage(num3));
		DrawHUDLine($"Bilge Water    : {num4:F1}%", GetStyleForWater(num4, component.sunk));
		void DrawHUDLine(string text2, GUIStyle style)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			GUI.Label(new Rect(startX, startY + (float)currentLine * lineHeight, 250f, 20f), text2, style);
			currentLine++;
		}
		GUIStyle GetStyleForAngle(float angle, float limit)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			GUIStyle val2 = new GUIStyle(defaultStyle);
			val2.normal.textColor = ((angle > limit) ? Color.yellow : Color.white);
			return val2;
		}
		GUIStyle GetStyleForClearance(float clearance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val2 = new GUIStyle(defaultStyle);
			val2.normal.textColor = ((clearance <= 0.1f) ? Color.red : ((clearance < 2f) ? Color.yellow : Color.white));
			return val2;
		}
		GUIStyle GetStyleForDamage(float damage)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val2 = new GUIStyle(defaultStyle);
			val2.normal.textColor = ((damage >= 95f) ? Color.red : ((damage > 15f) ? Color.yellow : Color.white));
			return val2;
		}
		GUIStyle GetStyleForWater(float water, bool sunk)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val2 = new GUIStyle(defaultStyle);
			val2.normal.textColor = (sunk ? Color.red : ((water > 15f) ? Color.yellow : Color.white));
			return val2;
		}
	}
}