Decompiled source of ModularWorkshop v1.1.5

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
{
	[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;
					}
					_firearm = value;
					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;
							}
						}
						else
						{
							val5.FireSelector_Modes = (FireSelectorMode[])_originalFireModes;
						}
					}
					else
					{
						val4.FireSelector_Modes = (FireSelectorMode[])_originalFireModes;
					}
				}
			}
		}

		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;
					}
				}
			}
		}
	}
	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. (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()
		{
			_magazine = ((Component)((Component)this).transform).GetComponentInParent<FVRFireArmMagazine>();
			_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!");
			}
		}

		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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			if (!_existingMagazineExtensions.Contains((FVRFireArmMagazine)(object)((__instance is FVRFireArmMagazine) ? __instance : null)))
			{
				return;
			}
			FVRFireArmMagazine component = ((Component)__instance).GetComponent<FVRFireArmMagazine>();
			FVRFireArmMagazine component2 = __result.GetComponent<FVRFireArmMagazine>();
			for (int i = 0; i < Mathf.Min(component.LoadedRounds.Length, component2.LoadedRounds.Length); i++)
			{
				if (component2.LoadedRounds[i] == null)
				{
					component2.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);
					}
					else if (ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary.ContainsKey(modularWeaponPartsAttachmentPoint.ModularPartsGroupID) && value.PartsDictionary.Count == 0)
					{
						ModularWorkshopManager.LogError((MonoBehaviour)(object)this, "PartsAttachmentPoint Error: Parts group \"" + modularWeaponPartsAttachmentPoint.ModularPartsGroupID + "\" found in ModularWorkshopManager dictionary, but it is empty!");
						modularWeaponPartsAttachmentPoint.IsPointDisabled = true;
					}
					else if (!ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary.ContainsKey(modularWeaponPartsAttachmentPoint.ModularPartsGroupID) && modularWeaponPartsAttachmentPoint.UsesExternalParts)
					{
						ModularWorkshopManager.Log((MonoBehaviour)(object)this, "PartsAttachmentPoint Info: Parts group \"" + modularWeaponPartsAttachmentPoint.ModularPartsGroupID + "\" disabled due to using external parts and no external parts found.");
						modularWeaponPartsAttachmentPoint.IsPointDisabled = true;
					}
					else if (!ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary.ContainsKey(modularWeaponPartsAttachmentPoint.ModularPartsGroupID))
					{
						ModularWorkshopManager.LogWarning((MonoBehaviour)(object)this, "PartsAttachmentPoint Warning: Parts group \"" + modularWeaponPartsAttachmentPoint.ModularPartsGroupID + "\" not found in ModularWorkshopManager dictionary! Disabling part point!");
						modularWeaponPartsAttachmentPoint.IsPointDisabled = true;
					}
				}
			}
		}

		public void OnDestroy()
		{
			_existingModularPhysicalObjects.Remove(MainObject);
		}

		public void ApplyReceiverSkin(string skinName)
		{
			if (ReceiverSkinsDefinition.SkinDictionary.TryGetValue(skinName, out var value))
			{
				try
				{
					for (int i = 0; i < ReceiverMeshRenderers.Length; i++)
					{
						((Renderer)ReceiverMeshRenderers[i]).materials = value.DifferentSkinnedMeshPieces[i].Materials;
					}
					CurrentSelectedReceiverSkinID = skinName;
					return;
				}
				catch (Exception)
				{
					ModularWorkshopManager.LogError((MonoBehaviour)(object)this, $"Number of DifferentSkinnedMeshPieces in SkinDefinition \"{value.ModularSkinID}\" does not match number of meshes on Receiver! ({ReceiverMeshRenderers.Length} vs {value.DifferentSkinnedMeshPieces.Length})");
					return;
				}
			}
			ModularWorkshopManager.LogError((MonoBehaviour)(object)this, "Skin with name \"" + skinName + "\" not found in SkinsDefinition \"" + ((Object)ReceiverSkinsDefinition).name + "\"!");
		}

		public void CheckForDefaultReceiverSkin(FVRPhysicalObject physicalObject)
		{
			if (CurrentSelectedReceiverSkinID == "Default" && ModularWorkshopManager.ModularWorkshopSkinsDictionary.TryGetValue(SkinPath, out var value))
			{
				if (!value.SkinDictionary.ContainsKey("Default"))
				{
					ModularWorkshopSkinsDefinition.SkinDefinition skinDefinition = new ModularWorkshopSkinsDefinition.SkinDefinition
					{
						ModularSkinID = "Default",
						DisplayName = "Default",
						Icon = MiscUtilities.CreateEmptySprite()
					};
					ModularWorkshopSkinsDefinition.MeshSkin[] array = new ModularWorkshopSkinsDefinition.MeshSkin[ReceiverMeshRenderers.Length];
					for (int i = 0; i < ReceiverMeshRenderers.Length; i++)
					{
						ModularWorkshopSkinsDefinition.MeshSkin meshSkin = new ModularWorkshopSkinsDefinition.MeshSkin
						{
							Materials = ((Renderer)ReceiverMeshRenderers[i]).sharedMaterials
						};
						array[i] = meshSkin;
					}
					skinDefinition.DifferentSkinnedMeshPieces = array;
					value.SkinDefinitions.Insert(0, skinDefinition);
				}
			}
			else if (CurrentSelectedReceiverSkinID == "Default")
			{
				ModularWorkshopSkinsDefinition.SkinDefinition skinDefinition2 = new ModularWorkshopSkinsDefinition.SkinDefinition
				{
					ModularSkinID = "Default",
					DisplayName = "Default",
					Icon = MiscUtilities.CreateEmptySprite()
				};
				ModularWorkshopSkinsDefinition.MeshSkin[] array2 = new ModularWorkshopSkinsDefinition.MeshSkin[ReceiverMeshRenderers.Length];
				for (int j = 0; j < ReceiverMeshRenderers.Length; j++)
				{
					ModularWorkshopSkinsDefinition.MeshSkin meshSkin2 = new ModularWorkshopSkinsDefinition.MeshSkin
					{
						Materials = ((Renderer)ReceiverMeshRenderers[j]).sharedMaterials
					};
					array2[j] = meshSkin2;
				}
				skinDefinition2.DifferentSkinnedMeshPieces = array2;
				value = ScriptableObject.CreateInstance<ModularWorkshopSkinsDefinition>();
				string[] array3 = SkinPath.Split(new char[1] { '/' });
				((Object)value).name = array3[0] + "/" + array3[1];
				value.ModularPartsGroupID = array3[0];
				value.PartName = array3[1];
				value.SkinDefinitions = new List<ModularWorkshopSkinsDefinition.SkinDefinition> { skinDefinition2 };
				value.AutomaticallyCreated = true;
				ModularWorkshopManager.ModularWorkshopSkinsDictionary.Add(SkinPath, value);
			}
			else if (CurrentSelectedReceiverSkinID != "Default" && !ModularWorkshopManager.ModularWorkshopSkinsDictionary.ContainsKey(SkinPath))
			{
				ModularWorkshopManager.LogWarning((MonoBehaviour)(object)this, "No SkinsDefinition found for receiver skin path \"" + SkinPath + "\", but part receiver \"" + ((Object)((Component)physicalObject).gameObject).name + "\" set to skin name \"" + CurrentSelectedReceiverSkinID + "\". Naming error?");
			}
		}

		public void GetReceiverMeshRenderers()
		{
			List<MeshRenderer> ignoredMeshRenderers = new List<MeshRenderer>();
			ModularWeaponPart[] componentsInChildren = ((Component)this).GetComponentsInChildren<ModularWeaponPart>();
			foreach (ModularWeaponPart modularWeaponPart in componentsInChildren)
			{
				ignoredMeshRenderers.AddRange(from m in ((Component)modularWeaponPart).GetComponentsInChildren<MeshRenderer>()
					where ((Renderer)m).enabled
					select m);
			}
			FVRFireArmAttachment[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<FVRFireArmAttachment>();
			foreach (FVRFireArmAttachment val in componentsInChildren2)
			{
				ignoredMeshRenderers.AddRange(from m in ((Component)val).GetComponentsInChildren<MeshRenderer>()
					where ((Renderer)m).enabled
					select m);
			}
			FVRFireArmChamber[] componentsInChildren3 = ((Component)this).GetComponentsInChildren<FVRFireArmChamber>();
			foreach (FVRFireArmChamber val2 in componentsInChildren3)
			{
				ignoredMeshRenderers.AddRange(from m in ((Component)val2).GetComponentsInChildren<MeshRenderer>()
					where ((Renderer)m).enabled
					select m);
			}
			FVRFirearmMovingProxyRound[] componentsInChildren4 = ((Component)this).GetComponentsInChildren<FVRFirearmMovingProxyRound>();
			foreach (FVRFirearmMovingProxyRound val3 in componentsInChildren4)
			{
				ignoredMeshRenderers.AddRange(from m in ((Component)val3).GetComponentsInChildren<MeshRenderer>()
					where ((Renderer)m).enabled
					select m);
			}
			FVRPhysicalObject mainObject = MainObject;
			FVRFireArmMagazine val4 = (FVRFireArmMagazine)(object)((mainObject is FVRFireArmMagazine) ? mainObject : null);
			if (val4 != null)
			{
				ignoredMeshRenderers.AddRange(val4.DisplayRenderers.OfType<MeshRenderer>());
			}
			ReceiverMeshRenderers = (from m in ((Component)this).GetComponentsInChildren<MeshRenderer>()
				where ((Renderer)m).enabled
				where !ignoredMeshRenderers.Contains(m)
				select m).ToArray();
		}

		[ContextMenu("Populate Receiver Mesh Renderer List")]
		public void PopulateReceiverMeshList()
		{
			GetReceiverMeshRenderers();
		}

		public ModularWeaponPart ConfigureModularWeaponPart(ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint, string selectedPart, bool isRandomized = false, Dictionary<string, string> oldSubParts = null, Dictionary<string, string> oldSkins = null)
		{
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			if (ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary.TryGetValue(modularWeaponPartsAttachmentPoint.ModularPartsGroupID, out var value))
			{
				if (!value.PartsDictionary.ContainsKey(selectedPart))
				{
					ModularWorkshopManager.LogError((MonoBehaviour)(object)this, "PartsAttachmentPoint Error: Parts group \"" + modularWeaponPartsAttachmentPoint.ModularPartsGroupID + "\" does not contain part with name \"" + selectedPart + "\"");
					return null;
				}
			}
			else
			{
				if (selectedPart != string.Empty && modularWeaponPartsAttachmentPoint.UsesExternalParts)
				{
					ModularWorkshopManager.Log((MonoBehaviour)(object)this, "PartsAttachmentPoint Info: Parts group \"" + modularWeaponPartsAttachmentPoint.ModularPartsGroupID + "\" disabled due to using external parts and no external parts found.");
					modularWeaponPartsAttachmentPoint.IsPointDisabled = true;
					return null;
				}
				if (selectedPart != string.Empty)
				{
					ModularWorkshopManager.LogError((MonoBehaviour)(object)this, "PartsAttachmentPoint Error: Parts group \"" + modularWeaponPartsAttachmentPoint.ModularPartsGroupID + "\" not found in ModularWorkshopManager dictionary!");
					return null;
				}
				if (selectedPart == string.Empty || modularWeaponPartsAttachmentPoint.SelectedModularWeaponPart == string.Empty)
				{
					ModularWorkshopManager.LogWarning((MonoBehaviour)(object)this, "PartsAttachmentPoint Warning: Parts group \"" + modularWeaponPartsAttachmentPoint.ModularPartsGroupID + "\" not found in ModularWorkshopManager dictionary, but current part name also empty. Treating as future attachment point!");
					modularWeaponPartsAttachmentPoint.IsPointDisabled = true;
					return null;
				}
			}
			if (oldSubParts == null)
			{
				oldSubParts = new Dictionary<string, string>();
			}
			if (oldSkins == null)
			{
				oldSkins = new Dictionary<string, string>();
			}
			ModularWeaponPart componentInChildren = ((Component)modularWeaponPartsAttachmentPoint.ModularPartPoint).GetComponentInChildren<ModularWeaponPart>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.DisablePart();
				RemovePartPointOccupation(componentInChildren);
				if (!oldSkins.ContainsKey(modularWeaponPartsAttachmentPoint.ModularPartsGroupID))
				{
					oldSkins.Add(modularWeaponPartsAttachmentPoint.ModularPartsGroupID, modularWeaponPartsAttachmentPoint.CurrentSkin);
				}
				ModularWeaponPartsAttachmentPoint[] subAttachmentPoints = componentInChildren.SubAttachmentPoints;
				foreach (ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint2 in subAttachmentPoints)
				{
					oldSubParts.Add(modularWeaponPartsAttachmentPoint2.ModularPartsGroupID, modularWeaponPartsAttachmentPoint2.SelectedModularWeaponPart);
					oldSkins.Add(modularWeaponPartsAttachmentPoint2.ModularPartsGroupID, modularWeaponPartsAttachmentPoint2.CurrentSkin);
					RemoveSubAttachmentPoint(modularWeaponPartsAttachmentPoint2, MainObject, oldSubParts);
				}
			}
			ModularWeaponPart component = Object.Instantiate<GameObject>(value.PartsDictionary[selectedPart], modularWeaponPartsAttachmentPoint.ModularPartPoint.position, modularWeaponPartsAttachmentPoint.ModularPartPoint.rotation, modularWeaponPartsAttachmentPoint.ModularPartPoint.parent).GetComponent<ModularWeaponPart>();
			component.AdjustScale(modularWeaponPartsAttachmentPoint);
			modularWeaponPartsAttachmentPoint.SelectedModularWeaponPart = selectedPart;
			UpdateMainObject(componentInChildren, component);
			Object.Destroy((Object)(object)((Component)modularWeaponPartsAttachmentPoint.ModularPartPoint).gameObject);
			modularWeaponPartsAttachmentPoint.ModularPartPoint = ((Component)component).transform;
			component.EnablePart();
			ApplyPartPointOccupation(component);
			TryApplyOldSkin(modularWeaponPartsAttachmentPoint, selectedPart, oldSkins, isRandomized);
			ConfigureNewSubParts(component, oldSubParts, oldSkins, isRandomized);
			this.PartAdded?.Invoke(modularWeaponPartsAttachmentPoint, component);
			MainObject.ResetClampCOM();
			return component;
		}

		private ModularWeaponPart OldPartOperations(ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint, Dictionary<string, string> oldSubParts, Dictionary<string, string> oldSkins)
		{
			ModularWeaponPart oldPart = ((Component)modularWeaponPartsAttachmentPoint.ModularPartPoint).GetComponentInChildren<ModularWeaponPart>();
			if ((Object)(object)oldPart != (Object)null)
			{
				oldPart.DisablePart();
				RemovePartPointOccupation(oldPart);
				if (!oldSkins.ContainsKey(modularWeaponPartsAttachmentPoint.ModularPartsGroupID))
				{
					oldSkins.Add(modularWeaponPartsAttachmentPoint.ModularPartsGroupID, modularWeaponPartsAttachmentPoint.CurrentSkin);
				}
				ModularWeaponPartsAttachmentPoint[] subAttachmentPoints = oldPart.SubAttachmentPoints;
				foreach (ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint2 in subAttachmentPoints)
				{
					oldSubParts.Add(modularWeaponPartsAttachmentPoint2.ModularPartsGroupID, modularWeaponPartsAttachmentPoint2.SelectedModularWeaponPart);
					oldSkins.Add(modularWeaponPartsAttachmentPoint2.ModularPartsGroupID, modularWeaponPartsAttachmentPoint2.CurrentSkin);
					RemoveSubAttachmentPoint(modularWeaponPartsAttachmentPoint2, MainObject, oldSubParts);
				}
				FVRFireArmAttachmentMount[] attachmentMounts = oldPart.AttachmentMounts;
				foreach (FVRFireArmAttachmentMount val in attachmentMounts)
				{
					DetachAllAttachmentsFromMount(val);
					MainObject.AttachmentMounts.Remove(val);
				}
				MainObject.Slots = MainObject.Slots.Where((FVRQuickBeltSlot s) => !oldPart.SubQuickBeltSlots.Contains(s)).ToArray();
				IPartFireArmRequirement[] components = ((Component)oldPart).GetComponents<IPartFireArmRequirement>();
				for (int i = 0; i < components.Length; i++)
				{
					components[i].FireArm = null;
				}
			}
			return oldPart;
		}

		private ModularWeaponPart NewPartOperations(ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint, ModularWorkshopPartsDefinition partsDefinition, string selectedPart, Dictionary<string, string> oldSubParts, Dictionary<string, string> oldSkins)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			ModularWeaponPart component = Object.Instantiate<GameObject>(partsDefinition.PartsDictionary[selectedPart], modularWeaponPartsAttachmentPoint.ModularPartPoint.position, modularWeaponPartsAttachmentPoint.ModularPartPoint.rotation, modularWeaponPartsAttachmentPoint.ModularPartPoint.parent).GetComponent<ModularWeaponPart>();
			component.AdjustScale(modularWeaponPartsAttachmentPoint);
			modularWeaponPartsAttachmentPoint.SelectedModularWeaponPart = selectedPart;
			Object.Destroy((Object)(object)((Component)modularWeaponPartsAttachmentPoint.ModularPartPoint).gameObject);
			modularWeaponPartsAttachmentPoint.ModularPartPoint = ((Component)component).transform;
			component.EnablePart();
			ApplyPartPointOccupation(component);
			MainObject.AttachmentMounts.AddRange(component.AttachmentMounts);
			FVRFireArmAttachmentMount[] attachmentMounts = component.AttachmentMounts;
			foreach (FVRFireArmAttachmentMount obj in attachmentMounts)
			{
				obj.Parent = MainObject;
				obj.MyObject = MainObject;
			}
			CollectionExtensions.AddRangeToArray<FVRQuickBeltSlot>(MainObject.Slots, component.SubQuickBeltSlots);
			((FVRInteractiveObject)MainObject).m_colliders = ((Component)MainObject).GetComponentsInChildren<Collider>(true);
			if ((Object)(object)MainObject.m_quickbeltSlot != (Object)null)
			{
				((FVRInteractiveObject)MainObject).SetAllCollidersToLayer(false, "NoCol");
			}
			IPartFireArmRequirement[] components = ((Component)component).GetComponents<IPartFireArmRequirement>();
			foreach (IPartFireArmRequirement obj2 in components)
			{
				FVRPhysicalObject mainObject = MainObject;
				obj2.FireArm = (FVRFireArm)(object)((mainObject is FVRFireArm) ? mainObject : null);
			}
			return component;
		}

		public void AddSubAttachmentPoint(ModularWeaponPartsAttachmentPoint subPoint, FVRPhysicalObject fireArm, Dictionary<string, string> oldSubParts, Dictionary<string, string> oldSkins, string selectedPart)
		{
			SubAttachmentPoints.Add(subPoint);
			ConfigureModularWeaponPart(subPoint, selectedPart, Object.op_Implicit((Object)(object)fireArm), oldSubParts, oldSkins);
			WorkshopPlatform?.CreateUIForPoint(subPoint);
		}

		public void RemoveSubAttachmentPoint(ModularWeaponPartsAttachmentPoint subPoint, FVRPhysicalObject fireArm, Dictionary<string, string> oldSubParts)
		{
			SubAttachmentPoints.Remove(subPoint);
			ModularWeaponPart component = ((Component)subPoint.ModularPartPoint).GetComponent<ModularWeaponPart>();
			if ((Object)(object)component != (Object)null)
			{
				component.DisablePart();
				FVRFireArmAttachmentMount[] attachmentMounts = component.AttachmentMounts;
				foreach (FVRFireArmAttachmentMount val in attachmentMounts)
				{
					DetachAllAttachmentsFromMount(val);
					fireArm.AttachmentMounts.Remove(val);
				}
				ModularWeaponPartsAttachmentPoint[] subAttachmentPoints = component.SubAttachmentPoints;
				foreach (ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint in subAttachmentPoints)
				{
					oldSubParts.Add(modularWeaponPartsAttachmentPoint.ModularPartsGroupID, modularWeaponPartsAttachmentPoint.SelectedModularWeaponPart);
					RemoveSubAttachmentPoint(modularWeaponPartsAttachmentPoint, fireArm, oldSubParts);
				}
			}
			WorkshopPlatform?.RemoveUIFromPoint(subPoint);
			Object.Destroy((Object)(object)((Component)subPoint.ModularPartPoint).gameObject);
		}

		private void DetachAllAttachmentsFromMount(FVRFireArmAttachmentMount mount)
		{
			FVRFireArmAttachment[] array = mount.AttachmentsList.ToArray();
			foreach (FVRFireArmAttachment val in array)
			{
				foreach (FVRFireArmAttachmentMount attachmentMount in ((FVRPhysicalObject)val).AttachmentMounts)
				{
					DetachAllAttachmentsFromMount(attachmentMount);
				}
				((FVRInteractiveObject)val).SetAllCollidersToLayer(false, "Default");
				val.DetachFromMount();
			}
		}

		private void RemovePartPointOccupation(ModularWeaponPart part)
		{
			string[] alsoOccupiesPointWithModularPartsGroupIDs = part.AlsoOccupiesPointWithModularPartsGroupIDs;
			foreach (string key in alsoOccupiesPointWithModularPartsGroupIDs)
			{
				if (AllAttachmentPoints.TryGetValue(key, out var value))
				{
					value.IsPointDisabled = false;
					ConfigureModularWeaponPart(value, value.SelectedModularWeaponPart);
					if (!SubAttachmentPoints.Contains(value))
					{
						WorkshopPlatform?.CreateUIForPoint(value, ModularWorkshopUI.EPartType.MainWeaponGeneralAttachmentPoint);
					}
					else
					{
						WorkshopPlatform?.CreateUIForPoint(value);
					}
				}
			}
		}

		private void ApplyPartPointOccupation(ModularWeaponPart part)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_0069: 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)
			string[] alsoOccupiesPointWithModularPartsGroupIDs = part.AlsoOccupiesPointWithModularPartsGroupIDs;
			ModularWeaponPart partToRemove = default(ModularWeaponPart);
			foreach (string key in alsoOccupiesPointWithModularPartsGroupIDs)
			{
				if (!AllAttachmentPoints.TryGetValue(key, out var value))
				{
					continue;
				}
				WorkshopPlatform?.RemoveUIFromPoint(value);
				value.IsPointDisabled = true;
				GameObject val = new GameObject(value.ModularPartsGroupID + "_TempPoint");
				val.transform.position = value.ModularPartPoint.position;
				val.transform.rotation = value.ModularPartPoint.rotation;
				val.transform.parent = value.ModularPartPoint.parent;
				if (UnityEngineExtensions.TryGetComponent<ModularWeaponPart>((Component)(object)value.ModularPartPoint, ref partToRemove))
				{
					FVRFireArmAttachmentMount[] attachmentMounts = partToRemove.AttachmentMounts;
					foreach (FVRFireArmAttachmentMount val2 in attachmentMounts)
					{
						DetachAllAttachmentsFromMount(val2);
						MainObject.AttachmentMounts.Remove(val2);
					}
					MainObject.Slots = MainObject.Slots.Where((FVRQuickBeltSlot s) => !partToRemove.SubQuickBeltSlots.Contains(s)).ToArray();
					IPartFireArmRequirement[] components = ((Component)partToRemove).GetComponents<IPartFireArmRequirement>();
					for (int j = 0; j < components.Length; j++)
					{
						components[j].FireArm = null;
					}
				}
				Object.Destroy((Object)(object)((Component)value.ModularPartPoint).gameObject);
				value.ModularPartPoint = val.transform;
			}
		}

		private void UpdateMainObject(ModularWeaponPart oldPart, ModularWeaponPart newPart)
		{
			FVRFireArmAttachmentMount[] attachmentMounts;
			IPartFireArmRequirement[] components;
			if ((Object)(object)oldPart != (Object)null)
			{
				attachmentMounts = oldPart.AttachmentMounts;
				foreach (FVRFireArmAttachmentMount val in attachmentMounts)
				{
					DetachAllAttachmentsFromMount(val);
					MainObject.AttachmentMounts.Remove(val);
				}
				MainObject.Slots = MainObject.Slots.Where((FVRQuickBeltSlot s) => !oldPart.SubQuickBeltSlots.Contains(s)).ToArray();
				components = ((Component)oldPart).GetComponents<IPartFireArmRequirement>();
				for (int i = 0; i < components.Length; i++)
				{
					components[i].FireArm = null;
				}
			}
			MainObject.AttachmentMounts.AddRange(newPart.AttachmentMounts);
			attachmentMounts = newPart.AttachmentMounts;
			foreach (FVRFireArmAttachmentMount obj in attachmentMounts)
			{
				obj.Parent = MainObject;
				obj.MyObject = MainObject;
			}
			CollectionExtensions.AddRangeToArray<FVRQuickBeltSlot>(MainObject.Slots, newPart.SubQuickBeltSlots);
			((FVRInteractiveObject)MainObject).m_colliders = ((Component)MainObject).GetComponentsInChildren<Collider>(true);
			if ((Object)(object)MainObject.m_quickbeltSlot != (Object)null)
			{
				((FVRInteractiveObject)MainObject).SetAllCollidersToLayer(false, "NoCol");
			}
			FVRPhysicalObject mainObject = MainObject;
			Handgun val2 = (Handgun)(object)((mainObject is Handgun) ? mainObject : null);
			if (val2 != null)
			{
				val2.m_slideCols.Clear();
				val2.InitSlideCols();
			}
			components = ((Component)newPart).GetComponents<IPartFireArmRequirement>();
			foreach (IPartFireArmRequirement obj2 in components)
			{
				FVRPhysicalObject mainObject2 = MainObject;
				obj2.FireArm = (FVRFireArm)(object)((mainObject2 is FVRFireArm) ? mainObject2 : null);
			}
		}

		private void TryApplyOldSkin(ModularWeaponPartsAttachmentPoint point, string selectedPart, Dictionary<string, string> oldSkins, bool isRandomized = false)
		{
			point.CheckForDefaultSkin();
			if (!ModularWorkshopManager.ModularWorkshopSkinsDictionary.TryGetValue(point.SkinPath, out var value))
			{
				return;
			}
			if (!isRandomized)
			{
				if (oldSkins.TryGetValue(point.ModularPartsGroupID, out var value2))
				{
					if (value.SkinDictionary.ContainsKey(value2))
					{
						point.ApplySkin(value2);
					}
					else if (point.PreviousSkins.TryGetValue(selectedPart, out value2) && value.SkinDictionary.ContainsKey(value2))
					{
						point.ApplySkin(value2);
					}
				}
				else if (point.PreviousSkins.TryGetValue(selectedPart, out value2) && value.SkinDictionary.ContainsKey(value2))
				{
					point.ApplySkin(value2);
				}
			}
			else
			{
				point.ApplySkin(value.GetRandomSkin());
			}
		}

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

		private void ConfigureNewSubParts(ModularWeaponPart newPart, Dictionary<string, string> oldSubParts, Dictionary<string, string> oldSkins, bool isRandomized)
		{
			ModularWeaponPartsAttachmentPoint[] subAttachmentPoints = newPart.SubAttachmentPoints;
			foreach (ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint in subAttachmentPoints)
			{
				if (!isRandomized && oldSubParts.TryGetValue(modularWeaponPartsAttachmentPoint.ModularPartsGroupID, out var value) && value != modularWeaponPartsAttachmentPoint.SelectedModularWeaponPart)
				{
					AddSubAttachmentPoint(modularWeaponPartsAttachmentPoint, MainObject, oldSubParts, oldSkins, value);
					continue;
				}
				string selectedPart = (isRandomized ? ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary[modularWeaponPartsAttachmentPoint.ModularPartsGroupID].GetRandomPart() : modularWeaponPartsAttachmentPoint.SelectedModularWeaponPart);
				AddSubAttachmentPoint(modularWeaponPartsAttachmentPoint, MainObject, oldSubParts, oldSkins, selectedPart);
			}
		}

		public void ConvertTransformsToProxies()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			ModularWeaponPartsAttachmentPoint[] modularWeaponPartsAttachmentPoints = ModularWeaponPartsAttachmentPoints;
			foreach (ModularWeaponPartsAttachmentPoint obj in modularWeaponPartsAttachmentPoints)
			{
				obj.ModularPartUIPointProxy = new TransformProxy(obj.ModularPartUIPoint, ((Component)MainObject).transform, true);
			}
			if ((Object)(object)ReceiverSkinUIPoint != (Object)null)
			{
				ReceiverSkinUIPointProxy = new TransformProxy(ReceiverSkinUIPoint, true);
				return;
			}
			GameObject val = new GameObject("UIPoint");
			val.transform.SetParent(((Component)MainObject).transform);
			val.transform.position = ((Component)MainObject).transform.position + -((Component)MainObject).transform.right * 0.1f;
			val.transform.rotation = ((Component)MainObject).transform.rotation * Quaternion.Euler(new Vector3(0f, 90f, 0f));
			ReceiverSkinUIPointProxy = new TransformProxy(val.transform, true);
		}

		[HarmonyPatch(typeof(FVRPhysicalObject), "GetFlagDic")]
		[HarmonyPostfix]
		public static void GetFlagDicPatch(FVRPhysicalObject __instance, ref Dictionary<string, string> __result)
		{
			if (_existingModularPhysicalObjects.TryGetValue(__instance, out var value))
			{
				__result = value.GetFlagDic(__result);
			}
		}

		[HarmonyPatch(typeof(FVRPhysicalObject), "ConfigureFromFlagDic")]
		[HarmonyPostfix]
		public static void ConfigureFromFlagDicPatch(FVRPhysicalObject __instance, Dictionary<string, string> f)
		{
			if (_existingModularPhysicalObjects.TryGetValue(__instance, out var value))
			{
				value.ConfigureFromFlagDic(f);
			}
		}

		[HarmonyPatch(typeof(FVRFireArmAttachment), "ConfigureFromFlagDic")]
		[HarmonyPostfix]
		public static void ConfigureFromFlagDicPatch_Attachment(FVRPhysicalObject __instance, Dictionary<string, string> f)
		{
			if (_existingModularPhysicalObjects.TryGetValue(__instance, out var value))
			{
				value.ConfigureFromFlagDic(f);
			}
		}

		[HarmonyPatch(typeof(FVRPhysicalObject), "DuplicateFromSpawnLock")]
		[HarmonyPostfix]
		public static void DuplicateFromSpawnLockPatch(FVRPhysicalObject __instance, ref GameObject __result)
		{
			if (_existingModularPhysicalObjects.TryGetValue(__instance, out var value))
			{
				__result = value.DuplicateFromSpawnLock(__result);
			}
		}

		public void ConfigureFromFlagDic(Dictionary<string, string> f)
		{
			WasUnvaulted = true;
			ModularWeaponPartsAttachmentPoint[] modularWeaponPartsAttachmentPoints = ModularWeaponPartsAttachmentPoints;
			string value;
			foreach (ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint in modularWeaponPartsAttachmentPoints)
			{
				if (!modularWeaponPartsAttachmentPoint.IsPointDisabled && f.TryGetValue("Modul" + modularWeaponPartsAttachmentPoint.ModularPartsGroupID, out value))
				{
					ConfigureModularWeaponPart(modularWeaponPartsAttachmentPoint, value);
				}
			}
			for (int j = 0; j < SubAttachmentPoints.Count; j++)
			{
				if (!SubAttachmentPoints[j].IsPointDisabled && f.TryGetValue("Modul" + SubAttachmentPoints.ElementAt(j).ModularPartsGroupID, out value))
				{
					ConfigureModularWeaponPart(SubAttachmentPoints.ElementAt(j), value);
				}
			}
			if (SkinPath != null && f.TryGetValue(SkinPath, out var value2))
			{
				ApplyReceiverSkin(value2);
			}
			List<ModularWeaponPartsAttachmentPoint> list = AllAttachmentPoints.Values.ToList();
			list.Sort((ModularWeaponPartsAttachmentPoint x, ModularWeaponPartsAttachmentPoint y) => string.Compare(x.ModularPartsGroupID, y.ModularPartsGroupID));
			List<FVRFireArmAttachmentMount> list2 = new List<FVRFireArmAttachmentMount>();
			foreach (ModularWeaponPartsAttachmentPoint item in list)
			{
				string key = item.ModularPartsGroupID + "/" + item.SelectedModularWeaponPart;
				if (f.TryGetValue(key, out value2))
				{
					item.ApplySkin(value2);
				}
				ModularWeaponPart component = ((Component)item.ModularPartPoint).GetComponent<ModularWeaponPart>();
				if ((Object)(object)component != (Object)null)
				{
					list2.AddRange(component.AttachmentMounts);
				}
			}
			MainObject.AttachmentMounts.RemoveAll(list2.Contains);
			MainObject.AttachmentMounts.AddRange(list2);
		}

		public Dictionary<string, string> GetFlagDic(Dictionary<string, string> flagDic)
		{
			ModularWeaponPartsAttachmentPoint[] modularWeaponPartsAttachmentPoints = ModularWeaponPartsAttachmentPoints;
			ModularWorkshopPartsDefinition value;
			foreach (ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint in modularWeaponPartsAttachmentPoints)
			{
				if (ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary.TryGetValue(modularWeaponPartsAttachmentPoint.ModularPartsGroupID, out value) && value.ModularPrefabs.Count > 0)
				{
					flagDic.Add("Modul" + modularWeaponPartsAttachmentPoint.ModularPartsGroupID, modularWeaponPartsAttachmentPoint.SelectedModularWeaponPart);
				}
			}
			foreach (ModularWeaponPartsAttachmentPoint subAttachmentPoint in SubAttachmentPoints)
			{
				if (ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary.TryGetValue(subAttachmentPoint.ModularPartsGroupID, out value) && value.ModularPrefabs.Count > 0)
				{
					flagDic.Add("Modul" + subAttachmentPoint.ModularPartsGroupID, subAttachmentPoint.SelectedModularWeaponPart);
				}
			}
			flagDic.Add(SkinPath, CurrentSelectedReceiverSkinID);
			List<ModularWeaponPartsAttachmentPoint> list = AllAttachmentPoints.Values.ToList();
			list.Sort((ModularWeaponPartsAttachmentPoint x, ModularWeaponPartsAttachmentPoint y) => string.Compare(x.ModularPartsGroupID, y.ModularPartsGroupID));
			List<FVRFireArmAttachmentMount> list2 = new List<FVRFireArmAttachmentMount>();
			foreach (ModularWeaponPartsAttachmentPoint item in list)
			{
				string key = item.ModularPartsGroupID + "/" + item.SelectedModularWeaponPart;
				string currentSkin = item.CurrentSkin;
				flagDic.Add(key, currentSkin);
				ModularWeaponPart component = ((Component)item.ModularPartPoint).GetComponent<ModularWeaponPart>();
				if ((Object)(object)component != (Object)null)
				{
					list2.AddRange(component.AttachmentMounts);
				}
			}
			MainObject.AttachmentMounts.RemoveAll(list2.Contains);
			MainObject.AttachmentMounts.AddRange(list2);
			return flagDic;
		}

		public GameObject DuplicateFromSpawnLock(GameObject copy)
		{
			ModularFVRPhysicalObject componentInChildren = copy.GetComponentInChildren<ModularFVRPhysicalObject>();
			componentInChildren.WasUnvaulted = true;
			foreach (KeyValuePair<string, ModularWeaponPartsAttachmentPoint> allAttachmentPoint in AllAttachmentPoints)
			{
				string key = allAttachmentPoint.Key;
				ModularWeaponPartsAttachmentPoint modularWeaponPartsAttachmentPoint = componentInChildren.AllAttachmentPoints[key];
				string selectedModularWeaponPart = allAttachmentPoint.Value.SelectedModularWeaponPart;
				string currentSkin = allAttachmentPoint.Value.CurrentSkin;
				if (!modularWeaponPartsAttachmentPoint.IsPointDisabled)
				{
					componentInChildren.ConfigureModularWeaponPart(modularWeaponPartsAttachmentPoint, selectedModularWeaponPart);
					componentInChildren.ApplySkin(key, currentSkin);
				}
			}
			componentInChildren.ApplyReceiverSkin(CurrentSelectedReceiverSkinID);
			return copy;
		}
	}
	public class ReceiverSkinSystem : MonoBehaviour
	{
		[Tooltip("Reference to the main physical object.")]
		public FVRPhysicalObject MainObject;

		[Tooltip("Prefab for the user interface (UI).")]
		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/ItemName\" as a standard.")]
		public string SkinPath;

		[Tooltip("Transform defining the location of the UI.")]
		public Transform ReceiverSkinUIPoint;

		[HideInInspector]
		public TransformProxy ReceiverSkinUIPointProxy;

		[Tooltip("The currently selected receiver skin ID.")]
		public string CurrentSelectedReceiverSkinID = "Default";

		[Tooltip("Mesh renderers for the receiver.\nCan be populated with the context menu on the gun.")]
		public MeshRenderer[] ReceiverMeshRenderers;

		private static readonly Dictionary<FVRPhysicalObject, ReceiverSkinSystem> _existingReceiverSkinSystems = new Dictionary<FVRPhysicalObject, ReceiverSkinSystem>();

		[HideInInspector]
		public bool IsInTakeAndHold;

		[HideInInspector]
		public bool WasUnvaulted;

		public ModularWorkshopSkinsDefinition ReceiverSkinsDefinition
		{
			get
			{
				if ((SkinPath == null || SkinPath == string.Empty) && (Object)(object)MainObject != (Object)null && (Object)(object)MainObject.ObjectWrapper != (Object)null)
				{
					SkinPath = MainObject.ObjectWrapper.ItemID + "/Receiver";
				}
				if (ModularWorkshopManager.ModularWorkshopSkinsDictionary.TryGetValue(SkinPath, out var value))
				{
					return value;
				}
				ModularWorkshopManager.LogError((MonoBehaviour)(object)this, "No Receiver SkinsDefinition found for \"" + SkinPath + "\"!");
				return null;
			}
		}

		public void Awake()
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: 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_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			if ((Object)(object)MainObject == (Object)null)
			{
				MainObject = ((Component)this).GetComponent<FVRPhysicalObject>();
			}
			if ((Object)(object)MainObject == (Object)null || (Object)(object)MainObject.ObjectWrapper == (Object)null)
			{
				Object.Destroy((Object)(object)this);
				return;
			}
			_existingReceiverSkinSystems.Add(MainObject, this);
			if (ReceiverMeshRenderers == null || ReceiverMeshRenderers.Length == 0)
			{
				GetReceiverMeshRenderers();
			}
			if ((Object)(object)GM.TNH_Manager != (Object)null)
			{
				IsInTakeAndHold = ModularWorkshopManager.EnableTNHRandomization.Value;
			}
			if (SkinPath == null || SkinPath == string.Empty)
			{
				SkinPath = MainObject.ObjectWrapper.ItemID + "/Receiver";
			}
			CheckForDefaultReceiverSkin();
			if ((Object)(object)ReceiverSkinUIPoint != (Object)null)
			{
				ReceiverSkinUIPointProxy = new TransformProxy(ReceiverSkinUIPoint, true);
				return;
			}
			GameObject val = new GameObject("temp");
			val.transform.SetParent(((Component)MainObject).transform);
			val.transform.position = ((Component)MainObject).transform.position + -((Component)MainObject).transform.right * 0.1f;
			val.transform.rotation = ((Component)MainObject).transform.rotation * Quaternion.Euler(new Vector3(0f, 90f, 0f));
			ReceiverSkinUIPointProxy = new TransformProxy(val.transform, true);
		}

		public void Start()
		{
			if (!WasUnvaulted)
			{
				ApplyReceiverSkin(IsInTakeAndHold ? ReceiverSkinsDefinition.GetRandomSkin() : CurrentSelectedReceiverSkinID);
			}
		}

		public void OnDestroy()
		{
			_existingReceiverSkinSystems.Remove(MainObject);
		}

		public void ApplyReceiverSkin(string skinName)
		{
			CurrentSelectedReceiverSkinID = skinName;
			if (ReceiverSkinsDefinition.SkinDictionary.TryGetValue(skinName, out var value))
			{
				try
				{
					for (int i = 0; i < ReceiverMeshRenderers.Length; i++)
					{
						((Renderer)ReceiverMeshRenderers[i]).materials = value.DifferentSkinnedMeshPieces[i].Materials;
					}
					return;
				}
				catch (Exception)
				{
					ModularWorkshopManager.LogError((MonoBehaviour)(object)this, $"Number of DifferentSkinnedMeshPieces in SkinDefinition \"{value.ModularSkinID}\" does not match number of meshes on Receiver! ({ReceiverMeshRenderers.Length} vs {value.DifferentSkinnedMeshPieces.Length})");
					return;
				}
			}
			ModularWorkshopManager.LogError((MonoBehaviour)(object)this, "Skin with name \"" + skinName + "\" not found in SkinsDefinition \"" + ((Object)ReceiverSkinsDefinition).name + "\"!");
		}

		public void CheckForDefaultReceiverSkin()
		{
			if (CurrentSelectedReceiverSkinID == "Default" && ModularWorkshopManager.ModularWorkshopSkinsDictionary.TryGetValue(SkinPath, out var value))
			{
				if (!value.SkinDictionary.ContainsKey("Default"))
				{
					ModularWorkshopSkinsDefinition.SkinDefinition skinDefinition = new ModularWorkshopSkinsDefinition.SkinDefinition
					{
						ModularSkinID = "Default",
						DisplayName = "Default",
						Icon = MiscUtilities.CreateEmptySprite()
					};
					ModularWorkshopSkinsDefinition.MeshSkin[] array = new ModularWorkshopSkinsDefinition.MeshSkin[ReceiverMeshRenderers.Length];
					for (int i = 0; i < ReceiverMeshRenderers.Length; i++)
					{
						ModularWorkshopSkinsDefinition.MeshSkin meshSkin = new ModularWorkshopSkinsDefinition.MeshSkin
						{
							Materials = ((Renderer)ReceiverMeshRenderers[i]).sharedMaterials
						};
						array[i] = meshSkin;
					}
					skinDefinition.DifferentSkinnedMeshPieces = array;
					value.SkinDefinitions.Insert(0, skinDefinition);
				}
			}
			else if (CurrentSelectedReceiverSkinID == "Default")
			{
				ModularWorkshopSkinsDefinition.SkinDefinition skinDefinition2 = new ModularWorkshopSkinsDefinition.SkinDefinition
				{
					ModularSkinID = "Default",
					DisplayName = "Default",
					Icon = MiscUtilities.CreateEmptySprite()
				};
				ModularWorkshopSkinsDefinition.MeshSkin[] array2 = new ModularWorkshopSkinsDefinition.MeshSkin[ReceiverMeshRenderers.Length];
				for (int j = 0; j < ReceiverMeshRenderers.Length; j++)
				{
					ModularWorkshopSkinsDefinition.MeshSkin meshSkin2 = new ModularWorkshopSkinsDefinition.MeshSkin
					{
						Materials = ((Renderer)ReceiverMeshRenderers[j]).sharedMaterials
					};
					array2[j] = meshSkin2;
				}
				skinDefinition2.DifferentSkinnedMeshPieces = array2;
				value = ScriptableObject.CreateInstance<ModularWorkshopSkinsDefinition>();
				string[] array3 = SkinPath.Split(new char[1] { '/' });
				((Object)value).name = array3[0] + "/" + array3[1];
				value.ModularPartsGroupID = array3[0];
				value.PartName = array3[1];
				value.SkinDefinitions = new List<ModularWorkshopSkinsDefinition.SkinDefinition> { skinDefinition2 };
				value.AutomaticallyCreated = true;
				ModularWorkshopManager.ModularWorkshopSkinsDictionary.Add(SkinPath, value);
			}
			else if (CurrentSelectedReceiverSkinID != "Default" && !ModularWorkshopManager.ModularWorkshopSkinsDictionary.ContainsKey(SkinPath))
			{
				ModularWorkshopManager.LogWarning((MonoBehaviour)(object)this, "No SkinsDefinition found for receiver skin path \"" + SkinPath + "\", but part receiver \"" + ((Object)((Component)MainObject).gameObject).name + "\" set to skin name \"" + CurrentSelectedReceiverSkinID + "\". Naming error?");
			}
		}

		public void GetReceiverMeshRenderers()
		{
			List<MeshRenderer> ignoredMeshRenderers = new List<MeshRenderer>();
			ModularWeaponPart[] componentsInChildren = ((Component)MainObject).GetComponentsInChildren<ModularWeaponPart>();
			foreach (ModularWeaponPart modularWeaponPart in componentsInChildren)
			{
				ignoredMeshRenderers.AddRange(from m in ((Component)modularWeaponPart).GetComponentsInChildren<MeshRenderer>()
					where ((Renderer)m).enabled
					select m);
			}
			FVRFireArmAttachment[] componentsInChildren2 = ((Component)MainObject).GetComponentsInChildren<FVRFireArmAttachment>();
			foreach (FVRFireArmAttachment val in componentsInChildren2)
			{
				ignoredMeshRenderers.AddRange(from m in ((Component)val).GetComponentsInChildren<MeshRenderer>()
					where ((Renderer)m).enabled
					select m);
			}
			FVRFireArmChamber[] componentsInChildren3 = ((Component)MainObject).GetComponentsInChildren<FVRFireArmChamber>();
			foreach (FVRFireArmChamber val2 in componentsInChildren3)
			{
				ignoredMeshRenderers.AddRange(from m in ((Component)val2).GetComponentsInChildren<MeshRenderer>()
					where ((Renderer)m).enabled
					select m);
			}
			FVRFirearmMovingProxyRound[] componentsInChildren4 = ((Component)MainObject).GetComponentsInChildren<FVRFirearmMovingProxyRound>();
			foreach (FVRFirearmMovingProxyRound val3 in componentsInChildren4)
			{
				ignoredMeshRenderers.AddRange(from m in ((Component)val3).GetComponentsInChildren<MeshRenderer>()
					where ((Renderer)m).enabled
					select m);
			}
			FVRPhysicalObject mainObject = MainObject;
			FVRFireArmMagazine val4 = (FVRFireArmMagazine)(object)((mainObject is FVRFireArmMagazine) ? mainObject : null);
			if (val4 != null)
			{
				ignoredMeshRenderers.AddRange(val4.DisplayRenderers.OfType<MeshRenderer>());
			}
			ReceiverMeshRenderers = (from m in ((Component)this).GetComponentsInChildren<MeshRenderer>()
				where ((Renderer)m).enabled
				where !ignoredMeshRenderers.Contains(m)
				select m).ToArray();
		}

		[ContextMenu("Populate Receiver Mesh Renderer List")]
		public void PopulateReceiverMeshList()
		{
			GetReceiverMeshRenderers();
		}

		[HarmonyPatch(typeof(FVRPhysicalObject), "GetFlagDic")]
		[HarmonyPostfix]
		public static void GetFlagDicPatch(FVRPhysicalObject __instance, ref Dictionary<string, string> __result)
		{
			if (_existingReceiverSkinSystems.TryGetValue(__instance, out var value))
			{
				__result = value.GetFlagDic(__result);
			}
		}

		public Dictionary<string, string> GetFlagDic(Dictionary<string, string> flagDic)
		{
			flagDic.Add(SkinPath, CurrentSelectedReceiverSkinID);
			return flagDic;
		}

		[HarmonyPatch(typeof(FVRPhysicalObject), "ConfigureFromFlagDic")]
		[HarmonyPostfix]
		public static void ConfigureFromFlagDicPatch(FVRPhysicalObject __instance, Dictionary<string, string> f)
		{
			if (_existingReceiverSkinSystems.TryGetValue(__instance, out var value))
			{
				value.ConfigureFromFlagDic(f);
			}
		}

		public void ConfigureFromFlagDic(Dictionary<string, string> f)
		{
			if (SkinPath != null && f.TryGetValue(SkinPath, out var value))
			{
				ApplyReceiverSkin(value);
			}
			WasUnvaulted = true;
		}

		[HarmonyPatch(typeof(FVRPhysicalObject), "DuplicateFromSpawnLock")]
		[HarmonyPostfix]
		public static void DuplicateFromSpawnLockPatch(FVRPhysicalObject __instance, ref GameObject __result)
		{
			if (_existingReceiverSkinSystems.TryGetValue(__instance, out var value))
			{
				__result = value.DuplicateFromSpawnLock(__result);
			}
		}

		public GameObject DuplicateFromSpawnLock(GameObject copy)
		{
			copy.GetComponentInChildren<ReceiverSkinSystem>().ApplyReceiverSkin(CurrentSelectedReceiverSkinID);
			WasUnvaulted = true;
			return copy;
		}
	}
	public class ModularPreattachedAttachments : OpenScripts2_BasePlugin
	{
		public GameObject ModularWeapon;

		[Tooltip("If left empty it will use the firearms own AttachmentMounts.")]
		public string ModularPartsGroupID;

		public int MountIndex;

		public FVRFireArmAttachment[] Attachments;

		private IModularWeapon _modularWeapon;

		public void Start()
		{
			_modularWeapon = ModularWeapon.GetComponent<IModularWeapon>();
			if (!_modularWeapon.GetModularFVRFireArm.WasUnvaulted)
			{
				((MonoBehaviour)this).StartCoroutine("AttachAllToMount");
				return;
			}
			for (int i = 0; i < Attachments.Length; i++)
			{
				Object.Destroy((Object)(object)((Component)Attachments[i]).gameObject);
			}
			Object.Destroy((Object)(object)this);
		}

		public IEnumerator AttachAllToMount()
		{
			yield return null;
			FVRFireArmAttachmentMount[] array = ((ModularPartsGroupID != string.Empty) ? ((Component)_modularWeapon.AllAttachmentPoints[ModularPartsGroupID].ModularPartPoint).GetComponent<ModularWeaponPart>().AttachmentMounts : ((FVRPhysicalObject)_modularWeapon.GetMod