Decompiled source of LC Extended HUD v1.0.1

LCExtendedHUD/LCExtendedHUD.dll

Decompiled 9 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LCExtendedHUD.Utility;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("LCExtendedHUD")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Extended HUD adds few  tweaks to the ingame HUD")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LCExtendedHUD")]
[assembly: AssemblyTitle("LCExtendedHUD")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace LCExtendedHUD
{
	[BepInPlugin("com.github.elishmel.lcextendedhud", "LC Extended HUD", "1.1")]
	public class ExtendedHUD : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "com.github.elishmel.lcextendedhud";

		public const string PLUGIN_NAME = "LC Extended HUD";

		public const string PLUGIN_VERSION = "1.1";

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"Plugin com.github.elishmel.lcextendedhud is loaded!");
			new Harmony("com.github.elishmel.lcextendedhud").PatchAll(Assembly.GetExecutingAssembly());
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LCExtendedHUD";

		public const string PLUGIN_NAME = "LCExtendedHUD";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace LCExtendedHUD.Utility
{
	internal class ResourceLoader
	{
		private ResourceLoader()
		{
		}

		public static byte[] GetResourceFromCurrentAssemblyAsBytes(in string resouce)
		{
			if (resouce == null)
			{
				return null;
			}
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string text = executingAssembly.GetName().Name + "." + resouce;
			using Stream stream = executingAssembly.GetManifestResourceStream(text);
			if (stream == null)
			{
				ExtendedHUD.Log.LogError((object)("Unable to fetch resouce " + text + "."));
				throw new ArgumentException("Resource " + text + " not found");
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}
	}
}
namespace LCExtendedHUD.Patches
{
	[HarmonyPatch]
	internal static class HUDPatches
	{
		private static GameObject _reticle;

		private static Image _reticleImage;

		private static GameObject _scrapCounter;

		private static TextMeshProUGUI _scrapTextMesh;

		private static GameObject _conductiveDisplay;

		private static TextMeshProUGUI _conductiveDisplayMesh;

		private const string NOT_CONDUCTIVE_TEXT = "not-conductive";

		private const string CONDUCTIVE_TEXT = "conductive";

		private const string CLEAR_TEXT = "clear";

		private const string PROFIT_TEXT = "credits";

		private const string RETICLE_TEXTURE_PATH = "Assets.circle.png";

		private static Vector3 CREDIT_OFFSET => new Vector3(0f, -15f, 0f);

		private static Vector3 CONDUCTIVE_OFFSET => new Vector3(0f, -30f, 0f);

		[HarmonyPostfix]
		[HarmonyPatch(typeof(HUDManager), "Awake")]
		private static void buildHUDPatches(HUDManager __instance)
		{
			((MonoBehaviour)__instance).StartCoroutine(awaitPlayerController());
			drawReticle();
			drawProfit();
			drawConductive();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(HUDManager), "Update")]
		private static void updateHUDPatches(HUDManager __instance)
		{
			updateReticle();
			updateProfit();
			updateConductive();
		}

		private static void drawReticle()
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("Systems/UI/Canvas/PlayerCursor/Cursor");
			_reticle = Object.Instantiate<GameObject>(val.gameObject, val.transform.parent, false);
			((Object)_reticle).name = "Reticle";
			_reticleImage = _reticle.GetComponent<Image>();
			Texture2D val2 = LoadTexture("Assets.circle.png");
			Sprite sprite = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), Vector2.zero);
			_reticleImage.sprite = sprite;
			((Behaviour)_reticleImage).enabled = true;
			_reticle.transform.localScale = new Vector3(-0.036f, -0.036f, 0.364f);
		}

		private static void updateReticle()
		{
			if (!((Object)(object)_reticle == (Object)null) && !((Object)(object)_reticleImage == (Object)null) && !((Object)(object)GameNetworkManager.Instance == (Object)null) && !((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null))
			{
				Image component = GameObject.Find("Systems/UI/Canvas/PlayerCursor/Cursor").GetComponent<Image>();
				if ((GameNetworkManager.Instance.localPlayerController.isPlayerDead || ((Behaviour)component).enabled) && ((Behaviour)_reticleImage).enabled)
				{
					((Behaviour)_reticleImage).enabled = false;
				}
				else if (!GameNetworkManager.Instance.localPlayerController.isPlayerDead && !((Behaviour)_reticleImage).enabled && !((Behaviour)component).enabled)
				{
					((Behaviour)_reticleImage).enabled = true;
				}
			}
		}

		private static void drawProfit()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//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)
			GameObject val = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD/TopLeftCorner/WeightUI");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			_scrapCounter = Object.Instantiate<GameObject>(val.gameObject, val.transform.parent, false);
			if (!Object.op_Implicit((Object)(object)_scrapCounter))
			{
				ExtendedHUD.Log.LogError((object)"Unable to create scrap copy.");
				return;
			}
			((Object)_scrapCounter).name = "Credit counter";
			Vector3 localPosition = _scrapCounter.transform.localPosition;
			_scrapCounter.transform.localPosition = localPosition + CREDIT_OFFSET;
			_scrapTextMesh = _scrapCounter.GetComponentInChildren<TextMeshProUGUI>();
			if (Object.op_Implicit((Object)(object)_scrapTextMesh))
			{
				((Object)_scrapTextMesh).name = "Credits";
				((TMP_Text)_scrapTextMesh).text = "0 credits";
			}
		}

		private static void updateProfit()
		{
			if (!((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null) && !GameNetworkManager.Instance.localPlayerController.isPlayerDead && !((Object)(object)_scrapTextMesh == (Object)null) && !((Object)(object)_scrapCounter == (Object)null) && GameNetworkManager.Instance.localPlayerController.ItemSlots != null && GameNetworkManager.Instance.localPlayerController.ItemSlots.Length != 0)
			{
				((TMP_Text)_scrapTextMesh).text = string.Format("{0} {1}", GameNetworkManager.Instance.localPlayerController.ItemSlots.Where((GrabbableObject item) => (Object)(object)item != (Object)null && item.itemProperties.isScrap).Sum((GrabbableObject item) => item.scrapValue), "credits");
			}
		}

		private static void drawConductive()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//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)
			GameObject val = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD/TopLeftCorner/WeightUI");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			_conductiveDisplay = Object.Instantiate<GameObject>(val.gameObject, val.transform.parent, false);
			if (!Object.op_Implicit((Object)(object)_conductiveDisplay))
			{
				ExtendedHUD.Log.LogError((object)"Unable to create conductive copy.");
				return;
			}
			((Object)_conductiveDisplay).name = "Conductive display";
			Vector3 localPosition = _conductiveDisplay.transform.localPosition;
			_conductiveDisplay.transform.localPosition = localPosition + CONDUCTIVE_OFFSET;
			_conductiveDisplayMesh = _conductiveDisplay.GetComponentInChildren<TextMeshProUGUI>();
			((Object)_conductiveDisplayMesh).name = "Conductive";
			if (Object.op_Implicit((Object)(object)_conductiveDisplayMesh))
			{
				((TMP_Text)_conductiveDisplayMesh).text = "not-conductive";
			}
		}

		private static void updateConductive()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Invalid comparison between Unknown and I4
			if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null || GameNetworkManager.Instance.localPlayerController.isPlayerDead || (Object)(object)_conductiveDisplayMesh == (Object)null || (Object)(object)_conductiveDisplay == (Object)null || GameNetworkManager.Instance.localPlayerController.ItemSlots == null || GameNetworkManager.Instance.localPlayerController.ItemSlots.Length == 0)
			{
				return;
			}
			if ((int)TimeOfDay.Instance.currentLevelWeather != 2)
			{
				((TMP_Text)_conductiveDisplayMesh).text = "clear";
				return;
			}
			((TMP_Text)_conductiveDisplayMesh).text = ((GameNetworkManager.Instance.localPlayerController.ItemSlots.Count((GrabbableObject item) => (Object)(object)item != (Object)null && item.itemProperties.isConductiveMetal) > 0) ? "conductive" : "not-conductive");
		}

		private static IEnumerator awaitPlayerController()
		{
			yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null));
		}

		private static Texture2D LoadTexture(string resource)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_001a: Expected O, but got Unknown
			byte[] resourceFromCurrentAssemblyAsBytes = ResourceLoader.GetResourceFromCurrentAssemblyAsBytes(in resource);
			Texture2D val = new Texture2D(25, 25);
			ImageConversion.LoadImage(val, resourceFromCurrentAssemblyAsBytes);
			return val;
		}
	}
}