Decompiled source of MagBoop v1.4.2

MagBoop.dll

Decompiled 11 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using FistVR;
using HarmonyLib;
using Newtonsoft.Json;
using Stovepipe;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("MagBoop")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MagBoop")]
[assembly: AssemblyTitle("MagBoop")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace MagBoop.ModFiles;

public class MagazineBoopComponent : MonoBehaviour
{
	public MagTriggerScript thisMagTrigger;

	public bool hasAlreadyAdjustedTrigger;
}
public class MagTriggerScript : FVRInteractiveObject
{
	public FVRFireArmMagazine thisMagScript;

	public AudioImpactController thisController;

	public bool insertsAboveWeapon;

	private const float MinSpeed = 0.001f;

	private const float MaxSpeed = 0.05f;

	private const float VolumeVariance = 2f;

	public const float PitchVariance = 0.4f;

	private static float _currentInvLerpOfSpeed;

	public bool isUnSeated;

	public bool hasStartedMagNoiseTimer;

	public const float SoundCooldown = 0.2f;

	public float soundCooldownTimer;

	private float _timeTillResetAudioTimer;

	private FVRPooledAudioSource _pooledAudioSource;

	private bool _hasFoundPooledAudioSource;

	private bool _hasResetAudioTimer;

	public bool hasAlreadyTappedOnce;

	protected override void Start()
	{
		Transform parent = ((Component)this).transform.parent;
		thisMagScript = ((Component)parent).GetComponent<FVRFireArmMagazine>();
		thisController = ((Component)parent).GetComponent<AudioImpactController>();
		((FVRInteractiveObject)this).Start();
	}

	public void StartCooldownTimer()
	{
		soundCooldownTimer = 0.2f;
	}

	public override bool IsInteractable()
	{
		return false;
	}

	private void Update()
	{
		if (soundCooldownTimer > 0f)
		{
			soundCooldownTimer -= Time.fixedDeltaTime;
		}
		if (_timeTillResetAudioTimer > 0f)
		{
			_timeTillResetAudioTimer -= Time.fixedDeltaTime;
		}
		else if (!_hasResetAudioTimer && _hasFoundPooledAudioSource)
		{
			ResetAudioAndAudioTimer();
		}
	}

	private void ResetAudioAndAudioTimer()
	{
		if (!((Object)(object)_pooledAudioSource == (Object)null))
		{
			_pooledAudioSource.Source.Stop();
			_pooledAudioSource.Source.time = 0f;
			_pooledAudioSource.Source.pitch = 1f;
			_hasResetAudioTimer = true;
		}
	}

	public void ReSeatMagazine()
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		if (isUnSeated && !((Object)(object)thisMagScript == (Object)null))
		{
			Vector3 position = thisMagScript.FireArm.GetMagMountPos(thisMagScript.IsBeltBox).position;
			if (Random.Range(0f, 1f) < UserConfig.MagRequiresTwoTapsProbability.Value && !hasAlreadyTappedOnce)
			{
				((Component)thisMagScript).transform.position = Vector3.Lerp(((Component)thisMagScript).transform.position, position, 0.5f);
				hasAlreadyTappedOnce = true;
			}
			else
			{
				((Component)thisMagScript).transform.position = position;
				isUnSeated = false;
			}
		}
	}

	public void CheckAndPlayBoopSound(FVRViveHand hand)
	{
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Invalid comparison between Unknown and I4
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: 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_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: 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_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		if (soundCooldownTimer > 0f || hand.Input.GripPressed)
		{
			return;
		}
		Rigidbody component = ((Component)hand).GetComponent<Rigidbody>();
		if ((Object)(object)thisMagScript.FireArm == (Object)null || ((Object)(object)((FVRPhysicalObject)thisMagScript.FireArm).QuickbeltSlot != (Object)null && !((FVRInteractiveObject)thisMagScript.FireArm).IsHeld && (int)GM.Options.MovementOptions.CurrentMovementMode == 4) || (Object)(object)hand.CurrentInteractable != (Object)null)
		{
			return;
		}
		Rigidbody rootRigidbody = ((FVRPhysicalObject)thisMagScript.FireArm).RootRigidbody;
		float num = Vector3.Dot(component.velocity - rootRigidbody.velocity, ((Component)thisMagScript.FireArm).transform.up);
		if (insertsAboveWeapon)
		{
			num *= -1f;
		}
		if (num < 0.002f || num < 0f)
		{
			return;
		}
		if (UserConfig.EnableMagUnSeating.Value)
		{
			ReSeatMagazine();
		}
		hand.Buzz(hand.Buzzer.Buzz_BeginInteraction);
		AudioImpactIntensity val = (AudioImpactIntensity)1;
		if (num > 0.015f)
		{
			val = (AudioImpactIntensity)2;
		}
		Vector3 val2 = component.velocity - rootRigidbody.velocity;
		float magnitude = ((Vector3)(ref val2)).magnitude;
		if (!((double)num < 0.5 * (double)magnitude))
		{
			_currentInvLerpOfSpeed = Mathf.InverseLerp(0.001f, 0.05f, num);
			float num2 = 3f + _currentInvLerpOfSpeed * 2f;
			float num3 = 1f + Random.Range(0f, 0.4f);
			if (insertsAboveWeapon && UserConfig.UseThirdLaw.Value)
			{
				ImpartTorqueOnWeapon(component, magnitude, -((Component)thisMagScript.FireArm).transform.up);
			}
			else if (UserConfig.UseThirdLaw.Value)
			{
				ImpartTorqueOnWeapon(component, magnitude, ((Component)thisMagScript.FireArm).transform.up);
			}
			if (UserConfig.UseOldSounds.Value)
			{
				SM.PlayImpactSound(thisController.ImpactType, (MatSoundType)2, val, ((Component)this).transform.parent.position, thisController.PoolToUse, thisController.DistLimit, num2, num3);
			}
			else
			{
				PlayEndOfMagInsertionNoise(num3);
			}
			StartCooldownTimer();
		}
	}

	private void ImpartTorqueOnWeapon(Rigidbody handRb, float handVelocityMag, Vector3 boopDir)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		Rigidbody rootRigidbody = ((FVRPhysicalObject)thisMagScript.FireArm).RootRigidbody;
		Vector3 val = 10f * UserConfig.ThirdLawPower.Value * handVelocityMag * boopDir;
		Vector3 val2 = Vector3.Cross(((Component)rootRigidbody).transform.position - ((Component)handRb).transform.position, val);
		if (Object.op_Implicit((Object)(object)rootRigidbody))
		{
			rootRigidbody.AddTorque(val2, (ForceMode)0);
		}
	}

	public void PlayEndOfMagInsertionNoise(float randomPitch)
	{
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		if (!thisMagScript.UsesOverrideInOut)
		{
			_pooledAudioSource = thisMagScript.FireArm.PlayAudioAsHandling(thisMagScript.Profile.MagazineIn, ((Component)thisMagScript.FireArm).transform.position);
		}
		else
		{
			_pooledAudioSource = thisMagScript.FireArm.PlayAudioAsHandling(thisMagScript.ProfileOverride.MagazineIn, ((Component)thisMagScript.FireArm).transform.position);
			if (_pooledAudioSource == null)
			{
				_pooledAudioSource = thisMagScript.FireArm.PlayAudioAsHandling(thisMagScript.Profile.MagazineIn, ((Component)thisMagScript.FireArm).transform.position);
			}
		}
		if (_pooledAudioSource == null)
		{
			thisMagScript.FireArm.PlayAudioEvent((FirearmAudioEventType)20, 1f);
			return;
		}
		_hasFoundPooledAudioSource = true;
		_pooledAudioSource.Source.Stop();
		_pooledAudioSource.Source.volume = 1f;
		_pooledAudioSource.Source.time = 0.1f * _pooledAudioSource.Source.clip.length;
		_pooledAudioSource.Source.pitch = randomPitch;
		_pooledAudioSource.Source.Play();
		_timeTillResetAudioTimer = _pooledAudioSource.Source.clip.length * 0.9f;
		_hasResetAudioTimer = false;
	}
}
public class SlideTriggerScript : MonoBehaviour
{
	private HandgunSlide slideScript;

	private void Start()
	{
		slideScript = ((Component)((Component)this).transform.parent).GetComponent<HandgunSlide>();
	}

	public void CheckSlideBoop(FVRViveHand hand)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Invalid comparison between Unknown and I4
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		if (((Object)(object)((FVRPhysicalObject)slideScript.Handgun).QuickbeltSlot != (Object)null && !((FVRInteractiveObject)slideScript.Handgun).IsHeld && (int)GM.Options.MovementOptions.CurrentMovementMode == 4) || (Object)(object)hand.CurrentInteractable != (Object)null || hand.Input.GripPressed)
		{
			return;
		}
		Rigidbody component = ((Component)hand).GetComponent<Rigidbody>();
		Vector3 val = component.velocity - ((FVRPhysicalObject)slideScript.Handgun).RootRigidbody.velocity;
		if (!(Vector3.Dot(val, ((Component)this).transform.forward) > 0.003f) || Vector3.Dot(val, ((Component)this).transform.forward) < 0.5f * ((Vector3)(ref val)).magnitude)
		{
			return;
		}
		hand.Buzz(hand.Buzzer.Buzz_BeginInteraction);
		StovepipeData component2 = ((Component)((Component)this).transform.parent).GetComponent<StovepipeData>();
		float num = 1f + Random.Range(0f, 0.4f);
		if (UserConfig.UseThirdLaw.Value)
		{
			ImpartTorqueOnWeapon(component, ((Vector3)(ref val)).magnitude, ((Component)this).transform.forward);
		}
		if ((Object)(object)component2 != (Object)null)
		{
			if (component2.isWeaponBatteryFailing)
			{
				((FVRFireArm)slideScript.Handgun).PlayAudioEvent((FirearmAudioEventType)0, num);
			}
			else
			{
				((FVRFireArm)slideScript.Handgun).PlayAudioEvent((FirearmAudioEventType)2, num);
			}
			component2.isWeaponBatteryFailing = false;
		}
		else
		{
			((FVRFireArm)slideScript.Handgun).PlayAudioEvent((FirearmAudioEventType)2, num);
		}
	}

	private void ImpartTorqueOnWeapon(Rigidbody handRb, float handVelocityMag, Vector3 boopDir)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: 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)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: 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)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		Rigidbody rootRigidbody = ((FVRPhysicalObject)slideScript.Handgun).RootRigidbody;
		if (Object.op_Implicit((Object)(object)rootRigidbody))
		{
			Vector3 val = UserConfig.ThirdLawPower.Value * 30f * handVelocityMag * boopDir;
			Vector3 val2 = Vector3.Cross(((Component)rootRigidbody).transform.position - ((Component)handRb).transform.position, val);
			rootRigidbody.AddTorque(val2, (ForceMode)0);
		}
	}
}
[BepInPlugin("dll.smidgeon.magboop", "Mag Boop", "1.1.0")]
[BepInProcess("h3vr.exe")]
public class MagBoopManager : BaseUnityPlugin
{
	private static FVRPooledAudioSource _currentMagSoundSource;

	private static float _defaultMagSoundVolume;

	private static float _timeLeft;

	private static float _timeUntilFadeOut;

	private static bool _hasStoppedSound = true;

	public static string[] ExcludedWeaponNames = new string[3] { "VZ58_P", "VZ58_V", "AKM" };

	private void Start()
	{
		GenerateUserConfigs();
		ReadOrCreateExclusionList();
		if (UserConfig.EnableMagTapping.Value)
		{
			Harmony.CreateAndPatchAll(typeof(HandPatch), (string)null);
			Harmony.CreateAndPatchAll(typeof(MagazineTriggerPatches), (string)null);
		}
		if (UserConfig.EnableMagUnSeating.Value)
		{
			Harmony.CreateAndPatchAll(typeof(MagazineUnseatingPatches), (string)null);
			Harmony.CreateAndPatchAll(typeof(DisableChamberingPatches), (string)null);
		}
		if (UserConfig.EnableSlideTapping.Value)
		{
			Harmony.CreateAndPatchAll(typeof(SlideTriggerPatches), (string)null);
		}
	}

	private void Update()
	{
		if (UserConfig.EnableMagUnSeating.Value && !_hasStoppedSound)
		{
			if (_timeLeft < 0f)
			{
				_currentMagSoundSource.Source.Stop();
				_currentMagSoundSource.Source.volume = _defaultMagSoundVolume;
				_hasStoppedSound = true;
			}
			if (_timeLeft < _timeUntilFadeOut)
			{
				_currentMagSoundSource.Source.volume = _defaultMagSoundVolume * Time.deltaTime / _timeUntilFadeOut;
			}
			_timeLeft -= Time.deltaTime;
		}
	}

	private void GenerateUserConfigs()
	{
		UserConfig.EnableMagTapping = ((BaseUnityPlugin)this).Config.Bind<bool>("Activation", "Enable Mag Tapping", true, "This enables the mag tapping aspect of the mod.");
		UserConfig.EnableMagUnSeating = ((BaseUnityPlugin)this).Config.Bind<bool>("Activation", "Enable Mag Unseating", true, "This enables the mag to be unseated, based on random chance as well as how fast / hard you push the magazine in.");
		UserConfig.EnableCustomSounds = ((BaseUnityPlugin)this).Config.Bind<bool>("Activation", "Enable Custom Sounds", true, "This enables the custom sounds, which should hopefully be better than the default sounds.");
		UserConfig.EnableSlideTapping = ((BaseUnityPlugin)this).Config.Bind<bool>("Activation", "Enable Slide Tapping", true, "This is enables the ability to tap the slide to make sure its totally forward. Useful when using Stovepipe + it's new failure to enter battery");
		UserConfig.EnableTriggerDebug = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Enable Mag Debug Cubes", false, "This is enables the weird white cubes where the boop trigger is located, can be used to see if the magazine you are using has it properly located.");
		UserConfig.MagUnseatedProbability = ((BaseUnityPlugin)this).Config.Bind<float>("Probabilities", "Probability of Being Unseated", 0.1f, "This is the base probability that the magazine will be seated incorrectly even if you push it in with decent force.");
		UserConfig.SlowSpeedUnseatingProbability = ((BaseUnityPlugin)this).Config.Bind<float>("Probabilities", "Probability of mag being unseated when inserted SLOWLY", 0.5f, "This is the base probability that the magazine will be seated incorrectly if you insert it really slowly.");
		UserConfig.DoubleFeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Probabilities", "Double Feed Probability Multiplier", 5f, "This is the multiplier applied to the double feeding chance of a weapon that has a magazine which isn't seated properly.");
		UserConfig.MagRequiresTwoTapsProbability = ((BaseUnityPlugin)this).Config.Bind<float>("Probabilities", "Magazine Requires Two Taps Probability", 0.3f, "This is the probability a single tap will not fully seat the magazine back into place.");
		UserConfig.UseOldSounds = ((BaseUnityPlugin)this).Config.Bind<bool>("Old Sounds", "Use Old Sounds", false, "This enables the old sounds.");
		UserConfig.HandgunProbability = ((BaseUnityPlugin)this).Config.Bind<float>("Specific Weapon Type Probabilities", "Handgun", 0.5f, "This is a modifier for how often the mag should be unseated for each type of weapon.");
		UserConfig.OpenBoltProbability = ((BaseUnityPlugin)this).Config.Bind<float>("Specific Weapon Type Probabilities", "Open Bolt", 1f, "This is a modifier for how often the mag should be unseated for each type of weapon.");
		UserConfig.ClosedBoltProbability = ((BaseUnityPlugin)this).Config.Bind<float>("Specific Weapon Type Probabilities", "Closed Bolt", 1f, "This is a modifier for how often the mag should be unseated for each type of weapon.");
		UserConfig.TubeFedShotgunProbability = ((BaseUnityPlugin)this).Config.Bind<float>("Specific Weapon Type Probabilities", "Tube Fed Shotguns", 1f, "This is a modifier for how often the mag should be unseated for each type of weapon.");
		UserConfig.DisableForBeltFeds = ((BaseUnityPlugin)this).Config.Bind<bool>("Disabling", "Disable for all belt-fed weapons.", true, "This allows you to stop the mag unseating for belt-fed weapons.");
		UserConfig.HKProbBoltClosed = ((BaseUnityPlugin)this).Config.Bind<float>("Probabilities Modifiers", "Probability modifier for unseating when BOLT CLOSED (HK)", 1.75f, "Probability modifier that the magazine won't enter correctly for HK-style weapons when the bolt is CLOSED (makes it harder for magazine to enter).");
		UserConfig.GenericProbBoltClosed = ((BaseUnityPlugin)this).Config.Bind<float>("Probabilities Modifiers", "Probability modifier for unseating when BOLT CLOSED (Generic Closed Bolt Weapons)", 1.2f, "Probability modifier that the magazine won't enter correctly for normal closed bolt weapons when the bolt is CLOSED (makes it harder for magazine to enter).");
		UserConfig.UseThirdLaw = ((BaseUnityPlugin)this).Config.Bind<bool>("Third Law Implementation", "Enable Third Law Jiggle", true, "This is the thing that causes the weapon to shake when you boop.");
		UserConfig.ThirdLawPower = ((BaseUnityPlugin)this).Config.Bind<float>("Third Law Implementation", "The size of the jiggle, default 30f", 30f, "This is the thing that causes the weapon to shake when you boop.");
	}

	public static void StartMagNoiseTimer(FVRPooledAudioSource source, float time)
	{
		_currentMagSoundSource = source;
		_timeLeft = time;
		_hasStoppedSound = false;
		_timeUntilFadeOut = time / 2f;
		_defaultMagSoundVolume = source.Source.volume;
	}

	private static void ReadOrCreateExclusionList()
	{
		string text = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/StovepipeData/";
		string path = text + "MagBoopExclusions.json";
		if (!File.Exists(text))
		{
			Directory.CreateDirectory(text);
		}
		if (!File.Exists(path))
		{
			File.Create(path).Dispose();
			File.WriteAllText(path, JsonConvert.SerializeObject((object)ExcludedWeaponNames));
		}
		else
		{
			ExcludedWeaponNames = JsonConvert.DeserializeObject<string[]>(File.ReadAllText(path));
		}
	}
}
public class DisableChamberingPatches
{
	[HarmonyPatch(typeof(ClosedBolt), "BoltEvent_ExtractRoundFromMag")]
	[HarmonyPrefix]
	private static bool StopFromLoadingRoundIfMagIsFullyUnSeated(ClosedBolt __instance)
	{
		if ((Object)(object)((FVRFireArm)__instance.Weapon).Magazine == (Object)null)
		{
			return true;
		}
		MagazineBoopComponent component = ((Component)((FVRFireArm)__instance.Weapon).Magazine).GetComponent<MagazineBoopComponent>();
		if ((Object)(object)component == (Object)null)
		{
			return true;
		}
		if (component.thisMagTrigger.isUnSeated && !component.thisMagTrigger.hasAlreadyTappedOnce && UserConfig.EnableMagUnSeating.Value)
		{
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(HandgunSlide), "SlideEvent_ExtractRoundFromMag")]
	[HarmonyPrefix]
	private static bool StopFromLoadingRoundIfMagIsFullyUnSeated(HandgunSlide __instance)
	{
		if ((Object)(object)((FVRFireArm)__instance.Handgun).Magazine == (Object)null)
		{
			return true;
		}
		MagazineBoopComponent component = ((Component)((FVRFireArm)__instance.Handgun).Magazine).GetComponent<MagazineBoopComponent>();
		if ((Object)(object)component == (Object)null)
		{
			return true;
		}
		if (component.thisMagTrigger.isUnSeated && !component.thisMagTrigger.hasAlreadyTappedOnce && UserConfig.EnableMagUnSeating.Value)
		{
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(OpenBoltReceiverBolt), "BoltEvent_BeginChambering")]
	[HarmonyPrefix]
	private static bool StopFromLoadingRoundIfMagIsFullyUnSeated(OpenBoltReceiverBolt __instance)
	{
		if ((Object)(object)((FVRFireArm)__instance.Receiver).Magazine == (Object)null)
		{
			return true;
		}
		MagazineBoopComponent component = ((Component)((FVRFireArm)__instance.Receiver).Magazine).GetComponent<MagazineBoopComponent>();
		if ((Object)(object)component == (Object)null)
		{
			return true;
		}
		if (component.thisMagTrigger.isUnSeated && !component.thisMagTrigger.hasAlreadyTappedOnce && UserConfig.EnableMagUnSeating.Value)
		{
			return false;
		}
		return true;
	}
}
public class HandPatch
{
	[HarmonyPatch(typeof(FVRViveHand), "TestCollider")]
	[HarmonyPostfix]
	private static void CheckCol(FVRViveHand __instance, Collider collider, bool isEnter)
	{
		if (!isEnter)
		{
			return;
		}
		MagTriggerScript component = ((Component)collider).GetComponent<MagTriggerScript>();
		if ((Object)(object)component != (Object)null)
		{
			if (!((Object)(object)((Component)((Component)component).transform.parent).GetComponent<FVRFireArmMagazine>().FireArm == (Object)(object)__instance.CurrentInteractable))
			{
				component.CheckAndPlayBoopSound(__instance);
			}
			return;
		}
		SlideTriggerScript component2 = ((Component)collider).GetComponent<SlideTriggerScript>();
		if ((Object)(object)component2 != (Object)null)
		{
			component2.CheckSlideBoop(__instance);
		}
	}
}
public class MagazineTriggerPatches
{
	[HarmonyPatch(typeof(FVRFireArmMagazine), "Load", new Type[] { typeof(FVRFireArm) })]
	[HarmonyPostfix]
	private static void StopFromBoopingOnMagLoad(FVRFireArmMagazine __instance)
	{
		((Component)__instance).GetComponent<MagazineBoopComponent>()?.thisMagTrigger.StartCooldownTimer();
	}

	[HarmonyPatch(typeof(FVRFireArmMagazine), "Release")]
	[HarmonyPatch(typeof(FVRFireArmMagazine), "ReleaseFromAttachableFireArm")]
	[HarmonyPatch(typeof(FVRFireArmMagazine), "ReleaseFromSecondarySlot")]
	[HarmonyPrefix]
	private static void StopFromBoopingAfterMagRelease(FVRFireArmMagazine __instance)
	{
		MagazineBoopComponent component = ((Component)__instance).GetComponent<MagazineBoopComponent>();
		if (component != null)
		{
			component.thisMagTrigger.StartCooldownTimer();
			if (component.thisMagTrigger.isUnSeated)
			{
				component.thisMagTrigger.isUnSeated = false;
			}
		}
	}

	[HarmonyPatch(typeof(FVRFireArm), "Fire")]
	[HarmonyPostfix]
	private static void StopFromBoopingIfJustShot(FVRFireArm __instance)
	{
		if (!((Object)(object)__instance.Magazine == (Object)null))
		{
			((Component)__instance.Magazine).GetComponent<MagazineBoopComponent>()?.thisMagTrigger.StartCooldownTimer();
		}
	}

	[HarmonyPatch(typeof(FVRFireArmMagazine), "Awake")]
	[HarmonyPostfix]
	public static void AddOrSwapOrientationOfImpactProxy(FVRFireArmMagazine __instance)
	{
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		if (__instance.IsIntegrated || __instance.IsEnBloc || ((Object)((Component)__instance).gameObject).name == "G11_Mag(Clone)")
		{
			return;
		}
		MagazineBoopComponent component = ((Component)__instance).GetComponent<MagazineBoopComponent>();
		if ((Object)(object)component != (Object)null && component.hasAlreadyAdjustedTrigger)
		{
			return;
		}
		BoxCollider val = FindLowestCollider(__instance);
		if ((Object)(object)val == (Object)null)
		{
			Debug.Log((object)("No magboop trigger could be identified for " + ((Object)__instance).name));
			return;
		}
		Transform val2 = ((Component)__instance).transform.FindChild("MagBoopObj");
		if ((Object)(object)val2 != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)val2).gameObject);
			val = FindHighestCollider(__instance);
			((Component)__instance).GetComponent<MagazineBoopComponent>().hasAlreadyAdjustedTrigger = true;
		}
		BoxCollider triggerCol;
		BoxCollider magCollider;
		MagazineBoopComponent magBoopComp;
		GameObject interactionObj = GenerateInteractionObjAndAddMagDataClass(__instance, out triggerCol, out magCollider, out magBoopComp);
		if ((Object)(object)magCollider == (Object)null)
		{
			Collider component2 = ((Component)__instance).GetComponent<Collider>();
			if (component2 is CapsuleCollider)
			{
				GenerateCapsuleMagazineTrigger(__instance, triggerCol, interactionObj);
			}
			else if (component2 is SphereCollider)
			{
				GenerateSphereMagazineTrigger(__instance, triggerCol, interactionObj);
			}
			if (UserConfig.EnableTriggerDebug.Value)
			{
				GenerateDebugCube(interactionObj, triggerCol);
			}
		}
		else
		{
			GenerateBoxMagazineTrigger(triggerCol, magCollider.size, interactionObj, magBoopComp, val);
			if (UserConfig.EnableTriggerDebug.Value)
			{
				GenerateDebugCube(interactionObj, triggerCol);
			}
		}
	}

	[HarmonyPatch(typeof(FVRFireArmMagazine), "Load", new Type[] { typeof(FVRFireArm) })]
	[HarmonyPostfix]
	private static void AdjustPositionOfTriggerIfTopLoad(FVRFireArmMagazine __instance)
	{
		MagazineBoopComponent component = ((Component)__instance).GetComponent<MagazineBoopComponent>();
		if (component != null && component.thisMagTrigger.insertsAboveWeapon)
		{
			AddOrSwapOrientationOfImpactProxy(__instance);
		}
	}

	private static void GenerateBoxMagazineTrigger(BoxCollider triggerCol, Vector3 magSize, GameObject interactionObj, MagazineBoopComponent magBoopComp, BoxCollider topOrBottomCol)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Invalid comparison between Unknown and I4
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: 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_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		triggerCol.center = Vector3.zero;
		triggerCol.size = new Vector3(magSize.x, 0.045f, magSize.z);
		((Collider)triggerCol).isTrigger = true;
		if ((Object)(object)GM.CurrentPlayerBody.LeftHand != (Object)null && (int)((Component)GM.CurrentPlayerBody.LeftHand).GetComponent<FVRViveHand>().DMode == 30)
		{
			triggerCol.size = new Vector3(triggerCol.size.x, 0.17f, triggerCol.size.z);
		}
		Vector3 val = -Vector3.forward * (float)Math.Tan(interactionObj.transform.localRotation.x) * (magSize.y / 2f + 0.04f);
		interactionObj.transform.localRotation = ((Component)topOrBottomCol).transform.localRotation;
		if (!magBoopComp.hasAlreadyAdjustedTrigger)
		{
			interactionObj.transform.localPosition = ColliderLocalLowestPos(topOrBottomCol) + val;
		}
		else
		{
			interactionObj.transform.localPosition = ColliderLocalHighestPos(topOrBottomCol) - val;
		}
	}

	public static void GenerateDebugCube(GameObject interactionObj, BoxCollider triggerCol)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
		val.transform.parent = interactionObj.transform;
		val.transform.localScale = triggerCol.size;
		val.transform.localPosition = Vector3.zero;
		val.transform.localRotation = Quaternion.Euler(Vector3.zero);
		val.GetComponent<Collider>().enabled = false;
	}

	private static GameObject GenerateInteractionObjAndAddMagDataClass(FVRFireArmMagazine mag, out BoxCollider triggerCol, out BoxCollider magCollider, out MagazineBoopComponent magBoopComp)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		GameObject val = new GameObject("MagBoopObj");
		val.transform.parent = ((Component)mag).transform;
		val.transform.localRotation = Quaternion.Euler(Vector3.zero);
		val.layer = LayerMask.NameToLayer("Interactable");
		GameObject val2 = val;
		triggerCol = val2.AddComponent<BoxCollider>();
		magCollider = ((Component)mag).GetComponent<BoxCollider>();
		MagTriggerScript thisMagTrigger = val2.AddComponent<MagTriggerScript>();
		magBoopComp = ((Component)mag).gameObject.GetComponent<MagazineBoopComponent>() ?? ((Component)mag).gameObject.AddComponent<MagazineBoopComponent>();
		magBoopComp.thisMagTrigger = thisMagTrigger;
		return val2;
	}

	private static void GenerateCapsuleMagazineTrigger(FVRFireArmMagazine mag, BoxCollider triggerCol, GameObject interactionObj)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: 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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		CapsuleCollider component = ((Component)mag).GetComponent<CapsuleCollider>();
		triggerCol.center = Vector3.zero;
		triggerCol.size = new Vector3(component.radius, 0.02f, component.height / 2f);
		((Collider)triggerCol).isTrigger = true;
		interactionObj.transform.localPosition = Vector3.zero - Vector3.up * component.radius * interactionObj.transform.localScale.y - Vector3.forward * component.height * interactionObj.transform.localScale.y / 4f;
	}

	private static void GenerateSphereMagazineTrigger(FVRFireArmMagazine mag, BoxCollider triggerCol, GameObject interactionObj)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		SphereCollider component = ((Component)mag).GetComponent<SphereCollider>();
		triggerCol.center = Vector3.zero;
		float radius = component.radius;
		triggerCol.size = new Vector3(radius, 0.02f, radius);
		((Collider)triggerCol).isTrigger = true;
		interactionObj.transform.localPosition = Vector3.zero - Vector3.up * radius * interactionObj.transform.localScale.y;
	}

	private static Vector3 ColliderLocalLowestPos(BoxCollider boxCol)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: 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_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		return ((Component)boxCol).transform.localPosition + (boxCol.center - Vector3.up * boxCol.size.y / 2f) * ((Component)boxCol).transform.localScale.y;
	}

	private static Vector3 ColliderLocalHighestPos(BoxCollider boxCol)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: 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_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		return ((Component)boxCol).transform.localPosition + (boxCol.center + Vector3.up * boxCol.size.y / 2f) * ((Component)boxCol).transform.localScale.y;
	}

	private static BoxCollider FindLowestCollider(FVRFireArmMagazine mag)
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		BoxCollider val = null;
		BoxCollider[] componentsInChildren = ((Component)mag).GetComponentsInChildren<BoxCollider>();
		BoxCollider[] array = componentsInChildren;
		foreach (BoxCollider val2 in array)
		{
			if (!((Object)(object)((Component)val2).transform == (Object)(object)((Component)mag).transform))
			{
				if (val == null)
				{
					val = val2;
				}
				else if (ColliderLocalLowestPos(val2).y < ColliderLocalLowestPos(val).y)
				{
					val = val2;
				}
			}
		}
		return val;
	}

	private static BoxCollider FindHighestCollider(FVRFireArmMagazine mag)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		BoxCollider val = null;
		BoxCollider[] componentsInChildren = ((Component)mag).GetComponentsInChildren<BoxCollider>();
		BoxCollider[] array = componentsInChildren;
		foreach (BoxCollider val2 in array)
		{
			if (val == null)
			{
				val = val2;
			}
			else if (ColliderLocalLowestPos(val2).y > ColliderLocalLowestPos(val).y)
			{
				val = val2;
			}
		}
		return val;
	}
}
public class MagazineUnseatingPatches
{
	private static FVRFireArm _currentUnSeatedWeapon;

	[HarmonyPatch(typeof(FVRFireArmMagazine), "Load", new Type[] { typeof(FVRFireArm) })]
	[HarmonyPrefix]
	private static void UnSeatMagDiceRoll(FVRFireArmMagazine __instance, FVRFireArm fireArm)
	{
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: 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_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Invalid comparison between Unknown and I4
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Invalid comparison between Unknown and I4
		if (!__instance.IsExtractable || __instance.IsEnBloc || (UserConfig.DisableForBeltFeds.Value && fireArm.UsesBeltBoxes))
		{
			return;
		}
		ClosedBoltWeapon val = (ClosedBoltWeapon)(object)((fireArm is ClosedBoltWeapon) ? fireArm : null);
		if ((val != null && val.Bolt.UsesAKSafetyLock) || MagBoopManager.ExcludedWeaponNames.Contains(((Object)fireArm).name.Remove(((Object)fireArm).name.Length - 7)))
		{
			return;
		}
		MagazineBoopComponent component = ((Component)__instance).GetComponent<MagazineBoopComponent>();
		if (component == null || component.thisMagTrigger.isUnSeated)
		{
			return;
		}
		float num = 1f;
		if (!(fireArm is Handgun))
		{
			if (!(fireArm is OpenBoltReceiver))
			{
				ClosedBoltWeapon val2 = (ClosedBoltWeapon)(object)((fireArm is ClosedBoltWeapon) ? fireArm : null);
				if (val2 != null)
				{
					num = (((Object)(object)val2.Handle == (Object)null) ? UserConfig.ClosedBoltProbability.Value : ((val2.Handle.IsSlappable && (int)val2.Bolt.CurPos == 0) ? UserConfig.HKProbBoltClosed.Value : (((int)val2.Bolt.CurPos != 0) ? UserConfig.ClosedBoltProbability.Value : UserConfig.GenericProbBoltClosed.Value)));
				}
				else if (fireArm is TubeFedShotgun)
				{
					num = UserConfig.TubeFedShotgunProbability.Value;
				}
			}
			else
			{
				num = UserConfig.OpenBoltProbability.Value;
			}
		}
		else
		{
			num = UserConfig.HandgunProbability.Value;
		}
		FVRViveHand hand = ((FVRInteractiveObject)__instance).m_hand;
		if (hand != null)
		{
			Vector3 val3 = ((Component)hand).GetComponent<Rigidbody>().velocity - ((FVRPhysicalObject)fireArm).RootRigidbody.velocity;
			float magnitude = ((Vector3)(ref val3)).magnitude;
			float num2 = Mathf.InverseLerp(0.02f, 0.2f, Mathf.Abs(magnitude));
			float num3 = Mathf.Lerp(UserConfig.SlowSpeedUnseatingProbability.Value, UserConfig.MagUnseatedProbability.Value, num2);
			if (Random.Range(0f, 1f) < num3 * num)
			{
				component.thisMagTrigger.isUnSeated = true;
				component.thisMagTrigger.hasStartedMagNoiseTimer = false;
				_currentUnSeatedWeapon = fireArm;
				component.thisMagTrigger.hasAlreadyTappedOnce = false;
			}
		}
	}

	[HarmonyPatch(typeof(FVRFireArmMagazine), "Load", new Type[] { typeof(FVRFireArm) })]
	[HarmonyPostfix]
	private static void UnSeatMag(FVRFireArmMagazine __instance)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		MagazineBoopComponent component = ((Component)__instance).GetComponent<MagazineBoopComponent>();
		if (component != null && component.thisMagTrigger.isUnSeated)
		{
			Transform transform = ((Component)__instance).transform;
			component.thisMagTrigger.insertsAboveWeapon = Vector3.Dot(((Component)__instance).transform.up, ((Component)__instance.FireArm).transform.up) < -0.2f;
			if (!component.thisMagTrigger.insertsAboveWeapon)
			{
				component.thisMagTrigger.insertsAboveWeapon = ((Component)__instance).transform.localPosition.y > 0.004f;
			}
			if (Mathf.Abs(Vector3.Dot(((Component)__instance).transform.up, ((Component)__instance.FireArm).transform.right)) > 0.2f)
			{
				component.thisMagTrigger.insertsAboveWeapon = false;
			}
			if (component.thisMagTrigger.insertsAboveWeapon)
			{
				transform.position += transform.up * 0.015f;
			}
			else
			{
				transform.position -= transform.up * 0.015f;
			}
		}
	}

	[HarmonyPatch(typeof(FVRFireArmMagazine), "Release")]
	[HarmonyPatch(typeof(FVRFireArmMagazine), "ReleaseFromAttachableFireArm")]
	[HarmonyPatch(typeof(FVRFireArmMagazine), "ReleaseFromSecondarySlot")]
	[HarmonyPrefix]
	private static void ReduceDoubleFeedMultsIfReleasedMag(FVRFireArmMagazine __instance)
	{
		MagazineBoopComponent component = ((Component)__instance).GetComponent<MagazineBoopComponent>();
		if (component != null && __instance.FireArm != null)
		{
			DoubleFeedData component2 = ((Component)__instance.FireArm).GetComponent<DoubleFeedData>();
			if (component2 != null)
			{
			}
		}
	}

	[HarmonyPatch(typeof(FVRPooledAudioSource), "Play")]
	[HarmonyPostfix]
	private static void MagInsertionNoiseAlteration(FVRPooledAudioSource __instance, Vector3 pos, AudioEvent audioEvent)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)_currentUnSeatedWeapon == (Object)null) && !(pos != ((Component)_currentUnSeatedWeapon).transform.position) && !((Object)(object)_currentUnSeatedWeapon.Magazine == (Object)null))
		{
			MagazineBoopComponent component = ((Component)_currentUnSeatedWeapon.Magazine).GetComponent<MagazineBoopComponent>();
			if (!component.thisMagTrigger.hasStartedMagNoiseTimer && component.thisMagTrigger.isUnSeated)
			{
				__instance.Source.Stop();
				AudioSource source = __instance.Source;
				source.volume *= 0.8f;
				__instance.Source.Play();
				MagBoopManager.StartMagNoiseTimer(__instance, 0.12f);
				component.thisMagTrigger.hasStartedMagNoiseTimer = true;
			}
		}
	}

	[HarmonyPatch(typeof(AudioImpactController), "ProcessCollision")]
	[HarmonyPostfix]
	private static void EnvironmentMagBoopPatch(AudioImpactController __instance, Collision col, bool ___m_hasPlayedAudioThisFrame)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		Vector3 relativeVelocity = col.relativeVelocity;
		if (((Vector3)(ref relativeVelocity)).magnitude < __instance.HitThreshold_Ignore || (Object)(object)((Component)__instance).transform.parent == (Object)null)
		{
			return;
		}
		FVRFireArm component = ((Component)__instance).GetComponent<FVRFireArm>();
		if ((Object)(object)component == (Object)null)
		{
			return;
		}
		FVRFireArmMagazine magazine = component.Magazine;
		if ((Object)(object)magazine == (Object)null)
		{
			return;
		}
		MagazineBoopComponent component2 = ((Component)magazine).GetComponent<MagazineBoopComponent>();
		if ((Object)(object)component2 == (Object)null)
		{
			return;
		}
		Collider[] source = ((Component)magazine).GetComponentsInChildren<Collider>().ToArray();
		ContactPoint[] contacts = col.contacts;
		int num = 0;
		if (num >= contacts.Length)
		{
			return;
		}
		ContactPoint contactPoint = contacts[num];
		Collider[] array = source.Where((Collider x) => (Object)(object)x == (Object)(object)((ContactPoint)(ref contactPoint)).otherCollider || (Object)(object)x == (Object)(object)((ContactPoint)(ref contactPoint)).thisCollider).ToArray();
		if (array.Any() && !(Vector3.Dot(col.relativeVelocity, ((Component)array[0]).transform.position) <= 0f))
		{
			component2.thisMagTrigger.ReSeatMagazine();
			if (UserConfig.UseOldSounds.Value || component2.thisMagTrigger.isUnSeated)
			{
				SM.PlayImpactSound(component2.thisMagTrigger.thisController.ImpactType, (MatSoundType)2, (AudioImpactIntensity)2, ((Component)component2.thisMagTrigger.thisMagScript.FireArm).transform.position, component2.thisMagTrigger.thisController.PoolToUse, component2.thisMagTrigger.thisController.DistLimit, 1f, 1f);
			}
			else
			{
				component2.thisMagTrigger.PlayEndOfMagInsertionNoise(1f + Random.Range(0f, 0.4f));
			}
		}
	}
}
public class SlideTriggerPatches
{
	[HarmonyPatch(typeof(HandgunSlide), "Awake")]
	[HarmonyPostfix]
	private static void AddSlideBoopTrigger(HandgunSlide __instance)
	{
		//IL_0023: 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_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Expected O, but got Unknown
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: 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_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		BoxCollider component = ((Component)__instance).GetComponent<BoxCollider>();
		if (component != null)
		{
			Transform transform = ((Component)__instance).transform;
			GameObject val = new GameObject("SlideBoopObj");
			val.transform.parent = transform;
			val.transform.localRotation = Quaternion.Euler(Vector3.zero);
			val.transform.localPosition = Vector3.zero;
			val.layer = LayerMask.NameToLayer("Interactable");
			GameObject val2 = val;
			BoxCollider val3 = val2.AddComponent<BoxCollider>();
			val2.AddComponent<SlideTriggerScript>();
			val3.center = Vector3.zero;
			val3.size = new Vector3(component.size.x * transform.localScale.x * 1.2f, component.size.y * transform.localScale.y * 1.5f, 0.04f);
			Vector3 val4 = Vector3.Scale(component.center, transform.localScale);
			float num = component.size.z * 0.5f * transform.localScale.z - 0.02f;
			val2.transform.position = transform.position + val4 - num * transform.forward;
			val2.transform.localPosition = new Vector3(val2.transform.localPosition.x, 0f, val2.transform.localPosition.z);
			if (UserConfig.EnableTriggerDebug.Value)
			{
				MagazineTriggerPatches.GenerateDebugCube(val2, val3);
			}
		}
	}
}
public static class UserConfig
{
	public static ConfigEntry<bool> EnableMagTapping;

	public static ConfigEntry<bool> EnableMagUnSeating;

	public static ConfigEntry<bool> EnableCustomSounds;

	public static ConfigEntry<bool> EnableTriggerDebug;

	public static ConfigEntry<bool> EnableSlideTapping;

	public static ConfigEntry<float> MagUnseatedProbability;

	public static ConfigEntry<float> SlowSpeedUnseatingProbability;

	public static ConfigEntry<float> DoubleFeedMultiplier;

	public static ConfigEntry<float> MagRequiresTwoTapsProbability;

	public static ConfigEntry<bool> UseOldSounds;

	public static ConfigEntry<float> HandgunProbability;

	public static ConfigEntry<float> ClosedBoltProbability;

	public static ConfigEntry<float> OpenBoltProbability;

	public static ConfigEntry<float> TubeFedShotgunProbability;

	public static ConfigEntry<bool> DisableForBeltFeds;

	public static ConfigEntry<float> HKProbBoltClosed;

	public static ConfigEntry<float> GenericProbBoltClosed;

	public static ConfigEntry<bool> UseThirdLaw;

	public static ConfigEntry<float> ThirdLawPower;
}