Decompiled source of PilotHUD v0.0.2

PilotHUD.dll

Decompiled 5 months 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("Template")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PilotHUD")]
[assembly: AssemblyTitle("PilotHUD")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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
{
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "id107.pilothud";

		public const string PLUGIN_NAME = "PilotHUD";

		public const string PLUGIN_VERSION = "0.0.2";
	}
	[BepInPlugin("id107.pilothud", "PilotHUD", "0.0.2")]
	[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(), "id107.pilothud");
			Configs.Load(this);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin id107.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);
		}
	}
	[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)3;

		public override string Author => "18107";

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

		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();
				}
			};
		}
	}
}