Decompiled source of 40SW Additional v1.0.0

40SW_Additional.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using OpenScripts2;
using OtherLoader;
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 WinterTrigger : FVRInteractiveObject
{
	[Header("Deploy")]
	public Transform Pivot;

	public Vector3 StowedLocalEuler;

	public Vector3 DeployedLocalEuler;

	public float DeploySpeed = 6f;

	[Header("Trigger Follow")]
	public ClosedBoltWeapon Weapon;

	public Transform WeaponTrigger;

	public Transform WinterTriggerTransform;

	public bool FollowRotation = true;

	public Vector3 RotationOffset;

	public bool FollowTranslation;

	public Vector3 PositionOffset;

	private bool m_isDeployed;

	private float m_deployLerp;

	private Quaternion m_stowedTriggerRotation;

	private Vector3 m_stowedTriggerPosition;

	private bool m_hasStowedTriggerPose;

	public override void Awake()
	{
		((FVRInteractiveObject)this).Awake();
		CacheWeaponTrigger();
		CacheStowedTriggerPose();
		SetPivotPose(0f);
	}

	public override void SimpleInteraction(FVRViveHand hand)
	{
		((FVRInteractiveObject)this).SimpleInteraction(hand);
		m_isDeployed = !m_isDeployed;
	}

	public override void FVRUpdate()
	{
		((FVRInteractiveObject)this).FVRUpdate();
		CacheWeaponTrigger();
		float num = ((!m_isDeployed) ? 0f : 1f);
		m_deployLerp = Mathf.MoveTowards(m_deployLerp, num, DeploySpeed * Time.deltaTime);
		SetPivotPose(m_deployLerp);
		if (m_isDeployed)
		{
			ApplyTriggerFollow();
		}
		else
		{
			RestoreStowedTriggerPose();
		}
	}

	private void CacheWeaponTrigger()
	{
		if ((Object)(object)WeaponTrigger == (Object)null && (Object)(object)Weapon != (Object)null)
		{
			WeaponTrigger = Weapon.Trigger;
		}
	}

	private void CacheStowedTriggerPose()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)WinterTriggerTransform == (Object)null))
		{
			m_stowedTriggerRotation = WinterTriggerTransform.localRotation;
			m_stowedTriggerPosition = WinterTriggerTransform.localPosition;
			m_hasStowedTriggerPose = true;
		}
	}

	private void SetPivotPose(float t)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)Pivot == (Object)null))
		{
			Quaternion val = Quaternion.Euler(StowedLocalEuler);
			Quaternion val2 = Quaternion.Euler(DeployedLocalEuler);
			Pivot.localRotation = Quaternion.Slerp(val, val2, t);
		}
	}

	private void ApplyTriggerFollow()
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: 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)
		if (!((Object)(object)WinterTriggerTransform == (Object)null) && !((Object)(object)WeaponTrigger == (Object)null))
		{
			if (FollowRotation)
			{
				WinterTriggerTransform.localRotation = WeaponTrigger.localRotation * Quaternion.Euler(RotationOffset);
			}
			if (FollowTranslation)
			{
				WinterTriggerTransform.localPosition = WeaponTrigger.localPosition + PositionOffset;
			}
		}
	}

	private void RestoreStowedTriggerPose()
	{
		//IL_002a: 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)
		if (m_hasStowedTriggerPose && !((Object)(object)WinterTriggerTransform == (Object)null))
		{
			WinterTriggerTransform.localRotation = m_stowedTriggerRotation;
			WinterTriggerTransform.localPosition = m_stowedTriggerPosition;
		}
	}
}
public class MDTCkyeBipodController : MonoBehaviour
{
	public Transform GroundContactReference;

	public LayerMask ValidGroundLayers;

	public float RaycastDistance = 0.5f;

	private Vector3 lastExternalPosition;

	private void Start()
	{
		//IL_001a: 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 ((Object)(object)GroundContactReference != (Object)null)
		{
			lastExternalPosition = GroundContactReference.position;
		}
	}

	private void LateUpdate()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)GroundContactReference != (Object)null && GroundContactReference.position != lastExternalPosition)
		{
			UpdateGroundPoint();
			lastExternalPosition = GroundContactReference.position;
		}
	}

	private void UpdateGroundPoint()
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: 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_00ed: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//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_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		Ray val = default(Ray);
		((Ray)(ref val))..ctor(GroundContactReference.position, -Vector3.up);
		RaycastHit val2 = default(RaycastHit);
		if (Physics.Raycast(val, ref val2, RaycastDistance, LayerMask.op_Implicit(ValidGroundLayers)))
		{
			float y = GroundContactReference.position.y;
			float y2 = ((RaycastHit)(ref val2)).point.y;
			if (Mathf.Abs(y - y2) > 0.001f)
			{
				GroundContactReference.position = new Vector3(GroundContactReference.position.x, y2, GroundContactReference.position.z);
			}
			Debug.DrawRay(GroundContactReference.position, -Vector3.up * RaycastDistance, Color.green);
		}
		else
		{
			Debug.DrawRay(GroundContactReference.position, -Vector3.up * RaycastDistance, Color.red);
		}
	}
}
public class ForeMagRelease : UniversalAdvancedMagazineGrabTrigger
{
	[Header("ForeMagRelease Config")]
	public bool EjectMainMagOnSecondaryRelease = true;

	private bool wasSecondaryMagPresent = true;

	public override void UpdateInteraction(FVRViveHand hand)
	{
		((UniversalAdvancedMagazineGrabTrigger)this).UpdateInteraction(hand);
		if (base.IsSecondarySlotGrab)
		{
			FVRFireArmMagazine magazine = base.FireArm.SecondaryMagazineSlots[base.SecondaryGrabSlot].Magazine;
			if (wasSecondaryMagPresent && (Object)(object)magazine == (Object)null && EjectMainMagOnSecondaryRelease && (Object)(object)base.FireArm.Magazine != (Object)null)
			{
				base.FireArm.EjectMag(false);
			}
			wasSecondaryMagPresent = (Object)(object)magazine != (Object)null;
		}
		else
		{
			wasSecondaryMagPresent = true;
		}
	}
}
public class AmmoRecoilBlast : MonoBehaviour
{
	public BallisticProjectile Projectile;

	[Header("Recoil Settings")]
	public float RecoilForce = 3.5f;

	public bool UseHeadDirection = true;

	private bool _hasBlasted = false;

	private void Start()
	{
		if ((Object)(object)Projectile == (Object)null)
		{
			Projectile = ((Component)this).GetComponent<BallisticProjectile>();
		}
		((MonoBehaviour)this).StartCoroutine(WaitAndApplyRecoil());
	}

	private IEnumerator WaitAndApplyRecoil()
	{
		while ((Object)(object)Projectile != (Object)null && !Projectile.IsMoving())
		{
			yield return null;
		}
		ApplyRecoil();
	}

	private void ApplyRecoil()
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_005d: 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_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: 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)
		if (_hasBlasted)
		{
			return;
		}
		_hasBlasted = true;
		if (!((Object)(object)GM.CurrentMovementManager == (Object)null) && !((Object)(object)GM.CurrentPlayerBody == (Object)null))
		{
			Vector3 forward = ((Component)GM.CurrentMovementManager).transform.forward;
			Vector3 up = ((Component)GM.CurrentMovementManager).transform.up;
			Vector3 val = Vector3.ProjectOnPlane(forward, up);
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			if ((Object)(object)Projectile != (Object)null && (Object)(object)((Component)Projectile).transform != (Object)null)
			{
				Vector3 val2 = Vector3.ProjectOnPlane(((Component)Projectile).transform.forward, up);
				normalized = ((Vector3)(ref val2)).normalized;
			}
			((MonoBehaviour)this).StartCoroutine(ApplyRecoilSmoothly(-normalized, RecoilForce, 0.2f));
		}
	}

	private IEnumerator ApplyRecoilSmoothly(Vector3 direction, float force, float duration)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		float elapsed = 0f;
		while (elapsed < duration)
		{
			float stepForce = force * Time.deltaTime / duration;
			GM.CurrentMovementManager.Blast(direction, stepForce, true);
			elapsed += Time.deltaTime;
			yield return null;
		}
	}
}
public class BoxMagBeltFix : MonoBehaviour
{
	public FVRFireArm targetGun;

	public GameObject boxMagazineObject;

	private FVRFireArmMagazine boxMagazine;

	private GameObject beltVisual;

	private bool beltHidden = false;

	private void Start()
	{
		if ((Object)(object)targetGun == (Object)null)
		{
			Debug.LogError((object)"BoxMagBeltFix: targetGun not assigned!");
			((Behaviour)this).enabled = false;
			return;
		}
		if ((Object)(object)targetGun.BeltDD != (Object)null)
		{
			beltVisual = ((Component)targetGun.BeltDD).gameObject;
		}
		if ((Object)(object)boxMagazineObject != (Object)null)
		{
			boxMagazine = boxMagazineObject.GetComponent<FVRFireArmMagazine>();
			if ((Object)(object)boxMagazine == (Object)null)
			{
				Debug.LogError((object)"BoxMagBeltFix: boxMagazineObject does not have FVRFireArmMagazine component!");
				((Behaviour)this).enabled = false;
				return;
			}
			FVRFireArmBeltSegment[] componentsInChildren = ((Component)targetGun).GetComponentsInChildren<FVRFireArmBeltSegment>(true);
			FVRFireArmBeltSegment[] array = componentsInChildren;
			foreach (FVRFireArmBeltSegment val in array)
			{
				if ((Object)(object)targetGun.BeltDD == (Object)null || (Object)(object)((Component)val).gameObject != (Object)(object)((Component)targetGun.BeltDD).gameObject)
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
		}
		else
		{
			Debug.LogError((object)"BoxMagBeltFix: boxMagazineObject not assigned!");
			((Behaviour)this).enabled = false;
		}
	}

	private void Update()
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)boxMagazine == (Object)null || (Object)(object)targetGun == (Object)null)
		{
			return;
		}
		if ((Object)(object)targetGun.Magazine != (Object)(object)boxMagazine && (int)boxMagazine.State == 0)
		{
			targetGun.LoadMag(boxMagazine);
		}
		bool flag = (Object)(object)targetGun.Magazine == (Object)(object)boxMagazine;
		if (flag && !beltHidden)
		{
			if ((Object)(object)beltVisual != (Object)null)
			{
				beltVisual.SetActive(false);
			}
			FVRFireArmBeltSegment[] componentsInChildren = ((Component)targetGun).GetComponentsInChildren<FVRFireArmBeltSegment>(true);
			FVRFireArmBeltSegment[] array = componentsInChildren;
			foreach (FVRFireArmBeltSegment val in array)
			{
				if ((Object)(object)((Component)val).gameObject != (Object)(object)((Component)targetGun.BeltDD).gameObject)
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
			beltHidden = true;
		}
		else if (!flag && beltHidden)
		{
			if ((Object)(object)beltVisual != (Object)null)
			{
				beltVisual.SetActive(true);
			}
			beltHidden = false;
		}
	}
}
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 ResidualBeltLinkHandler : MonoBehaviour
{
	public enum Axis
	{
		X,
		Y,
		Z
	}

	[Header("References")]
	public FVRFireArm Firearm;

	public Transform FeedTraySpawnPoint;

	public GameObject BeltLinkPrefab;

	[Header("Feed Tray")]
	public Transform FeedTray;

	public float FeedTrayClearAngleMin = 55f;

	public float FeedTrayClearAngleMax = 70f;

	public Axis FeedTrayClearAxis = Axis.X;

	[Header("Behavior")]
	public float AutoCleanupTime = 10f;

	public float ShakeClearAngularVelocity = 6f;

	public float HandClearVelocity = 0.5f;

	private GameObject _spawnedLink;

	private Rigidbody _linkRB;

	private bool _hasResidualLink;

	private float _cleanupTimer;

	private float _currentClearAngle;

	private int _lastKnownRounds = -1;

	private void Update()
	{
		//IL_00e9: 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_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Firearm != (Object)null && (Object)(object)Firearm.Magazine != (Object)null)
		{
			int numRounds = Firearm.Magazine.m_numRounds;
			if (_lastKnownRounds > 0 && numRounds == 0 && !_hasResidualLink)
			{
				SpawnResidualLink();
			}
			_lastKnownRounds = numRounds;
		}
		if (!_hasResidualLink)
		{
			return;
		}
		_cleanupTimer += Time.deltaTime;
		if ((Object)(object)_spawnedLink == (Object)null || _cleanupTimer > AutoCleanupTime)
		{
			ClearResidualLink();
			return;
		}
		if ((Object)(object)Firearm != (Object)null && (Object)(object)((FVRPhysicalObject)Firearm).RootRigidbody != (Object)null)
		{
			Vector3 angularVelocity = ((FVRPhysicalObject)Firearm).RootRigidbody.angularVelocity;
			if (((Vector3)(ref angularVelocity)).magnitude > ShakeClearAngularVelocity)
			{
				ClearResidualLink();
			}
		}
		if ((Object)(object)FeedTray != (Object)null)
		{
			float num = 0f;
			switch (FeedTrayClearAxis)
			{
			case Axis.X:
				num = Mathf.Abs(Mathf.DeltaAngle(FeedTray.localEulerAngles.x, 0f));
				break;
			case Axis.Y:
				num = Mathf.Abs(Mathf.DeltaAngle(FeedTray.localEulerAngles.y, 0f));
				break;
			case Axis.Z:
				num = Mathf.Abs(Mathf.DeltaAngle(FeedTray.localEulerAngles.z, 0f));
				break;
			}
			if (num > _currentClearAngle && num < 180f)
			{
				ClearResidualLink();
			}
		}
	}

	private void OnTriggerEnter(Collider other)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: 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_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		if (_hasResidualLink)
		{
			FVRViveHand componentInParent = ((Component)other).GetComponentInParent<FVRViveHand>();
			if ((Object)(object)componentInParent != (Object)null && (Object)(object)_linkRB != (Object)null)
			{
				Vector3 normalized = ((Vector3)(ref componentInParent.Input.VelLinearWorld)).normalized;
				_linkRB.AddForce(normalized * 5f, (ForceMode)1);
				_linkRB.AddTorque(Random.onUnitSphere * 2f, (ForceMode)1);
				ClearResidualLinkPhysicsDelayed(5f);
			}
		}
	}

	public void SpawnResidualLink()
	{
		//IL_002f: 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_0093: Unknown result type (might be due to invalid IL or missing references)
		if (!_hasResidualLink && !((Object)(object)BeltLinkPrefab == (Object)null))
		{
			_spawnedLink = Object.Instantiate<GameObject>(BeltLinkPrefab, FeedTraySpawnPoint.position, FeedTraySpawnPoint.rotation);
			_linkRB = _spawnedLink.GetComponent<Rigidbody>();
			if ((Object)(object)_linkRB != (Object)null && (Object)(object)((FVRPhysicalObject)Firearm).RootRigidbody != (Object)null)
			{
				_linkRB.velocity = ((FVRPhysicalObject)Firearm).RootRigidbody.velocity;
			}
			_cleanupTimer = 0f;
			_hasResidualLink = true;
			_currentClearAngle = Random.Range(FeedTrayClearAngleMin, FeedTrayClearAngleMax);
			Firearm.HasBelt = false;
			Firearm.ConnectedToBox = false;
		}
	}

	private void ClearResidualLinkPhysicsDelayed(float delay)
	{
		if ((Object)(object)_spawnedLink != (Object)null)
		{
			Object.Destroy((Object)(object)_spawnedLink, delay);
		}
		_spawnedLink = null;
		_linkRB = null;
		_hasResidualLink = false;
		_cleanupTimer = 0f;
	}

	private void ClearResidualLink()
	{
		if ((Object)(object)_spawnedLink != (Object)null)
		{
			Object.Destroy((Object)(object)_spawnedLink);
		}
		_spawnedLink = null;
		_linkRB = null;
		_hasResidualLink = false;
		_cleanupTimer = 0f;
	}

	public bool CanAcceptNewBelt()
	{
		return !_hasResidualLink;
	}
}
public class SAFA_BoltController : MonoBehaviour
{
	private enum BoltState
	{
		semiAuto,
		fullAuto,
		safe,
		uncocked
	}

	public OpenBoltReceiver weapon;

	public int semiAuto;

	public int fullAuto;

	public Transform closedBoltSearPosition;

	private OpenBoltReceiverBolt bolt;

	private Transform sear;

	private Vector3 uncockedPos;

	private Transform openBoltSearPosition;

	private string lastMessage = "";

	private bool waitForShot;

	private BoltState boltState;

	public void Start()
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		bolt = weapon.Bolt;
		sear = weapon.Bolt.Point_Bolt_LockPoint;
		uncockedPos = weapon.Bolt.Point_Bolt_Forward.localPosition;
		openBoltSearPosition = sear;
	}

	public void Update()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: 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_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		if (((Component)bolt).transform.localPosition == uncockedPos)
		{
			boltState = BoltState.uncocked;
		}
		else if (((Component)bolt).transform.localPosition == openBoltSearPosition.localPosition)
		{
			boltState = BoltState.fullAuto;
		}
		else if (((Component)bolt).transform.localPosition == closedBoltSearPosition.localPosition)
		{
			boltState = BoltState.semiAuto;
		}
		if (boltState == BoltState.uncocked && weapon.m_fireSelectorMode == fullAuto)
		{
			bolt.m_boltZ_lock = openBoltSearPosition.localPosition.z;
		}
		else if (boltState == BoltState.uncocked && weapon.m_fireSelectorMode == semiAuto)
		{
			bolt.m_boltZ_lock = closedBoltSearPosition.localPosition.z;
		}
		else if (boltState == BoltState.semiAuto && weapon.m_fireSelectorMode == fullAuto)
		{
			waitForShot = true;
		}
		else if (boltState == BoltState.fullAuto && weapon.m_fireSelectorMode == semiAuto)
		{
			bolt.m_boltZ_lock = closedBoltSearPosition.localPosition.z;
			bolt.LastPos = (BoltPos)4;
			bolt.CurPos = (BoltPos)3;
		}
		if (waitForShot && (int)bolt.LastPos == 0)
		{
			bolt.m_boltZ_lock = openBoltSearPosition.localPosition.z;
			waitForShot = false;
		}
	}

	public void DebugOnce(string message)
	{
		if (message != lastMessage)
		{
			Debug.Log((object)message);
		}
		lastMessage = message;
	}
}
namespace Volks.40SW_Additional;

[BepInPlugin("Volks.40SW_Additional", "40SW_Additional", "1.0.0")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
public class 40SW_AdditionalPlugin : 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.40SW_Additional");
		OtherLoader.RegisterDirectLoad(BasePath, "Volks.40SW_Additional", "", "", "40sw_additional", "");
	}
}
public class ThermalOverlayWithZoomDisplay : PIPScopeGUIDrawer
{
	public PIPScopeController ScopeController;

	public Canvas OverlayCanvas;

	public Text ZoomText;

	public Material OverlayMaterial;

	public Texture2D OverlayTexture;

	public Color OverlayColor = Color.white;

	public float UpdateInterval = 0.1f;

	private float nextUpdateTime = 0f;

	private int lastThermalZoomIndex = -1;

	public override void DrawGUI(PIPScope scope, Canvas canvas, Vector2 canvasSize)
	{
		//IL_004d: 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)
		if (scope.enableThermal)
		{
			if ((Object)(object)OverlayMaterial != (Object)null && (Object)(object)OverlayTexture != (Object)null)
			{
				OverlayMaterial.mainTexture = (Texture)(object)OverlayTexture;
				OverlayMaterial.color = OverlayColor;
				OverlayMaterial.SetPass(0);
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(0f, 0f, canvasSize.x, canvasSize.y);
				GUI.DrawTexture(val, (Texture)(object)OverlayTexture);
			}
			UpdateZoomLevelDisplay();
		}
	}

	private void UpdateZoomLevelDisplay()
	{
		if (Time.time < nextUpdateTime)
		{
			return;
		}
		nextUpdateTime = Time.time + UpdateInterval;
		if ((Object)(object)ScopeController == (Object)null || (Object)(object)ZoomText == (Object)null)
		{
			Debug.LogWarning((object)"ThermalOverlayWithZoomDisplay: Missing necessary references!");
			return;
		}
		int thermalZoomIndex = ScopeController.ThermalZoomIndex;
		if (lastThermalZoomIndex != thermalZoomIndex)
		{
			lastThermalZoomIndex = thermalZoomIndex;
			if (ScopeController.ThermalDigitalZoomMagnifications != null && thermalZoomIndex >= 0 && thermalZoomIndex < ScopeController.ThermalDigitalZoomMagnifications.Count)
			{
				float num = ScopeController.ThermalDigitalZoomMagnifications[thermalZoomIndex];
				ZoomText.text = $"Zoom Level: {num:F1}x";
			}
			else
			{
				ZoomText.text = "Zoom Level: N/A";
			}
		}
	}
}
public class BeltPhysic : MonoBehaviour
{
	[Header("Belt Settings")]
	public GameObject BeltLinkPrefab;

	public int MaxLinks = 50;

	public float LinkSpacing = 0.04f;

	public Transform BeltStart;

	public float GravityStrength = 9.8f;

	public int ConstraintIterations = 8;

	public float MaxBendAngle = 45f;

	public float SpacingStiffness = 0.6f;

	public float BendStiffness = 0.6f;

	public float MaxTwistAngle = 120f;

	public float VelocityDamping = 0.9f;

	public bool ConstrainToBeltPlane = true;

	[Header("Roll Settings")]
	public bool LockRollToBeltUp = false;

	public bool UseBeltRightAsUp = true;

	[Header("Feed Path")]
	public Transform[] FeedPathPoints;

	public float FeedPathStiffness = 1f;

	[Header("Link Visual Offsets")]
	[Tooltip("Offset from the link's pivot to the point that should connect to the next round.")]
	public Vector3 LinkPositionOffset = Vector3.zero;

	[Tooltip("Euler rotation offset for each link.")]
	public Vector3 LinkRotationOffset = Vector3.zero;

	[Header("Link Collision")]
	public float LinkCollisionRadius = 0.015f;

	public LayerMask CollisionMask = LayerMask.op_Implicit(-1);

	public float CollisionPushStrength = 1f;

	[Header("Magazine Reference (optional)")]
	public FVRFireArmMagazine Magazine;

	public bool AutoSyncMagazine = true;

	public bool ClampToMagazineCapacity = true;

	public int ManualRounds = 0;

	[Header("Anchoring")]
	public Transform StartAnchorOverride;

	[Header("Delinker Sync (optional)")]
	[Tooltip("Assign the firearm's delinker emitter transform here.")]
	public Transform DelinkerEmitterTransform;

	[Tooltip("Particle system to emit a fake delinker link.")]
	public ParticleSystem FakeDelinkerParticles;

	private readonly List<GameObject> _linkPool = new List<GameObject>();

	private readonly List<Vector3> _positions = new List<Vector3>();

	private readonly List<Vector3> _prevPositions = new List<Vector3>();

	private readonly List<Vector3> _upVectors = new List<Vector3>();

	private int _currentRounds = 0;

	private bool _isBeltSeated = false;

	private void Awake()
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < MaxLinks; i++)
		{
			GameObject val = Object.Instantiate<GameObject>(BeltLinkPrefab, ((Component)this).transform);
			val.SetActive(false);
			_linkPool.Add(val);
			_positions.Add(Vector3.zero);
			_prevPositions.Add(Vector3.zero);
			_upVectors.Add(Vector3.up);
		}
	}

	private void Start()
	{
		SeatBelt();
	}

	private void FixedUpdate()
	{
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		if (!_isBeltSeated)
		{
			return;
		}
		Transform val = ((!((Object)(object)StartAnchorOverride != (Object)null)) ? BeltStart : StartAnchorOverride);
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		int currentRoundCount = GetCurrentRoundCount();
		if (currentRoundCount != _currentRounds)
		{
			int currentRounds = _currentRounds;
			SetRounds(currentRoundCount);
			if (currentRoundCount < currentRounds)
			{
				int num = currentRounds - currentRoundCount;
				for (int i = 0; i < num; i++)
				{
					EmitFakeDelinker();
				}
			}
		}
		SimulateChainPhysics(val.position);
		UpdateBeltDisplay();
		if (_currentRounds == 0)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}

	private int GetCurrentRoundCount()
	{
		if (AutoSyncMagazine && (Object)(object)Magazine != (Object)null)
		{
			int num = Magazine.m_numRounds;
			if (ClampToMagazineCapacity)
			{
				num = Mathf.Min(num, Magazine.m_capacity);
			}
			return num;
		}
		return ManualRounds;
	}

	public void SetRounds(int count)
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: 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_008e: 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_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		Transform val = ((!((Object)(object)StartAnchorOverride != (Object)null)) ? BeltStart : StartAnchorOverride);
		if (!((Object)(object)val == (Object)null))
		{
			int currentRounds = _currentRounds;
			_currentRounds = Mathf.Clamp(count, 0, MaxLinks);
			Vector3 value = ((!UseBeltRightAsUp) ? val.up : val.right);
			for (int i = currentRounds; i < _currentRounds; i++)
			{
				Vector3 value2 = val.position + val.forward * ((float)i * LinkSpacing);
				_positions[i] = value2;
				_prevPositions[i] = value2;
				_upVectors[i] = value;
			}
		}
	}

	private void SimulateChainPhysics(Vector3 anchorPos)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: 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_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: 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_009e: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: 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_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: 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_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d4: 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_03e3: 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_03e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0289: Unknown result type (might be due to invalid IL or missing references)
		//IL_0298: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a6: 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_02b5: 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_02d2: 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_02d9: 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_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: 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_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: 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_0216: 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_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f4: 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_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0304: Unknown result type (might be due to invalid IL or missing references)
		//IL_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_031c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0321: 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)
		//IL_033a: Unknown result type (might be due to invalid IL or missing references)
		//IL_033c: Unknown result type (might be due to invalid IL or missing references)
		//IL_033e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0349: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		float fixedDeltaTime = Time.fixedDeltaTime;
		float num = 0.98f;
		for (int i = 1; i < _currentRounds; i++)
		{
			Vector3 val = (_positions[i] - _prevPositions[i]) * num * VelocityDamping;
			_prevPositions[i] = _positions[i];
			int index;
			List<Vector3> positions;
			(positions = _positions)[index = i] = positions[index] + val;
			int index2;
			(positions = _positions)[index2 = i] = positions[index2] + Vector3.down * GravityStrength * fixedDeltaTime * fixedDeltaTime;
		}
		for (int j = 0; j < ConstraintIterations; j++)
		{
			_positions[0] = anchorPos;
			if (FeedPathPoints != null && FeedPathPoints.Length > 0)
			{
				for (int k = 0; k < _currentRounds; k++)
				{
					float t = (float)k / (float)Mathf.Max(_currentRounds - 1, 1);
					Vector3 splinePosition = GetSplinePosition(t);
					Vector3 val2 = splinePosition - _positions[k];
					List<Vector3> positions;
					int index3;
					(positions = _positions)[index3 = k] = positions[index3] + val2 * FeedPathStiffness * 0.1f;
				}
			}
			for (int l = 1; l < _currentRounds; l++)
			{
				Vector3 val3 = _positions[l] - _positions[l - 1];
				float magnitude = ((Vector3)(ref val3)).magnitude;
				if (magnitude > 0f)
				{
					float num2 = magnitude - LinkSpacing;
					Vector3 val4 = ((Vector3)(ref val3)).normalized * (num2 * 0.5f * SpacingStiffness);
					if (l == 1)
					{
						List<Vector3> positions;
						int index4;
						(positions = _positions)[index4 = l] = positions[index4] - val4 * 2f;
					}
					else
					{
						int index5;
						List<Vector3> positions;
						(positions = _positions)[index5 = l] = positions[index5] - val4;
						int index6;
						(positions = _positions)[index6 = l - 1] = positions[index6] + val4;
					}
				}
				if (l > 1)
				{
					Vector3 val5 = _positions[l - 1] - _positions[l - 2];
					Vector3 normalized = ((Vector3)(ref val5)).normalized;
					Vector3 val6 = _positions[l] - _positions[l - 1];
					Vector3 normalized2 = ((Vector3)(ref val6)).normalized;
					float num3 = Vector3.Angle(normalized, normalized2);
					if (num3 > MaxBendAngle)
					{
						Vector3 val7 = Vector3.Cross(normalized, normalized2);
						Vector3 normalized3 = ((Vector3)(ref val7)).normalized;
						float num4 = (num3 - MaxBendAngle) * BendStiffness;
						Quaternion val8 = Quaternion.AngleAxis(num4, normalized3);
						_positions[l] = _positions[l - 1] + val8 * normalized * LinkSpacing;
					}
				}
			}
		}
		ResolveCollisions();
		if (ConstrainToBeltPlane && (Object)(object)BeltStart != (Object)null)
		{
			Vector3 up = BeltStart.up;
			for (int m = 0; m < _currentRounds; m++)
			{
				Vector3 val9 = _positions[m] - anchorPos;
				Vector3 val10 = Vector3.ProjectOnPlane(val9, up);
				_positions[m] = anchorPos + val10;
			}
		}
	}

	private Vector3 GetSplinePosition(float t)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: 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_0159: 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_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: 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_01a2: Unknown result type (might be due to invalid IL or missing references)
		if (FeedPathPoints.Length == 1)
		{
			return FeedPathPoints[0].position;
		}
		if (FeedPathPoints.Length == 2)
		{
			return Vector3.Lerp(FeedPathPoints[0].position, FeedPathPoints[1].position, t);
		}
		int num = FeedPathPoints.Length;
		int num2 = Mathf.FloorToInt(t * (float)(num - 1));
		int num3 = Mathf.Min(num2 + 1, num - 1);
		int num4 = Mathf.Min(num2 + 2, num - 1);
		int num5 = Mathf.Min(num2 + 3, num - 1);
		Vector3 position = FeedPathPoints[num2].position;
		Vector3 position2 = FeedPathPoints[num3].position;
		Vector3 position3 = FeedPathPoints[num4].position;
		Vector3 position4 = FeedPathPoints[num5].position;
		float num6 = t * (float)(num - 1) - (float)num2;
		return 0.5f * (2f * position2 + (-position + position3) * num6 + (2f * position - 5f * position2 + 4f * position3 - position4) * num6 * num6 + (-position + 3f * position2 - 3f * position3 + position4) * num6 * num6 * num6);
	}

	private void ResolveCollisions()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: 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_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < _currentRounds; i++)
		{
			Collider[] array = Physics.OverlapSphere(_positions[i], LinkCollisionRadius, LayerMask.op_Implicit(CollisionMask), (QueryTriggerInteraction)1);
			foreach (Collider val in array)
			{
				Vector3 val2 = val.ClosestPoint(_positions[i]);
				Vector3 val3 = _positions[i] - val2;
				float magnitude = ((Vector3)(ref val3)).magnitude;
				if (magnitude < LinkCollisionRadius)
				{
					if (magnitude > 0f)
					{
						float num = (LinkCollisionRadius - magnitude) * CollisionPushStrength;
						List<Vector3> positions;
						int index;
						(positions = _positions)[index = i] = positions[index] + ((Vector3)(ref val3)).normalized * num;
					}
					else
					{
						List<Vector3> positions;
						int index2;
						(positions = _positions)[index2 = i] = positions[index2] + Vector3.up * (LinkCollisionRadius * CollisionPushStrength);
					}
				}
			}
		}
	}

	private void UpdateBeltDisplay()
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: 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_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: 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_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0233: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: 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_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_027b: Unknown result type (might be due to invalid IL or missing references)
		//IL_027d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_028d: Unknown result type (might be due to invalid IL or missing references)
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_029e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: 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_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0350: Unknown result type (might be due to invalid IL or missing references)
		//IL_0352: Unknown result type (might be due to invalid IL or missing references)
		//IL_0358: Unknown result type (might be due to invalid IL or missing references)
		//IL_035d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0362: 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_0394: Unknown result type (might be due to invalid IL or missing references)
		//IL_039a: 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_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0308: Unknown result type (might be due to invalid IL or missing references)
		//IL_030d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_032a: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < _linkPool.Count; i++)
		{
			if (i < _currentRounds)
			{
				_linkPool[i].SetActive(true);
				_linkPool[i].transform.position = _positions[i];
				if (i == 0)
				{
					Vector3 val = ((!((Object)(object)BeltStart != (Object)null)) ? ((Component)this).transform.up : BeltStart.up);
					Vector3 val2 = ((!((Object)(object)BeltStart != (Object)null)) ? ((Component)this).transform.forward : BeltStart.forward);
					List<Vector3> upVectors = _upVectors;
					int index = i;
					Vector3 val3 = Vector3.ProjectOnPlane(val, val2);
					upVectors[index] = ((Vector3)(ref val3)).normalized;
					if (_upVectors[i] == Vector3.zero)
					{
						_upVectors[i] = Vector3.up;
					}
					_linkPool[i].transform.rotation = ((!((Object)(object)BeltStart != (Object)null)) ? ((Component)this).transform.rotation : BeltStart.rotation) * Quaternion.Euler(LinkRotationOffset);
				}
				else
				{
					Vector3 val4 = Vector3.forward;
					if (i < _currentRounds - 1)
					{
						Vector3 val5 = _positions[i + 1] - _positions[i];
						val4 = ((Vector3)(ref val5)).normalized;
					}
					else if (i > 0)
					{
						Vector3 val6 = _positions[i] - _positions[i - 1];
						val4 = ((Vector3)(ref val6)).normalized;
					}
					Vector3 val7 = (UseBeltRightAsUp ? ((!((Object)(object)BeltStart != (Object)null)) ? ((Component)this).transform.right : BeltStart.right) : ((!((Object)(object)BeltStart != (Object)null)) ? ((Component)this).transform.up : BeltStart.up));
					Vector3 val8 = Vector3.ProjectOnPlane(val7, val4);
					Vector3 val9 = ((Vector3)(ref val8)).normalized;
					if (val9 == Vector3.zero)
					{
						val9 = Vector3.up;
					}
					Vector3 val10;
					if (LockRollToBeltUp)
					{
						val10 = val9;
					}
					else
					{
						Vector3 val11 = Vector3.ProjectOnPlane(_upVectors[i - 1], val4);
						Vector3 val12 = ((Vector3)(ref val11)).normalized;
						if (val12 == Vector3.zero)
						{
							val12 = val9;
						}
						val10 = Vector3.RotateTowards(val12, val9, (float)Math.PI / 180f * MaxTwistAngle, 0f);
					}
					_upVectors[i] = val10;
					Transform val13 = _linkPool[i].transform.Find("Pivot");
					if ((Object)(object)val13 != (Object)null)
					{
						val13.localPosition = LinkPositionOffset;
						val13.localRotation = Quaternion.Euler(LinkRotationOffset);
						_linkPool[i].transform.rotation = Quaternion.LookRotation(val4, val10);
					}
					else
					{
						_linkPool[i].transform.rotation = Quaternion.LookRotation(val4, val10) * Quaternion.Euler(LinkRotationOffset);
						Transform transform = _linkPool[i].transform;
						transform.position += _linkPool[i].transform.rotation * LinkPositionOffset;
					}
				}
				UpdateLinkRoundType(_linkPool[i], i);
			}
			else
			{
				_linkPool[i].SetActive(false);
			}
		}
	}

	private void UpdateLinkRoundType(GameObject link, int index)
	{
		if (!((Object)(object)Magazine != (Object)null) || Magazine.LoadedRounds == null || index >= Magazine.LoadedRounds.Length)
		{
			return;
		}
		FVRLoadedRound val = Magazine.LoadedRounds[index];
		if (val != null)
		{
			MeshFilter component = link.GetComponent<MeshFilter>();
			Renderer component2 = link.GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null && (Object)(object)val.LR_Mesh != (Object)null)
			{
				component.mesh = val.LR_Mesh;
			}
			if ((Object)(object)component2 != (Object)null && (Object)(object)val.LR_Material != (Object)null)
			{
				component2.material = val.LR_Material;
			}
		}
	}

	public void AddRound()
	{
		SetRounds(_currentRounds + 1);
	}

	public void RemoveRound()
	{
		SetRounds(_currentRounds - 1);
		EmitFakeDelinker();
	}

	public void DetachBelt()
	{
		int currentRounds = _currentRounds;
		Object.Destroy((Object)(object)((Component)this).gameObject);
		if ((Object)(object)Magazine != (Object)null)
		{
			Magazine.m_numRounds = currentRounds;
		}
	}

	private void SeatBelt()
	{
		_isBeltSeated = true;
		SetRounds(GetCurrentRoundCount());
		UpdateBeltDisplay();
	}

	private void EmitFakeDelinker()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)FakeDelinkerParticles != (Object)null)
		{
			if ((Object)(object)DelinkerEmitterTransform != (Object)null)
			{
				((Component)FakeDelinkerParticles).transform.position = DelinkerEmitterTransform.position;
				((Component)FakeDelinkerParticles).transform.rotation = DelinkerEmitterTransform.rotation;
			}
			FakeDelinkerParticles.Emit(1);
		}
	}
}
public class ManualEjectorRod : FVRInteractiveObject
{
	[Header("Ejector Rod Points")]
	public Transform Point_Rod_Rest;

	public Transform Point_Rod_FullyOut;

	public Transform Point_Rod_Eject;

	public Transform Point_Rod_Closed;

	[Header("Spring Visual")]
	public Transform SpringObject;

	public Vector3 SpringScale_Rest = Vector3.one;

	public Vector3 SpringScale_FullyOut = new Vector3(1f, 1f, 0.5f);

	[Header("Revolver Reference")]
	public SingleActionRevolver Revolver;

	private float m_rodZ_rest;

	private float m_rodZ_out;

	private float m_rodZ_eject;

	private float m_rodZ_closed;

	private float m_rodZ_current;

	private float m_rodZ_heldTarget;

	private bool m_isHeld;

	public override void Awake()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		((FVRInteractiveObject)this).Awake();
		m_rodZ_rest = Point_Rod_Rest.localPosition.z;
		m_rodZ_out = Point_Rod_FullyOut.localPosition.z;
		m_rodZ_current = m_rodZ_rest;
		m_rodZ_eject = Point_Rod_Eject.localPosition.z;
		m_rodZ_closed = Point_Rod_Closed.localPosition.z;
	}

	public override void BeginInteraction(FVRViveHand hand)
	{
		((FVRInteractiveObject)this).BeginInteraction(hand);
		m_isHeld = true;
	}

	public override void UpdateInteraction(FVRViveHand hand)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: 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_0138: 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)
		((FVRInteractiveObject)this).UpdateInteraction(hand);
		Vector3 closestValidPoint = GetClosestValidPoint(Point_Rod_Rest.position, Point_Rod_FullyOut.position, ((HandInput)(ref hand.Input)).Pos);
		m_rodZ_heldTarget = ((Component)this).transform.parent.InverseTransformPoint(closestValidPoint).z;
		float num = Mathf.Min(m_rodZ_rest, m_rodZ_out);
		float num2 = Mathf.Max(m_rodZ_rest, m_rodZ_out);
		if ((Object)(object)Revolver != (Object)null && !Revolver.m_isStateToggled)
		{
			if (m_rodZ_rest < m_rodZ_out)
			{
				num2 = Mathf.Min(num2, m_rodZ_closed);
			}
			else
			{
				num = Mathf.Max(num, m_rodZ_closed);
			}
		}
		m_rodZ_current = Mathf.Clamp(m_rodZ_heldTarget, num, num2);
		Vector3 localPosition = ((Component)this).transform.localPosition;
		localPosition.z = m_rodZ_current;
		((Component)this).transform.localPosition = localPosition;
		if ((Object)(object)SpringObject != (Object)null)
		{
			float num3 = Mathf.InverseLerp(m_rodZ_rest, m_rodZ_out, m_rodZ_current);
			SpringObject.localScale = Vector3.Lerp(SpringScale_Rest, SpringScale_FullyOut, num3);
		}
		if ((Object)(object)Revolver != (Object)null && Revolver.m_isStateToggled && ((!(m_rodZ_rest < m_rodZ_out)) ? (m_rodZ_current <= m_rodZ_eject) : (m_rodZ_current >= m_rodZ_eject)))
		{
			Revolver.EjectPrevCylinder();
		}
	}

	public override void EndInteraction(FVRViveHand hand)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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)
		((FVRInteractiveObject)this).EndInteraction(hand);
		m_isHeld = false;
		Vector3 localPosition = ((Component)this).transform.localPosition;
		localPosition.z = m_rodZ_rest;
		((Component)this).transform.localPosition = localPosition;
	}

	private Vector3 GetClosestValidPoint(Vector3 a, Vector3 b, Vector3 point)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = b - a;
		float num = Vector3.Dot(point - a, ((Vector3)(ref val)).normalized) / ((Vector3)(ref val)).magnitude;
		num = Mathf.Clamp01(num);
		return a + val * num;
	}

	public void AnimateEject()
	{
		((MonoBehaviour)this).StartCoroutine(AnimateEjectRoutine());
	}

	private IEnumerator AnimateEjectRoutine()
	{
		float duration = 0.15f;
		float t2 = 0f;
		Vector3 localPos = ((Component)this).transform.localPosition;
		float startZ = m_rodZ_rest;
		float endZ = m_rodZ_eject;
		while (t2 < duration)
		{
			t2 += Time.deltaTime;
			float lerp = Mathf.Clamp01(t2 / duration);
			localPos.z = Mathf.Lerp(startZ, endZ, lerp);
			((Component)this).transform.localPosition = localPos;
			yield return null;
		}
		localPos.z = endZ;
		((Component)this).transform.localPosition = localPos;
		if ((Object)(object)Revolver != (Object)null && Revolver.m_isStateToggled)
		{
			Revolver.EjectPrevCylinder();
		}
		t2 = 0f;
		while (t2 < duration)
		{
			t2 += Time.deltaTime;
			float lerp2 = Mathf.Clamp01(t2 / duration);
			localPos.z = Mathf.Lerp(endZ, startZ, lerp2);
			((Component)this).transform.localPosition = localPos;
			yield return null;
		}
		localPos.z = startZ;
		((Component)this).transform.localPosition = localPos;
	}
}
public class SARotatingCylinder : FVRInteractiveObject
{
	[Header("References")]
	public SingleActionRevolver Revolver;

	public ManualEjectorRod EjectorRod;

	[Header("Rotation Settings")]
	public float SnapSpeed = 12f;

	public float RotationThreshold = 15f;

	[Header("Cylinder Direction")]
	public bool RotateClockwise = true;

	private int m_lastChamber = -1;

	private float m_lastAngle = 0f;

	private bool m_isProxyHoldingRevolver = false;

	private SingleActionRevolverCylinder Cylinder => (!((Object)(object)Revolver != (Object)null)) ? null : Revolver.Cylinder;

	private int GetAccessibleChamber()
	{
		return (!Revolver.IsAccessTwoChambersBack) ? Revolver.PrevChamber : Revolver.PrevChamber2;
	}

	public override void BeginInteraction(FVRViveHand hand)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		((FVRInteractiveObject)this).BeginInteraction(hand);
		if (!((Object)(object)Cylinder == (Object)null))
		{
			Vector3 val = ((HandInput)(ref hand.Input)).Pos - ((Component)this).transform.position;
			m_lastAngle = Mathf.Atan2(val.y, val.x) * 57.29578f;
			if ((Object)(object)Revolver != (Object)null && !((FVRInteractiveObject)Revolver).IsHeld)
			{
				((FVRInteractiveObject)Revolver).BeginInteraction(hand);
				m_isProxyHoldingRevolver = true;
			}
		}
	}

	public override void UpdateInteraction(FVRViveHand hand)
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: 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_0119: Unknown result type (might be due to invalid IL or missing references)
		((FVRInteractiveObject)this).UpdateInteraction(hand);
		if ((Object)(object)Cylinder == (Object)null || (Object)(object)Revolver == (Object)null || !Revolver.m_isStateToggled)
		{
			return;
		}
		Vector3 val = ((HandInput)(ref hand.Input)).Pos - ((Component)this).transform.position;
		float num = Mathf.Atan2(val.y, val.x) * 57.29578f;
		float num2 = Mathf.DeltaAngle(m_lastAngle, num);
		if (base.m_isHeld && Mathf.Abs(num2) > RotationThreshold)
		{
			int num3 = (RotateClockwise ? 1 : (-1));
			int accessibleChamber = GetAccessibleChamber();
			int curChamber = (accessibleChamber + num3 + Cylinder.NumChambers) % Cylinder.NumChambers;
			Revolver.CurChamber = curChamber;
			m_lastChamber = Revolver.CurChamber;
			m_lastAngle = num;
			((Component)this).transform.localRotation = Cylinder.GetLocalRotationFromCylinder(Revolver.CurChamber);
			((FVRFireArm)Revolver).PlayAudioEvent((FirearmAudioEventType)15, 1f);
			if (hand.Input.TriggerDown && (Object)(object)EjectorRod != (Object)null)
			{
				EjectorRod.AnimateEject();
			}
		}
		else
		{
			int accessibleChamber2 = GetAccessibleChamber();
			Revolver.CurChamber = accessibleChamber2;
			Quaternion localRotationFromCylinder = Cylinder.GetLocalRotationFromCylinder(accessibleChamber2);
			((Component)this).transform.localRotation = Quaternion.Slerp(((Component)this).transform.localRotation, localRotationFromCylinder, Time.deltaTime * SnapSpeed);
			if (accessibleChamber2 != m_lastChamber)
			{
				m_lastChamber = accessibleChamber2;
			}
		}
	}

	public override void EndInteraction(FVRViveHand hand)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		((FVRInteractiveObject)this).EndInteraction(hand);
		if ((Object)(object)Cylinder != (Object)null && (Object)(object)Revolver != (Object)null)
		{
			int accessibleChamber = GetAccessibleChamber();
			Revolver.CurChamber = accessibleChamber;
			((Component)this).transform.localRotation = Cylinder.GetLocalRotationFromCylinder(accessibleChamber);
		}
		if (m_isProxyHoldingRevolver && (Object)(object)Revolver != (Object)null && ((FVRInteractiveObject)Revolver).IsHeld)
		{
			((FVRInteractiveObject)Revolver).EndInteraction(hand);
			m_isProxyHoldingRevolver = false;
		}
	}
}
public class EjectionFollow : MonoBehaviour
{
	[Header("Open Bolt Weapon Config")]
	public OpenBoltReceiver FireArm;

	public Transform EjectionPortTransform;

	public Vector3 LocalEjectionSpeed = new Vector3(1f, 0f, 0f);

	public Vector3 LocalEjectionSpin = Vector3.zero;

	private void LateUpdate()
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: 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_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: 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_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)FireArm == (Object)null) && !((Object)(object)EjectionPortTransform == (Object)null))
		{
			FireArm.EjectionSpeed = EjectionPortTransform.right * LocalEjectionSpeed.x + EjectionPortTransform.up * LocalEjectionSpeed.y + EjectionPortTransform.forward * LocalEjectionSpeed.z;
			FireArm.EjectionSpin = EjectionPortTransform.right * LocalEjectionSpin.x + EjectionPortTransform.up * LocalEjectionSpin.y + EjectionPortTransform.forward * LocalEjectionSpin.z;
		}
	}
}
public class OneHandedFiring : MonoBehaviour
{
	public FVRFireArm Firearm;

	public bool ForegripWhenShouldered = true;

	public float StabilizeDistance = 0.22f;

	private FVRAlternateGrip _dummyAltGrip;

	private void Update()
	{
		//IL_0060: 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 ((Object)(object)Firearm == (Object)null)
		{
			return;
		}
		bool flag = false;
		if ((Object)(object)Firearm.StockPos != (Object)null && (Object)(object)GM.CurrentPlayerBody != (Object)null && (Object)(object)GM.CurrentPlayerBody.Torso != (Object)null)
		{
			float num = Vector3.Distance(Firearm.StockPos.position, GM.CurrentPlayerBody.Torso.position);
			flag = num < StabilizeDistance;
		}
		if (ForegripWhenShouldered && flag && (Object)(object)((FVRInteractiveObject)Firearm).m_hand != (Object)null && (Object)(object)((FVRInteractiveObject)Firearm).m_hand.OtherHand == (Object)null)
		{
			if ((Object)(object)((FVRPhysicalObject)Firearm).AltGrip == (Object)null || (Object)(object)((FVRPhysicalObject)Firearm).AltGrip == (Object)(object)_dummyAltGrip)
			{
				if ((Object)(object)_dummyAltGrip == (Object)null)
				{
					_dummyAltGrip = ((Component)Firearm).gameObject.AddComponent<FVRAlternateGrip>();
					_dummyAltGrip.PrimaryObject = (FVRPhysicalObject)(object)Firearm;
					((FVRInteractiveObject)_dummyAltGrip).m_hand = ((FVRInteractiveObject)Firearm).m_hand;
				}
				((FVRPhysicalObject)Firearm).AltGrip = _dummyAltGrip;
			}
		}
		else if ((Object)(object)((FVRPhysicalObject)Firearm).AltGrip == (Object)(object)_dummyAltGrip)
		{
			Object.Destroy((Object)(object)_dummyAltGrip);
			((FVRPhysicalObject)Firearm).AltGrip = null;
			_dummyAltGrip = null;
		}
	}
}
public class StockExtension : MonoBehaviour
{
	public FVRFireArm Firearm;

	[Tooltip("How far forward the weapon moves when shouldered")]
	public float PushDistance = 0.06f;

	public float LerpSpeed = 10f;

	private Vector3 _originalLocalPos;

	private float _lerp;

	private void Awake()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		_originalLocalPos = ((Component)this).transform.localPosition;
	}

	private void Update()
	{
		//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_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: 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_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_008e: 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_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)Firearm == (Object)null))
		{
			bool flag = Firearm.IsShoulderStabilized();
			_lerp = Mathf.MoveTowards(_lerp, (!flag) ? 0f : 1f, Time.deltaTime * LerpSpeed);
			if ((Object)(object)((Component)this).transform.parent != (Object)null)
			{
				Vector3 val = ((Component)this).transform.parent.InverseTransformDirection(((Component)Firearm).transform.forward);
				Vector3 val2 = _originalLocalPos + val * PushDistance;
				((Component)this).transform.localPosition = Vector3.Lerp(_originalLocalPos, val2, _lerp);
			}
			else
			{
				Vector3 val3 = _originalLocalPos + Vector3.forward * PushDistance;
				((Component)this).transform.localPosition = Vector3.Lerp(_originalLocalPos, val3, _lerp);
			}
		}
	}
}
public class ScopeControllerHandler : FVRInteractiveObject
{
	public GameObject TopObject;

	public GameObject BottomObject;

	public AudioEvent AudEvent_TopOn;

	public AudioEvent AudEvent_BottomOn;

	public bool IsTopSwitch;

	private static int _activeIndex = 0;

	public override void Start()
	{
		((FVRInteractiveObject)this).Start();
		SetActiveState(_activeIndex);
	}

	public override void SimpleInteraction(FVRViveHand hand)
	{
		//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)
		((FVRInteractiveObject)this).SimpleInteraction(hand);
		if (IsTopSwitch && _activeIndex != 1)
		{
			SetActiveState(1);
			if (AudEvent_TopOn != null)
			{
				SM.PlayCoreSound((FVRPooledAudioType)10, AudEvent_TopOn, ((Component)this).transform.position);
			}
		}
		else if (!IsTopSwitch && _activeIndex != 0)
		{
			SetActiveState(0);
			if (AudEvent_BottomOn != null)
			{
				SM.PlayCoreSound((FVRPooledAudioType)10, AudEvent_BottomOn, ((Component)this).transform.position);
			}
		}
	}

	private void SetActiveState(int index)
	{
		_activeIndex = index;
		if ((Object)(object)TopObject != (Object)null)
		{
			TopObject.SetActive(index == 1);
		}
		if ((Object)(object)BottomObject != (Object)null)
		{
			BottomObject.SetActive(index == 0);
		}
	}
}