using System; using System.Collections; 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("Temporarily disable the physical magazine latch on e.g. AKs after inserting a magazine so it won't get ejected immediately due to funny latch physics.")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("Niko666.CalmDownAKLatch")] [assembly: AssemblyTitle("CalmDownAKLatch")] [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.CalmDownAKLatch", "CalmDownAKLatch", "1.0.0")] public class CalmDownAKLatch : BaseUnityPlugin { public ConfigEntry configCooldownTime; public ConfigEntry configStiffenLatch; public ConfigEntry configLatchStiffness; public const string Id = "Niko666.CalmDownAKLatch"; public static CalmDownAKLatch Instance { get; private set; } internal static ManualLogSource Logger { get; private set; } public static string Name => "CalmDownAKLatch"; public static string Version => "1.0.0"; private void Awake() { Instance = this; Logger = ((BaseUnityPlugin)this).Logger; configCooldownTime = ((BaseUnityPlugin)this).Config.Bind("General", "CooldownTime", 1f, "Cooldown time before you can use the latch again"); configStiffenLatch = ((BaseUnityPlugin)this).Config.Bind("General", "StiffenLatch", false, "Stiffen the latch so it won't accidently eject the magazine when shaking the gun"); configLatchStiffness = ((BaseUnityPlugin)this).Config.Bind("General", "LatchStiffness", 500f, "Latch stiffness"); Harmony.CreateAndPatchAll(typeof(CalmDownAKLatchPatch), (string)null); Logger.LogMessage((object)("Hello, world! Sent from Niko666.CalmDownAKLatch " + Version)); } } internal static class CalmDownAKLatchPatch { private static bool _hasReleased; private static bool _isCooldown; public static IEnumerator DisableLatch(Collider[] collider) { yield return (object)new WaitForSeconds(CalmDownAKLatch.Instance.configCooldownTime.Value); for (int i = 0; i < collider.Length; i++) { collider[i].enabled = true; } _isCooldown = false; _hasReleased = false; } [HarmonyPatch(typeof(SteamVR_LoadLevel), "Begin")] [HarmonyPrefix] public static bool BeginPatch() { ((BaseUnityPlugin)CalmDownAKLatch.Instance).Config.Reload(); _hasReleased = false; _isCooldown = false; return true; } [HarmonyPatch(typeof(PhysicalMagazineReleaseLatch), "FixedUpdate")] [HarmonyPrefix] public static bool UpdatePatch(PhysicalMagazineReleaseLatch __instance) { //IL_0017: 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_0039: Unknown result type (might be due to invalid IL or missing references) if (CalmDownAKLatch.Instance.configStiffenLatch.Value) { JointSpring spring = __instance.Joint.spring; spring.spring = CalmDownAKLatch.Instance.configLatchStiffness.Value; __instance.Joint.spring = spring; } Collider[] componentsInChildren = ((Component)__instance).GetComponentsInChildren(); if ((Object)(object)__instance.FireArm.Magazine == (Object)null) { _hasReleased = true; Collider[] array = componentsInChildren; for (int i = 0; i < array.Length; i++) { array[i].enabled = false; } } if ((Object)(object)__instance.FireArm.Magazine != (Object)null && _hasReleased && !_isCooldown) { _isCooldown = true; ((MonoBehaviour)__instance).StartCoroutine(DisableLatch(componentsInChildren)); } return true; } } }