Decompiled source of ModulPU21 v1.0.0

ModulPU21.dll

Decompiled 2 days ago
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using ModularWorkshop;
using OpenScripts2;
using OtherLoader;
using Sodalite.Api;
using UnityEngine;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
public class ForwardAssist : FVRInteractiveObject
{
	[Header("Animation Settings")]
	public Transform TargetTransform;

	public Vector3 StartPosition;

	public Vector3 EndPosition;

	public Vector3 StartRotation;

	public Vector3 EndRotation;

	public float MoveSpeed = 10f;

	public float ResetDelay = 0.2f;

	[Header("Audio Settings")]
	public AudioEvent PokeAudioEvent;

	public FVRPooledAudioType AudioType = (FVRPooledAudioType)0;

	private float m_animFloat = 0f;

	private bool m_isPoked = false;

	private float m_resetTimer = 0f;

	protected void Awake()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		((FVRInteractiveObject)this).Awake();
		if ((Object)(object)TargetTransform == (Object)null)
		{
			TargetTransform = ((Component)this).transform;
		}
		if (StartPosition == Vector3.zero)
		{
			StartPosition = TargetTransform.localPosition;
		}
		if (StartRotation == Vector3.zero)
		{
			StartRotation = TargetTransform.localEulerAngles;
		}
	}

	public override void Poke(FVRViveHand hand)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		if (PokeAudioEvent != null)
		{
			SM.PlayCoreSound(AudioType, PokeAudioEvent, ((Component)this).transform.position);
		}
		m_isPoked = true;
		m_resetTimer = ResetDelay;
	}

	private void Update()
	{
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		if (m_isPoked)
		{
			m_animFloat = Mathf.MoveTowards(m_animFloat, 1f, Time.deltaTime * MoveSpeed);
			m_resetTimer -= Time.deltaTime;
			if (m_resetTimer <= 0f)
			{
				m_isPoked = false;
			}
		}
		else
		{
			m_animFloat = Mathf.MoveTowards(m_animFloat, 0f, Time.deltaTime * MoveSpeed);
		}
		if ((Object)(object)TargetTransform != (Object)null)
		{
			TargetTransform.localPosition = Vector3.Lerp(StartPosition, EndPosition, m_animFloat);
			TargetTransform.localEulerAngles = Vector3.Lerp(StartRotation, EndRotation, m_animFloat);
		}
	}
}
public class AudioConsistencyEnforcer : MonoBehaviour
{
	[Header("Audio Profiles")]
	public FVRFirearmAudioSet BaseHandlingAudioProfile;

	private FVRFireArm _firearm;

	private FVRFirearmAudioSet _lastAudioClipSet;

	private void Awake()
	{
		_firearm = ((Component)this).GetComponent<FVRFireArm>();
		if ((Object)(object)_firearm != (Object)null && (Object)(object)_firearm.AudioClipSet != (Object)null)
		{
			_lastAudioClipSet = _firearm.AudioClipSet;
			BaseHandlingAudioProfile = ScriptableObject.CreateInstance<FVRFirearmAudioSet>();
			SaveBaseHandlingAudio(_lastAudioClipSet);
		}
	}

	private void LateUpdate()
	{
		if ((Object)(object)_firearm == (Object)null)
		{
			return;
		}
		FVRFirearmAudioSet audioClipSet = _firearm.AudioClipSet;
		if (!((Object)(object)audioClipSet == (Object)null))
		{
			if ((Object)(object)audioClipSet != (Object)(object)_lastAudioClipSet)
			{
				_lastAudioClipSet = audioClipSet;
			}
			EnforceHandlingSounds(audioClipSet);
		}
	}

	private void SaveBaseHandlingAudio(FVRFirearmAudioSet source)
	{
		BaseHandlingAudioProfile.BoltRelease = source.BoltRelease;
		BaseHandlingAudioProfile.BoltSlideBack = source.BoltSlideBack;
		BaseHandlingAudioProfile.BoltSlideForward = source.BoltSlideForward;
		BaseHandlingAudioProfile.BoltSlideBackHeld = source.BoltSlideBackHeld;
		BaseHandlingAudioProfile.BoltSlideBackLocked = source.BoltSlideBackLocked;
		BaseHandlingAudioProfile.BreachOpen = source.BreachOpen;
		BaseHandlingAudioProfile.BreachClose = source.BreachClose;
		BaseHandlingAudioProfile.CatchOnSear = source.CatchOnSear;
		BaseHandlingAudioProfile.ChamberManual = source.ChamberManual;
		BaseHandlingAudioProfile.FireSelector = source.FireSelector;
		BaseHandlingAudioProfile.HammerHit = source.HammerHit;
		BaseHandlingAudioProfile.HandleBack = source.HandleBack;
		BaseHandlingAudioProfile.HandleBackEmpty = source.HandleBackEmpty;
		BaseHandlingAudioProfile.HandleForward = source.HandleForward;
		BaseHandlingAudioProfile.HandleForwardEmpty = source.HandleForwardEmpty;
		BaseHandlingAudioProfile.HandleUp = source.HandleUp;
		BaseHandlingAudioProfile.HandleDown = source.HandleDown;
		BaseHandlingAudioProfile.HandleGrab = source.HandleGrab;
		BaseHandlingAudioProfile.Prefire = source.Prefire;
		BaseHandlingAudioProfile.Safety = source.Safety;
		BaseHandlingAudioProfile.TriggerReset = source.TriggerReset;
		BaseHandlingAudioProfile.TopCoverRelease = source.TopCoverRelease;
		BaseHandlingAudioProfile.TopCoverUp = source.TopCoverUp;
		BaseHandlingAudioProfile.TopCoverDown = source.TopCoverDown;
		BaseHandlingAudioProfile.StockOpen = source.StockOpen;
		BaseHandlingAudioProfile.StockClosed = source.StockClosed;
		BaseHandlingAudioProfile.BipodOpen = source.BipodOpen;
		BaseHandlingAudioProfile.BipodClosed = source.BipodClosed;
		BaseHandlingAudioProfile.BeltGrab = source.BeltGrab;
		BaseHandlingAudioProfile.BeltRelease = source.BeltRelease;
		BaseHandlingAudioProfile.BeltSeat = source.BeltSeat;
		BaseHandlingAudioProfile.BeltSettle = source.BeltSettle;
	}

	private void EnforceHandlingSounds(FVRFirearmAudioSet targetProfile)
	{
		targetProfile.BoltRelease = BaseHandlingAudioProfile.BoltRelease;
		targetProfile.BoltSlideBack = BaseHandlingAudioProfile.BoltSlideBack;
		targetProfile.BoltSlideForward = BaseHandlingAudioProfile.BoltSlideForward;
		targetProfile.BoltSlideBackHeld = BaseHandlingAudioProfile.BoltSlideBackHeld;
		targetProfile.BoltSlideBackLocked = BaseHandlingAudioProfile.BoltSlideBackLocked;
		targetProfile.BreachOpen = BaseHandlingAudioProfile.BreachOpen;
		targetProfile.BreachClose = BaseHandlingAudioProfile.BreachClose;
		targetProfile.CatchOnSear = BaseHandlingAudioProfile.CatchOnSear;
		targetProfile.ChamberManual = BaseHandlingAudioProfile.ChamberManual;
		targetProfile.FireSelector = BaseHandlingAudioProfile.FireSelector;
		targetProfile.HammerHit = BaseHandlingAudioProfile.HammerHit;
		targetProfile.HandleBack = BaseHandlingAudioProfile.HandleBack;
		targetProfile.HandleBackEmpty = BaseHandlingAudioProfile.HandleBackEmpty;
		targetProfile.HandleForward = BaseHandlingAudioProfile.HandleForward;
		targetProfile.HandleForwardEmpty = BaseHandlingAudioProfile.HandleForwardEmpty;
		targetProfile.HandleUp = BaseHandlingAudioProfile.HandleUp;
		targetProfile.HandleDown = BaseHandlingAudioProfile.HandleDown;
		targetProfile.HandleGrab = BaseHandlingAudioProfile.HandleGrab;
		targetProfile.Prefire = BaseHandlingAudioProfile.Prefire;
		targetProfile.Safety = BaseHandlingAudioProfile.Safety;
		targetProfile.TriggerReset = BaseHandlingAudioProfile.TriggerReset;
		targetProfile.TopCoverRelease = BaseHandlingAudioProfile.TopCoverRelease;
		targetProfile.TopCoverUp = BaseHandlingAudioProfile.TopCoverUp;
		targetProfile.TopCoverDown = BaseHandlingAudioProfile.TopCoverDown;
		targetProfile.StockOpen = BaseHandlingAudioProfile.StockOpen;
		targetProfile.StockClosed = BaseHandlingAudioProfile.StockClosed;
		targetProfile.BipodOpen = BaseHandlingAudioProfile.BipodOpen;
		targetProfile.BipodClosed = BaseHandlingAudioProfile.BipodClosed;
		targetProfile.BeltGrab = BaseHandlingAudioProfile.BeltGrab;
		targetProfile.BeltRelease = BaseHandlingAudioProfile.BeltRelease;
		targetProfile.BeltSeat = BaseHandlingAudioProfile.BeltSeat;
		targetProfile.BeltSettle = BaseHandlingAudioProfile.BeltSettle;
	}
}
public class SecondaryMagSupport : ModularBarrelExtension
{
	[Header("Secondary Magazine Configuration")]
	public bool ChangesSecondaryMagazine = false;

	public FireArmMagazineType SecondaryMagazineType;

	public Transform CustomSecondaryMagMountPoint;

	public Transform CustomSecondaryMagEjectPoint;

	private FVRFireArm _firearm;

	private Transform _origSecMagMountPos;

	private Transform _origSecMagEjectPos;

	private FireArmMagazineType _origSecondaryMagazineType;

	private bool _hasCachedOriginals = false;

	public override void EnablePart()
	{
		((ModularBarrelExtension)this).EnablePart();
		if (UnityEngineExtensions.TryGetComponentInParent<FVRFireArm>((Component)(object)((Component)this).transform, ref _firearm) && ChangesSecondaryMagazine)
		{
			CacheOriginalSecondaryMagSettings(_firearm);
			UpdateSecondaryMagazine(_firearm);
		}
		else
		{
			Debug.LogWarning((object)"SecondaryMagSupport: Firearm not found or ChangesSecondaryMagazine is false!");
		}
	}

	public override void DisablePart()
	{
		((ModularBarrelExtension)this).DisablePart();
		if ((Object)(object)_firearm != (Object)null && ChangesSecondaryMagazine)
		{
			ResetSecondaryMagazine(_firearm);
		}
	}

	private void CacheOriginalSecondaryMagSettings(FVRFireArm firearm)
	{
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		if (!_hasCachedOriginals && firearm.SecondaryMagazineSlots.Length != 0)
		{
			_origSecMagMountPos = firearm.SecondaryMagazineSlots[0].MagazineMountPos;
			_origSecMagEjectPos = firearm.SecondaryMagazineSlots[0].MagazineEjectPos;
			if ((Object)(object)firearm.SecondaryMagazineSlots[0].Magazine != (Object)null)
			{
				_origSecondaryMagazineType = firearm.SecondaryMagazineSlots[0].Magazine.MagazineType;
			}
			_hasCachedOriginals = true;
		}
	}

	private void UpdateSecondaryMagazine(FVRFireArm firearm)
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		if (firearm.SecondaryMagazineSlots.Length != 0)
		{
			firearm.SecondaryMagazineSlots[0].MagazineMountPos = CustomSecondaryMagMountPoint;
			firearm.SecondaryMagazineSlots[0].MagazineEjectPos = CustomSecondaryMagEjectPoint;
			if ((Object)(object)firearm.SecondaryMagazineSlots[0].Magazine != (Object)null)
			{
				firearm.SecondaryMagazineSlots[0].Magazine.MagazineType = SecondaryMagazineType;
			}
			Debug.Log((object)"SecondaryMagSupport: Secondary magazine settings updated.");
		}
	}

	private void ResetSecondaryMagazine(FVRFireArm firearm)
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		if (_hasCachedOriginals && firearm.SecondaryMagazineSlots.Length != 0)
		{
			firearm.SecondaryMagazineSlots[0].MagazineMountPos = _origSecMagMountPos;
			firearm.SecondaryMagazineSlots[0].MagazineEjectPos = _origSecMagEjectPos;
			if ((Object)(object)firearm.SecondaryMagazineSlots[0].Magazine != (Object)null)
			{
				firearm.SecondaryMagazineSlots[0].Magazine.MagazineType = _origSecondaryMagazineType;
			}
			Debug.Log((object)"SecondaryMagSupport: Secondary magazine settings reset.");
		}
	}
}
public class HeatEffectToggleObject : FirearmHeatingEffect
{
	[Header("Explosion Spawn")]
	public GameObject PrefabToSpawn;

	public Transform SpawnPoint;

	public float ToggleHeatThreshold = 0.95f;

	private bool hasSpawned = false;

	public void Update()
	{
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		((FirearmHeatingEffect)this).Update();
		if (hasSpawned || !(base.Heat >= ToggleHeatThreshold))
		{
			return;
		}
		if ((Object)(object)PrefabToSpawn != (Object)null)
		{
			if ((Object)(object)SpawnPoint != (Object)null)
			{
				Object.Instantiate<GameObject>(PrefabToSpawn, SpawnPoint.position, SpawnPoint.rotation);
			}
			else
			{
				Object.Instantiate<GameObject>(PrefabToSpawn, ((Component)this).transform.position, ((Component)this).transform.rotation);
			}
		}
		hasSpawned = true;
	}
}
public class MGBarrel : MuzzleDevice
{
	[Header("MGBarrel Lock Settings")]
	public float CatchRot;

	public bool IsLocked = false;

	public AudioSource AudSourceLock;

	public AudioClip AudClipLock;

	public Vector3 LockedLocalPosition;

	public Vector3 LockedLocalEulerAngles;

	public float LockAngle = 90f;

	public bool HasPlayedLockSound = false;

	[Header("Loose Barrel Settings")]
	public int ShotsUntilFallOff = 3;

	[HideInInspector]
	public int ShotsFiredWhileLoose = 0;

	protected void Awake()
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		((MuzzleDevice)this).Awake();
		((FVRFireArmAttachment)this).Type = (FVRFireArmAttachementMountType)2;
	}

	public override void AttachToMount(FVRFireArmAttachmentMount m, bool playSound)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		((FVRFireArmAttachment)this).AttachToMount(m, playSound);
		((Component)this).transform.localEulerAngles = new Vector3(0f, 0f, CatchRot);
	}

	public override void OnShot(FVRFireArm f, FVRTailSoundClass tailClass)
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		if (!IsLocked && (Object)(object)((FVRFireArmAttachment)this).curMount != (Object)null)
		{
			ShotsFiredWhileLoose++;
			if (ShotsFiredWhileLoose >= ShotsUntilFallOff)
			{
				((FVRFireArmAttachment)this).DetachFromMount();
			}
		}
		else
		{
			ShotsFiredWhileLoose = 0;
		}
		((MuzzleDevice)this).OnShot(f, tailClass);
	}
}
public class MGBarrelInterface : MuzzleDeviceInterface
{
	private MGBarrel tempBarrel;

	private Vector3 lastHandForward = Vector3.zero;

	private Vector3 lastMountForward = Vector3.zero;

	public AudioClip AudClipUnlock;

	public AudioSource AudSourceUnlock;

	private const float lockThreshold = 2f;

	private const float unlockThreshold = 2f;

	private float lockCooldownTime = 0f;

	private float lockCooldownTimer = 0f;

	public float LockSnapBuffer = 3f;

	public float LockedPreventDetachTime = 0.35f;

	private float lockedGraceTimer = 0f;

	public float UnlockAllowDetachTime = 0.5f;

	private float canBePulledTimer = 0f;

	private Vector3 mountedLocalPosition = Vector3.zero;

	private bool mountedLocalPositionRecorded = false;

	public float DetachDistanceThreshold = 0.08f;

	private bool m_isInSnappingMode = false;

	private bool hasPlayedUnlockSoundThisUnlock = false;

	public float IgnoreDetachOnGrabTime = 0.12f;

	private float ignoreDetachTimer = 0f;

	public override void Awake()
	{
		((FVRFireArmAttachmentInterface)this).Awake();
		tempBarrel = ((FVRFireArmAttachmentInterface)this).Attachment as MGBarrel;
	}

	public override void OnAttach()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		((MuzzleDeviceInterface)this).OnAttach();
		tempBarrel = ((FVRFireArmAttachmentInterface)this).Attachment as MGBarrel;
		if ((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null)
		{
			mountedLocalPosition = ((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localPosition;
			mountedLocalPositionRecorded = true;
			((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localEulerAngles = new Vector3(0f, 0f, (!((Object)(object)tempBarrel != (Object)null)) ? 0f : tempBarrel.CatchRot);
		}
		if ((Object)(object)((FVRInteractiveObject)this).m_hand != (Object)null && ((FVRInteractiveObject)this).IsHeld && (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null && (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount != (Object)null)
		{
			SetSnapping(b: true);
			lastHandForward = ((HandInput)(ref ((FVRInteractiveObject)this).m_hand.Input)).Up;
			lastMountForward = ((Component)((FVRFireArmAttachmentInterface)this).Attachment.curMount).transform.up;
			lockCooldownTimer = 0f;
			lockedGraceTimer = 0f;
			canBePulledTimer = 0f;
			hasPlayedUnlockSoundThisUnlock = false;
			TryLockImmediateOnAttach();
		}
	}

	private void TryLockImmediateOnAttach()
	{
		if ((Object)(object)tempBarrel == (Object)null || (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment == (Object)null || (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount == (Object)null)
		{
			return;
		}
		float lockAngle = tempBarrel.LockAngle;
		float num = 2f + LockSnapBuffer;
		if (tempBarrel.IsLocked)
		{
			return;
		}
		if (lockAngle >= 0f)
		{
			if (tempBarrel.CatchRot >= lockAngle - num)
			{
				DoLock(lockAngle);
			}
		}
		else if (tempBarrel.CatchRot <= lockAngle + num)
		{
			DoLock(lockAngle);
		}
	}

	private void DoLock(float target)
	{
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		tempBarrel.CatchRot = target;
		tempBarrel.IsLocked = true;
		lockedGraceTimer = LockedPreventDetachTime;
		lockCooldownTimer = lockCooldownTime;
		if (mountedLocalPositionRecorded)
		{
			((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localPosition = mountedLocalPosition + tempBarrel.LockedLocalPosition;
		}
		else
		{
			((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localPosition = ((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localPosition + tempBarrel.LockedLocalPosition;
		}
		((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localEulerAngles = new Vector3(0f, 0f, target);
		if (!tempBarrel.HasPlayedLockSound && (Object)(object)tempBarrel.AudSourceLock != (Object)null && (Object)(object)tempBarrel.AudClipLock != (Object)null)
		{
			tempBarrel.AudSourceLock.PlayOneShot(tempBarrel.AudClipLock);
			tempBarrel.HasPlayedLockSound = true;
		}
		canBePulledTimer = 0f;
		hasPlayedUnlockSoundThisUnlock = false;
	}

	private void DoUnlock()
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		tempBarrel.IsLocked = false;
		tempBarrel.HasPlayedLockSound = false;
		tempBarrel.CatchRot = 0f;
		((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localEulerAngles = new Vector3(0f, 0f, 0f);
		if (mountedLocalPositionRecorded)
		{
			((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localPosition = mountedLocalPosition;
		}
		canBePulledTimer = UnlockAllowDetachTime;
		if (!hasPlayedUnlockSoundThisUnlock && (Object)(object)AudSourceUnlock != (Object)null && (Object)(object)AudClipUnlock != (Object)null)
		{
			AudSourceUnlock.PlayOneShot(AudClipUnlock);
			hasPlayedUnlockSoundThisUnlock = true;
		}
	}

	public override void OnDetach()
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)tempBarrel != (Object)null && mountedLocalPositionRecorded && (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null)
		{
			((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localPosition = mountedLocalPosition;
		}
		if ((Object)(object)tempBarrel != (Object)null)
		{
			tempBarrel.IsLocked = false;
			tempBarrel.HasPlayedLockSound = false;
			tempBarrel.CatchRot = 0f;
		}
		((MuzzleDeviceInterface)this).OnDetach();
		mountedLocalPositionRecorded = false;
		canBePulledTimer = 0f;
		hasPlayedUnlockSoundThisUnlock = false;
	}

	public override void BeginInteraction(FVRViveHand hand)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		((FVRInteractiveObject)this).BeginInteraction(hand);
		lastHandForward = ((HandInput)(ref ((FVRInteractiveObject)this).m_hand.Input)).Up;
		lastMountForward = ((!((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null) || !((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount != (Object)null)) ? Vector3.up : ((Component)((FVRFireArmAttachmentInterface)this).Attachment.curMount).transform.up);
		lockCooldownTimer = 0f;
		lockedGraceTimer = 0f;
		canBePulledTimer = 0f;
		hasPlayedUnlockSoundThisUnlock = false;
		ignoreDetachTimer = IgnoreDetachOnGrabTime;
	}

	public override void UpdateInteraction(FVRViveHand hand)
	{
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02db: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
		((FVRFireArmAttachmentInterface)this).UpdateInteraction(hand);
		if (lockedGraceTimer > 0f)
		{
			lockedGraceTimer -= Time.deltaTime;
			if (lockedGraceTimer < 0f)
			{
				lockedGraceTimer = 0f;
			}
		}
		if (lockCooldownTimer > 0f)
		{
			lockCooldownTimer -= Time.deltaTime;
			if (lockCooldownTimer < 0f)
			{
				lockCooldownTimer = 0f;
			}
		}
		if (canBePulledTimer > 0f)
		{
			canBePulledTimer -= Time.deltaTime;
			if (canBePulledTimer <= 0f)
			{
				canBePulledTimer = 0f;
			}
		}
		if (ignoreDetachTimer > 0f)
		{
			ignoreDetachTimer -= Time.deltaTime;
			if (ignoreDetachTimer < 0f)
			{
				ignoreDetachTimer = 0f;
			}
		}
		UpdateSnappingBasedOnDistance();
		if (((FVRInteractiveObject)this).IsHeld && (Object)(object)tempBarrel != (Object)null)
		{
			((Component)((FVRFireArmAttachmentInterface)this).Attachment).transform.localEulerAngles = new Vector3(0f, 0f, tempBarrel.CatchRot);
		}
		if ((Object)(object)tempBarrel == (Object)null)
		{
			return;
		}
		float lockAngle = tempBarrel.LockAngle;
		float num = 2f + LockSnapBuffer;
		if (!tempBarrel.IsLocked)
		{
			if (lockAngle >= 0f)
			{
				if (tempBarrel.CatchRot >= lockAngle - num)
				{
					DoLock(lockAngle);
				}
			}
			else if (tempBarrel.CatchRot <= lockAngle + num)
			{
				DoLock(lockAngle);
			}
		}
		else if (Mathf.Abs(tempBarrel.CatchRot) <= 2f && lockedGraceTimer <= 0f)
		{
			DoUnlock();
		}
		if (tempBarrel.IsLocked || !((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null) || !((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount != (Object)null))
		{
			return;
		}
		FVRFireArmAttachmentMount rootMount = ((FVRFireArmAttachmentInterface)this).Attachment.curMount.GetRootMount();
		Transform val = ((!((Object)(object)rootMount != (Object)null) || !(rootMount.MyObject is FVRFireArm)) ? null : ((FVRFireArm)rootMount.MyObject).MuzzlePos);
		if (!((Object)(object)val != (Object)null))
		{
			return;
		}
		Vector3 closestValidPoint = ((FVRInteractiveObject)this).GetClosestValidPoint(((FVRFireArmAttachmentInterface)this).Attachment.curMount.Point_Front.position, val.position, ((Component)this).transform.position);
		float num2 = Vector3.Distance(((HandInput)(ref ((FVRInteractiveObject)this).m_hand.Input)).Pos, closestValidPoint);
		if (canBePulledTimer > 0f)
		{
			if (num2 > DetachDistanceThreshold)
			{
				canBePulledTimer = 0f;
				((FVRInteractiveObject)this).EndInteraction(hand);
				hand.ForceSetInteractable((FVRInteractiveObject)(object)((FVRFireArmAttachmentInterface)this).Attachment);
				((FVRInteractiveObject)((FVRFireArmAttachmentInterface)this).Attachment).BeginInteraction(hand);
			}
		}
		else if (ignoreDetachTimer <= 0f && num2 > DetachDistanceThreshold)
		{
			((FVRInteractiveObject)this).EndInteraction(hand);
			hand.ForceSetInteractable((FVRInteractiveObject)(object)((FVRFireArmAttachmentInterface)this).Attachment);
			((FVRInteractiveObject)((FVRFireArmAttachmentInterface)this).Attachment).BeginInteraction(hand);
		}
	}

	public override void FVRFixedUpdate()
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)tempBarrel == (Object)null)
		{
			((FVRInteractiveObject)this).FVRFixedUpdate();
			return;
		}
		if (((FVRInteractiveObject)this).IsHeld && m_isInSnappingMode && lockCooldownTimer <= 0f && lockedGraceTimer <= 0f)
		{
			Vector3 val = Vector3.ProjectOnPlane(((HandInput)(ref ((FVRInteractiveObject)this).m_hand.Input)).Up, ((Component)this).transform.forward);
			Vector3 val2 = Vector3.ProjectOnPlane(lastHandForward, ((Component)this).transform.forward);
			float num = Mathf.Atan2(Vector3.Dot(((Component)this).transform.forward, Vector3.Cross(val, val2)), Vector3.Dot(val, val2)) * 57.29578f;
			Vector3 val3 = Vector3.ProjectOnPlane((!((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null) || !((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount != (Object)null)) ? Vector3.up : ((Component)((FVRFireArmAttachmentInterface)this).Attachment.curMount).transform.up, ((Component)this).transform.forward);
			Vector3 val4 = Vector3.ProjectOnPlane(lastMountForward, ((Component)this).transform.forward);
			float num2 = Mathf.Atan2(Vector3.Dot(((Component)this).transform.forward, Vector3.Cross(val3, val4)), Vector3.Dot(val3, val4)) * 57.29578f;
			tempBarrel.CatchRot -= num;
			tempBarrel.CatchRot += num2;
			float lockAngle = tempBarrel.LockAngle;
			float num3 = Mathf.Min(0f, lockAngle);
			float num4 = Mathf.Max(0f, lockAngle);
			tempBarrel.CatchRot = Mathf.Clamp(tempBarrel.CatchRot, num3, num4);
			lastHandForward = ((HandInput)(ref ((FVRInteractiveObject)this).m_hand.Input)).Up;
			lastMountForward = ((!((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null) || !((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount != (Object)null)) ? lastMountForward : ((Component)((FVRFireArmAttachmentInterface)this).Attachment.curMount).transform.up);
		}
		((FVRInteractiveObject)this).FVRFixedUpdate();
	}

	public override void EndInteraction(FVRViveHand hand)
	{
		if (!tempBarrel.IsLocked && Mathf.Abs(tempBarrel.CatchRot) <= 2f && lockedGraceTimer <= 0f)
		{
			((FVRInteractiveObject)this).EndInteraction(hand);
		}
	}

	private void UpdateSnappingBasedOnDistance()
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment == (Object)null || (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount == (Object)null)
		{
			SetSnapping(b: false);
			return;
		}
		if (((FVRInteractiveObject)this).IsHeld)
		{
			SetSnapping(b: true);
			return;
		}
		Vector3 closestValidPoint = ((FVRInteractiveObject)this).GetClosestValidPoint(((FVRFireArmAttachmentInterface)this).Attachment.curMount.Point_Front.position, ((FVRFireArmAttachmentInterface)this).Attachment.curMount.Point_Rear.position, ((Component)this).transform.position);
		if (Vector3.Distance(closestValidPoint, ((Component)this).transform.position) < DetachDistanceThreshold || ((Object)(object)tempBarrel != (Object)null && Mathf.Abs(tempBarrel.CatchRot) > 1f))
		{
			SetSnapping(b: true);
		}
		else
		{
			SetSnapping(b: false);
		}
	}

	private void SetSnapping(bool b)
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		if (m_isInSnappingMode == b)
		{
			return;
		}
		m_isInSnappingMode = b;
		if (m_isInSnappingMode)
		{
			((FVRInteractiveObject)this).SetAllCollidersToLayer(false, "NoCol");
			if ((Object)(object)((FVRInteractiveObject)this).m_hand != (Object)null)
			{
				lastHandForward = ((HandInput)(ref ((FVRInteractiveObject)this).m_hand.Input)).Up;
			}
			if ((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null && (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount != (Object)null)
			{
				lastMountForward = ((Component)((FVRFireArmAttachmentInterface)this).Attachment.curMount).transform.up;
			}
		}
		else
		{
			((FVRInteractiveObject)this).SetAllCollidersToLayer(false, "Default");
		}
	}
}
namespace Volks.ModulPU21;

[BepInPlugin("Volks.ModulPU21", "ModulPU21", "1.0.0")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
[BepInDependency("h3vr.cityrobo.ModularWorkshopManager", "1.0.0")]
[BepInDependency("nrgill28.Sodalite", "1.4.2")]
public class ModulPU21Plugin : BaseUnityPlugin
{
	private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

	internal static ManualLogSource Logger;

	private void Awake()
	{
		Logger = ((BaseUnityPlugin)this).Logger;
		LoadAssets();
	}

	private void LoadAssets()
	{
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "Volks.ModulPU21");
		OtherLoader.RegisterDirectLoad(BasePath, "Volks.ModulPU21", "", "", "modulpu21", "");
		GameAPI.PreloadAllAssets(Path.Combine(BasePath, "mw_modulpu21"));
	}
}