Decompiled source of ModularWorkshop v1.2.1

plugins/ModularWorkshop.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using OpenScripts2;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ModularWorkshop")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ModularWorkshop")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5d76fa8f-3383-4c98-9454-78def5a1249a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ModularWorkshop
{
	public class ModularLeverActionFirearm : LeverActionFirearm, IModularWeapon
	{
		[Header("Modular Configuration")]
		public ModularFVRFireArm ModularFVRFireArm;

		public GameObject UIPrefab => ModularFVRFireArm.UIPrefab;

		public string ModularBarrelPartsID => ModularFVRFireArm.ModularBarrelAttachmentPoint.ModularPartsGroupID;

		public Transform ModularBarrelPoint => ModularFVRFireArm.ModularBarrelAttachmentPoint.ModularPartPoint;

		public TransformProxy ModularBarrelUIPointProxy => ModularFVRFireArm.ModularBarrelAttachmentPoint.ModularPartUIPointProxy;

		public Dictionary<string, GameObject> ModularBarrelPrefabsDictionary => ModularFVRFireArm.ModularBarrelPrefabsDictionary;

		public string ModularHandguardPartsID => ModularFVRFireArm.ModularHandguardAttachmentPoint.ModularPartsGroupID;

		public Transform ModularHandguardPoint => ModularFVRFireArm.ModularHandguardAttachmentPoint.ModularPartPoint;

		public TransformProxy ModularHandguardUIPointProxy => ModularFVRFireArm.ModularHandguardAttachmentPoint.ModularPartUIPointProxy;

		public Dictionary<string, GameObject> ModularHandguardPrefabsDictionary => ModularFVRFireArm.ModularHandguardPrefabsDictionary;

		public string ModularStockPartsID => ModularFVRFireArm.ModularStockAttachmentPoint.ModularPartsGroupID;

		public Transform ModularStockPoint => ModularFVRFireArm.ModularStockAttachmentPoint.ModularPartPoint;

		public TransformProxy ModularStockUIPointProxy => ModularFVRFireArm.ModularStockAttachmentPoint.ModularPartUIPointProxy;

		public Dictionary<string, GameObject> ModularStockPrefabsDictionary => ModularFVRFireArm.ModularStockPrefabsDictionary;

		public string SelectedModularBarrel => ModularFVRFireArm.ModularBarrelAttachmentPoint.SelectedModularWeaponPart;

		public string SelectedModularHandguard => ModularFVRFireArm.ModularHandguardAttachmentPoint.SelectedModularWeaponPart;

		public string SelectedModularStock => ModularFVRFireArm.ModularStockAttachmentPoint.SelectedModularWeaponPart;

		public ModularWeaponPartsAttachmentPoint[] ModularWeaponPartsAttachmentPoints => ModularFVRFireArm.ModularWeaponPartsAttachmentPoints;

		public ModularWorkshopPlatform WorkshopPlatform
		{
			get
			{
				return ModularFVRFireArm.WorkshopPlatform;
			}
			set
			{
				ModularFVRFireArm.WorkshopPlatform = value;
			}
		}

		public List<ModularWeaponPartsAttachmentPoint> SubAttachmentPoints => ModularFVRFireArm.SubAttachmentPoints;

		public ModularFVRFireArm GetModularFVRFireArm => ModularFVRFireArm;

		public Dictionary<string, ModularWeaponPartsAttachmentPoint> AllAttachmentPoints => ModularFVRFireArm.AllAttachmentPoints;

		public override void Awake()
		{
			((LeverActionFirearm)this).Awake();
			ConvertTransformsToProxies();
			ModularFVRFireArm.Awake((FVRFireArm)(object)this);
			ConfigureAll();
		}

		public override void ConfigureFromFlagDic(Dictionary<string, string> f)
		{
			((FVRFireArm)this).ConfigureFromFlagDic(f);
			ModularFVRFireArm.ConfigureFromFlagDic(f, (FVRFireArm)(object)this);
		}

		public override Dictionary<string, string> GetFlagDic()
		{
			Dictionary<string, string> flagDic = ((FVRFireArm)this).GetFlagDic();
			return ModularFVRFireArm.GetFlagDic(flagDic);
		}

		public ModularWeaponPart ConfigureModularWeaponPart(ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint, string selectedPart, bool isRandomized = false)
		{
			return ModularFVRFireArm.ConfigureModularWeaponPart(modularWeaponPartsAttachmentPoint, selectedPart, isRandomized);
		}

		public ModularBarrel ConfigureModularBarrel(string selectedPart, bool isRandomized = false)
		{
			return ModularFVRFireArm.ConfigureModularBarrel(selectedPart, isRandomized);
		}

		public ModularHandguard ConfigureModularHandguard(string selectedPart, bool isRandomized = false)
		{
			return ModularFVRFireArm.ConfigureModularHandguard(selectedPart, isRandomized);
		}

		public ModularStock ConfigureModularStock(string selectedPart, bool isRandomized = false)
		{
			return ModularFVRFireArm.ConfigureModularStock(selectedPart, isRandomized);
		}

		public void ConfigureAll()
		{
			if (ModularBarrelPartsID != string.Empty)
			{
				string selectedPart = ((ModularFVRFireArm.IsInTakeAndHold && !ModularFVRFireArm.WasUnvaulted && !ModularFVRFireArm.ModularBarrelAttachmentPoint.DisallowTakeAndHoldRandomization) ? ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary[ModularBarrelPartsID].GetRandomPart() : SelectedModularBarrel);
				ConfigureModularBarrel(selectedPart);
			}
			if (ModularHandguardPartsID != string.Empty)
			{
				string selectedPart = ((ModularFVRFireArm.IsInTakeAndHold && !ModularFVRFireArm.WasUnvaulted && !ModularFVRFireArm.ModularHandguardAttachmentPoint.DisallowTakeAndHoldRandomization) ? ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary[ModularHandguardPartsID].GetRandomPart() : SelectedModularHandguard);
				ConfigureModularHandguard(selectedPart);
			}
			if (ModularStockPartsID != string.Empty)
			{
				string selectedPart = ((ModularFVRFireArm.IsInTakeAndHold && !ModularFVRFireArm.WasUnvaulted && !ModularFVRFireArm.ModularStockAttachmentPoint.DisallowTakeAndHoldRandomization) ? ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary[ModularStockPartsID].GetRandomPart() : SelectedModularStock);
				ConfigureModularStock(selectedPart);
			}
			ModularWeaponPartsAttachmentPoint[] modularWeaponPartsAttachmentPoints = ModularFVRFireArm.ModularWeaponPartsAttachmentPoints;
			foreach (ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint in modularWeaponPartsAttachmentPoints)
			{
				if (!modularWeaponPartsAttachmentPoint.IsPointDisabled && ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary.TryGetValue(modularWeaponPartsAttachmentPoint.ModularPartsGroupID, out var value) && value.PartsDictionary.Count > 0)
				{
					string selectedPart = ((ModularFVRFireArm.IsInTakeAndHold && !ModularFVRFireArm.WasUnvaulted && !modularWeaponPartsAttachmentPoint.DisallowTakeAndHoldRandomization) ? ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary[modularWeaponPartsAttachmentPoint.ModularPartsGroupID].GetRandomPart() : modularWeaponPartsAttachmentPoint.SelectedModularWeaponPart);
					ConfigureModularWeaponPart(modularWeaponPartsAttachmentPoint, selectedPart, ModularFVRFireArm.IsInTakeAndHold);
				}
			}
		}

		public void ConvertTransformsToProxies()
		{
			ModularFVRFireArm.ConvertTransformsToProxies((FVRFireArm)(object)this);
		}

		public void ApplySkin(string ModularPartsGroupID, string SkinName)
		{
			AllAttachmentPoints[ModularPartsGroupID].ApplySkin(SkinName);
		}

		[ContextMenu("Copy Existing Firearm Component")]
		public void CopyFirearm()
		{
			LeverActionFirearm val = ((Component)this).GetComponents<LeverActionFirearm>().Single((LeverActionFirearm c) => (Object)(object)c != (Object)(object)this);
			if ((Object)(object)val.Chamber != (Object)null)
			{
				val.Chamber.Firearm = (FVRFireArm)(object)this;
			}
			if ((Object)(object)val.Chamber2 != (Object)null)
			{
				val.Chamber2.Firearm = (FVRFireArm)(object)this;
			}
			if ((Object)(object)((FVRFireArm)val).Foregrip != (Object)null)
			{
				((FVRFireArm)val).Foregrip.GetComponent<FVRAlternateGrip>().PrimaryObject = (FVRPhysicalObject)(object)this;
			}
			UniversalMagGrabTrigger componentInChildren = ((Component)val).GetComponentInChildren<UniversalMagGrabTrigger>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.FireArm = (FVRFireArm)(object)this;
			}
			FVRFireArmReloadTriggerWell componentInChildren2 = ((Component)val).GetComponentInChildren<FVRFireArmReloadTriggerWell>();
			if ((Object)(object)componentInChildren2 != (Object)null)
			{
				componentInChildren2.FireArm = (FVRFireArm)(object)this;
			}
			LeverActionTubeACtion componentInChildren3 = ((Component)val).GetComponentInChildren<LeverActionTubeACtion>();
			if ((Object)(object)componentInChildren3 != (Object)null)
			{
				componentInChildren3.FA = (FVRFireArm)(object)this;
			}
			foreach (FVRFireArmAttachmentMount attachmentMount in ((FVRPhysicalObject)val).AttachmentMounts)
			{
				attachmentMount.MyObject = (FVRPhysicalObject)(object)this;
				attachmentMount.Parent = (FVRPhysicalObject)(object)this;
			}
			UniversalCopy.CopyComponent<LeverActionFirearm>((Component)(object)this, val);
		}

		[ContextMenu("Populate Receiver Mesh Renderer List")]
		public void PopulateReceiverMeshList()
		{
			ModularFVRFireArm.GetReceiverMeshRenderers((FVRFireArm)(object)this);
		}
	}
	[RequireComponent(typeof(ModularWeaponPart))]
	public class NonReciprocatingSlideHandleAddon : MonoBehaviour, IPartFireArmRequirement
	{
		private enum EColliderType
		{
			Sphere,
			Capsule,
			Box
		}

		public Transform SlideHandle;

		public float ForwardPos;

		public float RearwardPos;

		private HandgunSlide _slide;

		private bool _wasSlideGrabbed;

		private float _slideHandleSpeed;

		private float _curZPos;

		private float _lastSlidePosZ;

		public GameObject ColliderReference;

		private TransformProxy _colliderReferenceProxy;

		public bool ReplaceExistingCollider;

		private FVRFireArm _firearm;

		private Collider _origCollider;

		private Collider _addedCollider;

		private Vector3 _addedColliderCenter;

		private Vector3 _addedColliderSize;

		private EColliderType _addedColliderType;

		private Axis _addedColliderAxis;

		public FVRFireArm FireArm
		{
			set
			{
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0070: Unknown result type (might be due to invalid IL or missing references)
				//IL_007b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0136: Unknown result type (might be due to invalid IL or missing references)
				//IL_017e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0188: Expected I4, but got Unknown
				//IL_01a6: 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)
				if ((Object)(object)value != (Object)null)
				{
					Handgun val = (Handgun)(object)((value is Handgun) ? value : null);
					if (val != null)
					{
						_slide = val.Slide;
					}
				}
				if ((Object)(object)value != (Object)null)
				{
					_firearm = value;
					FVRFireArm firearm = _firearm;
					Handgun val2 = (Handgun)(object)((firearm is Handgun) ? firearm : null);
					Transform val3 = ((val2 == null) ? null : ((Component)val2.Slide).transform);
					Transform val4 = val3;
					Vector3 val5 = _colliderReferenceProxy.parent.TransformPoint(_colliderReferenceProxy.localPosition + UnityEngineExtensions.MultiplyComponentWise(_addedColliderCenter, _colliderReferenceProxy.localScale));
					Vector3 center = val4.InverseTransformPoint(val5);
					if (ReplaceExistingCollider)
					{
						_origCollider = ((Component)val4).GetComponent<Collider>();
						_origCollider.enabled = false;
					}
					switch (_addedColliderType)
					{
					case EColliderType.Sphere:
					{
						_addedCollider = (Collider)(object)((Component)val4).gameObject.AddComponent<SphereCollider>();
						Collider addedCollider7 = _addedCollider;
						((SphereCollider)((addedCollider7 is SphereCollider) ? addedCollider7 : null)).center = center;
						Collider addedCollider8 = _addedCollider;
						((SphereCollider)((addedCollider8 is SphereCollider) ? addedCollider8 : null)).radius = _addedColliderSize.x;
						break;
					}
					case EColliderType.Capsule:
					{
						_addedCollider = (Collider)(object)((Component)val4).gameObject.AddComponent<CapsuleCollider>();
						Collider addedCollider3 = _addedCollider;
						((CapsuleCollider)((addedCollider3 is CapsuleCollider) ? addedCollider3 : null)).center = center;
						Collider addedCollider4 = _addedCollider;
						((CapsuleCollider)((addedCollider4 is CapsuleCollider) ? addedCollider4 : null)).radius = _addedColliderSize.x;
						Collider addedCollider5 = _addedCollider;
						((CapsuleCollider)((addedCollider5 is CapsuleCollider) ? addedCollider5 : null)).height = _addedColliderSize.y;
						Collider addedCollider6 = _addedCollider;
						((CapsuleCollider)((addedCollider6 is CapsuleCollider) ? addedCollider6 : null)).direction = (int)_addedColliderAxis;
						break;
					}
					case EColliderType.Box:
					{
						_addedCollider = (Collider)(object)((Component)val4).gameObject.AddComponent<BoxCollider>();
						Collider addedCollider = _addedCollider;
						((BoxCollider)((addedCollider is BoxCollider) ? addedCollider : null)).center = center;
						Collider addedCollider2 = _addedCollider;
						((BoxCollider)((addedCollider2 is BoxCollider) ? addedCollider2 : null)).size = _addedColliderSize;
						break;
					}
					}
					_addedCollider.isTrigger = true;
				}
				else if ((Object)(object)value == (Object)null && (Object)(object)_firearm != (Object)null)
				{
					if (ReplaceExistingCollider)
					{
						_origCollider.enabled = true;
					}
					Object.Destroy((Object)(object)_addedCollider);
					_firearm = null;
				}
			}
		}

		private float GetSlideHandleLerpBetweenRearAndFore()
		{
			return Mathf.InverseLerp(RearwardPos, ForwardPos, _curZPos);
		}

		public void Awake()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ColliderReference != (Object)null)
			{
				_colliderReferenceProxy = new TransformProxy(ColliderReference.transform, false);
				Collider component = ColliderReference.GetComponent<Collider>();
				CapsuleCollider val = (CapsuleCollider)(object)((component is CapsuleCollider) ? component : null);
				if (val == null)
				{
					SphereCollider val2 = (SphereCollider)(object)((component is SphereCollider) ? component : null);
					if (val2 == null)
					{
						BoxCollider val3 = (BoxCollider)(object)((component is BoxCollider) ? component : null);
						if (val3 == null)
						{
							if (component == null)
							{
								ModularWorkshopManager.LogWarning((MonoBehaviour)(object)this, "ColliderReference " + ((Object)ColliderReference).name + " doesn't contain a collider you goofus! Shit's about to break!");
							}
						}
						else
						{
							_addedColliderCenter = val3.center;
							_addedColliderSize = val3.size;
							_addedColliderType = EColliderType.Box;
						}
					}
					else
					{
						_addedColliderCenter = val2.center;
						_addedColliderSize = new Vector3(val2.radius, 0f, 0f);
						_addedColliderType = EColliderType.Sphere;
					}
				}
				else
				{
					_addedColliderCenter = val.center;
					_addedColliderSize = new Vector3(val.radius, val.height, 0f);
					_addedColliderType = EColliderType.Capsule;
					_addedColliderAxis = (Axis)(val.direction switch
					{
						0 => 0, 
						1 => 1, 
						2 => 2, 
						_ => 0, 
					});
				}
				Object.Destroy((Object)(object)ColliderReference);
			}
			else if ((Object)(object)ColliderReference == (Object)null)
			{
				ModularWorkshopManager.LogError((MonoBehaviour)(object)this, "ColliderReference is empty but you want this to be a functional bolt grab point addon you goofus! Shit's about to break!");
			}
		}

		public void Update()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: 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_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_slide != (Object)null))
			{
				return;
			}
			float speed_Forward = _slide.Speed_Forward;
			float springStiffness = _slide.SpringStiffness;
			_curZPos = SlideHandle.localPosition.z;
			if (((FVRInteractiveObject)_slide).IsHeld)
			{
				_wasSlideGrabbed = true;
				_slideHandleSpeed = 0f;
				float slideLerpBetweenRearAndFore = _slide.GetSlideLerpBetweenRearAndFore();
				_curZPos = Mathf.Lerp(RearwardPos, ForwardPos, slideLerpBetweenRearAndFore);
				UnityEngineExtensions.ModifyLocalPositionAxisValue(SlideHandle, (Axis)2, _curZPos);
			}
			else if (!((FVRInteractiveObject)_slide).IsHeld && _wasSlideGrabbed)
			{
				_slideHandleSpeed = Mathf.MoveTowards(_slideHandleSpeed, speed_Forward, springStiffness * Time.deltaTime);
				_curZPos += _slideHandleSpeed * Time.deltaTime;
				_curZPos = Mathf.Clamp(_curZPos, RearwardPos, ForwardPos);
				UnityEngineExtensions.ModifyLocalPositionAxisValue(SlideHandle, (Axis)2, _curZPos);
				if (Mathf.Approximately(GetSlideHandleLerpBetweenRearAndFore(), 1f))
				{
					_slideHandleSpeed = 0f;
					_wasSlideGrabbed = false;
				}
				Vector3 val = _colliderReferenceProxy.parent.TransformPoint(_colliderReferenceProxy.localPosition + UnityEngineExtensions.MultiplyComponentWise(_addedColliderCenter, _colliderReferenceProxy.localScale));
				Vector3 center = ((Component)_slide).transform.InverseTransformPoint(val);
				switch (_addedColliderType)
				{
				case EColliderType.Sphere:
				{
					Collider addedCollider3 = _addedCollider;
					((SphereCollider)((addedCollider3 is SphereCollider) ? addedCollider3 : null)).center = center;
					break;
				}
				case EColliderType.Capsule:
				{
					Collider addedCollider2 = _addedCollider;
					((CapsuleCollider)((addedCollider2 is CapsuleCollider) ? addedCollider2 : null)).center = center;
					break;
				}
				case EColliderType.Box:
				{
					Collider addedCollider = _addedCollider;
					((BoxCollider)((addedCollider is BoxCollider) ? addedCollider : null)).center = center;
					break;
				}
				}
			}
			float slideZ_current = _slide.m_slideZ_current;
			if (slideZ_current != _lastSlidePosZ)
			{
				Vector3 val2 = _colliderReferenceProxy.parent.TransformPoint(_colliderReferenceProxy.localPosition + UnityEngineExtensions.MultiplyComponentWise(_addedColliderCenter, _colliderReferenceProxy.localScale));
				Vector3 center2 = ((Component)_slide).transform.InverseTransformPoint(val2);
				switch (_addedColliderType)
				{
				case EColliderType.Sphere:
				{
					Collider addedCollider6 = _addedCollider;
					((SphereCollider)((addedCollider6 is SphereCollider) ? addedCollider6 : null)).center = center2;
					break;
				}
				case EColliderType.Capsule:
				{
					Collider addedCollider5 = _addedCollider;
					((CapsuleCollider)((addedCollider5 is CapsuleCollider) ? addedCollider5 : null)).center = center2;
					break;
				}
				case EColliderType.Box:
				{
					Collider addedCollider4 = _addedCollider;
					((BoxCollider)((addedCollider4 is BoxCollider) ? addedCollider4 : null)).center = center2;
					break;
				}
				}
			}
			_lastSlidePosZ = slideZ_current;
		}
	}
	[RequireComponent(typeof(ModularWeaponPart))]
	public class BoltAndSlideInteractionVisualEffectAddon : MonoBehaviour, IPartFireArmRequirement
	{
		public InteractionVisualEffect InteractionVisualEffect;

		public FVRFireArm FireArm
		{
			set
			{
				if (!((Object)(object)value != (Object)null))
				{
					return;
				}
				Handgun val = (Handgun)(object)((value is Handgun) ? value : null);
				if (val == null)
				{
					ClosedBoltWeapon val2 = (ClosedBoltWeapon)(object)((value is ClosedBoltWeapon) ? value : null);
					if (val2 == null)
					{
						OpenBoltReceiver val3 = (OpenBoltReceiver)(object)((value is OpenBoltReceiver) ? value : null);
						if (val3 == null)
						{
							TubeFedShotgun val4 = (TubeFedShotgun)(object)((value is TubeFedShotgun) ? value : null);
							if (val4 == null)
							{
								BoltActionRifle val5 = (BoltActionRifle)(object)((value is BoltActionRifle) ? value : null);
								if (val5 != null)
								{
									InteractionVisualEffect.ObjectToMonitor = (FVRInteractiveObject)(object)val5.BoltHandle;
								}
							}
							else
							{
								InteractionVisualEffect.ObjectToMonitor = (FVRInteractiveObject)(object)val4.Bolt;
							}
						}
						else
						{
							InteractionVisualEffect.ObjectToMonitor = (FVRInteractiveObject)(object)val3.Bolt;
						}
					}
					else
					{
						InteractionVisualEffect.ObjectToMonitor = (FVRInteractiveObject)(object)val2.Bolt;
					}
				}
				else
				{
					InteractionVisualEffect.ObjectToMonitor = (FVRInteractiveObject)(object)val.Slide;
				}
			}
		}
	}
	[RequireComponent(typeof(ModularWeaponPart))]
	public class FireModeAddon : MonoBehaviour, IPartFireArmRequirement
	{
		public enum FireSelectorModeType
		{
			Safe,
			Single,
			Burst,
			FullAuto,
			SuperFastBurst
		}

		[Serializable]
		public class FireSelectorMode
		{
			public float SelectorPosition;

			public FireSelectorModeType ModeType;

			public int BurstAmount = 3;

			[Tooltip("Only works for closed bolt weapons")]
			public bool ARStyleBurst;

			public float EngagementDelay;
		}

		public FireSelectorMode[] FireSelectorModes;

		private FVRFireArm _firearm;

		private object[] _originalFireModes;

		public FVRFireArm FireArm
		{
			get
			{
				return _firearm;
			}
			set
			{
				if ((Object)(object)value != (Object)null)
				{
					_firearm = value;
					FVRFireArm firearm = _firearm;
					ClosedBoltWeapon val = (ClosedBoltWeapon)(object)((firearm is ClosedBoltWeapon) ? firearm : null);
					if (val == null)
					{
						OpenBoltReceiver val2 = (OpenBoltReceiver)(object)((firearm is OpenBoltReceiver) ? firearm : null);
						if (val2 == null)
						{
							Handgun val3 = (Handgun)(object)((firearm is Handgun) ? firearm : null);
							if (val3 != null)
							{
								object[] fireSelectorModes = val3.FireSelectorModes;
								_originalFireModes = fireSelectorModes;
								ModifyHandgunFireModes(val3);
							}
						}
						else
						{
							object[] fireSelectorModes = val2.FireSelector_Modes;
							_originalFireModes = fireSelectorModes;
							ModifyOpenBoltFireModes(val2);
						}
					}
					else
					{
						object[] fireSelectorModes = val.FireSelector_Modes;
						_originalFireModes = fireSelectorModes;
						ModifyClosedBoltFireModes(val);
					}
				}
				else
				{
					if (!((Object)(object)value == (Object)null) || !((Object)(object)_firearm != (Object)null))
					{
						return;
					}
					FVRFireArm firearm = _firearm;
					ClosedBoltWeapon val4 = (ClosedBoltWeapon)(object)((firearm is ClosedBoltWeapon) ? firearm : null);
					if (val4 == null)
					{
						OpenBoltReceiver val5 = (OpenBoltReceiver)(object)((firearm is OpenBoltReceiver) ? firearm : null);
						if (val5 == null)
						{
							Handgun val6 = (Handgun)(object)((firearm is Handgun) ? firearm : null);
							if (val6 != null)
							{
								val6.FireSelectorModes = (FireSelectorMode[])_originalFireModes;
								if (val6.m_fireSelectorMode >= val6.FireSelectorModes.Length)
								{
									val6.m_fireSelectorMode = val6.FireSelectorModes.Length - 1;
								}
							}
						}
						else
						{
							val5.FireSelector_Modes = (FireSelectorMode[])_originalFireModes;
							if (val5.m_fireSelectorMode >= val5.FireSelector_Modes.Length)
							{
								val5.m_fireSelectorMode = val5.FireSelector_Modes.Length - 1;
							}
						}
					}
					else
					{
						val4.FireSelector_Modes = (FireSelectorMode[])_originalFireModes;
						if (val4.m_fireSelectorMode >= val4.FireSelector_Modes.Length)
						{
							val4.m_fireSelectorMode = val4.FireSelector_Modes.Length - 1;
						}
					}
					_firearm = null;
				}
			}
		}

		private void ModifyClosedBoltFireModes(ClosedBoltWeapon w)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			List<FireSelectorMode> list = new List<FireSelectorMode>();
			FireSelectorMode[] fireSelectorModes = FireSelectorModes;
			foreach (FireSelectorMode fireSelectorMode in fireSelectorModes)
			{
				list.Add(new FireSelectorMode
				{
					SelectorPosition = fireSelectorMode.SelectorPosition,
					ModeType = fireSelectorMode.ModeType.ConvertToClosedBolt(),
					BurstAmount = fireSelectorMode.BurstAmount,
					ARStyleBurst = fireSelectorMode.ARStyleBurst,
					EngagementDelay = fireSelectorMode.EngagementDelay
				});
			}
			w.FireSelector_Modes = list.ToArray();
			w.FireSelector_Modes2 = list.ToArray();
		}

		private void ModifyOpenBoltFireModes(OpenBoltReceiver w)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_0055: Expected O, but got Unknown
			List<FireSelectorMode> list = new List<FireSelectorMode>();
			FireSelectorMode[] fireSelectorModes = FireSelectorModes;
			foreach (FireSelectorMode fireSelectorMode in fireSelectorModes)
			{
				list.Add(new FireSelectorMode
				{
					SelectorPosition = fireSelectorMode.SelectorPosition,
					ModeType = fireSelectorMode.ModeType.ConvertToOpenBolt(),
					BurstAmount = fireSelectorMode.BurstAmount,
					EngagementDelay = fireSelectorMode.EngagementDelay
				});
			}
			w.FireSelector_Modes = list.ToArray();
			w.FireSelector_Modes2 = list.ToArray();
		}

		private void ModifyHandgunFireModes(Handgun w)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_0055: Expected O, but got Unknown
			List<FireSelectorMode> list = new List<FireSelectorMode>();
			FireSelectorMode[] fireSelectorModes = FireSelectorModes;
			foreach (FireSelectorMode fireSelectorMode in fireSelectorModes)
			{
				list.Add(new FireSelectorMode
				{
					SelectorPosition = fireSelectorMode.SelectorPosition,
					ModeType = fireSelectorMode.ModeType.ConvertToHandgun(),
					BurstAmount = fireSelectorMode.BurstAmount,
					EngagementDelay = fireSelectorMode.EngagementDelay
				});
			}
			w.FireSelectorModes = list.ToArray();
		}
	}
	public static class FireModeEnumExtensions
	{
		public static FireSelectorModeType ConvertToClosedBolt(this FireModeAddon.FireSelectorModeType fireSelectorMode)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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)
			return (FireSelectorModeType)(fireSelectorMode switch
			{
				FireModeAddon.FireSelectorModeType.Safe => 0, 
				FireModeAddon.FireSelectorModeType.Single => 1, 
				FireModeAddon.FireSelectorModeType.Burst => 2, 
				FireModeAddon.FireSelectorModeType.FullAuto => 3, 
				FireModeAddon.FireSelectorModeType.SuperFastBurst => 4, 
				_ => 0, 
			});
		}

		public static FireSelectorModeType ConvertToOpenBolt(this FireModeAddon.FireSelectorModeType fireSelectorMode)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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)
			return (FireSelectorModeType)(fireSelectorMode switch
			{
				FireModeAddon.FireSelectorModeType.Safe => 0, 
				FireModeAddon.FireSelectorModeType.Single => 1, 
				FireModeAddon.FireSelectorModeType.Burst => 4, 
				FireModeAddon.FireSelectorModeType.FullAuto => 2, 
				FireModeAddon.FireSelectorModeType.SuperFastBurst => 3, 
				_ => 0, 
			});
		}

		public static FireSelectorModeType ConvertToHandgun(this FireModeAddon.FireSelectorModeType fireSelectorMode)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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)
			return (FireSelectorModeType)(fireSelectorMode switch
			{
				FireModeAddon.FireSelectorModeType.Safe => 3, 
				FireModeAddon.FireSelectorModeType.Single => 1, 
				FireModeAddon.FireSelectorModeType.Burst => 4, 
				FireModeAddon.FireSelectorModeType.FullAuto => 2, 
				FireModeAddon.FireSelectorModeType.SuperFastBurst => 4, 
				_ => 3, 
			});
		}
	}
	[RequireComponent(typeof(ModularWeaponPart))]
	public class BoltAndSlideManipAddon : MonoBehaviour, IPartFireArmRequirement
	{
		public ManipulateTransforms ManipulateTransform;

		public FVRFireArm FireArm
		{
			set
			{
				if (!((Object)(object)value != (Object)null))
				{
					return;
				}
				Handgun val = (Handgun)(object)((value is Handgun) ? value : null);
				if (val == null)
				{
					ClosedBoltWeapon val2 = (ClosedBoltWeapon)(object)((value is ClosedBoltWeapon) ? value : null);
					if (val2 == null)
					{
						OpenBoltReceiver val3 = (OpenBoltReceiver)(object)((value is OpenBoltReceiver) ? value : null);
						if (val3 == null)
						{
							TubeFedShotgun val4 = (TubeFedShotgun)(object)((value is TubeFedShotgun) ? value : null);
							if (val4 == null)
							{
								BoltActionRifle val5 = (BoltActionRifle)(object)((value is BoltActionRifle) ? value : null);
								if (val5 != null)
								{
									TransformModificationGroup[] transformGroups = ManipulateTransform.TransformGroups;
									for (int i = 0; i < transformGroups.Length; i++)
									{
										transformGroups[i].ObservedTransform = ((Component)val5.BoltHandle).transform;
									}
								}
							}
							else
							{
								TransformModificationGroup[] transformGroups = ManipulateTransform.TransformGroups;
								for (int i = 0; i < transformGroups.Length; i++)
								{
									transformGroups[i].ObservedTransform = ((Component)val4.Bolt).transform;
								}
							}
						}
						else
						{
							TransformModificationGroup[] transformGroups = ManipulateTransform.TransformGroups;
							for (int i = 0; i < transformGroups.Length; i++)
							{
								transformGroups[i].ObservedTransform = ((Component)val3.Bolt).transform;
							}
						}
					}
					else
					{
						TransformModificationGroup[] transformGroups = ManipulateTransform.TransformGroups;
						for (int i = 0; i < transformGroups.Length; i++)
						{
							transformGroups[i].ObservedTransform = ((Component)val2.Bolt).transform;
						}
					}
				}
				else
				{
					TransformModificationGroup[] transformGroups = ManipulateTransform.TransformGroups;
					for (int i = 0; i < transformGroups.Length; i++)
					{
						transformGroups[i].ObservedTransform = ((Component)val.Slide).transform;
					}
				}
			}
		}
	}
	[RequireComponent(typeof(ModularWeaponPart))]
	public class MagazineCompatibilityAddon : MonoBehaviour, IPartFireArmRequirement
	{
		public List<string> CompatibleMagazines = new List<string>();

		public bool RejectListedMagazinesInstead;

		public AudioEvent IncompatibleAudioEvent;

		private FVRFireArm _firearm;

		private static readonly Dictionary<FVRFireArm, MagazineCompatibilityAddon> _existingMagazineCompatibilityAddons = new Dictionary<FVRFireArm, MagazineCompatibilityAddon>();

		public FVRFireArm FireArm
		{
			set
			{
				if ((Object)(object)value != (Object)null)
				{
					_firearm = value;
					_existingMagazineCompatibilityAddons.Add(_firearm, this);
				}
				else if ((Object)(object)value == (Object)null && (Object)(object)_firearm != (Object)null)
				{
					_existingMagazineCompatibilityAddons.Remove(_firearm);
					_firearm = null;
				}
			}
		}

		[HarmonyPatch(typeof(FVRFireArmReloadTriggerMag), "OnTriggerEnter")]
		[HarmonyPrefix]
		public static bool FVRFireArmReloadTriggerMag_OnTriggerEnter_Patch(FVRFireArmReloadTriggerMag __instance, Collider collider)
		{
			//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_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: 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_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: 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_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance.Magazine != (Object)null && (Object)(object)__instance.Magazine.FireArm == (Object)null && (Object)(object)((FVRPhysicalObject)__instance.Magazine).QuickbeltSlot == (Object)null && ((Component)collider).gameObject.tag == "FVRFireArmReloadTriggerWell")
			{
				FVRFireArmReloadTriggerWell component = ((Component)collider).gameObject.GetComponent<FVRFireArmReloadTriggerWell>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.FireArm != (Object)null && _existingMagazineCompatibilityAddons.TryGetValue(component.FireArm, out var value))
				{
					if (component.IsAttachableWell && (Object)(object)component.AFireArm != (Object)null && (Object)(object)component.AFireArm.Magazine == (Object)null)
					{
						FireArmMagazineType val = component.AFireArm.MagazineType;
						if (component.UsesTypeOverride)
						{
							val = component.TypeOverride;
						}
						if (val == __instance.Magazine.MagazineType && (component.AFireArm.EjectDelay <= 0f || (Object)(object)__instance.Magazine != (Object)(object)component.AFireArm.LastEjectedMag) && (Object)(object)component.AFireArm.Magazine == (Object)null)
						{
							if ((!value.RejectListedMagazinesInstead) ? value.CompatibleMagazines.Contains(((FVRPhysicalObject)__instance.Magazine).ObjectWrapper.ItemID) : (!value.CompatibleMagazines.Contains(((FVRPhysicalObject)__instance.Magazine).ObjectWrapper.ItemID)))
							{
								__instance.Magazine.Load(component.AFireArm);
							}
							else
							{
								SM.PlayGenericSound(value.IncompatibleAudioEvent, ((Component)__instance).transform.position);
							}
						}
					}
					else if (component.UsesSecondaryMagSlots && (Object)(object)component.FireArm != (Object)null && (Object)(object)component.FireArm.SecondaryMagazineSlots[component.SecondaryMagSlotIndex].Magazine == (Object)null)
					{
						FireArmMagazineType val2 = component.FireArm.MagazineType;
						if (component.UsesTypeOverride)
						{
							val2 = component.TypeOverride;
						}
						if (val2 == __instance.Magazine.MagazineType && (component.FireArm.SecondaryMagazineSlots[component.SecondaryMagSlotIndex].m_ejectDelay <= 0f || (Object)(object)__instance.Magazine != (Object)(object)component.FireArm.SecondaryMagazineSlots[component.SecondaryMagSlotIndex].m_lastEjectedMag) && (Object)(object)component.FireArm.SecondaryMagazineSlots[component.SecondaryMagSlotIndex].Magazine == (Object)null)
						{
							if ((!value.RejectListedMagazinesInstead) ? value.CompatibleMagazines.Contains(((FVRPhysicalObject)__instance.Magazine).ObjectWrapper.ItemID) : (!value.CompatibleMagazines.Contains(((FVRPhysicalObject)__instance.Magazine).ObjectWrapper.ItemID)))
							{
								__instance.Magazine.LoadIntoSecondary(component.FireArm, component.SecondaryMagSlotIndex);
							}
							else
							{
								SM.PlayGenericSound(value.IncompatibleAudioEvent, ((Component)__instance).transform.position);
							}
						}
					}
					else
					{
						bool flag = false;
						if (!__instance.Magazine.IsBeltBox && (Object)(object)component.FireArm != (Object)null && component.FireArm.HasBelt)
						{
							flag = true;
						}
						if (component.IsBeltBox == __instance.Magazine.IsBeltBox && (Object)(object)component.FireArm != (Object)null && (Object)(object)component.FireArm.Magazine == (Object)null && !flag)
						{
							FireArmMagazineType val3 = component.FireArm.MagazineType;
							if (component.UsesTypeOverride)
							{
								val3 = component.TypeOverride;
							}
							if (val3 == __instance.Magazine.MagazineType && (component.FireArm.EjectDelay <= 0f || (Object)(object)__instance.Magazine != (Object)(object)component.FireArm.LastEjectedMag) && (Object)(object)component.FireArm.Magazine == (Object)null)
							{
								if ((!value.RejectListedMagazinesInstead) ? value.CompatibleMagazines.Contains(((FVRPhysicalObject)__instance.Magazine).ObjectWrapper.ItemID) : (!value.CompatibleMagazines.Contains(((FVRPhysicalObject)__instance.Magazine).ObjectWrapper.ItemID)))
								{
									__instance.Magazine.Load(component.FireArm);
								}
								else
								{
									SM.PlayGenericSound(value.IncompatibleAudioEvent, ((Component)__instance).transform.position);
								}
							}
						}
					}
					return false;
				}
			}
			return true;
		}
	}
	[RequireComponent(typeof(ModularWeaponPart))]
	public class BoltGrabPointAddon : MonoBehaviour, IPartFireArmRequirement
	{
		public enum EBoltType
		{
			Bolt,
			BoltHandle
		}

		private enum EColliderType
		{
			Sphere,
			Capsule,
			Box
		}

		public EBoltType BoltType;

		public GameObject ColliderReference;

		private TransformProxy _colliderReferenceProxy;

		public bool ReplaceExistingCollider;

		private FVRFireArm _firearm;

		private Collider _origCollider;

		private Collider _addedCollider;

		private Vector3 _addedColliderCenter;

		private Vector3 _addedColliderSize;

		private EColliderType _addedColliderType;

		private Axis _addedColliderAxis;

		public FVRFireArm FireArm
		{
			set
			{
				//IL_0171: Unknown result type (might be due to invalid IL or missing references)
				//IL_0177: Unknown result type (might be due to invalid IL or missing references)
				//IL_0182: Unknown result type (might be due to invalid IL or missing references)
				//IL_0187: Unknown result type (might be due to invalid IL or missing references)
				//IL_018c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0191: Unknown result type (might be due to invalid IL or missing references)
				//IL_0196: Unknown result type (might be due to invalid IL or missing references)
				//IL_0198: Unknown result type (might be due to invalid IL or missing references)
				//IL_0199: Unknown result type (might be due to invalid IL or missing references)
				//IL_019e: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_023d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0285: Unknown result type (might be due to invalid IL or missing references)
				//IL_028f: Expected I4, but got Unknown
				//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)value != (Object)null)
				{
					_firearm = value;
					Transform val = null;
					switch (BoltType)
					{
					case EBoltType.Bolt:
					{
						FVRFireArm firearm = _firearm;
						ClosedBoltWeapon val7 = (ClosedBoltWeapon)(object)((firearm is ClosedBoltWeapon) ? firearm : null);
						Transform val6;
						if (val7 == null)
						{
							Handgun val8 = (Handgun)(object)((firearm is Handgun) ? firearm : null);
							if (val8 == null)
							{
								TubeFedShotgun val9 = (TubeFedShotgun)(object)((firearm is TubeFedShotgun) ? firearm : null);
								if (val9 == null)
								{
									OpenBoltReceiver val10 = (OpenBoltReceiver)(object)((firearm is OpenBoltReceiver) ? firearm : null);
									if (val10 == null)
									{
										BoltActionRifle val11 = (BoltActionRifle)(object)((firearm is BoltActionRifle) ? firearm : null);
										val6 = ((val11 == null) ? null : ((Component)val11.BoltHandle).transform);
									}
									else
									{
										val6 = ((Component)val10.Bolt).transform;
									}
								}
								else
								{
									val6 = ((Component)val9.Bolt).transform;
								}
							}
							else
							{
								val6 = ((Component)val8.Slide).transform;
							}
						}
						else
						{
							val6 = ((Component)val7.Bolt).transform;
						}
						val = val6;
						break;
					}
					case EBoltType.BoltHandle:
					{
						FVRFireArm firearm = _firearm;
						ClosedBoltWeapon val2 = (ClosedBoltWeapon)(object)((firearm is ClosedBoltWeapon) ? firearm : null);
						Transform val6;
						if (val2 == null)
						{
							TubeFedShotgun val3 = (TubeFedShotgun)(object)((firearm is TubeFedShotgun) ? firearm : null);
							if (val3 == null)
							{
								OpenBoltReceiver val4 = (OpenBoltReceiver)(object)((firearm is OpenBoltReceiver) ? firearm : null);
								if (val4 == null)
								{
									BoltActionRifle val5 = (BoltActionRifle)(object)((firearm is BoltActionRifle) ? firearm : null);
									val6 = ((val5 == null) ? null : ((Component)val5.BoltHandle).transform);
								}
								else
								{
									val6 = ((Component)(((Component)val4).GetComponentInChildren<OpenBoltRotatingChargingHandle>() ?? ((Component)val4).GetComponentInChildren<OpenBoltRotatingChargingHandle>())).transform;
								}
							}
							else
							{
								val6 = ((Component)val3.Handle).transform;
							}
						}
						else
						{
							val6 = ((Component)val2.Handle).transform;
						}
						val = val6;
						break;
					}
					}
					Vector3 val12 = _colliderReferenceProxy.parent.TransformPoint(_colliderReferenceProxy.localPosition + UnityEngineExtensions.MultiplyComponentWise(_addedColliderCenter, _colliderReferenceProxy.localScale));
					Vector3 center = val.InverseTransformPoint(val12);
					if (ReplaceExistingCollider)
					{
						_origCollider = ((Component)val).GetComponent<Collider>();
						_origCollider.enabled = false;
					}
					switch (_addedColliderType)
					{
					case EColliderType.Sphere:
					{
						_addedCollider = (Collider)(object)((Component)val).gameObject.AddComponent<SphereCollider>();
						Collider addedCollider7 = _addedCollider;
						((SphereCollider)((addedCollider7 is SphereCollider) ? addedCollider7 : null)).center = center;
						Collider addedCollider8 = _addedCollider;
						((SphereCollider)((addedCollider8 is SphereCollider) ? addedCollider8 : null)).radius = _addedColliderSize.x;
						break;
					}
					case EColliderType.Capsule:
					{
						_addedCollider = (Collider)(object)((Component)val).gameObject.AddComponent<CapsuleCollider>();
						Collider addedCollider3 = _addedCollider;
						((CapsuleCollider)((addedCollider3 is CapsuleCollider) ? addedCollider3 : null)).center = center;
						Collider addedCollider4 = _addedCollider;
						((CapsuleCollider)((addedCollider4 is CapsuleCollider) ? addedCollider4 : null)).radius = _addedColliderSize.x;
						Collider addedCollider5 = _addedCollider;
						((CapsuleCollider)((addedCollider5 is CapsuleCollider) ? addedCollider5 : null)).height = _addedColliderSize.y;
						Collider addedCollider6 = _addedCollider;
						((CapsuleCollider)((addedCollider6 is CapsuleCollider) ? addedCollider6 : null)).direction = (int)_addedColliderAxis;
						break;
					}
					case EColliderType.Box:
					{
						_addedCollider = (Collider)(object)((Component)val).gameObject.AddComponent<BoxCollider>();
						Collider addedCollider = _addedCollider;
						((BoxCollider)((addedCollider is BoxCollider) ? addedCollider : null)).center = center;
						Collider addedCollider2 = _addedCollider;
						((BoxCollider)((addedCollider2 is BoxCollider) ? addedCollider2 : null)).size = _addedColliderSize;
						break;
					}
					}
					_addedCollider.isTrigger = true;
				}
				else if ((Object)(object)value == (Object)null && (Object)(object)_firearm != (Object)null)
				{
					if (ReplaceExistingCollider)
					{
						_origCollider.enabled = true;
					}
					Object.Destroy((Object)(object)_addedCollider);
					_firearm = null;
				}
			}
		}

		public void Awake()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ColliderReference != (Object)null)
			{
				_colliderReferenceProxy = new TransformProxy(ColliderReference.transform, false);
				Collider component = ColliderReference.GetComponent<Collider>();
				CapsuleCollider val = (CapsuleCollider)(object)((component is CapsuleCollider) ? component : null);
				if (val == null)
				{
					SphereCollider val2 = (SphereCollider)(object)((component is SphereCollider) ? component : null);
					if (val2 == null)
					{
						BoxCollider val3 = (BoxCollider)(object)((component is BoxCollider) ? component : null);
						if (val3 == null)
						{
							if (component == null)
							{
								ModularWorkshopManager.LogWarning((MonoBehaviour)(object)this, "ColliderReference " + ((Object)ColliderReference).name + " doesn't contain a collider you goofus! Shit's about to break!");
							}
						}
						else
						{
							_addedColliderCenter = val3.center;
							_addedColliderSize = val3.size;
							_addedColliderType = EColliderType.Box;
						}
					}
					else
					{
						_addedColliderCenter = val2.center;
						_addedColliderSize = new Vector3(val2.radius, 0f, 0f);
						_addedColliderType = EColliderType.Sphere;
					}
				}
				else
				{
					_addedColliderCenter = val.center;
					_addedColliderSize = new Vector3(val.radius, val.height, 0f);
					_addedColliderType = EColliderType.Capsule;
					_addedColliderAxis = (Axis)(val.direction switch
					{
						0 => 0, 
						1 => 1, 
						2 => 2, 
						_ => 0, 
					});
				}
				Object.Destroy((Object)(object)ColliderReference);
			}
			else if ((Object)(object)ColliderReference == (Object)null)
			{
				ModularWorkshopManager.LogError((MonoBehaviour)(object)this, "ColliderReference is empty but you want this to be a functional bolt grab point addon you goofus! Shit's about to break!");
			}
		}
	}
	[RequireComponent(typeof(ModularWeaponPart))]
	public class AltGripAddon : MonoBehaviour, IPartFireArmRequirement
	{
		public FVRAlternateGrip AltGrip;

		private FVRFireArm _firearm;

		private GameObject _origForeGrip;

		public FVRFireArm FireArm
		{
			set
			{
				if ((Object)(object)value != (Object)null)
				{
					_firearm = value;
					AltGrip.PrimaryObject = (FVRPhysicalObject)(object)_firearm;
					_origForeGrip = _firearm.Foregrip;
					_firearm.Foregrip = ((Component)AltGrip).gameObject;
				}
				else
				{
					_firearm.Foregrip = _origForeGrip;
				}
			}
		}
	}
	[RequireComponent(typeof(ModularWeaponPart))]
	public class RecoilModificationAddon : MonoBehaviour, IPartFireArmRequirement
	{
		public float VerticalRecoilMultiplier = 1f;

		[Tooltip("This option will use the below multipliers to\naffect the recoil profile directly.\nUse a brain. Don't also change the recoil profile with another part!")]
		public bool UseAdvancedRecoilMultipliers;

		public RecoilMultipliers RecoilMultipliers;

		private FVRFireArm _firearm;

		public FVRFireArm FireArm
		{
			set
			{
				if ((Object)(object)value != (Object)null)
				{
					_firearm = value;
					RecoilModificationCore val = ((Component)_firearm).GetComponent<RecoilModificationCore>() ?? ((Component)_firearm).gameObject.AddComponent<RecoilModificationCore>();
					val.VerticalRecoilMultipliers.Add(VerticalRecoilMultiplier);
					if (UseAdvancedRecoilMultipliers)
					{
						val.RecoilMultipliersList.Add(RecoilMultipliers);
						val.UpdateRecoilProfile();
					}
				}
				else
				{
					if (!((Object)(object)value == (Object)null) || !((Object)(object)_firearm != (Object)null))
					{
						return;
					}
					RecoilModificationCore component = ((Component)_firearm).GetComponent<RecoilModificationCore>();
					component?.VerticalRecoilMultipliers.Remove(VerticalRecoilMultiplier);
					if (UseAdvancedRecoilMultipliers)
					{
						component?.RecoilMultipliersList.Remove(RecoilMultipliers);
						if (component != null)
						{
							component.UpdateRecoilProfile();
						}
					}
					_firearm = null;
				}
			}
		}
	}
	[RequireComponent(typeof(ModularWeaponPart))]
	public class MagazineWellAddon : MonoBehaviour, IPartFireArmRequirement
	{
		public UniversalMagGrabTrigger MagGrabTrigger;

		public UniversalAdvancedMagazineGrabTrigger AdvancedMagazineGrabTrigger;

		public FVRFireArmReloadTriggerWell ReloadTriggerWell;

		public SecondaryMagazineSlot SecondaryMagazineSlot;

		private FVRFireArm _firearm;

		public FVRFireArm FireArm
		{
			set
			{
				if ((Object)(object)value != (Object)null)
				{
					_firearm = value;
					if ((Object)(object)MagGrabTrigger != (Object)null)
					{
						MagGrabTrigger.FireArm = _firearm;
					}
					if ((Object)(object)AdvancedMagazineGrabTrigger != (Object)null)
					{
						AdvancedMagazineGrabTrigger.FireArm = _firearm;
					}
					if ((Object)(object)ReloadTriggerWell != (Object)null)
					{
						ReloadTriggerWell.FireArm = _firearm;
					}
					List<SecondaryMagazineSlot> list = _firearm.SecondaryMagazineSlots.ToList();
					list.Add(SecondaryMagazineSlot);
					_firearm.SecondaryMagazineSlots = list.ToArray();
				}
				else
				{
					List<SecondaryMagazineSlot> list2 = _firearm.SecondaryMagazineSlots.ToList();
					int num = list2.IndexOf(SecondaryMagazineSlot);
					_firearm.EjectSecondaryMagFromSlot(num, false);
					list2.Remove(SecondaryMagazineSlot);
					_firearm.SecondaryMagazineSlots = list2.ToArray();
				}
			}
		}
	}
	public class SnappyTriggerAddon : MonoBehaviour, IPartFireArmRequirement
	{
		private static readonly List<FVRFireArm> _existingSnappyTriggers = new List<FVRFireArm>();

		private FVRFireArm _firearm;

		public FVRFireArm FireArm
		{
			set
			{
				if ((Object)(object)value != (Object)null)
				{
					_firearm = value;
					if (_firearm is Handgun)
					{
						_existingSnappyTriggers.Add(_firearm);
					}
				}
				else if ((Object)(object)value == (Object)null && (Object)(object)_firearm != (Object)null)
				{
					_existingSnappyTriggers.Remove(_firearm);
				}
			}
		}

		[HarmonyPatch(typeof(Handgun), "UpdateInputAndAnimate")]
		[HarmonyPrefix]
		private static void Handgun_UpdateInputAndAnimate_Patch(Handgun __instance, FVRViveHand hand)
		{
			if (!_existingSnappyTriggers.Contains((FVRFireArm)(object)__instance))
			{
				return;
			}
			if (!__instance.HasTriggerReset && hand.Input.TriggerUp)
			{
				__instance.HasTriggerReset = true;
				__instance.m_isSeerReady = true;
				((FVRFireArm)__instance).PlayAudioEvent((FirearmAudioEventType)16, 1f);
				if (__instance.FireSelectorModes.Length != 0)
				{
					__instance.m_CamBurst = __instance.FireSelectorModes[__instance.m_fireSelectorMode].BurstAmount;
				}
			}
			if (hand.Input.TriggerDown && !__instance.m_isSafetyEngaged && (!__instance.HasMagazineSafety || (Object)(object)((FVRFireArm)__instance).Magazine != (Object)null))
			{
				__instance.ReleaseSeer();
			}
		}

		[HarmonyPatch(typeof(ClosedBoltWeapon), "UpdateInputAndAnimate")]
		[HarmonyPrefix]
		private static void ClosedBoltWeapon_UpdateInputAndAnimate_Patch(ClosedBoltWeapon __instance, FVRViveHand hand)
		{
			if (!_existingSnappyTriggers.Contains((FVRFireArm)(object)__instance))
			{
				return;
			}
			if (!__instance.m_hasTriggerReset && hand.Input.TriggerUp)
			{
				__instance.m_hasTriggerReset = true;
				((FVRFireArm)__instance).PlayAudioEvent((FirearmAudioEventType)16, 1f);
				if (__instance.FireSelector_Modes.Length != 0)
				{
					__instance.m_CamBurst = __instance.FireSelector_Modes[__instance.m_fireSelectorMode].BurstAmount;
				}
			}
			if (hand.Input.TriggerDown && !__instance.IsWeaponOnSafe())
			{
				__instance.DropHammer();
			}
		}
	}
	[RequireComponent(typeof(ModularWeaponPart))]
	public class InteractionVisualEffectAddon : MonoBehaviour, IPartFireArmRequirement
	{
		[Tooltip("This list is optional, you can also place the Interaction Visual Effect scripts on this gameobject instead.")]
		public InteractionVisualEffect[] InteractionVisualEffects;

		public FVRFireArm FireArm
		{
			set
			{
				if ((Object)(object)value != (Object)null)
				{
					InteractionVisualEffect[] interactionVisualEffects = InteractionVisualEffects;
					for (int i = 0; i < interactionVisualEffects.Length; i++)
					{
						interactionVisualEffects[i].ObjectToMonitor = (FVRInteractiveObject)(object)value;
					}
					interactionVisualEffects = ((Component)this).GetComponents<InteractionVisualEffect>();
					for (int i = 0; i < interactionVisualEffects.Length; i++)
					{
						interactionVisualEffects[i].ObjectToMonitor = (FVRInteractiveObject)(object)value;
					}
				}
			}
		}
	}
	public class ModularBreakActionWeapon : BreakActionWeapon, IModularWeapon
	{
		[Header("Modular Configuration")]
		public ModularFVRFireArm ModularFVRFireArm;

		public GameObject UIPrefab => ModularFVRFireArm.UIPrefab;

		public string ModularBarrelPartsID => ModularFVRFireArm.ModularBarrelAttachmentPoint.ModularPartsGroupID;

		public Transform ModularBarrelPoint => ModularFVRFireArm.ModularBarrelAttachmentPoint.ModularPartPoint;

		public TransformProxy ModularBarrelUIPointProxy => ModularFVRFireArm.ModularBarrelAttachmentPoint.ModularPartUIPointProxy;

		public Dictionary<string, GameObject> ModularBarrelPrefabsDictionary => ModularFVRFireArm.ModularBarrelPrefabsDictionary;

		public string ModularHandguardPartsID => ModularFVRFireArm.ModularHandguardAttachmentPoint.ModularPartsGroupID;

		public Transform ModularHandguardPoint => ModularFVRFireArm.ModularHandguardAttachmentPoint.ModularPartPoint;

		public TransformProxy ModularHandguardUIPointProxy => ModularFVRFireArm.ModularHandguardAttachmentPoint.ModularPartUIPointProxy;

		public Dictionary<string, GameObject> ModularHandguardPrefabsDictionary => ModularFVRFireArm.ModularHandguardPrefabsDictionary;

		public string ModularStockPartsID => ModularFVRFireArm.ModularStockAttachmentPoint.ModularPartsGroupID;

		public Transform ModularStockPoint => ModularFVRFireArm.ModularStockAttachmentPoint.ModularPartPoint;

		public TransformProxy ModularStockUIPointProxy => ModularFVRFireArm.ModularStockAttachmentPoint.ModularPartUIPointProxy;

		public Dictionary<string, GameObject> ModularStockPrefabsDictionary => ModularFVRFireArm.ModularStockPrefabsDictionary;

		public string SelectedModularBarrel => ModularFVRFireArm.ModularBarrelAttachmentPoint.SelectedModularWeaponPart;

		public string SelectedModularHandguard => ModularFVRFireArm.ModularHandguardAttachmentPoint.SelectedModularWeaponPart;

		public string SelectedModularStock => ModularFVRFireArm.ModularStockAttachmentPoint.SelectedModularWeaponPart;

		public ModularWeaponPartsAttachmentPoint[] ModularWeaponPartsAttachmentPoints => ModularFVRFireArm.ModularWeaponPartsAttachmentPoints;

		public ModularWorkshopPlatform WorkshopPlatform
		{
			get
			{
				return ModularFVRFireArm.WorkshopPlatform;
			}
			set
			{
				ModularFVRFireArm.WorkshopPlatform = value;
			}
		}

		public List<ModularWeaponPartsAttachmentPoint> SubAttachmentPoints => ModularFVRFireArm.SubAttachmentPoints;

		public ModularFVRFireArm GetModularFVRFireArm => ModularFVRFireArm;

		public Dictionary<string, ModularWeaponPartsAttachmentPoint> AllAttachmentPoints => ModularFVRFireArm.AllAttachmentPoints;

		public override void Awake()
		{
			((BreakActionWeapon)this).Awake();
			ConvertTransformsToProxies();
			ModularFVRFireArm.Awake((FVRFireArm)(object)this);
			ConfigureAll();
		}

		public override void ConfigureFromFlagDic(Dictionary<string, string> f)
		{
			((BreakActionWeapon)this).ConfigureFromFlagDic(f);
			ModularFVRFireArm.ConfigureFromFlagDic(f, (FVRFireArm)(object)this);
		}

		public override Dictionary<string, string> GetFlagDic()
		{
			Dictionary<string, string> flagDic = ((BreakActionWeapon)this).GetFlagDic();
			return ModularFVRFireArm.GetFlagDic(flagDic);
		}

		public ModularWeaponPart ConfigureModularWeaponPart(ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint, string selectedPart, bool isRandomized = false)
		{
			return ModularFVRFireArm.ConfigureModularWeaponPart(modularWeaponPartsAttachmentPoint, selectedPart, isRandomized);
		}

		public ModularBarrel ConfigureModularBarrel(string selectedPart, bool isRandomized = false)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			ModularBarrel modularBarrel = ModularFVRFireArm.ConfigureModularBarrel(selectedPart, isRandomized);
			BreakActionBarrel[] barrels = base.Barrels;
			foreach (BreakActionBarrel obj in barrels)
			{
				Vector3 val = obj.Muzzle.parent.InverseTransformPoint(modularBarrel.MuzzlePosition.position);
				UnityEngineExtensions.ModifyLocalPositionAxisValue(obj.Muzzle, (Axis)2, val.z);
			}
			return modularBarrel;
		}

		public ModularHandguard ConfigureModularHandguard(string selectedPart, bool isRandomized = false)
		{
			return ModularFVRFireArm.ConfigureModularHandguard(selectedPart, isRandomized);
		}

		public ModularStock ConfigureModularStock(string selectedPart, bool isRandomized = false)
		{
			return ModularFVRFireArm.ConfigureModularStock(selectedPart, isRandomized);
		}

		public void ConfigureAll()
		{
			if (ModularBarrelPartsID != string.Empty)
			{
				string selectedPart = ((ModularFVRFireArm.IsInTakeAndHold && !ModularFVRFireArm.WasUnvaulted && !ModularFVRFireArm.ModularBarrelAttachmentPoint.DisallowTakeAndHoldRandomization) ? ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary[ModularBarrelPartsID].GetRandomPart() : SelectedModularBarrel);
				ConfigureModularBarrel(selectedPart);
			}
			if (ModularHandguardPartsID != string.Empty)
			{
				string selectedPart = ((ModularFVRFireArm.IsInTakeAndHold && !ModularFVRFireArm.WasUnvaulted && !ModularFVRFireArm.ModularHandguardAttachmentPoint.DisallowTakeAndHoldRandomization) ? ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary[ModularHandguardPartsID].GetRandomPart() : SelectedModularHandguard);
				ConfigureModularHandguard(selectedPart);
			}
			if (ModularStockPartsID != string.Empty)
			{
				string selectedPart = ((ModularFVRFireArm.IsInTakeAndHold && !ModularFVRFireArm.WasUnvaulted && !ModularFVRFireArm.ModularStockAttachmentPoint.DisallowTakeAndHoldRandomization) ? ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary[ModularStockPartsID].GetRandomPart() : SelectedModularStock);
				ConfigureModularStock(selectedPart);
			}
			ModularWeaponPartsAttachmentPoint[] modularWeaponPartsAttachmentPoints = ModularFVRFireArm.ModularWeaponPartsAttachmentPoints;
			foreach (ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint in modularWeaponPartsAttachmentPoints)
			{
				if (!modularWeaponPartsAttachmentPoint.IsPointDisabled && ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary.TryGetValue(modularWeaponPartsAttachmentPoint.ModularPartsGroupID, out var value) && value.PartsDictionary.Count > 0)
				{
					string selectedPart = ((ModularFVRFireArm.IsInTakeAndHold && !ModularFVRFireArm.WasUnvaulted && !modularWeaponPartsAttachmentPoint.DisallowTakeAndHoldRandomization) ? ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary[modularWeaponPartsAttachmentPoint.ModularPartsGroupID].GetRandomPart() : modularWeaponPartsAttachmentPoint.SelectedModularWeaponPart);
					ConfigureModularWeaponPart(modularWeaponPartsAttachmentPoint, selectedPart, ModularFVRFireArm.IsInTakeAndHold);
				}
			}
		}

		public void ConvertTransformsToProxies()
		{
			ModularFVRFireArm.ConvertTransformsToProxies((FVRFireArm)(object)this);
		}

		public void ApplySkin(string ModularPartsGroupID, string SkinName)
		{
			AllAttachmentPoints[ModularPartsGroupID].ApplySkin(SkinName);
		}

		[ContextMenu("Copy Existing Firearm Component")]
		public void CopyFirearm()
		{
			BreakActionWeapon val = ((Component)this).GetComponents<BreakActionWeapon>().Single((BreakActionWeapon c) => (Object)(object)c != (Object)(object)this);
			BreakActionBarrel[] barrels = val.Barrels;
			for (int i = 0; i < barrels.Length; i++)
			{
				barrels[i].Chamber.Firearm = (FVRFireArm)(object)this;
			}
			if ((Object)(object)((FVRFireArm)val).Foregrip != (Object)null)
			{
				((FVRFireArm)val).Foregrip.GetComponent<FVRAlternateGrip>().PrimaryObject = (FVRPhysicalObject)(object)this;
			}
			foreach (FVRFireArmAttachmentMount attachmentMount in ((FVRPhysicalObject)val).AttachmentMounts)
			{
				attachmentMount.MyObject = (FVRPhysicalObject)(object)this;
				attachmentMount.Parent = (FVRPhysicalObject)(object)this;
			}
			UniversalCopy.CopyComponent<BreakActionWeapon>((Component)(object)this, val);
		}

		[ContextMenu("Populate Receiver Mesh Renderer List")]
		public void PopulateReceiverMeshList()
		{
			ModularFVRFireArm.GetReceiverMeshRenderers((FVRFireArm)(object)this);
		}

		[ContextMenu("Update Selected Parts")]
		public void UpdateSelectedParts()
		{
			ModularFVRFireArm.UpdateSelectedParts();
		}
	}
	public class ModularTubeFedShotgun : TubeFedShotgun, IModularWeapon
	{
		[Header("Modular Configuration")]
		public ModularFVRFireArm ModularFVRFireArm;

		public bool AllowExternalBoltReleaseButtonModification = true;

		public GameObject UIPrefab => ModularFVRFireArm.UIPrefab;

		public string ModularBarrelPartsID => ModularFVRFireArm.ModularBarrelAttachmentPoint.ModularPartsGroupID;

		public Transform ModularBarrelPoint => ModularFVRFireArm.ModularBarrelAttachmentPoint.ModularPartPoint;

		public TransformProxy ModularBarrelUIPointProxy => ModularFVRFireArm.ModularBarrelAttachmentPoint.ModularPartUIPointProxy;

		public Dictionary<string, GameObject> ModularBarrelPrefabsDictionary => ModularFVRFireArm.ModularBarrelPrefabsDictionary;

		public string ModularHandguardPartsID => ModularFVRFireArm.ModularHandguardAttachmentPoint.ModularPartsGroupID;

		public Transform ModularHandguardPoint => ModularFVRFireArm.ModularHandguardAttachmentPoint.ModularPartPoint;

		public TransformProxy ModularHandguardUIPointProxy => ModularFVRFireArm.ModularHandguardAttachmentPoint.ModularPartUIPointProxy;

		public Dictionary<string, GameObject> ModularHandguardPrefabsDictionary => ModularFVRFireArm.ModularHandguardPrefabsDictionary;

		public string ModularStockPartsID => ModularFVRFireArm.ModularStockAttachmentPoint.ModularPartsGroupID;

		public Transform ModularStockPoint => ModularFVRFireArm.ModularStockAttachmentPoint.ModularPartPoint;

		public TransformProxy ModularStockUIPointProxy => ModularFVRFireArm.ModularStockAttachmentPoint.ModularPartUIPointProxy;

		public Dictionary<string, GameObject> ModularStockPrefabsDictionary => ModularFVRFireArm.ModularStockPrefabsDictionary;

		public string SelectedModularBarrel => ModularFVRFireArm.ModularBarrelAttachmentPoint.SelectedModularWeaponPart;

		public string SelectedModularHandguard => ModularFVRFireArm.ModularHandguardAttachmentPoint.SelectedModularWeaponPart;

		public string SelectedModularStock => ModularFVRFireArm.ModularStockAttachmentPoint.SelectedModularWeaponPart;

		public ModularWeaponPartsAttachmentPoint[] ModularWeaponPartsAttachmentPoints => ModularFVRFireArm.ModularWeaponPartsAttachmentPoints;

		public ModularWorkshopPlatform WorkshopPlatform
		{
			get
			{
				return ModularFVRFireArm.WorkshopPlatform;
			}
			set
			{
				ModularFVRFireArm.WorkshopPlatform = value;
			}
		}

		public List<ModularWeaponPartsAttachmentPoint> SubAttachmentPoints => ModularFVRFireArm.SubAttachmentPoints;

		public ModularFVRFireArm GetModularFVRFireArm => ModularFVRFireArm;

		public Dictionary<string, ModularWeaponPartsAttachmentPoint> AllAttachmentPoints => ModularFVRFireArm.AllAttachmentPoints;

		public override void Awake()
		{
			((TubeFedShotgun)this).Awake();
			ConvertTransformsToProxies();
			ModularFVRFireArm.Awake((FVRFireArm)(object)this);
			ConfigureAll();
		}

		public override void ConfigureFromFlagDic(Dictionary<string, string> f)
		{
			((TubeFedShotgun)this).ConfigureFromFlagDic(f);
			ModularFVRFireArm.ConfigureFromFlagDic(f, (FVRFireArm)(object)this);
		}

		public override Dictionary<string, string> GetFlagDic()
		{
			Dictionary<string, string> flagDic = ((TubeFedShotgun)this).GetFlagDic();
			return ModularFVRFireArm.GetFlagDic(flagDic);
		}

		public ModularWeaponPart ConfigureModularWeaponPart(ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint, string selectedPart, bool isRandomized = false)
		{
			return ModularFVRFireArm.ConfigureModularWeaponPart(modularWeaponPartsAttachmentPoint, selectedPart, isRandomized);
		}

		public ModularBarrel ConfigureModularBarrel(string selectedPart, bool isRandomized = false)
		{
			return ModularFVRFireArm.ConfigureModularBarrel(selectedPart, isRandomized);
		}

		public ModularHandguard ConfigureModularHandguard(string selectedPart, bool isRandomized = false)
		{
			return ModularFVRFireArm.ConfigureModularHandguard(selectedPart, isRandomized);
		}

		public ModularStock ConfigureModularStock(string selectedPart, bool isRandomized = false)
		{
			return ModularFVRFireArm.ConfigureModularStock(selectedPart, isRandomized);
		}

		public void ConfigureAll()
		{
			if (ModularBarrelPartsID != string.Empty)
			{
				string selectedPart = ((ModularFVRFireArm.IsInTakeAndHold && !ModularFVRFireArm.WasUnvaulted && !ModularFVRFireArm.ModularBarrelAttachmentPoint.DisallowTakeAndHoldRandomization) ? ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary[ModularBarrelPartsID].GetRandomPart() : SelectedModularBarrel);
				ConfigureModularBarrel(selectedPart);
			}
			if (ModularHandguardPartsID != string.Empty)
			{
				string selectedPart = ((ModularFVRFireArm.IsInTakeAndHold && !ModularFVRFireArm.WasUnvaulted && !ModularFVRFireArm.ModularHandguardAttachmentPoint.DisallowTakeAndHoldRandomization) ? ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary[ModularHandguardPartsID].GetRandomPart() : SelectedModularHandguard);
				ConfigureModularHandguard(selectedPart);
			}
			if (ModularStockPartsID != string.Empty)
			{
				string selectedPart = ((ModularFVRFireArm.IsInTakeAndHold && !ModularFVRFireArm.WasUnvaulted && !ModularFVRFireArm.ModularStockAttachmentPoint.DisallowTakeAndHoldRandomization) ? ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary[ModularStockPartsID].GetRandomPart() : SelectedModularStock);
				ConfigureModularStock(selectedPart);
			}
			ModularWeaponPartsAttachmentPoint[] modularWeaponPartsAttachmentPoints = ModularFVRFireArm.ModularWeaponPartsAttachmentPoints;
			foreach (ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint in modularWeaponPartsAttachmentPoints)
			{
				if (!modularWeaponPartsAttachmentPoint.IsPointDisabled && ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary.TryGetValue(modularWeaponPartsAttachmentPoint.ModularPartsGroupID, out var value) && value.PartsDictionary.Count > 0)
				{
					string selectedPart = ((ModularFVRFireArm.IsInTakeAndHold && !ModularFVRFireArm.WasUnvaulted && !modularWeaponPartsAttachmentPoint.DisallowTakeAndHoldRandomization) ? ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary[modularWeaponPartsAttachmentPoint.ModularPartsGroupID].GetRandomPart() : modularWeaponPartsAttachmentPoint.SelectedModularWeaponPart);
					ConfigureModularWeaponPart(modularWeaponPartsAttachmentPoint, selectedPart, ModularFVRFireArm.IsInTakeAndHold);
				}
			}
		}

		public void ConvertTransformsToProxies()
		{
			ModularFVRFireArm.ConvertTransformsToProxies((FVRFireArm)(object)this);
		}

		public void ApplySkin(string ModularPartsGroupID, string SkinName)
		{
			AllAttachmentPoints[ModularPartsGroupID].ApplySkin(SkinName);
		}

		[ContextMenu("Copy Existing Firearm Component")]
		public void CopyFirearm()
		{
			TubeFedShotgun val = ((Component)this).GetComponents<TubeFedShotgun>().Single((TubeFedShotgun c) => (Object)(object)c != (Object)(object)this);
			if ((Object)(object)val.Bolt != (Object)null)
			{
				val.Bolt.Shotgun = (TubeFedShotgun)(object)this;
			}
			if ((Object)(object)val.Chamber != (Object)null)
			{
				val.Chamber.Firearm = (FVRFireArm)(object)this;
			}
			if ((Object)(object)val.Handle != (Object)null)
			{
				val.Handle.Shotgun = (TubeFedShotgun)(object)this;
			}
			if ((Object)(object)((FVRFireArm)val).Foregrip != (Object)null)
			{
				((FVRFireArm)val).Foregrip.GetComponent<FVRAlternateGrip>().PrimaryObject = (FVRPhysicalObject)(object)this;
			}
			FVRFireArmReloadTriggerWell componentInChildren = ((Component)val).GetComponentInChildren<FVRFireArmReloadTriggerWell>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.FireArm = (FVRFireArm)(object)this;
			}
			((FVRPhysicalObject)val).AttachmentMounts = ((FVRPhysicalObject)val).AttachmentMounts.Where((FVRFireArmAttachmentMount mount) => (Object)(object)mount != (Object)null).ToList();
			foreach (FVRFireArmAttachmentMount attachmentMount in ((FVRPhysicalObject)val).AttachmentMounts)
			{
				attachmentMount.MyObject = (FVRPhysicalObject)(object)this;
				attachmentMount.Parent = (FVRPhysicalObject)(object)this;
			}
			UniversalCopy.CopyComponent<TubeFedShotgun>((Component)(object)this, val);
		}

		[ContextMenu("Populate Receiver Mesh Renderer List")]
		public void PopulateReceiverMeshList()
		{
			ModularFVRFireArm.GetReceiverMeshRenderers((FVRFireArm)(object)this);
		}
	}
	public class ModularMagazineExtension : ModularWeaponPart
	{
		[Header("Magazine Extension Config")]
		[Tooltip("This part will add (or subtract, with a negative number) this number of rounds to the capacity of magazine first found in the object hierarchy above this game object. \n(This is not the number of total rounds, but additional rounds. A true magazine extension!)")]
		public int AdditionalNumberOfRoundsInMagazine;

		protected FVRFireArmMagazine _magazine;

		private static readonly List<FVRFireArmMagazine> _existingMagazineExtensions = new List<FVRFireArmMagazine>();

		public override void Awake()
		{
			base.Awake();
			if (UnityEngineExtensions.TryGetComponentInParent<FVRFireArmMagazine>((Component)(object)((Component)this).transform, ref _magazine))
			{
				_existingMagazineExtensions.Add(_magazine);
			}
		}

		public override void OnDestroy()
		{
			if ((Object)(object)_magazine != (Object)null)
			{
				_existingMagazineExtensions.Remove(_magazine);
			}
			base.OnDestroy();
		}

		public override void EnablePart()
		{
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			base.EnablePart();
			if (UnityEngineExtensions.TryGetComponentInParent<FVRFireArmMagazine>((Component)(object)((Component)this).transform, ref _magazine))
			{
				int num = _magazine.m_capacity + AdditionalNumberOfRoundsInMagazine;
				if (_magazine.m_numRounds > num)
				{
					int num2 = _magazine.m_numRounds - num;
					for (int i = 0; i < num2; i++)
					{
						_magazine.RemoveRound();
					}
				}
				if (_magazine.LoadedRounds != null && _magazine.LoadedRounds.Length < num)
				{
					int num3 = num - _magazine.LoadedRounds.Length;
					Array.Resize(ref _magazine.LoadedRounds, num);
					for (int j = _magazine.LoadedRounds.Length - num3; j < _magazine.LoadedRounds.Length; j++)
					{
						_magazine.LoadedRounds[j] = new FVRLoadedRound();
					}
				}
				else if (_magazine.LoadedRounds != null && _magazine.m_numRounds < num)
				{
					for (int k = _magazine.m_numRounds; k < num; k++)
					{
						if (_magazine.LoadedRounds[k] == null)
						{
							_magazine.LoadedRounds[k] = new FVRLoadedRound();
						}
					}
				}
				else if (_magazine.LoadedRounds == null)
				{
					_magazine.LoadedRounds = (FVRLoadedRound[])(object)new FVRLoadedRound[num];
					for (int l = 0; l < _magazine.LoadedRounds.Length; l++)
					{
						_magazine.LoadedRounds[l] = new FVRLoadedRound();
					}
				}
				_magazine.m_capacity = num;
			}
			else if ((Object)(object)_magazine == (Object)null)
			{
				ModularWorkshopManager.LogWarning((MonoBehaviour)(object)this, "Magazine not found! ModularMagazineExtension disabled!");
				Object.Destroy((Object)(object)this);
			}
		}

		public override void DisablePart()
		{
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			base.DisablePart();
			if (UnityEngineExtensions.TryGetComponentInParent<FVRFireArmMagazine>((Component)(object)((Component)this).transform, ref _magazine))
			{
				int num = _magazine.m_capacity - AdditionalNumberOfRoundsInMagazine;
				if (_magazine.m_numRounds > num)
				{
					int num2 = _magazine.m_numRounds - num;
					for (int i = 0; i < num2; i++)
					{
						_magazine.RemoveRound();
					}
				}
				if (_magazine.LoadedRounds != null && _magazine.LoadedRounds.Length < num)
				{
					int num3 = num - _magazine.LoadedRounds.Length;
					Array.Resize(ref _magazine.LoadedRounds, num);
					for (int j = _magazine.LoadedRounds.Length - num3; j < _magazine.LoadedRounds.Length; j++)
					{
						_magazine.LoadedRounds[j] = new FVRLoadedRound();
					}
				}
				else if (_magazine.LoadedRounds != null && _magazine.m_numRounds < num)
				{
					for (int k = _magazine.m_numRounds; k < num; k++)
					{
						if (_magazine.LoadedRounds[k] == null)
						{
							_magazine.LoadedRounds[k] = new FVRLoadedRound();
						}
					}
				}
				else if (_magazine.LoadedRounds == null)
				{
					_magazine.LoadedRounds = (FVRLoadedRound[])(object)new FVRLoadedRound[num];
					for (int l = 0; l < _magazine.LoadedRounds.Length; l++)
					{
						_magazine.LoadedRounds[l] = new FVRLoadedRound();
					}
				}
				_magazine.m_capacity = num;
			}
			else if ((Object)(object)_magazine == (Object)null)
			{
				ModularWorkshopManager.LogWarning((MonoBehaviour)(object)this, "Magazine not found! ModularMagazineExtension couldn't be disabled!");
			}
		}

		[HarmonyPatch(typeof(FVRPhysicalObject), "DuplicateFromSpawnLock")]
		[HarmonyPostfix]
		public static void DuplicateFromSpawnLockPatch(FVRPhysicalObject __instance, ref GameObject __result)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			FVRFireArmMagazine componentInParent = ((Component)__instance).GetComponentInParent<FVRFireArmMagazine>();
			if (!((Object)(object)componentInParent != (Object)null) || !_existingMagazineExtensions.Contains(componentInParent))
			{
				return;
			}
			FVRFireArmMagazine componentInParent2 = __result.GetComponentInParent<FVRFireArmMagazine>();
			for (int i = 0; i < Mathf.Min(componentInParent.LoadedRounds.Length, componentInParent2.LoadedRounds.Length); i++)
			{
				if (componentInParent2.LoadedRounds[i] == null)
				{
					componentInParent2.LoadedRounds[i] = new FVRLoadedRound();
				}
			}
		}

		[HarmonyPatch(typeof(MultiCaliberMagazineMWCompatibility), "AdditionalRoundsFromMagExtension")]
		[HarmonyPostfix]
		public static void AdditionalRoundsFromMagExtensionPatch(MultiCaliberMagazine multiCaliberMagazine, ref int __result)
		{
			if (_existingMagazineExtensions.Contains(multiCaliberMagazine.Magazine))
			{
				ModularMagazineExtension[] componentsInChildren = ((Component)multiCaliberMagazine.Magazine).GetComponentsInChildren<ModularMagazineExtension>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					__result += componentsInChildren[i].AdditionalNumberOfRoundsInMagazine;
				}
			}
		}
	}
	public class ModularBayonet : ModularWeaponPart
	{
		[Header("Bayonet Config")]
		[Tooltip("HandPoint will be automatically set to the old hand point.")]
		public MeleeParams MeleeParams;

		private MeleeParams _origMeleeParams;

		protected FVRPhysicalObject _physicalObject;

		public override void EnablePart()
		{
			base.EnablePart();
			_physicalObject = ((Component)((Component)this).transform).GetComponentInParent<FVRPhysicalObject>();
			if ((Object)(object)_physicalObject != (Object)null)
			{
				_origMeleeParams = _physicalObject.MP;
				MeleeParams.HandPoint = _origMeleeParams.HandPoint;
				_physicalObject.MP = MeleeParams;
			}
			else if ((Object)(object)_physicalObject == (Object)null)
			{
				ModularWorkshopManager.LogWarning((MonoBehaviour)(object)this, "Firearm not found! ModularBayonet disabled!");
			}
		}

		public override void DisablePart()
		{
			base.DisablePart();
			_physicalObject = ((Component)((Component)this).transform).GetComponentInParent<FVRPhysicalObject>();
			if ((Object)(object)_physicalObject != (Object)null)
			{
				_physicalObject.MP = _origMeleeParams;
			}
		}
	}
	public class ModularHandguardExtension : ModularWeaponPart
	{
		public enum EColliderType
		{
			Sphere,
			Capsule,
			Box
		}

		[Header("Handguard Extension Config")]
		[Tooltip("This GameObject defines where the extension of the AltGrip trigger will end up. It should contain a trigger to define what the new handguard interaction zone looks like. Gets removed on load for performance reasons, so don't put anything below it.")]
		public GameObject ForeGripExtensionDefinition;

		[HideInInspector]
		public TransformProxy ForeGripExtensionTransformProxy;

		[HideInInspector]
		public Vector3 TriggerCenter;

		[HideInInspector]
		public Vector3 TriggerSize;

		[HideInInspector]
		public Axis ColliderAxis;

		[HideInInspector]
		public EColliderType ColliderType;

		private FVRFireArm _firearm;

		private Collider _addedCollider;

		public override void Awake()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			base.Awake();
			if ((Object)(object)ForeGripExtensionDefinition != (Object)null)
			{
				ForeGripExtensionTransformProxy = new TransformProxy(ForeGripExtensionDefinition.transform, false);
				Collider component = ForeGripExtensionDefinition.GetComponent<Collider>();
				CapsuleCollider val = (CapsuleCollider)(object)((component is CapsuleCollider) ? component : null);
				if (val == null)
				{
					SphereCollider val2 = (SphereCollider)(object)((component is SphereCollider) ? component : null);
					if (val2 == null)
					{
						BoxCollider val3 = (BoxCollider)(object)((component is BoxCollider) ? component : null);
						if (val3 == null)
						{
							if (component == null)
							{
								ModularWorkshopManager.LogWarning((MonoBehaviour)(object)this, "ForeGripDefinition " + ((Object)ForeGripExtensionDefinition).name + " doesn't contain a collider you goofus! Shit's about to break!");
							}
						}
						else
						{
							TriggerCenter = val3.center;
							TriggerSize = val3.size;
							ColliderType = EColliderType.Box;
						}
					}
					else
					{
						TriggerCenter = val2.center;
						TriggerSize = new Vector3(val2.radius, 0f, 0f);
						ColliderType = EColliderType.Sphere;
					}
				}
				else
				{
					TriggerCenter = val.center;
					TriggerSize = new Vector3(val.radius, val.height, 0f);
					ColliderType = EColliderType.Capsule;
					ColliderAxis = (Axis)(val.direction switch
					{
						0 => 0, 
						1 => 1, 
						2 => 2, 
						_ => 0, 
					});
				}
				Object.Destroy((Object)(object)ForeGripExtensionDefinition);
			}
			else if ((Object)(object)ForeGripExtensionDefinition == (Object)null)
			{
				ModularWorkshopManager.LogError((MonoBehaviour)(object)this, "ForeGripExtensionDefinition is empty but you want this to be a functional foregrip extension you goofus! Shit's about to break!");
			}
		}

		public override void EnablePart()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Expected I4, but got Unknown
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			base.EnablePart();
			if (UnityEngineExtensions.TryGetComponentInParent<FVRFireArm>((Component)(object)((Component)this).transform, ref _firearm))
			{
				Vector3 val = ForeGripExtensionTransformProxy.parent.TransformPoint(ForeGripExtensionTransformProxy.localPosition + UnityEngineExtensions.MultiplyComponentWise(TriggerCenter, ForeGripExtensionTransformProxy.localScale));
				Vector3 center = _firearm.Foregrip.transform.InverseTransformPoint(val);
				switch (ColliderType)
				{
				case EColliderType.Sphere:
				{
					_addedCollider = (Collider)(object)_firearm.Foregrip.AddComponent<SphereCollider>();
					Collider addedCollider7 = _addedCollider;
					((SphereCollider)((addedCollider7 is SphereCollider) ? addedCollider7 : null)).center = center;
					Collider addedCollider8 = _addedCollider;
					((SphereCollider)((addedCollider8 is SphereCollider) ? addedCollider8 : null)).radius = TriggerSize.x;
					break;
				}
				case EColliderType.Capsule:
				{
					_addedCollider = (Collider)(object)_firearm.Foregrip.AddComponent<CapsuleCollider>();
					Collider addedCollider3 = _addedCollider;
					((CapsuleCollider)((addedCollider3 is CapsuleCollider) ? addedCollider3 : null)).center = center;
					Collider addedCollider4 = _addedCollider;
					((CapsuleCollider)((addedCollider4 is CapsuleCollider) ? addedCollider4 : null)).radius = TriggerSize.x;
					Collider addedCollider5 = _addedCollider;
					((CapsuleCollider)((addedCollider5 is CapsuleCollider) ? addedCollider5 : null)).height = TriggerSize.y;
					Collider addedCollider6 = _addedCollider;
					((CapsuleCollider)((addedCollider6 is CapsuleCollider) ? addedCollider6 : null)).direction = (int)ColliderAxis;
					break;
				}
				case EColliderType.Box:
				{
					_addedCollider = (Collider)(object)_firearm.Foregrip.AddComponent<BoxCollider>();
					Collider addedCollider = _addedCollider;
					((BoxCollider)((addedCollider is BoxCollider) ? addedCollider : null)).center = center;
					Collider addedCollider2 = _addedCollider;
					((BoxCollider)((addedCollider2 is BoxCollider) ? addedCollider2 : null)).size = TriggerSize;
					break;
				}
				}
				_addedCollider.isTrigger = true;
			}
			else if ((Object)(object)_firearm == (Object)null)
			{
				ModularWorkshopManager.LogWarning((MonoBehaviour)(object)this, "Firearm not found! ModularHandguardExtension disabled!");
			}
		}

		public override void DisablePart()
		{
			base.DisablePart();
			if ((Object)(object)_addedCollider != (Object)null)
			{
				Object.Destroy((Object)(object)_addedCollider);
			}
		}
	}
	[CreateAssetMenu(fileName = "New ModularWorkshopCategoryDefinition", menuName = "ModularWorkshop/ModularWorkshopCategoryDefinition", order = 0)]
	public class ModularWorkshopCategoryDefinition : ScriptableObject
	{
		public string ModularPartsGroupID;

		public string CategoryName;

		public Sprite CategoryIcon;

		public List<string> ModularWeaponPartNames;

		public Dictionary<string, GameObject> CategoryPartsDictionary
		{
			get
			{
				Dictionary<string, GameObject> dictionary = new Dictionary<string, GameObject>();
				foreach (GameObject modularPrefab in ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary[ModularPartsGroupID].ModularPrefabs)
				{
					string name = modularPrefab.GetComponent<ModularWeaponPart>().Name;
					try
					{
						dictionary.Add(name, modularPrefab);
					}
					catch (ArgumentException)
					{
						ModularWorkshopManager.LogWarning("Part with name \"" + name + "\" already in category parts dictionary! Skipping duplicate part!");
					}
				}
				return dictionary;
			}
		}
	}
	public class ModularFVRPhysicalObject : MonoBehaviour
	{
		public FVRPhysicalObject MainObject;

		public GameObject UIPrefab;

		[Header("Receiver Skins")]
		[Tooltip("This is a combination of ModularPartsGroupID and PartName of a Skins definition, with a \"/\" in between. A requirement of the system. You should choose ModularPartsGroupID and PartName so that it doesn't conflict with anything else. Formatting Example: \"ModularPartsGroupID/PartName\". I would personally recommend something like \"ItemID/ReceiverName\" as a standard.")]
		public string SkinPath;

		public Transform ReceiverSkinUIPoint;

		[HideInInspector]
		public TransformProxy ReceiverSkinUIPointProxy;

		public string CurrentSelectedReceiverSkinID = "Default";

		[Tooltip("Can be populated with the context menu on the gun.")]
		public MeshRenderer[] ReceiverMeshRenderers;

		public ModularWeaponPartsAttachmentPoint[] ModularWeaponPartsAttachmentPoints;

		[HideInInspector]
		public List<ModularWeaponPartsAttachmentPoint> SubAttachmentPoints;

		[HideInInspector]
		public ModularWorkshopPlatform WorkshopPlatform;

		private static readonly Dictionary<FVRPhysicalObject, ModularFVRPhysicalObject> _existingModularPhysicalObjects = new Dictionary<FVRPhysicalObject, ModularFVRPhysicalObject>();

		[HideInInspector]
		public bool IsInTakeAndHold;

		[HideInInspector]
		public bool WasUnvaulted;

		public ModularWorkshopSkinsDefinition ReceiverSkinsDefinition
		{
			get
			{
				if (ModularWorkshopManager.ModularWorkshopSkinsDictionary.TryGetValue(SkinPath, out var value))
				{
					return value;
				}
				ModularWorkshopManager.LogError((MonoBehaviour)(object)MainObject, "No Receiver SkinsDefinition found for " + SkinPath + "!");
				return null;
			}
		}

		public Dictionary<string, ModularWeaponPartsAttachmentPoint> AllAttachmentPoints
		{
			get
			{
				Dictionary<string, ModularWeaponPartsAttachmentPoint> dictionary = new Dictionary<string, ModularWeaponPartsAttachmentPoint>();
				ModularWeaponPartsAttachmentPoint[] modularWeaponPartsAttachmentPoints = ModularWeaponPartsAttachmentPoints;
				foreach (ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint in modularWeaponPartsAttachmentPoints)
				{
					try
					{
						dictionary.Add(modularWeaponPartsAttachmentPoint.ModularPartsGroupID, modularWeaponPartsAttachmentPoint);
					}
					catch (Exception)
					{
						ModularWorkshopManager.LogError((MonoBehaviour)(object)MainObject, "PartPoint for ModularPartsGroupID " + modularWeaponPartsAttachmentPoint.ModularPartsGroupID + " already in AllAttachmentPoints dictionary!");
					}
				}
				foreach (ModularWeaponPartsAttachmentPoint subAttachmentPoint in SubAttachmentPoints)
				{
					try
					{
						dictionary.Add(subAttachmentPoint.ModularPartsGroupID, subAttachmentPoint);
					}
					catch (Exception)
					{
						ModularWorkshopManager.LogError((MonoBehaviour)(object)MainObject, "SubPartPoint for ModularPartsGroupID " + subAttachmentPoint.ModularPartsGroupID + " already in AllAttachmentPoints dictionary!");
					}
				}
				return dictionary;
			}
		}

		[HideInInspector]
		public event PartAdded PartAdded;

		public void Awake()
		{
			if ((Object)(object)MainObject == (Object)null)
			{
				MainObject = ((Component)this).GetComponent<FVRPhysicalObject>();
			}
			_existingModularPhysicalObjects.Add(MainObject, this);
			if (SkinPath == null && (Object)(object)MainObject != (Object)null && (Object)(object)MainObject.ObjectWrapper != (Object)null)
			{
				SkinPath = MainObject.ObjectWrapper.ItemID + "/Receiver";
			}
			if (ReceiverMeshRenderers == null || ReceiverMeshRenderers.Length == 0)
			{
				GetReceiverMeshRenderers();
			}
			CheckForDefaultReceiverSkin(MainObject);
			if ((Object)(object)GM.TNH_Manager != (Object)null)
			{
				IsInTakeAndHold = ModularWorkshopManager.EnableTNHRandomization.Value;
			}
		}

		public void Start()
		{
			if ((Object)(object)MainObject.ObjectWrapper == (Object)null)
			{
				Object.Destroy((Object)(object)this);
				return;
			}
			ConvertTransformsToProxies();
			if (!WasUnvaulted)
			{
				ApplyReceiverSkin(IsInTakeAndHold ? ReceiverSkinsDefinition.GetRandomSkin() : CurrentSelectedReceiverSkinID);
				ConfigureAll();
			}
		}

		public void ConfigureAll()
		{
			ModularWeaponPartsAttachmentPoint[] modularWeaponPartsAttachmentPoints = ModularWeaponPartsAttachmentPoints;
			foreach (ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint in modularWeaponPartsAttachmentPoints)
			{
				if (!modularWeaponPartsAttachmentPoint.IsPointDisabled)
				{
					if (ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary.TryGetValue(modularWeaponPartsAttachmentPoint.ModularPartsGroupID, out var value) && value.PartsDictionary.Count > 0)
					{
						string selectedPart = ((IsInTakeAndHold && !WasUnvaulted && !modularWeaponPartsAttachmentPoint.DisallowTakeAndHoldRandomization) ? ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary[modularWeaponPartsAttachmentPoint.ModularPartsGroupID].GetRandomPart() : modularWeaponPartsAttachmentPoint.SelectedModularWeaponPart);
						ConfigureModularWeaponPart(modularWeaponPartsAttachmentPoint, selectedPart, IsInTakeAndHold);
					}