using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using OtherLoader;
using UnityEngine;
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace ApexTripleTake
{
public class TripleTakeBolt : ClosedBolt
{
[Header("Triple Take handles")]
[Tooltip("Hinge of the left handle (rear outer corner); folds about its Y")]
public Transform FoldLeft;
[Tooltip("Hinge of the right handle (rear outer corner); folds about its Y")]
public Transform FoldRight;
[Tooltip("How far a grabbed handle swings out (deg); the G36C's is 90")]
public float FoldAngle = 90f;
[Tooltip("Fold speed (full folds per second)")]
public float FoldSpeed = 12f;
[Tooltip("The handles' grab colliders on this bolt (left, right); they stay with their handles")]
public CapsuleCollider ColliderLeft;
public CapsuleCollider ColliderRight;
[Tooltip("Fold angles (deg, ascending) the clearances were measured at")]
public float[] ClearanceAngles;
[Tooltip("How far back (m) the left handle can go at each fold angle before it meets the rifle")]
public float[] ClearanceLeft;
[Tooltip("How far back (m) the right handle can go at each fold angle before it meets the rifle")]
public float[] ClearanceRight;
private float m_foldL;
private float m_foldR;
private float m_targetL;
private float m_targetR;
private Vector3 m_hingeL;
private Vector3 m_hingeR;
private Vector3 m_colL;
private Vector3 m_colR;
private bool m_restKnown;
public override void Awake()
{
((ClosedBolt)this).Awake();
KeepRest();
}
private void KeepRest()
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: 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)
if (!m_restKnown)
{
m_restKnown = true;
if ((Object)(object)FoldLeft != (Object)null)
{
m_hingeL = FoldLeft.localPosition;
}
if ((Object)(object)FoldRight != (Object)null)
{
m_hingeR = FoldRight.localPosition;
}
if ((Object)(object)ColliderLeft != (Object)null)
{
m_colL = ColliderLeft.center;
}
if ((Object)(object)ColliderRight != (Object)null)
{
m_colR = ColliderRight.center;
}
}
}
public void PreviewPose(float foldLeft, float foldRight)
{
KeepRest();
m_foldL = (m_targetL = foldLeft);
m_foldR = (m_targetR = foldRight);
PlaceHandles();
}
public override void UpdateInteraction(FVRViveHand hand)
{
//IL_0030: 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_004a: 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_0057: Unknown result type (might be due to invalid IL or missing references)
((ClosedBolt)this).UpdateInteraction(hand);
if (!((Object)(object)hand == (Object)null) && !((Object)(object)base.Weapon == (Object)null))
{
Vector3 val = hand.PalmTransform.position - ((Component)base.Weapon).transform.position;
bool flag = Vector3.Dot(val, ((Component)base.Weapon).transform.right) > 0f;
m_targetR = ((!flag) ? 0f : 1f);
m_targetL = ((!flag) ? 1f : 0f);
}
}
public override void EndInteraction(FVRViveHand hand)
{
((ClosedBolt)this).EndInteraction(hand);
m_targetL = 0f;
m_targetR = 0f;
}
public override void FVRUpdate()
{
((FVRInteractiveObject)this).FVRUpdate();
if (!((FVRInteractiveObject)this).IsHeld)
{
m_targetL = 0f;
m_targetR = 0f;
}
}
private void LateUpdate()
{
float num = FoldSpeed * Time.deltaTime;
m_foldL = Mathf.MoveTowards(m_foldL, m_targetL, num);
m_foldR = Mathf.MoveTowards(m_foldR, m_targetR, num);
PlaceHandles();
}
private void PlaceHandles()
{
//IL_003e: 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_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: 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_007e: 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_00ae: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
float num = FoldAngle * Smooth(m_foldL);
float num2 = FoldAngle * Smooth(m_foldR);
float back = ((!((Object)(object)base.Point_Bolt_Forward != (Object)null)) ? 0f : (base.Point_Bolt_Forward.localPosition.z - ((Component)this).transform.localPosition.z));
Place(FoldLeft, m_hingeL, ColliderLeft, m_colL, Quaternion.Euler(0f, 0f - num, 0f), back, Limit(ClearanceLeft, num));
Place(FoldRight, m_hingeR, ColliderRight, m_colR, Quaternion.Euler(0f, num2, 0f), back, Limit(ClearanceRight, num2));
}
private static void Place(Transform hinge, Vector3 hingeAt, CapsuleCollider col, Vector3 colAt, Quaternion fold, float back, float limit)
{
//IL_001f: 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_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: 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_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
float num = Mathf.Max(0f, back - limit);
if ((Object)(object)hinge != (Object)null)
{
hinge.localRotation = fold;
hinge.localPosition = hingeAt + Vector3.forward * num;
}
if ((Object)(object)col != (Object)null)
{
col.center = colAt + Vector3.forward * num;
}
}
private float Limit(float[] clearance, float angle)
{
if (ClearanceAngles == null || clearance == null)
{
return float.PositiveInfinity;
}
int num = Mathf.Min(ClearanceAngles.Length, clearance.Length);
if (num == 0)
{
return float.PositiveInfinity;
}
for (int i = 0; i < num; i++)
{
if (Mathf.Abs(angle - ClearanceAngles[i]) < 0.01f)
{
return clearance[i];
}
if (ClearanceAngles[i] > angle)
{
return (i != 0) ? Mathf.Min(clearance[i - 1], clearance[i]) : clearance[0];
}
}
return clearance[num - 1];
}
private static float Smooth(float t)
{
return t * t * (3f - 2f * t);
}
}
public class TripleTakeMagazine : FVRFireArmMagazine
{
public override void Awake()
{
TripleTakeVanilla.Borrow((FVRFireArmMagazine)(object)this);
((FVRFireArmMagazine)this).Awake();
}
}
public class TripleTakeRifle : ClosedBoltWeapon
{
[Header("Triple Take")]
[Tooltip("Side-to-side position of each barrel against the muzzle point (m, +X right): centre, left, right")]
public float[] BarrelOffsets = new float[3] { 0f, -0.0221f, 0.022f };
[Tooltip("Where the three projectiles meet (m)")]
public float ConvergeDistance = 100f;
[Tooltip("Rounds drawn from the magazine for each chambering, besides the chambered one")]
public int ExtraRoundsPerLoad = 2;
[Tooltip("Apex's left ejection port (shell_L): every other side case leaves here")]
public Transform RoundPos_EjectionLeft;
[Tooltip("Apex's sight_front bodygroup (iron sight), shown while the top mount is empty")]
public GameObject IronSight;
public FVRFireArmAttachmentMount TopMount;
private static bool s_patched;
private bool m_lastHadOptic = true;
private readonly List<GameObject> m_extras = new List<GameObject>();
private bool m_extrasSpent;
public override void Awake()
{
Patch();
TripleTakeVanilla.Borrow((FVRFireArm)(object)this);
((ClosedBoltWeapon)this).Awake();
UpdateSights(force: true);
}
public override void FVRUpdate()
{
((ClosedBoltWeapon)this).FVRUpdate();
UpdateSights(force: false);
}
private void UpdateSights(bool force)
{
bool flag = (Object)(object)TopMount != (Object)null && TopMount.AttachmentsList.Count > 0;
if (force || flag != m_lastHadOptic)
{
m_lastHadOptic = flag;
if ((Object)(object)IronSight != (Object)null)
{
IronSight.SetActive(!flag);
}
}
}
private static void Patch()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Expected O, but got Unknown
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Expected O, but got Unknown
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Expected O, but got Unknown
if (!s_patched)
{
s_patched = true;
Harmony val = new Harmony("LJIndustries.ApexTripleTake");
MethodInfo methodInfo = AccessTools.Method(typeof(FVRFireArm), "Fire", new Type[5]
{
typeof(FVRFireArmChamber),
typeof(Transform),
typeof(bool),
typeof(float),
typeof(float)
}, (Type[])null);
MethodInfo methodInfo2 = AccessTools.Method(typeof(ClosedBoltWeapon), "ChamberRound", (Type[])null, (Type[])null);
MethodInfo methodInfo3 = AccessTools.Method(typeof(ClosedBoltWeapon), "EjectExtractedRound", (Type[])null, (Type[])null);
if ((object)methodInfo == null || (object)methodInfo2 == null || (object)methodInfo3 == null)
{
Debug.LogError((object)"[ApexTripleTake] FVRFireArm.Fire / ClosedBoltWeapon.ChamberRound / EjectExtractedRound not found: the Triple Take fires single bullets");
return;
}
val.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(TripleTakeRifle), "FirePrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(TripleTakeRifle), "ChamberPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
val.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(TripleTakeRifle), "EjectPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
private static bool FirePrefix(FVRFireArm __instance, FVRFireArmChamber chamber, Transform muzzle, bool doBuzz, float velMult, float rangeOverride)
{
TripleTakeRifle tripleTakeRifle = __instance as TripleTakeRifle;
if ((Object)(object)tripleTakeRifle == (Object)null)
{
return true;
}
tripleTakeRifle.FireLoad(chamber, muzzle, doBuzz, velMult, rangeOverride);
return false;
}
private static void ChamberPostfix(ClosedBoltWeapon __instance, bool __result)
{
TripleTakeRifle tripleTakeRifle = __instance as TripleTakeRifle;
if ((Object)(object)tripleTakeRifle != (Object)null && __result)
{
tripleTakeRifle.LoadExtras();
}
}
private static void EjectPrefix(ClosedBoltWeapon __instance)
{
TripleTakeRifle tripleTakeRifle = __instance as TripleTakeRifle;
if ((Object)(object)tripleTakeRifle != (Object)null && ((ClosedBoltWeapon)tripleTakeRifle).Chamber.IsFull)
{
tripleTakeRifle.EjectExtras();
}
}
private void LoadExtras()
{
if (m_extras.Count > 0)
{
return;
}
m_extrasSpent = false;
for (int i = 0; i < ExtraRoundsPerLoad; i++)
{
if ((Object)(object)((FVRFireArm)this).Magazine == (Object)null)
{
break;
}
if (((FVRFireArm)this).Magazine.IsBeltBox)
{
break;
}
if (!((FVRFireArm)this).Magazine.HasARound())
{
break;
}
GameObject val = ((FVRFireArm)this).Magazine.RemoveRound(false);
if ((Object)(object)val != (Object)null)
{
m_extras.Add(val);
}
}
}
private void EjectExtras()
{
//IL_0072: 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)
//IL_0088: 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_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_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: 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_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
for (int i = 0; i < m_extras.Count; i++)
{
if ((Object)(object)m_extras[i] == (Object)null)
{
continue;
}
bool flag = i % 2 == 1 && (Object)(object)RoundPos_EjectionLeft != (Object)null;
Transform val = ((!flag) ? base.RoundPos_Ejection : RoundPos_EjectionLeft);
float num = ((!flag) ? 1f : (-1f));
Vector3 val2 = ((Component)this).transform.right * base.EjectionSpeed.x * num + ((Component)this).transform.up * base.EjectionSpeed.y + ((Component)this).transform.forward * base.EjectionSpeed.z;
Vector3 val3 = ((Component)this).transform.right * base.EjectionSpin.x + ((Component)this).transform.up * base.EjectionSpin.y * num + ((Component)this).transform.forward * base.EjectionSpin.z;
GameObject val4 = Object.Instantiate<GameObject>(m_extras[i], val.position + val2 * Time.deltaTime, val.rotation);
FVRFireArmRound component = val4.GetComponent<FVRFireArmRound>();
if (!((Object)(object)component == (Object)null))
{
component.SetHasEjectedFlag();
((FVRPhysicalObject)component).SetIFF(GM.CurrentPlayerBody.GetPlayerIFF());
((FVRPhysicalObject)component).RootRigidbody.velocity = Vector3.Lerp(val2 * 0.7f, val2, Random.value) + GM.CurrentMovementManager.GetFilteredVel();
((FVRPhysicalObject)component).RootRigidbody.maxAngularVelocity = 200f;
((FVRPhysicalObject)component).RootRigidbody.angularVelocity = Vector3.Lerp(val3 * 0.3f, val3, Random.value);
if (m_extrasSpent)
{
component.SetKillCounting(true);
component.Fire();
}
}
}
m_extras.Clear();
m_extrasSpent = false;
}
private void FireLoad(FVRFireArmChamber chamber, Transform muzzle, bool doBuzz, float velMult, float rangeOverride)
{
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0207: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_021d: Unknown result type (might be due to invalid IL or missing references)
//IL_0222: Unknown result type (might be due to invalid IL or missing references)
//IL_0227: Unknown result type (might be due to invalid IL or missing references)
//IL_022c: Unknown result type (might be due to invalid IL or missing references)
//IL_0231: 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_024f: Unknown result type (might be due to invalid IL or missing references)
//IL_0254: Unknown result type (might be due to invalid IL or missing references)
//IL_0257: Unknown result type (might be due to invalid IL or missing references)
//IL_0282: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: Unknown result type (might be due to invalid IL or missing references)
//IL_028c: Unknown result type (might be due to invalid IL or missing references)
//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0302: Unknown result type (might be due to invalid IL or missing references)
//IL_030c: Unknown result type (might be due to invalid IL or missing references)
//IL_0311: 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_0318: Unknown result type (might be due to invalid IL or missing references)
//IL_0338: Unknown result type (might be due to invalid IL or missing references)
//IL_033d: Unknown result type (might be due to invalid IL or missing references)
//IL_0342: Unknown result type (might be due to invalid IL or missing references)
//IL_035c: Unknown result type (might be due to invalid IL or missing references)
//IL_035e: Unknown result type (might be due to invalid IL or missing references)
//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0369: Unknown result type (might be due to invalid IL or missing references)
//IL_036e: Unknown result type (might be due to invalid IL or missing references)
//IL_0373: Unknown result type (might be due to invalid IL or missing references)
//IL_0378: Unknown result type (might be due to invalid IL or missing references)
//IL_037d: Unknown result type (might be due to invalid IL or missing references)
//IL_0387: Unknown result type (might be due to invalid IL or missing references)
//IL_0396: Unknown result type (might be due to invalid IL or missing references)
//IL_039b: Unknown result type (might be due to invalid IL or missing references)
//IL_039d: Unknown result type (might be due to invalid IL or missing references)
//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
if (doBuzz && (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)this).m_hand.Buzzer.Buzz_GunShot);
}
}
if (!((FVRInteractiveObject)this).IsHeld && !((FVRPhysicalObject)this).IsKinematicLocked && !((FVRPhysicalObject)this).IsPivotLocked && (Object)(object)((FVRPhysicalObject)this).RootRigidbody != (Object)null)
{
((FVRPhysicalObject)this).RootRigidbody.AddForceAtPosition(Vector3.Slerp(-muzzle.forward, Random.onUnitSphere, 0.1f) * Random.Range(0.4f, 0.8f), muzzle.position, (ForceMode)2);
}
GM.CurrentSceneSettings.OnShotFired((FVRFireArm)(object)this);
GM.CurrentPlayerBody.VisibleEvent((!((FVRFireArm)this).IsSuppressed()) ? 2f : 0.1f);
List<FVRFireArmRound> list = new List<FVRFireArmRound>();
list.Add(chamber.GetRound());
if (!m_extrasSpent)
{
foreach (GameObject extra in m_extras)
{
list.Add((!((Object)(object)extra != (Object)null)) ? null : extra.GetComponent<FVRFireArmRound>());
}
m_extrasSpent = m_extras.Count > 0;
}
if ((Object)(object)list[0] == (Object)null)
{
return;
}
float chamberVelMult = AM.GetChamberVelMult(chamber.RoundType, Vector3.Distance(((Component)chamber).transform.position, muzzle.position));
float num = ((FVRFireArm)this).GetCombinedFixedDrop(((FVRFireArm)this).AccuracyClass) * 0.0166667f;
Vector2 val = ((FVRFireArm)this).GetCombinedFixedDrift(((FVRFireArm)this).AccuracyClass) * 0.0166667f;
float num2 = ((FVRFireArm)this).m_internalMechanicalMOA + ((FVRFireArm)this).GetCombinedMuzzleDeviceAccuracy();
Vector2 val2 = (Random.insideUnitCircle + Random.insideUnitCircle + Random.insideUnitCircle) * (1f / 3f) * (list[0].ProjectileSpread + num2);
Quaternion val3 = muzzle.rotation * Quaternion.Euler(val2.x + val.y + num, val2.y + val.x, 0f);
for (int i = 0; i < list.Count; i++)
{
FVRFireArmRound val4 = list[i];
if ((Object)(object)val4 == (Object)null || (Object)(object)val4.BallisticProjectilePrefab == (Object)null)
{
continue;
}
float num3 = ((i >= BarrelOffsets.Length) ? 0f : BarrelOffsets[i]);
Vector3 val5 = muzzle.position + muzzle.right * num3 - muzzle.forward * 0.005f;
Quaternion val6 = val3 * Quaternion.Euler(0f, (0f - Mathf.Atan2(num3, ConvergeDistance)) * 57.29578f, 0f);
int num4 = Mathf.Max(1, val4.NumProjectiles);
for (int j = 0; j < num4; j++)
{
Quaternion val7 = val6;
if (j > 0)
{
Vector2 val8 = (Random.insideUnitCircle + Random.insideUnitCircle + Random.insideUnitCircle) * (1f / 3f) * (val4.ProjectileSpread + num2);
val7 = val6 * Quaternion.Euler(val8.x, val8.y, 0f);
}
GameObject val9 = Object.Instantiate<GameObject>(val4.BallisticProjectilePrefab, val5, val7);
BallisticProjectile component = val9.GetComponent<BallisticProjectile>();
component.Fire(component.MuzzleVelocityBase * chamber.ChamberVelocityMultiplier * velMult * chamberVelMult, val9.transform.forward, (FVRFireArm)(object)this, true);
if (rangeOverride > 0f)
{
component.ForceSetMaxDist(rangeOverride);
}
}
}
}
}
public class TripleTakeStrap : MonoBehaviour
{
public float MaxAngle = 70f;
public float Stiffness = 60f;
public float Damping = 4f;
private Quaternion m_rest;
private Vector3 m_angles;
private Vector3 m_velocity;
private Vector3 m_lastPos;
private Vector3 m_lastVel;
private void Awake()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
m_rest = ((Component)this).transform.localRotation;
m_lastPos = ((Component)this).transform.position;
}
private void OnEnable()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
m_lastPos = ((Component)this).transform.position;
m_lastVel = Vector3.zero;
}
private void LateUpdate()
{
//IL_0034: 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_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)
//IL_004a: 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_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_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_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: 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_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: 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_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: 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)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
float num = Mathf.Max(Time.deltaTime, 0.0001f);
Transform parent = ((Component)this).transform.parent;
if (!((Object)(object)parent == (Object)null))
{
Vector3 val = (((Component)this).transform.position - m_lastPos) / num;
Vector3 val2 = (val - m_lastVel) / num;
m_lastPos = ((Component)this).transform.position;
m_lastVel = val;
Vector3 val3 = Physics.gravity - Vector3.ClampMagnitude(val2, 60f);
Vector3 val4 = Quaternion.Inverse(parent.rotation * m_rest) * ((Vector3)(ref val3)).normalized;
float num2 = Mathf.Atan2(val4.z, 0f - val4.y) * 57.29578f;
float num3 = (0f - Mathf.Atan2(val4.x, 0f - val4.y)) * 57.29578f;
Vector3 val5 = default(Vector3);
((Vector3)(ref val5))..ctor(Mathf.Clamp(num2, 0f - MaxAngle, MaxAngle), 0f, Mathf.Clamp(num3, 0f - MaxAngle, MaxAngle));
m_velocity += ((val5 - m_angles) * Stiffness - m_velocity * Damping) * num;
m_angles += m_velocity * num;
m_angles.x = Mathf.Clamp(m_angles.x, 0f - MaxAngle, MaxAngle);
m_angles.z = Mathf.Clamp(m_angles.z, 0f - MaxAngle, MaxAngle);
((Component)this).transform.localRotation = m_rest * Quaternion.Euler(m_angles.x, 0f, m_angles.z);
}
}
}
public static class TripleTakeVanilla
{
public const string DonorId = "Mk17";
private static bool s_looked;
private static ClosedBoltWeapon s_donor;
public static ClosedBoltWeapon Donor
{
get
{
if (!s_looked || (Object)(object)s_donor == (Object)null)
{
s_looked = true;
if (IM.OD != null && IM.OD.TryGetValue("Mk17", out var value) && (Object)(object)value != (Object)null)
{
GameObject gameObject = ((AnvilAsset)value).GetGameObject();
if ((Object)(object)gameObject != (Object)null)
{
s_donor = gameObject.GetComponent<ClosedBoltWeapon>();
}
}
if ((Object)(object)s_donor == (Object)null)
{
Debug.LogWarning((object)"[ApexTripleTake] H3VR's Mk17 was not found: the Triple Take is silent and kicks gently");
}
}
return s_donor;
}
}
public static void Borrow(FVRFireArm gun)
{
ClosedBoltWeapon donor = Donor;
if ((Object)(object)donor == (Object)null)
{
DropEmptyGas(gun);
return;
}
if ((Object)(object)((FVRFireArm)donor).AudioClipSet != (Object)null)
{
gun.AudioClipSet = ((FVRFireArm)donor).AudioClipSet;
}
if ((Object)(object)((FVRFireArm)donor).RecoilProfile != (Object)null)
{
gun.RecoilProfile = ((FVRFireArm)donor).RecoilProfile;
}
if ((Object)(object)((FVRFireArm)donor).RecoilProfileStocked != (Object)null)
{
gun.RecoilProfileStocked = ((FVRFireArm)donor).RecoilProfileStocked;
gun.UsesStockedRecoilProfile = ((FVRFireArm)donor).UsesStockedRecoilProfile;
}
if (gun.GasOutEffects != null && ((FVRFireArm)donor).GasOutEffects != null)
{
for (int i = 0; i < gun.GasOutEffects.Length && i < ((FVRFireArm)donor).GasOutEffects.Length; i++)
{
if ((Object)(object)gun.GasOutEffects[i].EffectPrefab == (Object)null)
{
gun.GasOutEffects[i].EffectPrefab = ((FVRFireArm)donor).GasOutEffects[i].EffectPrefab;
}
}
}
DropEmptyGas(gun);
}
public static void Borrow(FVRFireArmMagazine mag)
{
ClosedBoltWeapon donor = Donor;
if ((Object)(object)donor != (Object)null && (Object)(object)((FVRFireArm)donor).AudioClipSet != (Object)null)
{
mag.Profile = ((FVRFireArm)donor).AudioClipSet;
}
}
private static void DropEmptyGas(FVRFireArm gun)
{
if (gun.GasOutEffects == null)
{
return;
}
List<GasOutEffect> list = new List<GasOutEffect>();
GasOutEffect[] gasOutEffects = gun.GasOutEffects;
foreach (GasOutEffect val in gasOutEffects)
{
if (val != null && (Object)(object)val.EffectPrefab != (Object)null && (Object)(object)val.Parent != (Object)null)
{
list.Add(val);
}
}
gun.GasOutEffects = list.ToArray();
}
}
}
namespace LJIndustries.ApexTripleTake
{
[BepInPlugin("LJIndustries.ApexTripleTake", "ApexTripleTake", "0.5.0")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
public class ApexTripleTakePlugin : 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(), "LJIndustries.ApexTripleTake");
OtherLoader.RegisterDirectLoad(BasePath, "LJIndustries.ApexTripleTake", "", "", "apex_tripletake", "");
}
}
}