Decompiled source of NotYourHotkeys v0.1.0

NotYourHotkeys.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NotYourHotkeys")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NotYourHotkeys")]
[assembly: AssemblyTitle("NotYourHotkeys")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NotYourHotkeys;

[HarmonyPatch(typeof(BuildUi), "Update")]
internal static class BuildUiInputPatch
{
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		MethodInfo original = AccessTools.Method(typeof(ZInput), "GetButtonDown", new Type[1] { typeof(string) }, (Type[])null);
		MethodInfo replacement = AccessTools.Method(typeof(NotYourHotkeysPlugin), "GetButtonDownModifierAware", (Type[])null, (Type[])null);
		foreach (CodeInstruction instruction in instructions)
		{
			if (CodeInstructionExtensions.Calls(instruction, original))
			{
				yield return new CodeInstruction(OpCodes.Call, (object)replacement);
			}
			else
			{
				yield return instruction;
			}
		}
	}
}
[HarmonyPatch(typeof(InventoryGui), "Update")]
internal static class InventoryInputPatch
{
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		MethodInfo original = AccessTools.Method(typeof(ZInput), "GetButtonDown", new Type[1] { typeof(string) }, (Type[])null);
		MethodInfo replacement = AccessTools.Method(typeof(NotYourHotkeysPlugin), "GetButtonDownModifierAware", (Type[])null, (Type[])null);
		foreach (CodeInstruction instruction in instructions)
		{
			if (CodeInstructionExtensions.Calls(instruction, original))
			{
				yield return new CodeInstruction(OpCodes.Call, (object)replacement);
			}
			else
			{
				yield return instruction;
			}
		}
	}
}
[HarmonyPatch(typeof(Minimap), "Update")]
internal static class MinimapInputPatch
{
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		MethodInfo original = AccessTools.Method(typeof(ZInput), "GetButtonDown", new Type[1] { typeof(string) }, (Type[])null);
		MethodInfo replacement = AccessTools.Method(typeof(NotYourHotkeysPlugin), "GetButtonDownModifierAware", (Type[])null, (Type[])null);
		foreach (CodeInstruction instruction in instructions)
		{
			if (CodeInstructionExtensions.Calls(instruction, original))
			{
				yield return new CodeInstruction(OpCodes.Call, (object)replacement);
			}
			else
			{
				yield return instruction;
			}
		}
	}
}
[BepInPlugin("notyourfriend.NotYourHotkeys", "NotYourHotkeys", "0.1.0")]
public class NotYourHotkeysPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "notyourfriend.NotYourHotkeys";

	public const string PluginName = "NotYourHotkeys";

	public const string PluginVersion = "0.1.0";

	internal static ConfigEntry<bool> EnableMod;

	internal static ConfigEntry<bool> EnableAlt;

	internal static ConfigEntry<bool> EnableShift;

	internal static ConfigEntry<bool> EnableCtrl;

	internal static ConfigEntry<bool> IsolateMap;

	internal static ConfigEntry<bool> IsolateInventory;

	internal static ConfigEntry<bool> IsolateBuildMenu;

	internal static ConfigEntry<bool> IsolateHide;

	internal static ConfigEntry<bool> IsolateSit;

	internal static ConfigEntry<bool> IsolateAutoPickup;

	internal static ConfigEntry<bool> IsolateOpenEmote;

	internal static ConfigEntry<bool> IsolateOpenRadial;

	internal static ConfigEntry<bool> IsolateToggleWalk;

	internal static ConfigEntry<bool> IsolateGuardianPower;

	internal static ConfigEntry<bool> IsolateHotbar;

	private Harmony _harmony;

	private void Awake()
	{
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Expected O, but got Unknown
		EnableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable", true, "Enable modifier-aware vanilla hotkey isolation.");
		EnableAlt = ((BaseUnityPlugin)this).Config.Bind<bool>("Modifiers", "Alt", true, "Suppress configured vanilla actions while Alt is held.");
		EnableShift = ((BaseUnityPlugin)this).Config.Bind<bool>("Modifiers", "Shift", true, "Suppress configured vanilla actions while Shift is held.");
		EnableCtrl = ((BaseUnityPlugin)this).Config.Bind<bool>("Modifiers", "Ctrl", true, "Suppress configured vanilla actions while Ctrl is held.");
		IsolateMap = ((BaseUnityPlugin)this).Config.Bind<bool>("Vanilla Actions", "Map", true, "Prevent the vanilla Map action while an enabled modifier is held.");
		IsolateInventory = ((BaseUnityPlugin)this).Config.Bind<bool>("Vanilla Actions", "Inventory", true, "Prevent the vanilla Inventory action while an enabled modifier is held.");
		IsolateBuildMenu = ((BaseUnityPlugin)this).Config.Bind<bool>("Vanilla Actions", "BuildMenu", true, "Prevent the vanilla BuildMenu action while an enabled modifier is held.");
		IsolateHide = ((BaseUnityPlugin)this).Config.Bind<bool>("Vanilla Actions", "Hide", true, "Prevent the vanilla Hide action while an enabled modifier is held.");
		IsolateSit = ((BaseUnityPlugin)this).Config.Bind<bool>("Vanilla Actions", "Sit", true, "Prevent the vanilla Sit action while an enabled modifier is held.");
		IsolateAutoPickup = ((BaseUnityPlugin)this).Config.Bind<bool>("Vanilla Actions", "AutoPickup", true, "Prevent the vanilla AutoPickup action while an enabled modifier is held.");
		IsolateOpenEmote = ((BaseUnityPlugin)this).Config.Bind<bool>("Vanilla Actions", "OpenEmote", true, "Prevent the vanilla OpenEmote action while an enabled modifier is held.");
		IsolateOpenRadial = ((BaseUnityPlugin)this).Config.Bind<bool>("Vanilla Actions", "OpenRadial", true, "Prevent the vanilla OpenRadial action while an enabled modifier is held.");
		IsolateToggleWalk = ((BaseUnityPlugin)this).Config.Bind<bool>("Vanilla Actions", "ToggleWalk", true, "Prevent the vanilla ToggleWalk action while an enabled modifier is held.");
		IsolateGuardianPower = ((BaseUnityPlugin)this).Config.Bind<bool>("Vanilla Actions", "GuardianPower", true, "Prevent the vanilla Guardian Power action while an enabled modifier is held.");
		IsolateHotbar = ((BaseUnityPlugin)this).Config.Bind<bool>("Vanilla Actions", "Hotbar", true, "Prevent vanilla hotbar slot activation while an enabled modifier is held.");
		_harmony = new Harmony("notyourfriend.NotYourHotkeys");
		_harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"NotYourHotkeys 0.1.0 loaded.");
	}

	internal static bool AnyConfiguredModifierHeld()
	{
		if (EnableAlt.Value && (Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307)))
		{
			return true;
		}
		if (EnableShift.Value && (Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303)))
		{
			return true;
		}
		if (EnableCtrl.Value && (Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305)))
		{
			return true;
		}
		return false;
	}

	internal static bool ShouldSuppressBaseAction(string buttonName)
	{
		switch (buttonName)
		{
		case "Map":
			return IsolateMap.Value;
		case "Inventory":
			return IsolateInventory.Value;
		case "BuildMenu":
			return IsolateBuildMenu.Value;
		case "Hide":
			return IsolateHide.Value;
		case "Sit":
			return IsolateSit.Value;
		case "AutoPickup":
			return IsolateAutoPickup.Value;
		case "OpenEmote":
			return IsolateOpenEmote.Value;
		case "OpenRadial":
			return IsolateOpenRadial.Value;
		case "ToggleWalk":
			return IsolateToggleWalk.Value;
		case "GP":
			return IsolateGuardianPower.Value;
		default:
			if (buttonName.StartsWith("Hotbar"))
			{
				return IsolateHotbar.Value;
			}
			return false;
		}
	}

	internal static bool GetButtonDownModifierAware(string buttonName)
	{
		if (!EnableMod.Value)
		{
			return ZInput.GetButtonDown(buttonName);
		}
		if (ShouldSuppressBaseAction(buttonName) && AnyConfiguredModifierHeld())
		{
			return false;
		}
		return ZInput.GetButtonDown(buttonName);
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}
}
[HarmonyPatch(typeof(Player), "Update")]
internal static class PlayerInputPatch
{
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		MethodInfo original = AccessTools.Method(typeof(ZInput), "GetButtonDown", new Type[1] { typeof(string) }, (Type[])null);
		MethodInfo replacement = AccessTools.Method(typeof(NotYourHotkeysPlugin), "GetButtonDownModifierAware", (Type[])null, (Type[])null);
		foreach (CodeInstruction instruction in instructions)
		{
			if (CodeInstructionExtensions.Calls(instruction, original))
			{
				yield return new CodeInstruction(OpCodes.Call, (object)replacement);
			}
			else
			{
				yield return instruction;
			}
		}
	}
}