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 lastFrameSpent = new List(); private List disabledColliders = new List(); private float colliderRestoreTimer; private bool initialized; private void Start() { TryInitialize(); } private void Update() { //IL_01b0: 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_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: 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_01fb: 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_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_0245: 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 && ((FVRInteractiveObject)weapon).IsHeld && (Object)(object)((FVRPhysicalObject)weapon).AltGrip == (Object)null && 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(); 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(); } 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 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_handStartLocalZ; private float m_roundStartLocalZ; 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(); } 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_01d7: 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_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015e: 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_032a: Unknown result type (might be due to invalid IL or missing references) //IL_025e: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_038f: Unknown result type (might be due to invalid IL or missing references) //IL_0394: Unknown result type (might be due to invalid IL or missing references) //IL_03ef: Unknown result type (might be due to invalid IL or missing references) //IL_03fa: Unknown result type (might be due to invalid IL or missing references) //IL_03ff: 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_04e7: Unknown result type (might be due to invalid IL or missing references) //IL_0472: 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 z = ChamberSeatedPoint.InverseTransformPoint(((Component)hand).transform.position).z; float num = z - m_handStartLocalZ; float num2 = m_roundStartLocalZ + num; if (num2 >= loadThreshold) { PlaySound(AudEvent_ShellIn); ((FVRInteractiveObject)m_loadingRound).EndInteraction(hand); 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 (num2 < extractThreshold) { m_loadingRound = null; if (debug) { Debug.Log((object)"ManualChamberLoad: Loading aborted."); } } else { ((Component)m_loadingRound).transform.position = ChamberSeatedPoint.TransformPoint(new Vector3(0f, 0f, num2)); ((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 z2 = ChamberSeatedPoint.InverseTransformPoint(((Component)base.m_hand).transform.position).z; float num3 = z2 - m_handStartLocalZ; float num4 = m_roundStartLocalZ + num3; if (num4 <= extractThreshold) { PlaySound(AudEvent_ShellOut); FVRFireArmRound round = chamber.GetRound(); if ((Object)(object)round != (Object)null) { GameObject val = Object.Instantiate(((AnvilAsset)AM.GetRoundSelfPrefab(chamber.RoundType, round.RoundClass)).GetGameObject(), ChamberSeatedPoint.position, ChamberSeatedPoint.rotation); FVRFireArmRound component = val.GetComponent(); base.m_hand.ForceSetInteractable((FVRInteractiveObject)(object)component); ((FVRInteractiveObject)component).BeginInteraction(base.m_hand); chamber.SetRound((FVRFireArmRound)null, false); } ((FVRInteractiveObject)this).EndInteraction(base.m_hand); m_isExtracting = false; m_gravitySlideZ = 0f; if (debug) { Debug.Log((object)"ManualChamberLoad: Round successfully extracted."); } } else if ((Object)(object)chamber.ProxyRound != (Object)null) { chamber.ProxyRound.localPosition = new Vector3(0f, 0f, num4); } } if (!chamber.IsFull || chamber.IsSpent || !chamber.IsAccessible || ((FVRInteractiveObject)this).IsHeld || !((Object)(object)m_loadingRound == (Object)null)) { return; } float num5 = Vector3.Angle(((Component)chamber).transform.forward, Vector3.up); if (num5 > 110f) { m_gravitySlideZ -= Time.deltaTime * 0.2f; 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 dropped out due to gravity."); } } 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_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: 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(); 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; m_handStartLocalZ = ChamberSeatedPoint.InverseTransformPoint(((Component)hand).transform.position).z; m_roundStartLocalZ = ChamberSeatedPoint.InverseTransformPoint(((Component)m_loadingRound).transform.position).z; if (debug) { Debug.Log((object)"ManualChamberLoad: Round entered loading zone. Restricting path."); } } } public override bool IsInteractable() { return (Object)(object)chamber != (Object)null && chamber.IsFull && chamber.IsAccessible; } public override void BeginInteraction(FVRViveHand hand) { //IL_005a: 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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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; m_handStartLocalZ = ChamberSeatedPoint.InverseTransformPoint(((Component)hand).transform.position).z; float roundStartLocalZ = 0f; if ((Object)(object)chamber.ProxyRound != (Object)null) { roundStartLocalZ = chamber.ProxyRound.localPosition.z; } m_roundStartLocalZ = roundStartLocalZ; } } 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 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_0279: 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_028d: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: 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_018b: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: 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_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_042f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Revolver == (Object)null || (Object)(object)EjectorRod == (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 = ((Component)Revolver).transform.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); } } } 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 _slidingRounds = new List(); 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(); 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(); if ((Object)(object)componentInChildren != (Object)null) { Collider component = ((Component)componentInChildren).GetComponent(); if ((Object)(object)component != (Object)null) { component.enabled = false; } } } private void Update() { if (!((Object)(object)_revolver == (Object)null)) { FVRViveHand[] hands = Object.FindObjectsOfType(); 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(); if ((Object)(object)component != (Object)null) { component.isKinematic = true; component.useGravity = false; } Collider[] componentsInChildren = ((Component)round).GetComponentsInChildren(); 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(); if ((Object)(object)component != (Object)null) { component.isKinematic = false; component.useGravity = true; } Collider[] componentsInChildren = ((Component)round).GetComponentsInChildren(); 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; } 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(); 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.MLOK_Adapter; [BepInPlugin("Volks.MLOK_Adapter", "MLOK_Adapter", "1.0.0")] [BepInProcess("h3vr.exe")] [Description("Built with MeatKit")] [BepInDependency("h3vr.otherloader", "1.3.0")] public class MLOK_AdapterPlugin : 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.MLOK_Adapter"); OtherLoader.RegisterDirectLoad(BasePath, "Volks.MLOK_Adapter", "", "", "picmlok_adapter", ""); } }