Decompiled source of HikariPlus v1.0.0

HikariPlus.dll

Decompiled a day ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Hikari.Configuration;
using Hikari.Patches;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Hikari")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Hikari")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4080f450-bb71-42b7-80c0-2c32ff2dc2fc")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Hikari
{
	[BepInPlugin("junko.konno.Hikari", "Hikari", "0.0.3")]
	public class HikariEntry : BaseUnityPlugin
	{
		private const string modGUID = "junko.konno.Hikari";

		private const string modName = "Hikari";

		private const string modVersion = "0.0.3";

		private readonly Harmony harmony = new Harmony("junko.konno.Hikari");

		private static HikariEntry Self;

		internal ManualLogSource logger;

		private void Awake()
		{
			if ((Object)(object)Self == (Object)null)
			{
				Self = this;
			}
			logger = Logger.CreateLogSource("junko.konno.Hikari");
			logger.LogInfo((object)"Konnichiwa Sekai!");
			logger.LogInfo((object)"Running on version 0.0.3!");
			logger.LogInfo((object)"Loading config.");
			Config.Load();
			logger.LogInfo((object)"Loaded!");
			logger.LogInfo((object)"Applying Patches!");
			harmony.PatchAll(typeof(HikariEntry));
			harmony.PatchAll(typeof(MetricPatch));
			harmony.PatchAll(typeof(HealthDisplay));
			harmony.PatchAll(typeof(Crosshair));
			logger.LogInfo((object)"Patch applied!");
		}
	}
}
namespace Hikari.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class Crosshair
	{
		private static GameObject crossHairObject;

		private static TextMeshProUGUI crossHairText;

		private static RectTransform crossHairTransform;

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void Start(ref HUDManager __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			crossHairObject = new GameObject("Hikari.Crosshair.Display");
			crossHairObject.AddComponent<RectTransform>();
			crossHairText = crossHairObject.AddComponent<TextMeshProUGUI>();
			((TMP_Text)crossHairText).font = ((TMP_Text)__instance.weightCounter).font;
			((TMP_Text)crossHairText).fontSize = 32f * Config.CrossHairSize;
			((TMP_Text)crossHairText).text = Config.CrossHairText;
			((TMP_Text)crossHairText).alignment = (TextAlignmentOptions)514;
			((Graphic)crossHairText).color = Color32.op_Implicit(new Color32((byte)Config.CrossHairRed, (byte)Config.CrossHairGreen, (byte)Config.CrossHairBlue, (byte)(255f * Config.CrossHairAlpha)));
			((TMP_Text)crossHairText).outlineColor = new Color32((byte)Config.CrossHairOutlineRed, (byte)Config.CrossHairOutlineGreen, (byte)Config.CrossHairOutlineBlue, byte.MaxValue);
			((TMP_Text)crossHairText).outlineWidth = 32f * (Config.CrossHairSize + Config.CrossHairOutlineWidth);
			((Behaviour)crossHairText).enabled = true;
			crossHairTransform = ((TMP_Text)crossHairText).rectTransform;
			((Transform)crossHairTransform).SetParent(((Component)((Component)__instance.PTTIcon).transform.parent.parent.parent.Find("PlayerCursor").Find("Cursor")).transform, false);
			crossHairTransform.anchoredPosition = new Vector2(0f, 0f);
			((Transform)crossHairTransform).localPosition = new Vector3(0f, 0f, 0f);
			crossHairTransform.offsetMin = new Vector2(-500f, -500f);
			crossHairTransform.offsetMax = new Vector2(500f, 500f);
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void Update(ref HUDManager __instance)
		{
			if (!((Object)(object)GameNetworkManager.Instance == (Object)null) && !((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null) && !((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null))
			{
				((Behaviour)crossHairText).enabled = !GameNetworkManager.Instance.localPlayerController.isPlayerDead;
			}
		}
	}
	[HarmonyPatch(typeof(HUDManager))]
	internal class HealthDisplay
	{
		private static TextMeshProUGUI healthText;

		private static Color32 ShitsBussin = new Color32((byte)0, byte.MaxValue, (byte)0, byte.MaxValue);

		private static Color32 CapBussin = new Color32((byte)160, byte.MaxValue, (byte)0, byte.MaxValue);

		private static Color32 MidBussin = new Color32(byte.MaxValue, byte.MaxValue, (byte)0, byte.MaxValue);

		private static Color32 AintBussin = new Color32(byte.MaxValue, (byte)0, (byte)0, byte.MaxValue);

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void Start(ref HUDManager __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Hikari.Health.Display");
			val.AddComponent<RectTransform>();
			healthText = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)healthText).font = ((TMP_Text)__instance.weightCounter).font;
			((TMP_Text)healthText).fontSize = 16f;
			((TMP_Text)healthText).text = "100 HP";
			((TMP_Text)healthText).alignment = ((TMP_Text)__instance.weightCounter).alignment;
			((Graphic)healthText).color = Color32.op_Implicit(ShitsBussin);
			((TMP_Text)healthText).overflowMode = (TextOverflowModes)0;
			((Behaviour)healthText).enabled = true;
			RectTransform rectTransform = ((TMP_Text)healthText).rectTransform;
			((Transform)rectTransform).SetParent(((TMP_Text)__instance.weightCounter).transform, false);
			rectTransform.anchoredPosition = new Vector2(30f, 15f);
		}

		[HarmonyPatch("UpdateHealthUI")]
		[HarmonyPostfix]
		private static void Update(ref HUDManager __instance, int health, bool hurtPlayer = true)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			if (health <= 100)
			{
				((Graphic)healthText).color = Color32.op_Implicit(ShitsBussin);
			}
			if (health <= 75)
			{
				((Graphic)healthText).color = Color32.op_Implicit(CapBussin);
			}
			if (health <= 50)
			{
				((Graphic)healthText).color = Color32.op_Implicit(MidBussin);
			}
			if (health < 25)
			{
				((Graphic)healthText).color = Color32.op_Implicit(AintBussin);
			}
			((TMP_Text)healthText).text = $"{health} HP";
		}
	}
	[HarmonyPatch(typeof(HUDManager))]
	internal class MetricPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void patchMetricPostUpdate(ref HUDManager __instance, ref TextMeshProUGUI ___weightCounter, ref Animator ___weightCounterAnimator)
		{
			if (!((Object)(object)GameNetworkManager.Instance == (Object)null) && !((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null) && !((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null) && (Object)(object)___weightCounter != (Object)null && (Object)(object)___weightCounterAnimator != (Object)null)
			{
				float num = Mathf.RoundToInt(Mathf.Clamp(GameNetworkManager.Instance.localPlayerController.carryWeight - 1f, 0f, 100f) * 105f);
				if (Config.UseMetric)
				{
					float num2 = num / 2.205f;
					((TMP_Text)___weightCounter).text = num2.ToString("F2") + " kg";
					___weightCounterAnimator.SetFloat("weight", num2 / 130f);
				}
				else
				{
					((TMP_Text)___weightCounter).text = num.ToString("F2") + " lb";
					___weightCounterAnimator.SetFloat("weight", num / 130f);
				}
			}
		}
	}
}
namespace Hikari.Configuration
{
	internal static class Config
	{
		private static ConfigFile config;

		private static ConfigEntry<string> config_CrossHairText;

		private static ConfigEntry<float> config_CrossHairSize;

		private static ConfigEntry<float> config_CrossHairAlpha;

		private static ConfigEntry<float> config_CrossHairRed;

		private static ConfigEntry<float> config_CrossHairGreen;

		private static ConfigEntry<float> config_CrossHairBlue;

		private static ConfigEntry<float> config_CrossHairOutlineRed;

		private static ConfigEntry<float> config_CrossHairOutlineGreen;

		private static ConfigEntry<float> config_CrossHairOutlineBlue;

		private static ConfigEntry<float> config_CrossHairOutlineWidth;

		private static ConfigEntry<bool> config_UseMetric;

		public static string CrossHairText => config_CrossHairText.Value;

		public static float CrossHairSize => config_CrossHairSize.Value;

		public static float CrossHairRed => config_CrossHairRed.Value;

		public static float CrossHairGreen => config_CrossHairGreen.Value;

		public static float CrossHairBlue => config_CrossHairBlue.Value;

		public static float CrossHairAlpha => config_CrossHairAlpha.Value;

		public static float CrossHairOutlineRed => config_CrossHairOutlineRed.Value;

		public static float CrossHairOutlineGreen => config_CrossHairOutlineGreen.Value;

		public static float CrossHairOutlineBlue => config_CrossHairOutlineBlue.Value;

		public static float CrossHairOutlineWidth => config_CrossHairOutlineWidth.Value;

		public static bool UseMetric => config_UseMetric.Value;

		public static void Load()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			string text = Path.Combine(Paths.ConfigPath, "HikariPlus.cfg");
			config = new ConfigFile(text, true);
			InternalLoad();
		}

		public static void InternalLoad()
		{
			config_CrossHairText = config.Bind<string>("Hikari.Crosshair", "Text", "-  +  -", "The string for the Crosshair. ( Example: OwO, +, - )");
			config_CrossHairSize = config.Bind<float>("Hikari.Crosshair", "Size", 1f, "The scale for the Crosshair. (Default: 1.0)");
			config_CrossHairRed = config.Bind<float>("Hikari.Crosshair", "Color-Red", 255f, "The transparency for the Crosshair. (Default: 255)");
			config_CrossHairGreen = config.Bind<float>("Hikari.Crosshair", "Color-Green", 255f, "The transparency for the Crosshair. (Default: 255)");
			config_CrossHairBlue = config.Bind<float>("Hikari.Crosshair", "Color-Blue", 255f, "The transparency for the Crosshair. (Default: 255)");
			config_CrossHairAlpha = config.Bind<float>("Hikari.Crosshair", "Alpha", 1f, "The transparency for the Crosshair. (Default: 1.0)");
			config_CrossHairOutlineRed = config.Bind<float>("Hikari.Crosshair", "Outline-Color-Red", 0f, "The red component of the crosshair outline color. (Default: 0)");
			config_CrossHairOutlineGreen = config.Bind<float>("Hikari.Crosshair", "Outline-Color-Green", 0f, "The green component of the crosshair outline color. (Default: 0)");
			config_CrossHairOutlineBlue = config.Bind<float>("Hikari.Crosshair", "Outline-Color-Blue", 0f, "The blue component of the crosshair outline color. (Default: 0)");
			config_CrossHairOutlineWidth = config.Bind<float>("Hikari.Crosshair", "Outline-Width", 1f, "The width of the crosshair outline. (Default: 1.0)");
			config_UseMetric = config.Bind<bool>("Hikari.Metric", "UseMetric", true, "Toggle between metric (kg) and imperial (lb) units. (Default: true)");
		}
	}
}