Decompiled source of PK 23 01 v1.0.0

PK_23_01.dll

Decompiled 11 hours ago
using System;
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 OtherLoader;
using UnityEditor;
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 AdvanceLaserSightComponent : LaserLightAttachment
{
	public Transform KnobMesh;

	public Vector3 RotationAxis = Vector3.up;

	public List<float> CustomRotationAngles;

	public GameObject ControlledGameObject;

	public bool[] GameObjectEnableFlags;

	public AudioEvent SettingSwapSound;

	private int previousSettingsIndex = -1;

	private void Start()
	{
		UpdateKnobRotationAndGameObject();
	}

	private void Update()
	{
		UpdateKnobRotationAndGameObject();
	}

	private void UpdateKnobRotationAndGameObject()
	{
		//IL_0070: 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)
		if ((Object)(object)KnobMesh != (Object)null && base.Settings.Count > 0 && CustomRotationAngles.Count == base.Settings.Count && GameObjectEnableFlags.Length == base.Settings.Count)
		{
			float num = CustomRotationAngles[base.SettingsIndex];
			KnobMesh.localEulerAngles = RotationAxis * num;
			UpdateControlledGameObject(base.SettingsIndex);
			if (base.SettingsIndex != previousSettingsIndex)
			{
				PlaySettingSwapSound();
				previousSettingsIndex = base.SettingsIndex;
			}
		}
	}

	private void UpdateControlledGameObject(int settingIndex)
	{
		if ((Object)(object)ControlledGameObject != (Object)null)
		{
			ControlledGameObject.SetActive(GameObjectEnableFlags[settingIndex]);
		}
	}

	private void PlaySettingSwapSound()
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		if (SettingSwapSound != null && SettingSwapSound.Clips.Count > 0)
		{
			AudioClip val = SettingSwapSound.Clips[Random.Range(0, SettingSwapSound.Clips.Count)];
			AudioSource.PlayClipAtPoint(val, ((Component)this).transform.position, Random.Range(SettingSwapSound.VolumeRange.x, SettingSwapSound.VolumeRange.y));
		}
	}
}
public class DiceFaceDetector : MonoBehaviour
{
	public ParticleSystem effect;

	public Transform faceOneMarker;

	public float checkThreshold = 0.9f;

	public float cooldownTime = 2f;

	private float lastTriggerTime = 0f;

	private void Update()
	{
		//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)
		if (!((Object)(object)faceOneMarker == (Object)null) && !(Time.time - lastTriggerTime < cooldownTime) && Vector3.Dot(faceOneMarker.up, Vector3.up) > checkThreshold)
		{
			TriggerEffect();
		}
	}

	private void TriggerEffect()
	{
		if ((Object)(object)effect != (Object)null)
		{
			effect.Play();
			lastTriggerTime = Time.time;
		}
	}
}
public class HandgunExternalSafety : FVRInteractiveObject
{
	[Header("Weapon & Transform Settings")]
	public Handgun Weapon;

	public Transform SafetySwitch;

	[Header("Animation Settings")]
	public Axis Axis;

	public InterpStyle InterpStyle;

	[Header("Positions (Rotation or Translation values)")]
	public float SafetyOnPosition;

	public float SafetyOffPosition;

	public override void Awake()
	{
		((FVRInteractiveObject)this).Awake();
		UpdateSwitchVisual();
	}

	public override void SimpleInteraction(FVRViveHand hand)
	{
		((FVRInteractiveObject)this).SimpleInteraction(hand);
		ToggleSafetyState();
	}

	private void ToggleSafetyState()
	{
		if ((Object)(object)Weapon != (Object)null)
		{
			Weapon.ToggleSafety();
			UpdateSwitchVisual();
		}
	}

	private void UpdateSwitchVisual()
	{
		//IL_0059: 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)
		if (!((Object)(object)Weapon == (Object)null) && !((Object)(object)SafetySwitch == (Object)null))
		{
			float num = ((!Weapon.IsSafetyEngaged) ? SafetyOffPosition : SafetyOnPosition);
			((FVRPhysicalObject)Weapon).SetAnimatedComponent(SafetySwitch, num, InterpStyle, Axis);
		}
	}
}
public class QBScaler : MonoBehaviour
{
	public FVRQuickBeltSlot slot;

	public float scaleMultiplier = 0.5f;

	[Header("Debugging")]
	[Tooltip("Enable to output hierarchy diagnostic scans and scale logs to the Unity console.")]
	public bool enableDebugging = false;

	private Transform currentObj;

	private Vector3 originalScale;

	private Dictionary<Rigidbody, bool> trackedRigidbodies = new Dictionary<Rigidbody, bool>();

	private HashSet<FVRPhysicalObject> knownPhysObjs = new HashSet<FVRPhysicalObject>();

	private Dictionary<FVRPhysicalObject, Vector3> originalPhysScales = new Dictionary<FVRPhysicalObject, Vector3>();

	private HashSet<FVRFireArmAttachment> hoveringAttachments = new HashSet<FVRFireArmAttachment>();

	private void Awake()
	{
		if ((Object)(object)slot == (Object)null)
		{
			slot = ((Component)this).GetComponent<FVRQuickBeltSlot>();
		}
	}

	private void DebugLog(string message)
	{
		if (enableDebugging)
		{
			Debug.Log((object)("[QBScaler Debug] " + message));
		}
	}

	private void Update()
	{
		//IL_00b0: 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_00e2: 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_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0364: Unknown result type (might be due to invalid IL or missing references)
		//IL_057a: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_06a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ad: Expected O, but got Unknown
		//IL_08ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_08cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_086f: Unknown result type (might be due to invalid IL or missing references)
		//IL_087a: Unknown result type (might be due to invalid IL or missing references)
		//IL_087f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0889: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)slot == (Object)null || (Object)(object)slot.CurObject == (Object)null)
		{
			if ((Object)(object)currentObj != (Object)null)
			{
				DebugLog("Slotted object removed or slot became invalid. Restoring firearm state.");
				RestoreState();
				currentObj = null;
			}
			return;
		}
		if ((Object)(object)currentObj != (Object)(object)((Component)slot.CurObject).transform)
		{
			if ((Object)(object)currentObj != (Object)null)
			{
				RestoreState();
			}
			currentObj = ((Component)slot.CurObject).transform;
			originalScale = currentObj.localScale;
			DebugLog("Firearm entered QuickBelt slot: " + ((Object)currentObj).name + " | Original Scale: " + originalScale);
			trackedRigidbodies.Clear();
			knownPhysObjs.Clear();
			originalPhysScales.Clear();
			FVRPhysicalObject[] componentsInChildren = ((Component)currentObj).GetComponentsInChildren<FVRPhysicalObject>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if ((Object)(object)componentsInChildren[i] != (Object)null)
				{
					knownPhysObjs.Add(componentsInChildren[i]);
					originalPhysScales[componentsInChildren[i]] = ((Component)componentsInChildren[i]).transform.localScale;
				}
			}
			currentObj.localScale = originalScale * scaleMultiplier;
			PerformHierarchyDiagnostics(currentObj);
		}
		if (!((Object)(object)currentObj != (Object)null))
		{
			return;
		}
		Rigidbody component = ((Component)currentObj).GetComponent<Rigidbody>();
		Rigidbody[] componentsInChildren2 = ((Component)currentObj).GetComponentsInChildren<Rigidbody>(true);
		foreach (Rigidbody val in componentsInChildren2)
		{
			if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)component && !trackedRigidbodies.ContainsKey(val))
			{
				DebugLog("New child Rigidbody detected on slot: " + ((Object)val).name + " | Setting isKinematic to true.");
				trackedRigidbodies[val] = val.isKinematic;
				val.isKinematic = true;
			}
		}
		FVRFireArmAttachment[] array = Object.FindObjectsOfType<FVRFireArmAttachment>();
		List<FVRFireArmAttachment> list = new List<FVRFireArmAttachment>();
		foreach (FVRFireArmAttachment hoveringAttachment in hoveringAttachments)
		{
			if ((Object)(object)hoveringAttachment == (Object)null || !((FVRInteractiveObject)hoveringAttachment).IsHeld || (Object)(object)hoveringAttachment.Sensor == (Object)null || (Object)(object)hoveringAttachment.Sensor.CurHoveredMount == (Object)null || !((Component)hoveringAttachment.Sensor.CurHoveredMount).transform.IsChildOf(currentObj))
			{
				list.Add(hoveringAttachment);
			}
		}
		for (int k = 0; k < list.Count; k++)
		{
			FVRFireArmAttachment val2 = list[k];
			if ((Object)(object)val2 != (Object)null)
			{
				DebugLog("Attachment stopped hovering: " + ((Object)val2).name + ". Restoring its scale.");
				if (originalPhysScales.TryGetValue((FVRPhysicalObject)(object)val2, out var value))
				{
					((Component)val2).transform.localScale = value;
				}
			}
			hoveringAttachments.Remove(val2);
			if ((Object)(object)val2 != (Object)null && !((Component)val2).transform.IsChildOf(currentObj))
			{
				originalPhysScales.Remove((FVRPhysicalObject)(object)val2);
				knownPhysObjs.Remove((FVRPhysicalObject)(object)val2);
			}
		}
		foreach (FVRFireArmAttachment val3 in array)
		{
			if ((Object)(object)val3 != (Object)null && ((FVRInteractiveObject)val3).IsHeld && (Object)(object)val3.Sensor != (Object)null && (Object)(object)val3.Sensor.CurHoveredMount != (Object)null && ((Component)val3.Sensor.CurHoveredMount).transform.IsChildOf(currentObj) && !hoveringAttachments.Contains(val3))
			{
				hoveringAttachments.Add(val3);
				DebugLog("Attachment started hovering on scaled rail: " + ((Object)val3).name + ". Applying preview scale reduction.");
				if (!originalPhysScales.ContainsKey((FVRPhysicalObject)(object)val3))
				{
					originalPhysScales[(FVRPhysicalObject)(object)val3] = ((Component)val3).transform.localScale;
				}
				((Component)val3).transform.localScale = originalPhysScales[(FVRPhysicalObject)(object)val3] * scaleMultiplier;
			}
		}
		List<FVRPhysicalObject> list2 = new List<FVRPhysicalObject>();
		foreach (FVRPhysicalObject knownPhysObj in knownPhysObjs)
		{
			if ((Object)(object)knownPhysObj == (Object)null)
			{
				list2.Add(knownPhysObj);
			}
			else
			{
				if (((Component)knownPhysObj).transform.IsChildOf(currentObj))
				{
					continue;
				}
				DebugLog("Child physical object detached from slotted weapon: " + ((Object)knownPhysObj).name + ". Restoring its original scale.");
				if (originalPhysScales.TryGetValue(knownPhysObj, out var value2))
				{
					((Component)knownPhysObj).transform.localScale = value2;
				}
				Rigidbody[] componentsInChildren3 = ((Component)knownPhysObj).GetComponentsInChildren<Rigidbody>(true);
				for (int m = 0; m < componentsInChildren3.Length; m++)
				{
					if (trackedRigidbodies.TryGetValue(componentsInChildren3[m], out var value3))
					{
						componentsInChildren3[m].isKinematic = value3;
					}
					trackedRigidbodies.Remove(componentsInChildren3[m]);
				}
				list2.Add(knownPhysObj);
			}
		}
		for (int n = 0; n < list2.Count; n++)
		{
			knownPhysObjs.Remove(list2[n]);
			originalPhysScales.Remove(list2[n]);
		}
		FVRPhysicalObject[] componentsInChildren4 = ((Component)currentObj).GetComponentsInChildren<FVRPhysicalObject>(true);
		List<FVRPhysicalObject> list3 = new List<FVRPhysicalObject>();
		foreach (FVRPhysicalObject val4 in componentsInChildren4)
		{
			if (!((Object)(object)val4 != (Object)null) || knownPhysObjs.Contains(val4))
			{
				continue;
			}
			bool flag = false;
			if (val4 is FVRFireArmAttachment)
			{
				FVRFireArmAttachment val5 = (FVRFireArmAttachment)val4;
				if ((Object)(object)val5.curMount != (Object)null)
				{
					flag = true;
				}
			}
			else if (val4 is FVRFireArmMagazine)
			{
				flag = true;
			}
			if (flag)
			{
				Transform parent = ((Component)val4).transform.parent;
				while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)currentObj)
				{
					FVRPhysicalObject component2 = ((Component)parent).GetComponent<FVRPhysicalObject>();
					if ((Object)(object)component2 != (Object)null)
					{
						flag = false;
						break;
					}
					parent = parent.parent;
				}
			}
			if (flag)
			{
				list3.Add(val4);
				continue;
			}
			DebugLog("Identified child part spawned on firearm: " + ((Object)val4).name + " | Type: " + ((object)val4).GetType().Name + " | Handled by parent hierarchy.");
			knownPhysObjs.Add(val4);
		}
		for (int num2 = 0; num2 < list3.Count; num2++)
		{
			FVRPhysicalObject val6 = list3[num2];
			knownPhysObjs.Add(val6);
			bool flag2 = false;
			Transform parent2 = ((Component)val6).transform.parent;
			while ((Object)(object)parent2 != (Object)null && (Object)(object)parent2 != (Object)(object)currentObj)
			{
				FVRPhysicalObject component3 = ((Component)parent2).GetComponent<FVRPhysicalObject>();
				if ((Object)(object)component3 != (Object)null && list3.Contains(component3))
				{
					flag2 = true;
					break;
				}
				parent2 = parent2.parent;
			}
			if (!flag2)
			{
				if (!originalPhysScales.TryGetValue(val6, out var value4))
				{
					value4 = ((Component)val6).transform.localScale * scaleMultiplier;
					originalPhysScales[val6] = value4;
				}
				DebugLog("Manually correcting scale for newly attached item: " + ((Object)val6).name + " | New LocalScale: " + value4);
				((Component)val6).transform.localScale = value4;
			}
			else
			{
				originalPhysScales[val6] = ((Component)val6).transform.localScale;
			}
		}
		if (list3.Count > 0)
		{
			DebugLog("Dynamic hierarchy change detected inside slot. Running updated diagnostics.");
			PerformHierarchyDiagnostics(currentObj);
		}
	}

	private void RestoreState()
	{
		//IL_003b: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)currentObj == (Object)null)
		{
			return;
		}
		if ((Object)(object)currentObj != (Object)null)
		{
			DebugLog("Restoring firearm state to unslotted coordinates.");
			currentObj.localScale = originalScale;
			foreach (FVRFireArmAttachment hoveringAttachment in hoveringAttachments)
			{
				if ((Object)(object)hoveringAttachment != (Object)null && originalPhysScales.TryGetValue((FVRPhysicalObject)(object)hoveringAttachment, out var value))
				{
					((Component)hoveringAttachment).transform.localScale = value;
				}
			}
			foreach (KeyValuePair<FVRPhysicalObject, Vector3> originalPhysScale in originalPhysScales)
			{
				FVRPhysicalObject key = originalPhysScale.Key;
				Vector3 value2 = originalPhysScale.Value;
				if ((Object)(object)key != (Object)null)
				{
					((Component)key).transform.localScale = value2;
				}
			}
			foreach (KeyValuePair<Rigidbody, bool> trackedRigidbody in trackedRigidbodies)
			{
				Rigidbody key2 = trackedRigidbody.Key;
				bool value3 = trackedRigidbody.Value;
				if ((Object)(object)key2 != (Object)null)
				{
					key2.isKinematic = value3;
				}
			}
		}
		trackedRigidbodies.Clear();
		knownPhysObjs.Clear();
		originalPhysScales.Clear();
		hoveringAttachments.Clear();
	}

	private void PerformHierarchyDiagnostics(Transform root)
	{
		//IL_0048: 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_0097: 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_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		if (!enableDebugging || (Object)(object)root == (Object)null)
		{
			return;
		}
		Debug.Log((object)("[QBScaler Diagnostics] === START DIAGNOSTICS FOR: " + ((Object)root).name + " ==="));
		Debug.Log((object)string.Concat("[QBScaler Diagnostics] Root localScale: ", root.localScale, " | lossyScale: ", root.lossyScale));
		Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
		int num = 0;
		foreach (Transform val in componentsInChildren)
		{
			if ((Object)(object)val != (Object)null)
			{
				Vector3 localScale = val.localScale;
				if (Mathf.Abs(localScale.x - localScale.y) > 0.001f || Mathf.Abs(localScale.x - localScale.z) > 0.001f || Mathf.Abs(localScale.y - localScale.z) > 0.001f)
				{
					Debug.LogWarning((object)string.Concat("[QBScaler Warning] Non-Uniform scale detected on: ", ((Object)val).name, " | localScale: ", localScale, " | Path: ", GetGameObjectPath(val)));
					num++;
				}
			}
		}
		Debug.Log((object)("[QBScaler Diagnostics] Non-uniform scale transforms found: " + num + " (Non-uniform scale on parents can cause children to skew, warp, or offset when scaled or rotated)."));
		Rigidbody[] componentsInChildren2 = ((Component)root).GetComponentsInChildren<Rigidbody>(true);
		Debug.Log((object)("[QBScaler Diagnostics] Total child Rigidbodies found: " + componentsInChildren2.Length));
		foreach (Rigidbody val2 in componentsInChildren2)
		{
			if ((Object)(object)val2 != (Object)null)
			{
				Debug.Log((object)("[QBScaler Diagnostics] Rigidbody: " + ((Object)val2).name + " | isKinematic: " + val2.isKinematic + " | useGravity: " + val2.useGravity + " | Path: " + GetGameObjectPath(((Component)val2).transform)));
			}
		}
		Joint[] componentsInChildren3 = ((Component)root).GetComponentsInChildren<Joint>(true);
		Debug.Log((object)("[QBScaler Diagnostics] Total Joints found: " + componentsInChildren3.Length));
		foreach (Joint val3 in componentsInChildren3)
		{
			if ((Object)(object)val3 != (Object)null)
			{
				string text = ((!((Object)(object)val3.connectedBody != (Object)null)) ? "NULL (Connected to World)" : ((Object)val3.connectedBody).name);
				Debug.LogWarning((object)("[QBScaler Diagnostics] Joint found: " + ((object)val3).GetType().Name + " on " + ((Object)val3).name + " | connectedBody: " + text + " | Path: " + GetGameObjectPath(((Component)val3).transform)));
			}
		}
		FVRPhysicalObject[] componentsInChildren4 = ((Component)root).GetComponentsInChildren<FVRPhysicalObject>(true);
		Debug.Log((object)("[QBScaler Diagnostics] Total FVRPhysicalObject components found: " + componentsInChildren4.Length));
		foreach (FVRPhysicalObject val4 in componentsInChildren4)
		{
			if ((Object)(object)val4 != (Object)null)
			{
				Debug.Log((object)string.Concat("[QBScaler Diagnostics] FVRPhysicalObject: ", ((Object)val4).name, " | Type: ", ((object)val4).GetType().Name, " | localScale: ", ((Component)val4).transform.localScale, " | Path: ", GetGameObjectPath(((Component)val4).transform)));
			}
		}
		Debug.Log((object)("[QBScaler Diagnostics] === END DIAGNOSTICS FOR: " + ((Object)root).name + " ==="));
	}

	private string GetGameObjectPath(Transform t)
	{
		string text = ((Object)t).name;
		while ((Object)(object)t.parent != (Object)null)
		{
			t = t.parent;
			text = ((Object)t).name + "/" + text;
		}
		return text;
	}
}
namespace JerryComponent
{
	public class WristAttaching : MonoBehaviour
	{
		public enum HandPositionMode
		{
			PalmTransform,
			InputPos,
			WholeRig
		}

		public FVRPhysicalObject mainObj;

		public FVRInteractiveObject grabInterface;

		public GameObject phys;

		public Collider mainCol;

		public Rigidbody mainRig;

		public bool LeftOn = false;

		public bool RightOn = false;

		public GameObject posLeft;

		public GameObject posRight;

		public GameObject WatchGeo;

		public GameObject posMiddle;

		[Header("QB Slot (optional)")]
		public FVRQuickBeltSlot watchQBSlot;

		[Header("Gizmo (visual debugging)")]
		public bool ShowGizmos = true;

		public float GizmoSphereSize = 0.01f;

		public Color GizmoLeftColor = Color.cyan;

		public Color GizmoRightColor = Color.yellow;

		public Color GizmoMiddleColor = Color.green;

		public Color GizmoWatchColor = Color.magenta;

		[Header("Hand Position Debug")]
		public HandPositionMode HandPosMode = HandPositionMode.PalmTransform;

		public bool ShowHandPosLabels = true;

		[Header("Hand Orientation Debug")]
		public bool ShowHandOrientation = true;

		public float OrientationRayLength = 0.05f;

		public Color OrientationColor = Color.white;

		public float OrientationTipSizeMultiplier = 1.5f;

		private FVRPhysicalObject _trackedSlotObject;

		private void FixedUpdate()
		{
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: 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_010f: 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_01cb: 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_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)watchQBSlot != (Object)null)
			{
				if ((Object)(object)watchQBSlot.CurObject != (Object)null)
				{
					_trackedSlotObject = watchQBSlot.CurObject;
				}
				else if ((Object)(object)_trackedSlotObject != (Object)null)
				{
					if (((Component)_trackedSlotObject).transform.IsChildOf(((Component)this).transform))
					{
						((Component)_trackedSlotObject).transform.SetParent((Transform)null, true);
					}
					_trackedSlotObject = null;
				}
			}
			if (((FVRInteractiveObject)mainObj).m_isHeld)
			{
				if ((Object)(object)((Component)mainObj).transform.parent != (Object)null)
				{
					((Component)mainObj).transform.SetParent((Transform)null, true);
				}
				if ((Object)(object)((FVRInteractiveObject)mainObj).m_hand == (Object)(object)GM.CurrentMovementManager.Hands[0])
				{
					if (Vector3.Distance(((Component)mainObj).gameObject.transform.position, GM.CurrentMovementManager.Hands[1].PalmTransform.position) < 0.1f)
					{
						LeftOn = false;
						RightOn = true;
					}
					else if (Vector3.Distance(((Component)mainObj).gameObject.transform.position, GM.CurrentMovementManager.Hands[1].PalmTransform.position) >= 0.1f)
					{
						LeftOn = false;
						RightOn = false;
					}
				}
				if ((Object)(object)((FVRInteractiveObject)mainObj).m_hand == (Object)(object)GM.CurrentMovementManager.Hands[1])
				{
					if (Vector3.Distance(((Component)mainObj).gameObject.transform.position, GM.CurrentMovementManager.Hands[0].PalmTransform.position) < 0.1f)
					{
						LeftOn = true;
						RightOn = false;
					}
					else if (Vector3.Distance(((Component)mainObj).gameObject.transform.position, GM.CurrentMovementManager.Hands[0].PalmTransform.position) >= 0.1f)
					{
						LeftOn = false;
						RightOn = false;
					}
				}
			}
			else
			{
				if (!RightOn && !LeftOn)
				{
					WatchGeo.transform.localPosition = posMiddle.transform.localPosition;
					WatchGeo.transform.localRotation = posMiddle.transform.localRotation;
					mainRig.isKinematic = false;
					mainCol.enabled = true;
					phys.SetActive(true);
				}
				if (grabInterface.m_isHeld)
				{
					WatchGeo.transform.localPosition = posMiddle.transform.localPosition;
					WatchGeo.transform.localRotation = posMiddle.transform.localRotation;
					mainRig.isKinematic = false;
					mainCol.enabled = true;
					FVRViveHand hand = grabInterface.m_hand;
					grabInterface.ForceBreakInteraction();
					((FVRInteractiveObject)mainObj).BeginInteraction(hand);
					hand.ForceSetInteractable((FVRInteractiveObject)(object)mainObj);
					phys.SetActive(true);
					((Component)grabInterface).gameObject.SetActive(false);
				}
			}
		}

		private void Update()
		{
			//IL_004e: 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_009e: 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_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: 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_01bb: Unknown result type (might be due to invalid IL or missing references)
			if (LeftOn && !RightOn && !((FVRInteractiveObject)mainObj).m_isHeld)
			{
				((Component)mainObj).gameObject.transform.position = ((Component)GM.CurrentMovementManager.Hands[0]).gameObject.transform.position;
				((Component)mainObj).gameObject.transform.rotation = ((Component)GM.CurrentMovementManager.Hands[0]).gameObject.transform.rotation;
				WatchGeo.transform.localPosition = posLeft.transform.localPosition;
				WatchGeo.transform.localRotation = posLeft.transform.localRotation;
				mainRig.isKinematic = true;
				mainCol.enabled = false;
				phys.SetActive(false);
				((Component)grabInterface).gameObject.SetActive(true);
			}
			if (RightOn && !LeftOn && !((FVRInteractiveObject)mainObj).m_isHeld)
			{
				((Component)mainObj).gameObject.transform.position = ((Component)GM.CurrentMovementManager.Hands[1]).gameObject.transform.position;
				((Component)mainObj).gameObject.transform.rotation = ((Component)GM.CurrentMovementManager.Hands[1]).gameObject.transform.rotation;
				WatchGeo.transform.localPosition = posRight.transform.localPosition;
				WatchGeo.transform.localRotation = posRight.transform.localRotation;
				mainRig.isKinematic = true;
				mainCol.enabled = false;
				phys.SetActive(false);
				((Component)grabInterface).gameObject.SetActive(true);
			}
		}

		private Vector3 GetHandPositionSafe(int handIndex)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_00ca: 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)
			FVRMovementManager currentMovementManager = GM.CurrentMovementManager;
			if ((Object)(object)currentMovementManager == (Object)null)
			{
				return Vector3.zero;
			}
			FVRViveHand[] hands = currentMovementManager.Hands;
			if (hands == null || handIndex < 0 || handIndex >= hands.Length)
			{
				return Vector3.zero;
			}
			FVRViveHand val = hands[handIndex];
			if ((Object)(object)val == (Object)null)
			{
				return Vector3.zero;
			}
			return (Vector3)(HandPosMode switch
			{
				HandPositionMode.InputPos => ((HandInput)(ref val.Input)).Pos, 
				HandPositionMode.WholeRig => ((Object)(object)val.WholeRig != (Object)null) ? val.WholeRig.position : ((!((Object)(object)val.PalmTransform != (Object)null)) ? ((HandInput)(ref val.Input)).Pos : val.PalmTransform.position), 
				_ => (!((Object)(object)val.PalmTransform != (Object)null)) ? ((HandInput)(ref val.Input)).Pos : val.PalmTransform.position, 
			});
		}

		private Vector3 GetHandForwardSafe(int handIndex)
		{
			//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_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_0102: 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_006d: 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_008f: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			FVRMovementManager currentMovementManager = GM.CurrentMovementManager;
			if ((Object)(object)currentMovementManager == (Object)null)
			{
				return ((Component)this).transform.forward;
			}
			FVRViveHand[] hands = currentMovementManager.Hands;
			if (hands == null || handIndex < 0 || handIndex >= hands.Length)
			{
				return ((Component)this).transform.forward;
			}
			FVRViveHand val = hands[handIndex];
			if ((Object)(object)val == (Object)null)
			{
				return ((Component)this).transform.forward;
			}
			if ((Object)(object)val.PalmTransform != (Object)null)
			{
				return val.PalmTransform.forward;
			}
			if ((Object)(object)val.WholeRig != (Object)null)
			{
				return val.WholeRig.forward;
			}
			if ((Object)(object)GM.CurrentPlayerBody != (Object)null && (Object)(object)GM.CurrentPlayerBody.Torso != (Object)null)
			{
				return GM.CurrentPlayerBody.Torso.forward;
			}
			return ((Component)this).transform.forward;
		}

		private void OnDrawGizmos()
		{
			//IL_0024: 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_0055: 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_008d: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_0120: 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_0157: 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_0189: 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_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: 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_0219: 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_0233: 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_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: 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_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0425: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0446: Unknown result type (might be due to invalid IL or missing references)
			//IL_044b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0455: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0475: 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_02e5: 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_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: 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_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			if (!ShowGizmos)
			{
				return;
			}
			if ((Object)(object)posLeft != (Object)null)
			{
				Gizmos.color = GizmoLeftColor;
				Gizmos.DrawSphere(posLeft.transform.position, GizmoSphereSize);
				HandlesLabel(posLeft.transform.position, "posLeft");
			}
			if ((Object)(object)posRight != (Object)null)
			{
				Gizmos.color = GizmoRightColor;
				Gizmos.DrawSphere(posRight.transform.position, GizmoSphereSize);
				HandlesLabel(posRight.transform.position, "posRight");
			}
			if ((Object)(object)posMiddle != (Object)null)
			{
				Gizmos.color = GizmoMiddleColor;
				Gizmos.DrawSphere(posMiddle.transform.position, GizmoSphereSize);
				HandlesLabel(posMiddle.transform.position, "posMiddle");
			}
			if ((Object)(object)WatchGeo != (Object)null)
			{
				Gizmos.color = GizmoWatchColor;
				Gizmos.DrawWireSphere(WatchGeo.transform.position, GizmoSphereSize * 1.5f);
				HandlesLabel(WatchGeo.transform.position, "WatchGeo");
			}
			if ((Object)(object)posLeft != (Object)null)
			{
				Gizmos.color = Color.Lerp(GizmoLeftColor, Color.white, 0.6f);
				Gizmos.DrawLine(((Component)this).transform.position, posLeft.transform.position);
			}
			if ((Object)(object)posRight != (Object)null)
			{
				Gizmos.color = Color.Lerp(GizmoRightColor, Color.white, 0.6f);
				Gizmos.DrawLine(((Component)this).transform.position, posRight.transform.position);
			}
			if ((Object)(object)posMiddle != (Object)null)
			{
				Gizmos.color = Color.Lerp(GizmoMiddleColor, Color.white, 0.6f);
				Gizmos.DrawLine(((Component)this).transform.position, posMiddle.transform.position);
			}
			if (!Application.isPlaying)
			{
				return;
			}
			FVRMovementManager currentMovementManager = GM.CurrentMovementManager;
			FVRViveHand[] array = ((!((Object)(object)currentMovementManager != (Object)null)) ? null : currentMovementManager.Hands);
			if (array != null && array.Length >= 2)
			{
				Gizmos.color = Color.blue;
				Vector3 handPositionSafe = GetHandPositionSafe(0);
				Gizmos.DrawSphere(handPositionSafe, GizmoSphereSize * 0.8f);
				if (ShowHandPosLabels)
				{
					HandlesLabel(handPositionSafe, "LeftHand: " + HandPosMode);
				}
				Gizmos.color = Color.red;
				Vector3 handPositionSafe2 = GetHandPositionSafe(1);
				Gizmos.DrawSphere(handPositionSafe2, GizmoSphereSize * 0.8f);
				if (ShowHandPosLabels)
				{
					HandlesLabel(handPositionSafe2, "RightHand: " + HandPosMode);
				}
				if (ShowHandOrientation)
				{
					Gizmos.color = OrientationColor;
					Vector3 handForwardSafe = GetHandForwardSafe(0);
					Vector3 normalized = ((Vector3)(ref handForwardSafe)).normalized;
					Vector3 handForwardSafe2 = GetHandForwardSafe(1);
					Vector3 normalized2 = ((Vector3)(ref handForwardSafe2)).normalized;
					Vector3 val = handPositionSafe + normalized * OrientationRayLength;
					Vector3 val2 = handPositionSafe2 + normalized2 * OrientationRayLength;
					Gizmos.DrawLine(handPositionSafe, val);
					Gizmos.DrawSphere(val, GizmoSphereSize * OrientationTipSizeMultiplier);
					HandlesLabel(val, "L.forward");
					Gizmos.DrawLine(handPositionSafe2, val2);
					Gizmos.DrawSphere(val2, GizmoSphereSize * OrientationTipSizeMultiplier);
					HandlesLabel(val2, "R.forward");
				}
			}
			if ((Object)(object)mainObj != (Object)null && ((FVRInteractiveObject)mainObj).m_isHeld)
			{
				Gizmos.color = Color.white;
				Gizmos.DrawLine(((Component)mainObj).transform.position, ((Component)this).transform.position);
				HandlesLabel((((Component)mainObj).transform.position + ((Component)this).transform.position) * 0.5f, $"dist:{Vector3.Distance(((Component)mainObj).transform.position, ((Component)this).transform.position):F2}");
			}
		}

		private void HandlesLabel(Vector3 pos, string text)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0012: 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_001f: 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)
			GUIStyle val = new GUIStyle(EditorStyles.boldLabel);
			val.normal.textColor = Color.white;
			GUIStyle val2 = val;
			Handles.Label(pos + Vector3.up * (GizmoSphereSize * 2f), text, val2);
		}
	}
}
public class OpenBoltAltHandle : FVRInteractiveObject
{
	public enum HandleRot
	{
		Down,
		Mid,
		Up
	}

	public enum HandleState
	{
		Forward,
		Mid,
		Rear
	}

	[Header("References")]
	public OpenBoltReceiver Receiver;

	public OpenBoltReceiverBolt Bolt;

	[Header("Linear Travel")]
	public Transform Point_Fore;

	public Transform Point_Rear;

	public float ForwardSpeed = 1.5f;

	[Header("Rotation / Tilt")]
	public Transform BoltHandleRoot;

	public Transform BoltHandle;

	public float MinRot = 0f;

	public float MaxRot = 90f;

	public float UnlockThreshold = 65f;

	public float LockThreshold = 5f;

	public float RotateSnapSpeed = 270f;

	public HandleRot CurRot = HandleRot.Down;

	public HandleRot LastRot = HandleRot.Down;

	public HandleState CurState = HandleState.Forward;

	public HandleState LastState = HandleState.Forward;

	private float m_boltZ_forward;

	private float m_boltZ_rear;

	private float m_currentHandleZ;

	private float m_rotAngle;

	private bool m_hasReleasedBolt;

	protected 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_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)
		((FVRInteractiveObject)this).Awake();
		m_boltZ_forward = Point_Fore.localPosition.z;
		m_boltZ_rear = Point_Rear.localPosition.z;
		m_currentHandleZ = BoltHandleRoot.localPosition.z;
		m_rotAngle = MinRot;
		m_hasReleasedBolt = true;
	}

	public override void UpdateInteraction(FVRViveHand hand)
	{
		//IL_002e: 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_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: 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_0062: 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)
		((FVRInteractiveObject)this).UpdateInteraction(hand);
		UpdateRotationFromHand(hand);
		if (CurRot == HandleRot.Up || CurState != HandleState.Forward)
		{
			Vector3 closestValidPoint = ((FVRInteractiveObject)this).GetClosestValidPoint(Point_Fore.position, Point_Rear.position, ((HandInput)(ref hand.Input)).Pos);
			BoltHandleRoot.position = closestValidPoint;
			m_currentHandleZ = BoltHandleRoot.localPosition.z;
		}
		UpdateHandleState();
		UpdateRotState();
		if (CurState != HandleState.Forward)
		{
			float num = Mathf.InverseLerp(m_boltZ_forward, m_boltZ_rear, m_currentHandleZ);
			Bolt.ChargingHandleHeld(num);
		}
		else if (CurRot != HandleRot.Down)
		{
			Bolt.ChargingHandleHeld(0f);
		}
		if (CurState == HandleState.Forward && CurRot == HandleRot.Down)
		{
			if (!m_hasReleasedBolt)
			{
				Bolt.ChargingHandleReleased();
				m_hasReleasedBolt = true;
			}
		}
		else
		{
			m_hasReleasedBolt = false;
		}
		HandleRotAudioEvents();
		HandleStateAudioEvents();
		LastRot = CurRot;
		LastState = CurState;
	}

	public override void EndInteraction(FVRViveHand hand)
	{
		((FVRInteractiveObject)this).EndInteraction(hand);
	}

	protected void FVRUpdate()
	{
		//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_0072: 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_0085: 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)
		((FVRInteractiveObject)this).FVRUpdate();
		if (((FVRInteractiveObject)this).IsHeld)
		{
			return;
		}
		if (Mathf.Abs(m_currentHandleZ - m_boltZ_forward) > 0.001f)
		{
			m_currentHandleZ = Mathf.MoveTowards(m_currentHandleZ, m_boltZ_forward, Time.deltaTime * ForwardSpeed);
			BoltHandleRoot.localPosition = new Vector3(BoltHandleRoot.localPosition.x, BoltHandleRoot.localPosition.y, m_currentHandleZ);
			if (CurState != HandleState.Forward)
			{
				float num = Mathf.InverseLerp(m_boltZ_forward, m_boltZ_rear, m_currentHandleZ);
				Bolt.ChargingHandleHeld(num);
			}
		}
		if ((CurState == HandleState.Forward || CurState == HandleState.Mid) && m_rotAngle > MinRot + 0.5f)
		{
			m_rotAngle = Mathf.MoveTowards(m_rotAngle, MinRot, Time.deltaTime * RotateSnapSpeed);
			BoltHandle.localEulerAngles = new Vector3(0f, 0f, m_rotAngle);
		}
		UpdateHandleState();
		UpdateRotState();
		if (CurState == HandleState.Forward && CurRot == HandleRot.Down && !m_hasReleasedBolt)
		{
			Bolt.ChargingHandleReleased();
			m_hasReleasedBolt = true;
		}
		HandleStateAudioEvents();
		HandleRotAudioEvents();
		LastRot = CurRot;
		LastState = CurState;
	}

	private void UpdateRotationFromHand(FVRViveHand hand)
	{
		//IL_0007: 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_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_001d: 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_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_0031: 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_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_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: 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_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = ((HandInput)(ref hand.Input)).Pos - BoltHandle.position;
		Vector3 val2 = Vector3.ProjectOnPlane(val, BoltHandleRoot.forward);
		val = ((Vector3)(ref val2)).normalized;
		Vector3 right = BoltHandleRoot.right;
		float num = Mathf.Atan2(Vector3.Dot(BoltHandleRoot.forward, Vector3.Cross(right, val)), Vector3.Dot(right, val)) * 57.29578f;
		m_rotAngle = Mathf.Clamp(num, MinRot, MaxRot);
		BoltHandle.localEulerAngles = new Vector3(0f, 0f, m_rotAngle);
	}

	private void UpdateRotState()
	{
		if (m_rotAngle >= UnlockThreshold)
		{
			CurRot = HandleRot.Up;
		}
		else if (m_rotAngle <= MinRot + LockThreshold)
		{
			CurRot = HandleRot.Down;
		}
		else
		{
			CurRot = HandleRot.Mid;
		}
	}

	private void UpdateHandleState()
	{
		if (Mathf.Abs(m_currentHandleZ - m_boltZ_forward) < 0.005f)
		{
			CurState = HandleState.Forward;
		}
		else if (Mathf.Abs(m_currentHandleZ - m_boltZ_rear) < 0.005f)
		{
			CurState = HandleState.Rear;
		}
		else
		{
			CurState = HandleState.Mid;
		}
	}

	private void HandleRotAudioEvents()
	{
		if (!((Object)(object)Receiver == (Object)null))
		{
			if (CurRot == HandleRot.Up && LastRot != HandleRot.Up)
			{
				((FVRFireArm)Receiver).PlayAudioEvent((FirearmAudioEventType)12, 1f);
			}
			else if (CurRot == HandleRot.Down && LastRot != HandleRot.Down)
			{
				((FVRFireArm)Receiver).PlayAudioEvent((FirearmAudioEventType)13, 1f);
			}
		}
	}

	private void HandleStateAudioEvents()
	{
		if (!((Object)(object)Receiver == (Object)null))
		{
			if (CurState == HandleState.Rear && LastState != HandleState.Rear)
			{
				((FVRFireArm)Receiver).PlayAudioEvent((FirearmAudioEventType)10, 1f);
			}
			else if (CurState == HandleState.Forward && LastState != HandleState.Forward)
			{
				((FVRFireArm)Receiver).PlayAudioEvent((FirearmAudioEventType)11, 1f);
			}
		}
	}
}
public class SimpleFirearm : FVRFireArm
{
	[Serializable]
	public class SimpleFireSelectorMode
	{
		public float SelectorPosition;

		public FireSelectorModeType ModeType;

		public int BurstAmount = 3;

		public float EngagementDelay;
	}

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

	[Header("Optional Chamber")]
	[Tooltip("Leave this blank if the gun does not use a chamber and fires directly from the magazine.")]
	public FVRFireArmChamber Chamber;

	[Header("Bullet Ejection Configuration")]
	[Tooltip("If true, spent casings will be silently deleted instead of spawning physical brass.")]
	public bool DisableCaseEjections = false;

	public Transform RoundPos_Ejection;

	public Vector3 EjectionSpeed = new Vector3(4f, 2.5f, -1.2f);

	public Vector3 EjectionSpin = new Vector3(20f, 180f, 30f);

	[Header("Trigger Animation")]
	public bool HasTrigger = true;

	public Transform Trigger;

	public float TriggerFiringThreshold = 0.8f;

	public float TriggerResetThreshold = 0.4f;

	public float Trigger_ForwardValue;

	public float Trigger_RearwardValue;

	public Axis TriggerAxis;

	public InterpStyle TriggerInterpStyle = (InterpStyle)1;

	[Header("Fire Selector Configuration")]
	public Transform FireSelectorSwitch;

	public Axis FireSelector_Axis;

	public InterpStyle FireSelector_InterpStyle = (InterpStyle)1;

	public SimpleFireSelectorMode[] FireSelector_Modes;

	[Header("Magazine Release Button")]
	public bool HasMagReleaseButton = true;

	public Transform MagazineReleaseButton;

	public InterpStyle MagReleaseInterp;

	public Vector3 MagReleaseUnpressed;

	public Vector3 MagReleasePressed;

	private float m_triggerFloat;

	private bool m_hasTriggerReset = true;

	private int m_fireSelectorMode;

	private int m_CamBurst;

	private float m_engagementDelay;

	private float m_timeSinceFiredShot = 1f;

	private bool m_isMagReleaseHeld;

	private bool m_wasMagReleaseHeldDown;

	public override void Awake()
	{
		((FVRFireArm)this).Awake();
		if ((Object)(object)Chamber != (Object)null)
		{
			base.FChambers.Add(Chamber);
		}
		ResetCamBurst();
	}

	public override void FVRUpdate()
	{
		((FVRFireArm)this).FVRUpdate();
		if (m_engagementDelay > 0f)
		{
			m_engagementDelay -= Time.deltaTime;
		}
		if (m_timeSinceFiredShot < 1f)
		{
			m_timeSinceFiredShot += Time.deltaTime;
		}
		UpdateComponents();
	}

	public override void UpdateInteraction(FVRViveHand hand)
	{
		((FVRPhysicalObject)this).UpdateInteraction(hand);
		UpdateInputAndAnimate(hand);
	}

	public override void LoadMag(FVRFireArmMagazine mag)
	{
		((FVRFireArm)this).LoadMag(mag);
		if ((Object)(object)mag != (Object)null)
		{
			AutoChamberFromMag();
		}
	}

	public override void EjectMag(bool PhysicalRelease = false)
	{
		((FVRFireArm)this).EjectMag(PhysicalRelease);
	}

	private void UpdateInputAndAnimate(FVRViveHand hand)
	{
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: 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_0232: 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_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Invalid comparison between Unknown and I4
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Invalid comparison between Unknown and I4
		m_isMagReleaseHeld = false;
		if (((FVRPhysicalObject)this).IsAltHeld)
		{
			return;
		}
		if (((FVRInteractiveObject)this).m_hasTriggeredUpSinceBegin && m_engagementDelay <= 0f)
		{
			m_triggerFloat = hand.Input.TriggerFloat;
		}
		else
		{
			m_triggerFloat = 0f;
		}
		if (!m_hasTriggerReset && m_triggerFloat <= TriggerResetThreshold)
		{
			m_hasTriggerReset = true;
			if (FireSelector_Modes.Length > 0)
			{
				m_CamBurst = FireSelector_Modes[m_fireSelectorMode].BurstAmount;
				m_engagementDelay = FireSelector_Modes[m_fireSelectorMode].EngagementDelay;
			}
			((FVRFireArm)this).PlayAudioEvent((FirearmAudioEventType)16, 1f);
		}
		if (hand.IsInStreamlinedMode)
		{
			if (hand.Input.BYButtonDown)
			{
				ToggleFireSelector();
			}
			if (hand.Input.AXButtonDown && (Object)(object)MagazineReleaseButton != (Object)null)
			{
				ReleaseMag();
			}
			if (hand.Input.AXButtonPressed)
			{
				m_isMagReleaseHeld = true;
			}
		}
		else
		{
			Vector2 touchpadAxes = hand.Input.TouchpadAxes;
			if (hand.Input.TouchpadDown && ((Vector2)(ref touchpadAxes)).magnitude > 0.2f)
			{
				if (Vector2.Angle(touchpadAxes, Vector2.left) <= 45f)
				{
					ToggleFireSelector();
				}
				else if (Vector2.Angle(touchpadAxes, Vector2.down) <= 45f && (Object)(object)MagazineReleaseButton != (Object)null)
				{
					ReleaseMag();
				}
			}
			if (hand.Input.TouchpadPressed && ((Vector2)(ref touchpadAxes)).magnitude > 0.2f && Vector2.Angle(touchpadAxes, Vector2.down) <= 45f && (Object)(object)MagazineReleaseButton != (Object)null)
			{
				m_isMagReleaseHeld = true;
			}
		}
		if (FireSelector_Modes.Length <= 0 || !((FVRInteractiveObject)this).m_hasTriggeredUpSinceBegin)
		{
			return;
		}
		FireSelectorModeType modeType = FireSelector_Modes[m_fireSelectorMode].ModeType;
		if ((int)modeType != 0 && m_triggerFloat >= TriggerFiringThreshold && (m_hasTriggerReset || (int)modeType == 3 || ((int)modeType == 2 && m_CamBurst > 0)))
		{
			m_hasTriggerReset = false;
			if (Fire() && m_CamBurst > 0)
			{
				m_CamBurst--;
			}
		}
	}

	private void ToggleFireSelector()
	{
		//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)
		if (FireSelector_Modes.Length > 1)
		{
			m_fireSelectorMode++;
			if (m_fireSelectorMode >= FireSelector_Modes.Length)
			{
				m_fireSelectorMode = 0;
			}
			SimpleFireSelectorMode simpleFireSelectorMode = FireSelector_Modes[m_fireSelectorMode];
			if (m_triggerFloat < 0.1f)
			{
				m_CamBurst = simpleFireSelectorMode.BurstAmount;
				m_engagementDelay = 0f;
			}
			((FVRFireArm)this).PlayAudioEvent((FirearmAudioEventType)15, 1f);
			if ((Object)(object)FireSelectorSwitch != (Object)null)
			{
				((FVRPhysicalObject)this).SetAnimatedComponent(FireSelectorSwitch, simpleFireSelectorMode.SelectorPosition, FireSelector_InterpStyle, FireSelector_Axis);
			}
		}
		ResetCamBurst();
	}

	private void ResetCamBurst()
	{
		if (FireSelector_Modes.Length > 0)
		{
			m_CamBurst = FireSelector_Modes[m_fireSelectorMode].BurstAmount;
		}
		m_engagementDelay = 0f;
	}

	public void ReleaseMag()
	{
		if ((Object)(object)base.Magazine != (Object)null)
		{
			((FVRFireArm)this).EjectMag(false);
		}
	}

	private void AutoChamberFromMag()
	{
		if (!((Object)(object)Chamber != (Object)null) || Chamber.IsFull || !((Object)(object)base.Magazine != (Object)null) || !base.Magazine.HasARound())
		{
			return;
		}
		GameObject val = base.Magazine.RemoveRound(false);
		if ((Object)(object)val != (Object)null)
		{
			FVRFireArmRound component = val.GetComponent<FVRFireArmRound>();
			if ((Object)(object)component != (Object)null)
			{
				Chamber.SetRound(component, false);
				Chamber.PlayChamberingAudio();
			}
		}
	}

	public bool Fire()
	{
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: 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_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: 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_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: 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_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cc: 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_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: 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_02ff: 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_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_0346: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		FVRFireArmRound val = null;
		if ((Object)(object)Chamber != (Object)null)
		{
			if (!Chamber.IsFull || Chamber.IsSpent)
			{
				return false;
			}
			val = Chamber.GetRound();
			Chamber.IsSpent = true;
			Chamber.UpdateProxyDisplay();
		}
		else
		{
			if ((Object)(object)base.Magazine == (Object)null || !base.Magazine.HasARound())
			{
				return false;
			}
			GameObject val2 = base.Magazine.RemoveRound(false);
			if ((Object)(object)val2 != (Object)null)
			{
				val = val2.GetComponent<FVRFireArmRound>();
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			return false;
		}
		m_timeSinceFiredShot = 0f;
		if ((Object)(object)((FVRInteractiveObject)this).m_hand != (Object)null)
		{
			((FVRInteractiveObject)this).m_hand.Buzz(((FVRInteractiveObject)this).m_hand.Buzzer.Buzz_GunShot);
			if ((Object)(object)((FVRPhysicalObject)this).AltGrip != (Object)null && (Object)(object)((FVRInteractiveObject)((FVRPhysicalObject)this).AltGrip).m_hand != (Object)null)
			{
				((FVRInteractiveObject)((FVRPhysicalObject)this).AltGrip).m_hand.Buzz(((FVRInteractiveObject)((FVRPhysicalObject)this).AltGrip).m_hand.Buzzer.Buzz_GunShot);
			}
		}
		if ((Object)(object)val.BallisticProjectilePrefab != (Object)null)
		{
			Transform muzzle = ((FVRFireArm)this).GetMuzzle();
			GameObject val3 = Object.Instantiate<GameObject>(val.BallisticProjectilePrefab, muzzle.position, muzzle.rotation);
			BallisticProjectile component = val3.GetComponent<BallisticProjectile>();
			if ((Object)(object)component != (Object)null)
			{
				component.SetSource_IFF(GM.CurrentPlayerBody.GetPlayerIFF());
				component.Fire(component.MuzzleVelocityBase, val3.transform.forward, (FVRFireArm)(object)this, true);
			}
		}
		((FVRFireArm)this).FireMuzzleSmoke();
		bool flag = ((FVRFireArm)this).IsTwoHandStabilized();
		bool flag2 = (Object)(object)((FVRPhysicalObject)this).AltGrip != (Object)null;
		bool flag3 = ((FVRFireArm)this).IsShoulderStabilized();
		((FVRFireArm)this).Recoil(flag, flag2, flag3, (FVRFireArmRecoilProfile)null, 1f);
		((FVRFireArm)this).PlayAudioGunShot(val, GM.CurrentPlayerBody.GetCurrentSoundEnvironment(), 1f);
		if (!DisableCaseEjections && (Object)(object)RoundPos_Ejection != (Object)null)
		{
			Vector3 val4 = ((Component)this).transform.right * EjectionSpeed.x + ((Component)this).transform.up * EjectionSpeed.y + ((Component)this).transform.forward * EjectionSpeed.z;
			Vector3 angularVelocity = ((Component)this).transform.right * EjectionSpin.x + ((Component)this).transform.up * EjectionSpin.y + ((Component)this).transform.forward * EjectionSpin.z;
			GameObject val5 = Object.Instantiate<GameObject>(((Component)val).gameObject, RoundPos_Ejection.position, RoundPos_Ejection.rotation);
			FVRFireArmRound component2 = val5.GetComponent<FVRFireArmRound>();
			if ((Object)(object)component2 != (Object)null)
			{
				((FVRPhysicalObject)component2).SetIFF(GM.CurrentPlayerBody.GetPlayerIFF());
				((FVRPhysicalObject)component2).RootRigidbody.velocity = val4 + GM.CurrentMovementManager.GetFilteredVel();
				((FVRPhysicalObject)component2).RootRigidbody.angularVelocity = angularVelocity;
				component2.SetKillCounting(true);
				component2.Fire();
			}
		}
		if ((Object)(object)Chamber != (Object)null)
		{
			Chamber.SetRound((FVRFireArmRound)null, false);
			AutoChamberFromMag();
		}
		return true;
	}

	private void UpdateComponents()
	{
		//IL_003d: 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_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		if (HasTrigger && (Object)(object)Trigger != (Object)null)
		{
			((FVRPhysicalObject)this).SetAnimatedComponent(Trigger, Mathf.Lerp(Trigger_ForwardValue, Trigger_RearwardValue, m_triggerFloat), TriggerInterpStyle, TriggerAxis);
		}
		if (HasMagReleaseButton && (Object)(object)MagazineReleaseButton != (Object)null)
		{
			float num = ((!m_isMagReleaseHeld) ? 0f : 1f);
			Vector3 val = Vector3.Lerp(MagReleaseUnpressed, MagReleasePressed, num);
			if (m_wasMagReleaseHeldDown != m_isMagReleaseHeld)
			{
				m_wasMagReleaseHeldDown = m_isMagReleaseHeld;
				((FVRPhysicalObject)this).SetAnimatedComponent(MagazineReleaseButton, val, MagReleaseInterp);
			}
		}
	}

	private void LogDebug(string message)
	{
		if (DebugLogging)
		{
			Debug.Log((object)("SimpleFirearm: " + message));
		}
	}
}
[RequireComponent(typeof(Collider))]
public class GasRegulator : FVRInteractiveObject
{
	private enum BoltType
	{
		None,
		Open,
		Closed
	}

	[Serializable]
	public class RegulatorSetting
	{
		public string SettingName;

		[Header("Visual")]
		public float SelectorPosition;

		[Header("Bolt Params")]
		public float ForwardSpeed;

		public float RearwardSpeed;

		public float SpringStiffness;
	}

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

	public GameObject BoltObject;

	[Header("Regulator Settings")]
	public RegulatorSetting[] Settings;

	private int _index = 0;

	[Header("Visual")]
	public Transform RegulatorGeo;

	public Axis Axis;

	public InterpStyle InterpStyle;

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

	[Header("UI")]
	public GameObject TextRoot;

	public Text TextField;

	public float TextDisplayDuration = 2f;

	private BoltType _boltType = BoltType.None;

	private OpenBoltReceiverBolt _openBolt;

	private ClosedBolt _closedBolt;

	private bool _textVisible = false;

	private float _textTimer = 0f;

	public override void Awake()
	{
		((FVRInteractiveObject)this).Awake();
		if ((Object)(object)BoltObject != (Object)null)
		{
			_openBolt = BoltObject.GetComponent<OpenBoltReceiverBolt>();
			_closedBolt = BoltObject.GetComponent<ClosedBolt>();
			if ((Object)(object)_openBolt != (Object)null)
			{
				_boltType = BoltType.Open;
			}
			else if ((Object)(object)_closedBolt != (Object)null)
			{
				_boltType = BoltType.Closed;
			}
			else
			{
				Debug.LogWarning((object)"[GasRegulator] BoltObject has no OpenBoltReceiverBolt or ClosedBolt component.", (Object)(object)this);
			}
		}
		else
		{
			Debug.LogWarning((object)"[GasRegulator] No BoltObject assigned.", (Object)(object)this);
		}
		if ((Object)(object)TextRoot != (Object)null)
		{
			TextRoot.SetActive(false);
		}
		if (Settings != null && Settings.Length > 0)
		{
			ApplySetting(0);
		}
	}

	public override void FVRUpdate()
	{
		((FVRInteractiveObject)this).FVRUpdate();
		if (!_textVisible)
		{
			return;
		}
		_textTimer -= Time.deltaTime;
		if (_textTimer <= 0f)
		{
			_textVisible = false;
			if ((Object)(object)TextRoot != (Object)null)
			{
				TextRoot.SetActive(false);
			}
		}
	}

	public override void SimpleInteraction(FVRViveHand hand)
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		((FVRInteractiveObject)this).SimpleInteraction(hand);
		if (Settings != null && Settings.Length != 0)
		{
			_index++;
			if (_index >= Settings.Length)
			{
				_index = 0;
			}
			ApplySetting(_index);
			if ((Object)(object)Firearm != (Object)null)
			{
				Firearm.PlayAudioAsHandling(AudEvent_Switch, ((Component)this).transform.position);
			}
			ShowText(Settings[_index].SettingName);
		}
	}

	private void ApplySetting(int i)
	{
		//IL_003f: 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)
		RegulatorSetting regulatorSetting = Settings[i];
		if ((Object)(object)RegulatorGeo != (Object)null && (Object)(object)Firearm != (Object)null)
		{
			((FVRPhysicalObject)Firearm).SetAnimatedComponent(RegulatorGeo, regulatorSetting.SelectorPosition, InterpStyle, Axis);
		}
		switch (_boltType)
		{
		case BoltType.Open:
			_openBolt.BoltSpeed_Forward = regulatorSetting.ForwardSpeed;
			_openBolt.BoltSpeed_Rearward = regulatorSetting.RearwardSpeed;
			_openBolt.BoltSpringStiffness = regulatorSetting.SpringStiffness;
			break;
		case BoltType.Closed:
			_closedBolt.Speed_Forward = regulatorSetting.ForwardSpeed;
			_closedBolt.Speed_Rearward = regulatorSetting.RearwardSpeed;
			_closedBolt.SpringStiffness = regulatorSetting.SpringStiffness;
			break;
		}
	}

	private void ShowText(string settingName)
	{
		if (!((Object)(object)TextRoot == (Object)null))
		{
			if ((Object)(object)TextField != (Object)null)
			{
				TextField.text = settingName;
			}
			TextRoot.SetActive(true);
			_textVisible = true;
			_textTimer = TextDisplayDuration;
		}
	}
}
namespace Volks.PK_23_01
{
	[BepInPlugin("Volks.PK_23_01", "PK_23_01", "1.0.0")]
	[BepInProcess("h3vr.exe")]
	[Description("Built with MeatKit")]
	[BepInDependency("h3vr.otherloader", "1.3.0")]
	public class PK_23_01Plugin : 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.PK_23_01");
			OtherLoader.RegisterDirectLoad(BasePath, "Volks.PK_23_01", "", "", "pk2301_reddot", "");
		}
	}
}
public class AdvanceMagazineAudioProfile : MonoBehaviour
{
	[Header("References")]
	[Tooltip("Auto-populated from this GameObject if left empty.")]
	public FVRFireArmMagazine Magazine;

	[Header("Audio — Empty Magazine")]
	[Tooltip("Profile used for MagazineIn / MagazineOut when the magazine is empty.")]
	public FVRFirearmMagazineAudioSet EmptyProfile;

	private FVRFirearmMagazineAudioSet _originalProfileOverride;

	private bool _originalUsesOverrideInOut;

	private bool _wasEmpty;

	private void Start()
	{
		if ((Object)(object)Magazine == (Object)null)
		{
			Magazine = ((Component)this).GetComponent<FVRFireArmMagazine>();
		}
		if ((Object)(object)Magazine == (Object)null)
		{
			Debug.LogWarning((object)"[AdvanceMagazineAudioProfile] No FVRFireArmMagazine found on this GameObject.", (Object)(object)this);
			((Behaviour)this).enabled = false;
			return;
		}
		_originalProfileOverride = Magazine.ProfileOverride;
		_originalUsesOverrideInOut = Magazine.UsesOverrideInOut;
		_wasEmpty = !Magazine.HasARound();
		ApplyProfile(_wasEmpty);
	}

	private void Update()
	{
		if (!((Object)(object)Magazine == (Object)null))
		{
			bool flag = !Magazine.HasARound();
			if (flag != _wasEmpty)
			{
				_wasEmpty = flag;
				ApplyProfile(flag);
			}
		}
	}

	private void ApplyProfile(bool isEmpty)
	{
		if (isEmpty && (Object)(object)EmptyProfile != (Object)null)
		{
			Magazine.UsesOverrideInOut = true;
			Magazine.ProfileOverride = EmptyProfile;
		}
		else
		{
			Magazine.UsesOverrideInOut = _originalUsesOverrideInOut;
			Magazine.ProfileOverride = _originalProfileOverride;
		}
	}
}
public class BoltReleaseChargingHandle : MonoBehaviour
{
	public ClosedBoltWeapon Weapon;

	public ClosedBoltHandle Handle;

	public float LaunchSpeed = 5f;

	[Tooltip("If true, the handle stays at Rear until bolt release is pressed again. If false, it returns forward when pulled back manually.")]
	public bool HandleReturnsManually = false;

	private bool m_wasLocked;

	private void Start()
	{
		if ((Object)(object)Weapon == (Object)null || (Object)(object)Handle == (Object)null)
		{
			Debug.LogWarning((object)"[BoltReleaseChargingHandle] Weapon or Handle reference is missing.", (Object)(object)this);
			((Behaviour)this).enabled = false;
		}
		else
		{
			m_wasLocked = Weapon.Bolt.IsBoltLocked();
		}
	}

	private void Update()
	{
		//IL_005f: 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_0040: Invalid comparison between Unknown and I4
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Invalid comparison between Unknown and I4
		bool flag = Weapon.Bolt.IsBoltLocked();
		if (m_wasLocked && !flag && Weapon.HasBoltReleaseButton && (int)Handle.CurPos == 4)
		{
			Handle.Speed_Forward = LaunchSpeed;
		}
		if ((int)Handle.CurPos == 0 && Handle.Speed_Forward > 0f)
		{
			Handle.Speed_Forward = 0f;
		}
		if (!HandleReturnsManually && !flag && !((FVRInteractiveObject)Handle).IsHeld && (int)Handle.CurPos == 4 && Handle.Speed_Forward == 0f)
		{
			Handle.Speed_Forward = LaunchSpeed;
		}
		m_wasLocked = 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;
		}
	}
}
public class RPMCalculator : MonoBehaviour
{
	[Header("Assign only one bugee here")]
	public ClosedBolt ClosedBolt;

	public OpenBoltReceiverBolt OpenBolt;

	public HandgunSlide HandgunSlide;

	[Header("Simulation Settings (Don't touch this bugee unless you know how physics in Unity works)")]
	public float SimStepSize = 0.0005f;

	public int MaxSimSteps = 100000;

	[Header("Forward Calculator - Results")]
	public float Result_RPM;

	public float Result_CycleTimeMS;

	public float Result_RearwardTimeMS;

	public float Result_ForwardTimeMS;

	[Header("Reverse Calculator - Inputs")]
	[Tooltip("The RPM you want the weapon to fire at.")]
	public float Reverse_DesiredRPM = 600f;

	[Tooltip("What percentage of the cycle the bolt spends travelling rearward. Remainder is the forward (spring) stroke. Typical range: 20 to 50.")]
	[Range(1f, 99f)]
	public float Reverse_RearwardSplitPercent = 35f;

	[Tooltip("The maximum forward speed the spring drives the bolt toward. Pin this to a value that feels right for the weapon, the script will solve SpringStiffness to match.")]
	public float Reverse_DesiredSpeedForward = 10f;

	[Header("Reverse Calculator - Results")]
	public float Reverse_Result_SpeedForward;

	public float Reverse_Result_SpeedRearward;

	public float Reverse_Result_SpringStiffness;

	private float m_zForward;

	private float m_zRear;

	private float m_speedRearward;

	private float m_speedForward;

	private float m_springStiffness;

	[ContextMenu("Calculate RPM")]
	public void Calculate()
	{
		if (TryReadFields() && ValidateFields() && SimulateRearward(m_speedRearward, out var rearwardTime) && SimulateForward(m_speedForward, m_springStiffness, out var forwardTime))
		{
			float num = rearwardTime + forwardTime;
			Result_RearwardTimeMS = rearwardTime * 1000f;
			Result_ForwardTimeMS = forwardTime * 1000f;
			Result_CycleTimeMS = num * 1000f;
			Result_RPM = 60f / num;
			Debug.Log((object)("[RPMCalculator] RPM: " + Result_RPM.ToString("F0") + " | Cycle: " + Result_CycleTimeMS.ToString("F2") + "ms | Rearward: " + Result_RearwardTimeMS.ToString("F2") + "ms | Forward: " + Result_ForwardTimeMS.ToString("F2") + "ms"));
		}
	}

	[ContextMenu("Reverse Calculate this evil bugee ")]
	public void ReverseCalculate()
	{
		if (!TryReadFields())
		{
			return;
		}
		if (Reverse_DesiredRPM <= 0f)
		{
			Debug.LogError((object)"[RPMCalculator] Reverse_DesiredRPM must be greater than 0.");
			return;
		}
		if (Reverse_DesiredSpeedForward <= 0f)
		{
			Debug.LogError((object)"[RPMCalculator] Reverse_DesiredSpeedForward must be greater than 0.");
			return;
		}
		if (Mathf.Approximately(m_zForward, m_zRear))
		{
			Debug.LogError((object)"[RPMCalculator] Forward and Rear positions are the same. No travel distance to simulate.");
			return;
		}
		float num = 60f / Reverse_DesiredRPM;
		float num2 = num * (Reverse_RearwardSplitPercent / 100f);
		float targetForwardTime = num * (1f - Reverse_RearwardSplitPercent / 100f);
		float num3 = Mathf.Abs(m_zForward - m_zRear);
		float reverse_Result_SpeedRearward = 0f - num3 / num2;
		if (!SolveSpringStiffness(targetForwardTime, Reverse_DesiredSpeedForward, out var result))
		{
			Debug.LogError((object)"[RPMCalculator] Could not solve SpringStiffness. Try increasing Reverse_DesiredSpeedForward or lowering Reverse_DesiredRPM \ufffd the bolt may not be physically able to cross the travel distance in the time available.");
			return;
		}
		Reverse_Result_SpeedRearward = reverse_Result_SpeedRearward;
		Reverse_Result_SpeedForward = Reverse_DesiredSpeedForward;
		Reverse_Result_SpringStiffness = result;
		Debug.Log((object)("[RPMCalculator] Reverse Result for " + Reverse_DesiredRPM.ToString("F0") + " RPM: | Speed_Rearward: " + reverse_Result_SpeedRearward.ToString("F4") + " | Speed_Forward: " + Reverse_DesiredSpeedForward.ToString("F4") + " | SpringStiffness: " + result.ToString("F4")));
	}

	private bool SolveSpringStiffness(float targetForwardTime, float speedForward, out float result)
	{
		result = 0f;
		float num = Mathf.Abs(m_zForward - m_zRear) / speedForward;
		if (targetForwardTime < num)
		{
			return false;
		}
		float num2 = 0.001f;
		float num3 = 10000f;
		for (int i = 0; i < 64; i++)
		{
			float num4 = (num2 + num3) * 0.5f;
			SimulateForward(speedForward, num4, out var forwardTime);
			if (forwardTime > targetForwardTime)
			{
				num2 = num4;
			}
			else
			{
				num3 = num4;
			}
		}
		result = (num2 + num3) * 0.5f;
		return true;
	}

	private bool SimulateRearward(float speedRearward, out float rearwardTime)
	{
		rearwardTime = 0f;
		float num = m_zForward;
		int num2 = 0;
		while (num > m_zRear && num2 < MaxSimSteps)
		{
			num += speedRearward * SimStepSize;
			num = Mathf.Max(num, m_zRear);
			rearwardTime += SimStepSize;
			num2++;
		}
		if (num2 >= MaxSimSteps)
		{
			Debug.LogError((object)"[RPMCalculator] Hit max steps on rearward stroke.");
			return false;
		}
		return true;
	}

	private bool SimulateForward(float speedForward, float springStiffness, out float forwardTime)
	{
		forwardTime = 0f;
		float num = m_zRear;
		float num2 = 0f;
		int num3 = 0;
		while (num < m_zForward && num3 < MaxSimSteps)
		{
			num2 = Mathf.MoveTowards(num2, speedForward, SimStepSize * springStiffness);
			num += num2 * SimStepSize;
			num = Mathf.Min(num, m_zForward);
			forwardTime += SimStepSize;
			num3++;
		}
		if (num3 >= MaxSimSteps)
		{
			forwardTime = float.MaxValue;
			return false;
		}
		return true;
	}

	private bool TryReadFields()
	{
		//IL_00cf: 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_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_024a: 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_0269: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: 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_01b3: 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)
		int num = 0;
		if ((Object)(object)ClosedBolt != (Object)null)
		{
			num++;
		}
		if ((Object)(object)OpenBolt != (Object)null)
		{
			num++;
		}
		if ((Object)(object)HandgunSlide != (Object)null)
		{
			num++;
		}
		if (num == 0)
		{
			Debug.LogError((object)"[RPMCalculator] No component assigned.");
			return false;
		}
		if (num > 1)
		{
			Debug.LogError((object)"[RPMCalculator] More than one component assigned. Only assign one at a time.");
			return false;
		}
		if ((Object)(object)ClosedBolt != (Object)null)
		{
			if ((Object)(object)ClosedBolt.Point_Bolt_Forward == (Object)null || (Object)(object)ClosedBolt.Point_Bolt_Rear == (Object)null)
			{
				Debug.LogError((object)"[RPMCalculator] ClosedBolt is missing Point_Bolt_Forward or Point_Bolt_Rear.");
				return false;
			}
			m_zForward = ClosedBolt.Point_Bolt_Forward.localPosition.z;
			m_zRear = ClosedBolt.Point_Bolt_Rear.localPosition.z;
			m_speedRearward = ClosedBolt.Speed_Rearward;
			m_speedForward = ClosedBolt.Speed_Forward;
			m_springStiffness = ClosedBolt.SpringStiffness;
		}
		else if ((Object)(object)OpenBolt != (Object)null)
		{
			if ((Object)(object)OpenBolt.Point_Bolt_Forward == (Object)null || (Object)(object)OpenBolt.Point_Bolt_Rear == (Object)null)
			{
				Debug.LogError((object)"[RPMCalculator] OpenBoltReceiverBolt is missing Point_Bolt_Forward or Point_Bolt_Rear.");
				return false;
			}
			m_zForward = OpenBolt.Point_Bolt_Forward.localPosition.z;
			m_zRear = OpenBolt.Point_Bolt_Rear.localPosition.z;
			m_speedRearward = OpenBolt.BoltSpeed_Rearward;
			m_speedForward = OpenBolt.BoltSpeed_Forward;
			m_springStiffness = OpenBolt.BoltSpringStiffness;
		}
		else
		{
			if ((Object)(object)HandgunSlide.Point_Slide_Forward == (Object)null || (Object)(object)HandgunSlide.Point_Slide_Rear == (Object)null)
			{
				Debug.LogError((object)"[RPMCalculator] HandgunSlide is missing Point_Slide_Forward or Point_Slide_Rear.");
				return false;
			}
			m_zForward = HandgunSlide.Point_Slide_Forward.localPosition.z;
			m_zRear = HandgunSlide.Point_Slide_Rear.localPosition.z;
			m_speedRearward = HandgunSlide.Speed_Rearward;
			m_speedForward = HandgunSlide.Speed_Forward;
			m_springStiffness = HandgunSlide.SpringStiffness;
		}
		return true;
	}

	private bool ValidateFields()
	{
		if (Mathf.Approximately(m_zForward, m_zRear))
		{
			Debug.LogError((object)"[RPMCalculator] Forward and Rear positions are the same.");
			return false;
		}
		if (m_speedRearward >= 0f)
		{
			Debug.LogError((object)("[RPMCalculator] Rearward speed should be negative. Current value: " + m_speedRearward));
			return false;
		}
		if (m_speedForward <= 0f)
		{
			Debug.LogError((object)("[RPMCalculator] Forward speed must be greater than 0. Current value: " + m_speedForward));
			return false;
		}
		if (m_springStiffness <= 0f)
		{
			Debug.LogError((object)("[RPMCalculator] SpringStiffness must be greater than 0. Current value: " + m_springStiffness));
			return false;
		}
		return true;
	}
}
public class SecondaryMagPos : MonoBehaviour
{
	[Header("References")]
	public FVRFireArm FireArm;

	public FVRFireArmReloadTriggerWell TriggerWell;

	[Header("Mount Override")]
	public Transform MountPos;

	public Transform EjectPos;

	private Transform m_defaultMountPos;

	private Transform m_defaultEjectPos;

	private Vector3 m_defaultMountLocalPos;

	private Quaternion m_defaultMountLocalRot;

	private Vector3 m_defaultEjectLocalPos;

	private Quaternion m_defaultEjectLocalRot;

	private bool m_initialized = false;

	private bool m_overrideActive = false;

	private FVRFireArmMagazine m_pendingMag;

	private int m_pendingStableFrames;

	private const int kStableFramesRequired = 2;

	private FVRFireArmMagazine m_appliedMag;

	private void Start()
	{
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: 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)
		if ((Object)(object)FireArm == (Object)null || (Object)(object)TriggerWell == (Object)null)
		{
			((Behaviour)this).enabled = false;
			return;
		}
		if ((Object)(object)MountPos == (Object)null)
		{
			((Behaviour)this).enabled = false;
			return;
		}
		m_defaultMountPos = FireArm.MagazineMountPos;
		m_defaultEjectPos = FireArm.MagazineEjectPos;
		if ((Object)(object)m_defaultMountPos == (Object)null)
		{
			((Behaviour)this).enabled = false;
			return;
		}
		m_defaultMountLocalPos = m_defaultMountPos.localPosition;
		m_defaultMountLocalRot = m_defaultMountPos.localRotation;
		if ((Object)(object)m_defaultEjectPos != (Object)null)
		{
			m_defaultEjectLocalPos = m_defaultEjectPos.localPosition;
			m_defaultEjectLocalRot = m_defaultEjectPos.localRotation;
		}
		m_initialized = true;
		m_pendingMag = null;
		m_pendingStableFrames = 0;
		m_appliedMag = null;
	}

	private void Update()
	{
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		if (!m_initialized)
		{
			return;
		}
		FVRFireArmMagazine magazine = FireArm.Magazine;
		if ((Object)(object)magazine == (Object)(object)m_pendingMag)
		{
			if (m_pendingStableFrames < 2)
			{
				m_pendingStableFrames++;
			}
		}
		else
		{
			m_pendingMag = magazine;
			m_pendingStableFrames = 0;
		}
		if (m_pendingStableFrames < 2 || (Object)(object)m_pendingMag == (Object)(object)m_appliedMag)
		{
			return;
		}
		FireArmMagazineType val = ((!TriggerWell.UsesTypeOverride) ? FireArm.MagazineType : TriggerWell.TypeOverride);
		if ((Object)(object)m_pendingMag != (Object)null && m_pendingMag.MagazineType == val)
		{
			m_overrideActive = true;
			m_appliedMag = m_pendingMag;
			return;
		}
		if (m_overrideActive)
		{
			m_overrideActive = false;
			RestoreDefaults();
		}
		m_appliedMag = null;
	}

	private void LateUpdate()
	{
		//IL_0028: 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_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		if (m_initialized && m_overrideActive)
		{
			m_defaultMountPos.position = MountPos.position;
			m_defaultMountPos.rotation = MountPos.rotation;
			if ((Object)(object)m_defaultEjectPos != (Object)null && (Object)(object)EjectPos != (Object)null)
			{
				m_defaultEjectPos.position = EjectPos.position;
				m_defaultEjectPos.rotation = EjectPos.rotation;
			}
		}
	}

	private void RestoreDefaults()
	{
		//IL_0008: 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_003c: 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)
		m_defaultMountPos.localPosition = m_defaultMountLocalPos;
		m_defaultMountPos.localRotation = m_defaultMountLocalRot;
		if ((Object)(object)m_defaultEjectPos != (Object)null)
		{
			m_defaultEjectPos.localPosition = m_defaultEjectLocalPos;
			m_defaultEjectPos.localRotation = m_defaultEjectLocalRot;
		}
	}

	private void OnDisable()
	{
		if (m_initialized)
		{
			RestoreDefaults();
		}
	}

	private void OnDestroy()
	{
		if (m_initialized)
		{
			RestoreDefaults();
		}
	}
}
public class SimpleCompass : MonoBehaviour
{
	[Header("Target")]
	[Tooltip("Assign Forward Z for North Facing, I think.")]
	public Transform Target;

	[Header("Text Version")]
	public Text CompassText;

	[Header("Image Version")]
	[Tooltip("The arrow that will be rotated to indicate which direction.")]
	public RectTransform CompassImage;

	private void Update()
	{
		//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_00d4: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)Target == (Object)null))
		{
			Vector3 forward = Target.forward;
			forward.y = 0f;
			((Vector3)(ref forward)).Normalize();
			float num = Mathf.Atan2(forward.x, forward.z) * 57.29578f;
			if (num < 0f)
			{
				num += 360f;
			}
			if ((Object)(object)CompassText != (Object)null)
			{
				CompassText.text = GetCardinalLabel(num) + " " + Mathf.RoundToInt(num) + "°";
			}
			if ((Object)(object)CompassImage != (Object)null)
			{
				((Transform)CompassImage).localEulerAngles = new Vector3(0f, 0f, num);
			}
		}
	}

	private string GetCardinalLabel(float angle)
	{
		if (angle < 22.5f || angle >= 337.5f)
		{
			return "N";
		}
		if (angle < 67.5f)
		{
			return "NE";
		}
		if (angle < 112.5f)
		{
			return "E";
		}
		if (angle < 157.5f)
		{
			return "SE";
		}
		if (angle < 202.5f)
		{
			return "S";
		}
		if (angle < 247.5f)
		{
			return "SW";
		}
		if (angle < 292.5f)
		{
			return "W";
		}
		return "NW";
	}
}
public class InvertClosedBolt : MonoBehaviour
{
	public Transform OptionalLockPointOverride;

	private void Start()
	{
		//IL_00ab: 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)
		ClosedBolt component = ((Component)this).GetComponent<ClosedBolt>();
		if ((Object)(object)component == (Object)null)
		{
			Debug.LogWarning((object)"[InvertClosedBolt] No ClosedBolt component found on this GameObject.");
			return;
		}
		Transform point_Bolt_Forward = component.Point_Bolt_Forward;
		component.Point_Bolt_Forward = component.Point_Bolt_Rear;
		component.Point_Bolt_Rear = point_Bolt_Forward;
		if ((Object)(object)OptionalLockPointOverride != (Object)null)
		{
			component.Point_Bolt_LockPoint = OptionalLockPointOverride;
		}
		SetPrivateFloat(component, "m_boltZ_forward", LocalZ(component.Point_Bolt_Forward));
		SetPrivateFloat(component, "m_boltZ_rear", LocalZ(component.Point_Bolt_Rear));
		SetPrivateFloat(component, "m_boltZ_lock", LocalZ(component.Point_Bolt_LockPoint));
		SetPrivateFloat(component, "m_boltZ_current", ((Component)component).transform.localPosition.z);
		if (component.UsesAKSafetyLock && (Object)(object)component.Point_Bolt_SafetyLock != (Object)null)
		{
			SetPrivateFloat(component, "m_boltZ_safetylock", LocalZ(component.Point_Bolt_SafetyLock));
		}
		component.SnapToRear();
		component.UpdateBolt();
	}

	private static float LocalZ(Transform t)
	{
		//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)
		return (!((Object)(object)t != (Object)null)) ? 0f : t.localPosition.z;
	}

	private static void SetPrivateFloat(ClosedBolt cb, string name, float value)
	{
		typeof(ClosedBolt).GetField(name, BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(cb, value);
	}
}
public class FlickerRedDot : MonoBehaviour
{
	[Header("Controller Reference")]
	[Tooltip("The main ReflexSightController on this attachment.")]
	public ReflexSightController SightController;

	[Header("Flicker Configuration")]
	[Tooltip("How fast the reticle brightness oscillates/flickers. Higher values mean faster flicker.")]
	public float FlickerSpeed = 30f;

	[Range(0f, 1f)]
	[Tooltip("The minimum brightness multiplier during a flicker (e.g. 0.5 = dips to 50% of current brightness).")]
	public float MinBrightnessFactor = 0.5f;

	[Range(0f, 1f)]
	[Tooltip("The maximum brightness multiplier during a flicker (e.g. 1.0 = reaches 100% of current brightness).")]
	public float MaxBrightnessFactor = 1f;

	[Tooltip("If true, uses Perlin Noise for organic LED fluctuations. If false, uses a steady Sine wave.")]
	public bool UseRandomNoise = true;

	private MaterialPropertyBlock m_propBlock;

	private float m_noiseOffset;

	private void Start()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		if ((Object)(object)SightController == (Object)null)
		{
			SightController = ((Component)this).GetComponent<ReflexSightController>();
		}
		m_propBlock = new MaterialPropertyBlock();
		m_noiseOffset = Random.Range(0f, 1000f);
	}

	private void LateUpdate()
	{
		if ((Object)(object)SightController == (Object)null || SightController.ReflexSightRenderers == null || SightController.ReflexSightRenderers.Count == 0)
		{
			return;
		}
		float num = 0f;
		num = ((!UseRandomNoise) ? ((Mathf.Sin(Time.time * FlickerSpeed) + 1f) * 0.5f) : Mathf.PerlinNoise(Time.time * FlickerSpeed + m_noiseOffset, 0f));
		float num2 = Mathf.Lerp(MinBrightnessFactor, MaxBrightnessFactor, num);
		for (int i = 0; i < SightController.ReflexSightRenderers.Count; i++)
		{
			Renderer val = SightController.ReflexSightRenderers[i];
			if (!((Object)(object)val == (Object)null))
			{
				val.GetPropertyBlock(m_propBlock);
				float num3 = 1f;
				if (SightController.ReticleIlluminations != null && SightController.ReticleIlluminations.Count > 0)
				{
					int index = Mathf.Clamp(SightController.ReticleIlluminationIndex, 0, SightController.ReticleIlluminations.Count - 1);
					num3 = SightController.ReticleIlluminations[index];
				}
				m_propBlock.SetFloat("_ReticleIntensity", num3 * num2);
				val.SetPropertyBlock(m_propBlock);
			}
		}
	}
}
public class MagazineStock : MonoBehaviour
{
	[Header("References")]
	public FVRFireArm Weapon;

	public int SecondarySlotIndex = 0;

	public Transform Point_Stock;

	[Header("Objects to disable when stocked")]
	public GameObject[] ObjectsToDisableWhenStocked;

	private bool _wasStocked;

	private void Update()
	{
		SecondaryMagazineSlot val = Weapon.SecondaryMagazineSlots[SecondarySlotIndex];
		if ((Object)(object)val.Magazine != (Object)null && (Object)(object)((FVRInteractiveObject)val.Magazine).m_hand != (Object)null)
		{
			Weapon.EjectSecondaryMagFromSlot(SecondarySlotIndex, true);
		}
		bool flag = (Object)(object)val.Magazine != (Object)null;
		if (flag == _wasStocked)
		{
			return;
		}
		_wasStocked = flag;
		if (flag)
		{
			Weapon.StockPos = Point_Stock;
			Weapon.HasActiveShoulderStock = true;
		}
		else
		{
			Weapon.StockPos = null;
			Weapon.HasActiveShoulderStock = false;
		}
		for (int i = 0; i < ObjectsToDisableWhenStocked.Length; i++)
		{
			if ((Object)(object)ObjectsToDisableWhenStocked[i] != (Object)null)
			{
				ObjectsToDisableWhenStocked[i].SetActive(!flag);
			}
		}
	}
}
public class RifleToggleLock : MonoBehaviour
{
	public ClosedBolt ClosedBolt;

	public Transform BarrelSlide;

	public Transform BarrelSlideForward;

	public Transform BarrelSlideLockPoint;

	public Transform TogglePiece1;

	public Transform TogglePiece2;

	public Transform TogglePiece3;

	public Vector2 RotSet1 = new Vector2(0f, -86f);

	public Vector2 RotSet2 = new Vector2(0f, 132.864f);

	public Vector2 PosSet1 = new Vector2(0.02199817f, -0.02124f);

	public float Height = 0.03527606f;

	[Header("Motion Curves")]
	[Tooltip("Drives BarrelSlide and TogglePiece1.")]
	public AnimationCurve MotionCurve = AnimationCurve.Linear(0f, 0f, 1f, 1f);

	[Tooltip("Drives TogglePiece2 independently.")]
	public AnimationCurve MotionCurvePiece2 = AnimationCurve.Linear(0f, 0f, 1f, 1f);

	[Tooltip("Drives TogglePiece3 independently.")]
	public AnimationCurve MotionCurvePiece3 = AnimationCurve.Linear(0f, 0f, 1f, 1f);

	[Header("Debug")]
	public bool DebugOverride = false;

	[Range(0f, 1f)]
	public float DebugLerp = 0f;

	private void Update()
	{
		//IL_005d: 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_006e: 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_0100: 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)
		float num = ((!DebugOverride) ? (1f - ClosedBolt.GetBoltLerpBetweenRearAndFore()) : DebugLerp);
		float num2 = MotionCurve.Evaluate(num);
		float num3 = MotionCurvePiece2.Evaluate(num);
		float num4 = MotionCurvePiece3.Evaluate(num);
		BarrelSlide.localPosition = Vector3.Lerp(BarrelSlideForward.localPosition, BarrelSlideLockPoint.localPosition, num2);
		float num5 = Mathf.Lerp(RotSet1.x, RotSet1.y, num2);
		float num6 = Mathf.Lerp(RotSet2.x, RotSet2.y, num3);
		float num7 = Mathf.Lerp(PosSet1.x, PosSet1.y, num4);
		TogglePiece1.localEulerAngles = new Vector3(num5, 0f, 0f);
		TogglePiece2.localEulerAngles = new Vector3(num6, 0f, 0f);
		TogglePiece3.localPosition = new Vector3(0f, Height, num7);
	}
}
internal class AutoReleaseOnMagLoad : MonoBehaviour
{
	private FVRFireArm weapon;

	private Handgun handgun;

	private bool wasLoaded;

	public void Start()
	{
		weapon = ((Component)this).GetComponent<FVRFireArm>();
		if (!((Object)(object)weapon == (Ob