Decompiled source of BatteryText v1.0.0

BatteryText.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.IO;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LethalCompany-BatteryText")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A template for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9cc1d4fd0adf170014ec3aa6746cbb47034affcd")]
[assembly: AssemblyProduct("LethalCompany-BatteryText")]
[assembly: AssemblyTitle("LethalCompany-BatteryText")]
[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 ScruffyRuffles.LC.BatteryText
{
	[HarmonyPatch]
	internal class BatteryTextPatches
	{
		private static GameObject template;

		public static TextMeshProUGUI[] batteryTexts = (TextMeshProUGUI[])(object)new TextMeshProUGUI[0];

		[HarmonyPatch(typeof(HUDManager), "Update")]
		[HarmonyPostfix]
		public static void Update(HUDManager __instance)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < GameNetworkManager.Instance.localPlayerController.ItemSlots.Length; i++)
			{
				if (i >= batteryTexts.Length)
				{
					Array.Resize(ref batteryTexts, i + 1);
				}
				if ((Object)(object)batteryTexts[i] == (Object)null)
				{
					RectTransform rectTransform = ((Graphic)__instance.itemSlotIconFrames[i]).rectTransform;
					GameObject val = Object.Instantiate<GameObject>(template, ((Transform)rectTransform).parent);
					val.SetActive(true);
					val.transform.localScale = 0.5f * Vector3.one;
					batteryTexts[i] = val.GetComponent<TextMeshProUGUI>();
					RectTransform component = ((Component)batteryTexts[i]).GetComponent<RectTransform>();
					Vector2 anchorMin = (component.anchorMax = Vector2.op_Implicit(0.5f * Vector3.one));
					component.anchorMin = anchorMin;
					component.pivot = Vector2.op_Implicit(Vector3.one);
					float num = rectTransform.sizeDelta.x * 0.5f;
					component.anchoredPosition = rectTransform.anchoredPosition + new Vector2(num, 0f - num);
					component.anchoredPosition += new Vector2(Plugin.config.offsetX, Plugin.config.offsetY);
					((Transform)component).SetParent((Transform)(object)rectTransform, true);
				}
				GrabbableObject val3 = GameNetworkManager.Instance.localPlayerController.ItemSlots[i];
				if ((Object)(object)val3 != (Object)null)
				{
					if (val3.itemProperties.requiresBattery)
					{
						((TMP_Text)batteryTexts[i]).text = Mathf.Floor(val3.insertedBattery.charge * 100f) + "%";
						if (Plugin.config.showTimeRemaining)
						{
							TextMeshProUGUI obj = batteryTexts[i];
							((TMP_Text)obj).text = ((TMP_Text)obj).text + "\n" + TimeSpan.FromSeconds(val3.itemProperties.batteryUsage * val3.insertedBattery.charge).ToString("mm\\:ss");
						}
					}
					else
					{
						((TMP_Text)batteryTexts[i]).text = "";
					}
				}
				else
				{
					((TMP_Text)batteryTexts[i]).text = "";
				}
			}
		}

		[HarmonyPatch(typeof(HUDManager), "Awake")]
		[HarmonyPostfix]
		public static void Awake(HUDManager __instance)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			if ((Object)(object)__instance.weightCounter != (Object)null)
			{
				GameObject val = new GameObject("ItemSlotBatteryText")
				{
					layer = LayerMask.NameToLayer("UI")
				};
				val.SetActive(false);
				TextMeshProUGUI obj = val.AddComponent<TextMeshProUGUI>();
				((TMP_Text)obj).font = ((TMP_Text)__instance.weightCounter).font;
				((TMP_Text)obj).fontSize = ((TMP_Text)__instance.weightCounter).fontSize;
				((Graphic)obj).color = ((Graphic)__instance.batteryIcon).color;
				((TMP_Text)obj).alignment = (TextAlignmentOptions)260;
				((TMP_Text)obj).enableAutoSizing = ((TMP_Text)__instance.weightCounter).enableAutoSizing;
				((TMP_Text)obj).fontSizeMin = ((TMP_Text)__instance.weightCounter).fontSizeMin;
				((TMP_Text)obj).fontSizeMax = ((TMP_Text)__instance.weightCounter).fontSizeMax;
				template = val;
			}
		}
	}
	[BepInPlugin("ScruffyRuffles.BatteryText", "BatteryText", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public class ConfigA
		{
			private readonly ConfigFile config;

			private readonly FileSystemWatcher watcher;

			private readonly ConfigEntry<bool> _showTimeRemaining;

			private readonly ConfigEntry<float> _offsetX;

			private readonly ConfigEntry<float> _offsetY;

			public bool showTimeRemaining => _showTimeRemaining.Value;

			public float offsetX => _offsetX.Value;

			public float offsetY => _offsetY.Value;

			public ConfigA(Plugin plugin)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Expected O, but got Unknown
				config = new ConfigFile(Path.Combine(Paths.ConfigPath, "ScruffyRuffles.BatteryText.cfg"), true, MetadataHelper.GetMetadata((object)plugin));
				_showTimeRemaining = config.Bind<bool>("General", "Show Time Remaining", true, "Shows the remaining time under the percentage");
				_offsetX = config.Bind<float>("General", "Offset X", 0f, "Position Offset on the X Axis");
				_offsetY = config.Bind<float>("General", "Offset Y", -2f, "Position Offset on the Y Axis");
				watcher = new FileSystemWatcher(Path.GetDirectoryName(config.ConfigFilePath), "*.cfg")
				{
					NotifyFilter = (NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.Attributes | NotifyFilters.Size | NotifyFilters.LastWrite | NotifyFilters.LastAccess | NotifyFilters.CreationTime | NotifyFilters.Security)
				};
				watcher.Changed += ConfigFileChanged;
				watcher.EnableRaisingEvents = true;
			}

			private void OnConfigReloaded()
			{
				//IL_002d: 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)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: 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_008f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
				for (int i = 0; i < BatteryTextPatches.batteryTexts.Length; i++)
				{
					RectTransform component = ((Component)BatteryTextPatches.batteryTexts[i]).GetComponent<RectTransform>();
					RectTransform component2 = ((Component)((Transform)component).parent).GetComponent<RectTransform>();
					((Transform)component).SetParent(((Transform)component2).parent);
					component.anchoredPosition = component2.anchoredPosition + new Vector2(component2.sizeDelta.x * 0.5f, (0f - component2.sizeDelta.x) * 0.5f) * Vector2.op_Implicit(((Transform)component2).localScale);
					component.anchoredPosition += new Vector2(Plugin.config.offsetX, Plugin.config.offsetY) * Vector2.op_Implicit(((Transform)component2).localScale);
					((Transform)component).SetParent((Transform)(object)component2, true);
				}
			}

			private void ConfigFileChanged(object sender, FileSystemEventArgs e)
			{
				if (!(e.FullPath != config.ConfigFilePath))
				{
					config.Reload();
					OnConfigReloaded();
				}
			}
		}

		private const string modGUID = "ScruffyRuffles.BatteryText";

		private const string modName = "BatteryText";

		private const string modVersion = "1.0.0";

		public static ManualLogSource PluginLogger;

		public static ConfigA config;

		private void Awake()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			PluginLogger = ((BaseUnityPlugin)this).Logger;
			PluginLogger.LogInfo((object)"Plugin LethalCompany-BatteryText is loaded!");
			new Harmony("LethalCompany-BatteryText").PatchAll();
			config = new ConfigA(this);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LethalCompany-BatteryText";

		public const string PLUGIN_NAME = "LethalCompany-BatteryText";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}