Decompiled source of ModulGlockarov v1.0.0

ModulGlockarov.dll

Decompiled 3 weeks ago
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using H3VRUtils;
using HarmonyLib;
using ModularWorkshop;
using OpenScripts2;
using OtherLoader;
using Sodalite.Api;
using UnityEngine;
using UnityEngine.UI;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
public class 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.ModulGlockarov;

[BepInPlugin("Volks.ModulGlockarov", "ModulGlockarov", "1.0.0")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.cityrobo.ModularWorkshopManager", "1.0.0")]
[BepInDependency("nrgill28.Sodalite", "1.4.2")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
public class ModulGlockarovPlugin : 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.ModulGlockarov");
		GameAPI.PreloadAllAssets(Path.Combine(BasePath, "mw_modulglockarov"));
		OtherLoader.RegisterDirectLoad(BasePath, "Volks.ModulGlockarov", "", "", "modulglockarov", "");
	}
}
public class AttachableMeleeStock : FVRFireArmAttachmentInterface
{
	public Transform Point_Stock;

	public override void OnAttach()
	{
		((FVRFireArmAttachmentInterface)this).OnAttach();
		FVRFireArmAttachmentMount val = ((!((Object)(object)base.Attachment != (Object)null)) ? null : base.Attachment.curMount);
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		FVRFireArmAttachmentMount rootMount = val.GetRootMount();
		FVRPhysicalObject obj = ((!((Object)(object)rootMount != (Object)null)) ? val.Parent : rootMount.Parent);
		FVRFireArm val2 = (FVRFireArm)(object)((obj is FVRFireArm) ? obj : null);
		if (!((Object)(object)val2 == (Object)null))
		{
			FVRFireArmAttachment attachment = base.Attachment;
			AttachableMeleeWeapon val3 = (AttachableMeleeWeapon)(object)((attachment is AttachableMeleeWeapon) ? attachment : null);
			if ((Object)(object)val3 != (Object)null)
			{
				val2.RegisterAttachedMeleeWeapon(val3);
			}
			if ((Object)(object)Point_Stock != (Object)null)
			{
				val2.StockPos = Point_Stock;
				val2.HasActiveShoulderStock = true;
			}
		}
	}

	public override void OnDetach()
	{
		FVRFireArmAttachmentMount val = ((!((Object)(object)base.Attachment != (Object)null)) ? null : base.Attachment.curMount);
		if ((Object)(object)val != (Object)null)
		{
			FVRFireArmAttachmentMount rootMount = val.GetRootMount();
			FVRPhysicalObject obj = ((!((Object)(object)rootMount != (Object)null)) ? val.Parent : rootMount.Parent);
			FVRFireArm val2 = (FVRFireArm)(object)((obj is FVRFireArm) ? obj : null);
			if ((Object)(object)val2 != (Object)null)
			{
				if (base.Attachment is AttachableMeleeWeapon)
				{
					val2.RegisterAttachedMeleeWeapon((AttachableMeleeWeapon)null);
				}
				if ((Object)(object)Point_Stock != (Object)null)
				{
					val2.StockPos = null;
					val2.HasActiveShoulderStock = false;
				}
			}
		}
		((FVRFireArmAttachmentInterface)this).OnDetach();
	}
}
public class ExpandedAmmoDisplay : MonoBehaviour
{
	[Header("Ammo Counter Settings")]
	[Tooltip("Text to display ammo left in the gun.")]
	public Text UItext;

	[Tooltip("Text to display maximum ammo.")]
	public Text MaxAmmoText;

	[Tooltip("Text to display the type of ammo.")]
	public Text ammoTypeText;

	[Tooltip("Adds a minimum character count. See tooltip for MinCharLength for more.")]
	public bool AddMinCharLength;

	[Tooltip("i.e if MinCharLength is 2 and the amount of rounds left is 5, it will display 05 instead of 5.")]
	public int MinCharLength;

	[Tooltip("Will not instantly be the correct amount of rounds, but will tick up/down until it is.")]
	public bool enableDispLerp;

	[Tooltip("MaxAmmo will also lerp according to the DispLerpAmt")]
	public bool enableLerpForMaxAmmo;

	[Tooltip("EnabledObjects will also lerp according to the DispLerpAmt")]
	public bool enableLerpForEnabledObjects;

	[Tooltip("From 0-1. The % amount moved towards its correct amount every 50th of a second.")]
	[Range(0f, 0.2f)]
	public float DispLerpAmt;

	[Header("Alternate Displays")]
	[Tooltip("Enables enabling/disabling objects based on rounds left in mag.")]
	public bool EnabledObjects;

	[Tooltip("Object enabled when there is no magazine.")]
	public GameObject ObjectWhenEmpty;

	[Tooltip("Element no. corresponds to rounds left. 0 means no rounds, 1 means one round. Enables the 5th object if there are 5 rounds, and so on.")]
	public List<GameObject> Objects;

	[Tooltip("Enables all objects under the round count. Enables the 0th, 1st, 2nd, 3rd objects if there are 3 rounds left, and so on.")]
	public bool EnableAllUnderAmount;

	[Tooltip("Overrides Objects. #0 means Objects' #0 displays from 0% to #0%, #1 means Objects' #1 displays from #0% to #1%, etc- written normally, not mathmatically (e.g 57.32)")]
	public bool EnableBasedOnPercentage;

	public List<float> ObjectPercentages;

	[Header("Fire Mode Display")]
	[Tooltip("Text to display the fire mode (e.g., Safe, Single, FullAuto, Burst).")]
	public Text fireModeText;

	[Tooltip("Image to display fire mode visually.")]
	public Image fireModeImage;

	[Tooltip("Sprites for each fire mode: 0=Safe, 1=Single, 2=FullAuto, 3=Burst, 4=Other.")]
	public Sprite[] fireModeSprites;

	[Header("Low Ammo Warning")]
	[Tooltip("Enable sound and blink effects when ammo drops to a percentage of max.")]
	public bool enableLowAmmoWarning;

	[Tooltip("Percentage of max ammo at which the warning triggers (e.g. 25 means 25%).")]
	[Range(0f, 100f)]
	public float lowAmmoThresholdPercent = 25f;

	[Tooltip("AudioSource used to play warning sounds.")]
	public AudioSource warningAudioSource;

	[Tooltip("Sound played once when ammo drops to or below the low ammo threshold.")]
	public AudioClip lowAmmoClip;

	[Tooltip("Sound played once when ammo is fully depleted (0 rounds).")]
	public AudioClip depletedAmmoClip;

	[Tooltip("Enable blinking on the ammo text when at or below the low ammo threshold.")]
	public bool enableLowAmmoBlink;

	[Tooltip("How many times per second the text blinks on/off.")]
	public float blinkRate = 4f;

	private FVRFireArm _fa;

	private FVRFireArmMagazine _mag;

	private FVRFirearmMovingProxyRound[] proxies;

	private FVRFireArmChamber[] chambers;

	private int lastAmountOfBullets;

	private int lastAmountOfMaxBullets;

	private int lastAmountOfBulletsForEnableObjects;

	private bool _hasPlayedLowAmmoSound;

	private bool _hasPlayedDepletedSound;

	private bool _isBlinking;

	private float _blinkTimer;

	private bool _isUItextNotNull;

	private bool _isMaxAmmoTextNotNull;

	private bool _isammoTypeTextNotNull;

	private bool _isfireModeTextNotNull;

	private bool _isfireModeImageNotNull;

	private void Start()
	{
		NullCheck();
	}

	private void GetFirearmAndMag()
	{
		_fa = ((Component)this).GetComponent<FVRFireArm>() ?? ((Component)this).GetComponentInParent<FVRFireArm>();
		if ((Object)(object)_fa != (Object)null)
		{
			_mag = _fa.Magazine;
			if (chambers == null)
			{
				chambers = GetFireArmDeets.GetFireArmChamber(_fa);
			}
			proxies = GetFireArmDeets.GetFireArmProxySwitch(_fa, false);
		}
		else
		{
			_mag = null;
			chambers = null;
			proxies = null;
		}
	}

	private void Update()
	{
		GetFirearmAndMag();
		int ammoCount = GetAmmoCount();
		int maxAmmoCount = GetMaxAmmoCount();
		if (_isUItextNotNull)
		{
			string text = CalculateAmmoCounterAmount(ammoCount, ref lastAmountOfBullets, enableDispLerp, DispLerpAmt, AddMinCharLength, MinCharLength);
			UItext.text = text;
		}
		if (_isMaxAmmoTextNotNull)
		{
			string text2 = CalculateAmmoCounterAmount(maxAmmoCount, ref lastAmountOfMaxBullets, enableLerpForMaxAmmo, DispLerpAmt, AddMinCharLength, MinCharLength);
			MaxAmmoText.text = text2;
		}
		if (_isammoTypeTextNotNull)
		{
			ammoTypeText.text = GetAmmoType();
		}
		if (_isfireModeTextNotNull || _isfireModeImageNotNull)
		{
			string fireMode = GetFireMode();
			if (_isfireModeTextNotNull)
			{
				fireModeText.text = fireMode;
			}
			if (_isfireModeImageNotNull && fireModeSprites != null && fireModeSprites.Length > 0)
			{
				int spriteIndexForMode = GetSpriteIndexForMode(fireMode);
				if (spriteIndexForMode >= 0 && spriteIndexForMode < fireModeSprites.Length)
				{
					fireModeImage.sprite = fireModeSprites[spriteIndexForMode];
				}
			}
		}
		if (EnabledObjects)
		{
			int num = int.Parse(CalculateAmmoCounterAmount(ammoCount, ref lastAmountOfBulletsForEnableObjects, enableLerpForEnabledObjects, DispLerpAmt));
			if (EnableBasedOnPercentage)
			{
				SetEnabledObjectsPercentage(num);
			}
			else
			{
				SetEnabledObjects(num);
			}
		}
		if (enableLowAmmoWarning && maxAmmoCount > 0)
		{
			UpdateLowAmmoWarning(ammoCount, maxAmmoCount);
		}
		else
		{
			ResetWarningState();
		}
	}

	private void UpdateLowAmmoWarning(int currentAmmo, int maxAmmo)
	{
		float num = (float)currentAmmo / (float)maxAmmo * 100f;
		bool flag = num <= lowAmmoThresholdPercent && currentAmmo > 0;
		bool flag2 = currentAmmo <= 0;
		if (flag2)
		{
			if (!_hasPlayedDepletedSound)
			{
				PlayWarningClip(depletedAmmoClip);
				_hasPlayedDepletedSound = true;
			}
		}
		else
		{
			_hasPlayedDepletedSound = false;
		}
		if (flag)
		{
			if (!_hasPlayedLowAmmoSound)
			{
				PlayWarningClip(lowAmmoClip);
				_hasPlayedLowAmmoSound = true;
			}
		}
		else if (!flag2)
		{
			_hasPlayedLowAmmoSound = false;
		}
		if (enableLowAmmoBlink && _isUItextNotNull && (flag || flag2))
		{
			_isBlinking = true;
			_blinkTimer += Time.deltaTime;
			float num2 = ((!(blinkRate > 0f)) ? 1f : (1f / blinkRate));
			bool enabled = _blinkTimer % num2 < num2 * 0.5f;
			((Behaviour)UItext).enabled = enabled;
		}
		else if (_isBlinking)
		{
			_isBlinking = false;
			_blinkTimer = 0f;
			if (_isUItextNotNull)
			{
				((Behaviour)UItext).enabled = true;
			}
		}
	}

	private void ResetWarningState()
	{
		if (_isBlinking)
		{
			_isBlinking = false;
			_blinkTimer = 0f;
			if (_isUItextNotNull)
			{
				((Behaviour)UItext).enabled = true;
			}
		}
		_hasPlayedLowAmmoSound = false;
		_hasPlayedDepletedSound = false;
	}

	private void PlayWarningClip(AudioClip clip)
	{
		if ((Object)(object)clip != (Object)null && (Object)(object)warningAudioSource != (Object)null)
		{
			warningAudioSource.PlayOneShot(clip);
		}
	}

	private int GetAmmoCount()
	{
		int num = 0;
		if ((Object)(object)_mag != (Object)null)
		{
			num += _mag.m_numRounds;
		}
		if ((Object)(object)_fa != (Object)null)
		{
			if (chambers != null)
			{
				num += chambers.Count((FVRFireArmChamber chamber) => chamber.IsFull && !chamber.IsSpent);
			}
			if (proxies != null)
			{
				FVRFirearmMovingProxyRound[] array = proxies;
				foreach (FVRFirearmMovingProxyRound val in array)
				{
					if (val.IsFull)
					{
						num++;
					}
				}
			}
			if ((Object)(object)_fa.BeltDD != (Object)null)
			{
				num += _fa.BeltDD.m_roundsOnBelt;
			}
		}
		return num;
	}

	private int GetMaxAmmoCount()
	{
		if ((Object)(object)_mag != (Object)null)
		{
			return _mag.m_capacity;
		}
		if ((Object)(object)_fa != (Object)null && !_fa.UsesMagazines)
		{
			return (chambers != null) ? chambers.Length : 0;
		}
		return 0;
	}

	private string GetAmmoType()
	{
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: 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)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_fa != (Object)null)
		{
			List<FireArmRoundClass> chamberRoundList = _fa.GetChamberRoundList();
			if (chamberRoundList != null && chamberRoundList.Count > 0)
			{
				return AM.GetFullRoundName(_fa.RoundType, chamberRoundList[0]);
			}
			if ((Object)(object)_fa.BeltDD != (Object)null && _fa.BeltDD.m_roundsOnBelt > 0)
			{
				return AM.GetFullRoundName(_fa.RoundType, _fa.BeltDD.BeltRounds[0].LR_Class);
			}
		}
		if ((Object)(object)_mag != (Object)null && _mag.m_numRounds > 0)
		{
			return AM.GetFullRoundName(_mag.RoundType, _mag.LoadedRounds[0].LR_Class);
		}
		return string.Empty;
	}

	private string GetFireMode()
	{
		if ((Object)(object)_fa == (Object)null)
		{
			return "N/A";
		}
		FVRFireArm fa = _fa;
		Handgun val = (Handgun)(object)((fa is Handgun) ? fa : null);
		if ((Object)(object)val == (Object)null)
		{
			return "N/A";
		}
		if (val.IsSafetyEngaged)
		{
			return "Safe";
		}
		if (val.FireSelectorModes != null && val.FireSelectorModes.Length > 0)
		{
			FireSelectorMode val2 = val.FireSelectorModes[val.FireSelectorModeIndex];
			return ((object)(FireSelectorModeType)(ref val2.ModeType)).ToString();
		}
		return "N/A";
	}

	private int GetSpriteIndexForMode(string mode)
	{
		return mode switch
		{
			"Safe" => 0, 
			"Single" => 1, 
			"FullAuto" => 2, 
			"Burst" => 3, 
			_ => 4, 
		};
	}

	public static string CalculateAmmoCounterAmount(int currentammo, ref int lastammo, bool lerp = false, float lerpAmt = 0f, bool pad = false, int padAmt = 0)
	{
		if (lerp)
		{
			currentammo = LerpInt(lastammo, currentammo, lerpAmt);
		}
		string text = currentammo.ToString();
		if (pad)
		{
			text = PadStringNumberToAmt(text, padAmt);
		}
		lastammo = currentammo;
		return text;
	}

	public static string PadStringNumberToAmt(string str, int minCharLength)
	{
		int num = minCharLength - str.Length;
		for (int i = 0; i < num; i++)
		{
			str = "0" + str;
		}
		return str;
	}

	public static int LerpInt(int a, int b, float lerp)
	{
		bool flag = a == 0;
		a = Mathf.CeilToInt(Mathf.Lerp((float)a, (float)b, lerp));
		if (a == 1 && flag)
		{
			a = 0;
		}
		return a;
	}

	private void SetEnabledObjects(int amt)
	{
		amt = Mathf.Clamp(amt, 0, Objects.Count - 1);
		for (int i = 0; i < Objects.Count; i++)
		{
			Objects[i].SetActive(false);
		}
		if ((Object)(object)ObjectWhenEmpty != (Object)null)
		{
			ObjectWhenEmpty.SetActive(false);
		}
		if ((Object)(object)_mag == (Object)null && (Object)(object)ObjectWhenEmpty != (Object)null)
		{
			ObjectWhenEmpty.SetActive(true);
			return;
		}
		for (int j = 0; j < Objects.Count; j++)
		{
			if (j < amt)
			{
				if (EnableAllUnderAmount)
				{
					Objects[j].SetActive(true);
				}
			}
			else if (j == amt)
			{
				Objects[j].SetActive(true);
			}
		}
	}

	private void SetEnabledObjectsPercentage(int amt)
	{
		amt = Mathf.Clamp(amt, 0, Objects.Count - 1);
		int maxAmmoCount = GetMaxAmmoCount();
		if (maxAmmoCount <= 0)
		{
			return;
		}
		float num = (float)amt / (float)maxAmmoCount;
		for (int i = 0; i < Objects.Count; i++)
		{
			Objects[i].SetActive(false);
		}
		if ((Object)(object)ObjectWhenEmpty != (Object)null)
		{
			ObjectWhenEmpty.SetActive(false);
		}
		if ((Object)(object)_mag == (Object)null && (Object)(object)ObjectWhenEmpty != (Object)null)
		{
			ObjectWhenEmpty.SetActive(true);
			return;
		}
		for (int j = 0; j < Objects.Count; j++)
		{
			float num2 = ObjectPercentages[j] / 100f;
			float num3 = 0f;
			if (j > 0)
			{
				num3 = ObjectPercentages[j - 1] / 100f;
			}
			if (!(num > num2))
			{
				continue;
			}
			if (num > num3)
			{
				if (EnableAllUnderAmount)
				{
					Objects[j].SetActive(true);
				}
			}
			else
			{
				Objects[j].SetActive(true);
			}
		}
	}

	public void NullCheck()
	{
		_isammoTypeTextNotNull = (Object)(object)ammoTypeText != (Object)null;
		_isMaxAmmoTextNotNull = (Object)(object)MaxAmmoText != (Object)null;
		_isUItextNotNull = (Object)(object)UItext != (Object)null;
		_isfireModeTextNotNull = (Object)(object)fireModeText != (Object)null;
		_isfireModeImageNotNull = (Object)(object)fireModeImage != (Object)null;
	}
}