Decompiled source of HuntFragBomb v1.0.2

HuntFragBomb.dll

Decompiled 2 weeks ago
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using OtherLoader;
using 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]
namespace BitWizrd.HuntFragBomb
{
	[BepInPlugin("BitWizrd.HuntFragBomb", "HuntFragBomb", "1.0.2")]
	[BepInProcess("h3vr.exe")]
	[Description("Built with MeatKit")]
	[BepInDependency("h3vr.otherloader", "1.3.0")]
	public class HuntFragBombPlugin : 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(), "BitWizrd.HuntFragBomb");
			OtherLoader.RegisterDirectLoad(BasePath, "BitWizrd.HuntFragBomb", "", "huntfragbomb", "", "");
		}
	}
}
public class CustomWaggleJoint : MonoBehaviour
{
	public enum Axis
	{
		X,
		Y,
		Z
	}

	[Tooltip("The axis on which to perform the waggle.")]
	public Axis waggleAxis = Axis.Y;

	[Tooltip("Check this box to flip the waggle behavior to the opposite direction.")]
	public bool invertWaggleDirection = false;

	[Tooltip("The distance the particle is clamped to, scale this up to make it less sensitive to changes.")]
	public float distanceLimit = 0.25f;

	public float angleLimitLeft = 45f;

	public float angleLimitRight = 45f;

	[Tooltip("Multiplier for the physics gravity affecting the particle. Good for dealing with stiff joints or low gravity values.")]
	public float gravityScale = 1f;

	[Tooltip("Pulls the particle back to the hinge direction")]
	public bool useSpring;

	[Tooltip("Rate at which the particle approaches the hinge direction, eg: 0.95 means 95% closer each second.")]
	public float springApproachRate = 0.95f;

	[Tooltip("Rate at which the particle loses velocity, eg: 0.5 means 50% slower each second.")]
	public float damping;

	[Tooltip("This transform will LookAt() the particle being simulated.")]
	public Transform hingeGraphic;

	public bool ManualExecution;

	[Tooltip("Puts a cooldown on how often the OnHitLimit event can be fired.")]
	public float onHitLimitCooldown = 0.05f;

	private Vector3 particlePos;

	private Vector3 particleVel;

	private bool leftCatchState;

	private bool rightCatchState;

	private float lastTouchTime = float.MinValue;

	private Vector3 GetHingeAxis()
	{
		//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_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_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: 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)
		Vector3 val = (Vector3)(waggleAxis switch
		{
			Axis.X => ((Component)this).transform.right, 
			Axis.Y => ((Component)this).transform.up, 
			Axis.Z => ((Component)this).transform.forward, 
			_ => ((Component)this).transform.up, 
		});
		return (!invertWaggleDirection) ? val : (-val);
	}

	private static float Approach(float rate, float time)
	{
		return 1f - Mathf.Pow(1f - rate, time);
	}

	private static Vector3 Approach(Vector3 point, Vector3 target, float rate, float time)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		return Vector3.Lerp(point, target, Approach(rate, time));
	}

	private static float SignedAngle(Vector3 from, Vector3 to, Vector3 axis)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		float num = Vector3.Angle(from, to);
		float num2 = from.y * to.z - from.z * to.y;
		float num3 = from.z * to.x - from.x * to.z;
		float num4 = from.x * to.y - from.y * to.x;
		float num5 = Mathf.Sign(axis.x * num2 + axis.y * num3 + axis.z * num4);
		return num * num5;
	}

	private static float ToHingeAngle(Vector3 point, Vector3 hingePivot, Vector3 hingeAxis, Vector3 hingeDirection)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: 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_001a: 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)
		Vector3 val = point - hingePivot;
		Vector3 val2 = Vector3.ProjectOnPlane(val, hingeAxis);
		Vector3 normalized = ((Vector3)(ref val2)).normalized;
		return SignedAngle(hingeDirection, normalized, hingeAxis);
	}

	private static Vector3 ProjectOnHinge(Vector3 point, Vector3 hingePivot, Vector3 hingeAxis, Vector3 hingeDirection, float distanceLimit, float angleMin, float angleMax)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0038: Unknown result type (might be due to invalid IL or missing references)
		float num = ToHingeAngle(point, hingePivot, hingeAxis, hingeDirection);
		num = Mathf.Clamp(num, angleMin, angleMax);
		Vector3 val = Quaternion.AngleAxis(num, hingeAxis) * hingeDirection;
		return val * distanceLimit + hingePivot;
	}

	private static bool DetectOnHitLimit(float angle, float minAngle, float maxAngle, ref bool minCatchState, ref bool maxCatchState, float catchThreshold = 0.5f, float releaseThreshold = 5f)
	{
		float num = Mathf.Abs(maxAngle - minAngle);
		float num2 = Mathf.Min(releaseThreshold, num - catchThreshold);
		float num3 = angle - minAngle;
		float num4 = 0f - (angle - maxAngle);
		bool flag = minCatchState;
		bool flag2 = maxCatchState;
		minCatchState = num3 <= (minCatchState ? num2 : catchThreshold);
		maxCatchState = num4 <= (maxCatchState ? num2 : catchThreshold);
		return (!flag && minCatchState) || (!flag2 && maxCatchState);
	}

	public void ResetParticlePos()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: 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)
		particlePos = ((Component)this).transform.position + hingeGraphic.forward * distanceLimit;
		particleVel = Vector3.zero;
	}

	private void OnHitLimit(float angularVelocity)
	{
	}

	public void Execute()
	{
		//IL_000e: 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_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: 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_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: 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_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: 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_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00ee: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: 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_0115: 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_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: 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_0089: 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_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_00a4: 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_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		float deltaTime = Time.deltaTime;
		Transform transform = ((Component)this).transform;
		Vector3 val = Physics.gravity * gravityScale;
		Vector3 val2 = particlePos;
		Vector3 val3 = Approach(particleVel, Vector3.zero, damping, deltaTime);
		Vector3 val4 = val3 + val * deltaTime;
		Vector3 val5 = val2 + val4 * deltaTime;
		Vector3 val6 = val5;
		Vector3 position = transform.position;
		Vector3 hingeAxis = GetHingeAxis();
		Vector3 up = transform.up;
		if (useSpring)
		{
			val5 = Approach(val5, position + up * distanceLimit, springApproachRate, deltaTime);
		}
		particleVel = ((particlePos = ProjectOnHinge(val5, position, hingeAxis, up, distanceLimit, 0f - angleLimitRight, angleLimitLeft)) - val2) / deltaTime;
		float angularVelocity = SignedAngle(val6 - position, val2 - position, hingeAxis) / Mathf.Max(Mathf.Epsilon, deltaTime);
		bool flag = DetectOnHitLimit(ToHingeAngle(particlePos, position, hingeAxis, up), 0f - angleLimitRight, angleLimitLeft, ref rightCatchState, ref leftCatchState);
		bool flag2 = Time.timeSinceLevelLoad < lastTouchTime + onHitLimitCooldown;
		if (flag && !flag2)
		{
			OnHitLimit(angularVelocity);
			lastTouchTime = Time.timeSinceLevelLoad;
		}
		if ((Object)(object)hingeGraphic != (Object)null)
		{
			Vector3 val7 = Vector3.Cross(hingeGraphic.forward, hingeAxis);
			hingeGraphic.LookAt(particlePos, val7);
		}
	}

	private void Start()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: 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)
		particlePos = ((Component)this).transform.position + hingeGraphic.forward * distanceLimit;
		particleVel = Vector3.zero;
	}

	private void Update()
	{
		if (!ManualExecution)
		{
			Execute();
		}
	}

	private void OnDrawGizmosSelected()
	{
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00f8: 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_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: 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_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//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)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		if (Application.isPlaying)
		{
			Gizmos.color = new Color(0.1f, 0.3f, 0.9f);
			Gizmos.DrawWireCube(particlePos, Vector3.one * 0.025f);
			Gizmos.color = new Color(0.1f, 0.3f, 0.9f, 0.5f);
			Gizmos.DrawCube(particlePos, Vector3.one * 0.025f);
			float num = Time.timeSinceLevelLoad - lastTouchTime;
			Gizmos.color = new Color(0.1f, 0.7f, 0.9f, Mathf.Clamp01((0.5f - num) * 2f));
			Gizmos.DrawWireCube(particlePos, Vector3.one * (0.1f * (num + 0.5f)));
		}
		Vector3 val = ((Component)this).transform.position + ((Component)this).transform.up * distanceLimit;
		Gizmos.color = new Color(0.7f, 0.9f, 0.1f);
		Gizmos.DrawWireCube(val, Vector3.one * 0.02f);
		Gizmos.color = new Color(0.7f, 0.9f, 0.1f, 0.5f);
		Gizmos.DrawCube(val, Vector3.one * 0.02f);
		Gizmos.color = new Color(0.9f, 0.7f, 0.1f);
		Gizmos.DrawRay(((Component)this).transform.position, Quaternion.AngleAxis(angleLimitLeft, GetHingeAxis()) * ((Component)this).transform.up * distanceLimit);
		Gizmos.DrawRay(((Component)this).transform.position, Quaternion.AngleAxis(0f - angleLimitRight, GetHingeAxis()) * ((Component)this).transform.up * distanceLimit);
	}
}
namespace BitWizrd.GrenadeMod
{
	public class GrenadeMod : FVRPhysicalObject
	{
		[Header("Grenade Settings")]
		public GameObject grenadeGameObject;

		public PinnedGrenadeRing pinnedGrenadeRing;

		public Rigidbody grenadeRigidbody;

		public bool activateLeverOnPinPull = false;

		[Header("Sticky Grenade Settings")]
		public bool isStickyGrenade = true;

		public Collider stickyCollider;

		public float stickingDistance = 0.1f;

		public LayerMask stickyLayers;

		public float embeddingDistance = 0.02f;

		public bool playStickSoundForRigidbodiesOnly = true;

		public AudioSource stickSoundSource;

		public AudioClip[] stickSounds;

		public float minimumStickVelocity = 2f;

		public float regrabActivationDelay = 0.5f;

		public float massWhileStuck = 10f;

		[Header("Grenade Cooking Settings")]
		public GameObject pinPullEffectPrefab;

		public AudioSource cookingAudioSource;

		public AudioClip[] cookingClips;

		public float cookingSoundDelay = 1f;

		[Header("Grenade Fast Throw Settings")]
		public AudioSource fastThrowAudioSource;

		public AudioClip[] fastThrowClips;

		public float fastThrowVelocityThreshold = 10f;

		public float releaseWindow = 0.5f;

		private PinnedGrenade grenade;

		private Collider grenadeCollider;

		private bool hasPlayedFastThrowSound = false;

		private bool isPinPulled = false;

		private bool isHeld = false;

		private bool wasHeld = false;

		private bool pinPulledChecked = false;

		private bool shouldCheckVelocity = false;

		private bool hasReleasedLever = false;

		private bool isSticking = false;

		private bool canStick = false;

		private float timeSinceRelease = 0f;

		private GameObject parentObject;

		private Vector3 savedPosition;

		private Quaternion savedRotation;

		private Vector3 savedScale;

		private FVRInteractiveObject interactiveObject;

		private void Start()
		{
			interactiveObject = ((Component)this).GetComponent<FVRInteractiveObject>();
		}

		public override void FVRUpdate()
		{
			((FVRPhysicalObject)this).FVRUpdate();
			if ((Object)(object)grenadeGameObject == (Object)null)
			{
				return;
			}
			grenade = grenadeGameObject.GetComponent<PinnedGrenade>();
			if ((Object)(object)grenade == (Object)null)
			{
				return;
			}
			FVRPhysicalObject component = grenadeGameObject.GetComponent<FVRPhysicalObject>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			grenadeCollider = grenadeGameObject.GetComponent<Collider>();
			if ((Object)(object)grenadeCollider == (Object)null)
			{
				return;
			}
			isHeld = ((FVRInteractiveObject)component).IsHeld;
			if ((Object)(object)pinnedGrenadeRing != (Object)null)
			{
				isPinPulled = pinnedGrenadeRing.HasPinDetached();
				if (!pinPulledChecked && isPinPulled)
				{
					pinPulledChecked = true;
					shouldCheckVelocity = true;
					if (isStickyGrenade)
					{
						EnableStickyCollider();
					}
					if ((Object)(object)pinPullEffectPrefab != (Object)null)
					{
						pinPullEffectPrefab.SetActive(true);
					}
				}
				if (!wasHeld && isHeld)
				{
					hasPlayedFastThrowSound = false;
					timeSinceRelease = 0f;
					if (isPinPulled)
					{
						EnableStickyCollider();
					}
					shouldCheckVelocity = isPinPulled;
					wasHeld = true;
					canStick = true;
					isSticking = false;
					FixedJoint component2 = ((Component)this).GetComponent<FixedJoint>();
					if ((Object)(object)component2 != (Object)null)
					{
						Object.Destroy((Object)(object)component2);
						grenadeRigidbody.isKinematic = false;
						grenadeRigidbody.detectCollisions = true;
						grenadeRigidbody.useGravity = true;
						grenadeRigidbody.constraints = (RigidbodyConstraints)0;
						Debug.Log((object)"FixedJoint grenade unstuck upon being picked up.");
					}
					if (isStickyGrenade)
					{
						DisableStickyColliderTemporarily();
					}
				}
				if (wasHeld && !isHeld)
				{
					isSticking = false;
					wasHeld = false;
				}
			}
			if (isPinPulled || !isHeld)
			{
				DisableMeleeDamage(component);
			}
			else
			{
				EnableMeleeDamage(component);
			}
			if (isPinPulled && !cookingAudioSource.isPlaying && cookingClips.Length > 0)
			{
				if (cookingSoundDelay == 0f)
				{
					PlayCookingSoundImmediately();
				}
				else
				{
					((MonoBehaviour)this).StartCoroutine(HandleCookingSoundDelay());
				}
			}
			if (isPinPulled && (Object)(object)pinPullEffectPrefab != (Object)null)
			{
				pinPullEffectPrefab.SetActive(true);
			}
			if (isPinPulled && activateLeverOnPinPull && !hasReleasedLever)
			{
				grenade.ReleaseLever();
				hasReleasedLever = true;
			}
		}

		public override void FVRFixedUpdate()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			((FVRPhysicalObject)this).FVRFixedUpdate();
			if (shouldCheckVelocity && isHeld)
			{
				Vector3 velocity = grenadeRigidbody.velocity;
				if (((Vector3)(ref velocity)).magnitude >= minimumStickVelocity)
				{
					canStick = true;
				}
				else
				{
					canStick = false;
				}
			}
			if (!shouldCheckVelocity || isHeld)
			{
				return;
			}
			timeSinceRelease += Time.fixedDeltaTime;
			if (timeSinceRelease <= releaseWindow)
			{
				Vector3 velocity2 = grenadeRigidbody.velocity;
				if (((Vector3)(ref velocity2)).magnitude > fastThrowVelocityThreshold && !hasPlayedFastThrowSound)
				{
					PlayFastThrowSound();
				}
			}
			else
			{
				shouldCheckVelocity = false;
			}
		}

		private void DisableMeleeDamage(FVRPhysicalObject physicalObject)
		{
			if (physicalObject.MP != null && physicalObject.MP.IsMeleeWeapon)
			{
				physicalObject.MP.IsMeleeWeapon = false;
			}
		}

		private void EnableMeleeDamage(FVRPhysicalObject physicalObject)
		{
			if (physicalObject.MP != null && !physicalObject.MP.IsMeleeWeapon)
			{
				physicalObject.MP.IsMeleeWeapon = true;
			}
		}

		private void PlayFastThrowSound()
		{
			if (fastThrowClips.Length > 0 && (Object)(object)fastThrowAudioSource != (Object)null)
			{
				AudioClip val = fastThrowClips[Random.Range(0, fastThrowClips.Length)];
				fastThrowAudioSource.PlayOneShot(val);
			}
			hasPlayedFastThrowSound = true;
		}

		private void OnCollisionEnter(Collision collision)
		{
			//IL_00c1: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			if (!isPinPulled || isSticking || !isStickyGrenade || !((Object)(object)stickyCollider != (Object)null) || !canStick || (Object)(object)collision.gameObject.GetComponent<BreakableGlass>() != (Object)null || (Object)(object)collision.gameObject.GetComponent<PinnedGrenade>() != (Object)null || (Object)(object)collision.gameObject.GetComponent<PinnedGrenadePin>() != (Object)null || (Object)(object)collision.gameObject.GetComponent<SosigWeapon>() != (Object)null)
			{
				return;
			}
			ContactPoint[] contacts = collision.contacts;
			for (int i = 0; i < contacts.Length; i++)
			{
				ContactPoint contact = contacts[i];
				if (!((Object)(object)((ContactPoint)(ref contact)).thisCollider == (Object)(object)stickyCollider))
				{
					continue;
				}
				if ((LayerMask.op_Implicit(stickyLayers) & (1 << collision.gameObject.layer)) == 0 || !IsContactPointWithinStickingDistance(((ContactPoint)(ref contact)).point))
				{
					break;
				}
				isSticking = true;
				StickToSurface(collision, contact);
				PlayStickingSound(collision);
				parentObject = collision.gameObject;
				if ((Object)(object)parentObject != (Object)null)
				{
					DestroyNotifier destroyNotifier = parentObject.GetComponent<DestroyNotifier>();
					if ((Object)(object)destroyNotifier == (Object)null)
					{
						destroyNotifier = parentObject.AddComponent<DestroyNotifier>();
					}
					destroyNotifier.OnDestroyed += OnDestroyUnstickGrenade;
				}
				break;
			}
		}

		private bool IsContactPointWithinStickingDistance(Vector3 contactPoint)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = stickyCollider.ClosestPoint(contactPoint);
			float num = Vector3.Distance(contactPoint, val);
			return num < stickingDistance;
		}

		private void StickToSurface(Collision collision, ContactPoint contact)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Expected O, but got Unknown
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)stickyCollider == (Object)null)
			{
				return;
			}
			if ((Object)(object)interactiveObject != (Object)null && interactiveObject.IsHeld)
			{
				interactiveObject.ForceBreakInteraction();
			}
			savedPosition = ((Component)this).transform.position;
			savedRotation = ((Component)this).transform.rotation;
			Vector3 lossyScale = ((Component)this).transform.lossyScale;
			Rigidbody rigidbody = collision.rigidbody;
			Vector3 val = ((ContactPoint)(ref contact)).normal * embeddingDistance;
			if ((Object)(object)rigidbody != (Object)null)
			{
				((Component)this).transform.position = ((ContactPoint)(ref contact)).point + val;
				FixedJoint component = ((Component)this).GetComponent<FixedJoint>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
				FixedJoint val2 = ((Component)this).gameObject.AddComponent<FixedJoint>();
				((Joint)val2).connectedBody = rigidbody;
				((Joint)val2).breakForce = float.MaxValue;
				((Joint)val2).breakTorque = float.MaxValue;
				grenadeRigidbody.useGravity = false;
				grenadeRigidbody.isKinematic = false;
				grenadeRigidbody.constraints = (RigidbodyConstraints)0;
				grenadeRigidbody.mass = massWhileStuck;
				SetCollidersToLayer(stickyCollider, "NoCol");
			}
			else
			{
				GameObject val3 = new GameObject("DummyParent");
				val3.transform.position = ((ContactPoint)(ref contact)).point;
				val3.transform.rotation = collision.transform.rotation;
				grenadeRigidbody.isKinematic = true;
				val3.transform.SetParent(collision.transform, true);
				((Component)this).transform.SetParent(val3.transform, false);
				((Component)this).transform.localScale = new Vector3(lossyScale.x / ((Component)this).transform.lossyScale.x, lossyScale.y / ((Component)this).transform.lossyScale.y, lossyScale.z / ((Component)this).transform.lossyScale.z);
				((Component)this).transform.position = ((ContactPoint)(ref contact)).point + val;
				((Component)this).transform.rotation = savedRotation;
			}
		}

		private void UnstickFromSurface()
		{
			if ((Object)(object)((Component)this).GetComponent<FixedJoint>() != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).GetComponent<FixedJoint>());
			}
			SetCollidersToLayer(stickyCollider, "Default");
			grenadeRigidbody.isKinematic = false;
			grenadeRigidbody.detectCollisions = true;
			grenadeRigidbody.useGravity = true;
			grenadeRigidbody.constraints = (RigidbodyConstraints)0;
			grenadeRigidbody.mass = 1f;
			isSticking = false;
		}

		private void EnableStickyCollider()
		{
			if ((Object)(object)stickyCollider != (Object)null)
			{
				stickyCollider.enabled = true;
			}
		}

		private void DisableStickyColliderTemporarily()
		{
			if ((Object)(object)stickyCollider != (Object)null)
			{
				stickyCollider.enabled = false;
			}
			((MonoBehaviour)this).StartCoroutine(ReenableStickyColliderAfterDelay());
		}

		private IEnumerator ReenableStickyColliderAfterDelay()
		{
			yield return (object)new WaitForSeconds(regrabActivationDelay);
			EnableStickyCollider();
		}

		private void PlayStickingSound(Collision collision)
		{
			if ((Object)(object)stickSoundSource != (Object)null && stickSounds.Length > 0 && ((playStickSoundForRigidbodiesOnly && (Object)(object)collision.rigidbody != (Object)null) || !playStickSoundForRigidbodiesOnly))
			{
				int num = Random.Range(0, stickSounds.Length);
				stickSoundSource.clip = stickSounds[num];
				stickSoundSource.Play();
			}
		}

		private void OnDestroyUnstickGrenade()
		{
			if ((Object)(object)parentObject != (Object)null)
			{
				Object.Destroy((Object)(object)parentObject.GetComponent<DestroyNotifier>());
			}
			FixedJoint component = ((Component)this).GetComponent<FixedJoint>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			else
			{
				((Component)this).transform.SetParent((Transform)null);
			}
			grenadeRigidbody.isKinematic = false;
			grenadeRigidbody.detectCollisions = true;
			grenadeRigidbody.useGravity = true;
			grenadeRigidbody.constraints = (RigidbodyConstraints)0;
			isSticking = false;
			stickyCollider.enabled = false;
			canStick = false;
		}

		private void SetCollidersToLayer(Collider collider, string layer)
		{
			((Component)collider).gameObject.layer = LayerMask.NameToLayer(layer);
		}

		private IEnumerator HandleCookingSoundDelay()
		{
			if (cookingSoundDelay > 0f)
			{
				yield return (object)new WaitForSeconds(cookingSoundDelay);
			}
			if ((Object)(object)cookingAudioSource != (Object)null && cookingClips.Length > 0)
			{
				int num = Random.Range(0, cookingClips.Length);
				cookingAudioSource.clip = cookingClips[num];
				cookingAudioSource.Play();
			}
		}

		private void PlayCookingSoundImmediately()
		{
			if ((Object)(object)cookingAudioSource != (Object)null && cookingClips.Length > 0)
			{
				int num = Random.Range(0, cookingClips.Length);
				cookingAudioSource.clip = cookingClips[num];
				cookingAudioSource.Play();
			}
		}
	}
	public class DestroyNotifier : MonoBehaviour
	{
		public delegate void DestroyedAction();

		public event DestroyedAction OnDestroyed;

		private void OnDestroy()
		{
			if (this.OnDestroyed != null)
			{
				this.OnDestroyed();
			}
		}
	}
}