Decompiled source of ARAK ModulAR2 v1.0.0

ARAK_ModulAR2.dll

Decompiled a day 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 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 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.ARAK_ModulAR2;

[BepInPlugin("Volks.ARAK_ModulAR2", "ARAK_ModulAR2", "1.0.0")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.cityrobo.ModularWorkshopManager", "1.0.0")]
[BepInDependency("nrgill28.Sodalite", "1.4.2")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
public class ARAK_ModulAR2Plugin : 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.ARAK_ModulAR2");
		GameAPI.PreloadAllAssets(Path.Combine(BasePath, "mw_arak_modular2"));
		OtherLoader.RegisterDirectLoad(BasePath, "Volks.ARAK_ModulAR2", "", "", "modularak_receiver", "");
	}
}
[RequireComponent(typeof(FVRFireArmMagazine))]
public class BeltMagazinePhysics : MonoBehaviour
{
	[Header("Debugging")]
	[Tooltip("Enable to print diagnostic logs to the BepInEx / Unity developer console.")]
	public bool EnableDebug = false;

	[Header("Compatibility")]
	[Tooltip("If checked, the belt will bypass all magazine type checks and attempt to load into ANY belt-fed gun.")]
	public bool BypassTypeMatching = false;

	[Tooltip("Allows this belt to load into weapons of specific MagazineType enums (e.g. base-game M249 types).")]
	public FireArmMagazineType[] CompatibleMagazineTypes;

	[Header("Belt Chain")]
	[Tooltip("The point where the belt exits the magazine when NOT loaded. Its forward axis defines the exit direction.")]
	public Transform BeltExitPoint;

	[Tooltip("Number of physics nodes rigidly locked along the anchor's exit axis before free simulation begins. Increase this to prevent sagging into the gun.")]
	public int PinnedNodes = 3;

	[Tooltip("Total number of simulation nodes in the chain. More = smoother but more expensive.")]
	public int ChainNodeCount = 8;

	[Tooltip("Distance between each chain node in metres. Set this to match your link spacing (e.g., 0.018 to 0.02 for 5.56 ammo).")]
	public float NodeDistance = 0.02f;

	[Tooltip("Velocity damping per frame when NOT loaded. Lower values (e.g. 0.90) make the belt stiffer and reduce swinging.")]
	[Range(0f, 1f)]
	public float Damping = 0.95f;

	[Tooltip("Gravity scale applied to chain nodes.")]
	public float GravityScale = 1f;

	[Tooltip("Number of constraint solving iterations per frame. More = more stable.")]
	public int ConstraintIterations = 3;

	[Header("Loaded Physics Override")]
	[Range(0f, 1f)]
	[Tooltip("How rigid the belt becomes when loaded into the gun. 0 = fully floppy local physics, 1 = completely frozen straight. Adjust this to eliminate physics jitter when moving with the gun.")]
	public float LoadedRigidity = 0.5f;

	[Range(0f, 1f)]
	[Tooltip("Damping applied strictly when the belt is loaded into the gun. Lower values (e.g. 0.80) heavily slow down the swinging and absorb movement jitter.")]
	public float LoadedDamping = 0.9f;

	[Header("Bending Stiffness")]
	[Range(0f, 1f)]
	[Tooltip("How much the belt resists folding/bending. Higher values (e.g. 0.7) make the belt hang like a heavy, rigid metal belt rather than floppy cloth. Prevents wild swinging with zero jitter.")]
	public float BendingStiffness = 0.6f;

	[Header("Bullet Orientation & Constraints")]
	[Tooltip("Euler rotation offset applied strictly to the flat bullets sitting on the gun's feed tray.")]
	public Vector3 FeedTrayRotationOffset = Vector3.zero;

	[Tooltip("Euler rotation offset applied strictly to the dangled/simulated bullets hanging down.")]
	public Vector3 HangingRotationOffset = Vector3.zero;

	[Tooltip("The name of the child GameObject inside your bullet prefab that represents the metal link (case-insensitive). If found, only the link will bend, while the cartridge stays parallel.")]
	public string LinkChildName = "link";

	[Tooltip("The local direction of the gun's proxy round that the hanging belt should flow out from.")]
	public Vector3 LoadedExitDirection = new Vector3(-1f, 0f, 0f);

	[Tooltip("The local direction the belt exits from when NOT loaded (held in hand). Lies on the local X-Y plane to prevent squashing.")]
	public Vector3 UnloadedExitDirection = new Vector3(0f, -1f, 0f);

	[Header("Snapped Feed Tray Rounds")]
	[Tooltip("How many bullets sit rigidly flat on the gun's top feed tray cover before the belt hangs down dynamically. (Usually 3 to 5 on an M249).")]
	public int SnappedFeedTrayRounds = 4;

	[Header("Loading")]
	[Tooltip("Detection radius around BeltExitPoint for feed tray detection.")]
	public float LoadDetectionRadius = 0.12f;

	[Tooltip("After ejecting or removing the belt, how many seconds to wait before it can be loaded again. Prevents instant re-insertion.")]
	public float ReinsertCooldown = 1f;

	private FVRFireArmMagazine _magazine;

	private Vector3[] _positions;

	private Vector3[] _localPositions;

	private Vector3[] _localPrevPositions;

	private Transform[] _cachedLinkTransforms;

	private bool _chainInitialized = false;

	private bool _wasLoadedLastFrame = false;

	private FVRFireArm _lastLoadedFireArm = null;

	private float _cooldownTimer = 0f;

	private Vector3 _lastAnchorVelocity = Vector3.zero;

	private Vector3 _lastAnchorPos = Vector3.zero;

	private int _scanFrameThrottle = 0;

	private int _interactableLayerMask;

	private void Awake()
	{
		_magazine = ((Component)this).GetComponent<FVRFireArmMagazine>();
		if (EnableDebug)
		{
			Debug.Log((object)"[BeltPhysicsDebug] Awake called on custom belt.");
		}
		_interactableLayerMask = LayerMask.GetMask(new string[2] { "Default", "Interactable" });
		_magazine.HidesAllDisplayBulletsWhenGrabbed = false;
		FVRFireArmReloadTriggerMag[] componentsInChildren = ((Component)this).GetComponentsInChildren<FVRFireArmReloadTriggerMag>();
		FVRFireArmReloadTriggerMag[] array = componentsInChildren;
		foreach (FVRFireArmReloadTriggerMag val in array)
		{
			if ((Object)(object)val != (Object)null)
			{
				((Behaviour)val).enabled = false;
				Collider component = ((Component)val).GetComponent<Collider>();
				if ((Object)(object)component != (Object)null)
				{
					component.enabled = false;
				}
			}
		}
	}

	private void Start()
	{
		InitChain();
		CacheLinkTransforms();
	}

	private void OnEnable()
	{
		if (_chainInitialized)
		{
			InitChain();
			CacheLinkTransforms();
		}
	}

	private void CacheLinkTransforms()
	{
		if (_magazine.DisplayBullets == null || _magazine.DisplayBullets.Length == 0)
		{
			return;
		}
		_cachedLinkTransforms = (Transform[])(object)new Transform[_magazine.DisplayBullets.Length];
		for (int i = 0; i < _magazine.DisplayBullets.Length; i++)
		{
			if ((Object)(object)_magazine.DisplayBullets[i] != (Object)null)
			{
				_cachedLinkTransforms[i] = GetLinkChild(_magazine.DisplayBullets[i].transform);
			}
		}
	}

	private void FixedUpdate()
	{
		if (_cooldownTimer > 0f)
		{
			_cooldownTimer -= Time.fixedDeltaTime;
		}
		else
		{
			_cooldownTimer = 0f;
		}
		if (_cooldownTimer <= 0f)
		{
			_scanFrameThrottle++;
			if (_scanFrameThrottle >= 5)
			{
				_scanFrameThrottle = 0;
				HandleFeedTrayDetection();
			}
		}
		if ((Object)(object)_magazine.FireArm != (Object)null)
		{
			_magazine.FireArm.ConnectedToBox = true;
			_magazine.FireArm.HasBelt = true;
		}
		if (_chainInitialized)
		{
			UpdateChain();
		}
	}

	private void Update()
	{
		if ((Object)(object)_magazine != (Object)null && (Object)(object)_magazine.FireArm != (Object)null)
		{
			_magazine.FireArm.ConnectedToBox = true;
			_magazine.FireArm.HasBelt = true;
		}
	}

	private void HandleFeedTrayDetection()
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: 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_0123: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: 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_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_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0384: Unknown result type (might be due to invalid IL or missing references)
		//IL_0389: Unknown result type (might be due to invalid IL or missing references)
		//IL_031b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0326: Invalid comparison between Unknown and I4
		//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0401: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0447: Unknown result type (might be due to invalid IL or missing references)
		//IL_0448: Unknown result type (might be due to invalid IL or missing references)
		//IL_042f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0434: Unknown result type (might be due to invalid IL or missing references)
		if ((!((FVRInteractiveObject)_magazine).IsHeld && (!((Object)(object)_magazine.BeltGrabTrigger != (Object)null) || !((FVRInteractiveObject)_magazine.BeltGrabTrigger).IsHeld)) || (int)_magazine.State != 0 || (Object)(object)BeltExitPoint == (Object)null)
		{
			return;
		}
		Vector3 val = BeltExitPoint.position;
		if ((Object)(object)_magazine.BeltGrabTrigger != (Object)null && ((FVRInteractiveObject)_magazine.BeltGrabTrigger).IsHeld)
		{
			val = ((Component)_magazine.BeltGrabTrigger).transform.position;
		}
		else if (_chainInitialized && _positions != null && _positions.Length > 0)
		{
			int numRounds = _magazine.m_numRounds;
			int num = Mathf.Clamp(numRounds, 1, ChainNodeCount);
			val = _positions[num - 1];
		}
		float num2 = 0.25f;
		Collider[] array = Physics.OverlapSphere(val, num2, _interactableLayerMask, (QueryTriggerInteraction)2);
		Collider[] array2 = array;
		foreach (Collider val2 in array2)
		{
			FVRFireArm componentInParent = ((Component)val2).GetComponentInParent<FVRFireArm>();
			if ((Object)(object)componentInParent == (Object)null || !componentInParent.UsesBelts || (Object)(object)componentInParent.BeltDD == (Object)null || (Object)(object)componentInParent.Magazine != (Object)null)
			{
				continue;
			}
			bool flag = !componentInParent.UsesTopCover || componentInParent.IsTopCoverUp;
			if (componentInParent.UsesTopCover && !flag)
			{
				FVRFireArmTopCover componentInChildren = ((Component)componentInParent).GetComponentInChildren<FVRFireArmTopCover>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					float num3 = ((Component)componentInChildren).transform.localEulerAngles.x;
					if (num3 > 180f)
					{
						num3 -= 360f;
					}
					if (Mathf.Abs(num3) > 15f || ((FVRInteractiveObject)componentInChildren).IsHeld)
					{
						flag = true;
					}
				}
				else
				{
					flag = true;
				}
			}
			if (!flag)
			{
				continue;
			}
			FireArmMagazineType val3 = componentInParent.MagazineType;
			FVRFireArmReloadTriggerWell[] componentsInChildren = ((Component)componentInParent).GetComponentsInChildren<FVRFireArmReloadTriggerWell>(true);
			FVRFireArmReloadTriggerWell[] array3 = componentsInChildren;
			foreach (FVRFireArmReloadTriggerWell val4 in array3)
			{
				if ((Object)(object)val4 != (Object)null && ((_magazine.IsBeltBox && val4.IsBeltBox) || (val4.UsesTypeOverride && val4.TypeOverride == _magazine.MagazineType)))
				{
					val3 = val4.TypeOverride;
					break;
				}
			}
			bool flag2 = BypassTypeMatching || val3 == _magazine.MagazineType;
			if (!flag2 && CompatibleMagazineTypes != null)
			{
				for (int k = 0; k < CompatibleMagazineTypes.Length; k++)
				{
					if ((int)val3 == (int)CompatibleMagazineTypes[k])
					{
						flag2 = true;
						break;
					}
				}
			}
			if (!flag2 || (componentInParent.EjectDelay > 0f && (Object)(object)_magazine == (Object)(object)componentInParent.LastEjectedMag))
			{
				continue;
			}
			Vector3 val5 = Vector3.zero;
			bool flag3 = false;
			List<Transform> proxyRounds = componentInParent.BeltDD.ProxyRounds;
			if (proxyRounds != null && proxyRounds.Count > 0 && (Object)(object)proxyRounds[0] != (Object)null)
			{
				val5 = proxyRounds[0].position;
				flag3 = true;
			}
			else
			{
				FVRFireArmBeltRemovalTrigger componentInChildren2 = ((Component)componentInParent).GetComponentInChildren<FVRFireArmBeltRemovalTrigger>(true);
				if ((Object)(object)componentInChildren2 != (Object)null)
				{
					val5 = ((Component)componentInChildren2).transform.position;
					flag3 = true;
				}
			}
			if (!flag3)
			{
				FVRFireArmTopCover componentInChildren3 = ((Component)componentInParent).GetComponentInChildren<FVRFireArmTopCover>(true);
				if ((Object)(object)componentInChildren3 != (Object)null)
				{
					val5 = ((Component)componentInChildren3).transform.position;
					flag3 = true;
				}
			}
			if (!flag3)
			{
				continue;
			}
			float num4 = Vector3.Distance(val, val5);
			if (num4 <= LoadDetectionRadius)
			{
				if (EnableDebug)
				{
					Debug.Log((object)("[BeltPhysicsDebug] Loading belt directly into feed tray trigger of " + ((Object)componentInParent).name + "!"));
				}
				_magazine.Load(componentInParent);
				break;
			}
		}
	}

	private void LateUpdate()
	{
		//IL_0315: Unknown result type (might be due to invalid IL or missing references)
		//IL_0335: Unknown result type (might be due to invalid IL or missing references)
		if (!_chainInitialized)
		{
			return;
		}
		bool flag = (Object)(object)_magazine.FireArm != (Object)null;
		int num = _magazine.m_numRounds;
		if (flag && (Object)(object)_magazine.FireArm.BeltDD != (Object)null)
		{
			num += _magazine.FireArm.BeltDD.m_roundsOnBelt;
		}
		if (flag && num == 0)
		{
			FVRFireArm fireArm = _magazine.FireArm;
			SetGunProxyRenderersEnabled(enabled: true, fireArm);
			if ((Object)(object)fireArm.BeltDD != (Object)null)
			{
				fireArm.ConnectedToBox = false;
				fireArm.HasBelt = false;
				fireArm.BeltDD.PullPushBelt((FVRFireArmMagazine)null, 0);
			}
			fireArm.EjectMag(true);
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		if (flag && !_wasLoadedLastFrame)
		{
			FVRFireArm fireArm2 = _magazine.FireArm;
			if ((Object)(object)fireArm2.BeltDD != (Object)null)
			{
				fireArm2.ConnectedToBox = true;
				fireArm2.HasBelt = true;
				fireArm2.BeltDD.PullPushBelt(_magazine, fireArm2.BeltDD.BeltCapacity);
			}
			SetGunProxyRenderersEnabled(enabled: false, fireArm2);
			((FVRInteractiveObject)_magazine).SetAllCollidersToLayer(false, "NoCol");
			_lastLoadedFireArm = fireArm2;
			_wasLoadedLastFrame = true;
		}
		else if (!flag && _wasLoadedLastFrame)
		{
			if ((Object)(object)_lastLoadedFireArm != (Object)null && (Object)(object)_lastLoadedFireArm.BeltDD != (Object)null)
			{
				_lastLoadedFireArm.BeltDD.PullPushBelt(_magazine, 0);
				_lastLoadedFireArm.ConnectedToBox = false;
				_lastLoadedFireArm.HasBelt = false;
				_lastLoadedFireArm.BeltDD.PullPushBelt((FVRFireArmMagazine)null, 0);
			}
			_lastLoadedFireArm = null;
			((FVRInteractiveObject)_magazine).SetAllCollidersToLayer(false, "Default");
			_wasLoadedLastFrame = false;
		}
		if (flag && (Object)(object)_magazine.BeltGrabTrigger != (Object)null && ((FVRInteractiveObject)_magazine.BeltGrabTrigger).IsHeld)
		{
			FVRViveHand hand = ((FVRInteractiveObject)_magazine.BeltGrabTrigger).m_hand;
			if ((Object)(object)hand != (Object)null)
			{
				FVRFireArm fireArm3 = _magazine.FireArm;
				if ((Object)(object)fireArm3.BeltDD != (Object)null)
				{
					fireArm3.BeltDD.PullPushBelt(_magazine, 0);
				}
				fireArm3.EjectMag(false);
				((FVRInteractiveObject)_magazine.BeltGrabTrigger).ForceBreakInteraction();
				hand.ForceSetInteractable((FVRInteractiveObject)(object)_magazine);
				((FVRInteractiveObject)_magazine).BeginInteraction(hand);
				flag = false;
			}
		}
		if (flag && (Object)(object)_magazine.FireArm != (Object)null)
		{
			_magazine.FireArm.ConnectedToBox = true;
			_magazine.FireArm.HasBelt = true;
		}
		if (flag)
		{
			Transform anchorTransform = GetAnchorTransform();
			if ((Object)(object)anchorTransform != (Object)null)
			{
				((Component)this).transform.position = anchorTransform.position;
				((Component)this).transform.rotation = ((Component)_magazine.FireArm).transform.rotation;
			}
		}
		PositionBullets();
	}

	private void InitChain()
	{
		//IL_0058: 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_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: 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_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: 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_0137: 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_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		_positions = (Vector3[])(object)new Vector3[ChainNodeCount];
		_localPositions = (Vector3[])(object)new Vector3[ChainNodeCount];
		_localPrevPositions = (Vector3[])(object)new Vector3[ChainNodeCount];
		Transform anchorTransform = GetAnchorTransform();
		Vector3 val = ((!((Object)(object)anchorTransform != (Object)null)) ? ((Component)this).transform.position : anchorTransform.position);
		Vector3 val2 = ((!((Object)(object)_magazine.FireArm != (Object)null)) ? ((Vector3)(ref UnloadedExitDirection)).normalized : ((Vector3)(ref LoadedExitDirection)).normalized);
		for (int i = 0; i < ChainNodeCount; i++)
		{
			ref Vector3 reference = ref _localPositions[i];
			reference = val2 * (NodeDistance * (float)i);
			ref Vector3 reference2 = ref _localPrevPositions[i];
			reference2 = _localPositions[i];
			if ((Object)(object)anchorTransform != (Object)null)
			{
				ref Vector3 reference3 = ref _positions[i];
				reference3 = anchorTransform.TransformPoint(_localPositions[i]);
			}
			else
			{
				ref Vector3 reference4 = ref _positions[i];
				reference4 = val + val2 * (NodeDistance * (float)i);
			}
		}
		_lastAnchorPos = val;
		_lastAnchorVelocity = Vector3.zero;
		_chainInitialized = true;
	}

	private void UpdateChain()
	{
		//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_005e: 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_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0287: Unknown result type (might be due to invalid IL or missing references)
		//IL_028c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: 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_02ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c2: 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_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02df: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_031e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: Unknown result type (might be due to invalid IL or missing references)
		//IL_0347: Unknown result type (might be due to invalid IL or missing references)
		//IL_038d: Unknown result type (might be due to invalid IL or missing references)
		//IL_039f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0400: Unknown result type (might be due to invalid IL or missing references)
		//IL_0405: Unknown result type (might be due to invalid IL or missing references)
		//IL_0438: Unknown result type (might be due to invalid IL or missing references)
		//IL_0443: Unknown result type (might be due to invalid IL or missing references)
		//IL_0448: Unknown result type (might be due to invalid IL or missing references)
		//IL_079a: Unknown result type (might be due to invalid IL or missing references)
		//IL_079f: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0722: Unknown result type (might be due to invalid IL or missing references)
		//IL_072d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0732: Unknown result type (might be due to invalid IL or missing references)
		//IL_074e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0753: Unknown result type (might be due to invalid IL or missing references)
		//IL_075b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0760: Unknown result type (might be due to invalid IL or missing references)
		//IL_0484: Unknown result type (might be due to invalid IL or missing references)
		//IL_0496: Unknown result type (might be due to invalid IL or missing references)
		//IL_049b: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_050f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0514: Unknown result type (might be due to invalid IL or missing references)
		//IL_0518: Unknown result type (might be due to invalid IL or missing references)
		//IL_0522: Unknown result type (might be due to invalid IL or missing references)
		//IL_0527: Unknown result type (might be due to invalid IL or missing references)
		//IL_052c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0541: Unknown result type (might be due to invalid IL or missing references)
		//IL_0546: Unknown result type (might be due to invalid IL or missing references)
		//IL_054a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0554: Unknown result type (might be due to invalid IL or missing references)
		//IL_0559: Unknown result type (might be due to invalid IL or missing references)
		//IL_055e: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_05cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_05eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_066f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0674: Unknown result type (might be due to invalid IL or missing references)
		//IL_0678: Unknown result type (might be due to invalid IL or missing references)
		//IL_0683: Unknown result type (might be due to invalid IL or missing references)
		//IL_068d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0692: Unknown result type (might be due to invalid IL or missing references)
		//IL_0697: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_06cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0638: Unknown result type (might be due to invalid IL or missing references)
		//IL_063d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0641: Unknown result type (might be due to invalid IL or missing references)
		//IL_064c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0651: Unknown result type (might be due to invalid IL or missing references)
		//IL_0656: Unknown result type (might be due to invalid IL or missing references)
		Transform anchorTransform = GetAnchorTransform();
		if ((Object)(object)anchorTransform == (Object)null)
		{
			return;
		}
		bool flag = (Object)(object)((FVRPhysicalObject)_magazine).QuickbeltSlot != (Object)null;
		Vector3 position = anchorTransform.position;
		Vector3 val = ((!((Object)(object)_magazine.FireArm != (Object)null)) ? ((Vector3)(ref UnloadedExitDirection)).normalized : ((Vector3)(ref LoadedExitDirection)).normalized);
		bool flag2 = (Object)(object)_magazine.FireArm != (Object)null;
		List<Transform> list = ((!flag2 || !((Object)(object)_magazine.FireArm.BeltDD != (Object)null)) ? null : _magazine.FireArm.BeltDD.ProxyRounds);
		int num = 0;
		if (flag2 && list != null)
		{
			num = Mathf.Min(new int[3]
			{
				SnappedFeedTrayRounds,
				_magazine.FireArm.BeltDD.m_roundsOnBelt,
				list.Count
			});
		}
		int num2 = _magazine.m_numRounds;
		if (flag2 && (Object)(object)_magazine.FireArm.BeltDD != (Object)null)
		{
			num2 += _magazine.FireArm.BeltDD.m_roundsOnBelt;
		}
		int num3 = num2 - num;
		int num4 = Mathf.Clamp(num3, 1, ChainNodeCount);
		int num5 = Mathf.Clamp(PinnedNodes, 1, num4);
		if (flag)
		{
			for (int i = 0; i < num4; i++)
			{
				ref Vector3 reference = ref _localPositions[i];
				reference = val * (NodeDistance * (float)i);
				ref Vector3 reference2 = ref _localPrevPositions[i];
				reference2 = _localPositions[i];
				ref Vector3 reference3 = ref _positions[i];
				reference3 = anchorTransform.TransformPoint(_localPositions[i]);
			}
			return;
		}
		float fixedDeltaTime = Time.fixedDeltaTime;
		Vector3 zero = Vector3.zero;
		zero = (((Object)(object)_magazine.FireArm != (Object)null && (Object)(object)((FVRPhysicalObject)_magazine.FireArm).RootRigidbody != (Object)null) ? ((FVRPhysicalObject)_magazine.FireArm).RootRigidbody.velocity : ((!((Object)(object)((FVRPhysicalObject)_magazine).RootRigidbody != (Object)null)) ? ((position - _lastAnchorPos) / fixedDeltaTime) : ((FVRPhysicalObject)_magazine).RootRigidbody.velocity));
		Vector3 val2 = (zero - _lastAnchorVelocity) / fixedDeltaTime;
		_lastAnchorVelocity = zero;
		_lastAnchorPos = position;
		val2 = Vector3.ClampMagnitude(val2, 50f);
		Vector3 val3 = anchorTransform.InverseTransformDirection(Physics.gravity * GravityScale - val2);
		for (int j = 0; j < num5; j++)
		{
			ref Vector3 reference4 = ref _localPositions[j];
			reference4 = val * (NodeDistance * (float)j);
			ref Vector3 reference5 = ref _localPrevPositions[j];
			reference5 = _localPositions[j];
		}
		float num6 = ((!flag2) ? Damping : LoadedDamping);
		for (int k = num5; k < num4; k++)
		{
			Vector3 val4 = (_localPositions[k] - _localPrevPositions[k]) * num6;
			ref Vector3 reference6 = ref _localPrevPositions[k];
			reference6 = _localPositions[k];
			ref Vector3 reference7 = ref _localPositions[k];
			reference7 += val4 + val3 * fixedDeltaTime * fixedDeltaTime;
		}
		for (int l = 0; l < ConstraintIterations; l++)
		{
			for (int m = 0; m < num5; m++)
			{
				ref Vector3 reference8 = ref _localPositions[m];
				reference8 = val * (NodeDistance * (float)m);
			}
			for (int n = 0; n < num4 - 1; n++)
			{
				if (n + 1 < num5)
				{
					continue;
				}
				Vector3 val5 = _localPositions[n + 1] - _localPositions[n];
				float magnitude = ((Vector3)(ref val5)).magnitude;
				if (!(magnitude < 0.0001f))
				{
					float num7 = (magnitude - NodeDistance) / magnitude;
					if (n < num5)
					{
						ref Vector3 reference9 = ref _localPositions[n + 1];
						reference9 -= val5 * num7;
						continue;
					}
					ref Vector3 reference10 = ref _localPositions[n];
					reference10 += val5 * num7 * 0.5f;
					ref Vector3 reference11 = ref _localPositions[n + 1];
					reference11 -= val5 * num7 * 0.5f;
				}
			}
			for (int num8 = num5; num8 < num4; num8++)
			{
				_localPositions[num8].z = 0f;
			}
			for (int num9 = 0; num9 < num4 - 2; num9++)
			{
				if (num9 + 2 < num5)
				{
					continue;
				}
				Vector3 val6 = _localPositions[num9 + 2] - _localPositions[num9];
				float magnitude2 = ((Vector3)(ref val6)).magnitude;
				float num10 = NodeDistance * 2f;
				if (!(magnitude2 < 0.0001f))
				{
					float num11 = (magnitude2 - num10) / magnitude2;
					if (num9 < num5)
					{
						ref Vector3 reference12 = ref _localPositions[num9 + 2];
						reference12 -= val6 * num11 * BendingStiffness;
						continue;
					}
					ref Vector3 reference13 = ref _localPositions[num9];
					reference13 += val6 * num11 * BendingStiffness * 0.5f;
					ref Vector3 reference14 = ref _localPositions[num9 + 2];
					reference14 -= val6 * num11 * BendingStiffness * 0.5f;
				}
			}
		}
		if (flag2 && LoadedRigidity > 0f)
		{
			for (int num12 = num5; num12 < num4; num12++)
			{
				Vector3 val7 = val * (NodeDistance * (float)num12);
				ref Vector3 reference15 = ref _localPositions[num12];
				reference15 = Vector3.Lerp(_localPositions[num12], val7, LoadedRigidity);
			}
		}
		for (int num13 = 0; num13 < num4; num13++)
		{
			ref Vector3 reference16 = ref _positions[num13];
			reference16 = anchorTransform.TransformPoint(_localPositions[num13]);
		}
	}

	private void PositionBullets()
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: 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_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_035a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0374: Unknown result type (might be due to invalid IL or missing references)
		//IL_0379: Unknown result type (might be due to invalid IL or missing references)
		//IL_037e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0382: Unknown result type (might be due to invalid IL or missing references)
		//IL_0387: Unknown result type (might be due to invalid IL or missing references)
		//IL_031f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0331: Unknown result type (might be due to invalid IL or missing references)
		//IL_0336: Unknown result type (might be due to invalid IL or missing references)
		//IL_033b: Unknown result type (might be due to invalid IL or missing references)
		//IL_033f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: 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_0285: Unknown result type (might be due to invalid IL or missing references)
		//IL_041c: Unknown result type (might be due to invalid IL or missing references)
		//IL_041e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_042e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0430: Unknown result type (might be due to invalid IL or missing references)
		//IL_0435: Unknown result type (might be due to invalid IL or missing references)
		//IL_043a: Unknown result type (might be due to invalid IL or missing references)
		//IL_043c: Unknown result type (might be due to invalid IL or missing references)
		//IL_043e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0440: Unknown result type (might be due to invalid IL or missing references)
		//IL_0445: Unknown result type (might be due to invalid IL or missing references)
		//IL_044a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0472: Unknown result type (might be due to invalid IL or missing references)
		//IL_0477: Unknown result type (might be due to invalid IL or missing references)
		//IL_0484: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03de: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_040a: Unknown result type (might be due to invalid IL or missing references)
		if (_magazine.DisplayBullets == null || _magazine.DisplayBullets.Length == 0)
		{
			return;
		}
		Quaternion val = Quaternion.Euler(FeedTrayRotationOffset);
		Quaternion val2 = Quaternion.Euler(HangingRotationOffset);
		Transform anchorTransform = GetAnchorTransform();
		if ((Object)(object)anchorTransform == (Object)null)
		{
			return;
		}
		bool flag = (Object)(object)_magazine.FireArm != (Object)null;
		Vector3 val3 = ((!flag) ? ((Vector3)(ref UnloadedExitDirection)).normalized : ((Vector3)(ref LoadedExitDirection)).normalized);
		List<Transform> list = ((!flag || !((Object)(object)_magazine.FireArm.BeltDD != (Object)null)) ? null : _magazine.FireArm.BeltDD.ProxyRounds);
		int num = 0;
		if (flag && list != null)
		{
			num = Mathf.Min(new int[3]
			{
				SnappedFeedTrayRounds,
				_magazine.FireArm.BeltDD.m_roundsOnBelt,
				list.Count
			});
		}
		int num2 = _magazine.m_numRounds;
		if (flag && (Object)(object)_magazine.FireArm.BeltDD != (Object)null)
		{
			num2 += _magazine.FireArm.BeltDD.m_roundsOnBelt;
		}
		int num3 = num2 - num;
		int num4 = Mathf.Clamp(num3, 1, ChainNodeCount);
		int num5 = 0;
		Quaternion val4 = ((Component)_magazine).transform.rotation * val2;
		Quaternion rotation = ((!flag) ? (anchorTransform.rotation * val) : (((Component)_magazine.FireArm).transform.rotation * val));
		for (int i = 0; i < _magazine.DisplayBullets.Length; i++)
		{
			if ((Object)(object)_magazine.DisplayBullets[i] == (Object)null)
			{
				continue;
			}
			bool flag2 = num5 < num2;
			_magazine.DisplayBullets[i].SetActive(flag2);
			if (!flag2)
			{
				continue;
			}
			if (num5 < num && list != null && num5 < list.Count && (Object)(object)list[num5] != (Object)null)
			{
				Transform val5 = list[num5];
				_magazine.DisplayBullets[i].transform.position = val5.position;
				_magazine.DisplayBullets[i].transform.rotation = rotation;
				Transform val6 = _cachedLinkTransforms[i];
				if ((Object)(object)val6 != (Object)null)
				{
					val6.localRotation = Quaternion.identity;
				}
			}
			else
			{
				int num6 = num5 - num;
				if (num6 >= num4)
				{
					num6 = num4 - 1;
				}
				_magazine.DisplayBullets[i].transform.position = _positions[num6];
				Transform val7 = _cachedLinkTransforms[i];
				Vector3 normalized;
				if (num6 < num4 - 1)
				{
					Vector3 val8 = _positions[num6 + 1] - _positions[num6];
					normalized = ((Vector3)(ref val8)).normalized;
				}
				else
				{
					Vector3 val9 = _positions[num6] - _positions[Mathf.Max(num6 - 1, 0)];
					normalized = ((Vector3)(ref val9)).normalized;
				}
				if ((Object)(object)val7 != (Object)null)
				{
					_magazine.DisplayBullets[i].transform.rotation = val4;
					if (normalized != Vector3.zero)
					{
						Vector3 val10 = _magazine.DisplayBullets[i].transform.InverseTransformDirection(normalized);
						Vector3 normalized2 = ((Vector3)(ref val10)).normalized;
						Quaternion val11 = Quaternion.FromToRotation(val3, normalized2);
						val7.localRotation = Quaternion.Slerp(val7.localRotation, val11, Time.deltaTime * 20f);
					}
				}
				else if (normalized != Vector3.zero)
				{
					Vector3 val12 = val4 * Vector3.forward;
					Quaternion val13 = Quaternion.LookRotation(val12, -normalized);
					_magazine.DisplayBullets[i].transform.rotation = Quaternion.Slerp(_magazine.DisplayBullets[i].transform.rotation, val13, Time.deltaTime * 20f);
				}
			}
			num5++;
		}
	}

	private Transform GetAnchorTransform()
	{
		if ((Object)(object)_magazine.FireArm != (Object)null && (Object)(object)_magazine.FireArm.BeltDD != (Object)null && _magazine.FireArm.BeltDD.ProxyRounds != null)
		{
			List<Transform> proxyRounds = _magazine.FireArm.BeltDD.ProxyRounds;
			int num = Mathf.Clamp(SnappedFeedTrayRounds - 1, 0, proxyRounds.Count - 1);
			if (num >= 0 && num < proxyRounds.Count && (Object)(object)proxyRounds[num] != (Object)null)
			{
				return proxyRounds[num];
			}
		}
		return BeltExitPoint;
	}

	private void SetGunProxyRenderersEnabled(bool enabled, FVRFireArm gunContext)
	{
		if ((Object)(object)gunContext == (Object)null || (Object)(object)gunContext.BeltDD == (Object)null || gunContext.BeltDD.ProxyRounds == null)
		{
			return;
		}
		List<Transform> proxyRounds = gunContext.BeltDD.ProxyRounds;
		for (int i = 0; i < proxyRounds.Count; i++)
		{
			if (!((Object)(object)proxyRounds[i] != (Object)null))
			{
				continue;
			}
			Renderer[] componentsInChildren = ((Component)proxyRounds[i]).GetComponentsInChildren<Renderer>();
			for (int j = 0; j < componentsInChildren.Length; j++)
			{
				if ((Object)(object)componentsInChildren[j] != (Object)null)
				{
					componentsInChildren[j].enabled = enabled;
				}
			}
		}
	}

	private Transform GetLinkChild(Transform bulletParent)
	{
		if ((Object)(object)bulletParent == (Object)null || string.IsNullOrEmpty(LinkChildName))
		{
			return null;
		}
		for (int i = 0; i < bulletParent.childCount; i++)
		{
			Transform child = bulletParent.GetChild(i);
			if ((Object)(object)child != (Object)null && ((Object)child).name.ToLower().Contains(LinkChildName.ToLower()))
			{
				return child;
			}
		}
		return null;
	}

	[ContextMenu("Reset Chain")]
	public void ResetChain()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: 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_004d: 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_0061: 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)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)BeltExitPoint == (Object)null) && _positions != null)
		{
			Vector3 forward = BeltExitPoint.forward;
			for (int i = 0; i < ChainNodeCount; i++)
			{
				ref Vector3 reference = ref _positions[i];
				reference = BeltExitPoint.position + forward * (NodeDistance * (float)i);
				ref Vector3 reference2 = ref _localPositions[i];
				reference2 = forward * (NodeDistance * (float)i);
				ref Vector3 reference3 = ref _localPrevPositions[i];
				reference3 = _localPositions[i];
			}
		}
	}

	private void OnDrawGizmos()
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: 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_0060: 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_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: 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_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: 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)
		if (!((Object)(object)BeltExitPoint == (Object)null))
		{
			Vector3 position = BeltExitPoint.position;
			Vector3 forward = BeltExitPoint.forward;
			bool flag = _chainInitialized && Application.isPlaying;
			int num = Mathf.Clamp(PinnedNodes, 1, ChainNodeCount);
			Gizmos.color = Color.green;
			Gizmos.DrawSphere(position, 0.01f);
			Gizmos.color = new Color(0f, 1f, 0f, 0.15f);
			Gizmos.DrawSphere(position, LoadDetectionRadius);
			Vector3 val = position;
			for (int i = 1; i < ChainNodeCount; i++)
			{
				Vector3 val2 = ((!flag) ? (position + forward * (NodeDistance * (float)i)) : _positions[i]);
				Gizmos.color = ((i >= num) ? Color.yellow : Color.green);
				Gizmos.DrawLine(val, val2);
				Gizmos.color = ((i >= num) ? Color.cyan : Color.green);
				Gizmos.DrawSphere(val2, 0.005f);
				val = val2;
			}
			Gizmos.color = Color.red;
			Gizmos.DrawSphere(val, 0.008f);
		}
	}
}
public class MagazineLoadToggle : MonoBehaviour
{
	[Header("Target")]
	public GameObject TargetObject;

	[Header("Specific Trigger Well")]
	public FVRFireArmReloadTriggerWell ReloadTriggerWell;

	private bool _lastMagLoaded;

	private void Update()
	{
		if (!((Object)(object)ReloadTriggerWell == (Object)null) && !((Object)(object)TargetObject == (Object)null))
		{
			bool flag = (Object)(object)ReloadTriggerWell.FireArm != (Object)null && (Object)(object)ReloadTriggerWell.FireArm.Magazine != (Object)null;
			if (flag != _lastMagLoaded)
			{
				TargetObject.SetActive(!flag);
				_lastMagLoaded = flag;
			}
		}
	}
}
public class PartRecoilImpulse : MonoBehaviour
{
	public enum ImpulseMode
	{
		Rotation,
		Translation
	}

	public enum ImpulseAxis
	{
		X,
		Y,
		Z
	}

	[Serializable]
	public class RecoilPart
	{
		public Transform Piece;

		public ImpulseMode Mode = ImpulseMode.Rotation;

		public ImpulseAxis Axis = ImpulseAxis.X;

		public Vector2 Range = new Vector2(0f, 45f);

		public float ReturnSpeed = 5f;

		public float ImpulseStrength = 1f;

		[NonSerialized]
		public float CurrentLerp = 0f;
	}

	[Header("Parts")]
	public List<RecoilPart> Parts = new List<RecoilPart>();

	private FVRFireArm m_firearm;

	private void Awake()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		GM.CurrentSceneSettings.ShotFiredEvent += new ShotFired(OnShotFired);
	}

	private void OnDestroy()
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		if ((Object)(object)GM.CurrentSceneSettings != (Object)null)
		{
			GM.CurrentSceneSettings.ShotFiredEvent -= new ShotFired(OnShotFired);
		}
	}

	private void Start()
	{
		m_firearm = ((Component)this).GetComponentInParent<FVRFireArm>();
		if ((Object)(object)m_firearm == (Object)null)
		{
			Debug.LogWarning((object)"[PartRecoilImpulse] No FVRFireArm found in parent hierarchy.", (Object)(object)this);
		}
		for (int i = 0; i < Parts.Count; i++)
		{
			ApplyToPart(Parts[i]);
		}
	}

	private void OnShotFired(FVRFireArm firearm)
	{
		if (!((Object)(object)firearm != (Object)(object)m_firearm))
		{
			for (int i = 0; i < Parts.Count; i++)
			{
				Parts[i].CurrentLerp = Mathf.Clamp01(Parts[i].ImpulseStrength);
				ApplyToPart(Parts[i]);
			}
		}
	}

	private void Update()
	{
		for (int i = 0; i < Parts.Count; i++)
		{
			RecoilPart recoilPart = Parts[i];
			if (recoilPart.CurrentLerp > 0f)
			{
				recoilPart.CurrentLerp = Mathf.MoveTowards(recoilPart.CurrentLerp, 0f, Time.deltaTime * recoilPart.ReturnSpeed);
				ApplyToPart(recoilPart);
			}
		}
	}

	private void ApplyToPart(RecoilPart part)
	{
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: 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_00e8: 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)part.Piece == (Object)null)
		{
			return;
		}
		float num = Mathf.Lerp(part.Range.x, part.Range.y, part.CurrentLerp);
		if (part.Mode == ImpulseMode.Rotation)
		{
			Vector3 localEulerAngles = part.Piece.localEulerAngles;
			if (part.Axis == ImpulseAxis.X)
			{
				localEulerAngles.x = num;
			}
			else if (part.Axis == ImpulseAxis.Y)
			{
				localEulerAngles.y = num;
			}
			else
			{
				localEulerAngles.z = num;
			}
			part.Piece.localEulerAngles = localEulerAngles;
		}
		else
		{
			Vector3 localPosition = part.Piece.localPosition;
			if (part.Axis == ImpulseAxis.X)
			{
				localPosition.x = num;
			}
			else if (part.Axis == ImpulseAxis.Y)
			{
				localPosition.y = num;
			}
			else
			{
				localPosition.z = num;
			}
			part.Piece.localPosition = localPosition;
		}
	}
}
[RequireComponent(typeof(ModularWeaponPart))]
public class BayonetAddon : MonoBehaviour, IPartFireArmRequirement
{
	[Header("Bayonet Config")]
	public MeleeParams MeleeParams;

	private MeleeParams _origMeleeParams;

	private FVRFireArm _firearm;

	public FVRFireArm FireArm
	{
		get
		{
			return _firearm;
		}
		set
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			if ((Object)(object)value != (Object)null)
			{
				_firearm = value;
				_origMeleeParams = new MeleeParams();
				CopyMeleeParams(((FVRPhysicalObject)_firearm).MP, _origMeleeParams);
				CopyMeleeParams(MeleeParams, ((FVRPhysicalObject)_firearm).MP);
			}
			else if ((Object)(object)value == (Object)null && (Object)(object)_firearm != (Object)null)
			{
				if (_origMeleeParams != null)
				{
					CopyMeleeParams(_origMeleeParams, ((FVRPhysicalObject)_firearm).MP);
				}
				_firearm = null;
			}
		}
	}

	private void CopyMeleeParams(MeleeParams source, MeleeParams destination)
	{
		if (source == null || destination == null)
		{
			return;
		}
		Type typeFromHandle = typeof(MeleeParams);
		FieldInfo[] fields = typeFromHandle.GetFields(BindingFlags.Instance | BindingFlags.Public);
		FieldInfo[] array = fields;
		foreach (FieldInfo fieldInfo in array)
		{
			if ((object)fieldInfo.FieldType == typeof(FVRPhysicalObject) || (object)fieldInfo.FieldType == typeof(FVRInteractiveObject) || fieldInfo.Name == "HandPoint")
			{
				continue;
			}
			if ((object)fieldInfo.FieldType == typeof(List<Transform>))
			{
				try
				{
					List<Transform> list = (List<Transform>)fieldInfo.GetValue(source);
					if (list != null)
					{
						List<Transform> value = new List<Transform>(list);
						fieldInfo.SetValue(destination, value);
					}
				}
				catch (Exception ex)
				{
					Debug.LogError((object)("[BayonetAddon] Failed to clone list field " + fieldInfo.Name + ": " + ex.Message));
				}
				continue;
			}
			try
			{
				object value2 = fieldInfo.GetValue(source);
				if (value2 != null)
				{
					fieldInfo.SetValue(destination, value2);
				}
			}
			catch (Exception ex2)
			{
				Debug.LogError((object)("[BayonetAddon] Failed to copy field " + fieldInfo.Name + ": " + ex2.Message));
			}
		}
		PropertyInfo[] properties = typeFromHandle.GetProperties(BindingFlags.Instance | BindingFlags.Public);
		PropertyInfo[] array2 = properties;
		foreach (PropertyInfo propertyInfo in array2)
		{
			if (!propertyInfo.CanRead || !propertyInfo.CanWrite || (object)propertyInfo.PropertyType == typeof(FVRPhysicalObject) || (object)propertyInfo.PropertyType == typeof(FVRInteractiveObject) || propertyInfo.Name == "HandPoint")
			{
				continue;
			}
			if ((object)propertyInfo.PropertyType == typeof(List<Transform>))
			{
				try
				{
					List<Transform> list2 = (List<Transform>)propertyInfo.GetValue(source, null);
					if (list2 != null)
					{
						List<Transform> value3 = new List<Transform>(list2);
						propertyInfo.SetValue(destination, value3, null);
					}
				}
				catch (Exception ex3)
				{
					Debug.LogError((object)("[BayonetAddon] Failed to clone list property " + propertyInfo.Name + ": " + ex3.Message));
				}
				continue;
			}
			try
			{
				object value4 = propertyInfo.GetValue(source, null);
				if (value4 != null)
				{
					propertyInfo.SetValue(destination, value4, null);
				}
			}
			catch (Exception ex4)
			{
				Debug.LogError((object)("[BayonetAddon] Failed to copy property " + propertyInfo.Name + ": " + ex4.Message));
			}
		}
	}
}
[DefaultExecutionOrder(-200)]
[RequireComponent(typeof(ModularWeaponPart))]
public class FirearmMagazineAddons : MonoBehaviour, IPartFireArmRequirement
{
	[Header("Debug Settings")]
	[Tooltip("Enable detailed console logs to track component auto-detection and linking.")]
	public bool EnableDebugLogging = true;

	[Header("Detachable Magazine Settings")]
	[Tooltip("Does this part alter the firearm's detachable magazine parameters?")]
	public bool OverridesExternalMagazines = false;

	[Tooltip("The detachable magazine type accepted by this well.")]
	public FireArmMagazineType MagazineTypeOverride;

	[Tooltip("Local transform where the detachable magazine mounts on this part.")]
	public Transform MagazineMountPos;

	[Tooltip("Local transform where the detachable magazine ejects on this part.")]
	public Transform MagazineEjectPos;

	[Tooltip("Optional: The FVRFireArmReloadTriggerWell component on this part prefab.")]
	public FVRFireArmReloadTriggerWell MagazineWellTrigger;

	[Tooltip("Optional: The UniversalMagGrabTrigger component on this part prefab.")]
	public UniversalMagGrabTrigger MagGrabTrigger;

	[Tooltip("Optional: The UniversalAdvancedMagazineGrabTrigger component on this part prefab.")]
	public UniversalAdvancedMagazineGrabTrigger AdvancedMagGrabTrigger;

	[Tooltip("Optional: Manual AudioEvent to play when a magazine is inserted.")]
	public AudioEvent CustomMagazineInAudio;

	[Tooltip("Optional: Manual AudioEvent to play when a magazine is ejected.")]
	public AudioEvent CustomMagazineOutAudio;

	[Header("Integrated/Internal Magazine Settings")]
	[Tooltip("Does this part feature a built-in internal magazine (like a tube or fixed box)?")]
	public bool EnablesInternalMagazine = false;

	[Tooltip("The FVRFireArmMagazine component representing the internal feed system on this part.")]
	public FVRFireArmMagazine InternalMagazine;

	[Tooltip("Does this part override the base firearm's physical magazine release button behavior?")]
	public bool OverridesMagReleaseButton = false;

	[Tooltip("Should the physical magazine release button on the base receiver be enabled (true) or disabled (false)?")]
	public bool NewMagReleaseButtonState = true;

	[Header("Stripper Clip Settings")]
	[Tooltip("Does this part alter the firearm's stripper clip parameters?")]
	public bool OverridesStripperClips = false;

	[Tooltip("The stripper clip type accepted by this clip guide.")]
	public FireArmClipType ClipTypeOverride;

	[Tooltip("Local transform where the clip mounts on this part.")]
	public Transform ClipMountPos;

	[Tooltip("Local transform where the clip ejects on this part.")]
	public Transform ClipEjectPos;

	[Tooltip("Optional: The FVRFireArmClipTriggerWell component on this part prefab.")]
	public FVRFireArmClipTriggerWell ClipWellTrigger;

	[Tooltip("Optional: The clip trigger GameObject on this part.")]
	public GameObject ClipTrigger;

	[Header("Top Cover Settings")]
	[Tooltip("Does this part feature a functional top cover?")]
	public bool OverridesTopCover = false;

	[Tooltip("Should the top cover start in the open (up) state when equipped?")]
	public bool StartTopCoverUp = false;

	[Tooltip("Optional: The FVRFireArmTopCover component on this part prefab.")]
	public FVRFireArmTopCover TopCoverScript;

	[Header("Caliber Conversion Settings")]
	[Tooltip("Does this part perform a caliber conversion?")]
	public bool OverridesRoundType = false;

	[Tooltip("The round type accepted by the weapon with this part equipped.")]
	public FireArmRoundType RoundTypeOverride;

	[Header("Belt-Fed (LMG) Settings")]
	[Tooltip("Does this part convert the firearm to a belt-fed system?")]
	public bool OverridesBeltFed = false;

	[Tooltip("The Belt Display Data component on this part.")]
	public FVRFirearmBeltDisplayData BeltDisplayData;

	[Tooltip("Local transform where the belt box mounts on this part.")]
	public Transform BeltBoxMountPos;

	[Tooltip("Local transform where the belt box ejects on this part.")]
	public Transform BeltBoxEjectPos;

	[Tooltip("Does the belt system require the bolt to be back to seat the belt?")]
	public bool RequiresBoltBackToSeatBelt = false;

	[Tooltip("Optional: The FVRFireArmBeltRemovalTrigger component on this part prefab.")]
	public FVRFireArmBeltRemovalTrigger BeltRemovalTrigger;

	[Tooltip("Optional: The ParticleSystem that ejects links when firing.")]
	public ParticleSystem DelinkerSystemOverride;

	[Tooltip("Optional: The GameObject prefab containing your pre-combined bullet + link models.")]
	public GameObject CustomProxyPrefab;

	[Tooltip("Where the ammo belt physically exits your part (used if no magazine is loaded).")]
	public Transform BeltExitPointOverride;

	[Tooltip("Where the ammo belt physically enters the gun's feed tray.")]
	public Transform FeedTrayEntPos;

	[Tooltip("How far down (in meters) the ammo belt sags between the box and the gun.")]
	public float BeltGravitySag = 0.15f;

	[Tooltip("Rotate the bullet model in the Inspector if it is facing the wrong direction.")]
	public Vector3 BulletRotationOffset = Vector3.zero;

	private FVRFireArm _mainFireArm;

	private bool _originalUsesMagazines;

	privat