Decompiled source of ModulARLMG v1.2.0

ModulARLMG.dll

Decompiled 16 hours ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
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.Logging;
using FistVR;
using HarmonyLib;
using ModularWorkshop;
using OpenScripts2;
using OtherLoader;
using Sodalite.Api;
using UnityEngine;
using UnityEngine.UI;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
public class ForwardAssist : FVRInteractiveObject
{
	[Header("Animation Settings")]
	public Transform TargetTransform;

	public Vector3 StartPosition;

	public Vector3 EndPosition;

	public Vector3 StartRotation;

	public Vector3 EndRotation;

	public float MoveSpeed = 10f;

	public float ResetDelay = 0.2f;

	[Header("Audio Settings")]
	public AudioEvent PokeAudioEvent;

	public FVRPooledAudioType AudioType = (FVRPooledAudioType)0;

	private float m_animFloat = 0f;

	private bool m_isPoked = false;

	private float m_resetTimer = 0f;

	protected void Awake()
	{
		//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_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_0040: 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_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		((FVRInteractiveObject)this).Awake();
		if ((Object)(object)TargetTransform == (Object)null)
		{
			TargetTransform = ((Component)this).transform;
		}
		if (StartPosition == Vector3.zero)
		{
			StartPosition = TargetTransform.localPosition;
		}
		if (StartRotation == Vector3.zero)
		{
			StartRotation = TargetTransform.localEulerAngles;
		}
	}

	public override void Poke(FVRViveHand hand)
	{
		//IL_000e: 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)
		if (PokeAudioEvent != null)
		{
			SM.PlayCoreSound(AudioType, PokeAudioEvent, ((Component)this).transform.position);
		}
		m_isPoked = true;
		m_resetTimer = ResetDelay;
	}

	private void Update()
	{
		//IL_009d: 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)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: 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)
		if (m_isPoked)
		{
			m_animFloat = Mathf.MoveTowards(m_animFloat, 1f, Time.deltaTime * MoveSpeed);
			m_resetTimer -= Time.deltaTime;
			if (m_resetTimer <= 0f)
			{
				m_isPoked = false;
			}
		}
		else
		{
			m_animFloat = Mathf.MoveTowards(m_animFloat, 0f, Time.deltaTime * MoveSpeed);
		}
		if ((Object)(object)TargetTransform != (Object)null)
		{
			TargetTransform.localPosition = Vector3.Lerp(StartPosition, EndPosition, m_animFloat);
			TargetTransform.localEulerAngles = Vector3.Lerp(StartRotation, EndRotation, m_animFloat);
		}
	}
}
public class AudioConsistencyEnforcer : MonoBehaviour
{
	[Header("Audio Profiles")]
	public FVRFirearmAudioSet BaseHandlingAudioProfile;

	private FVRFireArm _firearm;

	private FVRFirearmAudioSet _lastAudioClipSet;

	private void Awake()
	{
		_firearm = ((Component)this).GetComponent<FVRFireArm>();
		if ((Object)(object)_firearm != (Object)null && (Object)(object)_firearm.AudioClipSet != (Object)null)
		{
			_lastAudioClipSet = _firearm.AudioClipSet;
			BaseHandlingAudioProfile = ScriptableObject.CreateInstance<FVRFirearmAudioSet>();
			SaveBaseHandlingAudio(_lastAudioClipSet);
		}
	}

	private void LateUpdate()
	{
		if ((Object)(object)_firearm == (Object)null)
		{
			return;
		}
		FVRFirearmAudioSet audioClipSet = _firearm.AudioClipSet;
		if (!((Object)(object)audioClipSet == (Object)null))
		{
			if ((Object)(object)audioClipSet != (Object)(object)_lastAudioClipSet)
			{
				_lastAudioClipSet = audioClipSet;
			}
			EnforceHandlingSounds(audioClipSet);
		}
	}

	private void SaveBaseHandlingAudio(FVRFirearmAudioSet source)
	{
		BaseHandlingAudioProfile.BoltRelease = source.BoltRelease;
		BaseHandlingAudioProfile.BoltSlideBack = source.BoltSlideBack;
		BaseHandlingAudioProfile.BoltSlideForward = source.BoltSlideForward;
		BaseHandlingAudioProfile.BoltSlideBackHeld = source.BoltSlideBackHeld;
		BaseHandlingAudioProfile.BoltSlideBackLocked = source.BoltSlideBackLocked;
		BaseHandlingAudioProfile.BreachOpen = source.BreachOpen;
		BaseHandlingAudioProfile.BreachClose = source.BreachClose;
		BaseHandlingAudioProfile.CatchOnSear = source.CatchOnSear;
		BaseHandlingAudioProfile.ChamberManual = source.ChamberManual;
		BaseHandlingAudioProfile.FireSelector = source.FireSelector;
		BaseHandlingAudioProfile.HammerHit = source.HammerHit;
		BaseHandlingAudioProfile.HandleBack = source.HandleBack;
		BaseHandlingAudioProfile.HandleBackEmpty = source.HandleBackEmpty;
		BaseHandlingAudioProfile.HandleForward = source.HandleForward;
		BaseHandlingAudioProfile.HandleForwardEmpty = source.HandleForwardEmpty;
		BaseHandlingAudioProfile.HandleUp = source.HandleUp;
		BaseHandlingAudioProfile.HandleDown = source.HandleDown;
		BaseHandlingAudioProfile.HandleGrab = source.HandleGrab;
		BaseHandlingAudioProfile.Prefire = source.Prefire;
		BaseHandlingAudioProfile.Safety = source.Safety;
		BaseHandlingAudioProfile.TriggerReset = source.TriggerReset;
		BaseHandlingAudioProfile.TopCoverRelease = source.TopCoverRelease;
		BaseHandlingAudioProfile.TopCoverUp = source.TopCoverUp;
		BaseHandlingAudioProfile.TopCoverDown = source.TopCoverDown;
		BaseHandlingAudioProfile.StockOpen = source.StockOpen;
		BaseHandlingAudioProfile.StockClosed = source.StockClosed;
		BaseHandlingAudioProfile.BipodOpen = source.BipodOpen;
		BaseHandlingAudioProfile.BipodClosed = source.BipodClosed;
		BaseHandlingAudioProfile.BeltGrab = source.BeltGrab;
		BaseHandlingAudioProfile.BeltRelease = source.BeltRelease;
		BaseHandlingAudioProfile.BeltSeat = source.BeltSeat;
		BaseHandlingAudioProfile.BeltSettle = source.BeltSettle;
	}

	private void EnforceHandlingSounds(FVRFirearmAudioSet targetProfile)
	{
		targetProfile.BoltRelease = BaseHandlingAudioProfile.BoltRelease;
		targetProfile.BoltSlideBack = BaseHandlingAudioProfile.BoltSlideBack;
		targetProfile.BoltSlideForward = BaseHandlingAudioProfile.BoltSlideForward;
		targetProfile.BoltSlideBackHeld = BaseHandlingAudioProfile.BoltSlideBackHeld;
		targetProfile.BoltSlideBackLocked = BaseHandlingAudioProfile.BoltSlideBackLocked;
		targetProfile.BreachOpen = BaseHandlingAudioProfile.BreachOpen;
		targetProfile.BreachClose = BaseHandlingAudioProfile.BreachClose;
		targetProfile.CatchOnSear = BaseHandlingAudioProfile.CatchOnSear;
		targetProfile.ChamberManual = BaseHandlingAudioProfile.ChamberManual;
		targetProfile.FireSelector = BaseHandlingAudioProfile.FireSelector;
		targetProfile.HammerHit = BaseHandlingAudioProfile.HammerHit;
		targetProfile.HandleBack = BaseHandlingAudioProfile.HandleBack;
		targetProfile.HandleBackEmpty = BaseHandlingAudioProfile.HandleBackEmpty;
		targetProfile.HandleForward = BaseHandlingAudioProfile.HandleForward;
		targetProfile.HandleForwardEmpty = BaseHandlingAudioProfile.HandleForwardEmpty;
		targetProfile.HandleUp = BaseHandlingAudioProfile.HandleUp;
		targetProfile.HandleDown = BaseHandlingAudioProfile.HandleDown;
		targetProfile.HandleGrab = BaseHandlingAudioProfile.HandleGrab;
		targetProfile.Prefire = BaseHandlingAudioProfile.Prefire;
		targetProfile.Safety = BaseHandlingAudioProfile.Safety;
		targetProfile.TriggerReset = BaseHandlingAudioProfile.TriggerReset;
		targetProfile.TopCoverRelease = BaseHandlingAudioProfile.TopCoverRelease;
		targetProfile.TopCoverUp = BaseHandlingAudioProfile.TopCoverUp;
		targetProfile.TopCoverDown = BaseHandlingAudioProfile.TopCoverDown;
		targetProfile.StockOpen = BaseHandlingAudioProfile.StockOpen;
		targetProfile.StockClosed = BaseHandlingAudioProfile.StockClosed;
		targetProfile.BipodOpen = BaseHandlingAudioProfile.BipodOpen;
		targetProfile.BipodClosed = BaseHandlingAudioProfile.BipodClosed;
		targetProfile.BeltGrab = BaseHandlingAudioProfile.BeltGrab;
		targetProfile.BeltRelease = BaseHandlingAudioProfile.BeltRelease;
		targetProfile.BeltSeat = BaseHandlingAudioProfile.BeltSeat;
		targetProfile.BeltSettle = BaseHandlingAudioProfile.BeltSettle;
	}
}
public class LeverActionMagRelease : MonoBehaviour
{
	[Tooltip("Reference to the LeverActionFirearm component. If unassigned, automatically resolves from this GameObject or parent.")]
	public LeverActionFirearm firearm;

	[Tooltip("Determines whether magazine release functionality and input polling are enabled.")]
	public bool hasMagReleaseButton = true;

	[Tooltip("If true, suppresses rifle spinning when the touchpad is clicked downward for magazine release on classic controls.")]
	public bool preventSpinOnMagRelease = true;

	[Tooltip("If true, the magazine can only be released when the lever action is cycled or open.")]
	public bool requireLeverOpen = false;

	[Tooltip("Optional transform for the physical magazine release button on the firearm.")]
	public Transform magazineReleaseButton;

	[Tooltip("Interpolation method used for the release button visual (Translate or Rotation).")]
	public InterpStyle magReleaseInterp = (InterpStyle)0;

	[Tooltip("Local position or Euler rotation of the button in its unpressed resting state.")]
	public Vector3 magReleaseUnpressed = Vector3.zero;

	[Tooltip("Local position or Euler rotation of the button in its depressed active state.")]
	public Vector3 magReleasePressed = Vector3.zero;

	[Tooltip("Optional AudioEvent played when the magazine release button is clicked.")]
	public AudioEvent releaseSound;

	private bool _isMagReleaseButtonHeld = false;

	private bool _wasMagReleaseHeldDown = false;

	private bool _initialCanSpin = false;

	public bool IsMagReleaseButtonHeld => _isMagReleaseButtonHeld;

	private void Awake()
	{
		if ((Object)(object)firearm == (Object)null)
		{
			firearm = ((Component)this).GetComponent<LeverActionFirearm>();
		}
		if ((Object)(object)firearm == (Object)null)
		{
			firearm = ((Component)this).GetComponentInParent<LeverActionFirearm>();
		}
		if ((Object)(object)firearm != (Object)null)
		{
			_initialCanSpin = firearm.CanSpin;
		}
	}

	private void Update()
	{
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: 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_0113: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)firearm == (Object)null)
		{
			return;
		}
		_isMagReleaseButtonHeld = false;
		if (!((FVRInteractiveObject)firearm).IsHeld || ((FVRPhysicalObject)firearm).IsAltHeld || (Object)(object)((FVRInteractiveObject)firearm).m_hand == (Object)null)
		{
			if (_wasMagReleaseHeldDown)
			{
				_wasMagReleaseHeldDown = false;
				UpdateButtonVisual(isHeld: false);
				if (preventSpinOnMagRelease)
				{
					firearm.CanSpin = _initialCanSpin;
				}
			}
		}
		else
		{
			if (!hasMagReleaseButton)
			{
				return;
			}
			FVRViveHand hand = ((FVRInteractiveObject)firearm).m_hand;
			if (hand.IsInStreamlinedMode)
			{
				if (hand.Input.AXButtonDown)
				{
					ReleaseMag();
				}
				if (hand.Input.AXButtonPressed)
				{
					_isMagReleaseButtonHeld = true;
				}
			}
			else
			{
				Vector2 touchpadAxes = hand.Input.TouchpadAxes;
				if (((Vector2)(ref touchpadAxes)).magnitude > 0.2f && Vector2.Angle(touchpadAxes, Vector2.down) <= 45f)
				{
					if (hand.Input.TouchpadDown)
					{
						ReleaseMag();
					}
					if (hand.Input.TouchpadPressed)
					{
						_isMagReleaseButtonHeld = true;
					}
				}
			}
			if (preventSpinOnMagRelease)
			{
				if (_isMagReleaseButtonHeld)
				{
					firearm.CanSpin = false;
					SuppressSpin();
				}
				else if (_wasMagReleaseHeldDown)
				{
					firearm.CanSpin = _initialCanSpin;
				}
			}
			if (_wasMagReleaseHeldDown != _isMagReleaseButtonHeld)
			{
				_wasMagReleaseHeldDown = _isMagReleaseButtonHeld;
				UpdateButtonVisual(_isMagReleaseButtonHeld);
			}
		}
	}

	private void LateUpdate()
	{
		if (preventSpinOnMagRelease && _isMagReleaseButtonHeld && (Object)(object)firearm != (Object)null)
		{
			SuppressSpin();
		}
	}

	private void SuppressSpin()
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		firearm.m_isSpinning = false;
		firearm.xSpinRot = 0f;
		firearm.xSpinVel = 0f;
		if ((Object)(object)firearm.PoseSpinHolder != (Object)null)
		{
			firearm.PoseSpinHolder.localEulerAngles = Vector3.zero;
		}
	}

	public void ReleaseMag()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Invalid comparison between Unknown and I4
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		if ((!requireLeverOpen || (int)firearm.m_curLeverPos != 2) && (Object)(object)((FVRFireArm)firearm).Magazine != (Object)null)
		{
			((FVRFireArm)firearm).EjectMag(false);
			if (releaseSound != null)
			{
				SM.PlayCoreSound((FVRPooledAudioType)10, releaseSound, ((Component)firearm).transform.position);
			}
		}
	}

	private void UpdateButtonVisual(bool isHeld)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: 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_0048: 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)
		if ((Object)(object)magazineReleaseButton != (Object)null && (Object)(object)firearm != (Object)null)
		{
			Vector3 val = ((!isHeld) ? magReleaseUnpressed : magReleasePressed);
			((FVRPhysicalObject)firearm).SetAnimatedComponent(magazineReleaseButton, val, magReleaseInterp);
		}
	}

	private void OnDisable()
	{
		if ((Object)(object)firearm != (Object)null && preventSpinOnMagRelease)
		{
			firearm.CanSpin = _initialCanSpin;
		}
		if (_wasMagReleaseHeldDown)
		{
			_wasMagReleaseHeldDown = false;
			UpdateButtonVisual(isHeld: false);
		}
	}
}
public class SecondaryMagSupport : ModularBarrelExtension
{
	[Header("Secondary Magazine Configuration")]
	public bool ChangesSecondaryMagazine = false;

	public FireArmMagazineType SecondaryMagazineType;

	public Transform CustomSecondaryMagMountPoint;

	public Transform CustomSecondaryMagEjectPoint;

	private FVRFireArm _firearm;

	private Transform _origSecMagMountPos;

	private Transform _origSecMagEjectPos;

	private FireArmMagazineType _origSecondaryMagazineType;

	private bool _hasCachedOriginals = false;

	public override void EnablePart()
	{
		((ModularBarrelExtension)this).EnablePart();
		if (UnityEngineExtensions.TryGetComponentInParent<FVRFireArm>((Component)(object)((Component)this).transform, ref _firearm) && ChangesSecondaryMagazine)
		{
			CacheOriginalSecondaryMagSettings(_firearm);
			UpdateSecondaryMagazine(_firearm);
		}
		else
		{
			Debug.LogWarning((object)"SecondaryMagSupport: Firearm not found or ChangesSecondaryMagazine is false!");
		}
	}

	public override void DisablePart()
	{
		((ModularBarrelExtension)this).DisablePart();
		if ((Object)(object)_firearm != (Object)null && ChangesSecondaryMagazine)
		{
			ResetSecondaryMagazine(_firearm);
		}
	}

	private void CacheOriginalSecondaryMagSettings(FVRFireArm firearm)
	{
		//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)
		if (!_hasCachedOriginals && firearm.SecondaryMagazineSlots.Length != 0)
		{
			_origSecMagMountPos = firearm.SecondaryMagazineSlots[0].MagazineMountPos;
			_origSecMagEjectPos = firearm.SecondaryMagazineSlots[0].MagazineEjectPos;
			if ((Object)(object)firearm.SecondaryMagazineSlots[0].Magazine != (Object)null)
			{
				_origSecondaryMagazineType = firearm.SecondaryMagazineSlots[0].Magazine.MagazineType;
			}
			_hasCachedOriginals = true;
		}
	}

	private void UpdateSecondaryMagazine(FVRFireArm firearm)
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		if (firearm.SecondaryMagazineSlots.Length != 0)
		{
			firearm.SecondaryMagazineSlots[0].MagazineMountPos = CustomSecondaryMagMountPoint;
			firearm.SecondaryMagazineSlots[0].MagazineEjectPos = CustomSecondaryMagEjectPoint;
			if ((Object)(object)firearm.SecondaryMagazineSlots[0].Magazine != (Object)null)
			{
				firearm.SecondaryMagazineSlots[0].Magazine.MagazineType = SecondaryMagazineType;
			}
			Debug.Log((object)"SecondaryMagSupport: Secondary magazine settings updated.");
		}
	}

	private void ResetSecondaryMagazine(FVRFireArm firearm)
	{
		//IL_006b: 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)
		if (_hasCachedOriginals && firearm.SecondaryMagazineSlots.Length != 0)
		{
			firearm.SecondaryMagazineSlots[0].MagazineMountPos = _origSecMagMountPos;
			firearm.SecondaryMagazineSlots[0].MagazineEjectPos = _origSecMagEjectPos;
			if ((Object)(object)firearm.SecondaryMagazineSlots[0].Magazine != (Object)null)
			{
				firearm.SecondaryMagazineSlots[0].Magazine.MagazineType = _origSecondaryMagazineType;
			}
			Debug.Log((object)"SecondaryMagSupport: Secondary magazine settings reset.");
		}
	}
}
public class AdvanceTopCoverControl : FVRFireArmTopCoverAdvanced
{
	public enum HingeAxis
	{
		X,
		Y,
		Z
	}

	public enum LatchButtonInput
	{
		TouchpadOrJoystick,
		BYButton,
		AXButton,
		TriggerPress
	}

	public enum LinkReloadEnforcementMode
	{
		Disabled,
		LatchGate,
		HardBeltLockout
	}

	[Header("Master Jam Toggle")]
	[Tooltip("If false, disables all jams, misfeeds, handle lockouts, and mislatches.")]
	public bool EnableAllJamsAndMisfeeds = true;

	[Header("Axis Configuration")]
	[Tooltip("Local axis around which the top cover rotates.")]
	public HingeAxis RotationHingeAxis = HingeAxis.X;

	[Header("Bolt Interlock")]
	[Tooltip("If true, the top cover cannot be opened fully unless the bolt is locked to the rear on OpenBoltReceiver firearms.")]
	public bool RequireBoltAtRearToMove = true;

	[Tooltip("Maximum angle in degrees the cover can move when pulled while the bolt is forward.")]
	[Range(0f, 5f)]
	public float InterlockJiggleMaxAngle = 0.75f;

	[Tooltip("Optional sound played when pulling against the bolt interlock.")]
	public AudioEvent InterlockRattleSound;

	[Header("Non-Reciprocating Charging Handle")]
	[Tooltip("If true, the charging handle will not auto-return forward when released.")]
	public bool EnableManualChargingHandle = true;

	[Tooltip("If true, firing with the handle rearward slingshots the handle forward.")]
	public bool SlingshotHandleOnFire = true;

	[Tooltip("Speed at which the handle slams forward when slingshotted.")]
	public float SlingshotSpeed = 3.5f;

	[Range(0f, 1f)]
	[Tooltip("Chance that firing with the handle rearward pops the top cover latch ajar.")]
	public float SlingshotPopCoverChance = 0.65f;

	[Range(0f, 1f)]
	[Tooltip("Chance that firing with the handle rearward wastes a belt round.")]
	public float SlingshotWasteAmmoChance = 0.35f;

	[Tooltip("Optional sound played when the bolt slams the charging handle forward.")]
	public AudioEvent HandleSlingshotSound;

	[Header("Latch Button Release")]
	[Tooltip("If true, opening the top cover requires pressing a controller button on the grabbing hand.")]
	public bool RequireLatchButtonToOpen = false;

	[Tooltip("Which controller input acts as the latch release button.")]
	public LatchButtonInput LatchReleaseButton = LatchButtonInput.TouchpadOrJoystick;

	[Tooltip("Maximum angle in degrees the cover can move when pulled without pressing the latch release button.")]
	[Range(0f, 5f)]
	public float LatchJiggleMaxAngle = 0.5f;

	[Tooltip("Optional sound played when the latch release button is pressed.")]
	public AudioEvent LatchUnlockSound;

	[Tooltip("Optional sound played when pulling the cover while the latch is locked.")]
	public AudioEvent LatchRattleSound;

	[Header("Bump / Slap to Slam Down")]
	[Tooltip("If true, bumping the top cover with a controller plays feedback or slams it shut.")]
	public bool AllowBumpToSlam = true;

	[Tooltip("Minimum angle in degrees above which a bump slams the cover shut.")]
	public float BumpMinAngle = 0f;

	[Tooltip("Maximum angle in degrees below which a bump slams the cover shut.")]
	public float BumpMaxAngle = 125f;

	[Tooltip("Maximum allowed angle in degrees between the hand velocity and straight down.")]
	public float BumpMaxDownwardAngle = 65f;

	[Tooltip("Minimum hand speed in meters per second required to slam the cover shut.")]
	public float BumpSlamVelocityThreshold = 0.25f;

	[Tooltip("Optional sound played when bumping the cover.")]
	public AudioEvent BumpSlamSound;

	[Header("Spent Link Retention and Clearing")]
	[Tooltip("If true, firing the last round of a belt leaves an empty link on the feed tray.")]
	public bool EnableSpentLinkRetention = true;

	[Tooltip("Minimum hand velocity in meters per second required to swipe the spent link off the tray.")]
	public float LinkSwipeVelocityThreshold = 0.6f;

	[Tooltip("If true, some spent links stick in the feed pawls, requiring a harder swipe or lifting the feed tray.")]
	public bool EnableStubbornLinkChance = true;

	[Range(0f, 1f)]
	[Tooltip("Probability that an emptied belt leaves a stubborn link.")]
	public float StubbornLinkChance = 0.35f;

	[Tooltip("Force multiplier required to swipe away a stubborn link.")]
	public float StubbornLinkSwipeMultiplier = 2f;

	[Tooltip("How an uncleared spent link impacts reloading.")]
	public LinkReloadEnforcementMode LinkReloadEnforcement = LinkReloadEnforcementMode.LatchGate;

	[Tooltip("Visual GameObject representing the empty link on the feed tray.")]
	public GameObject SpentLinkObject;

	[Tooltip("Optional physics prefab of the link spawned into the world when cleared.")]
	public GameObject PhysicalLinkPrefab;

	[Tooltip("Impulse force applied to the physical link when cleared.")]
	public float LinkEjectForce = 1.6f;

	[Tooltip("Time in seconds before the spawned physical link despawns.")]
	public float LinkDebrisLifetime = 10f;

	[Tooltip("Optional sound played when clearing the spent link.")]
	public AudioEvent LinkFlickSound;

	[Header("Slam-Shut Misfeed")]
	[Tooltip("If true, closing the cover violently wastes the next round on the belt.")]
	public bool CanMisfeedOnSlam = true;

	[Tooltip("Hand speed in meters per second at closing above which a misfeed is triggered.")]
	public float SlamVelocityThreshold = 2.5f;

	[Tooltip("Optional sound played when a slammed cover causes a misfeed.")]
	public AudioEvent MisfeedSound;

	[Header("Gravity Physics")]
	[Tooltip("If false, cover uses stock friction hold. If true, dynamic gravity swinging is enabled.")]
	public bool UseGravityPhysics = false;

	[Tooltip("Speed in degrees per second the cover swings under gravity.")]
	public float GravitySettleSpeed = 60f;

	[Tooltip("Direction in cover local space at closed angle pointing toward its center of mass.")]
	public Vector3 LocalMassOffsetAtClosed = Vector3.forward;

	[Header("Imperfect Latch")]
	[Range(0f, 1f)]
	[Tooltip("Chance that closing the cover leaves it resting slightly ajar.")]
	public float MislatchChance = 0.15f;

	[Tooltip("Resting angle offset in degrees above MinMaxAngle.x when imperfectly latched.")]
	public float MislatchRestAngle = 8f;

	[Header("Component References")]
	public OpenBoltChargingHandle TargetChargingHandle;

	public OpenBoltReceiverBolt TargetBolt;

	public AdvanceFeedTrayControl TargetFeedTray;

	[Header("Debugging")]
	public bool debug = false;

	private float m_currentAngle;

	private bool m_isBeingHeld;

	private bool m_isImperfectlyLatched;

	private bool m_isLatchUnlocked;

	private bool m_hasPlayedInterlockRattle;

	private bool m_hasPlayedLatchRattle;

	private bool m_hasRetainedSpentLink;

	private bool m_isLinkStubborn;

	private bool m_hasSlingshottedThisCycle;

	private bool m_isSlingshotMoving;

	private bool m_startedGrabFromClosed;

	private bool m_wasBeltLoadedLastFrame;

	private float m_linkClearCooldown;

	private float m_origHandleForwardSpeed = 1f;

	private Vector3 m_initialLocalEuler;

	private Vector3 m_spentLinkInitialLocalPos;

	private Quaternion m_spentLinkInitialLocalRot;

	public override void Awake()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		((FVRInteractiveObject)this).Awake();
		m_initialLocalEuler = ((Component)this).transform.localEulerAngles;
		if ((Object)(object)base.BaseVector == (Object)null || (Object)(object)base.BaseVector == (Object)(object)((Component)this).transform || base.BaseVector.IsChildOf(((Component)this).transform))
		{
			FVRFireArm componentInParent = ((Component)this).GetComponentInParent<FVRFireArm>();
			base.BaseVector = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).transform : ((!((Object)(object)((Component)this).transform.parent != (Object)null)) ? ((Component)this).transform : ((Component)this).transform.parent));
		}
		if ((Object)(object)SpentLinkObject != (Object)null)
		{
			m_spentLinkInitialLocalPos = SpentLinkObject.transform.localPosition;
			m_spentLinkInitialLocalRot = SpentLinkObject.transform.localRotation;
		}
	}

	public override void Start()
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Expected O, but got Unknown
		((FVRInteractiveObject)this).Start();
		if ((Object)(object)base.FireArm != (Object)null)
		{
			if ((Object)(object)TargetChargingHandle == (Object)null)
			{
				TargetChargingHandle = ((Component)base.FireArm).GetComponentInChildren<OpenBoltChargingHandle>();
			}
			if ((Object)(object)TargetBolt == (Object)null && base.FireArm is OpenBoltReceiver)
			{
				OpenBoltReceiver val = (OpenBoltReceiver)base.FireArm;
				TargetBolt = val.Bolt;
			}
			if ((Object)(object)TargetFeedTray == (Object)null)
			{
				TargetFeedTray = ((Component)base.FireArm).GetComponentInChildren<AdvanceFeedTrayControl>();
			}
		}
		if ((Object)(object)TargetFeedTray != (Object)null && (Object)(object)TargetFeedTray.TopCover == (Object)null)
		{
			TargetFeedTray.TopCover = this;
		}
		if ((Object)(object)TargetChargingHandle != (Object)null)
		{
			m_origHandleForwardSpeed = TargetChargingHandle.ForwardSpeed;
			if (EnableManualChargingHandle)
			{
				TargetChargingHandle.ForwardSpeed = 0f;
			}
		}
		if ((Object)(object)SpentLinkObject != (Object)null)
		{
			SpentLinkObject.SetActive(false);
		}
		float angle = ((!((Object)(object)base.FireArm != (Object)null) || !base.FireArm.IsTopCoverUp) ? base.MinMaxAngle.x : base.MinMaxAngle.y);
		SetAngle(angle);
		m_wasBeltLoadedLastFrame = IsBeltFeedActive() && GetBeltRoundCount() > 0;
	}

	public override void OnDestroy()
	{
		((FVRInteractiveObject)this).OnDestroy();
		if ((Object)(object)TargetChargingHandle != (Object)null)
		{
			TargetChargingHandle.ForwardSpeed = m_origHandleForwardSpeed;
		}
	}

	private void Update()
	{
		//IL_03be: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c4: Invalid comparison between Unknown and I4
		//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d5: Invalid comparison between Unknown and I4
		//IL_0307: Unknown result type (might be due to invalid IL or missing references)
		//IL_030c: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e6: Invalid comparison between Unknown and I4
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0361: Unknown result type (might be due to invalid IL or missing references)
		//IL_036f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0380: Unknown result type (might be due to invalid IL or missing references)
		//IL_0385: Unknown result type (might be due to invalid IL or missing references)
		//IL_0388: Unknown result type (might be due to invalid IL or missing references)
		//IL_038a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0394: Unknown result type (might be due to invalid IL or missing references)
		//IL_0399: Unknown result type (might be due to invalid IL or missing references)
		//IL_043e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0489: Unknown result type (might be due to invalid IL or missing references)
		//IL_049a: Unknown result type (might be due to invalid IL or missing references)
		//IL_053f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0544: Unknown result type (might be due to invalid IL or missing references)
		//IL_0548: Unknown result type (might be due to invalid IL or missing references)
		//IL_054d: Unknown result type (might be due to invalid IL or missing references)
		//IL_055b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0560: Unknown result type (might be due to invalid IL or missing references)
		//IL_056e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0573: Unknown result type (might be due to invalid IL or missing references)
		//IL_0575: Unknown result type (might be due to invalid IL or missing references)
		//IL_0577: Unknown result type (might be due to invalid IL or missing references)
		//IL_0580: Unknown result type (might be due to invalid IL or missing references)
		//IL_0582: Unknown result type (might be due to invalid IL or missing references)
		//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b0: Invalid comparison between Unknown and I4
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)TargetFeedTray != (Object)null)
		{
			if (m_currentAngle < TargetFeedTray.GetAngle())
			{
				TargetFeedTray.SetAngle(m_currentAngle);
			}
			if (TargetFeedTray.GetAngle() > 5f && (Object)(object)base.FireArm != (Object)null && (base.FireArm.HasBelt || (Object)(object)base.FireArm.Magazine != (Object)null))
			{
				base.FireArm.EjectMag(false);
				if (debug)
				{
					Debug.Log((object)"AdvanceTopCoverControl: Magazine rejected - feed tray is currently lifted.");
				}
			}
		}
		if (m_linkClearCooldown > 0f)
		{
			m_linkClearCooldown -= Time.deltaTime;
		}
		if ((Object)(object)base.FireArm != (Object)null && EnableSpentLinkRetention)
		{
			bool flag = IsBeltFeedActive();
			bool flag2 = (Object)(object)base.FireArm.Magazine != (Object)null && ((FVRInteractiveObject)base.FireArm.Magazine).IsHeld;
			if (flag && !flag2)
			{
				int beltRoundCount = GetBeltRoundCount();
				if (m_wasBeltLoadedLastFrame && beltRoundCount == 0 && !m_hasRetainedSpentLink)
				{
					m_hasRetainedSpentLink = true;
					m_linkClearCooldown = 0.25f;
					m_isLinkStubborn = EnableStubbornLinkChance && Random.value < StubbornLinkChance;
					if ((Object)(object)SpentLinkObject != (Object)null)
					{
						SpentLinkObject.transform.localPosition = m_spentLinkInitialLocalPos + new Vector3(Random.Range(-0.0015f, 0.0015f), 0f, Random.Range(-0.002f, 0.002f));
						SpentLinkObject.transform.localRotation = m_spentLinkInitialLocalRot * Quaternion.Euler(Random.Range(-4f, 4f), Random.Range(-8f, 8f), Random.Range(-4f, 4f));
						SpentLinkObject.SetActive(true);
					}
					if (debug)
					{
						Debug.Log((object)"AdvanceTopCoverControl: Belt emptied. Single link retained on feed tray.");
					}
				}
				if (EnableAllJamsAndMisfeeds && LinkReloadEnforcement == LinkReloadEnforcementMode.HardBeltLockout && m_hasRetainedSpentLink && !m_wasBeltLoadedLastFrame && beltRoundCount > 0)
				{
					base.FireArm.EjectMag(false);
					if (debug)
					{
						Debug.Log((object)"AdvanceTopCoverControl: Belt rejected - spent link must be cleared first.");
					}
				}
				m_wasBeltLoadedLastFrame = beltRoundCount > 0;
			}
			else
			{
				m_wasBeltLoadedLastFrame = false;
			}
		}
		if (m_hasRetainedSpentLink && m_currentAngle > base.MinMaxAngle.x + 15f && (Object)(object)base.FireArm != (Object)null)
		{
			float num = Mathf.Abs(((Component)base.FireArm).transform.localEulerAngles.z);
			if (num > 180f)
			{
				num = Mathf.Abs(num - 360f);
			}
			if (num > 55f)
			{
				Vector3 val = ((Component)base.FireArm).transform.right * Mathf.Sign(((Component)base.FireArm).transform.localEulerAngles.z) * (LinkEjectForce * 1.5f);
				ClearSpentLink(val + Vector3.down * 0.8f);
			}
		}
		if ((Object)(object)TargetBolt != (Object)null && ((int)TargetBolt.CurPos == 4 || (int)TargetBolt.CurPos == 2 || (int)TargetBolt.CurPos == 3))
		{
			m_hasSlingshottedThisCycle = false;
		}
		if (SlingshotHandleOnFire && (Object)(object)TargetChargingHandle != (Object)null && (Object)(object)TargetBolt != (Object)null)
		{
			if (m_isSlingshotMoving)
			{
				if ((int)TargetChargingHandle.CurPos == 0)
				{
					TargetChargingHandle.ForwardSpeed = 0f;
					m_isSlingshotMoving = false;
				}
			}
			else if (!m_hasSlingshottedThisCycle && !((FVRInteractiveObject)TargetChargingHandle).IsHeld && (int)TargetChargingHandle.CurPos != 0 && ((int)TargetBolt.CurPos == 0 || (int)TargetBolt.CurPos == 1))
			{
				ExecuteHandleSlingshotSlam();
			}
		}
		if (!((Object)(object)base.FireArm == (Object)null) && !m_isBeingHeld && UseGravityPhysics && !m_isImperfectlyLatched && m_currentAngle > base.MinMaxAngle.x + 0.5f && m_currentAngle < base.MinMaxAngle.y - 0.5f)
		{
			Vector3 gravity = Physics.gravity;
			Vector3 normalized = ((Vector3)(ref gravity)).normalized;
			Vector3 val2 = TransformMassOffsetAtAngle(base.MinMaxAngle.x);
			Vector3 val3 = TransformMassOffsetAtAngle(base.MinMaxAngle.y);
			float num2 = Vector3.Dot(val2, normalized);
			float num3 = Vector3.Dot(val3, normalized);
			float num4 = ((!(num2 > num3)) ? base.MinMaxAngle.y : base.MinMaxAngle.x);
			float num5 = Mathf.MoveTowards(m_currentAngle, num4, GravitySettleSpeed * Time.deltaTime);
			if (num5 <= base.MinMaxAngle.x + 0.01f)
			{
				SetAngle(base.MinMaxAngle.x);
				base.FireArm.PlayAudioEvent((FirearmAudioEventType)24, 1f);
				base.FireArm.IsTopCoverUp = false;
				m_isLatchUnlocked = false;
				RollForMislatch();
			}
			else if (num5 >= base.MinMaxAngle.y - 0.01f)
			{
				SetAngle(base.MinMaxAngle.y);
				base.FireArm.PlayAudioEvent((FirearmAudioEventType)23, 1f);
				base.FireArm.IsTopCoverUp = true;
			}
			else
			{
				SetAngle(num5);
			}
		}
	}

	private bool IsBeltFeedActive()
	{
		if ((Object)(object)base.FireArm == (Object)null)
		{
			return false;
		}
		if (base.FireArm.HasBelt && (Object)(object)base.FireArm.BeltDD != (Object)null)
		{
			return true;
		}
		if ((Object)(object)base.FireArm.Magazine != (Object)null && base.FireArm.Magazine.IsBeltBox)
		{
			return true;
		}
		return false;
	}

	private int GetBeltRoundCount()
	{
		if ((Object)(object)base.FireArm == (Object)null)
		{
			return 0;
		}
		if (base.FireArm.HasBelt && (Object)(object)base.FireArm.BeltDD != (Object)null)
		{
			return base.FireArm.BeltDD.BeltRounds.Count;
		}
		if ((Object)(object)base.FireArm.Magazine != (Object)null && base.FireArm.Magazine.IsBeltBox)
		{
			return base.FireArm.Magazine.m_numRounds;
		}
		return 0;
	}

	private void ExecuteHandleSlingshotSlam()
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		m_hasSlingshottedThisCycle = true;
		m_isSlingshotMoving = true;
		TargetChargingHandle.ForwardSpeed = SlingshotSpeed;
		if (HandleSlingshotSound != null)
		{
			SM.PlayCoreSound((FVRPooledAudioType)10, HandleSlingshotSound, ((Component)TargetChargingHandle).transform.position);
		}
		else if ((Object)(object)base.FireArm != (Object)null)
		{
			base.FireArm.PlayAudioEvent((FirearmAudioEventType)11, 1f);
		}
		if (EnableAllJamsAndMisfeeds && !m_isImperfectlyLatched && Random.value < SlingshotPopCoverChance)
		{
			m_isImperfectlyLatched = true;
			SetAngle(base.MinMaxAngle.x + MislatchRestAngle);
			if ((Object)(object)base.FireArm != (Object)null)
			{
				base.FireArm.IsTopCoverUp = true;
				base.FireArm.PlayAudioEvent((FirearmAudioEventType)23, 1f);
			}
			if (debug)
			{
				Debug.Log((object)"AdvanceTopCoverControl: Bolt slammed charging handle forward, popping top cover ajar.");
			}
		}
		if (EnableAllJamsAndMisfeeds && Random.value < SlingshotWasteAmmoChance)
		{
			TryTriggerSlamMisfeed(SlamVelocityThreshold);
		}
	}

	public bool HasRetainedSpentLink()
	{
		return m_hasRetainedSpentLink;
	}

	public bool CanClearLink()
	{
		return m_linkClearCooldown <= 0f;
	}

	public float GetRequiredLinkClearSpeed()
	{
		return LinkSwipeVelocityThreshold * ((!m_isLinkStubborn) ? 1f : StubbornLinkSwipeMultiplier);
	}

	public override void Poke(FVRViveHand hand)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: 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_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_027d: Unknown result type (might be due to invalid IL or missing references)
		((FVRInteractiveObject)this).Poke(hand);
		if ((Object)(object)hand == (Object)null || m_isBeingHeld)
		{
			return;
		}
		Vector3 velLinearWorld = hand.Input.VelLinearWorld;
		float magnitude = ((Vector3)(ref velLinearWorld)).magnitude;
		if (m_hasRetainedSpentLink && m_currentAngle > 15f && CanClearLink())
		{
			float requiredLinkClearSpeed = GetRequiredLinkClearSpeed();
			if (magnitude >= requiredLinkClearSpeed)
			{
				Vector3 ejectVelocity = ((Vector3)(ref velLinearWorld)).normalized * (LinkEjectForce * 1.5f) + Vector3.up * 0.6f;
				ClearSpentLink(ejectVelocity);
				if ((Object)(object)hand.Buzzer != (Object)null)
				{
					hand.Buzz(hand.Buzzer.Buzz_BeginInteraction);
				}
				return;
			}
		}
		if (!AllowBumpToSlam)
		{
			return;
		}
		Transform stableReferenceTransform = GetStableReferenceTransform();
		float num = Vector3.Angle(((Vector3)(ref velLinearWorld)).normalized, -stableReferenceTransform.up);
		if (m_currentAngle <= base.MinMaxAngle.x + 1f && !m_isImperfectlyLatched)
		{
			if (magnitude >= BumpSlamVelocityThreshold && num <= BumpMaxDownwardAngle)
			{
				if (BumpSlamSound != null)
				{
					SM.PlayCoreSound((FVRPooledAudioType)10, BumpSlamSound, ((Component)this).transform.position);
				}
				else if ((Object)(object)base.FireArm != (Object)null)
				{
					base.FireArm.PlayAudioEvent((FirearmAudioEventType)24, 1f);
				}
				if ((Object)(object)hand.Buzzer != (Object)null)
				{
					hand.Buzz(hand.Buzzer.Buzz_BeginInteraction);
				}
			}
		}
		else if (((m_currentAngle >= BumpMinAngle && m_currentAngle <= BumpMaxAngle) || m_isImperfectlyLatched) && !(magnitude < BumpSlamVelocityThreshold) && !(num > BumpMaxDownwardAngle))
		{
			m_isImperfectlyLatched = false;
			SetAngle(base.MinMaxAngle.x);
			if ((Object)(object)base.FireArm != (Object)null)
			{
				base.FireArm.IsTopCoverUp = false;
				base.FireArm.PlayAudioEvent((FirearmAudioEventType)24, 1f);
			}
			if (BumpSlamSound != null)
			{
				SM.PlayCoreSound((FVRPooledAudioType)10, BumpSlamSound, ((Component)this).transform.position);
			}
			if ((Object)(object)hand.Buzzer != (Object)null)
			{
				hand.Buzz(hand.Buzzer.Buzz_BeginInteraction);
			}
			TryTriggerSlamMisfeed(magnitude);
			RollForMislatch();
			if (!m_isImperfectlyLatched)
			{
				m_isLatchUnlocked = false;
			}
			if (debug)
			{
				Debug.Log((object)("AdvanceTopCoverControl: Bump slammed cover shut at speed " + magnitude + " m/s."));
			}
		}
	}

	public void ClearSpentLink(Vector3 ejectVelocity = default(Vector3))
	{
		//IL_004c: 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_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: 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_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: 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_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: 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_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: 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_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		if (!m_hasRetainedSpentLink)
		{
			return;
		}
		m_hasRetainedSpentLink = false;
		m_isLinkStubborn = false;
		Vector3 val = ((!((Object)(object)SpentLinkObject != (Object)null)) ? ((Component)this).transform.position : SpentLinkObject.transform.position);
		Quaternion val2 = ((!((Object)(object)SpentLinkObject != (Object)null)) ? ((Component)this).transform.rotation : SpentLinkObject.transform.rotation);
		if ((Object)(object)SpentLinkObject != (Object)null)
		{
			SpentLinkObject.SetActive(false);
		}
		if ((Object)(object)PhysicalLinkPrefab != (Object)null)
		{
			GameObject val3 = Object.Instantiate<GameObject>(PhysicalLinkPrefab, val, val2);
			val3.transform.SetParent((Transform)null);
			Rigidbody component = val3.GetComponent<Rigidbody>();
			if ((Object)(object)component != (Object)null)
			{
				Vector3 val4 = Vector3.zero;
				if ((Object)(object)base.FireArm != (Object)null && (Object)(object)((FVRPhysicalObject)base.FireArm).RootRigidbody != (Object)null)
				{
					val4 = ((FVRPhysicalObject)base.FireArm).RootRigidbody.velocity;
				}
				Vector3 val5 = ((!(ejectVelocity != Vector3.zero)) ? (((Component)this).transform.right * LinkEjectForce * 1.5f + Vector3.up * 0.8f) : ejectVelocity);
				component.velocity = val4 + val5;
				component.angularVelocity = Random.insideUnitSphere * 16f;
			}
			if (LinkDebrisLifetime > 0f)
			{
				Object.Destroy((Object)(object)val3, LinkDebrisLifetime);
			}
		}
		if (LinkFlickSound != null)
		{
			SM.PlayCoreSound((FVRPooledAudioType)10, LinkFlickSound, val);
		}
		if (debug)
		{
			Debug.Log((object)"AdvanceTopCoverControl: Spent link cleared from feed tray.");
		}
	}

	public override void BeginInteraction(FVRViveHand hand)
	{
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		m_isBeingHeld = true;
		m_startedGrabFromClosed = m_currentAngle <= base.MinMaxAngle.x + 5f;
		((FVRFireArmTopCoverAdvanced)this).BeginInteraction(hand);
		m_hasPlayedInterlockRattle = false;
		m_hasPlayedLatchRattle = false;
		m_isImperfectlyLatched = false;
		if (m_currentAngle <= base.MinMaxAngle.x + 1f && RequireLatchButtonToOpen)
		{
			if (IsLatchButtonPressed(hand))
			{
				m_isLatchUnlocked = true;
				if (LatchUnlockSound != null)
				{
					SM.PlayCoreSound((FVRPooledAudioType)10, LatchUnlockSound, ((Component)this).transform.position);
				}
				if ((Object)(object)hand != (Object)null && (Object)(object)hand.Buzzer != (Object)null)
				{
					hand.Buzz(hand.Buzzer.Buzz_BeginInteraction);
				}
			}
			else
			{
				m_isLatchUnlocked = false;
			}
		}
		else
		{
			m_isLatchUnlocked = true;
		}
		if (debug)
		{
			Debug.Log((object)("AdvanceTopCoverControl: BeginInteraction at angle " + m_currentAngle));
		}
	}

	public override void UpdateInteraction(FVRViveHand hand)
	{
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: 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_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_0279: Unknown result type (might be due to invalid IL or missing references)
		//IL_027e: 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: Expected O, but got Unknown
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Invalid comparison between Unknown and I4
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Invalid comparison between Unknown and I4
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Invalid comparison between Unknown and I4
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)hand == (Object)null)
		{
			return;
		}
		if (RequireBoltAtRearToMove && base.FireArm is OpenBoltReceiver)
		{
			OpenBoltReceiver val = (OpenBoltReceiver)base.FireArm;
			if ((Object)(object)val.Bolt != (Object)null && (int)val.Bolt.CurPos != 4 && (int)val.Bolt.CurPos != 2 && (int)val.Bolt.CurPos != 3)
			{
				SetAngle(Mathf.Min(m_currentAngle, base.MinMaxAngle.x + InterlockJiggleMaxAngle));
				if (!m_hasPlayedInterlockRattle)
				{
					if (InterlockRattleSound != null)
					{
						SM.PlayCoreSound((FVRPooledAudioType)10, InterlockRattleSound, ((Component)this).transform.position);
					}
					if ((Object)(object)hand.Buzzer != (Object)null)
					{
						hand.Buzz(hand.Buzzer.Buzz_OnHoverInteractive);
					}
					m_hasPlayedInterlockRattle = true;
				}
				return;
			}
		}
		if (RequireLatchButtonToOpen && !m_isLatchUnlocked)
		{
			if (!IsLatchButtonPressed(hand))
			{
				SetAngle(Mathf.Min(m_currentAngle, base.MinMaxAngle.x + LatchJiggleMaxAngle));
				if (!m_hasPlayedLatchRattle)
				{
					if (LatchRattleSound != null)
					{
						SM.PlayCoreSound((FVRPooledAudioType)10, LatchRattleSound, ((Component)this).transform.position);
					}
					if ((Object)(object)hand.Buzzer != (Object)null)
					{
						hand.Buzz(hand.Buzzer.Buzz_OnHoverInteractive);
					}
					m_hasPlayedLatchRattle = true;
				}
				return;
			}
			m_isLatchUnlocked = true;
			if (LatchUnlockSound != null)
			{
				SM.PlayCoreSound((FVRPooledAudioType)10, LatchUnlockSound, ((Component)this).transform.position);
			}
			if ((Object)(object)hand.Buzzer != (Object)null)
			{
				hand.Buzz(hand.Buzzer.Buzz_BeginInteraction);
			}
		}
		Transform stableReferenceTransform = GetStableReferenceTransform();
		Vector3 val2 = ((HandInput)(ref hand.Input)).Pos - ((Component)this).transform.position;
		Vector3 worldHingeAxis = GetWorldHingeAxis(stableReferenceTransform);
		Vector3 val3 = Vector3.ProjectOnPlane(val2, worldHingeAxis);
		Vector3 normalized = ((Vector3)(ref val3)).normalized;
		Vector3 val4 = Vector3.Cross(worldHingeAxis, -stableReferenceTransform.forward);
		float num = Mathf.Sign(Vector3.Dot(normalized, val4));
		float num2 = Vector3.Angle(normalized, -stableReferenceTransform.forward) * num;
		float num3 = Mathf.Clamp(num2, base.MinMaxAngle.x, base.MinMaxAngle.y);
		if (m_startedGrabFromClosed && num3 > base.MinMaxAngle.x + 10f)
		{
			if ((Object)(object)base.FireArm != (Object)null)
			{
				base.FireArm.PlayAudioEvent((FirearmAudioEventType)23, 1f);
			}
			m_startedGrabFromClosed = false;
		}
		SetAngle(num3);
		if (num3 > base.SnappingThresholds.x)
		{
			m_isLatchUnlocked = true;
		}
	}

	public override void EndInteraction(FVRViveHand hand)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Invalid comparison between Unknown and I4
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Invalid comparison between Unknown and I4
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Invalid comparison between Unknown and I4
		m_isBeingHeld = false;
		m_startedGrabFromClosed = false;
		bool flag = false;
		if (RequireBoltAtRearToMove && base.FireArm is OpenBoltReceiver)
		{
			OpenBoltReceiver val = (OpenBoltReceiver)base.FireArm;
			if ((Object)(object)val.Bolt != (Object)null && (int)val.Bolt.CurPos != 4 && (int)val.Bolt.CurPos != 2 && (int)val.Bolt.CurPos != 3)
			{
				flag = true;
			}
		}
		bool flag2 = RequireLatchButtonToOpen && !m_isLatchUnlocked;
		if (flag || flag2)
		{
			SetAngle(base.MinMaxAngle.x);
			if ((Object)(object)base.FireArm != (Object)null)
			{
				base.FireArm.IsTopCoverUp = false;
			}
			((FVRFireArmTopCoverAdvanced)this).EndInteraction(hand);
			SetAngle(base.MinMaxAngle.x);
			if ((Object)(object)base.FireArm != (Object)null)
			{
				base.FireArm.IsTopCoverUp = false;
			}
			return;
		}
		float speed = ((!((Object)(object)hand != (Object)null)) ? 0f : ((Vector3)(ref hand.Input.VelLinearWorld)).magnitude);
		float currentAngle = m_currentAngle;
		((FVRFireArmTopCoverAdvanced)this).EndInteraction(hand);
		if (currentAngle <= base.SnappingThresholds.x)
		{
			SetAngle(base.MinMaxAngle.x);
			if ((Object)(object)base.FireArm != (Object)null)
			{
				base.FireArm.IsTopCoverUp = false;
				base.FireArm.PlayAudioEvent((FirearmAudioEventType)24, 1f);
			}
		}
		else if (currentAngle >= base.SnappingThresholds.y)
		{
			SetAngle(base.MinMaxAngle.y);
			if ((Object)(object)base.FireArm != (Object)null)
			{
				base.FireArm.IsTopCoverUp = true;
			}
		}
		if ((Object)(object)base.FireArm != (Object)null && !base.FireArm.IsTopCoverUp)
		{
			TryTriggerSlamMisfeed(speed);
			RollForMislatch();
			if (!m_isImperfectlyLatched)
			{
				m_isLatchUnlocked = false;
			}
		}
		if (debug)
		{
			Debug.Log((object)("AdvanceTopCoverControl: EndInteraction at angle " + m_currentAngle));
		}
	}

	private void TryTriggerSlamMisfeed(float speed)
	{
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		if (EnableAllJamsAndMisfeeds && CanMisfeedOnSlam && speed >= SlamVelocityThreshold && (Object)(object)base.FireArm != (Object)null && base.FireArm.HasBelt && (Object)(object)base.FireArm.BeltDD != (Object)null && base.FireArm.BeltDD.BeltRounds.Count > 0)
		{
			base.FireArm.BeltDD.RemoveRound(false);
			if (MisfeedSound != null)
			{
				SM.PlayCoreSound((FVRPooledAudioType)10, MisfeedSound, ((Component)this).transform.position);
			}
			if (debug)
			{
				Debug.Log((object)("AdvanceTopCoverControl: Slammed shut at " + speed + " m/s - misfed a round."));
			}
		}
	}

	private void RollForMislatch()
	{
		if (!EnableAllJamsAndMisfeeds)
		{
			m_isImperfectlyLatched = false;
		}
		else if (LinkReloadEnforcement == LinkReloadEnforcementMode.LatchGate && m_hasRetainedSpentLink)
		{
			m_isImperfectlyLatched = true;
			SetAngle(base.MinMaxAngle.x + MislatchRestAngle);
			if ((Object)(object)base.FireArm != (Object)null)
			{
				base.FireArm.IsTopCoverUp = true;
			}
			if (debug)
			{
				Debug.Log((object)"AdvanceTopCoverControl: Cover blocked from latching by un-cleared spent link.");
			}
		}
		else if (MislatchChance > 0f && Random.value < MislatchChance)
		{
			m_isImperfectlyLatched = true;
			SetAngle(base.MinMaxAngle.x + MislatchRestAngle);
			if ((Object)(object)base.FireArm != (Object)null)
			{
				base.FireArm.IsTopCoverUp = true;
			}
			if (debug)
			{
				Debug.Log((object)"AdvanceTopCoverControl: Cover did not latch fully.");
			}
		}
		else
		{
			m_isImperfectlyLatched = false;
		}
	}

	private bool IsLatchButtonPressed(FVRViveHand hand)
	{
		if ((Object)(object)hand == (Object)null)
		{
			return false;
		}
		return LatchReleaseButton switch
		{
			LatchButtonInput.TouchpadOrJoystick => hand.Input.TouchpadDown || hand.Input.TouchpadPressed || hand.Input.Secondary2AxisNorthDown || hand.Input.Secondary2AxisCenterDown, 
			LatchButtonInput.BYButton => hand.Input.BYButtonDown || hand.Input.BYButtonPressed, 
			LatchButtonInput.AXButton => hand.Input.AXButtonDown || hand.Input.AXButtonPressed, 
			LatchButtonInput.TriggerPress => hand.Input.TriggerDown || hand.Input.TriggerPressed, 
			_ => false, 
		};
	}

	public float GetAngle()
	{
		return m_currentAngle;
	}

	public void SetAngle(float angle)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		m_currentAngle = Mathf.Clamp(angle, base.MinMaxAngle.x, base.MinMaxAngle.y);
		Vector3 initialLocalEuler = m_initialLocalEuler;
		switch (RotationHingeAxis)
		{
		case HingeAxis.X:
			initialLocalEuler.x = m_currentAngle;
			break;
		case HingeAxis.Y:
			initialLocalEuler.y = m_currentAngle;
			break;
		case HingeAxis.Z:
			initialLocalEuler.z = m_currentAngle;
			break;
		}
		((Component)this).transform.localEulerAngles = initialLocalEuler;
	}

	private Transform GetStableReferenceTransform()
	{
		if ((Object)(object)base.BaseVector != (Object)null && (Object)(object)base.BaseVector != (Object)(object)((Component)this).transform && !base.BaseVector.IsChildOf(((Component)this).transform))
		{
			return base.BaseVector;
		}
		if ((Object)(object)base.FireArm != (Object)null)
		{
			return ((Component)base.FireArm).transform;
		}
		FVRFireArm componentInParent = ((Component)this).GetComponentInParent<FVRFireArm>();
		if ((Object)(object)componentInParent != (Object)null)
		{
			return ((Component)componentInParent).transform;
		}
		return (!((Object)(object)((Component)this).transform.parent != (Object)null)) ? ((Component)this).transform : ((Component)this).transform.parent;
	}

	private Vector3 GetWorldHingeAxis(Transform refTransform)
	{
		//IL_0020: 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_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_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: 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_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		return (Vector3)(RotationHingeAxis switch
		{
			HingeAxis.X => refTransform.right, 
			HingeAxis.Y => refTransform.up, 
			HingeAxis.Z => refTransform.forward, 
			_ => refTransform.right, 
		});
	}

	private Vector3 TransformMassOffsetAtAngle(float angle)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: 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_0049: 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_004f: 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_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: 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_0032: 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_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: 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_0080: 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_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: 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)
		Vector3 val = Vector3.right;
		switch (RotationHingeAxis)
		{
		case HingeAxis.X:
			val = Vector3.right;
			break;
		case HingeAxis.Y:
			val = Vector3.up;
			break;
		case HingeAxis.Z:
			val = Vector3.forward;
			break;
		}
		Quaternion val2 = Quaternion.AngleAxis(angle, val);
		Vector3 val3 = val2 * LocalMassOffsetAtClosed;
		if ((Object)(object)((Component)this).transform.parent != (Object)null)
		{
			return ((Component)this).transform.parent.TransformDirection(val3);
		}
		return val3;
	}
}
public class ObservedObjectEnabler : MonoBehaviour
{
	[Header("Observed Target")]
	[Tooltip("The GameObject mesh or joint to observe.")]
	public Transform ObservedObject;

	[Header("Tracking Mode")]
	public bool ObservePosition = false;

	public bool ObserveRotation = true;

	[Header("Target Values")]
	[Tooltip("The local position target to reach.")]
	public Vector3 TargetPosition = Vector3.zero;

	[Tooltip("The local rotation target to reach (Euler angles).")]
	public Vector3 TargetRotation = new Vector3(90f, 0f, 0f);

	[Header("Tolerance Settings")]
	[Tooltip("Distance in meters to consider the position reached.")]
	public float DistanceTolerance = 0.05f;

	[Tooltip("Angle in degrees to consider the rotation reached.")]
	public float AngleTolerance = 1f;

	[Header("Trigger Actions")]
	[Tooltip("The GameObject to enable or disable when the target is reached.")]
	public GameObject TargetObject;

	[Tooltip("Should the TargetObject be set Active (true) or Inactive (false) when reached?")]
	public bool SetObjectActiveOnReach = true;

	[Tooltip("The Collider to enable or disable when the target is reached.")]
	public Collider TargetCollider;

	[Tooltip("Should the TargetCollider be set Enabled (true) or Disabled (false) when reached?")]
	public bool SetColliderEnabledOnReach = true;

	[Header("Behavior Settings")]
	[Tooltip("If true, the target object/collider will revert to their opposite state when the observed object moves away from the target values.")]
	public bool ResetWhenLeavingTarget = true;

	private bool m_isTargetReached = false;

	private bool m_hasTriggered = false;

	private void Update()
	{
		//IL_002d: 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_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: 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_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)ObservedObject == (Object)null)
		{
			return;
		}
		bool flag = true;
		bool flag2 = true;
		if (ObservePosition)
		{
			float num = Vector3.Distance(ObservedObject.localPosition, TargetPosition);
			flag = num <= DistanceTolerance;
		}
		if (ObserveRotation)
		{
			Quaternion localRotation = ObservedObject.localRotation;
			Quaternion val = Quaternion.Euler(TargetRotation);
			float num2 = Quaternion.Angle(localRotation, val);
			flag2 = num2 <= AngleTolerance;
		}
		bool flag3 = true;
		if (ObservePosition && !flag)
		{
			flag3 = false;
		}
		if (ObserveRotation && !flag2)
		{
			flag3 = false;
		}
		if (flag3)
		{
			if (!m_isTargetReached)
			{
				m_isTargetReached = true;
				if (!m_hasTriggered || ResetWhenLeavingTarget)
				{
					ApplyTriggerState(targetReached: true);
					m_hasTriggered = true;
				}
			}
		}
		else if (m_isTargetReached)
		{
			m_isTargetReached = false;
			if (ResetWhenLeavingTarget)
			{
				ApplyTriggerState(targetReached: false);
				m_hasTriggered = false;
			}
		}
	}

	private void ApplyTriggerState(bool targetReached)
	{
		if ((Object)(object)TargetObject != (Object)null)
		{
			bool active = ((!targetReached) ? (!SetObjectActiveOnReach) : SetObjectActiveOnReach);
			TargetObject.SetActive(active);
		}
		if ((Object)(object)TargetCollider != (Object)null)
		{
			bool enabled = ((!targetReached) ? (!SetColliderEnabledOnReach) : SetColliderEnabledOnReach);
			TargetCollider.enabled = enabled;
		}
	}
}
public class HeatEffectToggleObject : FirearmHeatingEffect
{
	[Header("Explosion Spawn")]
	public GameObject PrefabToSpawn;

	public Transform SpawnPoint;

	public float ToggleHeatThreshold = 0.95f;

	private bool hasSpawned = false;

	public void Update()
	{
		//IL_007a: 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_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		((FirearmHeatingEffect)this).Update();
		if (hasSpawned || !(base.Heat >= ToggleHeatThreshold))
		{
			return;
		}
		if ((Object)(object)PrefabToSpawn != (Object)null)
		{
			if ((Object)(object)SpawnPoint != (Object)null)
			{
				Object.Instantiate<GameObject>(PrefabToSpawn, SpawnPoint.position, SpawnPoint.rotation);
			}
			else
			{
				Object.Instantiate<GameObject>(PrefabToSpawn, ((Component)this).transform.position, ((Component)this).transform.rotation);
			}
		}
		hasSpawned = true;
	}
}
public class MGBarrel : MuzzleDevice
{
	[Header("MGBarrel Lock Settings")]
	public float CatchRot;

	public bool IsLocked = false;

	public AudioSource AudSourceLock;

	public AudioClip AudClipLock;

	public Vector3 LockedLocalPosition;

	public Vector3 LockedLocalEulerAngles;

	public float LockAngle = 90f;

	public bool HasPlayedLockSound = false;

	[Header("Loose Barrel Settings")]
	public int ShotsUntilFallOff = 3;

	[HideInInspector]
	public int ShotsFiredWhileLoose = 0;

	protected void Awake()
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		((MuzzleDevice)this).Awake();
		((FVRFireArmAttachment)this).Type = (FVRFireArmAttachementMountType)2;
	}

	public override void AttachToMount(FVRFireArmAttachmentMount m, bool playSound)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		((FVRFireArmAttachment)this).AttachToMount(m, playSound);
		((Component)this).transform.localEulerAngles = new Vector3(0f, 0f, CatchRot);
	}

	public override void OnShot(FVRFireArm f, FVRTailSoundClass tailClass)
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		if (!IsLocked && (Object)(object)((FVRFireArmAttachment)this).curMount != (Object)null)
		{
			ShotsFiredWhileLoose++;
			if (ShotsFiredWhileLoose >= ShotsUntilFallOff)
			{
				((FVRFireArmAttachment)this).DetachFromMount();
			}
		}
		else
		{
			ShotsFiredWhileLoose = 0;
		}
		((MuzzleDevice)this).OnShot(f, tailClass);
	}
}
public class MGBarrelInterface : MuzzleDeviceInterface
{
	private MGBarrel tempBarrel;

	private Vector3 lastHandForward = Vector3.zero;

	private Vector3 lastMountForward = Vector3.zero;

	public AudioClip AudClipUnlock;

	public AudioSource AudSourceUnlock;

	private const float lockThreshold = 2f;

	private const float unlockThreshold = 2f;

	private float lockCooldownTime = 0f;

	private float lockCooldownTimer = 0f;

	public float LockSnapBuffer = 3f;

	public float LockedPreventDetachTime = 0.35f;

	private float lockedGraceTimer = 0f;

	public float UnlockAllowDetachTime = 0.5f;

	private float canBePulledTimer = 0f;

	private Vector3 mountedLocalPosition = Vector3.zero;

	private bool mountedLocalPositionRecorded = false;

	public float DetachDistanceThreshold = 0.08f;

	private bool m_isInSnappingMode = false;

	private bool hasPlayedUnlockSoundThisUnlock = false;

	public float IgnoreDetachOnGrabTime = 0.12f;

	private float ignoreDetachTimer = 0f;

	public override void Awake()
	{
		((FVRFireArmAttachmentInterface)this).Awake();
		tempBarrel = ((FVRFireArmAttachmentInterface)this).Attachment as MGBarrel;
	}

	public override void OnAttach()
	{
		//IL_0036: 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_0082: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		((MuzzleDeviceInterface)this).OnAttach();
		tempBarrel = ((FVRFireArmAttachmentInterface)this).Attachment as MGBarrel;
		if ((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null)
		{
			mountedLocalPosition = ((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localPosition;
			mountedLocalPositionRecorded = true;
			((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localEulerAngles = new Vector3(0f, 0f, (!((Object)(object)tempBarrel != (Object)null)) ? 0f : tempBarrel.CatchRot);
		}
		if ((Object)(object)((FVRInteractiveObject)this).m_hand != (Object)null && ((FVRInteractiveObject)this).IsHeld && (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null && (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount != (Object)null)
		{
			SetSnapping(b: true);
			lastHandForward = ((HandInput)(ref ((FVRInteractiveObject)this).m_hand.Input)).Up;
			lastMountForward = ((Component)((FVRFireArmAttachmentInterface)this).Attachment.curMount).transform.up;
			lockCooldownTimer = 0f;
			lockedGraceTimer = 0f;
			canBePulledTimer = 0f;
			hasPlayedUnlockSoundThisUnlock = false;
			TryLockImmediateOnAttach();
		}
	}

	private void TryLockImmediateOnAttach()
	{
		if ((Object)(object)tempBarrel == (Object)null || (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment == (Object)null || (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount == (Object)null)
		{
			return;
		}
		float lockAngle = tempBarrel.LockAngle;
		float num = 2f + LockSnapBuffer;
		if (tempBarrel.IsLocked)
		{
			return;
		}
		if (lockAngle >= 0f)
		{
			if (tempBarrel.CatchRot >= lockAngle - num)
			{
				DoLock(lockAngle);
			}
		}
		else if (tempBarrel.CatchRot <= lockAngle + num)
		{
			DoLock(lockAngle);
		}
	}

	private void DoLock(float target)
	{
		//IL_0080: 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_0049: 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_0059: 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)
		tempBarrel.CatchRot = target;
		tempBarrel.IsLocked = true;
		lockedGraceTimer = LockedPreventDetachTime;
		lockCooldownTimer = lockCooldownTime;
		if (mountedLocalPositionRecorded)
		{
			((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localPosition = mountedLocalPosition + tempBarrel.LockedLocalPosition;
		}
		else
		{
			((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localPosition = ((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localPosition + tempBarrel.LockedLocalPosition;
		}
		((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localEulerAngles = new Vector3(0f, 0f, target);
		if (!tempBarrel.HasPlayedLockSound && (Object)(object)tempBarrel.AudSourceLock != (Object)null && (Object)(object)tempBarrel.AudClipLock != (Object)null)
		{
			tempBarrel.AudSourceLock.PlayOneShot(tempBarrel.AudClipLock);
			tempBarrel.HasPlayedLockSound = true;
		}
		canBePulledTimer = 0f;
		hasPlayedUnlockSoundThisUnlock = false;
	}

	private void DoUnlock()
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		tempBarrel.IsLocked = false;
		tempBarrel.HasPlayedLockSound = false;
		tempBarrel.CatchRot = 0f;
		((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localEulerAngles = new Vector3(0f, 0f, 0f);
		if (mountedLocalPositionRecorded)
		{
			((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localPosition = mountedLocalPosition;
		}
		canBePulledTimer = UnlockAllowDetachTime;
		if (!hasPlayedUnlockSoundThisUnlock && (Object)(object)AudSourceUnlock != (Object)null && (Object)(object)AudClipUnlock != (Object)null)
		{
			AudSourceUnlock.PlayOneShot(AudClipUnlock);
			hasPlayedUnlockSoundThisUnlock = true;
		}
	}

	public override void OnDetach()
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)tempBarrel != (Object)null && mountedLocalPositionRecorded && (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null)
		{
			((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localPosition = mountedLocalPosition;
		}
		if ((Object)(object)tempBarrel != (Object)null)
		{
			tempBarrel.IsLocked = false;
			tempBarrel.HasPlayedLockSound = false;
			tempBarrel.CatchRot = 0f;
		}
		((MuzzleDeviceInterface)this).OnDetach();
		mountedLocalPositionRecorded = false;
		canBePulledTimer = 0f;
		hasPlayedUnlockSoundThisUnlock = false;
	}

	public override void BeginInteraction(FVRViveHand hand)
	{
		//IL_0014: 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_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: 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)
		((FVRInteractiveObject)this).BeginInteraction(hand);
		lastHandForward = ((HandInput)(ref ((FVRInteractiveObject)this).m_hand.Input)).Up;
		lastMountForward = ((!((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null) || !((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount != (Object)null)) ? Vector3.up : ((Component)((FVRFireArmAttachmentInterface)this).Attachment.curMount).transform.up);
		lockCooldownTimer = 0f;
		lockedGraceTimer = 0f;
		canBePulledTimer = 0f;
		hasPlayedUnlockSoundThisUnlock = false;
		ignoreDetachTimer = IgnoreDetachOnGrabTime;
	}

	public override void UpdateInteraction(FVRViveHand hand)
	{
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02db: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
		((FVRFireArmAttachmentInterface)this).UpdateInteraction(hand);
		if (lockedGraceTimer > 0f)
		{
			lockedGraceTimer -= Time.deltaTime;
			if (lockedGraceTimer < 0f)
			{
				lockedGraceTimer = 0f;
			}
		}
		if (lockCooldownTimer > 0f)
		{
			lockCooldownTimer -= Time.deltaTime;
			if (lockCooldownTimer < 0f)
			{
				lockCooldownTimer = 0f;
			}
		}
		if (canBePulledTimer > 0f)
		{
			canBePulledTimer -= Time.deltaTime;
			if (canBePulledTimer <= 0f)
			{
				canBePulledTimer = 0f;
			}
		}
		if (ignoreDetachTimer > 0f)
		{
			ignoreDetachTimer -= Time.deltaTime;
			if (ignoreDetachTimer < 0f)
			{
				ignoreDetachTimer = 0f;
			}
		}
		UpdateSnappingBasedOnDistance();
		if (((FVRInteractiveObject)this).IsHeld && (Object)(object)tempBarrel != (Object)null)
		{
			((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localEulerAngles = new Vector3(0f, 0f, tempBarrel.CatchRot);
		}
		if ((Object)(object)tempBarrel == (Object)null)
		{
			return;
		}
		float lockAngle = tempBarrel.LockAngle;
		float num = 2f + LockSnapBuffer;
		if (!tempBarrel.IsLocked)
		{
			if (lockAngle >= 0f)
			{
				if (tempBarrel.CatchRot >= lockAngle - num)
				{
					DoLock(lockAngle);
				}
			}
			else if (tempBarrel.CatchRot <= lockAngle + num)
			{
				DoLock(lockAngle);
			}
		}
		else if (Mathf.Abs(tempBarrel.CatchRot) <= 2f && lockedGraceTimer <= 0f)
		{
			DoUnlock();
		}
		if (tempBarrel.IsLocked || !((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null) || !((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount != (Object)null))
		{
			return;
		}
		FVRFireArmAttachmentMount rootMount = ((FVRFireArmAttachmentInterface)this).Attachment.curMount.GetRootMount();
		Transform val = ((!((Object)(object)rootMount != (Object)null) || !(rootMount.MyObject is FVRFireArm)) ? null : ((FVRFireArm)rootMount.MyObject).MuzzlePos);
		if (!((Object)(object)val != (Object)null))
		{
			return;
		}
		Vector3 closestValidPoint = ((FVRInteractiveObject)this).GetClosestValidPoint(((FVRFireArmAttachmentInterface)this).Attachment.curMount.Point_Front.position, val.position, ((Component)this).transform.position);
		float num2 = Vector3.Distance(((HandInput)(ref ((FVRInteractiveObject)this).m_hand.Input)).Pos, closestValidPoint);
		if (canBePulledTimer > 0f)
		{
			if (num2 > DetachDistanceThreshold)
			{
				canBePulledTimer = 0f;
				((FVRInteractiveObject)this).EndInteraction(hand);
				hand.ForceSetInteractable((FVRInteractiveObject)(object)((FVRFireArmAttachmentInterface)this).Attachment);
				((FVRInteractiveObject)((FVRFireArmAttachmentInterface)this).Attachment).BeginInteraction(hand);
			}
		}
		else if (ignoreDetachTimer <= 0f && num2 > DetachDistanceThreshold)
		{
			((FVRInteractiveObject)this).EndInteraction(hand);
			hand.ForceSetInteractable((FVRInteractiveObject)(object)((FVRFireArmAttachmentInterface)this).Attachment);
			((FVRInteractiveObject)((FVRFireArmAttachmentInterface)this).Attachment).BeginInteraction(hand);
		}
	}

	public override void FVRFixedUpdate()
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: 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_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: 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_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: 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_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: 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_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: 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)
		if ((Object)(object)tempBarrel == (Object)null)
		{
			((FVRInteractiveObject)this).FVRFixedUpdate();
			return;
		}
		if (((FVRInteractiveObject)this).IsHeld && m_isInSnappingMode && lockCooldownTimer <= 0f && lockedGraceTimer <= 0f)
		{
			Vector3 val = Vector3.ProjectOnPlane(((HandInput)(ref ((FVRInteractiveObject)this).m_hand.Input)).Up, ((Component)this).transform.forward);
			Vector3 val2 = Vector3.ProjectOnPlane(lastHandForward, ((Component)this).transform.forward);
			float num = Mathf.Atan2(Vector3.Dot(((Component)this).transform.forward, Vector3.Cross(val, val2)), Vector3.Dot(val, val2)) * 57.29578f;
			Vector3 val3 = Vector3.ProjectOnPlane((!((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null) || !((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount != (Object)null)) ? Vector3.up : ((Component)((FVRFireArmAttachmentInterface)this).Attachment.curMount).transform.up, ((Component)this).transform.forward);
			Vector3 val4 = Vector3.ProjectOnPlane(lastMountForward, ((Component)this).transform.forward);
			float num2 = Mathf.Atan2(Vector3.Dot(((Component)this).transform.forward, Vector3.Cross(val3, val4)), Vector3.Dot(val3, val4)) * 57.29578f;
			tempBarrel.CatchRot -= num;
			tempBarrel.CatchRot += num2;
			float lockAngle = tempBarrel.LockAngle;
			float num3 = Mathf.Min(0f, lockAngle);
			float num4 = Mathf.Max(0f, lockAngle);
			tempBarrel.CatchRot = Mathf.Clamp(tempBarrel.CatchRot, num3, num4);
			lastHandForward = ((HandInput)(ref ((FVRInteractiveObject)this).m_hand.Input)).Up;
			lastMountForward = ((!((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null) || !((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount != (Object)null)) ? lastMountForward : ((Component)((FVRFireArmAttachmentInterface)this).Attachment.curMount).transform.up);
		}
		((FVRInteractiveObject)this).FVRFixedUpdate();
	}

	public override void EndInteraction(FVRViveHand hand)
	{
		if (!tempBarrel.IsLocked && Mathf.Abs(tempBarrel.CatchRot) <= 2f && lockedGraceTimer <= 0f)
		{
			((FVRInteractiveObject)this).EndInteraction(hand);
		}
	}

	private void UpdateSnappingBasedOnDistance()
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: 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)
		if ((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment == (Object)null || (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount == (Object)null)
		{
			SetSnapping(b: false);
			return;
		}
		if (((FVRInteractiveObject)this).IsHeld)
		{
			SetSnapping(b: true);
			return;
		}
		Vector3 closestValidPoint = ((FVRInteractiveObject)this).GetClosestValidPoint(((FVRFireArmAttachmentInterface)this).Attachment.curMount.Point_Front.position, ((FVRFireArmAttachmentInterface)this).Attachment.curMount.Point_Rear.position, ((Component)this).transform.position);
		if (Vector3.Distance(closestValidPoint, ((Component)this).transform.position) < DetachDistanceThreshold || ((Object)(object)tempBarrel != (Object)null && Mathf.Abs(tempBarrel.CatchRot) > 1f))
		{
			SetSnapping(b: true);
		}
		else
		{
			SetSnapping(b: false);
		}
	}

	private void SetSnapping(bool b)
	{
		//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_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		if (m_isInSnappingMode == b)
		{
			return;
		}
		m_isInSnappingMode = b;
		if (m_isInSnappingMode)
		{
			((FVRInteractiveObject)this).SetAllCollidersToLayer(false, "NoCol");
			if ((Object)(object)((FVRInteractiveObject)this).m_hand != (Object)null)
			{
				lastHandForward = ((HandInput)(ref ((FVRInteractiveObject)this).m_hand.Input)).Up;
			}
			if ((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null && (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount != (Object)null)
			{
				lastMountForward = ((Component)((FVRFireArmAttachmentInterface)this).Attachment.curMount).transform.up;
			}
		}
		else
		{
			((FVRInteractiveObject)this).SetAllCollidersToLayer(false, "Default");
		}
	}
}
namespace Volks.ModulARLMG;

[BepInPlugin("Volks.ModulARLMG", "ModulARLMG", "1.2.0")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
[BepInDependency("h3vr.cityrobo.ModularWorkshopManager", "1.0.0")]
[BepInDependency("nrgill28.Sodalite", "1.4.1")]
public class ModulARLMGPlugin : BaseUnityPlugin
{
	private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

	internal static ManualLogSource Logger;

	private void Awake()
	{
		Logger = ((BaseUnityPlugin)this).Logger;
		LoadAssets();
	}

	private void LoadAssets()
	{
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "Volks.ModulARLMG");
		OtherLoader.RegisterDirectLoad(BasePath, "Volks.ModulARLMG", "", "", "modularlmg", "");
		GameAPI.PreloadAllAssets(Path.Combine(BasePath, "mw_modularlmg"));
	}
}
public class AdvanceFeedTrayControl : FVRInteractiveObject
{
	public enum HingeAxis
	{
		X,
		Y,
		Z
	}

	[Header("Axis and Angle Configuration")]
	[Tooltip("Local axis around which the feed tray rotates.")]
	public HingeAxis RotationHingeAxis = HingeAxis.X;

	[Tooltip("Maximum angle in degrees the feed tray can be lifted.")]
	public float MaxFeedTrayAngle = 45f;

	[Tooltip("Optional static reference transform on the receiver. If empty or self, uses firearm root.")]
	public Transform BaseVector;

	[Header("Connections")]
	[Tooltip("Reference to the Top Cover script.")]
	public AdvanceTopCoverControl TopCover;

	[Header("Audio")]
	public AudioEvent TrayOpenSound;

	public AudioEvent TrayCloseSound;

	private float m_currentAngle;

	private bool m_wasUp;

	private bool m_wasOpenInGrab;

	private bool m_wasClosedInGrab;

	private Vector3 m_initialLocalEuler;

	public override void Awake()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		((FVRInteractiveObject)this).Awake();
		m_initialLocalEuler = ((Component)this).transform.localEulerAngles;
	}

	public override void Start()
	{
		((FVRInteractiveObject)this).Start();
		if ((Object)(object)TopCover == (Object)null)
		{
			FVRFireArm componentInParent = ((Component)this).GetComponentInParent<FVRFireArm>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				TopCover = ((Component)componentInParent).GetComponentInChildren<AdvanceTopCoverControl>();
			}
		}
		if ((Object)(object)TopCover != (Object)null && (Object)(object)TopCover.TargetFeedTray == (Object)null)
		{
			TopCover.TargetFeedTray = this;
		}
		SetAngle(0f);
	}

	public override bool IsInteractable()
	{
		if ((Object)(object)TopCover == (Object)null)
		{
			FVRFireArm componentInParent = ((Component)this).GetComponentInParent<FVRFireArm>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				TopCover = ((Component)componentInParent).GetComponentInChildren<AdvanceTopCoverControl>();
			}
		}
		if ((Object)(object)TopCover == (Object)null || TopCover.GetAngle() < 25f)
		{
			return false;
		}
		FVRFireArm val = ((!((Object)(object)TopCover != (Object)null)) ? ((Component)this).GetComponentInParent<FVRFireArm>() : ((FVRFireArmTopCoverAdvanced)TopCover).FireArm);
		if ((Object)(object)val != (Object)null)
		{
			if (val.HasBelt || (Object)(object)val.Magazine != (Object)null)
			{
				return false;
			}
			if ((Object)(object)val.BeltDD != (Object)null && val.BeltDD.BeltRounds.Count > 0)
			{
				return false;
			}
		}
		return ((FVRInteractiveObject)this).IsInteractable();
	}

	public override void Poke(FVRViveHand hand)
	{
		//IL_009c: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		((FVRInteractiveObject)this).Poke(hand);
		if ((Object)(object)hand == (Object)null || ((FVRInteractiveObject)this).IsHeld || (Object)(object)TopCover == (Object)null || !TopCover.HasRetainedSpentLink() || !(TopCover.GetAngle() > 15f) || !TopCover.CanClearLink())
		{
			return;
		}
		float magnitude = ((Vector3)(ref hand.Input.VelLinearWorld)).magnitude;
		float requiredLinkClearSpeed = TopCover.GetRequiredLinkClearSpeed();
		if (magnitude >= requiredLinkClearSpeed)
		{
			Vector3 ejectVelocity = ((Vector3)(ref hand.Input.VelLinearWorld)).normalized * (TopCover.LinkEjectForce * 1.5f) + Vector3.up * 0.6f;
			TopCover.ClearSpentLink(ejectVelocity);
			if ((Object)(object)hand.Buzzer != (Object)null)
			{
				hand.Buzz(hand.Buzzer.Buzz_BeginInteraction);
			}
		}
	}

	public override void BeginInteraction(FVRViveHand hand)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		((FVRInteractiveObject)this).BeginInteraction(hand);
		m_wasOpenInGrab = m_currentAngle > 15f;
		m_wasClosedInGrab = m_currentAngle < 5f;
		if (m_currentAngle < 5f && TrayOpenSound != null)
		{
			SM.PlayCoreSound((FVRPooledAudioType)10, TrayOpenSound, ((Component)this).transform.position);
			m_wasOpenInGrab = true;
			m_wasClosedInGrab = false;
		}
	}

	public override void UpdateInteraction(FVRViveHand hand)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: 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_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: 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_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: 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)
		//IL_004f: 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_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_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)hand == (Object)null)
		{
			return;
		}
		Transform stableReferenceTransform = GetStableReferenceTransform();
		Vector3 val = ((HandInput)(ref hand.Input)).Pos - ((Component)this).transform.position;
		Vector3 worldHingeAxis = GetWorldHingeAxis(stableReferenceTransform);
		Vector3 val2 = Vector3.ProjectOnPlane(val, worldHingeAxis);
		Vector3 normalized = ((Vector3)(ref val2)).normalized;
		Vector3 val3 = Vector3.Cross(worldHingeAxis, -stableReferenceTransform.forward);
		float num = Mathf.Sign(Vector3.Dot(normalized, val3));
		float num2 = Vector3.Angle(normalized, -stableReferenceTransform.forward) * num;
		float num3 = Mathf.Clamp(num2, 0f, MaxFeedTrayAngle);
		if ((Object)(object)TopCover != (Object)null)
		{
			num3 = Mathf.Min(num3, TopCover.GetAngle());
		}
		if (num3 > 15f && !m_wasOpenInGrab)
		{
			if (TrayOpenSound != null)
			{
				SM.PlayCoreSound((FVRPooledAudioType)10, TrayOpenSound, ((Component)this).transform.position);
			}
			m_wasOpenInGrab = true;
			m_wasClosedInGrab = false;
		}
		else if (num3 < 5f && !m_wasClosedInGrab && m_wasOpenInGrab)
		{
			if (TrayCloseSound != null)
			{
				SM.PlayCoreSound((FVRPooledAudioType)10, TrayCloseSound, ((Component)this).transform.position);
			}
			m_wasClosedInGrab = true;
			m_wasOpenInGrab = false;
		}
		SetAngle(num3);
		if (num3 > 15f && (Object)(object)TopCover != (Object)null)
		{
			Vector3 ejectVelocity = ((Component)this).transform.up * (TopCover.LinkEjectForce * 1.2f) + ((Component)this).transform.right * TopCover.LinkEjectForce;
			TopCover.ClearSpentLink(ejectVelocity);
		}
	}

	public override void EndInteraction(FVRViveHand hand)
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		((FVRInteractiveObject)this).EndInteraction(hand);
		if (m_currentAngle < 15f)
		{
			SetAngle(0f);
			if (m_wasUp && !m_wasClosedInGrab && TrayCloseSound != null)
			{
				SM.PlayCoreSound((FVRPooledAudioType)10, TrayCloseSound, ((Component)this).transform.position);
			}
			m_wasUp = false;
		}
		else if (m_currentAngle > MaxFeedTrayAngle - 10f)
		{
			float angle = ((!((Object)(object)TopCover != (Object)null)) ? MaxFeedTrayAngle : Mathf.Min(MaxFeedTrayAngle, TopCover.GetAngle()));
			SetAngle(angle);
			m_wasUp = true;
		}
		else
		{
			m_wasUp = m_currentAngle > 5f;
		}
		m_wasOpenInGrab = false;
		m_wasClosedInGrab = false;
	}

	public float GetAngle()
	{
		return m_currentAngle;
	}

	public void SetAngle(float angle)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		m_currentAngle = Mathf.Clamp(angle, 0f, MaxFeedTrayAngle);
		Vector3 initialLocalEuler = m_initialLocalEuler;
		switch (RotationHingeAxis)
		{
		case HingeAxis.X:
			initialLocalEuler.x = m_currentAngle;
			break;
		case HingeAxis.Y:
			initialLocalEuler.y = m_currentAngle;
			break;
		case HingeAxis.Z:
			initialLocalEuler.z = m_currentAngle;
			break;
		}
		((Component)this).transform.localEulerAngles = initialLocalEuler;
	}

	private Transform GetStableReferenceTransform()
	{
		if ((Object)(object)BaseVector != (Object)null && (Object)(object)BaseVector != (Object)(object)((Component)this).transform && !BaseVector.IsChildOf(((Component)this).transform))
		{
			return BaseVector;
		}
		if ((Object)(object)TopCover != (Object)null && (Object)(object)((FVRFireArmTopCoverAdvanced)TopCover).FireArm != (Object)null)
		{
			return ((Component)((FVRFireArmTopCoverAdvanced)TopCover).FireArm).transform;
		}
		FVRFireArm componentInParent = ((Component)this).GetComponentInParent<FVRFireArm>();
		if ((Object)(object)componentInParent != (Object)null)
		{
			return ((Component)componentInParent).transform;
		}
		return (!((Object)(object)((Component)this).transform.parent != (Object)null)) ? ((Component)this).transform : ((Component)this).transform.parent;
	}

	private Vector3 GetWorldHingeAxis(Transform refTransform)
	{
		//IL_0020: 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_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_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: 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_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		return (Vector3)(RotationHingeAxis switch
		{
			HingeAxis.X => refTransform.right, 
			HingeAxis.Y => refTransform.up, 
			HingeAxis.Z => refTransform.forward, 
			_ => refTransform.right, 
		});
	}
}
[RequireComponent(typeof(FVRFireArmMagazine))]
public class BeltMagazinePhysics : MonoBehaviour
{
	[Header("Debugging")]
	public bool EnableDebug = false;

	[Header("Compatibility")]
	public bool BypassTypeMatching = false;

	public FireArmMagazineType[] CompatibleMagazineTypes;

	[Header("Loading Controls")]
	[Tooltip("Disable magazine reload triggers on Awake. Keep false for standard M249 box/drum magazines so they can mount.")]
	public bool DisableNativeReloadTriggers = false;

	[Header("Visual Container")]
	[Tooltip("The actual child Transform inside the magazine prefab that represents the visual belt.")]
	public Transform VisualBeltContainer;

	[Header("Belt Generator")]
	[Tooltip("Existing single bu