using System;
using System.Collections.Generic;
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]
internal class HarshRecoilController : MonoBehaviour
{
public FVRFireArm weapon;
public float disarmChance = 1f;
public float recoilForceUp = 4f;
public float recoilForceBack = 6f;
public float recoilTorque = 12f;
public float recoilRandomness = 1.5f;
public bool debug;
private List<bool> lastFrameSpent = new List<bool>();
private List<Collider> disabledColliders = new List<Collider>();
private float colliderRestoreTimer;
private bool initialized;
private void Start()
{
TryInitialize();
}
private void Update()
{
//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_01e7: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0209: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_0216: Unknown result type (might be due to invalid IL or missing references)
//IL_022c: Unknown result type (might be due to invalid IL or missing references)
//IL_0237: Unknown result type (might be due to invalid IL or missing references)
//IL_023c: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
//IL_024f: Unknown result type (might be due to invalid IL or missing references)
//IL_0254: Unknown result type (might be due to invalid IL or missing references)
//IL_0258: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_025c: Unknown result type (might be due to invalid IL or missing references)
if (!initialized)
{
TryInitialize();
}
else
{
if ((Object)(object)weapon == (Object)null || weapon.FChambers == null)
{
return;
}
if (colliderRestoreTimer > 0f)
{
colliderRestoreTimer -= Time.deltaTime;
if (colliderRestoreTimer <= 0f)
{
RestoreColliders();
}
}
for (int i = 0; i < weapon.FChambers.Count; i++)
{
FVRFireArmChamber val = weapon.FChambers[i];
if ((Object)(object)val == (Object)null)
{
continue;
}
if (i >= lastFrameSpent.Count)
{
lastFrameSpent.Add(val.IsSpent);
}
bool isSpent = val.IsSpent;
bool flag = isSpent && !lastFrameSpent[i];
lastFrameSpent[i] = isSpent;
if (!flag)
{
continue;
}
bool flag2 = weapon.IsTwoHandStabilized() || (Object)(object)((FVRPhysicalObject)weapon).AltGrip != (Object)null;
if (((FVRInteractiveObject)weapon).IsHeld && !flag2 && Random.value <= disarmChance)
{
if (debug)
{
Debug.Log((object)"HarshRecoilController: Weapon fired one-handed. Applying recoil physics and disarming.");
}
FVRViveHand hand = ((FVRInteractiveObject)weapon).m_hand;
if ((Object)(object)hand != (Object)null)
{
hand.Buzz(hand.Buzzer.Buzz_BeginInteraction);
}
((FVRInteractiveObject)weapon).ForceBreakInteraction();
DisableColliders();
Rigidbody rootRigidbody = ((FVRPhysicalObject)weapon).RootRigidbody;
if ((Object)(object)rootRigidbody != (Object)null)
{
Vector3 val2 = -((Component)weapon).transform.forward * recoilForceBack + ((Component)weapon).transform.up * recoilForceUp;
Vector3 val3 = Random.insideUnitSphere * recoilRandomness;
rootRigidbody.AddForce(val2 + val3, (ForceMode)2);
Vector3 val4 = ((Component)weapon).transform.right * recoilTorque;
Vector3 val5 = Random.insideUnitSphere * (recoilRandomness * 3f);
rootRigidbody.AddTorque(val4 + val5, (ForceMode)2);
}
}
}
}
}
private void DisableColliders()
{
disabledColliders.Clear();
Collider[] componentsInChildren = ((Component)weapon).GetComponentsInChildren<Collider>();
foreach (Collider val in componentsInChildren)
{
if ((Object)(object)val != (Object)null && val.enabled)
{
val.enabled = false;
disabledColliders.Add(val);
}
}
colliderRestoreTimer = 0.25f;
}
private void RestoreColliders()
{
for (int i = 0; i < disabledColliders.Count; i++)
{
if ((Object)(object)disabledColliders[i] != (Object)null)
{
disabledColliders[i].enabled = true;
}
}
disabledColliders.Clear();
}
private void TryInitialize()
{
if ((Object)(object)weapon == (Object)null)
{
weapon = ((Component)this).GetComponent<FVRFireArm>();
}
if (!((Object)(object)weapon != (Object)null) || weapon.FChambers == null)
{
return;
}
lastFrameSpent.Clear();
for (int i = 0; i < weapon.FChambers.Count; i++)
{
if ((Object)(object)weapon.FChambers[i] != (Object)null)
{
lastFrameSpent.Add(weapon.FChambers[i].IsSpent);
}
else
{
lastFrameSpent.Add(item: false);
}
}
initialized = true;
}
}
internal class ManualChamberLoad : FVRInteractiveObject
{
public FVRFireArmChamber chamber;
public Transform ChamberSeatedPoint;
public Collider vanillaChamberCollider;
public float loadThreshold = -0.005f;
public float extractThreshold = -0.05f;
public float maxCasingPushDistance = 0.025f;
public float shuckForceThreshold = 1.5f;
public float spentShuckResistance = 6f;
public float shuckSensitivity = 1.2f;
public AudioEvent AudEvent_ShellInStart;
public AudioEvent AudEvent_ShellIn;
public AudioEvent AudEvent_ShellOutStart;
public AudioEvent AudEvent_ShellOut;
public bool debug;
private FVRFireArmRound m_loadingRound;
private float m_roundHandOffsetZ;
private bool m_isExtracting;
private float m_gravitySlideZ;
public override void Awake()
{
((FVRInteractiveObject)this).Awake();
if ((Object)(object)chamber == (Object)null)
{
chamber = ((Component)this).GetComponent<FVRFireArmChamber>();
}
if ((Object)(object)vanillaChamberCollider != (Object)null)
{
vanillaChamberCollider.enabled = false;
if (debug)
{
Debug.Log((object)"ManualChamberLoad: Disabled specified vanilla chamber collider.");
}
}
}
private void Update()
{
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
//IL_01f3: 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_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_0234: Unknown result type (might be due to invalid IL or missing references)
//IL_0239: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_033a: Unknown result type (might be due to invalid IL or missing references)
//IL_033f: Unknown result type (might be due to invalid IL or missing references)
//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
//IL_0473: Unknown result type (might be due to invalid IL or missing references)
//IL_047e: Unknown result type (might be due to invalid IL or missing references)
//IL_0483: Unknown result type (might be due to invalid IL or missing references)
//IL_048d: Unknown result type (might be due to invalid IL or missing references)
//IL_0492: Unknown result type (might be due to invalid IL or missing references)
//IL_056b: Unknown result type (might be due to invalid IL or missing references)
//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)chamber == (Object)null || (Object)(object)ChamberSeatedPoint == (Object)null)
{
return;
}
if ((Object)(object)m_loadingRound != (Object)null)
{
FVRViveHand hand = ((FVRInteractiveObject)m_loadingRound).m_hand;
if ((Object)(object)hand == (Object)null || !((FVRInteractiveObject)m_loadingRound).IsHeld)
{
m_loadingRound = null;
return;
}
float num = ChamberSeatedPoint.InverseTransformPoint(((Component)hand).transform.position).z + m_roundHandOffsetZ;
if (num >= loadThreshold)
{
PlaySound(AudEvent_ShellIn);
((FVRInteractiveObject)m_loadingRound).ForceBreakInteraction();
chamber.SetRound(m_loadingRound, false);
Object.Destroy((Object)(object)((Component)m_loadingRound).gameObject);
m_loadingRound = null;
if (debug)
{
Debug.Log((object)"ManualChamberLoad: Round successfully seated.");
}
}
else if (num < extractThreshold * 1.5f)
{
m_loadingRound = null;
if (debug)
{
Debug.Log((object)"ManualChamberLoad: Loading aborted.");
}
}
else
{
((Component)m_loadingRound).transform.position = ChamberSeatedPoint.TransformPoint(new Vector3(0f, 0f, num));
((Component)m_loadingRound).transform.rotation = ChamberSeatedPoint.rotation;
}
}
if (m_isExtracting)
{
if (!((FVRInteractiveObject)this).IsHeld || (Object)(object)base.m_hand == (Object)null)
{
m_isExtracting = false;
if ((Object)(object)chamber.ProxyRound != (Object)null)
{
chamber.ProxyRound.localPosition = Vector3.zero;
}
return;
}
float num2 = ChamberSeatedPoint.InverseTransformPoint(((Component)base.m_hand).transform.position).z + m_roundHandOffsetZ;
if (num2 <= extractThreshold)
{
PlaySound(AudEvent_ShellOut);
FVRFireArmRound val = chamber.EjectRound(ChamberSeatedPoint.position, Vector3.zero, Vector3.zero, false);
if ((Object)(object)val != (Object)null)
{
((FVRInteractiveObject)val).BeginInteraction(base.m_hand);
base.m_hand.ForceSetInteractable((FVRInteractiveObject)(object)val);
}
((FVRInteractiveObject)this).ForceBreakInteraction();
m_isExtracting = false;
m_gravitySlideZ = 0f;
if (debug)
{
Debug.Log((object)"ManualChamberLoad: Round successfully extracted.");
}
}
else
{
float num3 = Mathf.Clamp(num2, extractThreshold, 0f);
if ((Object)(object)chamber.ProxyRound != (Object)null)
{
chamber.ProxyRound.localPosition = new Vector3(0f, 0f, num3);
}
}
}
if (!chamber.IsFull || !chamber.IsAccessible || ((FVRInteractiveObject)this).IsHeld || !((Object)(object)m_loadingRound == (Object)null))
{
return;
}
float num4 = Vector3.Angle(((Component)chamber).transform.forward, Vector3.up);
float num5 = 0f;
if (!chamber.IsSpent && num4 < 70f)
{
num5 -= Time.deltaTime * 0.2f;
}
Rigidbody val2 = ((!((Object)(object)chamber.Firearm != (Object)null)) ? null : ((FVRPhysicalObject)chamber.Firearm).RootRigidbody);
if ((Object)(object)val2 != (Object)null)
{
float num6 = 0f - ChamberSeatedPoint.InverseTransformDirection(val2.velocity).z;
float num7 = num6 - shuckForceThreshold;
if (num7 > 0f)
{
float num8 = ((!chamber.IsSpent) ? 1f : spentShuckResistance);
num5 -= num7 / num8 * Time.deltaTime * shuckSensitivity;
}
}
if (num5 != 0f)
{
m_gravitySlideZ += num5;
if (m_gravitySlideZ <= extractThreshold)
{
PlaySound(AudEvent_ShellOut);
chamber.EjectRound(ChamberSeatedPoint.position, -ChamberSeatedPoint.forward * 0.5f, Random.onUnitSphere, false);
m_gravitySlideZ = 0f;
if (debug)
{
Debug.Log((object)"ManualChamberLoad: Round ejected via gravity/shucking.");
}
}
else if ((Object)(object)chamber.ProxyRound != (Object)null)
{
chamber.ProxyRound.localPosition = new Vector3(0f, 0f, m_gravitySlideZ);
}
}
else if (m_gravitySlideZ < 0f)
{
m_gravitySlideZ = Mathf.MoveTowards(m_gravitySlideZ, 0f, Time.deltaTime * 0.5f);
if ((Object)(object)chamber.ProxyRound != (Object)null)
{
chamber.ProxyRound.localPosition = new Vector3(0f, 0f, m_gravitySlideZ);
}
}
}
private void OnTriggerStay(Collider other)
{
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)chamber == (Object)null || (Object)(object)ChamberSeatedPoint == (Object)null || !chamber.IsAccessible || chamber.IsFull || (Object)(object)m_loadingRound != (Object)null || m_isExtracting)
{
return;
}
FVRFireArmRound componentInParent = ((Component)other).GetComponentInParent<FVRFireArmRound>();
if (!((Object)(object)componentInParent != (Object)null) || !((FVRInteractiveObject)componentInParent).IsHeld || componentInParent.RoundType != chamber.RoundType)
{
return;
}
FVRViveHand hand = ((FVRInteractiveObject)componentInParent).m_hand;
if ((Object)(object)hand != (Object)null)
{
PlaySound(AudEvent_ShellInStart);
m_loadingRound = componentInParent;
Vector3 val = ChamberSeatedPoint.InverseTransformPoint(((Component)hand).transform.position);
m_roundHandOffsetZ = ChamberSeatedPoint.InverseTransformPoint(((Component)m_loadingRound).transform.position).z - val.z;
if (debug)
{
Debug.Log((object)"ManualChamberLoad: Round entered loading zone. Initializing sliding guide.");
}
}
}
public override bool IsInteractable()
{
return (Object)(object)chamber != (Object)null && chamber.IsFull && chamber.IsAccessible;
}
public override void BeginInteraction(FVRViveHand hand)
{
//IL_0059: 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_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
((FVRInteractiveObject)this).BeginInteraction(hand);
if ((Object)(object)chamber != (Object)null && chamber.IsFull && chamber.IsAccessible)
{
PlaySound(AudEvent_ShellOutStart);
m_isExtracting = true;
Vector3 val = ChamberSeatedPoint.InverseTransformPoint(((Component)hand).transform.position);
float num = 0f;
if ((Object)(object)chamber.ProxyRound != (Object)null)
{
num = chamber.ProxyRound.localPosition.z;
}
m_roundHandOffsetZ = num - val.z;
}
}
public override void EndInteraction(FVRViveHand hand)
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
((FVRInteractiveObject)this).EndInteraction(hand);
m_isExtracting = false;
if ((Object)(object)chamber != (Object)null && (Object)(object)chamber.ProxyRound != (Object)null)
{
chamber.ProxyRound.localPosition = Vector3.zero;
}
}
private void PlaySound(AudioEvent aud)
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
if (aud != null)
{
if ((Object)(object)chamber != (Object)null && (Object)(object)chamber.Firearm != (Object)null)
{
chamber.Firearm.PlayAudioAsHandling(aud, ((Component)this).transform.position);
}
else
{
SM.PlayCoreSound((FVRPooledAudioType)10, aud, ((Component)this).transform.position);
}
}
}
}
internal class ManualCylinderIndex : FVRAlternateGrip
{
public SingleActionRevolver Revolver;
public float indexCooldown = 0.2f;
public bool debug;
private float m_cooldownTimer;
public override void Awake()
{
if ((Object)(object)((FVRInteractiveObject)this).PoseOverride == (Object)null)
{
((FVRInteractiveObject)this).PoseOverride = ((Component)this).transform;
}
((FVRAlternateGrip)this).Awake();
if ((Object)(object)base.PrimaryObject == (Object)null && (Object)(object)Revolver != (Object)null)
{
base.PrimaryObject = (FVRPhysicalObject)(object)Revolver;
}
base.DoesBracing = false;
}
private void Update()
{
if ((Object)(object)Revolver == (Object)null)
{
return;
}
if (m_cooldownTimer > 0f)
{
m_cooldownTimer -= Time.deltaTime;
}
FVRViveHand holdingHand = GetHoldingHand();
if ((Object)(object)holdingHand != (Object)null)
{
bool flag = false;
if (holdingHand.IsInStreamlinedMode)
{
if (holdingHand.Input.AXButtonDown || holdingHand.Input.BYButtonDown)
{
flag = true;
}
}
else if (holdingHand.Input.TouchpadDown)
{
flag = true;
}
if (flag && m_cooldownTimer <= 0f && Revolver.m_isStateToggled)
{
if (debug)
{
Debug.Log((object)"ManualCylinderIndex: Indexing cylinder forward one chamber.");
}
Revolver.AdvanceCylinder();
m_cooldownTimer = indexCooldown;
holdingHand.Buzz(holdingHand.Buzzer.Buzz_BeginInteraction);
}
}
if ((Object)(object)holdingHand != (Object)null)
{
Revolver.UpdateCylinderRot();
}
}
public override bool IsInteractable()
{
return (Object)(object)Revolver != (Object)null && ((FVRAlternateGrip)this).IsInteractable();
}
public override void BeginInteraction(FVRViveHand hand)
{
((FVRAlternateGrip)this).BeginInteraction(hand);
if (debug)
{
Debug.Log((object)"ManualCylinderIndex: Cylinder grabbed safely via AltGrip.");
}
}
public override void EndInteraction(FVRViveHand hand)
{
((FVRAlternateGrip)this).EndInteraction(hand);
if (debug)
{
Debug.Log((object)"ManualCylinderIndex: Cylinder released.");
}
}
private FVRViveHand GetHoldingHand()
{
if ((Object)(object)((FVRInteractiveObject)this).m_hand != (Object)null)
{
return ((FVRInteractiveObject)this).m_hand;
}
if ((Object)(object)Revolver != (Object)null && ((FVRPhysicalObject)Revolver).IsAltHeld)
{
return ((FVRInteractiveObject)Revolver).m_hand;
}
return null;
}
}
internal class ManualRevolverEjectorRod : FVRInteractiveObject
{
public SingleActionRevolver Revolver;
public Transform EjectorRod;
public Transform Point_Rod_Forward;
public Transform Point_Rod_Rearward;
public float Speed_Forward = 10f;
public float Speed_Held = 20f;
public float SpringStiffness = 40f;
public float EjectThreshold = 0.9f;
public float maxCasingPushDistance = 0.025f;
public AudioEvent AudEvent_RodBack;
public AudioEvent AudEvent_RodForward;
public bool debug;
private float m_rodZ;
private float m_rodZ_forward;
private float m_rodZ_rear;
private float m_curSpeed;
private bool m_isRearPlayed;
private bool m_isForwardPlayed;
private bool m_isAutoPushing;
private int m_autoPushDir = 1;
public override void Awake()
{
//IL_0042: 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_005b: 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)
((FVRInteractiveObject)this).Awake();
if ((Object)(object)EjectorRod != (Object)null && (Object)(object)Point_Rod_Forward != (Object)null && (Object)(object)Point_Rod_Rearward != (Object)null)
{
m_rodZ_forward = Point_Rod_Forward.localPosition.z;
m_rodZ_rear = Point_Rod_Rearward.localPosition.z;
m_rodZ = m_rodZ_forward;
}
}
private void Update()
{
//IL_028f: Unknown result type (might be due to invalid IL or missing references)
//IL_0294: Unknown result type (might be due to invalid IL or missing references)
//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
//IL_0196: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: 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_01b6: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: 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_01c8: Unknown result type (might be due to invalid IL or missing references)
//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
//IL_0445: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Revolver == (Object)null || (Object)(object)EjectorRod == (Object)null || (Object)(object)EjectorRod.parent == (Object)null)
{
return;
}
bool isHeld = ((FVRInteractiveObject)this).IsHeld;
float rodZ_forward = m_rodZ_forward;
if ((Object)(object)((FVRInteractiveObject)Revolver).m_hand != (Object)null && ((FVRInteractiveObject)Revolver).m_hand.Input.TriggerDown && Revolver.m_isStateToggled && !isHeld)
{
m_isAutoPushing = true;
m_autoPushDir = 1;
}
if (m_isAutoPushing)
{
m_curSpeed = 0f;
if (m_autoPushDir == 1)
{
m_rodZ = Mathf.MoveTowards(m_rodZ, m_rodZ_rear, Speed_Held * 2f * Time.deltaTime);
if (Mathf.Abs(m_rodZ - m_rodZ_rear) < 0.001f)
{
m_autoPushDir = -1;
}
}
else
{
m_rodZ = Mathf.MoveTowards(m_rodZ, m_rodZ_forward, Speed_Forward * 2f * Time.deltaTime);
if (Mathf.Abs(m_rodZ - m_rodZ_forward) < 0.001f)
{
m_isAutoPushing = false;
m_autoPushDir = 1;
}
}
}
else if (isHeld && (Object)(object)base.m_hand != (Object)null)
{
Vector3 closestValidPoint = ((FVRInteractiveObject)this).GetClosestValidPoint(Point_Rod_Forward.position, Point_Rod_Rearward.position, ((HandInput)(ref base.m_hand.Input)).Pos);
rodZ_forward = EjectorRod.parent.InverseTransformPoint(closestValidPoint).z;
m_curSpeed = 0f;
m_rodZ = Mathf.MoveTowards(m_rodZ, rodZ_forward, Speed_Held * Time.deltaTime);
}
else
{
m_curSpeed = Mathf.MoveTowards(m_curSpeed, Speed_Forward, Time.deltaTime * SpringStiffness);
m_rodZ = Mathf.MoveTowards(m_rodZ, rodZ_forward, m_curSpeed * Time.deltaTime);
}
float num = Mathf.Min(m_rodZ_forward, m_rodZ_rear);
float num2 = Mathf.Max(m_rodZ_forward, m_rodZ_rear);
m_rodZ = Mathf.Clamp(m_rodZ, num, num2);
EjectorRod.localPosition = new Vector3(EjectorRod.localPosition.x, EjectorRod.localPosition.y, m_rodZ);
float num3 = Mathf.InverseLerp(m_rodZ_forward, m_rodZ_rear, m_rodZ);
if (num3 > EjectThreshold)
{
if (!m_isRearPlayed)
{
PlaySound(AudEvent_RodBack);
m_isRearPlayed = true;
m_isForwardPlayed = false;
if (!m_isAutoPushing)
{
Revolver.EjectPrevCylinder();
}
if (debug)
{
Debug.Log((object)"ManualRevolverEjectorRod: Rod reached threshold. Ejecting.");
}
}
}
else if (num3 < 0.1f && !m_isForwardPlayed)
{
PlaySound(AudEvent_RodForward);
m_isForwardPlayed = true;
m_isRearPlayed = false;
}
int num4 = Revolver.PrevChamber;
if (Revolver.IsAccessTwoChambersBack)
{
num4 = Revolver.PrevChamber2;
}
if ((Object)(object)Revolver.Cylinder != (Object)null && Revolver.Cylinder.Chambers != null && num4 < Revolver.Cylinder.Chambers.Length)
{
FVRFireArmChamber val = Revolver.Cylinder.Chambers[num4];
if ((Object)(object)val != (Object)null && val.IsFull && (Object)(object)val.ProxyRound != (Object)null)
{
val.ProxyRound.localPosition = new Vector3(0f, 0f, (0f - num3) * maxCasingPushDistance);
}
}
}
public override bool IsInteractable()
{
return (Object)(object)Revolver != (Object)null && Revolver.m_isStateToggled;
}
public override void BeginInteraction(FVRViveHand hand)
{
((FVRInteractiveObject)this).BeginInteraction(hand);
if ((Object)(object)EjectorRod != (Object)null && (Object)(object)Point_Rod_Forward != (Object)null && (Object)(object)EjectorRod.parent != (Object)(object)Point_Rod_Forward.parent)
{
EjectorRod.SetParent(Point_Rod_Forward.parent);
}
}
private void PlaySound(AudioEvent aud)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
if (aud != null && (Object)(object)Revolver != (Object)null)
{
((FVRFireArm)Revolver).PlayAudioAsHandling(aud, ((Component)this).transform.position);
}
}
}
public class SingleActionPhysicalEnhancer : MonoBehaviour
{
public float CartridgeLength = 0.04f;
public float CartridgePivotOffset = 0f;
public bool DebugMode = false;
private SingleActionRevolver _revolver;
private List<ActiveSlidingRound> _slidingRounds = new List<ActiveSlidingRound>();
private FVRViveHand _ejectorHand;
private FVRViveHand _gateHand;
private FVRViveHand _cylinderHand;
private float _gateStartLocalY;
private bool _hasEjectedThisStroke;
private bool _hasIndexedThisPress;
private void Awake()
{
_revolver = ((Component)this).GetComponent<SingleActionRevolver>();
if (!((Object)(object)_revolver != (Object)null))
{
return;
}
_revolver.StateToggles = false;
if (DebugMode)
{
Debug.Log((object)("SingleActionPhysicalEnhancer: Initialized on revolver " + ((Object)((Component)this).gameObject).name));
}
SingleActionEjectorRod componentInChildren = ((Component)this).GetComponentInChildren<SingleActionEjectorRod>();
if ((Object)(object)componentInChildren != (Object)null)
{
Collider component = ((Component)componentInChildren).GetComponent<Collider>();
if ((Object)(object)component != (Object)null)
{
component.enabled = false;
}
}
}
private void Update()
{
if (!((Object)(object)_revolver == (Object)null))
{
FVRViveHand[] hands = Object.FindObjectsOfType<FVRViveHand>();
UpdateGateInteraction(hands);
UpdateEjectorInteraction(hands);
UpdateCylinderInteraction(hands);
UpdateCartridgeDetection(hands);
UpdateSlidingRounds(hands);
}
}
private void OffsetChamber(int offset)
{
int numChambers = _revolver.Cylinder.NumChambers;
int num = (_revolver.CurChamber + offset) % numChambers;
if (num < 0)
{
num += numChambers;
}
_revolver.CurChamber = num;
_revolver.UpdateCylinderRot();
}
private bool IsHandHoldingGun(FVRViveHand hand)
{
if ((Object)(object)hand == (Object)null)
{
return false;
}
if ((Object)(object)hand.CurrentInteractable == (Object)(object)_revolver)
{
return true;
}
if ((Object)(object)((FVRPhysicalObject)_revolver).AltGrip != (Object)null && (Object)(object)hand.CurrentInteractable == (Object)(object)((FVRPhysicalObject)_revolver).AltGrip)
{
return true;
}
return false;
}
private void UpdateGateInteraction(FVRViveHand[] hands)
{
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: 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_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: 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_00ac: 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)
if ((Object)(object)_gateHand == (Object)null)
{
foreach (FVRViveHand val in hands)
{
if (!((Object)(object)val == (Object)null) && !((Object)(object)val.PalmTransform == (Object)null) && !IsHandHoldingGun(val))
{
float num = Vector3.Distance(val.PalmTransform.position, _revolver.LoadingGate.position);
if (num < 0.04f && val.Input.TriggerPressed)
{
_gateHand = val;
_gateStartLocalY = ((Component)_revolver).transform.InverseTransformPoint(val.PalmTransform.position).y;
break;
}
}
}
return;
}
if (!_gateHand.Input.TriggerPressed)
{
_gateHand = null;
return;
}
float y = ((Component)_revolver).transform.InverseTransformPoint(_gateHand.PalmTransform.position).y;
float num2 = y - _gateStartLocalY;
if (num2 < -0.02f && !_revolver.m_isStateToggled)
{
if (DebugMode)
{
Debug.Log((object)"SingleActionPhysicalEnhancer: Manual gate opening registered.");
}
_revolver.ToggleState();
((FVRFireArm)_revolver).PlayAudioEvent((FirearmAudioEventType)17, 1f);
_gateHand = null;
}
else if (num2 > 0.02f && _revolver.m_isStateToggled)
{
if (DebugMode)
{
Debug.Log((object)"SingleActionPhysicalEnhancer: Manual gate closing registered.");
}
_revolver.ToggleState();
((FVRFireArm)_revolver).PlayAudioEvent((FirearmAudioEventType)18, 1f);
_gateHand = null;
}
}
private void UpdateEjectorInteraction(FVRViveHand[] hands)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: 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_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_0112: 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_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Unknown result type (might be due to invalid IL or missing references)
//IL_0206: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: 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_0081: Unknown result type (might be due to invalid IL or missing references)
Vector3 ejectorRod_Pos_Forward = _revolver.EjectorRod_Pos_Forward;
Vector3 ejectorRod_Pos_Rearward = _revolver.EjectorRod_Pos_Rearward;
if ((Object)(object)_ejectorHand == (Object)null)
{
foreach (FVRViveHand val in hands)
{
if (!((Object)(object)val == (Object)null) && !((Object)(object)val.PalmTransform == (Object)null) && !IsHandHoldingGun(val))
{
float num = Vector3.Distance(val.PalmTransform.position, _revolver.EjectorRod.position);
if (num < 0.04f && val.Input.TriggerPressed)
{
_ejectorHand = val;
break;
}
}
}
}
else if (!_ejectorHand.Input.TriggerPressed)
{
_ejectorHand = null;
}
else
{
float num2 = Mathf.Clamp(((Component)_revolver).transform.InverseTransformPoint(((HandInput)(ref _ejectorHand.Input)).Pos).z, ejectorRod_Pos_Forward.z, ejectorRod_Pos_Rearward.z);
_revolver.EjectorRod.localPosition = new Vector3(_revolver.EjectorRod.localPosition.x, _revolver.EjectorRod.localPosition.y, num2);
float num3 = (num2 - ejectorRod_Pos_Forward.z) / (ejectorRod_Pos_Rearward.z - ejectorRod_Pos_Forward.z);
if (num3 > 0.9f && !_hasEjectedThisStroke)
{
if (DebugMode)
{
Debug.Log((object)"SingleActionPhysicalEnhancer: Ejector stroke completed. Clearing chamber.");
}
_revolver.EjectPrevCylinder();
_hasEjectedThisStroke = true;
}
}
if ((Object)(object)_ejectorHand == (Object)null)
{
_revolver.EjectorRod.localPosition = Vector3.MoveTowards(_revolver.EjectorRod.localPosition, ejectorRod_Pos_Forward, Time.deltaTime * 2f);
_hasEjectedThisStroke = false;
}
}
private void UpdateCylinderInteraction(FVRViveHand[] hands)
{
//IL_0057: 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)
if ((Object)(object)_cylinderHand == (Object)null)
{
foreach (FVRViveHand val in hands)
{
if (!((Object)(object)val == (Object)null) && !((Object)(object)val.PalmTransform == (Object)null) && !IsHandHoldingGun(val))
{
float num = Vector3.Distance(val.PalmTransform.position, ((Component)_revolver.Cylinder).transform.position);
if (num < 0.06f && val.Input.GripPressed && _revolver.m_isStateToggled)
{
_cylinderHand = val;
_hasIndexedThisPress = false;
break;
}
}
}
}
else if (!_cylinderHand.Input.GripPressed || !_revolver.m_isStateToggled)
{
_cylinderHand = null;
}
else if (_cylinderHand.Input.TouchpadDown || _cylinderHand.Input.TriggerDown || _cylinderHand.Input.AXButtonDown || _cylinderHand.Input.BYButtonDown)
{
if (!_hasIndexedThisPress)
{
if (DebugMode)
{
Debug.Log((object)"SingleActionPhysicalEnhancer: Offhand index input registered.");
}
OffsetChamber(1);
_hasIndexedThisPress = true;
}
}
else
{
_hasIndexedThisPress = false;
}
}
private void UpdateCartridgeDetection(FVRViveHand[] hands)
{
//IL_00aa: 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)
if (!_revolver.m_isStateToggled)
{
return;
}
int num = _revolver.PrevChamber;
if (_revolver.IsAccessTwoChambersBack)
{
num = _revolver.PrevChamber2;
}
FVRFireArmChamber val = _revolver.Cylinder.Chambers[num];
if (val.IsFull)
{
return;
}
foreach (FVRViveHand val2 in hands)
{
if ((Object)(object)val2 == (Object)null)
{
continue;
}
FVRInteractiveObject currentInteractable = val2.CurrentInteractable;
FVRFireArmRound val3 = (FVRFireArmRound)(object)((currentInteractable is FVRFireArmRound) ? currentInteractable : null);
if (!((Object)(object)val3 != (Object)null))
{
continue;
}
float num2 = Vector3.Distance(((Component)val3).transform.position, ((Component)val).transform.position);
if (num2 < 0.05f && !IsRoundAlreadySliding(val3))
{
if (DebugMode)
{
Debug.Log((object)("SingleActionPhysicalEnhancer: Proximity trigger met. Dropping cartridge and binding round: " + ((Object)val3).name));
}
((FVRInteractiveObject)val3).ForceBreakInteraction();
BindRoundToChamber(val3, val, val2);
}
}
}
private bool IsRoundAlreadySliding(FVRFireArmRound round)
{
for (int i = 0; i < _slidingRounds.Count; i++)
{
if ((Object)(object)_slidingRounds[i].Round == (Object)(object)round)
{
return true;
}
}
return false;
}
private void BindRoundToChamber(FVRFireArmRound round, FVRFireArmChamber chamber, FVRViveHand hand)
{
Rigidbody component = ((Component)round).GetComponent<Rigidbody>();
if ((Object)(object)component != (Object)null)
{
component.isKinematic = true;
component.useGravity = false;
}
Collider[] componentsInChildren = ((Component)round).GetComponentsInChildren<Collider>();
Collider[] array = componentsInChildren;
foreach (Collider val in array)
{
val.enabled = false;
}
float num = 0f - CartridgePivotOffset;
ActiveSlidingRound activeSlidingRound = new ActiveSlidingRound();
activeSlidingRound.Round = round;
activeSlidingRound.Chamber = chamber;
activeSlidingRound.Hand = hand;
activeSlidingRound.MaxZ = num;
activeSlidingRound.MinZ = num - CartridgeLength;
activeSlidingRound.LocalProgress = activeSlidingRound.MinZ;
_slidingRounds.Add(activeSlidingRound);
}
private void UpdateSlidingRounds(FVRViveHand[] hands)
{
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_0184: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_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_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: 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_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_0209: Unknown result type (might be due to invalid IL or missing references)
for (int num = _slidingRounds.Count - 1; num >= 0; num--)
{
ActiveSlidingRound activeSlidingRound = _slidingRounds[num];
if ((Object)(object)activeSlidingRound.Round == (Object)null || (Object)(object)activeSlidingRound.Chamber == (Object)null)
{
_slidingRounds.RemoveAt(num);
}
else if (((FVRInteractiveObject)activeSlidingRound.Round).IsHeld)
{
if (DebugMode)
{
Debug.Log((object)"SingleActionPhysicalEnhancer: Cartridge was grabbed again. Restoring physics.");
}
RestoreRoundPhysics(activeSlidingRound.Round);
_slidingRounds.RemoveAt(num);
}
else
{
Vector3 forward = ((Component)activeSlidingRound.Chamber).transform.forward;
Vector3 position = ((Component)activeSlidingRound.Chamber).transform.position;
foreach (FVRViveHand val in hands)
{
if (!((Object)(object)val == (Object)null) && !((Object)(object)val.PalmTransform == (Object)null))
{
Vector3 val2 = val.PalmTransform.position - position;
float num2 = Vector3.Dot(val2, forward);
Vector3 val3 = val2 - forward * num2;
if (((Vector3)(ref val3)).magnitude < 0.03f && num2 < activeSlidingRound.MaxZ && num2 > activeSlidingRound.LocalProgress)
{
activeSlidingRound.LocalProgress = num2;
}
}
}
((Component)activeSlidingRound.Round).transform.position = ((Component)activeSlidingRound.Chamber).transform.position + ((Component)activeSlidingRound.Chamber).transform.forward * activeSlidingRound.LocalProgress;
((Component)activeSlidingRound.Round).transform.rotation = ((Component)activeSlidingRound.Chamber).transform.rotation;
if (activeSlidingRound.LocalProgress >= activeSlidingRound.MaxZ - 0.002f)
{
if (DebugMode)
{
Debug.Log((object)"SingleActionPhysicalEnhancer: Cartridge reached seating threshold. Chambering round.");
}
activeSlidingRound.Chamber.Autochamber(activeSlidingRound.Round.RoundClass);
((FVRFireArm)_revolver).PlayAudioEvent((FirearmAudioEventType)42, 1f);
((Component)activeSlidingRound.Round).gameObject.SetActive(false);
Object.Destroy((Object)(object)((Component)activeSlidingRound.Round).gameObject);
_slidingRounds.RemoveAt(num);
}
}
}
}
private void RestoreRoundPhysics(FVRFireArmRound round)
{
Rigidbody component = ((Component)round).GetComponent<Rigidbody>();
if ((Object)(object)component != (Object)null)
{
component.isKinematic = false;
component.useGravity = true;
}
Collider[] componentsInChildren = ((Component)round).GetComponentsInChildren<Collider>();
Collider[] array = componentsInChildren;
foreach (Collider val in array)
{
val.enabled = true;
}
}
}
public class ActiveSlidingRound
{
public FVRFireArmRound Round;
public FVRFireArmChamber Chamber;
public FVRViveHand Hand;
public float MinZ;
public float MaxZ;
public float LocalProgress;
}
public class MagTapeFix : MonoBehaviour
{
private enum ActiveMagazine
{
primary,
secondary
}
private enum AttachedMagazine
{
none,
primary,
secondary
}
[Tooltip("Enable status logging in the Unity console.")]
public bool EnableDebug = false;
[Tooltip("Main Magazine")]
public FVRFireArmMagazine PrimaryMagazine;
[Tooltip("Attached Magazine")]
public FVRFireArmMagazine SecondaryMagazine;
[Tooltip("Tape visuals and colliders (not a requirement)")]
public GameObject Tape = null;
[Header("Relative Mag Positions (Use Context Menu to calculate)")]
[Tooltip("Primary mag position when parented to secondary mag.")]
[ReadOnly]
public Vector3 Primary2SecondaryPos;
[Tooltip("Primary mag rotation when parented to secondary mag.")]
[ReadOnly]
public Quaternion Primary2SecondaryRot;
[Tooltip("Secondary mag position when parented to primary mag.")]
[ReadOnly]
public Vector3 Secondary2PrimaryPos;
[Tooltip("Primary mag rotation when parented to primary mag.")]
[ReadOnly]
public Quaternion Secondary2PrimaryRot;
private ActiveMagazine _activeMagazine = ActiveMagazine.primary;
private AttachedMagazine _attachedMagazine = AttachedMagazine.none;
private List<Collider> _primaryColliders = new List<Collider>();
private List<Collider> _secondaryColliders = new List<Collider>();
private void Log(string message, params object[] args)
{
if (EnableDebug)
{
if (args != null && args.Length > 0)
{
Debug.Log((object)string.Format(message, args));
}
else
{
Debug.Log((object)message);
}
}
}
[ContextMenu("Calculate Relative Mag Positions")]
public void CalculateReltativeMagPositions()
{
//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_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: 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_0078: 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_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
Secondary2PrimaryPos = ((Component)PrimaryMagazine).transform.InverseTransformPoint(((Component)SecondaryMagazine).transform.position);
Secondary2PrimaryRot = Quaternion.Inverse(((Component)PrimaryMagazine).transform.rotation) * ((Component)SecondaryMagazine).transform.rotation;
Primary2SecondaryPos = ((Component)SecondaryMagazine).transform.InverseTransformPoint(((Component)PrimaryMagazine).transform.position);
Primary2SecondaryRot = Quaternion.Inverse(((Component)SecondaryMagazine).transform.rotation) * ((Component)PrimaryMagazine).transform.rotation;
Log("[MagTapeFix] Relative positions calculated and updated in Inspector.");
}
private void SetCollidersAndLayer(FVRFireArmMagazine mag, bool enabled, string layerName)
{
if ((Object)(object)mag == (Object)null)
{
return;
}
((Component)mag).gameObject.layer = LayerMask.NameToLayer(layerName);
Log("[MagTapeFix] Setting root layer of {0} to '{1}'", ((Object)mag).name, layerName);
List<Collider> list = ((!((Object)(object)mag == (Object)(object)PrimaryMagazine)) ? _secondaryColliders : _primaryColliders);
Log("[MagTapeFix] Ensuring {0} colliders on {1} stay active (Enabled: {2})", list.Count, ((Object)mag).name, enabled);
for (int i = 0; i < list.Count; i++)
{
if ((Object)(object)list[i] != (Object)null)
{
list[i].enabled = enabled;
}
}
}
public void Start()
{
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Invalid comparison between Unknown and I4
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Invalid comparison between Unknown and I4
Log("[MagTapeFix] Initializing...");
_primaryColliders.Clear();
_secondaryColliders.Clear();
List<Collider> list = new List<Collider>();
list.AddRange(((Component)PrimaryMagazine).GetComponentsInChildren<Collider>(true));
list.AddRange(((Component)SecondaryMagazine).GetComponentsInChildren<Collider>(true));
HashSet<Collider> hashSet = new HashSet<Collider>(list);
foreach (Collider item in hashSet)
{
if (!((Object)(object)item == (Object)null))
{
FVRFireArmMagazine componentInParent = ((Component)item).GetComponentInParent<FVRFireArmMagazine>();
if ((Object)(object)componentInParent == (Object)(object)PrimaryMagazine)
{
_primaryColliders.Add(item);
}
else if ((Object)(object)componentInParent == (Object)(object)SecondaryMagazine)
{
_secondaryColliders.Add(item);
}
}
}
Log("[MagTapeFix] Cached {0} colliders for Primary, {1} for Secondary.", _primaryColliders.Count, _secondaryColliders.Count);
if ((int)PrimaryMagazine.State == 1)
{
Log("[MagTapeFix] Primary Magazine spawned in LOCKED state.");
_attachedMagazine = AttachedMagazine.primary;
((FVRPhysicalObject)SecondaryMagazine).StoreAndDestroyRigidbody();
((FVRPhysicalObject)SecondaryMagazine).RootRigidbody = ((FVRPhysicalObject)PrimaryMagazine).RootRigidbody;
SetCollidersAndLayer(SecondaryMagazine, enabled: true, "NoCol");
SetCollidersAndLayer(PrimaryMagazine, enabled: true, "Interactable");
}
else if ((int)SecondaryMagazine.State == 1)
{
Log("[MagTapeFix] Secondary Magazine spawned in LOCKED state.");
_attachedMagazine = AttachedMagazine.secondary;
_activeMagazine = ActiveMagazine.secondary;
((FVRPhysicalObject)PrimaryMagazine).StoreAndDestroyRigidbody();
((FVRPhysicalObject)PrimaryMagazine).RootRigidbody = ((FVRPhysicalObject)SecondaryMagazine).RootRigidbody;
SetCollidersAndLayer(PrimaryMagazine, enabled: true, "NoCol");
SetCollidersAndLayer(SecondaryMagazine, enabled: true, "Interactable");
}
else if ((Object)(object)((Component)PrimaryMagazine).transform.parent == (Object)(object)((Component)SecondaryMagazine).transform)
{
Log("[MagTapeFix] Spawning with Secondary as parent.");
_activeMagazine = ActiveMagazine.secondary;
((FVRPhysicalObject)PrimaryMagazine).StoreAndDestroyRigidbody();
((FVRPhysicalObject)PrimaryMagazine).RootRigidbody = ((FVRPhysicalObject)SecondaryMagazine).RootRigidbody;
SetCollidersAndLayer(PrimaryMagazine, enabled: true, "NoCol");
SetCollidersAndLayer(SecondaryMagazine, enabled: true, "Interactable");
}
else
{
Log("[MagTapeFix] Spawning with Primary as parent (Default).");
_activeMagazine = ActiveMagazine.primary;
((FVRPhysicalObject)SecondaryMagazine).StoreAndDestroyRigidbody();
((FVRPhysicalObject)SecondaryMagazine).RootRigidbody = ((FVRPhysicalObject)PrimaryMagazine).RootRigidbody;
SetCollidersAndLayer(SecondaryMagazine, enabled: true, "NoCol");
SetCollidersAndLayer(PrimaryMagazine, enabled: true, "Interactable");
}
}
public void Update()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Invalid comparison between Unknown and I4
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Invalid comparison between Unknown and I4
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Unknown result type (might be due to invalid IL or missing references)
//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
try
{
if ((int)PrimaryMagazine.State == 1 && _attachedMagazine == AttachedMagazine.none && _activeMagazine == ActiveMagazine.secondary)
{
Log("[MagTapeFix] Auto-Reload: Primary Magazine locked into magwell. Swapping parents automatically.");
_attachedMagazine = AttachedMagazine.primary;
((FVRInteractiveObject)SecondaryMagazine).ForceBreakInteraction();
((FVRInteractiveObject)SecondaryMagazine).IsHeld = false;
UsePrimaryAsParent(((Component)PrimaryMagazine).transform.parent);
((FVRPhysicalObject)SecondaryMagazine).StoreAndDestroyRigidbody();
((FVRPhysicalObject)SecondaryMagazine).RootRigidbody = ((FVRPhysicalObject)PrimaryMagazine).RootRigidbody;
SetCollidersAndLayer(SecondaryMagazine, enabled: true, "NoCol");
SetCollidersAndLayer(PrimaryMagazine, enabled: true, "Interactable");
}
else if ((int)SecondaryMagazine.State == 1 && _attachedMagazine == AttachedMagazine.none && _activeMagazine == ActiveMagazine.primary)
{
Log("[MagTapeFix] Auto-Reload: Secondary Magazine locked into magwell. Swapping parents automatically.");
_attachedMagazine = AttachedMagazine.secondary;
((FVRInteractiveObject)PrimaryMagazine).ForceBreakInteraction();
((FVRInteractiveObject)PrimaryMagazine).IsHeld = false;
UseSecondaryAsParent(((Component)SecondaryMagazine).transform.parent);
((FVRPhysicalObject)PrimaryMagazine).StoreAndDestroyRigidbody();
((FVRPhysicalObject)PrimaryMagazine).RootRigidbody = ((FVRPhysicalObject)SecondaryMagazine).RootRigidbody;
SetCollidersAndLayer(PrimaryMagazine, enabled: true, "NoCol");
SetCollidersAndLayer(SecondaryMagazine, enabled: true, "Interactable");
}
else if ((int)PrimaryMagazine.State == 0 && (int)SecondaryMagazine.State == 0 && _attachedMagazine != AttachedMagazine.none)
{
Log("[MagTapeFix] Both magazines are now free (unlocked). Resetting attachment tracking.");
_attachedMagazine = AttachedMagazine.none;
}
if (_activeMagazine == ActiveMagazine.primary)
{
UpdateSecondaryMagTransform();
}
else if (_activeMagazine == ActiveMagazine.secondary)
{
UpdatePrimaryMagTransform();
}
}
catch (Exception ex)
{
if ((Object)(object)PrimaryMagazine == (Object)null || (Object)(object)SecondaryMagazine == (Object)null)
{
Debug.LogWarning((object)"[MagTapeFix] A magazine was destroyed! Cleaning up component.");
Object.Destroy((Object)(object)Tape);
Object.Destroy((Object)(object)((Component)this).GetComponent<MagTapeFix>());
}
else
{
Debug.LogError((object)("[MagTapeFix] Error in Update Loop: " + ex.Message));
}
}
if (_activeMagazine == ActiveMagazine.primary)
{
if (!((Object)(object)((FVRInteractiveObject)PrimaryMagazine).m_hand != (Object)null))
{
return;
}
FVRViveHand hand = ((FVRInteractiveObject)PrimaryMagazine).m_hand;
if (hand.IsInStreamlinedMode)
{
if (hand.Input.AXButtonDown || hand.Input.TouchpadDown)
{
Log("[MagTapeFix] Input detected (Streamlined). Initiating manual pose swap to Secondary.");
ChangeActiveToSecondary(hand);
}
}
else if (hand.Input.TouchpadDown && Vector2.Angle(hand.Input.TouchpadAxes, Vector2.right) < 45f)
{
Log("[MagTapeFix] Input detected (Classic). Initiating manual pose swap to Secondary.");
ChangeActiveToSecondary(hand);
}
}
else
{
if (_activeMagazine != ActiveMagazine.secondary || !((Object)(object)((FVRInteractiveObject)SecondaryMagazine).m_hand != (Object)null))
{
return;
}
FVRViveHand hand2 = ((FVRInteractiveObject)SecondaryMagazine).m_hand;
if (hand2.IsInStreamlinedMode)
{
if (hand2.Input.AXButtonDown || hand2.Input.TouchpadDown)
{
Log("[MagTapeFix] Input detected (Streamlined). Initiating manual pose swap to Primary.");
ChangeActiveToPrimary(hand2);
}
}
else if (hand2.Input.TouchpadDown && Vector2.Angle(hand2.Input.TouchpadAxes, Vector2.right) < 45f)
{
Log("[MagTapeFix] Input detected (Classic). Initiating manual pose swap to Primary.");
ChangeActiveToPrimary(hand2);
}
}
}
private void UsePrimaryAsParent(Transform parent = null)
{
Log("[MagTapeFix] Parenting Secondary under Primary.");
_activeMagazine = ActiveMagazine.primary;
((Component)PrimaryMagazine).transform.SetParent(parent);
((Component)SecondaryMagazine).transform.SetParent(((Component)PrimaryMagazine).transform);
}
private void UseSecondaryAsParent(Transform parent = null)
{
Log("[MagTapeFix] Parenting Primary under Secondary.");
_activeMagazine = ActiveMagazine.secondary;
((Component)SecondaryMagazine).transform.SetParent(parent);
((Component)PrimaryMagazine).transform.SetParent(((Component)SecondaryMagazine).transform);
}
private void UpdateSecondaryMagTransform()
{
//IL_000d: 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)
((Component)SecondaryMagazine).transform.localPosition = Secondary2PrimaryPos;
((Component)SecondaryMagazine).transform.localRotation = Secondary2PrimaryRot;
}
private void UpdatePrimaryMagTransform()
{
//IL_000d: 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)
((Component)PrimaryMagazine).transform.localPosition = Primary2SecondaryPos;
((Component)PrimaryMagazine).transform.localRotation = Primary2SecondaryRot;
}
private void ChangeActiveToPrimary(FVRViveHand hand)
{
Log("[MagTapeFix] Manually activating Primary Magazine...");
((FVRInteractiveObject)SecondaryMagazine).ForceBreakInteraction();
((FVRInteractiveObject)SecondaryMagazine).IsHeld = false;
((FVRPhysicalObject)PrimaryMagazine).RecoverRigidbody();
UsePrimaryAsParent();
((FVRPhysicalObject)SecondaryMagazine).StoreAndDestroyRigidbody();
((FVRPhysicalObject)SecondaryMagazine).RootRigidbody = ((FVRPhysicalObject)PrimaryMagazine).RootRigidbody;
SetCollidersAndLayer(SecondaryMagazine, enabled: true, "NoCol");
SetCollidersAndLayer(PrimaryMagazine, enabled: true, "Interactable");
hand.ForceSetInteractable((FVRInteractiveObject)(object)PrimaryMagazine);
((FVRInteractiveObject)PrimaryMagazine).BeginInteraction(hand);
Log("[MagTapeFix] Manual pose swap complete. Primary is now active.");
}
private void ChangeActiveToSecondary(FVRViveHand hand)
{
Log("[MagTapeFix] Manually activating Secondary Magazine...");
((FVRInteractiveObject)PrimaryMagazine).ForceBreakInteraction();
((FVRInteractiveObject)PrimaryMagazine).IsHeld = false;
((FVRPhysicalObject)SecondaryMagazine).RecoverRigidbody();
UseSecondaryAsParent();
((FVRPhysicalObject)PrimaryMagazine).StoreAndDestroyRigidbody();
((FVRPhysicalObject)PrimaryMagazine).RootRigidbody = ((FVRPhysicalObject)SecondaryMagazine).RootRigidbody;
SetCollidersAndLayer(PrimaryMagazine, enabled: true, "NoCol");
SetCollidersAndLayer(SecondaryMagazine, enabled: true, "Interactable");
hand.ForceSetInteractable((FVRInteractiveObject)(object)SecondaryMagazine);
((FVRInteractiveObject)SecondaryMagazine).BeginInteraction(hand);
Log("[MagTapeFix] Manual pose swap complete. Secondary is now active.");
}
}
internal class Mauser0608Controller : MonoBehaviour
{
public FVRFireArm weapon;
public float slideForwardShiftOnMagEject = 0.004f;
public bool debug;
public Transform manualReleaseTriggerPoint;
public float triggerRadius = 0.03f;
private Handgun hg;
private FVRFireArmMagazine lastFrameMag;
private float originalSlideZLock;
private FieldInfo slideZLockField;
private FieldInfo slideSpeedField;
private bool initialized;
private void Start()
{
TryInitialize();
}
private void Update()
{
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Invalid comparison between Unknown and I4
//IL_0220: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
if (!initialized)
{
TryInitialize();
}
else
{
if ((Object)(object)hg == (Object)null)
{
return;
}
FVRFireArmMagazine magazine = ((FVRFireArm)hg).Magazine;
if ((Object)(object)magazine != (Object)(object)lastFrameMag)
{
if ((Object)(object)magazine != (Object)null && (Object)(object)lastFrameMag == (Object)null)
{
OnMagazineInserted();
}
else if ((Object)(object)magazine == (Object)null && (Object)(object)lastFrameMag != (Object)null)
{
OnMagazineEjected();
}
lastFrameMag = magazine;
}
if (!((Object)(object)magazine == (Object)null) || !((Object)(object)hg.Slide != (Object)null))
{
return;
}
if ((int)hg.Slide.CurPos == 4 && !hg.IsSlideLockUp)
{
if (debug)
{
Debug.Log((object)"Mauser0608Controller: Slide racked to rear without a magazine. Locking open.");
}
hg.EngageSlideRelease();
}
if (((FVRInteractiveObject)hg.Slide).IsHeld && (Object)(object)((FVRInteractiveObject)hg.Slide).m_hand != (Object)null)
{
FVRViveHand hand = ((FVRInteractiveObject)hg.Slide).m_hand;
bool flag = false;
if (hand.IsInStreamlinedMode)
{
if (hand.Input.BYButtonDown || hand.Input.AXButtonDown)
{
flag = true;
}
}
else if (hand.Input.TouchpadDown && Vector2.Angle(hand.Input.TouchpadAxes, Vector2.down) <= 45f)
{
flag = true;
}
if (flag && hg.IsSlideLockUp)
{
if (debug)
{
Debug.Log((object)"Mauser0608Controller: Manual slide release override triggered via hand input.");
}
hg.DropSlideRelease();
}
}
if (!((Object)(object)manualReleaseTriggerPoint != (Object)null) || !hg.IsSlideLockUp)
{
return;
}
Collider[] array = Physics.OverlapSphere(manualReleaseTriggerPoint.position, triggerRadius);
for (int i = 0; i < array.Length; i++)
{
FVRViveHand componentInParent = ((Component)array[i]).GetComponentInParent<FVRViveHand>();
if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent != (Object)(object)((FVRInteractiveObject)hg).m_hand && ((Object)(object)hg.Slide == (Object)null || (Object)(object)componentInParent != (Object)(object)((FVRInteractiveObject)hg.Slide).m_hand))
{
if (debug)
{
Debug.Log((object)"Mauser0608Controller: Hand detected near trigger point. Releasing slide.");
}
hg.DropSlideRelease();
break;
}
}
}
}
private void TryInitialize()
{
if (!((Object)(object)weapon != (Object)null) || !(weapon is Handgun))
{
return;
}
ref Handgun reference = ref hg;
FVRFireArm obj = weapon;
reference = (Handgun)(object)((obj is Handgun) ? obj : null);
lastFrameMag = ((FVRFireArm)hg).Magazine;
slideZLockField = typeof(HandgunSlide).GetField("m_slideZ_lock", BindingFlags.Instance | BindingFlags.NonPublic);
slideSpeedField = typeof(HandgunSlide).GetField("m_curSlideSpeed", BindingFlags.Instance | BindingFlags.NonPublic);
if ((Object)(object)hg.Slide != (Object)null && (object)slideZLockField != null)
{
originalSlideZLock = (float)slideZLockField.GetValue(hg.Slide);
initialized = true;
if ((Object)(object)lastFrameMag == (Object)null)
{
float num = originalSlideZLock + slideForwardShiftOnMagEject;
slideZLockField.SetValue(hg.Slide, num);
}
if (debug)
{
Debug.Log((object)("Mauser0608Controller: Initialized. Original Z lock is " + originalSlideZLock));
}
}
}
private void OnMagazineInserted()
{
if (debug)
{
Debug.Log((object)"Mauser0608Controller: Magazine inserted.");
}
ResetSlideLock();
if (hg.IsSlideLockUp)
{
if (debug)
{
Debug.Log((object)"Mauser0608Controller: Slide is locked. Dropping slide release.");
}
hg.DropSlideRelease();
}
}
private void OnMagazineEjected()
{
if (debug)
{
Debug.Log((object)"Mauser0608Controller: Magazine ejected.");
}
if (hg.IsSlideLockUp && (object)slideZLockField != null)
{
float num = originalSlideZLock + slideForwardShiftOnMagEject;
if (debug)
{
Debug.Log((object)("Mauser0608Controller: Shifting slide lock to " + num));
}
slideZLockField.SetValue(hg.Slide, num);
if ((object)slideSpeedField != null)
{
slideSpeedField.SetValue(hg.Slide, hg.Slide.Speed_Forward);
}
}
}
private void ResetSlideLock()
{
if ((Object)(object)hg.Slide != (Object)null && (object)slideZLockField != null)
{
if (debug)
{
Debug.Log((object)("Mauser0608Controller: Resetting slide lock to " + originalSlideZLock));
}
slideZLockField.SetValue(hg.Slide, originalSlideZLock);
}
}
}
namespace Volks.AirTronic_PSRL;
[BepInPlugin("Volks.AirTronic_PSRL", "AirTronic_PSRL", "1.0.1")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
public class AirTronic_PSRLPlugin : 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.AirTronic_PSRL");
OtherLoader.RegisterDirectLoad(BasePath, "Volks.AirTronic_PSRL", "", "", "airtronic_rpg", "");
}
}
public class UnderbarrelChainsaw : AttachableMeleeWeapon
{
public AudioSource SawAudio;
public AudioSource StartingAudio;
public AudioClip AudClip_Start;
public AudioClip AudClip_Idle;
public AudioClip AudClip_Buzzing;
public AudioClip AudClip_Hitting;
public bool UsesBladeSolidBits = true;
public Renderer BladeSolid;
public Renderer BladeBits;
public Collider[] BladeCols;
public ParticleSystem Sparks;
public Transform BladePoint1;
public Transform BladePoint2;
public ParticleSystem EngineSmoke;
public bool UsesEngineRot = true;
public Transform EngineRot;
public float PerceptibleEventVolume = 50f;
public float PerceptibleEventRange = 30f;
public float BaseCuttingDamage = 250f;
public bool ChainsawDebugMode;
private Material m_matBladeSolid;
private Material m_matBladeBits;
private EmitParams emitParams;
private List<IFVRDamageable> DamageablesToDo = new List<IFVRDamageable>();
private HashSet<IFVRDamageable> DamageablesToDoHS = new HashSet<IFVRDamageable>();
private List<Vector3> DamageableHitPoints = new List<Vector3>();
private List<Vector3> DamageableHitNormals = new List<Vector3>();
private HashSet<Collider> m_bladeCols = new HashSet<Collider>();
private Collider[] m_overlapResults = (Collider[])(object)new Collider[10];
[NonSerialized]
[HideInInspector]
public float m_sawingIntensity;
[NonSerialized]
[HideInInspector]
public float triggerAmount;
[NonSerialized]
[HideInInspector]
public bool m_isRunning;
[NonSerialized]
[HideInInspector]
public float m_motorSpeed;
private float TimeSinceDamageDealing = 0.2f;
private float m_timeTilPerceptibleEventTick = 0.2f;
private float m_timeSinceCollision = 1f;
private int framesTilFlash;
private bool m_isCustomLodged;
private FixedJoint m_customLodgeJoint;
private Rigidbody m_customLodgeTargetRB;
private SosigLink m_customLodgeLink;
private float m_lodgeContactTimer;
public override void Awake()
{
//IL_000a: 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_0011: Unknown result type (might be due to invalid IL or missing references)
((FVRFireArmAttachment)this).Awake();
emitParams = default(EmitParams);
if (UsesBladeSolidBits && (Object)(object)BladeSolid != (Object)null && (Object)(object)BladeBits != (Object)null)
{
m_matBladeSolid = BladeSolid.materials[0];
m_matBladeBits = BladeBits.material;
}
for (int i = 0; i < BladeCols.Length; i++)
{
m_bladeCols.Add(BladeCols[i]);
}
}
public override void UpdateInteraction(FVRViveHand hand)
{
((FVRFireArmAttachment)this).UpdateInteraction(hand);
if ((Object)(object)hand != (Object)null)
{
SetMotorPower(hand.Input.TriggerFloat);
}
}
public override void EndInteraction(FVRViveHand hand)
{
StopMotor();
((FVRFireArmAttachment)this).EndInteraction(hand);
}
public override void FVRUpdate()
{
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_063d: Unknown result type (might be due to invalid IL or missing references)
//IL_0644: Expected O, but got Unknown
//IL_067d: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Unknown result type (might be due to invalid IL or missing references)
//IL_026f: Unknown result type (might be due to invalid IL or missing references)
//IL_0274: Unknown result type (might be due to invalid IL or missing references)
//IL_027e: Unknown result type (might be due to invalid IL or missing references)
//IL_0283: Unknown result type (might be due to invalid IL or missing references)
//IL_028b: Unknown result type (might be due to invalid IL or missing references)
//IL_0296: Unknown result type (might be due to invalid IL or missing references)
//IL_029b: Unknown result type (might be due to invalid IL or missing references)
//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
//IL_02af: Unknown result type (might be due to invalid IL or missing references)
//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
//IL_02de: Unknown result type (might be due to invalid IL or missing references)
//IL_06a9: Unknown result type (might be due to invalid IL or missing references)
//IL_06b4: Expected O, but got Unknown
//IL_06c4: Unknown result type (might be due to invalid IL or missing references)
//IL_06c9: Unknown result type (might be due to invalid IL or missing references)
//IL_06d8: Unknown result type (might be due to invalid IL or missing references)
//IL_06dd: Unknown result type (might be due to invalid IL or missing references)
//IL_06e6: Unknown result type (might be due to invalid IL or missing references)
//IL_06eb: Unknown result type (might be due to invalid IL or missing references)
//IL_06f0: Unknown result type (might be due to invalid IL or missing references)
//IL_087f: Unknown result type (might be due to invalid IL or missing references)
//IL_0884: Unknown result type (might be due to invalid IL or missing references)
//IL_0888: Unknown result type (might be due to invalid IL or missing references)
//IL_088d: Unknown result type (might be due to invalid IL or missing references)
//IL_08b1: Unknown result type (might be due to invalid IL or missing references)
//IL_0b4a: Unknown result type (might be due to invalid IL or missing references)
//IL_0b4f: Unknown result type (might be due to invalid IL or missing references)
//IL_0b53: Unknown result type (might be due to invalid IL or missing references)
//IL_0b58: Unknown result type (might be due to invalid IL or missing references)
//IL_0ba4: Unknown result type (might be due to invalid IL or missing references)
//IL_0afd: Unknown result type (might be due to invalid IL or missing references)
//IL_0b02: Unknown result type (might be due to invalid IL or missing references)
//IL_0b21: Unknown result type (might be due to invalid IL or missing references)
//IL_0b26: Unknown result type (might be due to invalid IL or missing references)
//IL_0a1d: Unknown result type (might be due to invalid IL or missing references)
//IL_0a22: Unknown result type (might be due to invalid IL or missing references)
//IL_0a42: Unknown result type (might be due to invalid IL or missing references)
//IL_0a47: Unknown result type (might be due to invalid IL or missing references)
//IL_083d: Unknown result type (might be due to invalid IL or missing references)
//IL_0842: Unknown result type (might be due to invalid IL or missing references)
//IL_0857: Unknown result type (might be due to invalid IL or missing references)
//IL_085c: Unknown result type (might be due to invalid IL or missing references)
//IL_0347: Unknown result type (might be due to invalid IL or missing references)
//IL_0349: Unknown result type (might be due to invalid IL or missing references)
//IL_034e: Unknown result type (might be due to invalid IL or missing references)
//IL_0371: Unknown result type (might be due to invalid IL or missing references)
//IL_037c: Unknown result type (might be due to invalid IL or missing references)
//IL_0381: Unknown result type (might be due to invalid IL or missing references)
//IL_0383: Unknown result type (might be due to invalid IL or missing references)
//IL_0388: Unknown result type (might be due to invalid IL or missing references)
//IL_038a: Unknown result type (might be due to invalid IL or missing references)
//IL_038c: Unknown result type (might be due to invalid IL or missing references)
//IL_038e: Unknown result type (might be due to invalid IL or missing references)
//IL_0393: Unknown result type (might be due to invalid IL or missing references)
//IL_0395: Unknown result type (might be due to invalid IL or missing references)
//IL_039c: Unknown result type (might be due to invalid IL or missing references)
//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0400: Unknown result type (might be due to invalid IL or missing references)
//IL_0402: Unknown result type (might be due to invalid IL or missing references)
//IL_0409: Unknown result type (might be due to invalid IL or missing references)
//IL_040e: Unknown result type (might be due to invalid IL or missing references)
//IL_0413: Unknown result type (might be due to invalid IL or missing references)
//IL_041b: Unknown result type (might be due to invalid IL or missing references)
//IL_043b: Unknown result type (might be due to invalid IL or missing references)
//IL_0461: Unknown result type (might be due to invalid IL or missing references)
//IL_0469: Unknown result type (might be due to invalid IL or missing references)
//IL_046e: Unknown result type (might be due to invalid IL or missing references)
//IL_0470: Unknown result type (might be due to invalid IL or missing references)
//IL_0475: Unknown result type (might be due to invalid IL or missing references)
//IL_0479: Unknown result type (might be due to invalid IL or missing references)
//IL_048d: Unknown result type (might be due to invalid IL or missing references)
//IL_0c34: Unknown result type (might be due to invalid IL or missing references)
//IL_0c39: Unknown result type (might be due to invalid IL or missing references)
//IL_0d3f: Unknown result type (might be due to invalid IL or missing references)
//IL_0528: Unknown result type (might be due to invalid IL or missing references)
//IL_053b: Unknown result type (might be due to invalid IL or missing references)
//IL_0540: Unknown result type (might be due to invalid IL or missing references)
//IL_0542: Unknown result type (might be due to invalid IL or missing references)
//IL_0547: Unknown result type (might be due to invalid IL or missing references)
//IL_054b: Unknown result type (might be due to invalid IL or missing references)
//IL_0cb1: Unknown result type (might be due to invalid IL or missing references)
((FVRPhysicalObject)this).FVRUpdate();
bool flag = false;
if ((Object)(object)((FVRFireArmAttachment)this).curMount != (Object)null && ((FVRFireArmAttachment)this).curMount.Parent is FVRFireArm)
{
FVRPhysicalObject parent = ((FVRFireArmAttachment)this).curMount.Parent;
FVRFireArm val = (FVRFireArm)(object)((parent is FVRFireArm) ? parent : null);
UnderbarrelChainsawInterface underbarrelChainsawInterface = ((FVRFireArmAttachment)this).AttachmentInterface as UnderbarrelChainsawInterface;
if ((Object)(object)((FVRPhysicalObject)val).AltGrip != (Object)null && (Object)(object)((FVRPhysicalObject)val).AltGrip.LastGrabbedInGrip == (Object)(object)underbarrelChainsawInterface && ((FVRInteractiveObject)((FVRPhysicalObject)val).AltGrip).IsHeld)
{
flag = true;
m_isRunning = true;
if ((Object)(object)((FVRInteractiveObject)((FVRPhysicalObject)val).AltGrip).m_hand != (Object)null)
{
triggerAmount = ((FVRInteractiveObject)((FVRPhysicalObject)val).AltGrip).m_hand.Input.TriggerFloat;
}
}
}
if (!flag)
{
if (((FVRInteractiveObject)this).IsHeld && (Object)(object)((FVRInteractiveObject)this).m_hand != (Object)null)
{
m_isRunning = true;
triggerAmount = ((FVRInteractiveObject)this).m_hand.Input.TriggerFloat;
}
else if (m_isRunning)
{
StopMotor();
}
}
if (m_isCustomLodged)
{
if ((Object)(object)m_customLodgeJoint == (Object)null || (Object)(object)m_customLodgeTargetRB == (Object)null)
{
BreakCustomLodge(spawnBurst: false);
}
else
{
Rigidbody activeRigidbody = GetActiveRigidbody();
if ((Object)(object)activeRigidbody != (Object)null)
{
float num = Vector3.Dot(activeRigidbody.velocity, -((Component)this).transform.forward);
if (num > 3f)
{
BreakCustomLodge(spawnBurst: true);
}
}
}
}
else
{
m_lodgeContactTimer = 0f;
}
if (framesTilFlash > 0)
{
framesTilFlash--;
}
if (m_timeSinceCollision < 1f)
{
m_timeSinceCollision += Time.deltaTime;
}
if (TimeSinceDamageDealing > 0f)
{
TimeSinceDamageDealing -= Time.deltaTime;
}
else
{
if (m_isRunning && m_sawingIntensity > 0.1f && (Object)(object)BladePoint1 != (Object)null && (Object)(object)BladePoint2 != (Object)null)
{
Vector3 val2 = (BladePoint1.position + BladePoint2.position) * 0.5f;
Vector3 val3 = BladePoint2.position - BladePoint1.position;
Quaternion val4 = Quaternion.LookRotation(val3, ((Component)this).transform.up);
Vector3 val5 = default(Vector3);
((Vector3)(ref val5))..ctor(0.04f, 0.12f, ((Vector3)(ref val3)).magnitude * 0.5f);
int num2 = Physics.OverlapBoxNonAlloc(val2, val5, m_overlapResults, val4, -1, (QueryTriggerInteraction)2);
int num3 = 0;
for (int i = 0; i < num2; i++)
{
Collider val6 = m_overlapResults[i];
if ((Object)(object)val6 == (Object)null || m_bladeCols.Contains(val6) || (Object)(object)((Component)val6).transform.root == (Object)(object)((Component)this).transform.root)
{
continue;
}
Vector3 val7 = val6.ClosestPoint(val2);
if (num3 < 2)
{
m_timeSinceCollision = 0f;
num3++;
Vector3 closestValidPoint = ((FVRInteractiveObject)this).GetClosestValidPoint(BladePoint1.position, BladePoint2.position, val7);
Vector3 val8 = val7 - closestValidPoint;
val8 = Vector3.ClampMagnitude(val8, 0.04f);
Vector3 val9 = closestValidPoint + val8;
((EmitParams)(ref emitParams)).position = val9;
Vector3 val10 = Vector3.Cross(((Vector3)(ref val8)).normalized, ((Component)this).transform.right) * Random.Range(1f, 10f);
val10 += Random.onUnitSphere * 3f;
val10 += val8 * 2f;
((EmitParams)(ref emitParams)).velocity = val10;
if ((Object)(object)Sparks != (Object)null)
{
Sparks.Emit(emitParams, 1);
}
if (framesTilFlash <= 0)
{
framesTilFlash = Random.Range(3, 7);
Vector3 val11 = ((Component)this).transform.position - val7;
FXM.InitiateMuzzleFlash(val9, ((Vector3)(ref val11)).normalized, Random.Range(0.25f, 2f), Color.white, Random.Range(0.5f, 1f));
}
}
IFVRDamageable component = ((Component)val6).GetComponent<IFVRDamageable>();
if (component == null && (Object)(object)val6.attachedRigidbody != (Object)null)
{
component = ((Component)val6.attachedRigidbody).GetComponent<IFVRDamageable>();
}
if (component == null || !DamageablesToDoHS.Add(component))
{
continue;
}
if (ChainsawDebugMode)
{
Debug.Log((object)("Chainsaw: Spatial contact detected with " + ((Object)val6).name));
}
DamageablesToDo.Add(component);
DamageableHitPoints.Add(val7);
List<Vector3> damageableHitNormals = DamageableHitNormals;
Vector3 val12 = ((Component)this).transform.position - val7;
damageableHitNormals.Add(((Vector3)(ref val12)).normalized);
SosigLink component2 = ((Component)val6).GetComponent<SosigLink>();
if ((Object)(object)component2 == (Object)null && (Object)(object)val6.attachedRigidbody != (Object)null)
{
component2 = ((Component)val6.attachedRigidbody).GetComponent<SosigLink>();
}
if ((Object)(object)component2 != (Object)null && m_sawingIntensity > 0.5f && !m_isCustomLodged)
{
m_lodgeContactTimer += Time.deltaTime;
if (m_lodgeContactTimer >= 0.4f)
{
TriggerCustomLodge(component2, val6.attachedRigidbody);
}
}
}
}
if (DamageablesToDo.Count > 0)
{
if (ChainsawDebugMode)
{
Debug.Log((object)("Chainsaw: Ticking damage on " + DamageablesToDo.Count + " victims."));
}
Damage val13 = new Damage();
val13.Dam_Blunt = 15f;
val13.Dam_Cutting = BaseCuttingDamage * m_sawingIntensity;
val13.Dam_TotalKinetic = val13.Dam_Cutting + val13.Dam_Blunt;
val13.Class = (DamageClass)3;
val13.Source_IFF = GM.CurrentPlayerBody.GetPlayerIFF();
for (int j = 0; j < DamageablesToDo.Count; j++)
{
if ((Object)(MonoBehaviour)DamageablesToDo[j] != (Object)null)
{
val13.hitNormal = DamageableHitNormals[j];
val13.point = DamageableHitPoints[j];
val13.strikeDir = -val13.hitNormal;
DamageablesToDo[j].Damage(val13);
}
}
}
DamageablesToDo.Clear();
DamageablesToDoHS.Clear();
DamageableHitPoints.Clear();
DamageableHitNormals.Clear();
Array.Clear(m_overlapResults, 0, m_overlapResults.Length);
TimeSinceDamageDealing = 0.1f;
}
if (!m_isRunning)
{
if ((Object)(object)SawAudio != (Object)null)
{
SawAudio.volume = m_motorSpeed * 0.7f;
}
if ((Object)(object)StartingAudio != (Object)null)
{
StartingAudio.volume = m_motorSpeed;
}
if (m_motorSpeed <= 0f && (Object)(object)StartingAudio != (Object)null && StartingAudio.isPlaying)
{
StartingAudio.Stop();
}
if (UsesBladeSolidBits && (Object)(object)m_matBladeSolid != (Object)null && (Object)(object)m_matBladeBits != (Object)null)
{
m_matBladeSolid.SetVector("_MainTexVelocity", Vector4.op_Implicit(Vector2.zero));
m_matBladeBits.SetVector("_MainTexVelocity", Vector4.op_Implicit(Vector2.zero));
}
if ((Object)(object)EngineSmoke != (Object)null)
{
EmissionModule emission = EngineSmoke.emission;
MinMaxCurve rateOverTime = ((EmissionModule)(ref emission)).rateOverTime;
((MinMaxCurve)(ref rateOverTime)).mode = (ParticleSystemCurveMode)0;
((MinMaxCurve)(ref rateOverTime)).constantMax = 0f;
((MinMaxCurve)(ref rateOverTime)).constantMin = 0f;
((EmissionModule)(ref emission)).rateOverTime = rateOverTime;
}
}
else
{
if ((Object)(object)SawAudio != (Object)null && !SawAudio.isPlaying)
{
SawAudio.Play();
}
triggerAmount += Random.Range(-0.05f, 0.05f);
m_sawingIntensity = Mathf.Lerp(m_sawingIntensity, triggerAmount, Time.deltaTime * 5f);
if (m_sawingIntensity > 0.1f)
{
if ((Object)(object)SawAudio != (Object)null)
{
SawAudio.volume = (0.8f + m_sawingIntensity * 0.5f) * 0.3f;
SawAudio.pitch = 0.6f + m_sawingIntensity * 0.7f;
AudioClip val14 = ((!(m_timeSinceCollision < 0.2f)) ? AudClip_Buzzing : AudClip_Hitting);
if ((Object)(object)SawAudio.clip != (Object)(object)val14)
{
SawAudio.clip = val14;
}
}
if (UsesBladeSolidBits && (Object)(object)m_matBladeSolid != (Object)null && (Object)(object)m_matBladeBits != (Object)null)
{
m_matBladeSolid.SetVector("_MainTexVelocity", Vector4.op_Implicit(new Vector2(m_sawingIntensity, 0f)));
m_matBladeBits.SetVector("_MainTexVelocity", Vector4.op_Implicit(new Vector2(m_sawingIntensity, 0f)));
}
}
else
{
if ((Object)(object)SawAudio != (Object)null)
{
SawAudio.volume = 0.25f;
SawAudio.pitch = 1f;
if ((Object)(object)SawAudio.clip != (Object)(object)AudClip_Idle)
{
SawAudio.clip = AudClip_Idle;
}
}
if (UsesBladeSolidBits && (Object)(object)m_matBladeSolid != (Object)null && (Object)(object)m_matBladeBits != (Object)null)
{
m_matBladeSolid.SetVector("_MainTexVelocity", Vector4.op_Implicit(new Vector2(0.01f, 0f)));
m_matBladeBits.SetVector("_MainTexVelocity", Vector4.op_Implicit(new Vector2(0.01f, 0f)));
}
}
if ((Object)(object)EngineSmoke != (Object)null)
{
EmissionModule emission2 = EngineSmoke.emission;
MinMaxCurve rateOverTime2 = ((EmissionModule)(ref emission2)).rateOverTime;
((MinMaxCurve)(ref rateOverTime2)).mode = (ParticleSystemCurveMode)0;
((MinMaxCurve)(ref rateOverTime2)).constantMax = m_motorSpeed * 2f + m_sawingIntensity * 20f;
((MinMaxCurve)(ref rateOverTime2)).constantMin = m_motorSpeed * 2f + m_sawingIntensity * 20f;
((EmissionModule)(ref emission2)).rateOverTime = rateOverTime2;
}
}
if (m_isRunning)
{
if (m_motorSpeed < 1f)
{
m_motorSpeed = 1f;
}
}
else
{
m_motorSpeed -= Time.deltaTime * 3f;
m_motorSpeed = Mathf.Clamp(m_motorSpeed, 0f, 1f);
}
if (UsesEngineRot && (Object)(object)EngineRot != (Object)null)
{
float x = EngineRot.localEulerAngles.x;
x = ((!(m_sawingIntensity > 0f)) ? (x + Time.deltaTime * (360f * m_motorSpeed)) : (x + Time.deltaTime * (360f + m_sawingIntensity * 1200f)));
x = Mathf.Repeat(x, 360f);
EngineRot.localEulerAngles = new Vector3(x, 0f, 0f);
}
if (m_isRunning)
{
m_timeTilPerceptibleEventTick -= Time.deltaTime;
if (m_timeTilPerceptibleEventTick <= 0f)
{
m_timeTilPerceptibleEventTick = Random.Range(0.2f, 0.3f);
GM.CurrentSceneSettings.OnPerceiveableSound(PerceptibleEventVolume * m_motorSpeed * m_sawingIntensity * 0.5f, PerceptibleEventRange * m_motorSpeed * m_sawingIntensity * 0.5f, ((Component)this).transform.position, GM.CurrentPlayerBody.GetPlayerIFF(), GM.CurrentPlayerBody.PlayerEntities[0]);
}
}
}
public override void FVRFixedUpdate()
{
//IL_003c: 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_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_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
((FVRFireArmAttachment)this).FVRFixedUpdate();
if (m_isRunning)
{
Rigidbody activeRigidbody = GetActiveRigidbody();
if ((Object)(object)activeRigidbody != (Object)null)
{
float num = 0.1f + m_sawingIntensity * 0.3f;
activeRigidbody.velocity += Random.onUnitSphere * num;
activeRigidbody.angularVelocity += Random.onUnitSphere * num;
}
}
}
public void SetMotorPower(float intensity)
{
if (ChainsawDebugMode)
{
Debug.Log((object)("Chainsaw: SetMotorPower called with intensity: " + intensity));
}
triggerAmount = intensity;
m_isRunning = true;
if (m_motorSpeed <= 0.1f && (Object)(object)StartingAudio != (Object)null && !StartingAudio.isPlaying)
{
StartingAudio.Play();
}
m_motorSpeed += Time.deltaTime * 3f;
m_motorSpeed = Mathf.Clamp(m_motorSpeed, 0f, 1f);
}
public void StopMotor()
{
if (ChainsawDebugMode)
{
Debug.Log((object)"Chainsaw: StopMotor called");
}
m_isRunning = false;
triggerAmount = 0f;
m_sawingIntensity = 0f;
DamageablesToDo.Clear();
DamageablesToDoHS.Clear();
DamageableHitPoints.Clear();
DamageableHitNormals.Clear();
Array.Clear(m_overlapResults, 0, m_overlapResults.Length);
BreakCustomLodge(spawnBurst: false);
}
private Rigidbody GetActiveRigidbody()
{
if ((Object)(object)((FVRPhysicalObject)this).RootRigidbody != (Object)null)
{
return ((FVRPhysicalObject)this).RootRigidbody;
}
return ((Component)this).GetComponentInParent<Rigidbody>();
}
private void TriggerCustomLodge(SosigLink link, Rigidbody targetRB)
{
Rigidbody activeRigidbody = GetActiveRigidbody();
if (!((Object)(object)activeRigidbody == (Object)null) && !((Object)(object)targetRB == (Object)null))
{
m_isCustomLodged = true;
m_customLodgeTargetRB = targetRB;
m_customLodgeLink = link;
m_customLodgeJoint = ((Component)activeRigidbody).gameObject.AddComponent<FixedJoint>();
((Joint)m_customLodgeJoint).connectedBody = targetRB;
((Joint)m_customLodgeJoint).enableCollision = false;
if (ChainsawDebugMode)
{
Debug.Log((object)("Chainsaw: Custom lodged into " + ((Object)link).name));
}
}
}
private void BreakCustomLodge(bool spawnBurst)
{
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Expected O, but got Unknown
//IL_00da: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)m_customLodgeJoint != (Object)null)
{
Object.Destroy((Object)(object)m_customLodgeJoint);
}
if (spawnBurst && (Object)(object)m_customLodgeLink != (Object)null && (Object)(object)m_customLodgeLink.S != (Object)null && (Object)(object)BladePoint1 != (Object)null && (Object)(object)BladePoint2 != (Object)null)
{
Vector3 val = (BladePoint1.position + BladePoint2.position) * 0.5f;
m_customLodgeLink.S.SpawnLargeMustardBurst(val, -((Component)this).transform.forward * 5f);
Damage val2 = new Damage();
val2.Dam_Cutting = BaseCuttingDamage * 1.5f;
val2.Class = (DamageClass)3;
val2.Source_IFF = GM.CurrentPlayerBody.GetPlayerIFF();
val2.point = val;
val2.strikeDir = -((Component)this).transform.forward;
m_customLodgeLink.Damage(val2);
}
m_isCustomLodged = false;
m_customLodgeTargetRB = null;
m_customLodgeLink = null;
m_lodgeContactTimer = 0f;
}
}
public class UnderbarrelChainsawInterface : AttachableForegrip
{
public bool ChainsawInterfaceDebug;
public override void OnAttach()
{
((FVRFireArmAttachmentInterface)this).OnAttach();
if (ChainsawInterfaceDebug)
{
Debug.Log((object)"Interface: OnAttach called");
}
if ((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null && (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount != (Object)null && ((FVRFireArmAttachmentInterface)this).Attachment.curMount.Parent is FVRFireArm)
{
FVRPhysicalObject parent = ((FVRFireArmAttachmentInterface)this).Attachment.curMount.Parent;
FVRFireArm val = (FVRFireArm)(object)((parent is FVRFireArm) ? parent : null);
? val2 = val;
FVRFireArmAttachment attachment = ((FVRFireArmAttachmentInterface)this).Attachment;
((FVRFireArm)val2).RegisterAttachedMeleeWeapon((AttachableMeleeWeapon)(object)((attachment is AttachableMeleeWeapon) ? attachment : null));
}
}
public override void OnDetach()
{
if (ChainsawInterfaceDebug)
{
Debug.Log((object)"Interface: OnDetach called");
}
if ((Object)(object)((FVRFireArmAttachmentInterface)this).Attachment != (Object)null && (Object)(object)((FVRFireArmAttachmentInterface)this).Attachment.curMount != (Object)null && ((FVRFireArmAttachmentInterface)this).Attachment.curMount.Parent is FVRFireArm)
{
FVRPhysicalObject parent = ((FVRFireArmAttachmentInterface)this).Attachment.curMount.Parent;
FVRFireArm val = (FVRFireArm)(object)((parent is FVRFireArm) ? parent : null);
val.RegisterAttachedMeleeWeapon((AttachableMeleeWeapon)null);
}
((FVRFireArmAttachmentInterface)this).OnDetach();
}
}