using System;
using System.Collections;
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 ModularWorkshop;
using OpenScripts2;
using OtherLoader;
using Sodalite.Api;
using UnityEngine;
using UnityEngine.SceneManagement;
[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 MagLatchCollisionForwarder : MonoBehaviour
{
public ModulPhysicalMagReleaseLatch Target;
private void OnCollisionStay(Collision col)
{
if ((Object)(object)Target != (Object)null)
{
Target.ReportCollision(col);
}
}
}
public class ModulPhysicalMagReleaseLatch : MonoBehaviour, IPartFireArmRequirement
{
private FVRFireArm _fireArm;
public HingeJoint Joint;
public float Threshold = -35f;
private float timeSinceLastCollision = 6f;
private Vector3 _connectedAnchor;
private bool _hasStoredAnchor;
public FVRFireArm FireArm
{
get
{
return _fireArm;
}
set
{
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
_fireArm = value;
if ((Object)(object)Joint == (Object)null)
{
Joint = ((Component)this).GetComponentInChildren<HingeJoint>();
}
if ((Object)(object)_fireArm != (Object)null && (Object)(object)((FVRPhysicalObject)_fireArm).RootRigidbody != (Object)null && _hasStoredAnchor)
{
((Joint)Joint).autoConfigureConnectedAnchor = false;
((Joint)Joint).connectedAnchor = _connectedAnchor;
((Joint)Joint).connectedBody = ((FVRPhysicalObject)_fireArm).RootRigidbody;
}
else if ((Object)(object)Joint != (Object)null)
{
((Joint)Joint).connectedBody = null;
}
}
}
private void Awake()
{
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Joint == (Object)null)
{
Joint = ((Component)this).GetComponentInChildren<HingeJoint>();
}
if ((Object)(object)Joint != (Object)null)
{
MagLatchCollisionForwarder magLatchCollisionForwarder = ((Component)Joint).gameObject.GetComponent<MagLatchCollisionForwarder>();
if ((Object)(object)magLatchCollisionForwarder == (Object)null)
{
magLatchCollisionForwarder = ((Component)Joint).gameObject.AddComponent<MagLatchCollisionForwarder>();
}
magLatchCollisionForwarder.Target = this;
}
FVRFireArm componentInParent = ((Component)this).GetComponentInParent<FVRFireArm>();
if ((Object)(object)componentInParent != (Object)null && (Object)(object)((FVRPhysicalObject)componentInParent).RootRigidbody != (Object)null && (Object)(object)Joint != (Object)null)
{
Vector3 val = ((Component)Joint).transform.TransformPoint(((Joint)Joint).anchor);
_connectedAnchor = ((Component)((FVRPhysicalObject)componentInParent).RootRigidbody).transform.InverseTransformPoint(val);
_hasStoredAnchor = true;
}
}
private void FixedUpdate()
{
if (!((Object)(object)_fireArm == (Object)null) && !((Object)(object)Joint == (Object)null))
{
if (timeSinceLastCollision < 5f)
{
timeSinceLastCollision += Time.deltaTime;
}
if ((Object)(object)_fireArm.Magazine != (Object)null && timeSinceLastCollision < 0.03f && Joint.angle < Threshold)
{
_fireArm.EjectMag(true);
}
}
}
public void ReportCollision(Collision col)
{
if (!((Object)(object)_fireArm == (Object)null) && !((Object)(object)col.collider.attachedRigidbody == (Object)null) && !((Object)(object)col.collider.attachedRigidbody == (Object)(object)((FVRPhysicalObject)_fireArm).RootRigidbody))
{
FVRPhysicalObject component = ((Component)col.collider.attachedRigidbody).gameObject.GetComponent<FVRPhysicalObject>();
if ((Object)(object)component != (Object)null && ((FVRInteractiveObject)component).IsHeld)
{
timeSinceLastCollision = 0f;
}
}
}
}
public class EjectionChanger : MonoBehaviour, IPartFireArmRequirement
{
[Header("Ejection Config")]
public Vector3 NewEjectionSpeed;
public Vector3 NewEjectionSpin;
private Vector3 _origEjectionSpeed;
private Vector3 _origEjectionSpin;
private ClosedBoltWeapon _ejectionFirearm;
public FVRFireArm FireArm
{
get
{
return (FVRFireArm)(object)_ejectionFirearm;
}
set
{
if ((Object)(object)_ejectionFirearm != (Object)null)
{
RemoveEjection();
}
ClosedBoltWeapon val = (ClosedBoltWeapon)(object)((value is ClosedBoltWeapon) ? value : null);
if ((Object)(object)val != (Object)null)
{
ApplyEjection(val);
}
else
{
_ejectionFirearm = null;
}
}
}
private void ApplyEjection(ClosedBoltWeapon firearm)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
_ejectionFirearm = firearm;
if (!((Object)(object)_ejectionFirearm == (Object)null))
{
_origEjectionSpeed = _ejectionFirearm.EjectionSpeed;
_origEjectionSpin = _ejectionFirearm.EjectionSpin;
_ejectionFirearm.EjectionSpeed = NewEjectionSpeed;
_ejectionFirearm.EjectionSpin = NewEjectionSpin;
Debug.Log((object)"EjectionChanger: Applying new ejection values.");
}
}
private void RemoveEjection()
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_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)
Debug.Log((object)"EjectionChanger: Reverting ejection values.");
if (!((Object)(object)_ejectionFirearm == (Object)null))
{
_ejectionFirearm.EjectionSpeed = _origEjectionSpeed;
_ejectionFirearm.EjectionSpin = _origEjectionSpin;
_ejectionFirearm = null;
}
}
}
namespace Volks.ModulAR2_AR1022_Lower;
[BepInPlugin("Volks.ModulAR2_AR1022_Lower", "ModulAR2_AR1022_Lower", "1.0.0")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.cityrobo.ModularWorkshopManager", "1.0.0")]
[BepInDependency("nrgill28.Sodalite", "1.4.2")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
public class ModulAR2_AR1022_LowerPlugin : 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.ModulAR2_AR1022_Lower");
GameAPI.PreloadAllAssets(Path.Combine(BasePath, "mw_modular2_ar1022_lower"));
OtherLoader.RegisterDirectLoad(BasePath, "Volks.ModulAR2_AR1022_Lower", "", "", "modular1022_receiver", "");
}
}
public class ForwardAssist : FVRInteractiveObject
{
[Header("Animation Settings")]
public Transform TargetTransform;
public Vector3 StartPosition;
public Vector3 EndPosition;
public Vector3 StartRotation;
public Vector3 EndRotation;
public float MoveSpeed = 10f;
public float ResetDelay = 0.2f;
[Header("Audio Settings")]
public AudioEvent PokeAudioEvent;
public FVRPooledAudioType AudioType = (FVRPooledAudioType)0;
private float m_animFloat = 0f;
private bool m_isPoked = false;
private float m_resetTimer = 0f;
protected void Awake()
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
((FVRInteractiveObject)this).Awake();
if ((Object)(object)TargetTransform == (Object)null)
{
TargetTransform = ((Component)this).transform;
}
if (StartPosition == Vector3.zero)
{
StartPosition = TargetTransform.localPosition;
}
if (StartRotation == Vector3.zero)
{
StartRotation = TargetTransform.localEulerAngles;
}
}
public override void Poke(FVRViveHand hand)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
if (PokeAudioEvent != null)
{
SM.PlayCoreSound(AudioType, PokeAudioEvent, ((Component)this).transform.position);
}
m_isPoked = true;
m_resetTimer = ResetDelay;
}
private void Update()
{
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
if (m_isPoked)
{
m_animFloat = Mathf.MoveTowards(m_animFloat, 1f, Time.deltaTime * MoveSpeed);
m_resetTimer -= Time.deltaTime;
if (m_resetTimer <= 0f)
{
m_isPoked = false;
}
}
else
{
m_animFloat = Mathf.MoveTowards(m_animFloat, 0f, Time.deltaTime * MoveSpeed);
}
if ((Object)(object)TargetTransform != (Object)null)
{
TargetTransform.localPosition = Vector3.Lerp(StartPosition, EndPosition, m_animFloat);
TargetTransform.localEulerAngles = Vector3.Lerp(StartRotation, EndRotation, m_animFloat);
}
}
}
public class ModularSubPartOverride : MonoBehaviour
{
[Serializable]
public class SubPartOverrideRule
{
[Tooltip("The ModularPartsGroupID of the sub-attachment point to override (e.g. GasBlocks_AR).")]
public string TargetSubGroupID;
[Tooltip("The exact Name of the modular part you want to force-select for this sub-point.")]
public string DesiredPartName;
[Tooltip("Optional: If specified, this override only triggers if the parent part matches this name. Leave empty to apply to any parent part.")]
public string OnlyWhenParentPartIs;
}
[Tooltip("Enables verbose console logging for debugging.")]
public bool EnableDebugLogging = false;
[Tooltip("If true, will not overwrite parts restored from a player's Vault save file.")]
public bool RespectVaultSaves = true;
[Tooltip("Rules defining which sub-attachment points to override with your chosen parts.")]
public SubPartOverrideRule[] Overrides = new SubPartOverrideRule[0];
private IModularWeapon m_modularWeapon;
private ModularFVRFireArm m_modularFireArm;
private ModularFVRPhysicalObject m_modularPhysicalObject;
private bool m_hasSubscribed;
private bool m_isApplyingOverride;
public void Awake()
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Expected O, but got Unknown
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Expected O, but got Unknown
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Expected O, but got Unknown
Component val = ((Component)this).GetComponent(typeof(IModularWeapon));
if ((Object)(object)val == (Object)null)
{
val = ((Component)this).GetComponentInChildren(typeof(IModularWeapon));
}
if ((Object)(object)val != (Object)null)
{
m_modularWeapon = (IModularWeapon)val;
m_modularFireArm = m_modularWeapon.GetModularFVRFireArm;
}
if (m_modularFireArm == null)
{
m_modularPhysicalObject = ((Component)this).GetComponent<ModularFVRPhysicalObject>();
if ((Object)(object)m_modularPhysicalObject == (Object)null)
{
m_modularPhysicalObject = ((Component)this).GetComponentInChildren<ModularFVRPhysicalObject>();
}
}
if (m_modularFireArm == null && (Object)(object)m_modularPhysicalObject == (Object)null)
{
Debug.LogError((object)"[ModularSubPartOverride] Fatal: Neither IModularWeapon (ModularFVRFireArm) nor ModularFVRPhysicalObject found on GameObject or children!");
}
else
{
if (m_hasSubscribed)
{
return;
}
if (m_modularFireArm != null)
{
m_modularFireArm.PartAdded += new PartAdded(OnPartAdded);
m_hasSubscribed = true;
if (EnableDebugLogging)
{
Debug.Log((object)"[ModularSubPartOverride] Subscribed to ModularFVRFireArm.PartAdded event.");
}
}
else if ((Object)(object)m_modularPhysicalObject != (Object)null)
{
m_modularPhysicalObject.PartAdded += new PartAdded(OnPartAdded);
m_hasSubscribed = true;
if (EnableDebugLogging)
{
Debug.Log((object)"[ModularSubPartOverride] Subscribed to ModularFVRPhysicalObject.PartAdded event.");
}
}
}
}
public void Start()
{
ReconcileExistingSubPoints();
}
public void OnDestroy()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
if (m_hasSubscribed)
{
if (m_modularFireArm != null)
{
m_modularFireArm.PartAdded -= new PartAdded(OnPartAdded);
}
else if ((Object)(object)m_modularPhysicalObject != (Object)null)
{
m_modularPhysicalObject.PartAdded -= new PartAdded(OnPartAdded);
}
m_hasSubscribed = false;
}
}
private bool IsWeaponUnvaulted()
{
if (m_modularFireArm != null)
{
return m_modularFireArm.WasUnvaulted;
}
if ((Object)(object)m_modularPhysicalObject != (Object)null)
{
return m_modularPhysicalObject.WasUnvaulted;
}
return false;
}
private List<ModularWeaponPartsAttachmentPoint> GetActiveSubPoints()
{
if (m_modularFireArm != null)
{
return m_modularFireArm.SubAttachmentPoints;
}
if ((Object)(object)m_modularPhysicalObject != (Object)null)
{
return m_modularPhysicalObject.SubAttachmentPoints;
}
return null;
}
private void ReconcileExistingSubPoints()
{
List<ModularWeaponPartsAttachmentPoint> activeSubPoints = GetActiveSubPoints();
if (activeSubPoints == null || activeSubPoints.Count == 0 || (RespectVaultSaves && IsWeaponUnvaulted()))
{
return;
}
for (int i = 0; i < activeSubPoints.Count; i++)
{
ModularWeaponPartsAttachmentPoint val = activeSubPoints[i];
if (val != null && !string.IsNullOrEmpty(val.ModularPartsGroupID))
{
SubPartOverrideRule subPartOverrideRule = FindMatchingRule(val.ModularPartsGroupID, string.Empty);
if (subPartOverrideRule != null && !string.IsNullOrEmpty(subPartOverrideRule.DesiredPartName) && !string.Equals(val.SelectedModularWeaponPart, subPartOverrideRule.DesiredPartName, StringComparison.OrdinalIgnoreCase))
{
ApplySubPartOverride(val, subPartOverrideRule.DesiredPartName);
}
}
}
}
private void OnPartAdded(ModularWeaponPartsAttachmentPoint attachmentPoint, ModularWeaponPart newPart)
{
if (m_isApplyingOverride || (Object)(object)newPart == (Object)null || (RespectVaultSaves && IsWeaponUnvaulted()) || Overrides == null || Overrides.Length == 0 || newPart.SubAttachmentPoints == null || newPart.SubAttachmentPoints.Length == 0)
{
return;
}
string parentPartName = string.Empty;
ModularWeaponPart component = ((Component)newPart).GetComponent<ModularWeaponPart>();
if ((Object)(object)component != (Object)null)
{
parentPartName = component.Name;
}
for (int i = 0; i < newPart.SubAttachmentPoints.Length; i++)
{
ModularWeaponPartsAttachmentPoint val = newPart.SubAttachmentPoints[i];
if (val != null && !string.IsNullOrEmpty(val.ModularPartsGroupID))
{
SubPartOverrideRule subPartOverrideRule = FindMatchingRule(val.ModularPartsGroupID, parentPartName);
if (subPartOverrideRule != null && !string.IsNullOrEmpty(subPartOverrideRule.DesiredPartName) && !string.Equals(val.SelectedModularWeaponPart, subPartOverrideRule.DesiredPartName, StringComparison.OrdinalIgnoreCase))
{
ApplySubPartOverride(val, subPartOverrideRule.DesiredPartName);
}
}
}
}
private SubPartOverrideRule FindMatchingRule(string subGroupID, string parentPartName)
{
for (int i = 0; i < Overrides.Length; i++)
{
SubPartOverrideRule subPartOverrideRule = Overrides[i];
if (subPartOverrideRule != null && !string.IsNullOrEmpty(subPartOverrideRule.TargetSubGroupID) && string.Equals(subPartOverrideRule.TargetSubGroupID, subGroupID, StringComparison.OrdinalIgnoreCase))
{
if (string.IsNullOrEmpty(subPartOverrideRule.OnlyWhenParentPartIs))
{
return subPartOverrideRule;
}
if (!string.IsNullOrEmpty(parentPartName) && string.Equals(subPartOverrideRule.OnlyWhenParentPartIs, parentPartName, StringComparison.OrdinalIgnoreCase))
{
return subPartOverrideRule;
}
}
}
return null;
}
private void ApplySubPartOverride(ModularWeaponPartsAttachmentPoint subPoint, string targetPartName)
{
m_isApplyingOverride = true;
try
{
if (EnableDebugLogging)
{
Debug.Log((object)("[ModularSubPartOverride] Overriding sub-point '" + subPoint.ModularPartsGroupID + "' (was '" + subPoint.SelectedModularWeaponPart + "') with: " + targetPartName));
}
subPoint.SelectedModularWeaponPart = targetPartName;
if (m_modularFireArm != null)
{
m_modularFireArm.ConfigureModularWeaponPart(subPoint, targetPartName, false, (Dictionary<string, string>)null, (Dictionary<string, string>)null);
}
else if ((Object)(object)m_modularPhysicalObject != (Object)null)
{
m_modularPhysicalObject.ConfigureModularWeaponPart(subPoint, targetPartName, false, (Dictionary<string, string>)null, (Dictionary<string, string>)null);
}
if (EnableDebugLogging)
{
Debug.Log((object)("[ModularSubPartOverride] Successfully overridden sub-point '" + subPoint.ModularPartsGroupID + "'."));
}
}
catch (Exception ex)
{
Debug.LogError((object)("[ModularSubPartOverride] Error overriding sub-point '" + subPoint.ModularPartsGroupID + "': " + ex.Message));
}
finally
{
m_isApplyingOverride = false;
}
}
}
public class MultipleGroupIDAttachment : MonoBehaviour
{
[Tooltip("Enables verbose console logging for debugging.")]
public bool EnableDebugLogging = false;
[Tooltip("List of additional ModularPartsGroupIDs this part should also belong to.")]
public string[] AdditionalGroupIDs = new string[0];
[Tooltip("Specific ModularPartsGroupIDs on the host weapon to replace/disable when this part is attached (e.g. BufferTubes_AR, Grips_AR, Triggers_AR, Selectors_AR).")]
public string[] RelocatedGroupIDs = new string[0];
[Tooltip("If enabled, automatically detects any sub-attachment point on this part that shares a group ID with the host weapon's points, replacing the host weapon's slot.")]
public bool AutoRelocateMatchingSubPoints = true;
private bool m_isRelocated;
private List<ModularWeaponPartsAttachmentPoint> m_relocatedPoints = new List<ModularWeaponPartsAttachmentPoint>();
private List<string> m_originalGroupIDs = new List<string>();
private List<string> m_originalSelectedParts = new List<string>();
public void Awake()
{
ApplyRelocations();
}
public void OnDestroy()
{
RevertRelocations();
}
private void ApplyRelocations()
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
if (m_isRelocated)
{
return;
}
IModularWeapon val = null;
Component componentInParent = ((Component)this).GetComponentInParent(typeof(IModularWeapon));
if ((Object)(object)componentInParent != (Object)null)
{
val = (IModularWeapon)componentInParent;
}
ModularFVRPhysicalObject val2 = null;
if (val == null)
{
val2 = ((Component)this).GetComponentInParent<ModularFVRPhysicalObject>();
}
List<ModularWeaponPartsAttachmentPoint> list = new List<ModularWeaponPartsAttachmentPoint>();
if (val != null)
{
ModularFVRFireArm getModularFVRFireArm = val.GetModularFVRFireArm;
if (getModularFVRFireArm != null)
{
if (getModularFVRFireArm.ModularBarrelAttachmentPoint != null)
{
list.Add(getModularFVRFireArm.ModularBarrelAttachmentPoint);
}
if (getModularFVRFireArm.ModularHandguardAttachmentPoint != null)
{
list.Add(getModularFVRFireArm.ModularHandguardAttachmentPoint);
}
if (getModularFVRFireArm.ModularStockAttachmentPoint != null)
{
list.Add(getModularFVRFireArm.ModularStockAttachmentPoint);
}
}
if (val.ModularWeaponPartsAttachmentPoints != null)
{
list.AddRange(val.ModularWeaponPartsAttachmentPoints);
}
if (val.SubAttachmentPoints != null)
{
list.AddRange(val.SubAttachmentPoints);
}
}
else if ((Object)(object)val2 != (Object)null)
{
if (val2.ModularWeaponPartsAttachmentPoints != null)
{
list.AddRange(val2.ModularWeaponPartsAttachmentPoints);
}
if (val2.SubAttachmentPoints != null)
{
list.AddRange(val2.SubAttachmentPoints);
}
}
if (list.Count == 0)
{
return;
}
List<string> list2 = new List<string>();
ModularWeaponPart component = ((Component)this).GetComponent<ModularWeaponPart>();
if (RelocatedGroupIDs != null)
{
for (int i = 0; i < RelocatedGroupIDs.Length; i++)
{
string text = RelocatedGroupIDs[i];
if (!string.IsNullOrEmpty(text) && !list2.Contains(text))
{
list2.Add(text);
}
}
}
if (AutoRelocateMatchingSubPoints && (Object)(object)component != (Object)null && component.SubAttachmentPoints != null)
{
for (int j = 0; j < component.SubAttachmentPoints.Length; j++)
{
ModularWeaponPartsAttachmentPoint val3 = component.SubAttachmentPoints[j];
if (val3 != null && !string.IsNullOrEmpty(val3.ModularPartsGroupID) && !list2.Contains(val3.ModularPartsGroupID))
{
list2.Add(val3.ModularPartsGroupID);
}
}
}
if (list2.Count == 0)
{
return;
}
for (int k = 0; k < list.Count; k++)
{
ModularWeaponPartsAttachmentPoint val4 = list[k];
if (val4 != null && !string.IsNullOrEmpty(val4.ModularPartsGroupID) && (!((Object)(object)component != (Object)null) || component.SubAttachmentPoints == null || Array.IndexOf(component.SubAttachmentPoints, val4) < 0) && list2.Contains(val4.ModularPartsGroupID))
{
RelocateSinglePoint(val4, val, val2);
}
}
if (m_relocatedPoints.Count > 0)
{
m_isRelocated = true;
}
}
private void RelocateSinglePoint(ModularWeaponPartsAttachmentPoint targetPoint, IModularWeapon modWeapon, ModularFVRPhysicalObject modPhys)
{
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Expected O, but got Unknown
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
if (targetPoint == null || m_relocatedPoints.Contains(targetPoint))
{
return;
}
string modularPartsGroupID = targetPoint.ModularPartsGroupID;
string selectedModularWeaponPart = targetPoint.SelectedModularWeaponPart;
m_relocatedPoints.Add(targetPoint);
m_originalGroupIDs.Add(modularPartsGroupID);
m_originalSelectedParts.Add(selectedModularWeaponPart);
if (modWeapon != null && (Object)(object)modWeapon.WorkshopPlatform != (Object)null)
{
modWeapon.WorkshopPlatform.RemoveUIFromPoint(targetPoint);
}
else if ((Object)(object)modPhys != (Object)null && (Object)(object)modPhys.WorkshopPlatform != (Object)null)
{
modPhys.WorkshopPlatform.RemoveUIFromPoint(targetPoint);
}
if ((Object)(object)targetPoint.ModularPartPoint != (Object)null)
{
GameObject val = new GameObject(modularPartsGroupID + "_TempPoint");
val.transform.position = targetPoint.ModularPartPoint.position;
val.transform.rotation = targetPoint.ModularPartPoint.rotation;
val.transform.parent = targetPoint.ModularPartPoint.parent;
ModularWeaponPart componentInChildren = ((Component)targetPoint.ModularPartPoint).GetComponentInChildren<ModularWeaponPart>();
if ((Object)(object)componentInChildren != (Object)null)
{
componentInChildren.DisablePart();
Object.Destroy((Object)(object)((Component)componentInChildren).gameObject);
}
targetPoint.ModularPartPoint = val.transform;
}
targetPoint.IsPointDisabled = true;
targetPoint.ModularPartsGroupID = modularPartsGroupID + "_Relocated";
if (EnableDebugLogging)
{
Debug.Log((object)("[MultipleGroupIDAttachment] Replaced point '" + modularPartsGroupID + "' -> renamed to '" + targetPoint.ModularPartsGroupID + "' and created temporary anchor."));
}
}
private void RevertRelocations()
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Expected O, but got Unknown
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: 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)
if (!m_isRelocated || m_relocatedPoints.Count == 0)
{
return;
}
IModularWeapon val = null;
Component componentInParent = ((Component)this).GetComponentInParent(typeof(IModularWeapon));
if ((Object)(object)componentInParent != (Object)null)
{
val = (IModularWeapon)componentInParent;
}
ModularFVRPhysicalObject val2 = null;
if (val == null)
{
val2 = ((Component)this).GetComponentInParent<ModularFVRPhysicalObject>();
}
ClosedBoltWeapon componentInParent2 = ((Component)this).GetComponentInParent<ClosedBoltWeapon>();
if ((Object)(object)componentInParent2 != (Object)null)
{
componentInParent2.HasTrigger = false;
componentInParent2.Trigger = ((Component)componentInParent2).transform;
}
for (int i = 0; i < m_relocatedPoints.Count; i++)
{
ModularWeaponPartsAttachmentPoint val3 = m_relocatedPoints[i];
string text = m_originalGroupIDs[i];
string text2 = m_originalSelectedParts[i];
if (val3 == null)
{
continue;
}
val3.ModularPartsGroupID = text;
val3.IsPointDisabled = false;
if ((Object)(object)componentInParent2 != (Object)null && componentInParent2.HasTrigger && (Object)(object)componentInParent2.Trigger == (Object)null && (Object)(object)val3.ModularPartPoint != (Object)null)
{
componentInParent2.Trigger = val3.ModularPartPoint;
}
if (string.IsNullOrEmpty(text2))
{
continue;
}
val3.SelectedModularWeaponPart = text2;
try
{
if (val != null)
{
val.ConfigureModularWeaponPart(val3, text2, false);
}
else if ((Object)(object)val2 != (Object)null)
{
val2.ConfigureModularWeaponPart(val3, text2, false, (Dictionary<string, string>)null, (Dictionary<string, string>)null);
}
ModularWorkshopPlatform val4 = null;
if (val != null)
{
val4 = val.WorkshopPlatform;
}
else if ((Object)(object)val2 != (Object)null)
{
val4 = val2.WorkshopPlatform;
}
if ((Object)(object)val4 != (Object)null)
{
EPartType val5 = DeterminePartType(val3, val, val2);
val4.CreateUIForPoint(val3, val5);
}
if (EnableDebugLogging)
{
Debug.Log((object)("[MultipleGroupIDAttachment] Synchronously restored point '" + text + "' with part: " + text2));
}
}
catch (Exception ex)
{
if (EnableDebugLogging)
{
Debug.LogError((object)("[MultipleGroupIDAttachment] Error restoring point '" + text + "': " + ex.Message));
}
}
}
if ((Object)(object)componentInParent2 != (Object)null && (Object)(object)componentInParent2.Trigger != (Object)null && (Object)(object)componentInParent2.Trigger != (Object)(object)((Component)componentInParent2).transform)
{
componentInParent2.HasTrigger = true;
}
m_relocatedPoints.Clear();
m_originalGroupIDs.Clear();
m_originalSelectedParts.Clear();
m_isRelocated = false;
}
private EPartType DeterminePartType(ModularWeaponPartsAttachmentPoint point, IModularWeapon modWeapon, ModularFVRPhysicalObject modPhys)
{
//IL_00f1: 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_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
if (modWeapon != null)
{
if (!string.IsNullOrEmpty(modWeapon.ModularBarrelPartsID) && string.Equals(point.ModularPartsGroupID, modWeapon.ModularBarrelPartsID, StringComparison.OrdinalIgnoreCase))
{
return (EPartType)0;
}
if (!string.IsNullOrEmpty(modWeapon.ModularHandguardPartsID) && string.Equals(point.ModularPartsGroupID, modWeapon.ModularHandguardPartsID, StringComparison.OrdinalIgnoreCase))
{
return (EPartType)1;
}
if (!string.IsNullOrEmpty(modWeapon.ModularStockPartsID) && string.Equals(point.ModularPartsGroupID, modWeapon.ModularStockPartsID, StringComparison.OrdinalIgnoreCase))
{
return (EPartType)2;
}
if (modWeapon.SubAttachmentPoints != null && modWeapon.SubAttachmentPoints.Contains(point))
{
return (EPartType)4;
}
return (EPartType)3;
}
if ((Object)(object)modPhys != (Object)null && modPhys.SubAttachmentPoints != null && modPhys.SubAttachmentPoints.Contains(point))
{
return (EPartType)4;
}
return (EPartType)3;
}
}
[BepInPlugin("com.custom.multiplegroupidattachment", "MultipleGroupIDAttachment", "1.0.0")]
public class MultipleGroupIDPlugin : BaseUnityPlugin
{
[Tooltip("Enables verbose console logging for debugging.")]
public bool EnableDebugLogging = false;
private static MultipleGroupIDPlugin s_instance;
private bool m_isRunning;
private HashSet<string> m_registeredPairs = new HashSet<string>();
public static MultipleGroupIDPlugin Instance => s_instance;
public void Awake()
{
s_instance = this;
SceneManager.sceneLoaded += OnSceneLoaded;
TriggerScan();
}
public void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
if ((Object)(object)s_instance == (Object)(object)this)
{
s_instance = null;
}
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
TriggerScan();
}
public void TriggerScan()
{
if (!m_isRunning)
{
((MonoBehaviour)this).StartCoroutine(RegistrationRoutine());
}
}
private IEnumerator RegistrationRoutine()
{
m_isRunning = true;
for (float timer = 0f; timer < 20f; timer += 1.5f)
{
ProcessRegistrations();
yield return (object)new WaitForSeconds(1.5f);
}
ProcessRegistrations();
m_isRunning = false;
}
private void ProcessRegistrations()
{
if (ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary == null)
{
return;
}
MultipleGroupIDAttachment[] array = Resources.FindObjectsOfTypeAll<MultipleGroupIDAttachment>();
if (array != null && array.Length > 0)
{
foreach (MultipleGroupIDAttachment multipleGroupIDAttachment in array)
{
if ((Object)(object)multipleGroupIDAttachment != (Object)null && (Object)(object)((Component)multipleGroupIDAttachment).gameObject != (Object)null && multipleGroupIDAttachment.AdditionalGroupIDs != null && multipleGroupIDAttachment.AdditionalGroupIDs.Length > 0)
{
InjectPrefabIntoGroups(((Component)multipleGroupIDAttachment).gameObject, multipleGroupIDAttachment.AdditionalGroupIDs);
}
}
}
if (ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary.Count <= 0)
{
return;
}
List<ModularWorkshopPartsDefinition> list = new List<ModularWorkshopPartsDefinition>(ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary.Values);
for (int j = 0; j < list.Count; j++)
{
ModularWorkshopPartsDefinition val = list[j];
if ((Object)(object)val == (Object)null || val.ModularPrefabs == null)
{
continue;
}
for (int k = 0; k < val.ModularPrefabs.Count; k++)
{
GameObject val2 = val.ModularPrefabs[k];
if (!((Object)(object)val2 == (Object)null))
{
MultipleGroupIDAttachment component = val2.GetComponent<MultipleGroupIDAttachment>();
if ((Object)(object)component != (Object)null && component.AdditionalGroupIDs != null && component.AdditionalGroupIDs.Length > 0)
{
InjectPrefabIntoGroups(val2, component.AdditionalGroupIDs);
}
}
}
}
}
private void InjectPrefabIntoGroups(GameObject prefab, string[] targetGroupIDs)
{
ModularWeaponPart component = prefab.GetComponent<ModularWeaponPart>();
string targetPartName = ((!((Object)(object)component != (Object)null)) ? ((Object)prefab).name : component.Name);
int instanceID = ((Object)prefab).GetInstanceID();
foreach (string text in targetGroupIDs)
{
if (string.IsNullOrEmpty(text))
{
continue;
}
string item = instanceID + ":" + text;
if (m_registeredPairs.Contains(item))
{
continue;
}
if (ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary.TryGetValue(text, out var value))
{
if (!((Object)(object)value != (Object)null) || value.ModularPrefabs == null)
{
continue;
}
if (IsPartNameAlreadyInGroup(value, targetPartName))
{
m_registeredPairs.Add(item);
}
else if (!value.ModularPrefabs.Contains(prefab))
{
value.ModularPrefabs.Add(prefab);
m_registeredPairs.Add(item);
if (EnableDebugLogging)
{
Debug.Log((object)("[MultipleGroupIDAttachment] Injected prefab '" + ((Object)prefab).name + "' into existing group: " + text));
}
}
else
{
m_registeredPairs.Add(item);
}
}
else
{
value = ScriptableObject.CreateInstance<ModularWorkshopPartsDefinition>();
((Object)value).name = text + "_DynamicDefinition";
value.ModularPartsGroupID = text;
value.DisplayName = text;
value.ModularPrefabs = new List<GameObject>();
value.ModularPrefabs.Add(prefab);
ModularWorkshopManager.ModularWorkshopPartsGroupsDictionary.Add(text, value);
m_registeredPairs.Add(item);
if (EnableDebugLogging)
{
Debug.Log((object)("[MultipleGroupIDAttachment] Created dynamic group '" + text + "' and registered prefab: " + ((Object)prefab).name));
}
}
}
}
private bool IsPartNameAlreadyInGroup(ModularWorkshopPartsDefinition def, string targetPartName)
{
if ((Object)(object)def == (Object)null || def.ModularPrefabs == null)
{
return false;
}
for (int i = 0; i < def.ModularPrefabs.Count; i++)
{
GameObject val = def.ModularPrefabs[i];
if (!((Object)(object)val == (Object)null))
{
ModularWeaponPart component = val.GetComponent<ModularWeaponPart>();
if ((Object)(object)component != (Object)null && string.Equals(component.Name, targetPartName, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
}
return false;
}
}
[DefaultExecutionOrder(-200)]
[RequireComponent(typeof(ModularWeaponPart))]
public class IntegratedAttachableFirearmAddon : MonoBehaviour, IPartFireArmRequirement
{
[Header("Debug Settings")]
[Tooltip("Enable detailed console logs to track component auto-detection and linking.")]
public bool EnableDebugLogging = true;
private FVRFireArm _mainFireArm;
private AttachableFirearm _underbarrelFirearm;
private AttachableFirearmPhysicalObject _underbarrelPhysical;
private AttachableFirearmInterface _underbarrelInterface;
private bool _needsLayerForce = false;
public FVRFireArm FireArm
{
get
{
return _mainFireArm;
}
set
{
if ((Object)(object)value != (Object)null)
{
_mainFireArm = value;
if (EnableDebugLogging)
{
Debug.Log((object)$"[IntegratedAttachableFirearmAddon] Equipping - Main Firearm assigned: {((Object)value).name}");
}
if ((Object)(object)_underbarrelFirearm != (Object)null)
{
_underbarrelFirearm.OverrideFA = value;
value.SetIntegratedAttachableFirearm(_underbarrelFirearm);
}
((Behaviour)this).enabled = true;
_needsLayerForce = true;
return;
}
if (EnableDebugLogging)
{
Debug.Log((object)"[IntegratedAttachableFirearmAddon] Swapping away - Part unequipped. Starting cleanup.");
}
_needsLayerForce = false;
if ((Object)(object)_underbarrelFirearm != (Object)null)
{
_underbarrelFirearm.OverrideFA = null;
}
if ((Object)(object)_underbarrelInterface != (Object)null)
{
((AttachableForegrip)_underbarrelInterface).OverrideFirearm = null;
}
if ((Object)(object)_mainFireArm != (Object)null)
{
_mainFireArm.SetIntegratedAttachableFirearm((AttachableFirearm)null);
}
if ((Object)(object)_underbarrelPhysical != (Object)null)
{
if (EnableDebugLogging)
{
Debug.Log((object)$"[IntegratedAttachableFirearmAddon] Swapping away - Destroying unparented physical launcher GameObject: {((Object)((Component)_underbarrelPhysical).gameObject).name}");
}
Object.Destroy((Object)(object)((Component)_underbarrelPhysical).gameObject);
_underbarrelPhysical = null;
}
_mainFireArm = null;
}
}
private void Awake()
{
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Expected O, but got Unknown
//IL_027f: Unknown result type (might be due to invalid IL or missing references)
//IL_0286: Expected O, but got Unknown
//IL_0371: Unknown result type (might be due to invalid IL or missing references)
//IL_0378: Expected O, but got Unknown
_underbarrelFirearm = ((Component)this).GetComponentInChildren<AttachableFirearm>(true);
_underbarrelPhysical = ((Component)this).GetComponentInChildren<AttachableFirearmPhysicalObject>(true);
_underbarrelInterface = ((Component)this).GetComponentInChildren<AttachableFirearmInterface>(true);
if (EnableDebugLogging)
{
Debug.Log((object)$"[IntegratedAttachableFirearmAddon] Awake - Underbarrel Firearm: {(Object)(object)_underbarrelFirearm != (Object)null}, Physical: {(Object)(object)_underbarrelPhysical != (Object)null}, Interface: {(Object)(object)_underbarrelInterface != (Object)null}");
}
if ((Object)(object)_underbarrelFirearm != (Object)null)
{
_underbarrelFirearm.Attachment = _underbarrelPhysical;
_underbarrelFirearm.Interface = _underbarrelInterface;
}
if ((Object)(object)_underbarrelPhysical != (Object)null)
{
((FVRFireArmAttachment)_underbarrelPhysical).AttachmentInterface = (FVRFireArmAttachmentInterface)(object)_underbarrelInterface;
}
if ((Object)(object)_underbarrelInterface != (Object)null)
{
_underbarrelInterface.FA = _underbarrelFirearm;
((FVRFireArmAttachmentInterface)_underbarrelInterface).Attachment = (FVRFireArmAttachment)(object)_underbarrelPhysical;
}
if (EnableDebugLogging)
{
Debug.Log((object)"[IntegratedAttachableFirearmAddon] Awake - Unconditionally forced all component cross-references in memory.");
}
if ((Object)(object)_underbarrelPhysical != (Object)null && (Object)(object)((FVRInteractiveObject)_underbarrelPhysical).PoseOverride == (Object)null)
{
Transform val = ((Component)_underbarrelPhysical).transform.Find("_Pose");
if ((Object)(object)val == (Object)null)
{
foreach (Transform item in ((Component)_underbarrelPhysical).transform)
{
Transform val2 = item;
if (((Object)val2).name.ToLower().Contains("pose"))
{
val = val2;
break;
}
}
}
if ((Object)(object)val != (Object)null)
{
((FVRInteractiveObject)_underbarrelPhysical).PoseOverride = val;
if (EnableDebugLogging)
{
Debug.Log((object)$"[IntegratedAttachableFirearmAddon] Awake - PoseOverride was NULL. Auto-repaired by linking to child: {((Object)val).name}");
}
}
}
if (!((Object)(object)_underbarrelFirearm != (Object)null))
{
return;
}
if ((Object)(object)_underbarrelFirearm.MuzzlePos == (Object)null)
{
Transform val3 = ((Component)_underbarrelFirearm).transform.Find("_Muzzle");
if ((Object)(object)val3 == (Object)null)
{
foreach (Transform item2 in ((Component)_underbarrelFirearm).transform)
{
Transform val4 = item2;
if (((Object)val4).name.ToLower().Contains("muzzle"))
{
val3 = val4;
break;
}
}
}
if ((Object)(object)val3 != (Object)null)
{
_underbarrelFirearm.MuzzlePos = val3;
if (EnableDebugLogging)
{
Debug.Log((object)$"[IntegratedAttachableFirearmAddon] Awake - MuzzlePos was NULL. Auto-repaired by linking to child: {((Object)val3).name}");
}
}
}
if (!((Object)(object)_underbarrelFirearm.RecoilingPoseHolder == (Object)null))
{
return;
}
Transform val5 = ((Component)_underbarrelFirearm).transform.Find("_RecoilHolder");
if ((Object)(object)val5 == (Object)null)
{
foreach (Transform item3 in ((Component)_underbarrelFirearm).transform)
{
Transform val6 = item3;
if (((Object)val6).name.ToLower().Contains("recoil"))
{
val5 = val6;
break;
}
}
}
if ((Object)(object)val5 != (Object)null)
{
_underbarrelFirearm.RecoilingPoseHolder = val5;
if (EnableDebugLogging)
{
Debug.Log((object)$"[IntegratedAttachableFirearmAddon] Awake - RecoilingPoseHolder was NULL. Auto-repaired by linking to child: {((Object)val5).name}");
}
}
}
private void Update()
{
if (!_needsLayerForce || !((Object)(object)_mainFireArm != (Object)null))
{
return;
}
_needsLayerForce = false;
int num = LayerMask.NameToLayer("Interactable");
if (num != -1)
{
if ((Object)(object)_underbarrelPhysical != (Object)null)
{
SetLayerRecursive(((Component)_underbarrelPhysical).gameObject, num);
}
if ((Object)(object)_underbarrelInterface != (Object)null)
{
SetLayerRecursive(((Component)_underbarrelInterface).gameObject, num);
}
if (EnableDebugLogging)
{
Debug.Log((object)"[IntegratedAttachableFirearmAddon] Update - Unconditionally forced 'Interactable' layer recursively down the hierarchies.");
}
}
else if (EnableDebugLogging)
{
Debug.LogError((object)"[IntegratedAttachableFirearmAddon] Update - Could not find 'Interactable' layer in Unity.");
}
}
private void SetLayerRecursive(GameObject obj, int layer)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
if ((Object)(object)obj == (Object)null)
{
return;
}
obj.layer = layer;
foreach (Transform item in obj.transform)
{
Transform val = item;
if ((Object)(object)val != (Object)null)
{
SetLayerRecursive(((Component)val).gameObject, layer);
}
}
}
}
public class SafetyToggle : FVRInteractiveObject
{
public ClosedBoltWeapon Weapon;
public Transform SelctorSwitch;
public Axis Axis;
public InterpStyle InterpStyle;
[Tooltip("Index in Weapon.FireSelector_Modes that this secondary toggle will override (e.g. 1)")]
public int ModeIndexToSub = 1;
public FireSelectorMode[] Modes;
[Tooltip("Enable to show debug logs in console.")]
public bool DebugLogging = false;
private int CurModeIndex;
private FireSelectorMode[] _backupModes;
private FireSelectorMode[] _backupModes2;
private bool _isGloballySafe;
public override void Awake()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
//IL_0047: 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_0074: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: 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_0129: Expected O, but got Unknown
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
((FVRInteractiveObject)this).Awake();
if (Modes == null || Modes.Length < 2)
{
Modes = (FireSelectorMode[])(object)new FireSelectorMode[2];
FireSelectorMode[] modes = Modes;
FireSelectorMode val = new FireSelectorMode();
val.SelectorPosition = 0f;
val.ModeType = (FireSelectorModeType)0;
val.BurstAmount = 0;
val.ARStyleBurst = false;
val.EngagementDelay = 0f;
modes[0] = val;
FireSelectorMode[] modes2 = Modes;
val = new FireSelectorMode();
val.SelectorPosition = 0f;
val.ModeType = (FireSelectorModeType)1;
val.BurstAmount = 1;
val.ARStyleBurst = false;
val.EngagementDelay = 0f;
modes2[1] = val;
}
if ((Object)(object)Weapon != (Object)null && Weapon.FireSelector_Modes != null && ModeIndexToSub >= 0 && ModeIndexToSub < Weapon.FireSelector_Modes.Length)
{
FireSelectorMode val2 = Weapon.FireSelector_Modes[ModeIndexToSub];
if ((int)val2.ModeType == 0)
{
CurModeIndex = 0;
}
else
{
CurModeIndex = 1;
FireSelectorMode[] modes3 = Modes;
FireSelectorMode val = new FireSelectorMode();
val.SelectorPosition = val2.SelectorPosition;
val.ModeType = val2.ModeType;
val.BurstAmount = val2.BurstAmount;
val.ARStyleBurst = val2.ARStyleBurst;
val.EngagementDelay = val2.EngagementDelay;
modes3[1] = val;
}
if ((Object)(object)SelctorSwitch != (Object)null)
{
((FVRPhysicalObject)Weapon).SetAnimatedComponent(SelctorSwitch, Modes[CurModeIndex].SelectorPosition, InterpStyle, Axis);
}
}
}
public override void SimpleInteraction(FVRViveHand hand)
{
((FVRInteractiveObject)this).SimpleInteraction(hand);
CycleMode();
}
private void CycleMode()
{
if (!((Object)(object)Weapon == (Object)null) && Weapon.FireSelector_Modes != null && ModeIndexToSub >= 0 && ModeIndexToSub < Weapon.FireSelector_Modes.Length && Modes != null && Modes.Length >= 2)
{
CurModeIndex++;
if (CurModeIndex >= Modes.Length)
{
CurModeIndex = 0;
}
if (CurModeIndex == 0)
{
EnableGlobalSafe();
}
else
{
DisableGlobalSafeAndRestore();
}
((FVRFireArm)Weapon).PlayAudioEvent((FirearmAudioEventType)15, 1f);
}
}
private void EnableGlobalSafe()
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
//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_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Expected O, but got Unknown
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
FireSelectorMode[] fireSelector_Modes = Weapon.FireSelector_Modes;
_backupModes = (FireSelectorMode[])(object)new FireSelectorMode[fireSelector_Modes.Length];
for (int i = 0; i < fireSelector_Modes.Length; i++)
{
FireSelectorMode[] backupModes = _backupModes;
int num = i;
FireSelectorMode val = new FireSelectorMode();
val.SelectorPosition = fireSelector_Modes[i].SelectorPosition;
val.ModeType = fireSelector_Modes[i].ModeType;
val.BurstAmount = fireSelector_Modes[i].BurstAmount;
val.ARStyleBurst = fireSelector_Modes[i].ARStyleBurst;
val.EngagementDelay = fireSelector_Modes[i].EngagementDelay;
backupModes[num] = val;
}
if (Weapon.FireSelector_Modes2 != null)
{
FireSelectorMode[] fireSelector_Modes2 = Weapon.FireSelector_Modes2;
_backupModes2 = (FireSelectorMode[])(object)new FireSelectorMode[fireSelector_Modes2.Length];
for (int j = 0; j < fireSelector_Modes2.Length; j++)
{
FireSelectorMode[] backupModes2 = _backupModes2;
int num2 = j;
FireSelectorMode val = new FireSelectorMode();
val.SelectorPosition = fireSelector_Modes2[j].SelectorPosition;
val.ModeType = fireSelector_Modes2[j].ModeType;
val.BurstAmount = fireSelector_Modes2[j].BurstAmount;
val.ARStyleBurst = fireSelector_Modes2[j].ARStyleBurst;
val.EngagementDelay = fireSelector_Modes2[j].EngagementDelay;
backupModes2[num2] = val;
}
}
else
{
_backupModes2 = null;
}
for (int k = 0; k < Weapon.FireSelector_Modes.Length; k++)
{
Weapon.FireSelector_Modes[k].ModeType = (FireSelectorModeType)0;
Weapon.FireSelector_Modes[k].BurstAmount = 0;
}
if (Weapon.FireSelector_Modes2 != null)
{
for (int l = 0; l < Weapon.FireSelector_Modes2.Length; l++)
{
Weapon.FireSelector_Modes2[l].ModeType = (FireSelectorModeType)0;
Weapon.FireSelector_Modes2[l].BurstAmount = 0;
}
}
if ((Object)(object)SelctorSwitch != (Object)null)
{
((FVRPhysicalObject)Weapon).SetAnimatedComponent(SelctorSwitch, Modes[0].SelectorPosition, InterpStyle, Axis);
}
Weapon.ResetCamBurst();
_isGloballySafe = true;
if (DebugLogging)
{
Debug.Log((object)"SafetyToggle: Global safe enabled.");
}
}
private void DisableGlobalSafeAndRestore()
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: Unknown result type (might be due to invalid IL or missing references)
//IL_023b: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
if (!_isGloballySafe)
{
ApplyModeToWeapon(1);
return;
}
if (_backupModes != null)
{
int num = Math.Min(_backupModes.Length, Weapon.FireSelector_Modes.Length);
for (int i = 0; i < num; i++)
{
Weapon.FireSelector_Modes[i].ModeType = _backupModes[i].ModeType;
Weapon.FireSelector_Modes[i].BurstAmount = _backupModes[i].BurstAmount;
Weapon.FireSelector_Modes[i].ARStyleBurst = _backupModes[i].ARStyleBurst;
Weapon.FireSelector_Modes[i].EngagementDelay = _backupModes[i].EngagementDelay;
Weapon.FireSelector_Modes[i].SelectorPosition = _backupModes[i].SelectorPosition;
}
}
if (_backupModes2 != null && Weapon.FireSelector_Modes2 != null)
{
int num2 = Math.Min(_backupModes2.Length, Weapon.FireSelector_Modes2.Length);
for (int j = 0; j < num2; j++)
{
Weapon.FireSelector_Modes2[j].ModeType = _backupModes2[j].ModeType;
Weapon.FireSelector_Modes2[j].BurstAmount = _backupModes2[j].BurstAmount;
Weapon.FireSelector_Modes2[j].ARStyleBurst = _backupModes2[j].ARStyleBurst;
Weapon.FireSelector_Modes2[j].EngagementDelay = _backupModes2[j].EngagementDelay;
Weapon.FireSelector_Modes2[j].SelectorPosition = _backupModes2[j].SelectorPosition;
}
}
if (_backupModes != null && ModeIndexToSub >= 0 && ModeIndexToSub < _backupModes.Length)
{
Modes[1].SelectorPosition = _backupModes[ModeIndexToSub].SelectorPosition;
Modes[1].ModeType = _backupModes[ModeIndexToSub].ModeType;
Modes[1].BurstAmount = _backupModes[ModeIndexToSub].BurstAmount;
Modes[1].ARStyleBurst = _backupModes[ModeIndexToSub].ARStyleBurst;
Modes[1].EngagementDelay = _backupModes[ModeIndexToSub].EngagementDelay;
}
if ((Object)(object)SelctorSwitch != (Object)null)
{
((FVRPhysicalObject)Weapon).SetAnimatedComponent(SelctorSwitch, Modes[1].SelectorPosition, InterpStyle, Axis);
}
Weapon.ResetCamBurst();
_isGloballySafe = false;
if (DebugLogging)
{
Debug.Log((object)"SafetyToggle: Global safe disabled, original modes restored.");
}
}
private void ApplyModeToWeapon(int modeIndex)
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
FireSelectorMode val = Modes[modeIndex];
if ((Object)(object)SelctorSwitch != (Object)null)
{
((FVRPhysicalObject)Weapon).SetAnimatedComponent(SelctorSwitch, val.SelectorPosition, InterpStyle, Axis);
}
FireSelectorMode val2 = Weapon.FireSelector_Modes[ModeIndexToSub];
val2.ModeType = val.ModeType;
val2.BurstAmount = val.BurstAmount;
val2.ARStyleBurst = val.ARStyleBurst;
val2.EngagementDelay = val.EngagementDelay;
val2.SelectorPosition = val.SelectorPosition;
if (Weapon.FireSelector_Modes2 != null && ModeIndexToSub >= 0 && ModeIndexToSub < Weapon.FireSelector_Modes2.Length)
{
FireSelectorMode val3 = Weapon.FireSelector_Modes2[ModeIndexToSub];
val3.ModeType = val2.ModeType;
val3.BurstAmount = val2.BurstAmount;
val3.ARStyleBurst = val2.ARStyleBurst;
val3.EngagementDelay = val2.EngagementDelay;
val3.SelectorPosition = val2.SelectorPosition;
}
Weapon.ResetCamBurst();
}
}
[DefaultExecutionOrder(-100)]
public class ModularAttachableTubeFed : MonoBehaviour
{
[Tooltip("Enables verbose console logging for debugging.")]
public bool EnableDebugLogging = false;
[Tooltip("The primary AttachableTubeFed component managing firing and cycling logic.")]
public AttachableTubeFed TubeFed;
[Tooltip("The ModularFVRPhysicalObject managing modular points on this weapon.")]
public ModularFVRPhysicalObject ModularPhysicalObject;
[Tooltip("The sliding bolt component on the shotgun.")]
public AttachableTubeFedBolt Bolt;
[Tooltip("The persistent sliding carriage handle component on the shotgun.")]
public AttachableTubeFedFore Handle;
[Tooltip("Fallback trigger transform if no modular trigger is installed.")]
public Transform DefaultTrigger;
[Tooltip("Fallback safety selector transform if no modular selector is installed.")]
public Transform DefaultSafety;
[Tooltip("Fallback stock position transform if no modular stock is installed.")]
public Transform DefaultStock;
[Tooltip("If enabled, forces UsesAnimatedCarrier to false and UsesMagazines to true on Awake for box magazine feeding.")]
public bool EnforceBoxMagazineFeed = true;
private bool m_originalHasTrigger;
private bool m_originalHasSafety;
private float m_originalTriggerBreakThreshold;
private float m_originalTriggerResetThreshold;
private FireArmRoundType m_originalRoundType;
private FireArmMagazineType m_originalMagazineType;
private FVRFireArmRecoilProfile m_originalRecoilProfile;
private FVRFireArmRecoilProfile m_originalRecoilProfileStocked;
private FVRFirearmAudioSet m_originalAudioClipSet;
private float m_originalBoltSpeedForward;
private float m_originalBoltSpeedRearward;
private float m_originalBoltSpringStiffness;
private bool m_hasSubscribed;
private bool m_wasMounted;
private TransformProxy m_cachedSkinProxy;
private Transform m_originalMuzzleParent;
private Vector3 m_originalMuzzleLocalPos;
private Quaternion m_originalMuzzleLocalRot;
private Transform m_originalMagMountParent;
private Vector3 m_originalMagMountLocalPos;
private Quaternion m_originalMagMountLocalRot;
private Transform m_originalMagEjectParent;
private Vector3 m_originalMagEjectLocalPos;
private Quaternion m_originalMagEjectLocalRot;
public void Awake()
{
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ea: 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_0200: Unknown result type (might be due to invalid IL or missing references)
//IL_023f: 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_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_0305: Unknown result type (might be due to invalid IL or missing references)
//IL_030a: Unknown result type (might be due to invalid IL or missing references)
//IL_0316: Unknown result type (might be due to invalid IL or missing references)
//IL_031b: Unknown result type (might be due to invalid IL or missing references)
//IL_0299: Unknown result type (might be due to invalid IL or missing references)
//IL_029e: Unknown result type (might be due to invalid IL or missing references)
//IL_02af: Unknown result type (might be due to invalid IL or missing references)
//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)TubeFed == (Object)null)
{
TubeFed = ((Component)this).GetComponent<AttachableTubeFed>();
if ((Object)(object)TubeFed == (Object)null)
{
TubeFed = ((Component)this).GetComponentInParent<AttachableTubeFed>();
}
}
if ((Object)(object)TubeFed == (Object)null)
{
Debug.LogError((object)"[ModularAttachableTubeFed] Fatal: AttachableTubeFed component not found on GameObject or parents!");
return;
}
if ((Object)(object)ModularPhysicalObject == (Object)null)
{
ModularPhysicalObject = ((Component)this).GetComponentInChildren<ModularFVRPhysicalObject>(true);
if ((Object)(object)ModularPhysicalObject == (Object)null)
{
ModularPhysicalObject = ((Component)this).GetComponent<ModularFVRPhysicalObject>();
}
}
if ((Object)(object)ModularPhysicalObject == (Object)null)
{
Debug.LogError((object)"[ModularAttachableTubeFed] Fatal: ModularFVRPhysicalObject component not found on GameObject or children!");
return;
}
if ((Object)(object)Bolt == (Object)null)
{
Bolt = TubeFed.Bolt;
if ((Object)(object)Bolt == (Object)null)
{
Bolt = ((Component)this).GetComponentInChildren<AttachableTubeFedBolt>();
}
}
if ((Object)(object)Handle == (Object)null)
{
Handle = TubeFed.Handle;
if ((Object)(object)Handle == (Object)null)
{
Handle = ((Component)this).GetComponentInChildren<AttachableTubeFedFore>();
}
}
if ((Object)(object)DefaultTrigger == (Object)null)
{
DefaultTrigger = TubeFed.Trigger;
}
if ((Object)(object)DefaultSafety == (Object)null)
{
DefaultSafety = TubeFed.Safety;
}
if ((Object)(object)DefaultStock == (Object)null)
{
DefaultStock = ((AttachableFirearm)TubeFed).StockPos;
}
if ((Object)(object)((AttachableFirearm)TubeFed).MuzzlePos != (Object)null)
{
m_originalMuzzleParent = ((AttachableFirearm)TubeFed).MuzzlePos.parent;
m_originalMuzzleLocalPos = ((AttachableFirearm)TubeFed).MuzzlePos.localPosition;
m_originalMuzzleLocalRot = ((AttachableFirearm)TubeFed).MuzzlePos.localRotation;
}
if ((Object)(object)((AttachableFirearm)TubeFed).MagazineMountPos != (Object)null)
{
m_originalMagMountParent = ((AttachableFirearm)TubeFed).MagazineMountPos.parent;
m_originalMagMountLocalPos = ((AttachableFirearm)TubeFed).MagazineMountPos.localPosition;
m_originalMagMountLocalRot = ((AttachableFirearm)TubeFed).MagazineMountPos.localRotation;
}
if ((Object)(object)((AttachableFirearm)TubeFed).MagazineEjectPos != (Object)null)
{
m_originalMagEjectParent = ((AttachableFirearm)TubeFed).MagazineEjectPos.parent;
m_originalMagEjectLocalPos = ((AttachableFirearm)TubeFed).MagazineEjectPos.localPosition;
m_originalMagEjectLocalRot = ((AttachableFirearm)TubeFed).MagazineEjectPos.localRotation;
}
m_originalHasTrigger = TubeFed.HasTrigger;
m_originalHasSafety = TubeFed.HasSafety;
m_originalTriggerBreakThreshold = TubeFed.TriggerBreakThreshold;
m_originalTriggerResetThreshold = TubeFed.TriggerResetThreshold;
m_originalRoundType = ((AttachableFirearm)TubeFed).RoundType;
m_originalMagazineType = ((AttachableFirearm)TubeFed).MagazineType;
m_originalRecoilProfile = ((AttachableFirearm)TubeFed).RecoilProfile;
m_originalRecoilProfileStocked = ((AttachableFirearm)TubeFed).RecoilProfileStocked;
m_originalAudioClipSet = ((AttachableFirearm)TubeFed).AudioClipSet;
if ((Object)(object)((AttachableFirearm)TubeFed).RecoilProfileStocked == (Object)null)
{
((AttachableFirearm)TubeFed).UsesStockedRecoilProfile = false;
}
if ((Object)(object)Bolt != (Object)null)
{
m_originalBoltSpeedForward = Bolt.Speed_Forward;
m_originalBoltSpeedRearward = Bolt.Speed_Rearward;
m_originalBoltSpringStiffness = Bolt.SpringStiffness;
}
if (EnforceBoxMagazineFeed)
{
TubeFed.UsesAnimatedCarrier = false;
((AttachableFirearm)TubeFed).UsesMagazines = true;
}
ForceCheckMountState();
}
public void Start()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
if ((Object)(object)ModularPhysicalObject != (Object)null && !m_hasSubscribed)
{
ModularPhysicalObject.PartAdded += new PartAdded(OnModularPartAdded);
m_hasSubscribed = true;
}
RebuildWeaponState();
ForceCheckMountState();
}
public void OnEnable()
{
ForceCheckMountState();
}
public void OnTransformParentChanged()
{
ForceCheckMountState();
}
public void Update()
{
ForceCheckMountState();
CheckForDestroyedReferences();
}
public void LateUpdate()
{
ForceCheckMountState();
}
public void OnDestroy()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
if (m_hasSubscribed && (Object)(object)ModularPhysicalObject != (Object)null)
{
ModularPhysicalObject.PartAdded -= new PartAdded(OnModularPartAdded);
m_hasSubscribed = false;
}
}
private void ForceCheckMountState()
{
if (!((Object)(object)TubeFed == (Object)null) && !((Object)(object)((AttachableFirearm)TubeFed).Attachment == (Object)null) && !((Object)(object)ModularPhysicalObject == (Object)null))
{
bool flag = (Object)(object)((FVRFireArmAttachment)((AttachableFirearm)TubeFed).Attachment).curMount != (Object)null;
if (flag && ModularPhysicalObject.ReceiverSkinUIPointProxy != null)
{
m_cachedSkinProxy = ModularPhysicalObject.ReceiverSkinUIPointProxy;
ModularPhysicalObject.ReceiverSkinUIPointProxy = null;
}
if (flag != m_wasMounted)
{
m_wasMounted = flag;
SetModularPointsMountedState(flag);
}
else if (flag && ((Component)ModularPhysicalObject).gameObject.activeSelf)
{
SetModularPointsMountedState(isMounted: true);
}
}
}
private void SetModularPointsMountedState(bool isMounted)
{
if ((Object)(object)ModularPhysicalObject == (Object)null)
{
return;
}
if ((Object)(object)((Component)ModularPhysicalObject).gameObject != (Object)null)
{
((Component)ModularPhysicalObject).gameObject.SetActive(!isMounted);
}
((Behaviour)ModularPhysicalObject).enabled = !isMounted;
if (isMounted)
{
ModularWorkshopUI[] componentsInChildren = ((Component)this).GetComponentsInChildren<ModularWorkshopUI>(true);
if (componentsInChildren != null)
{
for (int i = 0; i < componentsInChildren.Length; i++)
{
if ((Object)(object)componentsInChildren[i] != (Object)null && (Object)(object)((Component)componentsInChildren[i]).gameObject != (Object)null)
{
Object.Destroy((Object)(object)((Component)componentsInChildren[i]).gameObject);
}
}
}
if (ModularPhysicalObject.ReceiverSkinUIPointProxy != null)
{
m_cachedSkinProxy = ModularPhysicalObject.ReceiverSkinUIPointProxy;
ModularPhysicalObject.ReceiverSkinUIPointProxy = null;
}
if (!string.IsNullOrEmpty(ModularPhysicalObject.SkinPath) && !ModularPhysicalObject.SkinPath.EndsWith("_MOUNTED"))
{
ModularPhysicalObject.SkinPath = ModularPhysicalObject.SkinPath + "_" + ((Object)this).GetInstanceID() + "_MOUNTED";
}
return;
}
if (m_cachedSkinProxy != null)
{
ModularPhysicalObject.ReceiverSkinUIPointProxy = m_cachedSkinProxy;
m_cachedSkinProxy = null;
}
if (!string.IsNullOrEmpty(ModularPhysicalObject.SkinPath) && ModularPhysicalObject.SkinPath.EndsWith("_MOUNTED"))
{
int num = ModularPhysicalObject.SkinPath.IndexOf("_" + ((Object)this).GetInstanceID() + "_MOUNTED");
if (num > 0)
{
ModularPhysicalObject.SkinPath = ModularPhysicalObject.SkinPath.Substring(0, num);
}
}
}
private void CheckForDestroyedReferences()
{
bool flag = false;
if ((Object)(object)((AttachableFirearm)TubeFed).StockPos == (Object)null)
{
flag = true;
}
if (TubeFed.HasTrigger && (Object)(object)TubeFed.Trigger == (Object)null)
{
flag = true;
}
if (TubeFed.HasSafety && (Object)(object)TubeFed.Safety == (Object)null)
{
flag = true;
}
if (flag)
{
if (EnableDebugLogging)
{
Debug.Log((object)"[ModularAttachableTubeFed] Detected destroyed transform reference (part removed). Triggering state rebuild.");
}
RebuildWeaponState();
}
}
public void OnModularPartAdded(ModularWeaponPartsAttachmentPoint attachmentPoint, ModularWeaponPart newPart)
{
if (!((Object)(object)newPart == (Object)null) && !((Object)(object)TubeFed == (Object)null))
{
RebuildWeaponState();
}
}
private void RebuildWeaponState()
{
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: 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_064c: Unknown result type (might be due to invalid IL or missing references)
//IL_0662: Unknown result type (might be due to invalid IL or missing references)
//IL_06a8: Unknown result type (might be due to invalid IL or missing references)
//IL_06be: Unknown result type (might be due to invalid IL or missing references)
//IL_08f2: Unknown result type (might be due to invalid IL or missing references)
//IL_08f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0759: Unknown result type (might be due to invalid IL or missing references)
//IL_076f: Unknown result type (might be due to invalid IL or missing references)
//IL_0927: Unknown result type (might be due to invalid IL or missing references)
//IL_0929: Unknown result type (might be due to invalid IL or missing references)
//IL_091a: Unknown result type (might be due to invalid IL or missing references)
//IL_091c: Unknown result type (might be due to invalid IL or missing references)
//IL_0807: Unknown result type (might be due to invalid IL or missing references)
//IL_081d: Unknown result type (might be due to invalid IL or missing references)
//IL_07b5: Unknown result type (might be due to invalid IL or missing references)
//IL_07cb: Unknown result type (might be due to invalid IL or missing references)
//IL_0863: Unknown result type (might be due to invalid IL or missing references)
//IL_0879: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: 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_0a24: Unknown result type (might be due to invalid IL or missing references)
//IL_0a29: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: 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_0297: Unknown result type (might be due to invalid IL or missing references)
//IL_029c: 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_02b1: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)TubeFed == (Object)null)
{
return;
}
Transform val = null;
Transform val2 = null;
Transform val3 = null;
Transform val4 = DefaultStock;
bool hasActiveShoulderStock = false;
Transform trigger = DefaultTrigger;
bool hasTrigger = m_originalHasTrigger && (Object)(object)DefaultTrigger != (Object)null;
Transform safety = DefaultSafety;
bool hasSafety = m_originalHasSafety && (Object)(object)DefaultSafety != (Object)null;
FireArmRoundType roundType = m_originalRoundType;
FireArmMagazineType magazineType = m_originalMagazineType;
FVRFireArmRecoilProfile recoilProfile = m_originalRecoilProfile;
FVRFireArmRecoilProfile recoilProfileStocked = m_originalRecoilProfileStocked;
FVRFirearmAudioSet audioClipSet = m_originalAudioClipSet;
float triggerBreakThreshold = m_originalTriggerBreakThreshold;
float triggerResetThreshold = m_originalTriggerResetThreshold;
float speed_Forward = m_originalBoltSpeedForward;
float speed_Rearward = m_originalBoltSpeedRearward;
float springStiffness = m_originalBoltSpringStiffness;
ModularWeaponPart[] componentsInChildren = ((Component)this).GetComponentsInChildren<ModularWeaponPart>(false);
if (componentsInChildren != null)
{
foreach (ModularWeaponPart val5 in componentsInChildren)
{
if ((Object)(object)val5 == (Object)null || (Object)(object)((Component)val5).gameObject == (Object)null || !((Component)val5).gameObject.activeInHierarchy)
{
continue;
}
ModularBarrel val6 = ((Component)val5).GetComponent<ModularBarrel>();
if ((Object)(object)val6 == (Object)null)
{
val6 = ((Component)val5).GetComponentInChildren<ModularBarrel>();
}
if ((Object)(object)val6 != (Object)null)
{
if ((Object)(object)val6.MuzzlePosition != (Object)null)
{
val = val6.MuzzlePosition;
}
if (val6.ChangesFireArmRoundType)
{
roundType = val6.CustomRoundType;
}
if (val6.ChangesMagazineType)
{
magazineType = val6.CustomMagazineType;
}
if (val6.ChangesMagazineMountPoint)
{
if ((Object)(object)val6.CustomMagMountPoint != (Object)null)
{
val2 = val6.CustomMagMountPoint;
}
if ((Object)(object)val6.CustomMagEjectPoint != (Object)null)
{
val3 = val6.CustomMagEjectPoint;
}
}
if (val6.ChangesRecoilProfile && (Object)(object)val6.CustomRecoilProfile != (Object)null)
{
recoilProfile = val6.CustomRecoilProfile;
if ((Object)(object)val6.CustomRecoilProfileStocked != (Object)null)
{
recoilProfileStocked = val6.CustomRecoilProfileStocked;
}
}
if (val6.ChangesAudioSet && (Object)(object)val6.CustomAudioSet != (Object)null)
{
audioClipSet = val6.CustomAudioSet;
}
}
ModularBarrelExtension val7 = ((Component)val5).GetComponent<ModularBarrelExtension>();
if ((Object)(object)val7 == (Object)null)
{
val7 = ((Component)val5).GetComponentInChildren<ModularBarrelExtension>();
}
if ((Object)(object)val7 != (Object)null)
{
if (val7.ChangesMuzzlePosition && (Object)(object)val7.MuzzlePosition != (Object)null)
{
val = val7.MuzzlePosition;
}
if (val7.ChangesFireArmRoundType)
{
roundType = val7.CustomRoundType;
}
if (val7.ChangesMagazineType)
{
magazineType = val7.CustomMagazineType;
}
if (val7.ChangesMagazineMountPoint)
{
if ((Object)(object)val7.CustomMagMountPoint != (Object)null)
{
val2 = val7.CustomMagMountPoint;
}
if ((Object)(object)val7.CustomMagEjectPoint != (Object)null)
{
val3 = val7.CustomMagEjectPoint;
}
}
if (val7.ChangesRecoilProfile && (Object)(object)val7.CustomRecoilProfile != (Object)null)
{
recoilProfile = val7.CustomRecoilProfile;
if ((Object)(object)val7.CustomRecoilProfileStocked != (Object)null)
{
recoilProfileStocked = val7.CustomRecoilProfileStocked;
}
}
if (val7.ChangesAudioSet && (Object)(object)val7.CustomAudioSet != (Object)null)
{
audioClipSet = val7.CustomAudioSet;
}
}
FirearmModificationAddon val8 = ((Component)val5).GetComponent<FirearmModificationAddon>();
if ((Object)(object)val8 == (Object)null)
{
val8 = ((Component)val5).GetComponentInChildren<FirearmModificationAddon>();
}
if ((Object)(object)val8 != (Object)null)
{
if ((Object)(object)val8.Trigger != (Object)null)
{
trigger = val8.Trigger;
hasTrigger = true;
}
if (val8.ChangesTriggerThresholds)
{
triggerBreakThreshold = val8.TriggerThreshold;
triggerResetThreshold = val8.TriggerReset;
}
if ((Object)(object)val8.FireSelector != (Object)null)
{
safety = val8.FireSelector;
hasSafety = true;
}
if (val8.AdjustsFireRate)
{
if (val8.BoltSpeed_Forward > 0f)
{
speed_Forward = val8.BoltSpeed_Forward;
}
if (val8.BoltSpeed_Rearward > 0f)
{
speed_Rearward = val8.BoltSpeed_Rearward;
}
if (val8.BoltSpringStiffness > 0f)
{
springStiffness = val8.BoltSpringStiffness;
}
}
}
ModularStock val9 = ((Component)val5).GetComponent<ModularStock>();
if ((Object)(object)val9 == (Object)null)
{
val9 = ((Component)val5).GetComponentInChildren<ModularStock>();
}
if ((Object)(object)val9 != (Object)null)
{
Transform val10 = val9.StockPoint;
if ((Object)(object)val10 == (Object)null)
{
val10 = FindChildTransformRecursive(((Component)val5).transform, "Point_Stock");
}
if ((Object)(object)val10 == (Object)null)
{
val10 = FindChildTransformRecursive(((Component)val5).transform, "StockPoint");
}
if ((Object)(object)val10 == (Object)null)
{
val10 = FindChildTransformRecursive(((Component)val5).transform, "Stock");
}
if ((Object)(object)val10 != (Object)null)
{
val4 = val10;
hasActiveShoulderStock = val9.ActsLikeStock;
}
}
ModularStockExtension val11 = ((Component)val5).GetComponent<ModularStockExtension>();
if ((Object)(object)val11 == (Object)null)
{
val11 = ((Component)val5).GetComponentInChildren<ModularStockExtension>();
}
if ((Object)(object)val11 != (Object)null)
{
Transform val12 = val11.StockPoint;
if ((Object)(object)val12 == (Object)null)
{
val12 = FindChildTransformRecursive(((Component)val5).transform, "Point_Stock");
}
if ((Object)(object)val12 == (Object)null)
{
val12 = FindChildTransformRecursive(((Component)val5).transform, "StockPoint");
}
if ((Object)(object)val12 == (Object)null)
{
val12 = FindChildTransformRecursive(((Component)val5).transform, "Stock");
}
if ((Object)(object)val12 != (Object)null)
{
val4 = val12;
hasActiveShoulderStock = val11.ActsLikeStock;
}
}
FVRAlternateGrip val13 = ((Component)val5).GetComponent<FVRAlternateGrip>();
if ((Object)(object)val13 == (Object)null)
{
val13 = ((Component)val5).GetComponentInChildren<FVRAlternateGrip>();
}
if ((Object)(object)val13 != (Object)null && (Object)(object)((AttachableFirearm)TubeFed).Attachment != (Object)null)
{
val13.PrimaryObject = (FVRPhysicalObject)(object)((AttachableFirearm)TubeFed).Attachment;
}
}
}
if ((Object)(object)((AttachableFirearm)TubeFed).MuzzlePos != (Object)null)
{
if ((Object)(object)val != (Object)null)
{
((AttachableFirearm)TubeFed).MuzzlePos.position = val.position;
((AttachableFirearm)TubeFed).MuzzlePos.rotation = val.rotation;
}
else
{
if ((Object)(object)m_originalMuzzleParent != (Object)null)
{
((AttachableFirearm)TubeFed).MuzzlePos.SetParent(m_originalMuzzleParent);
}
((AttachableFirearm)TubeFed).MuzzlePos.localPosition = m_originalMuzzleLocalPos;
((AttachableFirearm)TubeFed).MuzzlePos.localRotation = m_originalMuzzleLocalRot;
}
}
if (((AttachableFirearm)TubeFed).MuzzleEffects != null)
{
for (int j = 0; j < ((AttachableFirearm)TubeFed).MuzzleEffects.Length; j++)
{
if (((AttachableFirearm)TubeFed).MuzzleEffects[j] != null)
{
((AttachableFirearm)TubeFed).MuzzleEffects[j].OverridePoint = null;
}
}
}
if ((Object)(object)((AttachableFirearm)TubeFed).MagazineMountPos != (Object)null)
{
if ((Object)(object)val2 != (Object)null)
{
((AttachableFirearm)TubeFed).MagazineMountPos.position = val2.position;
((AttachableFirearm)TubeFed).MagazineMountPos.rotation = val2.rotation;
}
else
{
if ((Object)(object)m_originalMagMountParent != (Object)null)
{
((AttachableFirearm)TubeFed).MagazineMountPos.SetParent(m_originalMagMountParent);
}
((AttachableFirearm)TubeFed).MagazineMountPos.localPosition = m_originalMagMountLocalPos;
((AttachableFirearm)TubeFed).MagazineMountPos.localRotation = m_originalMagMountLocalRot;
}
}
if ((Object)(object)((AttachableFirearm)TubeFed).MagazineEjectPos != (Object)null)
{
if ((Object)(object)val3 != (Object)null)
{
((AttachableFirearm)TubeFed).MagazineEjectPos.position = val3.position;
((AttachableFirearm)TubeFed).MagazineEjectPos.rotation = val3.rotation;
}
else
{
if ((Object)(object)m_originalMagEjectParent != (Object)null)
{
((AttachableFirearm)TubeFed).MagazineEjectPos.SetParent(m_originalMagEjectParent);
}
((AttachableFirearm)TubeFed).MagazineEjectPos.localPosition = m_originalMagEjectLocalPos;
((AttachableFirearm)TubeFed).MagazineEjectPos.localRotation = m_originalMagEjectLocalRot;
}
}
((AttachableFirearm)TubeFed).StockPos = val4;
((AttachableFirearm)TubeFed).HasActiveShoulderStock = hasActiveShoulderStock;
TubeFed.Trigger = trigger;
TubeFed.HasTrigger = hasTrigger;
TubeFed.TriggerBreakThreshold = triggerBreakThreshold;
TubeFed.TriggerResetThreshold = triggerResetThreshold;
TubeFed.Safety = safety;
TubeFed.HasSafety = hasSafety;
((AttachableFirearm)TubeFed).RoundType = roundType;
if ((Object)(object)TubeFed.Chamber != (Object)null)
{
TubeFed.Chamber.RoundType = roundType;
}
((AttachableFirearm)TubeFed).MagazineType = magazineType;
((AttachableFirearm)TubeFed).RecoilProfile = recoilProfile;
((AttachableFirearm)TubeFed).RecoilProfileStocked = recoilProfileStocked;
((AttachableFirearm)TubeFed).AudioClipSet = audioClipSet;
if ((Object)(object)((AttachableFirearm)TubeFed).StockPos != (Object)null && ((AttachableFirearm)TubeFed).HasActiveShoulderStock && (Object)(object)((AttachableFirearm)TubeFed).RecoilProfileStocked != (Object)null)
{
((AttachableFirearm)TubeFed).UsesStockedRecoilProfile = true;
}
else
{
((AttachableFirearm)TubeFed).UsesStockedRecoilProfile = false;
}
if ((Object)(object)Bolt != (Object)null)
{
Bolt.Speed_Forward = speed_Forward;
Bolt.Speed_Rearward = speed_Rearward;
Bolt.SpringStiffness = springStiffness;
}
((AttachableFirearm)TubeFed).UpdateCurrentMuzzle();
if (EnableDebugLogging)
{
string text = ((!((Object)(object)((AttachableFirearm)TubeFed).MuzzlePos != (Object)null)) ? "Null" : ((object)((AttachableFirearm)TubeFed).MuzzlePos.position/*cast due to .constrained prefix*/).ToString());
string text2 = ((!((Object)(object)val4 != (Object)null)) ? "Null" : ((Object)val4).name);
Debug.Log((object)("[ModularAttachableTubeFed] State rebuilt successfully. Mirrored Muzzle WorldPos: " + text + " | Stock: " + text2 + " | HasVirtualStock: " + hasActiveShoulderStock));
}
}
private Transform FindChildTransformRecursive(Transform parent, string targetName)
{
if ((Object)(object)parent == (Object)null)
{
return null;
}
if (string.Equals(((Object)parent).name, targetName, StringComparison.OrdinalIgnoreCase))
{
return parent;
}
for (int i = 0; i < parent.childCount; i++)
{
Transform val = FindChildTransformRecursive(parent.GetChild(i), targetName);
if ((Object)(object)val != (Object)null)
{
return val;
}
}
return null;
}
}
public class AudioConsistencyEnforcer : MonoBehaviour
{
[Header("Audio Profiles")]
public FVRFirearmAudioSet BaseHandlingAudioProfile;
private FVRFireArm _firearm;
private FVRFirearmAudioSet _lastAudioClipSet;
private void Awake()
{
_firearm = ((Component)this).GetComponent<FVRFireArm>();
if ((Object)(object)_firearm != (Object)null && (Object)(object)_firearm.AudioClipSet != (Object)null)
{
_lastAudioClipSet = _firearm.AudioClipSet;
BaseHandlingAudioProfile = ScriptableObject.CreateInstance<FVRFirearmAudioSet>();
SaveBaseHandlingAudio(_lastAudioClipSet);
}
else
{
Debug.LogError((object)"AudioConsistencyEnforcer: No FVRFireArm or AudioClipSet found on the object!");
}
}
private void LateUpdate()
{
if ((Object)(object)_firearm == (Object)null)
{
return;
}
FVRFirearmAudioSet audioClipSet = _firearm.AudioClipSet;
if ((Object)(object)audioClipSet == (Object)null)
{
Debug.LogWarning((object)"AudioConsistencyEnforcer: AudioClipSet is null!");
return;
}
if ((Object)(object)audioClipSet != (Object)(object)_lastAudioClipSet)
{
_lastAudioClipSet = audioClipSet;
}
EnforceHandlingSounds(audioClipSet);
}
private void SaveBaseHandlingAudio(FVRFirearmAudioSet source)
{
BaseHandlingAudioProfile.BoltRelease = source.BoltRelease;
BaseHandlingAudioProfile.BoltSlideBack = source.BoltSlideBack;
BaseHandlingAudioProfile.BoltSlideForward = source.BoltSlideForward;
BaseHandlingAudioProfile.BoltSlideBackHeld = source.BoltSlideBackHeld;
BaseHandlingAudioProfile.BoltSlideBackLocked = source.BoltSlideBackLocked;
BaseHandlingAudioProfile.BreachOpen = source.BreachOpen;
BaseHandlingAudioProfile.BreachClose = source.BreachClose;
BaseHandlingAudioProfile.CatchOnSear = source.CatchOnSear;
BaseHandlingAudioProfile.ChamberManual = source.ChamberManual;
BaseHandlingAudioProfile.FireSelector = source.FireSelector;
BaseHandlingAudioProfile.HammerHit = source.HammerHit;
BaseHandlingAudioProfile.HandleBack = source.HandleBack;
BaseHandlingAudioProfile.HandleBackEmpty = source.HandleBackEmpty;
BaseHandlingAudioProfile.HandleForward = source.HandleForward;
BaseHandlingAudioProfile.HandleForwardEmpty = source.HandleForwardEmpty;
BaseHandlingAudioProfile.HandleUp = source.HandleUp;
BaseHandlingAudioProfile.HandleDown = source.HandleDown;
BaseHandlingAudioProfile.HandleGrab = source.HandleGrab;
BaseHandlingAudioProfile.Prefire = source.Prefire;
BaseHandlingAudioProfile.Safety = source.Safety;
BaseHandlingAudioProfile.TriggerReset = source.TriggerReset;
BaseHandlingAudioProfile.TopCoverRelease = source.TopCoverRelease;
BaseHandlingAudioProfile.TopCoverUp = source.TopCoverUp;
BaseHandlingAudioProfile.TopCoverDown = source.TopCoverDown;
BaseHandlingAudioProfile.StockOpen = source.StockOpen;
BaseHandlingAudioProfile.StockClosed = source.StockClosed;
BaseHandlingAudioProfile.BipodOpen = source.BipodOpen;
BaseHandlingAudioProfile.BipodClosed = source.BipodClosed;
BaseHandlingAudioProfile.BeltGrab = source.BeltGrab;
BaseHandlingAudioProfile.BeltRelease = source.BeltRelease;
BaseHandlingAudioProfile.BeltSeat = source.BeltSeat;
BaseHandlingAudioProfile.BeltSettle = source.BeltSettle;
Debug.Log((object)"AudioConsistencyEnforcer: Base handling audio saved successfully!");
}
private void EnforceHandlingSounds(FVRFirearmAudioSet targetProfile)
{
targetProfile.BoltRelease = BaseHandlingAudioProfile.BoltRelease;
targetProfile.BoltSlideBack = BaseHandlingAudioProfile.BoltSlideBack;
targetProfile.BoltSlideForward = BaseHandlingAudioProfile.BoltSlideForward;
targetProfile.BoltSlideBackHeld = BaseHandlingAudioProfile.BoltSlideBackHeld;
targetProfile.BoltSlideBackLocked = BaseHandlingAudioProfile.BoltSlideBackLocked;
targetProfile.BreachOpen = BaseHandlingAudioProfile.BreachOpen;
targetProfile.BreachClose = BaseHandlingAudioProfile.BreachClose;
targetProfile.CatchOnSear = BaseHandlingAudioProfile.CatchOnSear;
targetProfile.ChamberManual = BaseHandlingAudioProfile.ChamberManual;
targetProfile.FireSelector = BaseHandlingAudioProfile.FireSelector;
targetProfile.HammerHit = BaseHandlingAudioProfile.HammerHit;
targetProfile.HandleBack = BaseHandlingAudioProfile.HandleBack;
targetProfile.HandleBackEmpty = BaseHandlingAudioProfile.HandleBackEmpty;
targetProfile.HandleForward = BaseHandlingAudioProfile.HandleForward;
targetProfile.HandleForwardEmpty = BaseHandlingAudioProfile.HandleForwardEmpty;
targetProfile.HandleUp = BaseHandlingAudioProfile.HandleUp;
targetProfile.HandleDown = BaseHandlingAudioProfile.HandleDown;
targetProfile.HandleGrab = BaseHandlingAudioProfile.HandleGrab;
targetProfile.Prefire = BaseHandlingAudioProfile.Prefire;
targetProfile.Safety = BaseHandlingAudioProfile.Safety;
targetProfile.TriggerReset = BaseHandlingAudioProfile.TriggerReset;
targetProfile.TopCoverRelease = BaseHandlingAudioProfile.TopCoverRelease;
targetProfile.TopCoverUp = BaseHandlingAudioProfile.TopCoverUp;
targetProfile.TopCoverDown = BaseHandlingAudioProfile.TopCoverDown;
targetProfile.StockOpen = BaseHandlingAudioProfile.StockOpen;
targetProfile.StockClosed = BaseHandlingAudioProfile.StockClosed;
targetProfile.BipodOpen = BaseHandlingAudioProfile.BipodOpen;
targetProfile.BipodClosed = BaseHandlingAudioProfile.BipodClosed;
targetProfile.BeltGrab = BaseHandlingAudioProfile.BeltGrab;
targetProfile.BeltRelease = BaseHandlingAudioProfile.BeltRelease;
targetProfile.BeltSeat = BaseHandlingAudioProfile.BeltSeat;
targetProfile.BeltSettle = BaseHandlingAudioProfile.BeltSettle;
}
}
public class BoltActionDustCover : FVRInteractiveObject
{
public FVRFireArm BoltActionRifle;
public BoltActionRifle_Handle BoltActionRifle_Handle;
public Transform DustCoverGeo;
private bool m_isOpen;
public float OpenRot;
public float ClosedRot;
public float RotSpeed = 360f;
private float m_curRot;
private float m_tarRot;
public AudioEvent AudEvent_CoverOpen;
public AudioEvent AudEvent_CoverClose;
public override void Awake()
{
((FVRInteractiveObject)this).Awake();
m_curRot = ClosedRot;
m_tarRot = ClosedRot;
}
public override void SimpleInteraction(FVRViveHand hand)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Invalid comparison between Unknown and I4
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
((FVRInteractiveObject)this).SimpleInteraction(hand);
if ((Object)(object)BoltActionRifle_Handle != (Object)null && (int)BoltActionRifle_Handle.HandleRot == 2)
{
if (m_isOpen)
{
Close();
}
else
{
Open();
}
}
else if ((Object)(object)BoltActionRifle_Handle != (Object)null && (int)BoltActionRifle_Handle.HandleRot == 0 && m_isOpen)
{
Close();
}
}
private void ToggleDustCoverState()
{
if (m_isOpen)
{
Close();
}
else
{
Open();
}
}
public override void FVRUpdate()
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
((FVRInteractiveObject)this).FVRUpdate();
if (!m_isOpen && (Object)(object)BoltActionRifle_Handle != (Object)null && (int)BoltActionRifle_Handle.HandleRot == 0)
{
Open();
}
if (Mathf.Abs(m_tarRot - m_curRot) > 0.01f)
{
m_curRot = Mathf.MoveTowards(m_curRot, m_tarRot, Time.deltaTime * RotSpeed);
if ((Object)(object)DustCoverGeo != (Object)null)
{
DustCoverGeo.localEulerAngles = new Vector3(0f, 0f, m_curRot);
}
}
}
private void Open()
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
if (!m_isOpen)
{
m_isOpen = true;
m_tarRot = OpenRot;
RotSpeed = 1900f;
if (AudEvent_CoverOpen != null && (Object)(object)BoltActionRifle != (Object)null)
{
BoltActionRifle.PlayAudioAsHandling(AudEvent_CoverOpen, ((Component)this).transform.position);
}
}
}
private void Close()
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
if (m_isOpen)
{
m_isOpen = false;
m_tarRot = ClosedRot;
RotSpeed = 800f;
if (AudEvent_CoverClose != null && (Object)(object)BoltActionRifle != (Object)null)
{
BoltActionRifle.PlayAudioAsHandling(AudEvent_CoverClose, ((Component)this).transform.position);
}
}
}
}