Decompiled source of Void Charge HUD v0.0.4

VoidChargeHUD.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.Client;
using CG.Game;
using CG.Network;
using CG.Ship.Modules;
using CG.Space;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("VoidChargeHUD")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.3.0")]
[assembly: AssemblyInformationalVersion("0.0.3+97fc855a468a432b66bd787c147ff1b0e227db89")]
[assembly: AssemblyProduct("VoidChargeHUD")]
[assembly: AssemblyTitle("Displays the void charge state while in the pilot's seat,. 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 VoidChargeHUD
{
	[BepInPlugin("18107.VoidChargeHUD", "Void Charge HUD", "0.0.4")]
	[BepInProcess("Void Crew.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BepinPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "18107.VoidChargeHUD");
			Configs.Load(this);
			((Object)new GameObject("VoidChargeGUI", new Type[1] { typeof(VoidChargeGUI) })).hideFlags = (HideFlags)61;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin 18107.VoidChargeHUD is loaded!");
		}
	}
	internal class Configs
	{
		internal static ConfigEntry<bool> AlwaysOnConfig;

		internal static ConfigEntry<float> GUIPosX;

		internal static ConfigEntry<float> GUIPosY;

		internal static ConfigEntry<int> TextSizeConfig;

		internal static void Load(BepinPlugin plugin)
		{
			AlwaysOnConfig = ((BaseUnityPlugin)plugin).Config.Bind<bool>("VoidChargeHUD", "AlwaysOn", false, (ConfigDescription)null);
			GUIPosX = ((BaseUnityPlugin)plugin).Config.Bind<float>("VoidChargeHUD", "GUIPosX", 0.93f, (ConfigDescription)null);
			GUIPosY = ((BaseUnityPlugin)plugin).Config.Bind<float>("VoidChargeHUD", "GUIPosY", 0.806f, (ConfigDescription)null);
			TextSizeConfig = ((BaseUnityPlugin)plugin).Config.Bind<int>("VoidChargeHUD", "TextSize", 15, (ConfigDescription)null);
		}
	}
	internal class GUI : ModSettingsMenu
	{
		public override string Name()
		{
			return "Void Charge HUD";
		}

		public override void Draw()
		{
			GUITools.DrawCheckbox("Always display GUI", ref Configs.AlwaysOnConfig);
			GUILayout.Label("", Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			GUILayout.Label("GUI Position", Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			GUILayout.Label("x: ", Array.Empty<GUILayoutOption>());
			if (GUITools.DrawSlider(ref Configs.GUIPosX, 0f, 1f))
			{
				VoidChargeGUI.Instance.UpdateWindowPos();
			}
			GUILayout.Label("y: ", Array.Empty<GUILayoutOption>());
			if (GUITools.DrawSlider(ref Configs.GUIPosY, 0f, 1f))
			{
				VoidChargeGUI.Instance.UpdateWindowPos();
			}
			if (GUILayout.Button("Reset", Array.Empty<GUILayoutOption>()))
			{
				Configs.GUIPosX.Value = (float)((ConfigEntryBase)Configs.GUIPosX).DefaultValue;
				Configs.GUIPosY.Value = (float)((ConfigEntryBase)Configs.GUIPosY).DefaultValue;
				VoidChargeGUI.Instance.UpdateWindowPos();
			}
			GUILayout.Label("", Array.Empty<GUILayoutOption>());
			GUITools.DrawTextField<int>("Text Size", ref Configs.TextSizeConfig, 80f);
		}
	}
	public class MyPluginInfo
	{
		public const string PLUGIN_GUID = "18107.VoidChargeHUD";

		public const string PLUGIN_NAME = "VoidChargeHUD";

		public const string USERS_PLUGIN_NAME = "Void Charge HUD";

		public const string PLUGIN_VERSION = "0.0.4";

		public const string PLUGIN_DESCRIPTION = "Displays the void charge state while in the pilot's seat. Client side.";

		public const string PLUGIN_ORIGINAL_AUTHOR = "18107";

		public const string PLUGIN_AUTHORS = "18107";

		public const string PLUGIN_THUNDERSTORE_ID = "VoidCrewModdingTeam/Void_Charge_HUD";
	}
	internal class VoidChargeGUI : MonoBehaviour
	{
		private bool mainUiEnabled = true;

		private bool guiActive = false;

		internal Rect WindowPos;

		internal const float width = 80f;

		internal const float height = 24f;

		private VoidDriveModule voidDrive;

		internal static VoidChargeGUI Instance { get; private set; }

		private VoidChargeGUI()
		{
			Instance = this;
			Tools.DelayDo((Action)delegate
			{
				ViewEventBus.Instance.OnUIToggle.Subscribe((Action<bool>)delegate(bool enable)
				{
					mainUiEnabled = enable;
				}, (AutoUnsubscribeCollection)null);
			}, 12000.0);
		}

		internal void UpdateWindowPos()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			WindowPos = new Rect((float)Screen.width * Configs.GUIPosX.Value, (float)Screen.height * Configs.GUIPosY.Value, 80f, 24f);
		}

		private void Update()
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			bool flag = mainUiEnabled && ((Configs.AlwaysOnConfig.Value && Game.PlayerShipExists) || ((Object)(object)Game.CurrentPilot != (Object)null && ((AbstractCloneStarObject)Game.CurrentPilot).IsMine));
			if (flag == guiActive)
			{
				return;
			}
			guiActive = !guiActive;
			WindowPos = new Rect((float)Screen.width * Configs.GUIPosX.Value, (float)Screen.height * Configs.GUIPosY.Value, 80f, 24f);
			ClientGame current = ClientGame.Current;
			object obj;
			if (current == null)
			{
				obj = null;
			}
			else
			{
				AbstractPlayerControlledShip playerShip = current.PlayerShip;
				if (playerShip == null)
				{
					obj = null;
				}
				else
				{
					GameObject gameObject = ((AbstractCloneStarObject)playerShip).GameObject;
					obj = ((gameObject != null) ? gameObject.GetComponentInChildren<VoidDriveModule>() : null);
				}
			}
			voidDrive = (VoidDriveModule)obj;
		}

		private void OnGUI()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (guiActive)
			{
				GUI.Window(718107, WindowPos, (WindowFunction)null, $"<color=#ffffff><size={Configs.TextSizeConfig.Value}><b>{voidDrive.JumpCharge * 100f:0}%</b></size></color>", GUIStyle.none);
			}
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)8;

		public override string Author => "18107";

		public override string Description => "Displays the void charge state while in the pilot's seat. Client side.";

		public override string ThunderstoreID => "VoidCrewModdingTeam/Void_Charge_HUD";
	}
}