Decompiled source of UseBothHands v1.0.0

UseBothHands.dll

Decompiled 20 hours ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("UseBothHands")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UseBothHands")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8214ed98-a6ef-4f49-99ad-2cfa674391d3")]
[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 UseBothHands
{
	[BepInPlugin("finishim.UseBothHands", "Use Both Hands", "1.0.0")]
	public class UseBothHandsPlugin : BaseUnityPlugin
	{
		internal static ConfigEntry<bool> AllowMultipleTwoHanded;

		internal static ManualLogSource Log;

		private Harmony harmony;

		private void Awake()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			AllowMultipleTwoHanded = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AllowMultipleTwoHandedItems", true, "HOST ONLY. Allows players to grab and switch between multiple two-handed items.");
			harmony = new Harmony("finishim.UseBothHands");
			harmony.PatchAll();
			Log.LogInfo((object)"UseBothHands loaded successfully.");
			Log.LogInfo((object)"Successor of Acromata's concept – rewritten and host-authoritative.");
			Log.LogInfo((object)$"Host setting AllowMultipleTwoHandedItems = {AllowMultipleTwoHanded.Value}");
		}
	}
}
namespace UseBothHands.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerB_Patches
	{
		private static bool prevTwoHanded;

		private static bool prevTwoHandedAnim;

		[HarmonyPatch("BeginGrabObject")]
		[HarmonyPrefix]
		private static void Prefix_BeginGrabObject(PlayerControllerB __instance)
		{
			if (((NetworkBehaviour)__instance).IsOwner && UseBothHandsPlugin.AllowMultipleTwoHanded.Value)
			{
				__instance.twoHanded = false;
			}
		}

		[HarmonyPatch("GrabObject")]
		[HarmonyPostfix]
		private static void Postfix_GrabObject(PlayerControllerB __instance)
		{
			if (((NetworkBehaviour)__instance).IsOwner && UseBothHandsPlugin.AllowMultipleTwoHanded.Value)
			{
				__instance.twoHanded = false;
				__instance.twoHandedAnimation = false;
			}
		}

		[HarmonyPatch("SwitchToItemSlot")]
		[HarmonyPrefix]
		private static void Prefix_SwitchToItemSlot(PlayerControllerB __instance)
		{
			if (((NetworkBehaviour)__instance).IsOwner && UseBothHandsPlugin.AllowMultipleTwoHanded.Value)
			{
				prevTwoHanded = __instance.twoHanded;
				prevTwoHandedAnim = __instance.twoHandedAnimation;
				__instance.twoHanded = false;
				__instance.twoHandedAnimation = false;
			}
		}

		[HarmonyPatch("SwitchToItemSlot")]
		[HarmonyPostfix]
		private static void Postfix_SwitchToItemSlot(PlayerControllerB __instance)
		{
			if (((NetworkBehaviour)__instance).IsOwner && UseBothHandsPlugin.AllowMultipleTwoHanded.Value)
			{
				__instance.twoHanded = prevTwoHanded;
				__instance.twoHandedAnimation = prevTwoHandedAnim;
			}
		}
	}
}