Decompiled source of Hikari v0.0.3

Hikari.dll

Decompiled a year 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.IgnoreSymbolStoreSequencePoints)]
[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_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: 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.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(255f * Config.CrossHairAlpha)));
			((TMP_Text)crossHairText).outlineColor = Color32.op_Implicit(Color.black);
			((TMP_Text)crossHairText).outlineWidth = 32f * Config.CrossHairSize;
			((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_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_005a: 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 = (float)Mathf.RoundToInt(Mathf.Clamp(GameNetworkManager.Instance.localPlayerController.carryWeight - 1f, 0f, 100f) * 105f) / 2.205f;
				((TMP_Text)___weightCounter).text = num.ToString("F2") + " kg";
				___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;

		public static string CrossHairText => config_CrossHairText.Value;

		public static float CrossHairSize => config_CrossHairSize.Value;

		public static float CrossHairAlpha => config_CrossHairAlpha.Value;

		public static void Load()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			config = new ConfigFile(Path.Combine(Paths.ConfigPath, "Hikari.cfg"), 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_CrossHairAlpha = config.Bind<float>("Hikari.Crosshair", "Alpha", 1f, "The transparency for the Crosshair. (Default: 1.0)");
		}
	}
}