using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("Niko666")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Allows players to slap close barrel / breech that is \\\"stiff\\\" (\\\"not physical\\\"), on i.e. Derringers, IPSICK 2011, Flaregun, etc.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Niko666.StiffHingeSlapper")]
[assembly: AssemblyTitle("StiffHingeSlapper")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
{
}
}
}
namespace Niko666
{
[BepInProcess("h3vr.exe")]
[BepInPlugin("Niko666.StiffHingeSlapper", "StiffHingeSlapper", "1.0.0")]
public class StiffHingeSlapper : BaseUnityPlugin
{
public static ConfigEntry<bool> AllowSlapWithoutEmptyHand;
public static ConfigEntry<float> SlapDistance;
public static ConfigEntry<float> SlapAngle;
public const string Id = "Niko666.StiffHingeSlapper";
public static StiffHingeSlapper Instance { get; private set; }
internal static ManualLogSource Logger { get; private set; }
public static string Name => "StiffHingeSlapper";
public static string Version => "1.0.0";
private void Awake()
{
Instance = this;
AllowSlapWithoutEmptyHand = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AllowSlapWithoutEmptyHand", false, "Allow slap without your hand being empty. Might cause the hinge closes accidently when reloading.");
SlapDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SlapDistance", 0.15f, "Registered distance for slapping. 0.15 being H3VR default (for revolvers hammer fanning).");
SlapAngle = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SlapAngle", 45f, "Registered angle for slapping. 60 being H3VR default (for revolvers hammer fanning).");
Logger = ((BaseUnityPlugin)this).Logger;
Harmony.CreateAndPatchAll(typeof(SlapPatch), (string)null);
Logger.LogMessage((object)("Hello, world! Sent from Niko666.StiffHingeSlapper " + Version));
}
}
public class Slapper : MonoBehaviour
{
public Flaregun flaregun;
public Derringer derringer;
public AttachableBreakActions M320;
public Transform MuzzleSlapPoint;
public Transform ChamberSlapPoint;
public void Awake()
{
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Invalid comparison between Unknown and I4
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_0196: Invalid comparison between Unknown and I4
//IL_0722: Unknown result type (might be due to invalid IL or missing references)
//IL_0737: Unknown result type (might be due to invalid IL or missing references)
//IL_0782: Unknown result type (might be due to invalid IL or missing references)
//IL_0792: Unknown result type (might be due to invalid IL or missing references)
//IL_07ad: Unknown result type (might be due to invalid IL or missing references)
//IL_07c1: Unknown result type (might be due to invalid IL or missing references)
//IL_07c6: Unknown result type (might be due to invalid IL or missing references)
//IL_07e1: Unknown result type (might be due to invalid IL or missing references)
//IL_07f5: Unknown result type (might be due to invalid IL or missing references)
//IL_07fa: Unknown result type (might be due to invalid IL or missing references)
//IL_029a: Unknown result type (might be due to invalid IL or missing references)
//IL_02af: Unknown result type (might be due to invalid IL or missing references)
//IL_0310: Unknown result type (might be due to invalid IL or missing references)
//IL_0320: Unknown result type (might be due to invalid IL or missing references)
//IL_0330: Unknown result type (might be due to invalid IL or missing references)
//IL_0336: Invalid comparison between Unknown and I4
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
//IL_0341: Unknown result type (might be due to invalid IL or missing references)
//IL_0347: Invalid comparison between Unknown and I4
//IL_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0400: Invalid comparison between Unknown and I4
//IL_057b: Unknown result type (might be due to invalid IL or missing references)
//IL_0581: Invalid comparison between Unknown and I4
//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
//IL_0383: Unknown result type (might be due to invalid IL or missing references)
//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
//IL_0634: Unknown result type (might be due to invalid IL or missing references)
//IL_063a: Invalid comparison between Unknown and I4
//IL_0547: Unknown result type (might be due to invalid IL or missing references)
//IL_0566: Unknown result type (might be due to invalid IL or missing references)
//IL_0504: Unknown result type (might be due to invalid IL or missing references)
//IL_0523: Unknown result type (might be due to invalid IL or missing references)
//IL_047f: Unknown result type (might be due to invalid IL or missing references)
//IL_049e: Unknown result type (might be due to invalid IL or missing references)
//IL_043c: Unknown result type (might be due to invalid IL or missing references)
//IL_045b: Unknown result type (might be due to invalid IL or missing references)
//IL_0600: Unknown result type (might be due to invalid IL or missing references)
//IL_061f: Unknown result type (might be due to invalid IL or missing references)
//IL_05bd: Unknown result type (might be due to invalid IL or missing references)
//IL_05dc: Unknown result type (might be due to invalid IL or missing references)
//IL_06b6: Unknown result type (might be due to invalid IL or missing references)
//IL_06d5: Unknown result type (might be due to invalid IL or missing references)
//IL_0676: Unknown result type (might be due to invalid IL or missing references)
//IL_0695: Unknown result type (might be due to invalid IL or missing references)
flaregun = ((Component)this).GetComponent<Flaregun>();
derringer = ((Component)this).GetComponent<Derringer>();
M320 = ((Component)this).GetComponent<AttachableBreakActions>();
if ((Object)(object)flaregun != (Object)null && (Object)(object)flaregun.Muzzle != (Object)null && (Object)(object)flaregun.Chamber != (Object)null)
{
MuzzleSlapPoint = new GameObject("tempMuzzleSlapPoint").transform;
ChamberSlapPoint = new GameObject("tempChamberSlapPoint").transform;
MuzzleSlapPoint.parent = ((Component)flaregun.Muzzle).transform;
ChamberSlapPoint.parent = ((Component)flaregun.Chamber).transform;
MuzzleSlapPoint.localPosition = Vector3.zero;
ChamberSlapPoint.localPosition = Vector3.zero;
if ((int)flaregun.HingeAxis != 1)
{
if (flaregun.RotOut > 0f)
{
MuzzleSlapPoint.rotation = Quaternion.Euler(-90f, 0f, 0f);
ChamberSlapPoint.rotation = Quaternion.Euler(90f, 0f, 0f);
}
else
{
MuzzleSlapPoint.rotation = Quaternion.Euler(90f, 0f, 0f);
ChamberSlapPoint.rotation = Quaternion.Euler(-90f, 0f, 0f);
}
}
else if ((int)flaregun.HingeAxis == 1)
{
if (flaregun.RotOut > 0f)
{
MuzzleSlapPoint.rotation = Quaternion.Euler(0f, -90f, 0f);
ChamberSlapPoint.rotation = Quaternion.Euler(0f, 90f, 0f);
}
else
{
MuzzleSlapPoint.rotation = Quaternion.Euler(0f, 90f, 0f);
ChamberSlapPoint.rotation = Quaternion.Euler(0f, -90f, 0f);
}
}
}
if ((Object)(object)derringer != (Object)null && derringer.Barrels[0] != null && (Object)(object)derringer.Barrels[0].MuzzlePoint != (Object)null && (Object)(object)derringer.Barrels[0].Chamber != (Object)null)
{
MuzzleSlapPoint = new GameObject("tempMuzzleSlapPoint").transform;
ChamberSlapPoint = new GameObject("tempChamberSlapPoint").transform;
MuzzleSlapPoint.parent = ((Component)derringer.Barrels[0].MuzzlePoint).transform;
ChamberSlapPoint.parent = ((Component)derringer.Barrels[0].Chamber).transform;
MuzzleSlapPoint.localPosition = Vector3.zero;
ChamberSlapPoint.localPosition = Vector3.zero;
if ((int)derringer.Hinge_InterpStyle == 1)
{
if ((int)derringer.Hinge_Axis != 1)
{
if (derringer.HingeValues.y > derringer.HingeValues.x)
{
MuzzleSlapPoint.rotation = Quaternion.Euler(-90f, 0f, 0f);
ChamberSlapPoint.rotation = Quaternion.Euler(90f, 0f, 0f);
}
else
{
MuzzleSlapPoint.rotation = Quaternion.Euler(90f, 0f, 0f);
ChamberSlapPoint.rotation = Quaternion.Euler(-90f, 0f, 0f);
}
}
else if ((int)derringer.Hinge_Axis == 1)
{
if (derringer.HingeValues.y > derringer.HingeValues.x)
{
MuzzleSlapPoint.rotation = Quaternion.Euler(0f, -90f, 0f);
ChamberSlapPoint.rotation = Quaternion.Euler(0f, 90f, 0f);
}
else
{
MuzzleSlapPoint.rotation = Quaternion.Euler(0f, 90f, 0f);
ChamberSlapPoint.rotation = Quaternion.Euler(0f, -90f, 0f);
}
}
}
else if ((int)derringer.Hinge_InterpStyle == 0)
{
if ((int)derringer.Hinge_Axis == 0)
{
if (derringer.HingeValues.y > derringer.HingeValues.x)
{
MuzzleSlapPoint.rotation = Quaternion.Euler(0f, 90f, 0f);
ChamberSlapPoint.rotation = Quaternion.Euler(0f, 90f, 0f);
}
else
{
MuzzleSlapPoint.rotation = Quaternion.Euler(0f, -90f, 0f);
ChamberSlapPoint.rotation = Quaternion.Euler(0f, -90f, 0f);
}
}
else if ((int)derringer.Hinge_Axis == 1)
{
if (derringer.HingeValues.y > derringer.HingeValues.x)
{
MuzzleSlapPoint.rotation = Quaternion.Euler(90f, 0f, 0f);
ChamberSlapPoint.rotation = Quaternion.Euler(90f, 0f, 0f);
}
else
{
MuzzleSlapPoint.rotation = Quaternion.Euler(-90f, 0f, 0f);
ChamberSlapPoint.rotation = Quaternion.Euler(-90f, 0f, 0f);
}
}
else if ((int)derringer.Hinge_Axis == 2)
{
if (derringer.HingeValues.y > derringer.HingeValues.x)
{
MuzzleSlapPoint.rotation = Quaternion.Euler(0f, 0f, 0f);
ChamberSlapPoint.rotation = Quaternion.Euler(0f, 0f, 0f);
}
else
{
MuzzleSlapPoint.rotation = Quaternion.Euler(180f, 0f, 0f);
ChamberSlapPoint.rotation = Quaternion.Euler(180f, 0f, 0f);
}
}
}
}
if ((Object)(object)M320 != (Object)null && (Object)(object)((AttachableFirearm)M320).MuzzlePos != (Object)null && (Object)(object)M320.Chamber != (Object)null)
{
MuzzleSlapPoint = new GameObject("tempMuzzleSlapPoint").transform;
ChamberSlapPoint = new GameObject("tempChamberSlapPoint").transform;
MuzzleSlapPoint.parent = ((Component)((AttachableFirearm)M320).MuzzlePos).transform;
ChamberSlapPoint.parent = ((Component)M320.Chamber).transform;
MuzzleSlapPoint.localPosition = Vector3.zero;
ChamberSlapPoint.localPosition = Vector3.zero;
MuzzleSlapPoint.rotation = M320.InertialCloseDir.rotation * Quaternion.Euler(0f, 180f, 0f);
ChamberSlapPoint.rotation = M320.InertialCloseDir.rotation * Quaternion.Euler(0f, 0f, 0f);
}
}
public void Update()
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Invalid comparison between Unknown and I4
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_022e: Invalid comparison between Unknown and I4
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_028f: Unknown result type (might be due to invalid IL or missing references)
//IL_0294: Unknown result type (might be due to invalid IL or missing references)
//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
//IL_02df: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_049f: Unknown result type (might be due to invalid IL or missing references)
//IL_04a4: Unknown result type (might be due to invalid IL or missing references)
//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
//IL_04f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0331: Unknown result type (might be due to invalid IL or missing references)
//IL_0338: Unknown result type (might be due to invalid IL or missing references)
//IL_0526: Unknown result type (might be due to invalid IL or missing references)
//IL_052e: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)flaregun != (Object)null && (Object)(object)flaregun.Muzzle != (Object)null && (Object)(object)flaregun.Chamber != (Object)null)
{
if (((FVRInteractiveObject)flaregun).IsHeld && (int)flaregun.m_hingeState == 2 && flaregun.CanUnlatch && (Object)(object)((FVRInteractiveObject)flaregun).m_hand.OtherHand != (Object)null && (StiffHingeSlapper.AllowSlapWithoutEmptyHand.Value || (Object)(object)((FVRInteractiveObject)flaregun).m_hand.OtherHand.m_currentInteractable == (Object)null))
{
Vector3 velLinearWorld = ((FVRInteractiveObject)flaregun).m_hand.OtherHand.Input.VelLinearWorld;
float num = Vector3.Distance(((FVRInteractiveObject)flaregun).m_hand.OtherHand.PalmTransform.position, MuzzleSlapPoint.position);
float num2 = Vector3.Distance(((FVRInteractiveObject)flaregun).m_hand.OtherHand.PalmTransform.position, ChamberSlapPoint.position);
if ((num < StiffHingeSlapper.SlapDistance.Value && Vector3.Angle(velLinearWorld, MuzzleSlapPoint.forward) < StiffHingeSlapper.SlapAngle.Value && ((Vector3)(ref velLinearWorld)).magnitude > 1f) || (num2 < StiffHingeSlapper.SlapDistance.Value && Vector3.Angle(velLinearWorld, ChamberSlapPoint.forward) < StiffHingeSlapper.SlapAngle.Value && ((Vector3)(ref velLinearWorld)).magnitude > 1f))
{
flaregun.Latch();
}
}
}
else if ((Object)(object)derringer != (Object)null && derringer.Barrels[0] != null && (Object)(object)derringer.Barrels[0].MuzzlePoint != (Object)null && (Object)(object)derringer.Barrels[0].Chamber != (Object)null)
{
if (((FVRInteractiveObject)derringer).IsHeld && (int)derringer.m_hingeState == 2 && (Object)(object)((FVRInteractiveObject)derringer).m_hand.OtherHand != (Object)null && (StiffHingeSlapper.AllowSlapWithoutEmptyHand.Value || (Object)(object)((FVRInteractiveObject)derringer).m_hand.OtherHand.m_currentInteractable == (Object)null))
{
Vector3 velLinearWorld2 = ((FVRInteractiveObject)derringer).m_hand.OtherHand.Input.VelLinearWorld;
float num3 = Vector3.Distance(((FVRInteractiveObject)derringer).m_hand.OtherHand.PalmTransform.position, MuzzleSlapPoint.position);
float num4 = Vector3.Distance(((FVRInteractiveObject)derringer).m_hand.OtherHand.PalmTransform.position, ChamberSlapPoint.position);
if ((num3 < StiffHingeSlapper.SlapDistance.Value && Vector3.Angle(velLinearWorld2, MuzzleSlapPoint.forward) < StiffHingeSlapper.SlapAngle.Value && ((Vector3)(ref velLinearWorld2)).magnitude > 1f) || (num4 < StiffHingeSlapper.SlapDistance.Value && Vector3.Angle(velLinearWorld2, ChamberSlapPoint.forward) < StiffHingeSlapper.SlapAngle.Value && ((Vector3)(ref velLinearWorld2)).magnitude > 1f))
{
derringer.Latch();
}
}
}
else
{
if (!((Object)(object)M320 != (Object)null) || !((Object)(object)((AttachableFirearm)M320).MuzzlePos != (Object)null) || !((Object)(object)M320.Chamber != (Object)null))
{
return;
}
FVRViveHand val = null;
if (((FVRInteractiveObject)((AttachableFirearm)M320).Attachment).IsHeld)
{
val = ((FVRInteractiveObject)((AttachableFirearm)M320).Attachment).m_hand.OtherHand;
}
else if ((Object)(object)((FVRFireArmAttachment)((AttachableFirearm)M320).Attachment).curMount != (Object)null && (Object)(object)((FVRFireArmAttachment)((AttachableFirearm)M320).Attachment).curMount.GetRootMount().MyObject != (Object)null && ((FVRInteractiveObject)((FVRFireArmAttachment)((AttachableFirearm)M320).Attachment).curMount.GetRootMount().MyObject).IsHeld)
{
val = ((FVRInteractiveObject)((FVRFireArmAttachment)((AttachableFirearm)M320).Attachment).curMount.GetRootMount().MyObject).m_hand.OtherHand;
}
if (M320.m_isBreachOpen && (Object)(object)val != (Object)null && (StiffHingeSlapper.AllowSlapWithoutEmptyHand.Value || (Object)(object)val.m_currentInteractable == (Object)null))
{
Vector3 velLinearWorld3 = val.Input.VelLinearWorld;
float num5 = Vector3.Distance(val.PalmTransform.position, MuzzleSlapPoint.position);
float num6 = Vector3.Distance(val.PalmTransform.position, ChamberSlapPoint.position);
if ((num5 < StiffHingeSlapper.SlapDistance.Value && Vector3.Angle(velLinearWorld3, MuzzleSlapPoint.forward) < StiffHingeSlapper.SlapAngle.Value && ((Vector3)(ref velLinearWorld3)).magnitude > 1f) || (num6 < StiffHingeSlapper.SlapDistance.Value && Vector3.Angle(velLinearWorld3, ChamberSlapPoint.forward) < StiffHingeSlapper.SlapAngle.Value && ((Vector3)(ref velLinearWorld3)).magnitude > 1f))
{
M320.ToggleBreach();
}
}
}
}
}
public static class SlapPatch
{
[HarmonyPatch(typeof(Flaregun), "Awake")]
[HarmonyPostfix]
public static void FlaregunAwakePostfix(Flaregun __instance)
{
if ((Object)(object)((Component)__instance).gameObject.GetComponent<Slapper>() == (Object)null)
{
((Component)__instance).gameObject.AddComponent<Slapper>();
}
}
[HarmonyPatch(typeof(Derringer), "Awake")]
[HarmonyPostfix]
public static void DerringerAwakePostfix(Derringer __instance)
{
if ((Object)(object)((Component)__instance).gameObject.GetComponent<Slapper>() == (Object)null)
{
((Component)__instance).gameObject.AddComponent<Slapper>();
}
}
[HarmonyPatch(typeof(AttachableFirearm), "Awake")]
[HarmonyPostfix]
public static void AttachableFirearmAwakePostfix(AttachableFirearm __instance)
{
if (__instance is AttachableBreakActions && (Object)(object)((Component)__instance).gameObject.GetComponent<Slapper>() == (Object)null)
{
((Component)__instance).gameObject.AddComponent<Slapper>();
}
}
[HarmonyPatch(typeof(SteamVR_LoadLevel), "Begin")]
[HarmonyPrefix]
public static bool BeginPatch()
{
((BaseUnityPlugin)StiffHingeSlapper.Instance).Config.Reload();
return true;
}
}
}