Decompiled source of Latch Grab v1.0.4

LatchGrab.dll

Decompiled 2 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using FistVR;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("LatchGrab")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+660f1b49eeee1076739f394b72a05624205666f8")]
[assembly: AssemblyProduct("LatchGrab")]
[assembly: AssemblyTitle("LatchGrab")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LatchGrab;

[BepInPlugin("dll.smidgeon.latchgrab", "LatchGrab", "1.0.3")]
[BepInProcess("h3vr.exe")]
public class Mod : BaseUnityPlugin
{
	private static CoreControlMode _controlMode;

	private void Awake()
	{
		Harmony.CreateAndPatchAll(typeof(Mod), (string)null);
	}

	[HarmonyPatch(typeof(ClosedBolt), "UpdateInteraction")]
	[HarmonyPostfix]
	private static void ClosedBoltPatch(ClosedBolt __instance)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Invalid comparison between Unknown and I4
		//IL_0031: 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_0042: Invalid comparison between Unknown and I4
		if (((FVRInteractiveObject)__instance).IsHeld)
		{
			HandInput input = ((FVRInteractiveObject)__instance).m_hand.Input;
			bool flag = (((int)_controlMode != 0) ? input.TriggerPressed : input.TouchpadWestPressed);
			if (flag && (int)__instance.LastPos >= 2 && !__instance.IsBoltLocked())
			{
				__instance.LockBolt();
				((FVRFireArm)__instance.Weapon).PlayAudioEvent((FirearmAudioEventType)8, 1f);
			}
		}
	}

	[HarmonyPatch(typeof(ClosedBoltHandle), "UpdateHandle")]
	[HarmonyPostfix]
	private static void StreamlinedBoltCatchFix(ClosedBoltHandle __instance)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Invalid comparison between Unknown and I4
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Invalid comparison between Unknown and I4
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: 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)
		if (__instance.Weapon.HasBoltCatchButton && (int)_controlMode == 1 && ((FVRInteractiveObject)__instance).IsHeld && (int)__instance.CurPos == 4)
		{
			HandInput input = ((FVRInteractiveObject)__instance).m_hand.Input;
			__instance.Weapon.IsBoltCatchButtonHeld = input.TriggerPressed;
		}
	}

	[HarmonyPatch(typeof(HandgunSlide), "UpdateSlide")]
	[HarmonyPostfix]
	private static void PistolPatch(HandgunSlide __instance)
	{
		//IL_0031: 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_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Invalid comparison between Unknown and I4
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Invalid comparison between Unknown and I4
		if (!((FVRInteractiveObject)__instance).IsHeld)
		{
			return;
		}
		Handgun handgun = __instance.Handgun;
		if (handgun.HasSlideRelease)
		{
			HandInput input = ((FVRInteractiveObject)__instance).m_hand.Input;
			bool flag = (((int)_controlMode != 0) ? input.TriggerPressed : input.Hand.OtherHand.Input.TouchpadWestPressed);
			if (flag && !handgun.IsSlideCatchEngaged() && (int)__instance.LastPos >= 2)
			{
				handgun.EngageSlideRelease();
				((FVRFireArm)__instance.Handgun).PlayAudioEvent((FirearmAudioEventType)8, 1f);
			}
		}
	}

	[HarmonyPatch(typeof(GameOptions), "InitializeFromSaveFile")]
	[HarmonyPostfix]
	private static void InitialOptionsGrabPatch(GameOptions __instance)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		_controlMode = __instance.ControlOptions.CCM;
	}

	[HarmonyPatch(typeof(GameOptions), "SaveToFile")]
	[HarmonyPostfix]
	private static void UpdateControlOptionsPatch(GameOptions __instance)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		_controlMode = __instance.ControlOptions.CCM;
	}
}