Decompiled source of HandMirror v1.0.1

HandMirror.dll

Decompiled 10 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HandMirror.Patches;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HandMirror")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HandMirror")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d947fd9d-387f-4245-b08d-49f9a1c8a2f1")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HandMirror
{
	[BepInPlugin("spiderbuttons.HandMirror", "HandMirror", "1.0.0")]
	public class HandMirrorBase : BaseUnityPlugin
	{
		private const string modGUID = "spiderbuttons.HandMirror";

		private const string modName = "HandMirror";

		private const string modVersion = "1.0.0";

		public static ManualLogSource logger;

		private readonly Harmony harmony = new Harmony("spiderbuttons.HandMirror");

		private static HandMirrorBase Instance;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin spiderbuttons.HandMirror is loaded!");
			harmony.PatchAll(typeof(HandMirrorBase));
			harmony.PatchAll(typeof(MirrorCoilheadPatch));
			harmony.PatchAll(typeof(MagnifyingGlassRenamePatch));
		}
	}
}
namespace HandMirror.Patches
{
	public class MirrorCoilheadPatch
	{
		[HarmonyPatch(typeof(PlayerControllerB), "HasLineOfSightToPosition")]
		[HarmonyPostfix]
		public static void CheckRear(ref Vector3 pos, ref int range, ref float proximityAwareness, ref GrabbableObject ___currentlyHeldObjectServer, ref bool __result, ref PlayerControllerB __instance, ref Transform ___playerEye, ref Camera ___gameplayCamera)
		{
			//IL_0009: 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_005c: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			float num = Vector3.Distance(((Component)__instance).transform.position, pos);
			if ((Object)(object)__instance.currentlyHeldObjectServer != (Object)null && __instance.currentlyHeldObjectServer.itemProperties.itemName.Equals("Hand-Mirror") && num < (float)range && (Vector3.Angle(-((Component)___playerEye).transform.forward, pos - ((Component)___gameplayCamera).transform.position) < 180f || num < proximityAwareness) && !Physics.Linecast(((Component)___playerEye).transform.position, pos, StartOfRound.Instance.collidersRoomDefaultAndFoliage, (QueryTriggerInteraction)1))
			{
				__result = true;
			}
		}
	}
	public class MagnifyingGlassRenamePatch
	{
		[HarmonyPatch(typeof(GrabbableObject), "Start")]
		[HarmonyPrefix]
		public static bool RenameToMirror(ref GrabbableObject __instance)
		{
			if (__instance.itemProperties.itemName.Equals("Magnifying glass"))
			{
				__instance.itemProperties.itemName = "Hand-Mirror";
			}
			return true;
		}

		[HarmonyPatch(typeof(HUDManager), "DisplayScrapItemsOnHud")]
		[HarmonyPrefix]
		public static bool RenameCollectedMirror(ref ScrapItemHUDDisplay[] ___ScrapItemBoxes)
		{
			for (int i = 0; i < ___ScrapItemBoxes.Length; i++)
			{
				if (((TMP_Text)___ScrapItemBoxes[i].headerText).text.Equals("Magnifying glass"))
				{
					((TMP_Text)___ScrapItemBoxes[i].headerText).text = "Hand-Mirror";
				}
			}
			return true;
		}

		[HarmonyPatch(typeof(HUDManager), "UpdateScanNodes")]
		[HarmonyPrefix]
		public static bool RenameScannedMirror(ref Dictionary<RectTransform, ScanNodeProperties> ___scanNodes)
		{
			foreach (KeyValuePair<RectTransform, ScanNodeProperties> ___scanNode in ___scanNodes)
			{
				if (___scanNode.Value.headerText.Equals("Magnifying glass"))
				{
					___scanNode.Value.headerText = "Hand-Mirror";
				}
			}
			return true;
		}
	}
}