Decompiled source of VoidChargeHUD v0.0.2

VoidChargeHUD.dll

Decompiled 3 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.Client;
using CG.Game;
using CG.Network;
using CG.Ship.Modules;
using CG.Space;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
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: AssemblyDescription("Template")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("VoidChargeHUD")]
[assembly: AssemblyTitle("VoidChargeHUD")]
[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 VoidChargeHUD
{
	internal static class MyPluginInfo
	{
		internal const string PLUGIN_GUID = "id107.voidchargehud";

		internal const string PLUGIN_NAME = "VoidChargeHUD";

		internal const string PLUGIN_VERSION = "0.0.2";
	}
	[BepInPlugin("id107.voidchargehud", "VoidChargeHUD", "0.0.2")]
	[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(), "id107.voidchargehud");
			Configs.Load(this);
			((Object)new GameObject("VoidChargeGUI", new Type[1] { typeof(VoidChargeGUI) })).hideFlags = (HideFlags)61;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin id107.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);
		}
	}
	internal class Helper
	{
		internal static bool IsInPilotsSeat(Player player)
		{
			if (player == null)
			{
				return false;
			}
			ClientGame current = ClientGame.Current;
			object obj;
			if (current == null)
			{
				obj = null;
			}
			else
			{
				AbstractPlayerControlledShip playerShip = current.PlayerShip;
				if (playerShip == null)
				{
					obj = null;
				}
				else
				{
					Helm module = playerShip.GetModule<Helm>();
					obj = ((module != null) ? module.Chair : null);
				}
			}
			TakeoverChair val = (TakeoverChair)((obj is TakeoverChair) ? obj : null);
			return (Object)(object)val != (Object)null && !val.IsAvailable && player == ((MonoBehaviourPun)val).photonView.Owner;
		}
	}
	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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			bool flag = mainUiEnabled && (Configs.AlwaysOnConfig.Value || Helper.IsInPilotsSeat(PhotonNetwork.LocalPlayer)) && Tools.PlayerShipExists;
			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)3;

		public override string Author => "18107";

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