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;
using UnityEngine.UI;
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
public class AdvanceLaserSightComponent : LaserLightAttachment
{
public Transform KnobMesh;
public Vector3 RotationAxis = Vector3.up;
public List<float> CustomRotationAngles;
public GameObject ControlledGameObject;
public bool[] GameObjectEnableFlags;
public AudioEvent SettingSwapSound;
private int previousSettingsIndex = -1;
private void Start()
{
UpdateKnobRotationAndGameObject();
}
private void Update()
{
UpdateKnobRotationAndGameObject();
}
private void UpdateKnobRotationAndGameObject()
{
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)KnobMesh != (Object)null && base.Settings.Count > 0 && CustomRotationAngles.Count == base.Settings.Count && GameObjectEnableFlags.Length == base.Settings.Count)
{
float num = CustomRotationAngles[base.SettingsIndex];
KnobMesh.localEulerAngles = RotationAxis * num;
UpdateControlledGameObject(base.SettingsIndex);
if (base.SettingsIndex != previousSettingsIndex)
{
PlaySettingSwapSound();
previousSettingsIndex = base.SettingsIndex;
}
}
}
private void UpdateControlledGameObject(int settingIndex)
{
if ((Object)(object)ControlledGameObject != (Object)null)
{
ControlledGameObject.SetActive(GameObjectEnableFlags[settingIndex]);
}
}
private void PlaySettingSwapSound()
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
if (SettingSwapSound != null && SettingSwapSound.Clips.Count > 0)
{
AudioClip val = SettingSwapSound.Clips[Random.Range(0, SettingSwapSound.Clips.Count)];
AudioSource.PlayClipAtPoint(val, ((Component)this).transform.position, Random.Range(SettingSwapSound.VolumeRange.x, SettingSwapSound.VolumeRange.y));
}
}
}
public class DiceFaceDetector : MonoBehaviour
{
public ParticleSystem effect;
public Transform faceOneMarker;
public float checkThreshold = 0.9f;
public float cooldownTime = 2f;
private float lastTriggerTime = 0f;
private void Update()
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)faceOneMarker == (Object)null) && !(Time.time - lastTriggerTime < cooldownTime) && Vector3.Dot(faceOneMarker.up, Vector3.up) > checkThreshold)
{
TriggerEffect();
}
}
private void TriggerEffect()
{
if ((Object)(object)effect != (Object)null)
{
effect.Play();
lastTriggerTime = Time.time;
}
}
}
public class HandgunExternalSafety : FVRInteractiveObject
{
[Header("Weapon & Transform Settings")]
public Handgun Weapon;
public Transform SafetySwitch;
[Header("Animation Settings")]
public Axis Axis;
public InterpStyle InterpStyle;
[Header("Positions (Rotation or Translation values)")]
public float SafetyOnPosition;
public float SafetyOffPosition;
public override void Awake()
{
((FVRInteractiveObject)this).Awake();
UpdateSwitchVisual();
}
public override void SimpleInteraction(FVRViveHand hand)
{
((FVRInteractiveObject)this).SimpleInteraction(hand);
ToggleSafetyState();
}
private void ToggleSafetyState()
{
if ((Object)(object)Weapon != (Object)null)
{
Weapon.ToggleSafety();
UpdateSwitchVisual();
}
}
private void UpdateSwitchVisual()
{
//IL_0059: 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)
if (!((Object)(object)Weapon == (Object)null) && !((Object)(object)SafetySwitch == (Object)null))
{
float num = ((!Weapon.IsSafetyEngaged) ? SafetyOffPosition : SafetyOnPosition);
((FVRPhysicalObject)Weapon).SetAnimatedComponent(SafetySwitch, num, InterpStyle, Axis);
}
}
}
public class QBScaler : MonoBehaviour
{
public FVRQuickBeltSlot slot;
public float scaleMultiplier = 0.5f;
[Header("Debugging")]
[Tooltip("Enable to output hierarchy diagnostic scans and scale logs to the Unity console.")]
public bool enableDebugging = false;
private Transform currentObj;
private Vector3 originalScale;
private Dictionary<Rigidbody, bool> trackedRigidbodies = new Dictionary<Rigidbody, bool>();
private HashSet<FVRPhysicalObject> knownPhysObjs = new HashSet<FVRPhysicalObject>();
private Dictionary<FVRPhysicalObject, Vector3> originalPhysScales = new Dictionary<FVRPhysicalObject, Vector3>();
private HashSet<FVRFireArmAttachment> hoveringAttachments = new HashSet<FVRFireArmAttachment>();
private void Awake()
{
if ((Object)(object)slot == (Object)null)
{
slot = ((Component)this).GetComponent<FVRQuickBeltSlot>();
}
}
private void DebugLog(string message)
{
if (enableDebugging)
{
Debug.Log((object)("[QBScaler Debug] " + message));
}
}
private void Update()
{
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0364: Unknown result type (might be due to invalid IL or missing references)
//IL_057a: Unknown result type (might be due to invalid IL or missing references)
//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
//IL_06a6: Unknown result type (might be due to invalid IL or missing references)
//IL_06ad: Expected O, but got Unknown
//IL_08ea: Unknown result type (might be due to invalid IL or missing references)
//IL_08b4: Unknown result type (might be due to invalid IL or missing references)
//IL_08cd: Unknown result type (might be due to invalid IL or missing references)
//IL_086f: Unknown result type (might be due to invalid IL or missing references)
//IL_087a: 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_0889: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)slot == (Object)null || (Object)(object)slot.CurObject == (Object)null)
{
if ((Object)(object)currentObj != (Object)null)
{
DebugLog("Slotted object removed or slot became invalid. Restoring firearm state.");
RestoreState();
currentObj = null;
}
return;
}
if ((Object)(object)currentObj != (Object)(object)((Component)slot.CurObject).transform)
{
if ((Object)(object)currentObj != (Object)null)
{
RestoreState();
}
currentObj = ((Component)slot.CurObject).transform;
originalScale = currentObj.localScale;
DebugLog("Firearm entered QuickBelt slot: " + ((Object)currentObj).name + " | Original Scale: " + originalScale);
trackedRigidbodies.Clear();
knownPhysObjs.Clear();
originalPhysScales.Clear();
FVRPhysicalObject[] componentsInChildren = ((Component)currentObj).GetComponentsInChildren<FVRPhysicalObject>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
if ((Object)(object)componentsInChildren[i] != (Object)null)
{
knownPhysObjs.Add(componentsInChildren[i]);
originalPhysScales[componentsInChildren[i]] = ((Component)componentsInChildren[i]).transform.localScale;
}
}
currentObj.localScale = originalScale * scaleMultiplier;
PerformHierarchyDiagnostics(currentObj);
}
if (!((Object)(object)currentObj != (Object)null))
{
return;
}
Rigidbody component = ((Component)currentObj).GetComponent<Rigidbody>();
Rigidbody[] componentsInChildren2 = ((Component)currentObj).GetComponentsInChildren<Rigidbody>(true);
foreach (Rigidbody val in componentsInChildren2)
{
if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)component && !trackedRigidbodies.ContainsKey(val))
{
DebugLog("New child Rigidbody detected on slot: " + ((Object)val).name + " | Setting isKinematic to true.");
trackedRigidbodies[val] = val.isKinematic;
val.isKinematic = true;
}
}
FVRFireArmAttachment[] array = Object.FindObjectsOfType<FVRFireArmAttachment>();
List<FVRFireArmAttachment> list = new List<FVRFireArmAttachment>();
foreach (FVRFireArmAttachment hoveringAttachment in hoveringAttachments)
{
if ((Object)(object)hoveringAttachment == (Object)null || !((FVRInteractiveObject)hoveringAttachment).IsHeld || (Object)(object)hoveringAttachment.Sensor == (Object)null || (Object)(object)hoveringAttachment.Sensor.CurHoveredMount == (Object)null || !((Component)hoveringAttachment.Sensor.CurHoveredMount).transform.IsChildOf(currentObj))
{
list.Add(hoveringAttachment);
}
}
for (int k = 0; k < list.Count; k++)
{
FVRFireArmAttachment val2 = list[k];
if ((Object)(object)val2 != (Object)null)
{
DebugLog("Attachment stopped hovering: " + ((Object)val2).name + ". Restoring its scale.");
if (originalPhysScales.TryGetValue((FVRPhysicalObject)(object)val2, out var value))
{
((Component)val2).transform.localScale = value;
}
}
hoveringAttachments.Remove(val2);
if ((Object)(object)val2 != (Object)null && !((Component)val2).transform.IsChildOf(currentObj))
{
originalPhysScales.Remove((FVRPhysicalObject)(object)val2);
knownPhysObjs.Remove((FVRPhysicalObject)(object)val2);
}
}
foreach (FVRFireArmAttachment val3 in array)
{
if ((Object)(object)val3 != (Object)null && ((FVRInteractiveObject)val3).IsHeld && (Object)(object)val3.Sensor != (Object)null && (Object)(object)val3.Sensor.CurHoveredMount != (Object)null && ((Component)val3.Sensor.CurHoveredMount).transform.IsChildOf(currentObj) && !hoveringAttachments.Contains(val3))
{
hoveringAttachments.Add(val3);
DebugLog("Attachment started hovering on scaled rail: " + ((Object)val3).name + ". Applying preview scale reduction.");
if (!originalPhysScales.ContainsKey((FVRPhysicalObject)(object)val3))
{
originalPhysScales[(FVRPhysicalObject)(object)val3] = ((Component)val3).transform.localScale;
}
((Component)val3).transform.localScale = originalPhysScales[(FVRPhysicalObject)(object)val3] * scaleMultiplier;
}
}
List<FVRPhysicalObject> list2 = new List<FVRPhysicalObject>();
foreach (FVRPhysicalObject knownPhysObj in knownPhysObjs)
{
if ((Object)(object)knownPhysObj == (Object)null)
{
list2.Add(knownPhysObj);
}
else
{
if (((Component)knownPhysObj).transform.IsChildOf(currentObj))
{
continue;
}
DebugLog("Child physical object detached from slotted weapon: " + ((Object)knownPhysObj).name + ". Restoring its original scale.");
if (originalPhysScales.TryGetValue(knownPhysObj, out var value2))
{
((Component)knownPhysObj).transform.localScale = value2;
}
Rigidbody[] componentsInChildren3 = ((Component)knownPhysObj).GetComponentsInChildren<Rigidbody>(true);
for (int m = 0; m < componentsInChildren3.Length; m++)
{
if (trackedRigidbodies.TryGetValue(componentsInChildren3[m], out var value3))
{
componentsInChildren3[m].isKinematic = value3;
}
trackedRigidbodies.Remove(componentsInChildren3[m]);
}
list2.Add(knownPhysObj);
}
}
for (int n = 0; n < list2.Count; n++)
{
knownPhysObjs.Remove(list2[n]);
originalPhysScales.Remove(list2[n]);
}
FVRPhysicalObject[] componentsInChildren4 = ((Component)currentObj).GetComponentsInChildren<FVRPhysicalObject>(true);
List<FVRPhysicalObject> list3 = new List<FVRPhysicalObject>();
foreach (FVRPhysicalObject val4 in componentsInChildren4)
{
if (!((Object)(object)val4 != (Object)null) || knownPhysObjs.Contains(val4))
{
continue;
}
bool flag = false;
if (val4 is FVRFireArmAttachment)
{
FVRFireArmAttachment val5 = (FVRFireArmAttachment)val4;
if ((Object)(object)val5.curMount != (Object)null)
{
flag = true;
}
}
else if (val4 is FVRFireArmMagazine)
{
flag = true;
}
if (flag)
{
Transform parent = ((Component)val4).transform.parent;
while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)currentObj)
{
FVRPhysicalObject component2 = ((Component)parent).GetComponent<FVRPhysicalObject>();
if ((Object)(object)component2 != (Object)null)
{
flag = false;
break;
}
parent = parent.parent;
}
}
if (flag)
{
list3.Add(val4);
continue;
}
DebugLog("Identified child part spawned on firearm: " + ((Object)val4).name + " | Type: " + ((object)val4).GetType().Name + " | Handled by parent hierarchy.");
knownPhysObjs.Add(val4);
}
for (int num2 = 0; num2 < list3.Count; num2++)
{
FVRPhysicalObject val6 = list3[num2];
knownPhysObjs.Add(val6);
bool flag2 = false;
Transform parent2 = ((Component)val6).transform.parent;
while ((Object)(object)parent2 != (Object)null && (Object)(object)parent2 != (Object)(object)currentObj)
{
FVRPhysicalObject component3 = ((Component)parent2).GetComponent<FVRPhysicalObject>();
if ((Object)(object)component3 != (Object)null && list3.Contains(component3))
{
flag2 = true;
break;
}
parent2 = parent2.parent;
}
if (!flag2)
{
if (!originalPhysScales.TryGetValue(val6, out var value4))
{
value4 = ((Component)val6).transform.localScale * scaleMultiplier;
originalPhysScales[val6] = value4;
}
DebugLog("Manually correcting scale for newly attached item: " + ((Object)val6).name + " | New LocalScale: " + value4);
((Component)val6).transform.localScale = value4;
}
else
{
originalPhysScales[val6] = ((Component)val6).transform.localScale;
}
}
if (list3.Count > 0)
{
DebugLog("Dynamic hierarchy change detected inside slot. Running updated diagnostics.");
PerformHierarchyDiagnostics(currentObj);
}
}
private void RestoreState()
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)currentObj == (Object)null)
{
return;
}
if ((Object)(object)currentObj != (Object)null)
{
DebugLog("Restoring firearm state to unslotted coordinates.");
currentObj.localScale = originalScale;
foreach (FVRFireArmAttachment hoveringAttachment in hoveringAttachments)
{
if ((Object)(object)hoveringAttachment != (Object)null && originalPhysScales.TryGetValue((FVRPhysicalObject)(object)hoveringAttachment, out var value))
{
((Component)hoveringAttachment).transform.localScale = value;
}
}
foreach (KeyValuePair<FVRPhysicalObject, Vector3> originalPhysScale in originalPhysScales)
{
FVRPhysicalObject key = originalPhysScale.Key;
Vector3 value2 = originalPhysScale.Value;
if ((Object)(object)key != (Object)null)
{
((Component)key).transform.localScale = value2;
}
}
foreach (KeyValuePair<Rigidbody, bool> trackedRigidbody in trackedRigidbodies)
{
Rigidbody key2 = trackedRigidbody.Key;
bool value3 = trackedRigidbody.Value;
if ((Object)(object)key2 != (Object)null)
{
key2.isKinematic = value3;
}
}
}
trackedRigidbodies.Clear();
knownPhysObjs.Clear();
originalPhysScales.Clear();
hoveringAttachments.Clear();
}
private void PerformHierarchyDiagnostics(Transform root)
{
//IL_0048: 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_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_037f: Unknown result type (might be due to invalid IL or missing references)
if (!enableDebugging || (Object)(object)root == (Object)null)
{
return;
}
Debug.Log((object)("[QBScaler Diagnostics] === START DIAGNOSTICS FOR: " + ((Object)root).name + " ==="));
Debug.Log((object)string.Concat("[QBScaler Diagnostics] Root localScale: ", root.localScale, " | lossyScale: ", root.lossyScale));
Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
int num = 0;
foreach (Transform val in componentsInChildren)
{
if ((Object)(object)val != (Object)null)
{
Vector3 localScale = val.localScale;
if (Mathf.Abs(localScale.x - localScale.y) > 0.001f || Mathf.Abs(localScale.x - localScale.z) > 0.001f || Mathf.Abs(localScale.y - localScale.z) > 0.001f)
{
Debug.LogWarning((object)string.Concat("[QBScaler Warning] Non-Uniform scale detected on: ", ((Object)val).name, " | localScale: ", localScale, " | Path: ", GetGameObjectPath(val)));
num++;
}
}
}
Debug.Log((object)("[QBScaler Diagnostics] Non-uniform scale transforms found: " + num + " (Non-uniform scale on parents can cause children to skew, warp, or offset when scaled or rotated)."));
Rigidbody[] componentsInChildren2 = ((Component)root).GetComponentsInChildren<Rigidbody>(true);
Debug.Log((object)("[QBScaler Diagnostics] Total child Rigidbodies found: " + componentsInChildren2.Length));
foreach (Rigidbody val2 in componentsInChildren2)
{
if ((Object)(object)val2 != (Object)null)
{
Debug.Log((object)("[QBScaler Diagnostics] Rigidbody: " + ((Object)val2).name + " | isKinematic: " + val2.isKinematic + " | useGravity: " + val2.useGravity + " | Path: " + GetGameObjectPath(((Component)val2).transform)));
}
}
Joint[] componentsInChildren3 = ((Component)root).GetComponentsInChildren<Joint>(true);
Debug.Log((object)("[QBScaler Diagnostics] Total Joints found: " + componentsInChildren3.Length));
foreach (Joint val3 in componentsInChildren3)
{
if ((Object)(object)val3 != (Object)null)
{
string text = ((!((Object)(object)val3.connectedBody != (Object)null)) ? "NULL (Connected to World)" : ((Object)val3.connectedBody).name);
Debug.LogWarning((object)("[QBScaler Diagnostics] Joint found: " + ((object)val3).GetType().Name + " on " + ((Object)val3).name + " | connectedBody: " + text + " | Path: " + GetGameObjectPath(((Component)val3).transform)));
}
}
FVRPhysicalObject[] componentsInChildren4 = ((Component)root).GetComponentsInChildren<FVRPhysicalObject>(true);
Debug.Log((object)("[QBScaler Diagnostics] Total FVRPhysicalObject components found: " + componentsInChildren4.Length));
foreach (FVRPhysicalObject val4 in componentsInChildren4)
{
if ((Object)(object)val4 != (Object)null)
{
Debug.Log((object)string.Concat("[QBScaler Diagnostics] FVRPhysicalObject: ", ((Object)val4).name, " | Type: ", ((object)val4).GetType().Name, " | localScale: ", ((Component)val4).transform.localScale, " | Path: ", GetGameObjectPath(((Component)val4).transform)));
}
}
Debug.Log((object)("[QBScaler Diagnostics] === END DIAGNOSTICS FOR: " + ((Object)root).name + " ==="));
}
private string GetGameObjectPath(Transform t)
{
string text = ((Object)t).name;
while ((Object)(object)t.parent != (Object)null)
{
t = t.parent;
text = ((Object)t).name + "/" + text;
}
return text;
}
}
public class OpenBoltAltHandle : FVRInteractiveObject
{
public enum HandleRot
{
Down,
Mid,
Up
}
public enum HandleState
{
Forward,
Mid,
Rear
}
[Header("References")]
public OpenBoltReceiver Receiver;
public OpenBoltReceiverBolt Bolt;
[Header("Linear Travel")]
public Transform Point_Fore;
public Transform Point_Rear;
public float ForwardSpeed = 1.5f;
[Header("Rotation / Tilt")]
public Transform BoltHandleRoot;
public Transform BoltHandle;
public float MinRot = 0f;
public float MaxRot = 90f;
public float UnlockThreshold = 65f;
public float LockThreshold = 5f;
public float RotateSnapSpeed = 270f;
public HandleRot CurRot = HandleRot.Down;
public HandleRot LastRot = HandleRot.Down;
public HandleState CurState = HandleState.Forward;
public HandleState LastState = HandleState.Forward;
private float m_boltZ_forward;
private float m_boltZ_rear;
private float m_currentHandleZ;
private float m_rotAngle;
private bool m_hasReleasedBolt;
protected void Awake()
{
//IL_000e: 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_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
((FVRInteractiveObject)this).Awake();
m_boltZ_forward = Point_Fore.localPosition.z;
m_boltZ_rear = Point_Rear.localPosition.z;
m_currentHandleZ = BoltHandleRoot.localPosition.z;
m_rotAngle = MinRot;
m_hasReleasedBolt = true;
}
public override void UpdateInteraction(FVRViveHand hand)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
((FVRInteractiveObject)this).UpdateInteraction(hand);
UpdateRotationFromHand(hand);
if (CurRot == HandleRot.Up || CurState != HandleState.Forward)
{
Vector3 closestValidPoint = ((FVRInteractiveObject)this).GetClosestValidPoint(Point_Fore.position, Point_Rear.position, ((HandInput)(ref hand.Input)).Pos);
BoltHandleRoot.position = closestValidPoint;
m_currentHandleZ = BoltHandleRoot.localPosition.z;
}
UpdateHandleState();
UpdateRotState();
if (CurState != HandleState.Forward)
{
float num = Mathf.InverseLerp(m_boltZ_forward, m_boltZ_rear, m_currentHandleZ);
Bolt.ChargingHandleHeld(num);
}
else if (CurRot != HandleRot.Down)
{
Bolt.ChargingHandleHeld(0f);
}
if (CurState == HandleState.Forward && CurRot == HandleRot.Down)
{
if (!m_hasReleasedBolt)
{
Bolt.ChargingHandleReleased();
m_hasReleasedBolt = true;
}
}
else
{
m_hasReleasedBolt = false;
}
HandleRotAudioEvents();
HandleStateAudioEvents();
LastRot = CurRot;
LastState = CurState;
}
public override void EndInteraction(FVRViveHand hand)
{
((FVRInteractiveObject)this).EndInteraction(hand);
}
protected void FVRUpdate()
{
//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_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
((FVRInteractiveObject)this).FVRUpdate();
if (((FVRInteractiveObject)this).IsHeld)
{
return;
}
if (Mathf.Abs(m_currentHandleZ - m_boltZ_forward) > 0.001f)
{
m_currentHandleZ = Mathf.MoveTowards(m_currentHandleZ, m_boltZ_forward, Time.deltaTime * ForwardSpeed);
BoltHandleRoot.localPosition = new Vector3(BoltHandleRoot.localPosition.x, BoltHandleRoot.localPosition.y, m_currentHandleZ);
if (CurState != HandleState.Forward)
{
float num = Mathf.InverseLerp(m_boltZ_forward, m_boltZ_rear, m_currentHandleZ);
Bolt.ChargingHandleHeld(num);
}
}
if ((CurState == HandleState.Forward || CurState == HandleState.Mid) && m_rotAngle > MinRot + 0.5f)
{
m_rotAngle = Mathf.MoveTowards(m_rotAngle, MinRot, Time.deltaTime * RotateSnapSpeed);
BoltHandle.localEulerAngles = new Vector3(0f, 0f, m_rotAngle);
}
UpdateHandleState();
UpdateRotState();
if (CurState == HandleState.Forward && CurRot == HandleRot.Down && !m_hasReleasedBolt)
{
Bolt.ChargingHandleReleased();
m_hasReleasedBolt = true;
}
HandleStateAudioEvents();
HandleRotAudioEvents();
LastRot = CurRot;
LastState = CurState;
}
private void UpdateRotationFromHand(FVRViveHand hand)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: 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_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: 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)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: 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_009b: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = ((HandInput)(ref hand.Input)).Pos - BoltHandle.position;
Vector3 val2 = Vector3.ProjectOnPlane(val, BoltHandleRoot.forward);
val = ((Vector3)(ref val2)).normalized;
Vector3 right = BoltHandleRoot.right;
float num = Mathf.Atan2(Vector3.Dot(BoltHandleRoot.forward, Vector3.Cross(right, val)), Vector3.Dot(right, val)) * 57.29578f;
m_rotAngle = Mathf.Clamp(num, MinRot, MaxRot);
BoltHandle.localEulerAngles = new Vector3(0f, 0f, m_rotAngle);
}
private void UpdateRotState()
{
if (m_rotAngle >= UnlockThreshold)
{
CurRot = HandleRot.Up;
}
else if (m_rotAngle <= MinRot + LockThreshold)
{
CurRot = HandleRot.Down;
}
else
{
CurRot = HandleRot.Mid;
}
}
private void UpdateHandleState()
{
if (Mathf.Abs(m_currentHandleZ - m_boltZ_forward) < 0.005f)
{
CurState = HandleState.Forward;
}
else if (Mathf.Abs(m_currentHandleZ - m_boltZ_rear) < 0.005f)
{
CurState = HandleState.Rear;
}
else
{
CurState = HandleState.Mid;
}
}
private void HandleRotAudioEvents()
{
if (!((Object)(object)Receiver == (Object)null))
{
if (CurRot == HandleRot.Up && LastRot != HandleRot.Up)
{
((FVRFireArm)Receiver).PlayAudioEvent((FirearmAudioEventType)12, 1f);
}
else if (CurRot == HandleRot.Down && LastRot != HandleRot.Down)
{
((FVRFireArm)Receiver).PlayAudioEvent((FirearmAudioEventType)13, 1f);
}
}
}
private void HandleStateAudioEvents()
{
if (!((Object)(object)Receiver == (Object)null))
{
if (CurState == HandleState.Rear && LastState != HandleState.Rear)
{
((FVRFireArm)Receiver).PlayAudioEvent((FirearmAudioEventType)10, 1f);
}
else if (CurState == HandleState.Forward && LastState != HandleState.Forward)
{
((FVRFireArm)Receiver).PlayAudioEvent((FirearmAudioEventType)11, 1f);
}
}
}
}
public class SimpleFirearm : FVRFireArm
{
[Serializable]
public class SimpleFireSelectorMode
{
public float SelectorPosition;
public FireSelectorModeType ModeType;
public int BurstAmount = 3;
public float EngagementDelay;
}
[Header("Debugging")]
public bool DebugLogging = false;
[Header("Optional Chamber")]
[Tooltip("Leave this blank if the gun does not use a chamber and fires directly from the magazine.")]
public FVRFireArmChamber Chamber;
[Header("Bullet Ejection Configuration")]
[Tooltip("If true, spent casings will be silently deleted instead of spawning physical brass.")]
public bool DisableCaseEjections = false;
public Transform RoundPos_Ejection;
public Vector3 EjectionSpeed = new Vector3(4f, 2.5f, -1.2f);
public Vector3 EjectionSpin = new Vector3(20f, 180f, 30f);
[Header("Trigger Animation")]
public bool HasTrigger = true;
public Transform Trigger;
public float TriggerFiringThreshold = 0.8f;
public float TriggerResetThreshold = 0.4f;
public float Trigger_ForwardValue;
public float Trigger_RearwardValue;
public Axis TriggerAxis;
public InterpStyle TriggerInterpStyle = (InterpStyle)1;
[Header("Fire Selector Configuration")]
public Transform FireSelectorSwitch;
public Axis FireSelector_Axis;
public InterpStyle FireSelector_InterpStyle = (InterpStyle)1;
public SimpleFireSelectorMode[] FireSelector_Modes;
[Header("Magazine Release Button")]
public bool HasMagReleaseButton = true;
public Transform MagazineReleaseButton;
public InterpStyle MagReleaseInterp;
public Vector3 MagReleaseUnpressed;
public Vector3 MagReleasePressed;
private float m_triggerFloat;
private bool m_hasTriggerReset = true;
private int m_fireSelectorMode;
private int m_CamBurst;
private float m_engagementDelay;
private float m_timeSinceFiredShot = 1f;
private bool m_isMagReleaseHeld;
private bool m_wasMagReleaseHeldDown;
public override void Awake()
{
((FVRFireArm)this).Awake();
if ((Object)(object)Chamber != (Object)null)
{
base.FChambers.Add(Chamber);
}
ResetCamBurst();
}
public override void FVRUpdate()
{
((FVRFireArm)this).FVRUpdate();
if (m_engagementDelay > 0f)
{
m_engagementDelay -= Time.deltaTime;
}
if (m_timeSinceFiredShot < 1f)
{
m_timeSinceFiredShot += Time.deltaTime;
}
UpdateComponents();
}
public override void UpdateInteraction(FVRViveHand hand)
{
((FVRPhysicalObject)this).UpdateInteraction(hand);
UpdateInputAndAnimate(hand);
}
public override void LoadMag(FVRFireArmMagazine mag)
{
((FVRFireArm)this).LoadMag(mag);
if ((Object)(object)mag != (Object)null)
{
AutoChamberFromMag();
}
}
public override void EjectMag(bool PhysicalRelease = false)
{
((FVRFireArm)this).EjectMag(PhysicalRelease);
}
private void UpdateInputAndAnimate(FVRViveHand hand)
{
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: 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_0188: 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_0232: 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_0238: Unknown result type (might be due to invalid IL or missing references)
//IL_025b: Unknown result type (might be due to invalid IL or missing references)
//IL_025d: Invalid comparison between Unknown and I4
//IL_0262: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Invalid comparison between Unknown and I4
m_isMagReleaseHeld = false;
if (((FVRPhysicalObject)this).IsAltHeld)
{
return;
}
if (((FVRInteractiveObject)this).m_hasTriggeredUpSinceBegin && m_engagementDelay <= 0f)
{
m_triggerFloat = hand.Input.TriggerFloat;
}
else
{
m_triggerFloat = 0f;
}
if (!m_hasTriggerReset && m_triggerFloat <= TriggerResetThreshold)
{
m_hasTriggerReset = true;
if (FireSelector_Modes.Length > 0)
{
m_CamBurst = FireSelector_Modes[m_fireSelectorMode].BurstAmount;
m_engagementDelay = FireSelector_Modes[m_fireSelectorMode].EngagementDelay;
}
((FVRFireArm)this).PlayAudioEvent((FirearmAudioEventType)16, 1f);
}
if (hand.IsInStreamlinedMode)
{
if (hand.Input.BYButtonDown)
{
ToggleFireSelector();
}
if (hand.Input.AXButtonDown && (Object)(object)MagazineReleaseButton != (Object)null)
{
ReleaseMag();
}
if (hand.Input.AXButtonPressed)
{
m_isMagReleaseHeld = true;
}
}
else
{
Vector2 touchpadAxes = hand.Input.TouchpadAxes;
if (hand.Input.TouchpadDown && ((Vector2)(ref touchpadAxes)).magnitude > 0.2f)
{
if (Vector2.Angle(touchpadAxes, Vector2.left) <= 45f)
{
ToggleFireSelector();
}
else if (Vector2.Angle(touchpadAxes, Vector2.down) <= 45f && (Object)(object)MagazineReleaseButton != (Object)null)
{
ReleaseMag();
}
}
if (hand.Input.TouchpadPressed && ((Vector2)(ref touchpadAxes)).magnitude > 0.2f && Vector2.Angle(touchpadAxes, Vector2.down) <= 45f && (Object)(object)MagazineReleaseButton != (Object)null)
{
m_isMagReleaseHeld = true;
}
}
if (FireSelector_Modes.Length <= 0 || !((FVRInteractiveObject)this).m_hasTriggeredUpSinceBegin)
{
return;
}
FireSelectorModeType modeType = FireSelector_Modes[m_fireSelectorMode].ModeType;
if ((int)modeType != 0 && m_triggerFloat >= TriggerFiringThreshold && (m_hasTriggerReset || (int)modeType == 3 || ((int)modeType == 2 && m_CamBurst > 0)))
{
m_hasTriggerReset = false;
if (Fire() && m_CamBurst > 0)
{
m_CamBurst--;
}
}
}
private void ToggleFireSelector()
{
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
if (FireSelector_Modes.Length > 1)
{
m_fireSelectorMode++;
if (m_fireSelectorMode >= FireSelector_Modes.Length)
{
m_fireSelectorMode = 0;
}
SimpleFireSelectorMode simpleFireSelectorMode = FireSelector_Modes[m_fireSelectorMode];
if (m_triggerFloat < 0.1f)
{
m_CamBurst = simpleFireSelectorMode.BurstAmount;
m_engagementDelay = 0f;
}
((FVRFireArm)this).PlayAudioEvent((FirearmAudioEventType)15, 1f);
if ((Object)(object)FireSelectorSwitch != (Object)null)
{
((FVRPhysicalObject)this).SetAnimatedComponent(FireSelectorSwitch, simpleFireSelectorMode.SelectorPosition, FireSelector_InterpStyle, FireSelector_Axis);
}
}
ResetCamBurst();
}
private void ResetCamBurst()
{
if (FireSelector_Modes.Length > 0)
{
m_CamBurst = FireSelector_Modes[m_fireSelectorMode].BurstAmount;
}
m_engagementDelay = 0f;
}
public void ReleaseMag()
{
if ((Object)(object)base.Magazine != (Object)null)
{
((FVRFireArm)this).EjectMag(false);
}
}
private void AutoChamberFromMag()
{
if (!((Object)(object)Chamber != (Object)null) || Chamber.IsFull || !((Object)(object)base.Magazine != (Object)null) || !base.Magazine.HasARound())
{
return;
}
GameObject val = base.Magazine.RemoveRound(false);
if ((Object)(object)val != (Object)null)
{
FVRFireArmRound component = val.GetComponent<FVRFireArmRound>();
if ((Object)(object)component != (Object)null)
{
Chamber.SetRound(component, false);
Chamber.PlayChamberingAudio();
}
}
}
public bool Fire()
{
//IL_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: 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_0234: Unknown result type (might be due to invalid IL or missing references)
//IL_0244: 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_025f: 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_027f: Unknown result type (might be due to invalid IL or missing references)
//IL_0284: Unknown result type (might be due to invalid IL or missing references)
//IL_0289: Unknown result type (might be due to invalid IL or missing references)
//IL_0291: 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_02ac: Unknown result type (might be due to invalid IL or missing references)
//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
//IL_02ff: 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_0341: Unknown result type (might be due to invalid IL or missing references)
//IL_0346: Unknown result type (might be due to invalid IL or missing references)
//IL_0357: Unknown result type (might be due to invalid IL or missing references)
FVRFireArmRound val = null;
if ((Object)(object)Chamber != (Object)null)
{
if (!Chamber.IsFull || Chamber.IsSpent)
{
return false;
}
val = Chamber.GetRound();
Chamber.IsSpent = true;
Chamber.UpdateProxyDisplay();
}
else
{
if ((Object)(object)base.Magazine == (Object)null || !base.Magazine.HasARound())
{
return false;
}
GameObject val2 = base.Magazine.RemoveRound(false);
if ((Object)(object)val2 != (Object)null)
{
val = val2.GetComponent<FVRFireArmRound>();
}
}
if ((Object)(object)val == (Object)null)
{
return false;
}
m_timeSinceFiredShot = 0f;
if ((Object)(object)((FVRInteractiveObject)this).m_hand != (Object)null)
{
((FVRInteractiveObject)this).m_hand.Buzz(((FVRInteractiveObject)this).m_hand.Buzzer.Buzz_GunShot);
if ((Object)(object)((FVRPhysicalObject)this).AltGrip != (Object)null && (Object)(object)((FVRInteractiveObject)((FVRPhysicalObject)this).AltGrip).m_hand != (Object)null)
{
((FVRInteractiveObject)((FVRPhysicalObject)this).AltGrip).m_hand.Buzz(((FVRInteractiveObject)((FVRPhysicalObject)this).AltGrip).m_hand.Buzzer.Buzz_GunShot);
}
}
if ((Object)(object)val.BallisticProjectilePrefab != (Object)null)
{
Transform muzzle = ((FVRFireArm)this).GetMuzzle();
GameObject val3 = Object.Instantiate<GameObject>(val.BallisticProjectilePrefab, muzzle.position, muzzle.rotation);
BallisticProjectile component = val3.GetComponent<BallisticProjectile>();
if ((Object)(object)component != (Object)null)
{
component.SetSource_IFF(GM.CurrentPlayerBody.GetPlayerIFF());
component.Fire(component.MuzzleVelocityBase, val3.transform.forward, (FVRFireArm)(object)this, true);
}
}
((FVRFireArm)this).FireMuzzleSmoke();
bool flag = ((FVRFireArm)this).IsTwoHandStabilized();
bool flag2 = (Object)(object)((FVRPhysicalObject)this).AltGrip != (Object)null;
bool flag3 = ((FVRFireArm)this).IsShoulderStabilized();
((FVRFireArm)this).Recoil(flag, flag2, flag3, (FVRFireArmRecoilProfile)null, 1f);
((FVRFireArm)this).PlayAudioGunShot(val, GM.CurrentPlayerBody.GetCurrentSoundEnvironment(), 1f);
if (!DisableCaseEjections && (Object)(object)RoundPos_Ejection != (Object)null)
{
Vector3 val4 = ((Component)this).transform.right * EjectionSpeed.x + ((Component)this).transform.up * EjectionSpeed.y + ((Component)this).transform.forward * EjectionSpeed.z;
Vector3 angularVelocity = ((Component)this).transform.right * EjectionSpin.x + ((Component)this).transform.up * EjectionSpin.y + ((Component)this).transform.forward * EjectionSpin.z;
GameObject val5 = Object.Instantiate<GameObject>(((Component)val).gameObject, RoundPos_Ejection.position, RoundPos_Ejection.rotation);
FVRFireArmRound component2 = val5.GetComponent<FVRFireArmRound>();
if ((Object)(object)component2 != (Object)null)
{
((FVRPhysicalObject)component2).SetIFF(GM.CurrentPlayerBody.GetPlayerIFF());
((FVRPhysicalObject)component2).RootRigidbody.velocity = val4 + GM.CurrentMovementManager.GetFilteredVel();
((FVRPhysicalObject)component2).RootRigidbody.angularVelocity = angularVelocity;
component2.SetKillCounting(true);
component2.Fire();
}
}
if ((Object)(object)Chamber != (Object)null)
{
Chamber.SetRound((FVRFireArmRound)null, false);
AutoChamberFromMag();
}
return true;
}
private void UpdateComponents()
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: 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)
if (HasTrigger && (Object)(object)Trigger != (Object)null)
{
((FVRPhysicalObject)this).SetAnimatedComponent(Trigger, Mathf.Lerp(Trigger_ForwardValue, Trigger_RearwardValue, m_triggerFloat), TriggerInterpStyle, TriggerAxis);
}
if (HasMagReleaseButton && (Object)(object)MagazineReleaseButton != (Object)null)
{
float num = ((!m_isMagReleaseHeld) ? 0f : 1f);
Vector3 val = Vector3.Lerp(MagReleaseUnpressed, MagReleasePressed, num);
if (m_wasMagReleaseHeldDown != m_isMagReleaseHeld)
{
m_wasMagReleaseHeldDown = m_isMagReleaseHeld;
((FVRPhysicalObject)this).SetAnimatedComponent(MagazineReleaseButton, val, MagReleaseInterp);
}
}
}
private void LogDebug(string message)
{
if (DebugLogging)
{
Debug.Log((object)("SimpleFirearm: " + message));
}
}
}
[RequireComponent(typeof(Collider))]
public class GasRegulator : FVRInteractiveObject
{
private enum BoltType
{
None,
Open,
Closed
}
[Serializable]
public class RegulatorSetting
{
public string SettingName;
[Header("Visual")]
public float SelectorPosition;
[Header("Bolt Params")]
public float ForwardSpeed;
public float RearwardSpeed;
public float SpringStiffness;
}
[Header("Firearm Reference")]
public FVRFireArm Firearm;
public GameObject BoltObject;
[Header("Regulator Settings")]
public RegulatorSetting[] Settings;
private int _index = 0;
[Header("Visual")]
public Transform RegulatorGeo;
public Axis Axis;
public InterpStyle InterpStyle;
[Header("Audio")]
public AudioEvent AudEvent_Switch;
[Header("UI")]
public GameObject TextRoot;
public Text TextField;
public float TextDisplayDuration = 2f;
private BoltType _boltType = BoltType.None;
private OpenBoltReceiverBolt _openBolt;
private ClosedBolt _closedBolt;
private bool _textVisible = false;
private float _textTimer = 0f;
public override void Awake()
{
((FVRInteractiveObject)this).Awake();
if ((Object)(object)BoltObject != (Object)null)
{
_openBolt = BoltObject.GetComponent<OpenBoltReceiverBolt>();
_closedBolt = BoltObject.GetComponent<ClosedBolt>();
if ((Object)(object)_openBolt != (Object)null)
{
_boltType = BoltType.Open;
}
else if ((Object)(object)_closedBolt != (Object)null)
{
_boltType = BoltType.Closed;
}
else
{
Debug.LogWarning((object)"[GasRegulator] BoltObject has no OpenBoltReceiverBolt or ClosedBolt component.", (Object)(object)this);
}
}
else
{
Debug.LogWarning((object)"[GasRegulator] No BoltObject assigned.", (Object)(object)this);
}
if ((Object)(object)TextRoot != (Object)null)
{
TextRoot.SetActive(false);
}
if (Settings != null && Settings.Length > 0)
{
ApplySetting(0);
}
}
public override void FVRUpdate()
{
((FVRInteractiveObject)this).FVRUpdate();
if (!_textVisible)
{
return;
}
_textTimer -= Time.deltaTime;
if (_textTimer <= 0f)
{
_textVisible = false;
if ((Object)(object)TextRoot != (Object)null)
{
TextRoot.SetActive(false);
}
}
}
public override void SimpleInteraction(FVRViveHand hand)
{
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
((FVRInteractiveObject)this).SimpleInteraction(hand);
if (Settings != null && Settings.Length != 0)
{
_index++;
if (_index >= Settings.Length)
{
_index = 0;
}
ApplySetting(_index);
if ((Object)(object)Firearm != (Object)null)
{
Firearm.PlayAudioAsHandling(AudEvent_Switch, ((Component)this).transform.position);
}
ShowText(Settings[_index].SettingName);
}
}
private void ApplySetting(int i)
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
RegulatorSetting regulatorSetting = Settings[i];
if ((Object)(object)RegulatorGeo != (Object)null && (Object)(object)Firearm != (Object)null)
{
((FVRPhysicalObject)Firearm).SetAnimatedComponent(RegulatorGeo, regulatorSetting.SelectorPosition, InterpStyle, Axis);
}
switch (_boltType)
{
case BoltType.Open:
_openBolt.BoltSpeed_Forward = regulatorSetting.ForwardSpeed;
_openBolt.BoltSpeed_Rearward = regulatorSetting.RearwardSpeed;
_openBolt.BoltSpringStiffness = regulatorSetting.SpringStiffness;
break;
case BoltType.Closed:
_closedBolt.Speed_Forward = regulatorSetting.ForwardSpeed;
_closedBolt.Speed_Rearward = regulatorSetting.RearwardSpeed;
_closedBolt.SpringStiffness = regulatorSetting.SpringStiffness;
break;
}
}
private void ShowText(string settingName)
{
if (!((Object)(object)TextRoot == (Object)null))
{
if ((Object)(object)TextField != (Object)null)
{
TextField.text = settingName;
}
TextRoot.SetActive(true);
_textVisible = true;
_textTimer = TextDisplayDuration;
}
}
}
namespace Volks.M9BayonetAdapter;
[BepInPlugin("Volks.M9BayonetAdapter", "M9BayonetAdapter", "1.0.0")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
public class M9BayonetAdapterPlugin : 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.M9BayonetAdapter");
OtherLoader.RegisterDirectLoad(BasePath, "Volks.M9BayonetAdapter", "", "", "bayonetadapter_m9", "");
}
}
public class AdvanceMagazineAudioProfile : MonoBehaviour
{
[Header("References")]
[Tooltip("Auto-populated from this GameObject if left empty.")]
public FVRFireArmMagazine Magazine;
[Header("Audio — Empty Magazine")]
[Tooltip("Profile used for MagazineIn / MagazineOut when the magazine is empty.")]
public FVRFirearmMagazineAudioSet EmptyProfile;
private FVRFirearmMagazineAudioSet _originalProfileOverride;
private bool _originalUsesOverrideInOut;
private bool _wasEmpty;
private void Start()
{
if ((Object)(object)Magazine == (Object)null)
{
Magazine = ((Component)this).GetComponent<FVRFireArmMagazine>();
}
if ((Object)(object)Magazine == (Object)null)
{
Debug.LogWarning((object)"[AdvanceMagazineAudioProfile] No FVRFireArmMagazine found on this GameObject.", (Object)(object)this);
((Behaviour)this).enabled = false;
return;
}
_originalProfileOverride = Magazine.ProfileOverride;
_originalUsesOverrideInOut = Magazine.UsesOverrideInOut;
_wasEmpty = !Magazine.HasARound();
ApplyProfile(_wasEmpty);
}
private void Update()
{
if (!((Object)(object)Magazine == (Object)null))
{
bool flag = !Magazine.HasARound();
if (flag != _wasEmpty)
{
_wasEmpty = flag;
ApplyProfile(flag);
}
}
}
private void ApplyProfile(bool isEmpty)
{
if (isEmpty && (Object)(object)EmptyProfile != (Object)null)
{
Magazine.UsesOverrideInOut = true;
Magazine.ProfileOverride = EmptyProfile;
}
else
{
Magazine.UsesOverrideInOut = _originalUsesOverrideInOut;
Magazine.ProfileOverride = _originalProfileOverride;
}
}
}
public class BoltReleaseChargingHandle : MonoBehaviour
{
public ClosedBoltWeapon Weapon;
public ClosedBoltHandle Handle;
public float LaunchSpeed = 5f;
[Tooltip("If true, the handle stays at Rear until bolt release is pressed again. If false, it returns forward when pulled back manually.")]
public bool HandleReturnsManually = false;
private bool m_wasLocked;
private void Start()
{
if ((Object)(object)Weapon == (Object)null || (Object)(object)Handle == (Object)null)
{
Debug.LogWarning((object)"[BoltReleaseChargingHandle] Weapon or Handle reference is missing.", (Object)(object)this);
((Behaviour)this).enabled = false;
}
else
{
m_wasLocked = Weapon.Bolt.IsBoltLocked();
}
}
private void Update()
{
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Invalid comparison between Unknown and I4
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Invalid comparison between Unknown and I4
bool flag = Weapon.Bolt.IsBoltLocked();
if (m_wasLocked && !flag && Weapon.HasBoltReleaseButton && (int)Handle.CurPos == 4)
{
Handle.Speed_Forward = LaunchSpeed;
}
if ((int)Handle.CurPos == 0 && Handle.Speed_Forward > 0f)
{
Handle.Speed_Forward = 0f;
}
if (!HandleReturnsManually && !flag && !((FVRInteractiveObject)Handle).IsHeld && (int)Handle.CurPos == 4 && Handle.Speed_Forward == 0f)
{
Handle.Speed_Forward = LaunchSpeed;
}
m_wasLocked = flag;
}
}
public class PartRecoilImpulse : MonoBehaviour
{
public enum ImpulseMode
{
Rotation,
Translation
}
public enum ImpulseAxis
{
X,
Y,
Z
}
[Serializable]
public class RecoilPart
{
public Transform Piece;
public ImpulseMode Mode = ImpulseMode.Rotation;
public ImpulseAxis Axis = ImpulseAxis.X;
public Vector2 Range = new Vector2(0f, 45f);
public float ReturnSpeed = 5f;
public float ImpulseStrength = 1f;
[NonSerialized]
public float CurrentLerp = 0f;
}
[Header("Parts")]
public List<RecoilPart> Parts = new List<RecoilPart>();
private FVRFireArm m_firearm;
private void Awake()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
GM.CurrentSceneSettings.ShotFiredEvent += new ShotFired(OnShotFired);
}
private void OnDestroy()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
if ((Object)(object)GM.CurrentSceneSettings != (Object)null)
{
GM.CurrentSceneSettings.ShotFiredEvent -= new ShotFired(OnShotFired);
}
}
private void Start()
{
m_firearm = ((Component)this).GetComponentInParent<FVRFireArm>();
if ((Object)(object)m_firearm == (Object)null)
{
Debug.LogWarning((object)"[PartRecoilImpulse] No FVRFireArm found in parent hierarchy.", (Object)(object)this);
}
for (int i = 0; i < Parts.Count; i++)
{
ApplyToPart(Parts[i]);
}
}
private void OnShotFired(FVRFireArm firearm)
{
if (!((Object)(object)firearm != (Object)(object)m_firearm))
{
for (int i = 0; i < Parts.Count; i++)
{
Parts[i].CurrentLerp = Mathf.Clamp01(Parts[i].ImpulseStrength);
ApplyToPart(Parts[i]);
}
}
}
private void Update()
{
for (int i = 0; i < Parts.Count; i++)
{
RecoilPart recoilPart = Parts[i];
if (recoilPart.CurrentLerp > 0f)
{
recoilPart.CurrentLerp = Mathf.MoveTowards(recoilPart.CurrentLerp, 0f, Time.deltaTime * recoilPart.ReturnSpeed);
ApplyToPart(recoilPart);
}
}
}
private void ApplyToPart(RecoilPart part)
{
//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)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)part.Piece == (Object)null)
{
return;
}
float num = Mathf.Lerp(part.Range.x, part.Range.y, part.CurrentLerp);
if (part.Mode == ImpulseMode.Rotation)
{
Vector3 localEulerAngles = part.Piece.localEulerAngles;
if (part.Axis == ImpulseAxis.X)
{
localEulerAngles.x = num;
}
else if (part.Axis == ImpulseAxis.Y)
{
localEulerAngles.y = num;
}
else
{
localEulerAngles.z = num;
}
part.Piece.localEulerAngles = localEulerAngles;
}
else
{
Vector3 localPosition = part.Piece.localPosition;
if (part.Axis == ImpulseAxis.X)
{
localPosition.x = num;
}
else if (part.Axis == ImpulseAxis.Y)
{
localPosition.y = num;
}
else
{
localPosition.z = num;
}
part.Piece.localPosition = localPosition;
}
}
}
public class RPMCalculator : MonoBehaviour
{
[Header("Assign only one bugee here")]
public ClosedBolt ClosedBolt;
public OpenBoltReceiverBolt OpenBolt;
public HandgunSlide HandgunSlide;
[Header("Simulation Settings (Don't touch this bugee unless you know how physics in Unity works)")]
public float SimStepSize = 0.0005f;
public int MaxSimSteps = 100000;
[Header("Forward Calculator - Results")]
public float Result_RPM;
public float Result_CycleTimeMS;
public float Result_RearwardTimeMS;
public float Result_ForwardTimeMS;
[Header("Reverse Calculator - Inputs")]
[Tooltip("The RPM you want the weapon to fire at.")]
public float Reverse_DesiredRPM = 600f;
[Tooltip("What percentage of the cycle the bolt spends travelling rearward. Remainder is the forward (spring) stroke. Typical range: 20 to 50.")]
[Range(1f, 99f)]
public float Reverse_RearwardSplitPercent = 35f;
[Tooltip("The maximum forward speed the spring drives the bolt toward. Pin this to a value that feels right for the weapon, the script will solve SpringStiffness to match.")]
public float Reverse_DesiredSpeedForward = 10f;
[Header("Reverse Calculator - Results")]
public float Reverse_Result_SpeedForward;
public float Reverse_Result_SpeedRearward;
public float Reverse_Result_SpringStiffness;
private float m_zForward;
private float m_zRear;
private float m_speedRearward;
private float m_speedForward;
private float m_springStiffness;
[ContextMenu("Calculate RPM")]
public void Calculate()
{
if (TryReadFields() && ValidateFields() && SimulateRearward(m_speedRearward, out var rearwardTime) && SimulateForward(m_speedForward, m_springStiffness, out var forwardTime))
{
float num = rearwardTime + forwardTime;
Result_RearwardTimeMS = rearwardTime * 1000f;
Result_ForwardTimeMS = forwardTime * 1000f;
Result_CycleTimeMS = num * 1000f;
Result_RPM = 60f / num;
Debug.Log((object)("[RPMCalculator] RPM: " + Result_RPM.ToString("F0") + " | Cycle: " + Result_CycleTimeMS.ToString("F2") + "ms | Rearward: " + Result_RearwardTimeMS.ToString("F2") + "ms | Forward: " + Result_ForwardTimeMS.ToString("F2") + "ms"));
}
}
[ContextMenu("Reverse Calculate this evil bugee ")]
public void ReverseCalculate()
{
if (!TryReadFields())
{
return;
}
if (Reverse_DesiredRPM <= 0f)
{
Debug.LogError((object)"[RPMCalculator] Reverse_DesiredRPM must be greater than 0.");
return;
}
if (Reverse_DesiredSpeedForward <= 0f)
{
Debug.LogError((object)"[RPMCalculator] Reverse_DesiredSpeedForward must be greater than 0.");
return;
}
if (Mathf.Approximately(m_zForward, m_zRear))
{
Debug.LogError((object)"[RPMCalculator] Forward and Rear positions are the same. No travel distance to simulate.");
return;
}
float num = 60f / Reverse_DesiredRPM;
float num2 = num * (Reverse_RearwardSplitPercent / 100f);
float targetForwardTime = num * (1f - Reverse_RearwardSplitPercent / 100f);
float num3 = Mathf.Abs(m_zForward - m_zRear);
float reverse_Result_SpeedRearward = 0f - num3 / num2;
if (!SolveSpringStiffness(targetForwardTime, Reverse_DesiredSpeedForward, out var result))
{
Debug.LogError((object)"[RPMCalculator] Could not solve SpringStiffness. Try increasing Reverse_DesiredSpeedForward or lowering Reverse_DesiredRPM \ufffd the bolt may not be physically able to cross the travel distance in the time available.");
return;
}
Reverse_Result_SpeedRearward = reverse_Result_SpeedRearward;
Reverse_Result_SpeedForward = Reverse_DesiredSpeedForward;
Reverse_Result_SpringStiffness = result;
Debug.Log((object)("[RPMCalculator] Reverse Result for " + Reverse_DesiredRPM.ToString("F0") + " RPM: | Speed_Rearward: " + reverse_Result_SpeedRearward.ToString("F4") + " | Speed_Forward: " + Reverse_DesiredSpeedForward.ToString("F4") + " | SpringStiffness: " + result.ToString("F4")));
}
private bool SolveSpringStiffness(float targetForwardTime, float speedForward, out float result)
{
result = 0f;
float num = Mathf.Abs(m_zForward - m_zRear) / speedForward;
if (targetForwardTime < num)
{
return false;
}
float num2 = 0.001f;
float num3 = 10000f;
for (int i = 0; i < 64; i++)
{
float num4 = (num2 + num3) * 0.5f;
SimulateForward(speedForward, num4, out var forwardTime);
if (forwardTime > targetForwardTime)
{
num2 = num4;
}
else
{
num3 = num4;
}
}
result = (num2 + num3) * 0.5f;
return true;
}
private bool SimulateRearward(float speedRearward, out float rearwardTime)
{
rearwardTime = 0f;
float num = m_zForward;
int num2 = 0;
while (num > m_zRear && num2 < MaxSimSteps)
{
num += speedRearward * SimStepSize;
num = Mathf.Max(num, m_zRear);
rearwardTime += SimStepSize;
num2++;
}
if (num2 >= MaxSimSteps)
{
Debug.LogError((object)"[RPMCalculator] Hit max steps on rearward stroke.");
return false;
}
return true;
}
private bool SimulateForward(float speedForward, float springStiffness, out float forwardTime)
{
forwardTime = 0f;
float num = m_zRear;
float num2 = 0f;
int num3 = 0;
while (num < m_zForward && num3 < MaxSimSteps)
{
num2 = Mathf.MoveTowards(num2, speedForward, SimStepSize * springStiffness);
num += num2 * SimStepSize;
num = Mathf.Min(num, m_zForward);
forwardTime += SimStepSize;
num3++;
}
if (num3 >= MaxSimSteps)
{
forwardTime = float.MaxValue;
return false;
}
return true;
}
private bool TryReadFields()
{
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_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)
//IL_024a: 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_0269: Unknown result type (might be due to invalid IL or missing references)
//IL_026e: 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_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
int num = 0;
if ((Object)(object)ClosedBolt != (Object)null)
{
num++;
}
if ((Object)(object)OpenBolt != (Object)null)
{
num++;
}
if ((Object)(object)HandgunSlide != (Object)null)
{
num++;
}
if (num == 0)
{
Debug.LogError((object)"[RPMCalculator] No component assigned.");
return false;
}
if (num > 1)
{
Debug.LogError((object)"[RPMCalculator] More than one component assigned. Only assign one at a time.");
return false;
}
if ((Object)(object)ClosedBolt != (Object)null)
{
if ((Object)(object)ClosedBolt.Point_Bolt_Forward == (Object)null || (Object)(object)ClosedBolt.Point_Bolt_Rear == (Object)null)
{
Debug.LogError((object)"[RPMCalculator] ClosedBolt is missing Point_Bolt_Forward or Point_Bolt_Rear.");
return false;
}
m_zForward = ClosedBolt.Point_Bolt_Forward.localPosition.z;
m_zRear = ClosedBolt.Point_Bolt_Rear.localPosition.z;
m_speedRearward = ClosedBolt.Speed_Rearward;
m_speedForward = ClosedBolt.Speed_Forward;
m_springStiffness = ClosedBolt.SpringStiffness;
}
else if ((Object)(object)OpenBolt != (Object)null)
{
if ((Object)(object)OpenBolt.Point_Bolt_Forward == (Object)null || (Object)(object)OpenBolt.Point_Bolt_Rear == (Object)null)
{
Debug.LogError((object)"[RPMCalculator] OpenBoltReceiverBolt is missing Point_Bolt_Forward or Point_Bolt_Rear.");
return false;
}
m_zForward = OpenBolt.Point_Bolt_Forward.localPosition.z;
m_zRear = OpenBolt.Point_Bolt_Rear.localPosition.z;
m_speedRearward = OpenBolt.BoltSpeed_Rearward;
m_speedForward = OpenBolt.BoltSpeed_Forward;
m_springStiffness = OpenBolt.BoltSpringStiffness;
}
else
{
if ((Object)(object)HandgunSlide.Point_Slide_Forward == (Object)null || (Object)(object)HandgunSlide.Point_Slide_Rear == (Object)null)
{
Debug.LogError((object)"[RPMCalculator] HandgunSlide is missing Point_Slide_Forward or Point_Slide_Rear.");
return false;
}
m_zForward = HandgunSlide.Point_Slide_Forward.localPosition.z;
m_zRear = HandgunSlide.Point_Slide_Rear.localPosition.z;
m_speedRearward = HandgunSlide.Speed_Rearward;
m_speedForward = HandgunSlide.Speed_Forward;
m_springStiffness = HandgunSlide.SpringStiffness;
}
return true;
}
private bool ValidateFields()
{
if (Mathf.Approximately(m_zForward, m_zRear))
{
Debug.LogError((object)"[RPMCalculator] Forward and Rear positions are the same.");
return false;
}
if (m_speedRearward >= 0f)
{
Debug.LogError((object)("[RPMCalculator] Rearward speed should be negative. Current value: " + m_speedRearward));
return false;
}
if (m_speedForward <= 0f)
{
Debug.LogError((object)("[RPMCalculator] Forward speed must be greater than 0. Current value: " + m_speedForward));
return false;
}
if (m_springStiffness <= 0f)
{
Debug.LogError((object)("[RPMCalculator] SpringStiffness must be greater than 0. Current value: " + m_springStiffness));
return false;
}
return true;
}
}
public class SecondaryMagPos : MonoBehaviour
{
[Header("References")]
public FVRFireArm FireArm;
public FVRFireArmReloadTriggerWell TriggerWell;
[Header("Mount Override")]
public Transform MountPos;
public Transform EjectPos;
private Transform m_defaultMountPos;
private Transform m_defaultEjectPos;
private Vector3 m_defaultMountLocalPos;
private Quaternion m_defaultMountLocalRot;
private Vector3 m_defaultEjectLocalPos;
private Quaternion m_defaultEjectLocalRot;
private bool m_initialized = false;
private bool m_overrideActive = false;
private FVRFireArmMagazine m_pendingMag;
private int m_pendingStableFrames;
private const int kStableFramesRequired = 2;
private FVRFireArmMagazine m_appliedMag;
private void Start()
{
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//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_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)FireArm == (Object)null || (Object)(object)TriggerWell == (Object)null)
{
((Behaviour)this).enabled = false;
return;
}
if ((Object)(object)MountPos == (Object)null)
{
((Behaviour)this).enabled = false;
return;
}
m_defaultMountPos = FireArm.MagazineMountPos;
m_defaultEjectPos = FireArm.MagazineEjectPos;
if ((Object)(object)m_defaultMountPos == (Object)null)
{
((Behaviour)this).enabled = false;
return;
}
m_defaultMountLocalPos = m_defaultMountPos.localPosition;
m_defaultMountLocalRot = m_defaultMountPos.localRotation;
if ((Object)(object)m_defaultEjectPos != (Object)null)
{
m_defaultEjectLocalPos = m_defaultEjectPos.localPosition;
m_defaultEjectLocalRot = m_defaultEjectPos.localRotation;
}
m_initialized = true;
m_pendingMag = null;
m_pendingStableFrames = 0;
m_appliedMag = null;
}
private void Update()
{
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
if (!m_initialized)
{
return;
}
FVRFireArmMagazine magazine = FireArm.Magazine;
if ((Object)(object)magazine == (Object)(object)m_pendingMag)
{
if (m_pendingStableFrames < 2)
{
m_pendingStableFrames++;
}
}
else
{
m_pendingMag = magazine;
m_pendingStableFrames = 0;
}
if (m_pendingStableFrames < 2 || (Object)(object)m_pendingMag == (Object)(object)m_appliedMag)
{
return;
}
FireArmMagazineType val = ((!TriggerWell.UsesTypeOverride) ? FireArm.MagazineType : TriggerWell.TypeOverride);
if ((Object)(object)m_pendingMag != (Object)null && m_pendingMag.MagazineType == val)
{
m_overrideActive = true;
m_appliedMag = m_pendingMag;
return;
}
if (m_overrideActive)
{
m_overrideActive = false;
RestoreDefaults();
}
m_appliedMag = null;
}
private void LateUpdate()
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
if (m_initialized && m_overrideActive)
{
m_defaultMountPos.position = MountPos.position;
m_defaultMountPos.rotation = MountPos.rotation;
if ((Object)(object)m_defaultEjectPos != (Object)null && (Object)(object)EjectPos != (Object)null)
{
m_defaultEjectPos.position = EjectPos.position;
m_defaultEjectPos.rotation = EjectPos.rotation;
}
}
}
private void RestoreDefaults()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: 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)
m_defaultMountPos.localPosition = m_defaultMountLocalPos;
m_defaultMountPos.localRotation = m_defaultMountLocalRot;
if ((Object)(object)m_defaultEjectPos != (Object)null)
{
m_defaultEjectPos.localPosition = m_defaultEjectLocalPos;
m_defaultEjectPos.localRotation = m_defaultEjectLocalRot;
}
}
private void OnDisable()
{
if (m_initialized)
{
RestoreDefaults();
}
}
private void OnDestroy()
{
if (m_initialized)
{
RestoreDefaults();
}
}
}
public class SimpleCompass : MonoBehaviour
{
[Header("Target")]
[Tooltip("Assign Forward Z for North Facing, I think.")]
public Transform Target;
[Header("Text Version")]
public Text CompassText;
[Header("Image Version")]
[Tooltip("The arrow that will be rotated to indicate which direction.")]
public RectTransform CompassImage;
private void Update()
{
//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_00d4: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)Target == (Object)null))
{
Vector3 forward = Target.forward;
forward.y = 0f;
((Vector3)(ref forward)).Normalize();
float num = Mathf.Atan2(forward.x, forward.z) * 57.29578f;
if (num < 0f)
{
num += 360f;
}
if ((Object)(object)CompassText != (Object)null)
{
CompassText.text = GetCardinalLabel(num) + " " + Mathf.RoundToInt(num) + "°";
}
if ((Object)(object)CompassImage != (Object)null)
{
((Transform)CompassImage).localEulerAngles = new Vector3(0f, 0f, num);
}
}
}
private string GetCardinalLabel(float angle)
{
if (angle < 22.5f || angle >= 337.5f)
{
return "N";
}
if (angle < 67.5f)
{
return "NE";
}
if (angle < 112.5f)
{
return "E";
}
if (angle < 157.5f)
{
return "SE";
}
if (angle < 202.5f)
{
return "S";
}
if (angle < 247.5f)
{
return "SW";
}
if (angle < 292.5f)
{
return "W";
}
return "NW";
}
}
public class InvertClosedBolt : MonoBehaviour
{
public Transform OptionalLockPointOverride;
private void Start()
{
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
ClosedBolt component = ((Component)this).GetComponent<ClosedBolt>();
if ((Object)(object)component == (Object)null)
{
Debug.LogWarning((object)"[InvertClosedBolt] No ClosedBolt component found on this GameObject.");
return;
}
Transform point_Bolt_Forward = component.Point_Bolt_Forward;
component.Point_Bolt_Forward = component.Point_Bolt_Rear;
component.Point_Bolt_Rear = point_Bolt_Forward;
if ((Object)(object)OptionalLockPointOverride != (Object)null)
{
component.Point_Bolt_LockPoint = OptionalLockPointOverride;
}
SetPrivateFloat(component, "m_boltZ_forward", LocalZ(component.Point_Bolt_Forward));
SetPrivateFloat(component, "m_boltZ_rear", LocalZ(component.Point_Bolt_Rear));
SetPrivateFloat(component, "m_boltZ_lock", LocalZ(component.Point_Bolt_LockPoint));
SetPrivateFloat(component, "m_boltZ_current", ((Component)component).transform.localPosition.z);
if (component.UsesAKSafetyLock && (Object)(object)component.Point_Bolt_SafetyLock != (Object)null)
{
SetPrivateFloat(component, "m_boltZ_safetylock", LocalZ(component.Point_Bolt_SafetyLock));
}
component.SnapToRear();
component.UpdateBolt();
}
private static float LocalZ(Transform t)
{
//IL_000e: 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)
return (!((Object)(object)t != (Object)null)) ? 0f : t.localPosition.z;
}
private static void SetPrivateFloat(ClosedBolt cb, string name, float value)
{
typeof(ClosedBolt).GetField(name, BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(cb, value);
}
}
public class FlickerRedDot : MonoBehaviour
{
[Header("Controller Reference")]
[Tooltip("The main ReflexSightController on this attachment.")]
public ReflexSightController SightController;
[Header("Flicker Configuration")]
[Tooltip("How fast the reticle brightness oscillates/flickers. Higher values mean faster flicker.")]
public float FlickerSpeed = 30f;
[Range(0f, 1f)]
[Tooltip("The minimum brightness multiplier during a flicker (e.g. 0.5 = dips to 50% of current brightness).")]
public float MinBrightnessFactor = 0.5f;
[Range(0f, 1f)]
[Tooltip("The maximum brightness multiplier during a flicker (e.g. 1.0 = reaches 100% of current brightness).")]
public float MaxBrightnessFactor = 1f;
[Tooltip("If true, uses Perlin Noise for organic LED fluctuations. If false, uses a steady Sine wave.")]
public bool UseRandomNoise = true;
private MaterialPropertyBlock m_propBlock;
private float m_noiseOffset;
private void Start()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
if ((Object)(object)SightController == (Object)null)
{
SightController = ((Component)this).GetComponent<ReflexSightController>();
}
m_propBlock = new MaterialPropertyBlock();
m_noiseOffset = Random.Range(0f, 1000f);
}
private void LateUpdate()
{
if ((Object)(object)SightController == (Object)null || SightController.ReflexSightRenderers == null || SightController.ReflexSightRenderers.Count == 0)
{
return;
}
float num = 0f;
num = ((!UseRandomNoise) ? ((Mathf.Sin(Time.time * FlickerSpeed) + 1f) * 0.5f) : Mathf.PerlinNoise(Time.time * FlickerSpeed + m_noiseOffset, 0f));
float num2 = Mathf.Lerp(MinBrightnessFactor, MaxBrightnessFactor, num);
for (int i = 0; i < SightController.ReflexSightRenderers.Count; i++)
{
Renderer val = SightController.ReflexSightRenderers[i];
if (!((Object)(object)val == (Object)null))
{
val.GetPropertyBlock(m_propBlock);
float num3 = 1f;
if (SightController.ReticleIlluminations != null && SightController.ReticleIlluminations.Count > 0)
{
int index = Mathf.Clamp(SightController.ReticleIlluminationIndex, 0, SightController.ReticleIlluminations.Count - 1);
num3 = SightController.ReticleIlluminations[index];
}
m_propBlock.SetFloat("_ReticleIntensity", num3 * num2);
val.SetPropertyBlock(m_propBlock);
}
}
}
}
public class MagazineStock : MonoBehaviour
{
[Header("References")]
public FVRFireArm Weapon;
public int SecondarySlotIndex = 0;
public Transform Point_Stock;
[Header("Objects to disable when stocked")]
public GameObject[] ObjectsToDisableWhenStocked;
private bool _wasStocked;
private void Update()
{
SecondaryMagazineSlot val = Weapon.SecondaryMagazineSlots[SecondarySlotIndex];
if ((Object)(object)val.Magazine != (Object)null && (Object)(object)((FVRInteractiveObject)val.Magazine).m_hand != (Object)null)
{
Weapon.EjectSecondaryMagFromSlot(SecondarySlotIndex, true);
}
bool flag = (Object)(object)val.Magazine != (Object)null;
if (flag == _wasStocked)
{
return;
}
_wasStocked = flag;
if (flag)
{
Weapon.StockPos = Point_Stock;
Weapon.HasActiveShoulderStock = true;
}
else
{
Weapon.StockPos = null;
Weapon.HasActiveShoulderStock = false;
}
for (int i = 0; i < ObjectsToDisableWhenStocked.Length; i++)
{
if ((Object)(object)ObjectsToDisableWhenStocked[i] != (Object)null)
{
ObjectsToDisableWhenStocked[i].SetActive(!flag);
}
}
}
}
public class RifleToggleLock : MonoBehaviour
{
public ClosedBolt ClosedBolt;
public Transform BarrelSlide;
public Transform BarrelSlideForward;
public Transform BarrelSlideLockPoint;
public Transform TogglePiece1;
public Transform TogglePiece2;
public Transform TogglePiece3;
public Vector2 RotSet1 = new Vector2(0f, -86f);
public Vector2 RotSet2 = new Vector2(0f, 132.864f);
public Vector2 PosSet1 = new Vector2(0.02199817f, -0.02124f);
public float Height = 0.03527606f;
[Header("Motion Curves")]
[Tooltip("Drives BarrelSlide and TogglePiece1.")]
public AnimationCurve MotionCurve = AnimationCurve.Linear(0f, 0f, 1f, 1f);
[Tooltip("Drives TogglePiece2 independently.")]
public AnimationCurve MotionCurvePiece2 = AnimationCurve.Linear(0f, 0f, 1f, 1f);
[Tooltip("Drives TogglePiece3 independently.")]
public AnimationCurve MotionCurvePiece3 = AnimationCurve.Linear(0f, 0f, 1f, 1f);
[Header("Debug")]
public bool DebugOverride = false;
[Range(0f, 1f)]
public float DebugLerp = 0f;
private void Update()
{
//IL_005d: 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)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: 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)
float num = ((!DebugOverride) ? (1f - ClosedBolt.GetBoltLerpBetweenRearAndFore()) : DebugLerp);
float num2 = MotionCurve.Evaluate(num);
float num3 = MotionCurvePiece2.Evaluate(num);
float num4 = MotionCurvePiece3.Evaluate(num);
BarrelSlide.localPosition = Vector3.Lerp(BarrelSlideForward.localPosition, BarrelSlideLockPoint.localPosition, num2);
float num5 = Mathf.Lerp(RotSet1.x, RotSet1.y, num2);
float num6 = Mathf.Lerp(RotSet2.x, RotSet2.y, num3);
float num7 = Mathf.Lerp(PosSet1.x, PosSet1.y, num4);
TogglePiece1.localEulerAngles = new Vector3(num5, 0f, 0f);
TogglePiece2.localEulerAngles = new Vector3(num6, 0f, 0f);
TogglePiece3.localPosition = new Vector3(0f, Height, num7);
}
}
internal class AutoReleaseOnMagLoad : MonoBehaviour
{
private FVRFireArm weapon;
private Handgun handgun;
private bool wasLoaded;
public void Start()
{
weapon = ((Component)this).GetComponent<FVRFireArm>();
if (!((Object)(object)weapon == (Object)null) && weapon is Handgun)
{
ref Handgun reference = ref handgun;
FVRFireArm obj = weapon;
reference = (Handgun)(object)((obj is Handgun) ? obj : null);
}
}
public void FixedUpdate()
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Invalid comparison between Unknown and I4
if ((Object)(object)handgun != (Object)null)
{
if ((Object)(object)weapon.Magazine != (Object)null)
{
if (weapon.Magazine.HasARound())
{
if ((int)handgun.Slide.CurPos >= 2 && !wasLoaded)
{
handgun.Slide.ImpartFiringImpulse();
wasLoaded = true;
}
}
else
{
wasLoaded = false;
}
}
else
{
wasLoaded = false;
}
}
else
{
wasLoaded = false;
}
}
}
public class HandgunSlideSafety : MonoBehaviour
{
public HandgunSlide Slide;
public Handgun Handgun;
[Tooltip("Place between Point_Slide_Forward and Point_Slide_LockPoint. Controls how far back the slide can travel with no magazine.")]
public Transform Point_Slide_NoMagLimit;
private FieldInfo _slideZCurrentField;
private float _limitZ;
private bool _rearIsLess;
private bool _initialized;
private void Awake()
{
//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_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
_slideZCurrentField = typeof(HandgunSlide).GetField("m_slideZ_current", BindingFlags.Instance | BindingFlags.NonPublic);
if ((Object)(object)Slide != (Object)null && (Object)(object)Point_Slide_NoMagLimit != (Object)null)
{
_limitZ = Point_Slide_NoMagLimit.localPosition.z;
_rearIsLess = Slide.Point_Slide_Rear.localPosition.z < Slide.Point_Slide_Forward.localPosition.z;
}
_initialized = (Object)(object)Slide != (Object)null && (Object)(object)Handgun != (Object)null && (Object)(object)Point_Slide_NoMagLimit != (Object)null && (object)_slideZCurrentField != null;
}
private void LateUpdate()
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
if (_initialized && !((Object)(object)((FVRFireArm)Handgun).Magazine != (Object)null))
{
Vector3 localPosition = ((Component)Slide).transform.localPosition;
if ((!_rearIsLess) ? (localPosition.z > _limitZ) : (localPosition.z < _limitZ))
{
((Component)Slide).transform.localPosition = new Vector3(localPosition.x, localPosition.y, _limitZ);
_slideZCurrentField.SetValue(Slide, _limitZ);
}
}
}
}
[RequireComponent(typeof(Collider))]
public class HandgunSlideControl : FVRInteractiveObject
{
[Serializable]
public class SlideControlSetting
{
public string SettingName;
[Header("Visual")]
public float SelectorPosition;
[Header("Slide Params")]
public float ForwardSpeed;
public float RearwardSpeed;
public float HeldSpeed;
public float SpringStiffness;
}
[Header("References")]
public Handgun Handgun;
public HandgunSlide Slide;
[Header("Settings")]
public SlideControlSetting[] Settings;
private int _index = 0;
[Header("Visual")]
public Transform ControlGeo;
public Axis Axis;
public InterpStyle InterpStyle;
[Header("Audio")]
public AudioEvent AudEvent_Switch;
[Header("UI")]
public GameObject TextRoot;
public TextMesh TextField;
public float TextDisplayDuration = 2f;
private bool _textVisible = false;
private float _textTimer = 0f;
public override void Awake()
{
((FVRInteractiveObject)this).Awake();
if ((Object)(object)Slide == (Object)null)
{
Debug.LogWarning((object)"[HandgunSlideControl] No HandgunSlide assigned.", (Object)(object)this);
}
if ((Object)(object)TextRoot != (Object)null)
{
TextRoot.SetActive(false);
}
if (Settings != null && Settings.Length > 0)
{
ApplySetting(0);
}
}
public override void FVRUpdate()
{
((FVRInteractiveObject)this).FVRUpdate();
if (!_textVisible)
{
return;
}
_textTimer -= Time.deltaTime;
if (_textTimer <= 0f)
{
_textVisible = false;
if ((Object)(object)TextRoot != (Object)null)
{
TextRoot.SetActive(false);
}
}
}
public override void SimpleInteraction(FVRViveHand hand)
{
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
((FVRInteractiveObject)this).SimpleInteraction(hand);
if (Settings != null && Settings.Length != 0)
{
_index++;
if (_index >= Settings.Length)
{
_index = 0;
}
ApplySetting(_index);
if ((Object)(object)Handgun != (Object)null)
{
((FVRFireArm)Handgun).PlayAudioAsHandling(AudEvent_Switch, ((Component)this).transform.position);
}
ShowText(Settings[_index].SettingName);
}
}
private void ApplySetting(int i)
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
SlideControlSetting slideControlSetting = Settings[i];
if ((Object)(object)ControlGeo != (Object)null && (Object)(object)Handgun != (Object)null)
{
((FVRPhysicalObject)Handgun).SetAnimatedComponent(ControlGeo, slideControlSetting.SelectorPosition, InterpStyle, Axis);
}
if (!((Object)(object)Slide == (Object)null))
{
Slide.Speed_Forward = slideControlSetting.ForwardSpeed;
Slide.Speed_Rearward = slideControlSetting.RearwardSpeed;
Slide.Speed_Held = slideControlSetting.HeldSpeed;
Slide.SpringStiffness = slideControlSetting.SpringStiffness;
}
}
private void ShowText(string settingName)
{
if (!((Object)(object)TextRoot == (Object)null))
{
if ((Object)(object)TextField != (Object)null)
{
TextField.text = settingName;
}
TextRoot.SetActive(true);
_textVisible = true;
_textTimer = TextDisplayDuration;
}
}
}
public class StreamlineDecocker : MonoBehaviour
{
public enum EStreamlineInputType
{
AXButton,
BYButton
}
public enum EInputType
{
TouchpadUp,
TouchpadDown,
TouchpadLeft,
TouchpadRight
}
[Header("Manual Handgun Decocker")]
public Handgun Handgun;
[Header("Streamlined Controls Input")]
public EStreamlineInputType StreamlineInputType;
[Header("Classic Controls Input")]
public EInputType InputType;
[Tooltip("Use this if you wanna use the safety as it is configured on the handgun itself.")]
public bool UsesHandgunSafetyObjectInstead = false;
[Header("Standalone decocker object.")]
public Transform Decocker;
public Axis DecockerAxis;
public InterpStyle DecockerInterpStyle;
public float DecockerReleased;
public float DecockerPressed;
private bool _wasDecocked = false;
public void Update()
{
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//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)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Handgun == (Object)null)
{
return;
}
FVRViveHand hand = ((FVRInteractiveObject)Handgun).m_hand;
if ((Object)(object)hand != (Object)null && CorrectInput(hand))
{
if (!_wasDecocked)
{
Handgun.DeCockHammer(true, true);
if (!UsesHandgunSafetyObjectInstead)
{
((FVRPhysicalObject)Handgun).SetAnimatedComponent(Decocker, DecockerPressed, DecockerInterpStyle, DecockerAxis);
}
else
{
((FVRPhysicalObject)Handgun).SetAnimatedComponent(Handgun.Safety, Handgun.SafetyOn, Handgun.Safety_Interp, Handgun.SafetyAxis);
}
_wasDecocked = true;
}
}
else if (_wasDecocked)
{
if (!UsesHandgunSafetyObjectInstead)
{
((FVRPhysicalObject)Handgun).SetAnimatedComponent(Decocker, DecockerReleased, DecockerInterpStyle, DecockerAxis);
}
else
{
((FVRPhysicalObject)Handgun).SetAnimatedComponent(Handgun.Safety, Handgun.SafetyOff, Handgun.Safety_Interp, Handgun.SafetyAxis);
}
_wasDecocked = false;
}
}
private bool CorrectInput(FVRViveHand hand)
{
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
if (hand.IsInStreamlinedMode)
{
return StreamlineInputType switch
{
EStreamlineInputType.AXButton => hand.Input.AXButtonPressed,
EStreamlineInputType.BYButton => hand.Input.BYButtonDown,
_ => false,
};
}
Vector2 dir;
switch (InputType)
{
case EInputType.TouchpadUp:
dir = Vector2.up;
break;
case EInputType.TouchpadDown:
dir = Vector2.down;
break;
case EInputType.TouchpadLeft:
dir = Vector2.left;
break;
case EInputType.TouchpadRight:
dir = Vector2.right;
break;
default:
return false;
}
return TouchpadDirPressed(hand, dir);
}
private bool TouchpadDirPressed(FVRViveHand hand, Vector2 dir)
{
//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_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
Vector2 touchpadAxes = hand.Input.TouchpadAxes;
if (((Vector2)(ref touchpadAxes)).magnitude <= 0.2f)
{
return false;
}
float num = Vector2.Angle(touchpadAxes, dir);
if (num > 45f)
{
return false;
}
if (hand.Input.TouchpadDown || hand.Input.TouchpadPressed)
{
return true;
}
return false;
}
}