Decompiled source of Pilot HUD v0.0.3

PilotHUD.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
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 CG;
using CG.Game;
using CG.Input;
using CG.Ship.Modules;
using CG.Space;
using Gameplay.Helm;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UI.PilotHUD;
using UnityEngine;
using VoidManager;
using VoidManager.CustomGUI;
using VoidManager.MPModChecks;
using VoidManager.Utilities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("PilotHUD")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Displays the pilot HUD when the helm is powered. Client side.")]
[assembly: AssemblyFileVersion("0.0.3.0")]
[assembly: AssemblyInformationalVersion("0.0.3+154b3b5c1be0a3817ff7b878b92b5165c14c5634")]
[assembly: AssemblyProduct("PilotHUD")]
[assembly: AssemblyTitle("Displays the pilot HUD when the helm is powered. Client side.")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 PilotHUD
{
	[BepInPlugin("18107.PilotHUD", "Pilot HUD", "0.0.3")]
	[BepInProcess("Void Crew.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BepinPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "18107.PilotHUD");
			Configs.Load(this);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin 18107.PilotHUD is loaded!");
		}
	}
	internal class Configs
	{
		internal static ConfigEntry<bool> HUDVisible;

		internal static ConfigEntry<KeyCode> ToggleHUDKeybindConfig;

		internal static void Load(BepinPlugin plugin)
		{
			HUDVisible = ((BaseUnityPlugin)plugin).Config.Bind<bool>("PilotHUD", "HUDVisible", true, (ConfigDescription)null);
			ToggleHUDKeybindConfig = ((BaseUnityPlugin)plugin).Config.Bind<KeyCode>("PilotHUD", "ToggleHUD", (KeyCode)0, (ConfigDescription)null);
		}
	}
	internal class GUI : ModSettingsMenu
	{
		public override string Name()
		{
			return "Pilot HUD";
		}

		public override void Draw()
		{
			if (GUITools.DrawCheckbox("Pilot HUD", ref Configs.HUDVisible))
			{
				PilotHUDDisplayerPatch.UpdateHUD();
			}
			GUITools.DrawChangeKeybindButton("Change Toggle HUD Keybind", ref Configs.ToggleHUDKeybindConfig);
		}
	}
	public class MyPluginInfo
	{
		public const string PLUGIN_GUID = "18107.PilotHUD";

		public const string PLUGIN_NAME = "PilotHUD";

		public const string USERS_PLUGIN_NAME = "Pilot HUD";

		public const string PLUGIN_VERSION = "0.0.3";

		public const string PLUGIN_DESCRIPTION = "Displays the pilot HUD when the helm is powered. Client side.";

		public const string PLUGIN_ORIGINAL_AUTHOR = "18107";

		public const string PLUGIN_AUTHORS = "18107";

		public const string PLUGIN_THUNDERSTORE_ID = "";
	}
	[HarmonyPatch(typeof(MainMenu), "Start")]
	internal class Patch
	{
		private static void Postfix()
		{
			BepinPlugin.Log.LogInfo((object)"Example Patch Executed");
		}
	}
	[HarmonyPatch(typeof(PilotHUDDisplayer))]
	internal class PilotHUDDisplayerPatch
	{
		public static CameraType currentCamera = (CameraType)0;

		private static readonly MethodInfo show = AccessTools.Method(typeof(PilotHUDDisplayer), "Show", (Type[])null, (Type[])null);

		[HarmonyPrefix]
		[HarmonyPatch("Show")]
		private static void PatchShow(ref CameraType obj)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			currentCamera = obj;
			if (Configs.HUDVisible.Value)
			{
				obj = (CameraType)1;
			}
		}

		public static void UpdateHUD()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			AbstractPlayerControlledShip playerShip = ClientGame.Current.PlayerShip;
			object obj;
			if (playerShip == null)
			{
				obj = null;
			}
			else
			{
				Helm module = playerShip.GetModule<Helm>();
				obj = ((module != null) ? ((Component)module).GetComponentInChildren<PilotHUDDisplayer>() : null);
			}
			PilotHUDDisplayer val = (PilotHUDDisplayer)obj;
			if (!((Object)(object)val == (Object)null))
			{
				show.Invoke(val, new object[1] { currentCamera });
			}
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)8;

		public override string Author => "18107";

		public override string Description => "Displays the pilot HUD when the helm is powered. Client side.";

		public override string ThunderstoreID => "";

		public VoidManagerPlugin()
		{
			Events.Instance.LateUpdate += delegate
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				if ((int)Configs.ToggleHUDKeybindConfig.Value != 0 && UnityInput.Current.GetKeyDown(Configs.ToggleHUDKeybindConfig.Value) && !ServiceBase<InputService>.Instance.CursorVisibilityControl.IsCursorShown)
				{
					Configs.HUDVisible.Value = !Configs.HUDVisible.Value;
					PilotHUDDisplayerPatch.UpdateHUD();
				}
			};
		}
	}
}